Solved

Could this be done?

Posted on 2013-01-09
4
221 Views
Last Modified: 2013-01-12
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?
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 166 total points
ID: 38759947
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.

Cd&
0
 
LVL 35

Assisted Solution

by:gr8gonzo
gr8gonzo earned 167 total points
ID: 38759949
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 https://code.google.com/apis/console/ 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 http://www.google.com/cse
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:

<?php

// 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
print_r($results1);
print_r($results2);

/* GoogleSearch 1.0 by gr8gonzo */
class GoogleSearch
{
	private $apiKey = "";
	private $cx = "";
	private $baseURL = "https://www.googleapis.com/customsearch/v1?key=---APIKEY---&cx=---CXID---&q=---QUERY---&alt=json";

	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
		if(!file_exists("cache"))
		{
			if(!mkdir("cache"))
			{
				// 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);
		
		if(!file_exists($cache))
		{
			// No cached file - download and cache
			$contents = file_get_contents($url);
			file_put_contents($cache,$contents);
			
			// Record in index
			file_put_contents("cache/index.html","<a href='".substr($cache,6)."'>{$url}</a><br />\n",FILE_APPEND);
		}
		elseif($returncontents)
		{
			// Cache exists, use it
			$contents = file_get_contents($cache);
		}
	
		// Return contents or cache filename?
		if($returncontents)
		{
			return $contents;
		}
		else
		{
			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.
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 38759966
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.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 167 total points
ID: 38760409
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 http://www.harryfox.com/public/songfile.jsp is their database search.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question