Lyricsplugin Search Script

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Guest

Post by Guest » Thu Feb 28, 2008 5:32 pm

Yes, a batch lyric download would be a major plus, instead of doing each song one by one on the auto-tag screen. It will eliminate the switching of the search source as well when tagging.

Cool script as it is- thanks!

das Monkey
Posts: 70
Joined: Tue Feb 12, 2008 7:11 pm

Post by das Monkey » Fri Feb 29, 2008 5:15 pm

Whoops. I just wrote my own fix for the delay on this thing only to see someone else did the same thing already and posted it in this thread. :) Anyway, I wrote mine on whether lyrics was populated and noticed that lyrics is always an object, so IsObject(lyrics) is true whether it has accessible data or not. Future work on this code may want to use something like "NOT(lyrics IS Nothing)". Something to consider.

If I can find the time, I may start messing around with a batch lyric updater as well.

das

das Monkey
Posts: 70
Joined: Tue Feb 12, 2008 7:11 pm

Post by das Monkey » Fri Feb 29, 2008 6:05 pm

OK, I gave it a shot. The right events and methods don't seem to be exposed to do this properly, and you can't even display lyrics in the track listing to know if you got it right. In fact, this is almost certainly not the correct interface to use for batch lyric updating ... but I did it anyway. :) It's a heck of a lot quicker to code this than write something as involved as the Batch Album script.

