A script to pick up song lyrics from the web - feedback

Below is a PC implementation of this script written by Chris Schull which uses google to grab the lyrics of the selected song in iTunes and add them to the tags for the song.
Enjoy Andrew's first go at converting an Applescript to .net for the PC. I guess it is written in C++ since the file he gave me is .cs ?
using System;
using iTunesLib;
using System.Net;
using System.IO;
using System.Collections;
namespace AJCOWLEY
/// <summary>
/// Provides Windows .Net methods for interacting with iTunes.
/// version 0.1 (this version) gets the lyrics for the currently playing track.
/// </summary>
public class myTunes
IiTunes iTunesApp;
const string baseurl = "http://www.google.com/search?q=site:searchlyrics.org-download";
public myTunes()
iTunesApp = new iTunesAppClass();
//Currently am only supporting one method: so go to it.
//Supply the current track playing. In future could loop around
// a playlist or selected tracks and get lyrics for all of them.
// easy enough to add when it is working reliably for one..
get_lyrical(iTunesApp.CurrentTrack, true);
static void Main()
//Instantiate an instance of the main class
myTunes _this = new myTunes();
* get_lyrical:
* First method developed for the myTunes application.
* Will get the lyrics for a given track
void get_lyrical(iTunesLib.IITTrack t, bool overwrite)
if ( (t != null) && ( ( t.Kind == ITTrackKind.ITTrackKindCD ) || (t.Kind == ITTrackKind.ITTrackKindFile )))
//Cast the generic track pointer
// to a pointer that supports lyrics
IITFileOrCDTrack f = (IITFileOrCDTrack) t;
//Get the current lyrics
string l = f.Lyrics;
//Check if okay to overwrite
if ( (l == null) || ( l.Length == 0 ) || (overwrite == true))
f.Lyrics = get_lyrics(f.Artist, f.Name );
* get_lyrics:
* Asks google to search a lyric website, and loops through
* each of the google hits. Each hit is opened and examined to see if
* it contains lyrics within predetermined delimters.
string get_lyrics(string Artist, string TrackName)
//Setup the url to be searched. remove parantheses and spaces from arguments
string url = baseurl+ fixup(Artist) +" lyrics " + fixup(TrackName);
string google_response=WebQuery(url);
* Loop through each google hit, get the URL, open the page, strip out the lyrics
* until lyrics != null
foreach( string hiturl in getgooglehits(googleresponse))
//launch the hit
//get responses in between the values "<font" and "</font>"
//then home in on the first ">" character.
string hitpage = WebQuery(fixup(hiturl));
hitpage=TextBetween(hitpage,"<font","</font>");
//Strio off the "" text
hitpage=hitpage.Substring(hitpage.IndexOf(">")+1);
//Strip off the "" text
hitpage=hitpage.Substring(0,hitpage.Length - 7);
//Strip off html newline breaks
string lyrics = clearHTML(hitpage);
if (lyrics.Length > 0 )
return hiturl":n"lyrics;
return "";
string clearHTML(string text)
string clean_text="";
bool kill=false;
foreach (char c in text)
if (c=='<') kill = false;
return clean_text;
* WebQuery:
* Open a web page and return the results as a string using System.Net
* N.B. The GetResponse method doesnt seem to like going through proxy servers.
* and yes, this should be in a class of its own (sic)
string WebQuery(string url)
WebResponse myResponse=null;
StreamReader readStream=null;
try
// Initialize the WebRequest and get the Webresponse handle
WebRequest myRequest = WebRequest.Create(url);
myResponse = myRequest.GetResponse();
// Read through the WebResponse.
Stream receiveStream = myResponse.GetResponseStream();
// Pipes the stream to a higher level stream reader with the required encoding format.
readStream = new StreamReader (receiveStream, System.Text.Encoding.UTF8 );
string text= readStream.ReadToEnd();
return text;
catch
return "";
finally
// Free up the resources.
if ( readStream != null) readStream.Close();
if (myResponse != null) myResponse.Close();
/* Loop throught the results using the <div> tags and http/html as markers
* to indicate where the results are
ArrayList get_googlehits(string google_results)
string text= google_results;
ArrayList s = new ArrayList();
string part;
while ( text.Length > 0)
//First zone in on the text between the div tags
part=TextBetween(text,"","");
//Now zone in on the url itself. The url will start with http and end in .html
part=TextBetween(part,"http",".html");
if ( part.Length == 0 )text=""; //reached end of the line
else
//prepare string for the next go around by stripping off
//the bit we have already looked at.
text=text.Substring(text.IndexOf(""));
//Add hit to the array
s.Add(part);
return s;
//Simple function to extract text between ( and including) two
//separators.
//Ideally this would be a class extension of "string"
string TextBetween(string s, string spat, string epat)
int startpos = 0, len;
string tmp;
if ((s==null) || (s.Length==0))
return "";
startpos=s.IndexOf(spat,startpos);
if (startpos== -1 )
return "";
tmp=s.Substring(startpos);
len=tmp.IndexOf(epat);
if (len==-1)
return "";
else
tmp=tmp.Substring(0,len+epat.Length);
return tmp;
//Replace spaces with + and remove parentheses
string fixup(string s)
return s.Replace(" ","+").Replace("(","").Replace(")","");
} //end of class declaration
}//end of Namespace

Otto42 has a multi-script utility that will do just this function.
See here for individual functions: http://ottodestruct.com/blog/2005/10/20/itunes-javascripts/
Or get his 'QuickScripts.zip' multi-script utility: http://ottodestruct.com/blog/category/geekery/programmery/

Similar Messages

  • Reading Lyrics from the iPod....?

    Is there anybody who knows how to make use of the storage of song lyrics in the iPod? I'm using now the widget "Sing that iTune", which is able to display lyrics within the widget, but also stores it as a .txt file in a separate folder, called 'Sing that iTune". I understand from previous posts and discusssions that it is possible to import them as notes. Is there anybody who has been able to script tihs syncing of notes folders?
    Second, when I was updating my iPod I saw that all the songs that include lyrics (besides storing the lyrics in the separate folder it can also automatically update the lyrics panel of the songs info!) were also automatically updated to my iPod. This means that the info of the txt file is also somewhere sitting in my iPod...!! It would be fantastic if Apple would exploid that possibility to also allow displaying lyrics instead of for example art-work during playback. I'm not a programmer, but I suppose that it should well be possible to include such option in a next software update..... Or are there any third party utilities that do the trick? Any ideas appreciated!

    Coming back to my previous question: I've now been experimenting with 'Sing that iTune' a bit more, and to my big surpise one is able to start up a song by clicking the note that contains the lyrics! I do not know if this is different or similar to the iPod Nano Lyrics feature where one talks about, but it is at least something.
    HOWEVER: one problem remains! The iPod can only load 1000 notes!? The rest are copied to the iPod, but remain unvisible?! Does anyone know a work around?
    Thanx!

  • Is there any way to do a mass copy and paste of song titles from the "name" column to the "sort name" column? I know it can be done with individual titles but I have over 6,000 titles in my library.

    In iTunes, is there any way to do a mass copy and paste of song titles from the "name" column to the "sort name" column? I know it can be done with individual titles but I have over 6,000 titles in my library.

    Thank you. I have heard of Logic Pro 7, but I have never personally used it. I'm still growing in the world of Composition, and I know that it is something I will be studying in one of my Computer Music classes coming up for my degree. I think it is something I will look into getting once I can justify the price of it. I guess for the time being, I will continue to play and grow in my ability to use and take advantage of GB, and then see what I can do about or with Logic Pro when I'm ready. The thought of spending $1000 for a program is hard to bite, because I've already spent a lot to produce my music, not only electronic music, but also chamber music and so on. I had no idea it would be so expensive to dive deep into the world of composition! lol.
    Finale 2007: $500
    Sibelius 4: $500
    Jam Packs: $400
    Midi Keyboard Interface: $100
    PowerBook: $1700
    Printer for printing scores and analysis: $150
    Logic Pro 7: Oy!
    As you can see it adds up very quickly...that doesn't even include my personal instruments and study materials.
    Thank you for your input, as I haven't really worked much with LP, and therefore didn't know which features are available. I will talk with some of my Composition buddies, and professors and see what they have to say as well, and who knows, I may be able to get the express version through one of them.

  • How Do I Get An Uploaded Song Removed From The iTunes Store That I Own?

    I own a production company and I own a song that has been uploaded to iTunes Store for sale.  I am having problems with the people that I have trusted in properly administering the publishing aspects of the song. How do i get the song removed from the iTunes Store so i can get it re-released under another publishing group who have shown they can properly administer the publishing/copyrighting/monetary aspects of my song?

    DUPDAWG wrote:
      ps I used to be able to create my own "Ringtones" via iTunes and songs I had in iTunes, but they took that away I guess.
    No they didn't. You can still create your own ringtone using computer iTunes.
    Here are the steps:
    Select a title (.mp3 or .m4a) in your iTunes Library
    2. Do File > Get Info on selected title (Windows do Edit > Get Info)
    3. In the dialog choose Options tab
    4. Set Start Time and End Time (no more than 35 secs otherwise won't work)
    5. Close dialog.
    6. Now control click the title (right click) and choose Create AAC Version
    7. When it is done, drag the newly create title to the desktop.
    8. Delete the newly create title in iTunes.
    9. Rename the title on your desktop from ringtone.m4a to ringtone.m4r
    10. Drag and drop it into iTunes
    Now you have a ringtone.
    Make sure it is selected in iTunes's Tones tab for syncing with your iPhone.

  • I have MBP 13 late 2011:Will it be able to support a 3tb hardisk?Secondly, if i delete a song from itunes,is that song removed from the mac and is the space freed up?If not then what should I do to free up space when i delete songs from itunes?

    I have MBP 13 late 2011:
    Will it be able to support a 3tb hardisk?
    Secondly, if i delete a song from itunes,is that song removed from the mac and is the space freed up?If not then what should I do to free up space when i delete songs from itunes?

    Your MBP will support a 3T HDD provided it is formatted correctly and has sufficient power.  Most large HDDs require an outboard power source.
    When you delete songs from iTunes you will get a message if you want to send it to trash.  If you send it to trash, space will be freed up only when you empty trash.  An individual song does not consume much space so if your HDD is becoming full, more drastic action s should be considered, such as moving an entire file to an external HDD.
    Ciao.

  • I have just come back from morocco where my phone worked ok using the morroco network, but since returning to the uk I can't get it to pick up a signal from the 'Three' network, have tried resetting etc but still wont work, any suggestions

    I have just come back from morocco where my phone worked ok using the morroco network, but since returning to the uk I can't get it to pick up a signal from the 'Three' network, have tried resetting etc but still wont work, any suggestions

    banannaphone,
    Welcome to Apple Discussions.
    Quit Safari, find the com.apple.Safari.plist file in your Macintosh HD/Users/yourusername/Library/Preferences Folder, drag it to the Desktop, log out/in or restart and let us know what happens.
    ;~)

  • My pc crashed and erased my itunes songs purchased from the itunes store. How do i get that content back without having to purchase them again?

    my pc crashed and erased my itunes songs purchased from the itunes store. How do i get that content back without having to purchase them again?

    I have somewhat of a similar problem. After iTunes last update, I am missing some of my purchased files of music,ringtones, and TV shows. Possibly movies, but just thought of that and did not look yet. Seems everytime there is an iTunes update, something happens, but usually an easy fix by just deleting music files from CD's that I loaded onto iTunes and no longer recognized after an update and reload from the hard drive. This time I do not have a current back up of all the music, ringtones, and tv shows I have purchased.
    So I am also wondering how can I redownload purchases without being charged when there is no file left on the hard drive. It just stays listed in iTunes though.

  • I am unable to transfer song bought from the itunes store to my ipod- can anyone please assist?

    I am unable to transfer song bought from the itunes store to my ipod- can anyone please assist?

    What happens when you try?
    If the song is an older purchase (from more than a few years ago), it may have DRM (copy protection).  You can check by selecting the song on a list in iTunes, and doing a Get Info (right click - Get Into).  On the Info window Summary tab, if Kind is Protected AAC audio file, it has DRM.  Also note what it says there for Apple ID.  You need to authorize the computer you use with the iPod to play content purchased with that Apple ID.
    From the iTunes menu bar, under Store, select Authorize This Computer.  Enter the Apple ID (and password) used to purchase the song.  One computer can be authorize for multiple Apple IDs.
    NOTE:  More recent iTunes Store song purchases do not use DRM, although other type of media (such as TV shows and movies) still do.
    If that's not the cause of your problem, please post back with more details...

  • I have added more songs to my library. Half of the library has selected ticks but when I click on any of the others to select them the whole song disappears from the list. Why and what can I do to fix?

    I have added more songs to my library. Half of the library has selected ticks but when I click on any of the others to select them, the whole song disappears from the list. Why and what can I do to fix?

    Hey Paul,
    If I understand correctly, it sounds like iTunes is not grouping the songs from a particular CD together. The cause could be something as minor as a misspelling or slight variations. For more information, see the following resource:
    Why aren't songs with the same album art grouped together?
    http://support.apple.com/kb/TS1468
    Thanks,
    Matt M.

  • How do I close the played songs list from the miniplayer?

    How do I close the played songs list from the miniplayer?

    Click on the same 3 bar symbol that opened it.
    tt2

  • Download file from the web

    Hey,
    I'm struggling to download files from the web.
    The first approach I though of was simply opening the url in Safari, but it would just open the file, not download it.
    Then there is an application called "URL Access Scripting", but I can't figure out how it works.
    That might sound stupid, since it has only a download and an upload command, but they do not work.
    The download function asks for a file specification, what the #$^& is that?
    I tried supplying a file, but to no avail.
    For obvious reasons I can't make an alias of a not yet existing file, so what do I put in there?
    It seems file specification is a deprecated format.
    My last resort was running curl in a shell script, which works, but that feels hackish.
    Is there any good way to do this?

    Hi pepsel,
    Let's take an example. Suppose that you want to download “UltiCalc Mac 2.5” (freeware) from [this Web page|http://www.apple.com/downloads/macosx/games/utilities/ulticalcmac.html]. You can proceed as follows:
    --BEGINNING OF SCRIPT
    set theURL to "http://wsidecar.apple.com/cgi-bin/nph-reg3rdpty2.pl/product=23023&cat=25&platf orm=osx&method=sa/ulticalc_mac.zip"
    set theFile to "/Users/pierre/Desktop/My_download.zip" -- same extension as the file to download
    tell application "URL Access Scripting" to download theURL to theFile
    --END OF SCRIPT
    Of course, you should replace “pierre” with the name of your own home folder.
    Hope it can help.
    Message was edited by: Pierre L.

  • How do I access my AE attached lacie drive from the web

    I just hooked up a 1TB drive to my new AE and think I have it configured properly in the disk pane of airport utility. I'm very much hoping that I have it configured correctly! I chose to configure "with a disk password", and not " accounts", and just for the heck of it clicked on the "?" [airport utility help] at the bottom of the Disks/File Sharing page. At the bottom of the page in help under "sharing a usb hard disk on your network", under " to set up disk sharing:" #4 "select the " share disks over ethernet WAN port" checkbox if you want to provide remote access to the disk over the wan port", It turns out that I don't have that message on my airport utility pane for Disk/ file sharing. I do have a checkbox that says " share disks over the internet using Bonjour, but I definitely don't have a checkbox that says " ethernet wan port" as a choice.
    Why would my pane be missing that choice? I recall setting up the AE choosing to be able to use computers with the pre 802.11n compatability. Should I have chosen the 5ghz which is 802.11n only as I recall.
    I hope this all isn't sounding to complicated. I just want to be able to access my hard drive [connected to the AE] remotely from the web and hopefully be able to access a huge music library that i have on that drive. HELP, PLEASE, KIND APPLE PEOPLE!

    It is attached to another router.
    In order to access a drive from the Internet, you need to know the Public IP address of the router and the router would need to be configured to port map the file service requests from the Internet to the drive. Apple provides Leopard and Snow Leopard users a means to access drives attached to an 802.11n AirPort Extreme Base Station (AEBSn), from the Internet, by using a feature known as "Back to My Mac." You may want to explore this option further.
    Without Back to My Mac, the router would need to be manually configured to make this work. In a much simpler case where the 802.11 AirPort Extreme Base Station (AEBSn) is directly connected to the Internet modem, you would use the AirPort Utility to determine its Public IP address and to configure it for port mapping. The only difficult issue is the type of Public IP address that your ISP provides you. Most consumer-grade Internet service comes with a dynamic IP address. That means this address will change periodically and you will need to keep track of the changes in order to be successful in accessing it from the Internet. One way to do this is to use a DDNS service, like DynDNS.
    In your case, there is an added level of complexity since the AEBSn is downstream of another router. You would have to configure both this router and the AEBSn to get this to work.
    Should I try to set up with accounts, would that be different in regards to this problem?
    The 802.11n AirPort Extreme Base Station (AEBSn) can share out a hard drive with three types of access: 1) Base Station Password, 2) Disk Password, or 3) With Accounts. Which type you choose will not affect the drive from being accessed from the Internet.

  • I am trying to use an education program that needs Java applets to install and use and it will not use Safari. When I download IE from the web it will not install. How can I get a browser that will work on my MacAir for travel use of this program?

    I am trying to use and education program that needs Java applets and it will not run on Safari. IE will not install from the web. How do I get a browser that will work to install so I can use this program when I travel.

    Try using FireFox. IE will only run on a Mac if you run Windows on the Mac.
    Windows on Intel Macs
    There are presently several alternatives for running Windows on Intel Macs.
    Install the Apple Boot Camp software.  Purchase Windows 7 or Windows 8.  Follow instructions in the Boot Camp documentation on installation of Boot Camp, creating Driver CD, and installing Windows.  Boot Camp enables you to boot the computer into OS X or Windows.
    Parallels Desktop for Mac and Windows XP, Vista Business, Vista Ultimate, or Windows 7.  Parallels is software virtualization that enables running Windows concurrently with OS X.
    VM Fusion and Windows XP, Vista Business, Vista Ultimate, or Windows 7.  VM Fusion is software virtualization that enables running Windows concurrently with OS X.
    CrossOver which enables running many Windows applications without having to install Windows.  The Windows applications can run concurrently with OS X.
    VirtualBox is a new Open Source freeware virtual machine such as VM Fusion and Parallels that was developed by Solaris.  It is not as fully developed for the Mac as Parallels and VM Fusion.
    Note that Parallels and VM Fusion can also run other operating systems such as Linux, Unix, OS/2, Solaris, etc.  There are performance differences between dual-boot systems and virtualization.  The latter tend to be a little slower (not much) and do not provide the video performance of the dual-boot system. See MacTech.com's Virtualization Benchmarking for comparisons of Boot Camp, Parallels, and VM Fusion. A more recent comparison of Parallels, VM Fusion, and Virtual Box is found at Virtualization Benchmarks- Parallels 10 vs. Fusion 7 vs. VirtualBox. Boot Camp is only available with Leopard and later. Except for Crossover and a couple of similar alternatives like DarWine you must have a valid installer disc for Windows.
    You must also have an internal optical drive for installing Windows. Windows cannot be installed from an external optical drive.

  • I am a new iPhone 4s owner. I have a tone in iTunes that I downloaded from the web as a m4r file. Why won't it sync to my iPhone so I can set it as a ringtone.

    I am a new iPhone 4s owner. I have a tone in iTunes that I downloaded from the web as a m4r file. Why won't it sync to my iPhone so I can set it as a ringtone?
    Lois

    Yes, the tone is available and checked in iTunes under the Tones library.
    Yes, it is also listed under the Tones tab for my iPhone, but it is grayed out.
    Yes, tones are selected under "sources" in General Preferences, along with everything else.
    SyncTones was NOT selected under the Tones tab for my iPhone. I did so and it synced.
    Thanks for your help!
    Lois

  • Lately pdf files from the Web do not display properly; what is wrong and how can I fix it so I don't have to use IE?

    I am a professor and frequently need to open pdfs of academic journal articles from electronic databases. Within the last two or three weeks, when I try to do this using Firefox, only the first page of the pdf displays and the rest are blank. In addition, a bar appears across the top with the message "This pdf file may not display properly." So I have had to switch to Internet Explorer to open the files and do my research. What is going on and how can I fix it so I can open pdf files from the Web in Firefox and have them display properly?

    My question is simple - why would you put an application in production that has a lot of bugs? To replace a good and steady Adobe product? My customers will believe that I put a pathetic fallible form online. They are not sophisticated on computers so I just tell them to use IE. Ugh
    I must agree with pgwebgirl!

Maybe you are looking for