Could this be done?

I've got a table of 1,000 plus song titles. Most of these are original compositions. What I've done in the past is do a google search one song title at a time to see if there's any published material with the same song title. If there is, I'll do a little more digging to see if the song is a cover as opposed to an original.

That was fine when I had about a 100 titles. Now that the list is so much bigger, I was wondering if there was a way that I could write a script that would loop through all of the song titles and do a google search on each one and then flag those titles where something came back that said this was a possible song title.

I've read a little on google search array, but I'm not certain I'm even barking up the right tree. Any suggestions?
brucegustPHP DeveloperAsked:
Who is Participating?
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
The best place to look for published song titles is The Harry Fox Agency (HFA) who handles licensing for about 99% of the music that has been published.  Songfile is their database search.
COBOLdinosaurConnect With a Mentor Commented:
You can automate the whole thing using Google alerts.  It would take some time and work to do the initial setup, but once it is done.  You will get an email that every time an item shows up. You want to be very careful about using php to bypass the Google APIs, they don't like having anything go around their APIs and might block you; ban you; and make life miserable.

gr8gonzoConnect With a Mentor ConsultantCommented:
Google gives you an API to perform searches. To use it, follow these steps:

Part 1: Get access to Google Custom Search
Step 1: Go to and login if you're not already.
Step 2: If you don't already have an API key, go to API Access and get one for browser apps (keep this handy).
Step 3: Go to Services (on the left menu) and turn on the Custom Search API.

Part 2: Create a new search engine
Step 1: Go to
Step 2: Click on New search engine (on the left menu)
Step 3: Fill out the description, put in any domain in the included sites, and agree to the ToS and continue.
Step 4: Click on Next
Step 5: Copy the value of the "cx" parameter from the textbox. It should be a long string of numbers and letters with a colon in the middle, like 00513368777701234567:abcdefghi3j8
Step 6: Click on the link to change Basics and then towards the bottom, check the option to search the entire web and click on Save Changes.

Part 3: Use the search engine
At this point, you should have an API key from Part 1, and a Custom Search Engine ID from Part 2. Now, performing the search is extremely easy in PHP, and I created a PHP class to assist with caching results, too:


// Define the API key and Custom Search Engine ID
$apiKey = "ABCdefGHIjklMNOpqrSTUvwxYZ1234567890";
$cseID = "005612312312312312312:abcabc3_h08";

// Add a new instance of GoogleSearch
$GS = new GoogleSearch($apiKey,$cseID);

// Perform a couple searches
$results1 = $GS->search("some keyword");
$results2 = $GS->search("a different keyword");

// Display the results

/* GoogleSearch 1.0 by gr8gonzo */
class GoogleSearch
	private $apiKey = "";
	private $cx = "";
	private $baseURL = "";

	public function __construct($apiKey,$cxID)
		$this->baseURL = str_replace(array("---APIKEY---","---CXID---"),array($apiKey,$cxID),$this->baseURL);
	public function search($keyword)
			$url = str_replace("---QUERY---",urlencode($keyword),$this->baseurl);
			return = json_decode($this->getCachedDocument($url),true);

	private function getCachedDocument($url,$returncontents = true)
		// Ensure cache directory exists
				// Can't cache - just get the data
				return file_get_contents($url);
		// Cached filename
		$cache = "cache/".md5($url).".html";
		// Check for failed caching
		if(file_exists($cache) && (filesize($cache) == 0)) unlink($cache);
			// No cached file - download and cache
			$contents = file_get_contents($url);
			// Record in index
			file_put_contents("cache/index.html","<a href='".substr($cache,6)."'>{$url}</a><br />\n",FILE_APPEND);
			// Cache exists, use it
			$contents = file_get_contents($cache);
		// Return contents or cache filename?
			return $contents;
			return $cache;


Open in new window

Bear in mind that the results are in an array that has a ton of information about each listing, so you'll need to look at the results to figure out what information you actually want.
Also bear in mind that the API lets you perform 100 searches per day for free. Anything beyond that and you'll need to pay a small fee, but as long as you're only performing 100 searches, you're fine.

Make sure you use the API, though, and don't try to search Google directly unless you just haven't had a really good headache in a while.
All Courses

From novice to tech pro — start learning today.