Anyway, here's the code. You should probably backup your database (twice ;) ) since I've only been messing around with this for about ... well, since my last post 45 minutes ago. And maybe 2 of those minutes were spent testing it. This code is most certainly a "hack", and you may want to stick to just doing an album at a time until we see how this reacts to large file lists. Essentially, all I did was force the search dropdown to loop through every file and store the lyrics one-by-one. Depending on your connection speed, it should go rather quickly (and if you have the sounds turned on, you'll hear quite a bit of page-load clicking). When it's done, all the tracks will be automatically checked. There's no way I could see to preview what's going to happen when you click Auto-Tag, so there's some faith involved here, but it seems to work OK.

Proceed with caution :D

Code: Select all

Dim Browser
Dim Tmr
Dim Current
Dim ResultCounter
Dim TryAgain

Sub StartSearch(Panel, SearchTerm, SearchArtist, SearchAlbum)
		TryAgain = 0
		Set Browser = SDB.UI.NewActiveX(Panel, "Shell.Explorer")
		Browser.Common.Align = 5
		
		Dim Tracks : Set Tracks = SDB.Tools.WebSearch.NewTracks
		Dim Results : Set Results = SDB.NewStringList

		For i = 0 to Tracks.Count-1
			Results.Add Tracks.item(i).ArtistName & " - " & Tracks.item(i).Title
		Next
		
		SDB.Tools.WebSearch.SetSearchResults Results
		If Results.Count > 0 Then
			ResultCounter = 0
			SDB.Tools.WebSearch.ResultIndex = ResultCounter
		End If
End Sub

Sub ShowResult(ResultID)
     If (ResultID >= 0)  Then
          Browser.SetHTMLDocument ""

          With SDB.Tools.WebSearch
             .TrackChecked(ResultID) = True
             title = .NewTracks.Item(ResultID).Title
             artist = .NewTracks.Item(ResultID).ArtistName
          End With
         
					Dim pos :	pos = InStr(artist, ";")
					If pos > 1 Then
						artist = Mid(artist, 1, pos - 1)
					End If
          
          url = "http://www.lyricsplugin.com/plugin/?title=" & Escape(title) & "&artist=" & Escape(artist)
          Browser.Interf.Navigate url
         
          Set Tmr = SDB.CreateTimer(40)
          Script.RegisterEvent Tmr, "OnTimer", "WebsiteLoaded"
     End If
End Sub

Sub WebsiteLoaded(Timer)
		Script.UnregisterEvents Tmr
		Set Tmr = Nothing

		If Len(Browser.Interf.LocationURL) < 10 Then ' A trick - wait until navigation to the search results page starts
			Set Tmr = SDB.CreateTimer(40)
			Script.RegisterEvent Tmr, "OnTimer", "WebsiteLoaded"
			Exit Sub
		End If
		
		If Browser.Interf.ReadyState = 1 Or Browser.Interf.Busy Then
			Set Tmr = SDB.CreateTimer(40)
			Script.RegisterEvent Tmr, "OnTimer", "WebsiteLoaded"
			Exit Sub
		End If

     Dim Doc : Set Doc = Browser.Interf.Document
     If IsObject(Doc) Then
          Set lyrics = Doc.getElementById("lyrics")
          If Not(lyrics IS Nothing) Then
          	If lyrics.innerText = "" Then
          		Dim NewTitle : NewTitle = SDB.Tools.WebSearch.NewTracks.Item(ResultCounter).Title
          		Dim NewArtist : NewArtist = SDB.Tools.WebSearch.NewTracks.Item(ResultCounter).ArtistName
		         
          		If TryAgain > 0 Or (InStr(NewTitle, "(") = 0 And InStr(NewTitle, "[") = 0) Then
          			TryAgain = 0
          		Else
          			TryAgain = 1

								Dim pos : pos = 0
								pos = InStr(NewTitle, "(")
								If pos > 1 Then
									NewTitle = Mid(NewTitle, 1, pos - 1)
								End If
								pos = InStr(NewTitle, "[")
								If pos > 1 Then
									NewTitle = Mid(NewTitle, 1, pos - 1)
								End If
								NewTitle = LTrim(RTrim(NewTitle))
								
			          Browser.SetHTMLDocument ""
			
			          url = "http://www.lyricsplugin.com/plugin/?title=" & Escape(NewTitle) & "&artist=" & Escape(NewArtist)
			          Browser.Interf.Navigate url

			          Set Tmr = SDB.CreateTimer(40)
			          Script.RegisterEvent Tmr, "OnTimer", "WebsiteLoaded"
			          Exit Sub
          		End If
          	End If
          	TryAgain = 0
						SDB.Tools.WebSearch.NewTracks.Item(ResultCounter).Lyrics = lyrics.innerText
						If ResultCounter < SDB.Tools.WebSearch.NewTracks.Count - 1 Then
							ResultCounter = ResultCounter + 1
							SDB.Tools.WebSearch.ResultIndex = ResultCounter
						End If
          End If
     End If
End Sub

Sub FinishSearch(Panel)
		Browser.Common.DestroyControl     
		Set Browser = Nothing             
End Sub
Edit: For fun, I threw in a second-chance routine. If it finds no lyrics and has a "(" or "[" somewhere other than the beginning of the track title, it tries a second time truncating the parenthetical. This works for most "live" or "acoustic" or "featuring" or whatever. It's possible this will find some false positives, but keep in mind that it only does it if it can't find lyrics otherwise, and it's still searching by artist. The false positive rate is likely extremely low.

Also, if there's an ampersand in the artist or title, the url string gets muddled, so I replace them with the word "and". The plugin server seems to respond more favorably that way.


das
Last edited by das Monkey on Sat Mar 01, 2008 11:17 am, edited 2 times in total.

drjboulder
Posts: 1119
Joined: Mon Apr 09, 2007 12:03 am
Location: Boulder, Colorado, USA

Post by drjboulder » Fri Feb 29, 2008 10:06 pm

Thanks Das!!!
Worked like a charm for me. :P
Not to worried about the accuracy aspect of auto tagging in bulk. The success rate with the LyricsPlugin is so high that I would imagine very few will get tagged wrong. And if a few do get the wrong lyric, its is no big deal to just fix them as they are encountered in normal Monkey usage.
Thanks, again.
D Rock
Image
MediaMonkeyGoldv3.0.3.1183
Vista Home Basic|4thGen 20GPod
Zune Small Player Skin w/ Aqua 4 Player Mod
Backup | Last FM Node | Scrobbler DJ | TopTracks | StayInSameStyleDJ
RadioDJ | RadioFreeMonkey | PrettyPictures | MiniLyricsEmbedder
LyricsViewer | Lyricator | LyricsPlugin | VisualizationEmbedder | MonkeyRok
RightClickForWeb | WebSearchPanels | WebNodes | MagicNodes | FavoritesNodes
NowPlayingArtNode |AutoRateAccurate | TaggingInconsistencies
AdvancedDuplicateFind&Fix | CaseModify | PlayHistory&Stats | Etc...

nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Post by nynaevelan » Fri Feb 29, 2008 10:12 pm

The plugin is working like a charm for me also. I have one small question, does the original or the modified script take into account multiple artists which are separated by a ';'? If not, is there a way for the script to only query based on the first artist? I have over a 1000 that no site can find and over 90% of them are due to the multiple artists.

Nyn
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files

das Monkey
Posts: 70
Joined: Tue Feb 12, 2008 7:11 pm

Post by das Monkey » Fri Feb 29, 2008 10:40 pm

drjboulder, happy to help. I just ran it on a batch of a few thousand tracks, and aside from a brief clog trying to change all those tags at once, it ran surprisingly smoothly.

nynaevelan, I tweaked the code a little bit for you (recopy it from the post above). I can't think of a single case where the artist name will legitimately have a semi-colon in it and only be found if it's included, so I didn't bother with a "try again" approach. I just truncate the artist name at the first semi-colon regardless. It may not solve all your problems, but it should snag more than a few and is unlikely to break anything else.

All my files are tagged now, so my motivation factor is significantly less :), but if I get some time, maybe I'll write a brute force search that tries every artist in the list until if finds something.

