Solved

Could this be done?

Posted on 2013-01-09
4
212 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
  • 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 34

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 34

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 82

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now