Let me know if the change I made has helped. If not, we can try another approach.

das

nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Post by nynaevelan » Fri Feb 29, 2008 11:02 pm

Hi Das:

It's working, it was able to find over 200 that it wasn't finding before but I have a lot of manual work ahead of me, but I'm a lot closer, thanks for the update. :P

Nyn
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files

Guest

Post by Guest » Fri Feb 29, 2008 11:57 pm

I'm the guest from the top post on the page- thanks for the revised code! Works great.
Thanks

MeMeMe
Posts: 263
Joined: Fri Dec 23, 2005 11:42 am
Location: In front of my computer

Post by MeMeMe » Sat Mar 01, 2008 12:11 am

There's a script somewhere on the forum called EvilTagger. It was a batch lyrics tagger. I mention it because it was once used a lot, so is well-tested. It was written for MM 2, but it might be worth checking it out to see if it has any techniques that could make the above script even better.

spacefish
Posts: 1427
Joined: Mon Jan 14, 2008 7:21 am
Location: Denmark

Post by spacefish » Sat Mar 01, 2008 1:13 am

das Monkey wrote:OK, I gave it a shot.
Alright that is just awesome! Thanks so much. 8)
Image
MM Gold 3.0.3.1183 : Vista HP SP1 (x86) : Zen Stone (2GB)
Zekton: An original MM3 skin by Eyal.
Scripts in Use: Add/Remove PlayStat | Auto Album DJ | AutoRateAccurate | Backup
Case & Leading Zero Fixer | Classification & Genre Changer | Clean Scripts.ini | Clear
Field | Custom Report | Discogs Auto-Tag Web Search | Forget Crossfade | Invert
Selection/Select None | Last 100... | Lyricator | Lyrics to Instrumental | MonkeyRok
MusicBrainz Tagger | My Custom Nodes | Now Playing Art Node | Play History & Stats
Right Click for Reports | Right Click for Scripts | Right Click for Web | Stop After Current
WebNodes

spacefish
Posts: 1427
Joined: Mon Jan 14, 2008 7:21 am
Location: Denmark

Post by spacefish » Sat Mar 01, 2008 3:08 am

I think I found a glitch:

I just tried to tag Bob Dylan - Masterpieces but when it got to Rainy Day Women #12 & 35 the script stalled and I couldn't tag any of the ones previously found. I went back and selected everything but that track and it worked fine.
Image
MM Gold 3.0.3.1183 : Vista HP SP1 (x86) : Zen Stone (2GB)
Zekton: An original MM3 skin by Eyal.
Scripts in Use: Add/Remove PlayStat | Auto Album DJ | AutoRateAccurate | Backup
Case & Leading Zero Fixer | Classification & Genre Changer | Clean Scripts.ini | Clear
Field | Custom Report | Discogs Auto-Tag Web Search | Forget Crossfade | Invert
Selection/Select None | Last 100... | Lyricator | Lyrics to Instrumental | MonkeyRok
MusicBrainz Tagger | My Custom Nodes | Now Playing Art Node | Play History & Stats
Right Click for Reports | Right Click for Scripts | Right Click for Web | Stop After Current
WebNodes

drjboulder
Posts: 1119
Joined: Mon Apr 09, 2007 12:03 am
Location: Boulder, Colorado, USA

Post by drjboulder » Sat Mar 01, 2008 3:54 am

spacefish wrote:I think I found a glitch:

I just tried to tag Bob Dylan - Masterpieces but when it got to Rainy Day Women #12 & 35 the script stalled and I couldn't tag any of the ones previously found. I went back and selected everything but that track and it worked fine.
It stalled on "#" for me, also had some song titles with [*] that it did not like. Was working from an auto play list. So, I just edited play list to exclude those.
Managed to do about 1,700 songs. Still have around 800 with no lyrics.
:o Think that I shall not try synching my Ipod before work tomorrow!
D Rock
Image
MediaMonkeyGoldv3.0.3.1183
Vista Home Basic|4thGen 20GPod
Zune Small Player Skin w/ Aqua 4 Player Mod
Backup | Last FM Node | Scrobbler DJ | TopTracks | StayInSameStyleDJ
RadioDJ | RadioFreeMonkey | PrettyPictures | MiniLyricsEmbedder
LyricsViewer | Lyricator | LyricsPlugin | VisualizationEmbedder | MonkeyRok
RightClickForWeb | WebSearchPanels | WebNodes | MagicNodes | FavoritesNodes
NowPlayingArtNode |AutoRateAccurate | TaggingInconsistencies
AdvancedDuplicateFind&Fix | CaseModify | PlayHistory&Stats | Etc...

das Monkey
Posts: 70
Joined: Tue Feb 12, 2008 7:11 pm

Post by das Monkey » Sat Mar 01, 2008 10:06 am

Pounds are another query string key like the ampersand. Many of you probably know this already, but ampersands are used to indicate new elements in the list, and pounds are used to reference an anchor on the page. When I fixed the ampersand problem, I should have just fixed the pound too. It probably just needs to be replaced with an empty string. I'm not sure what the deal with the asterisk is. I'll take a look at it later today and post a fix.

drjboulder, could you post an example title/artist that isn't working right with the asterisk? Thanks.

das

das Monkey
Posts: 70
Joined: Tue Feb 12, 2008 7:11 pm

Post by das Monkey » Sat Mar 01, 2008 11:27 am

I tested a few combinations, and lyricsplugin.com seems able to handle the symbols, so I'm just escaping them in the url. Ampersands and pounds should work now. I'll mess around with a brute-force multi-artist script and see where that goes.

If anyone has scenarios that are not working, please post the specifics of the title/artist and how your tag is structured. I'm sure there are many scenarios I don't have in my collection and simply haven't thought of.

If anyone's interested, I also fixed Missing Lyrics Node to work with MM3 and added some code to ignore classical, film scores, podcasts, etc. I use the node in combination with this script to clean up my lyrics.

das

spacefish
Posts: 1427
Joined: Mon Jan 14, 2008 7:21 am
Location: Denmark

Post by spacefish » Sat Mar 01, 2008 1:36 pm

das Monkey wrote:Ampersands and pounds should work now.
Works, thanks!
Image
MM Gold 3.0.3.1183 : Vista HP SP1 (x86) : Zen Stone (2GB)
Zekton: An original MM3 skin by Eyal.
Scripts in Use: Add/Remove PlayStat | Auto Album DJ | AutoRateAccurate | Backup
Case & Leading Zero Fixer | Classification & Genre Changer | Clean Scripts.ini | Clear
Field | Custom Report | Discogs Auto-Tag Web Search | Forget Crossfade | Invert
Selection/Select None | Last 100... | Lyricator | Lyrics to Instrumental | MonkeyRok
MusicBrainz Tagger | My Custom Nodes | Now Playing Art Node | Play History & Stats
Right Click for Reports | Right Click for Scripts | Right Click for Web | Stop After Current
WebNodes

Post Reply