Copy To Others

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

Risser
Posts: 184
Joined: Thu Mar 03, 2005 11:28 am

Copy To Others

Post by Risser »

Alrighty, I've recently had a few instances where I had new MP3s that replaced old MP3s, and I got tired of copying all the info from the old to the new. Thus, I created this cheap-o "copy to others" script to do it for me.

How it works is, you select the track you want as the original, and hit "Copy To Others". The script searches for any track with the same artist and song title (so, yes, you have to do that much yourself, and they must be exactly the same). Then it shows you a window with the differences highlighted so you don't accidentally overwrite something important to you. Then, when you hit OK, it writes 'em.

It doesn't do album art. But for me that's not such a big deal, as you can just open the art on the old one, select Apply to All Tracks on Album and the art will update itself after you've finished your copying.

Um, what else. Oh yeah. One track at a time. I could have probably made it handle multiple tracks, but I'm out of time and it's easier for me to hit "copy to others" 12 times than to work more on the script.

Anyway, it'll do.

Peter
Risser
Posts: 184
Joined: Thu Mar 03, 2005 11:28 am

Post by Risser »

Code: Select all

' Version 20070320

Option Explicit

Dim res

Public hold
Set hold = CreateObject("Scripting.Dictionary")

Const mmAnchorRight = 4
Const mmAnchorBottom = 8
Const mmAlignTop = 1
Const mmAlignBottom = 2
Const mmAlignClient = 5
Const mmListDropdown = 2
Const mmFormScreenCenter = 4

Dim trackList

Function fixit(s)
    fixit = Replace(s, "'", "''")
End Function

Function match_clause(original)
	match_clause = " artists.artist = '"&fixit(original.artistName)&"' AND " & _
				   " songs.IdArtist = artists.id AND songs.songtitle = '"&fixit(original.title)&"'" & _
				   " AND NOT (songs.id = "&original.id&")"
End Function


Sub CloseDown
	Set hold = nothing
	SDB.Objects("StatusThingy") = Nothing
	SDB.Objects("original") = Nothing
End Sub

Sub OnCancel(Btn)
	CloseDown
End Sub

Sub OnOK(Btn)
	Set hold  = SDB.Objects("hold")
	Dim original : Set original = SDB.Objects("original")

	Dim itm

	For Each itm In hold
		itm.artistName = original.artistName
		itm.title = original.title
		itm.albumName = original.albumName
		itm.albumArtistName = original.albumArtistName
		itm.year = original.year
		itm.trackOrder = original.trackOrder
		itm.genre = original.genre
		itm.rating = original.rating
		itm.involvedPeople = original.involvedPeople
		itm.originalArtist = original.originalArtist
		itm.originalTitle = original.originalTitle
		itm.originalYear = original.originalYear
		itm.lyricist = original.lyricist
		itm.originalLyricist = original.originalLyricist
		itm.bpm = original.bpm
		itm.isrc = original.isrc
		itm.publisher = original.publisher
		itm.copyright = original.copyright
		itm.encoder = original.encoder
		itm.author = original.author
		itm.comment = original.comment
		itm.lyrics = original.lyrics
		itm.custom1 = original.custom1
		itm.custom2 = original.custom2
		itm.custom3 = original.custom3
		itm.tempo = original.tempo
		itm.occasion = original.occasion
		itm.mood = original.mood
		itm.quality = original.quality

		If itm.ID>-1 Then
			itm.UpdateDB
		End If
		itm.WriteTags
	Next 'itm	
	
	CloseDown
End Sub

Function MapXML(original)
	Dim out
	out = Replace(original, "&", "&")
	out = Replace(out, "  ", "  ")
	out = Replace(out, "<", "<")
	out = Replace(out, ">", ">")
	Dim i
	i=1
	While i<=Len(out)
		If (AscW(Mid(out, i, 1))>127) Then
			out = Mid(out, 1, i-1)+"&#"+CStr(AscW(Mid(out, i, 1)))+";"+Mid(out, i+1)
		End If
		i=i+1
	WEnd
	MapXML = out
End Function

Function tooBig(s)
	If (Len(s) > 50) Then
		tooBig = Left(s,47) & "..."
	Else
		tooBig = s
	End If
End Function

Function outField (fixed, normal)
	If fixed = normal Then
		outField = "<td>" & MapXML(tooBig(normal)) & "</td>" & vbcrlf
	Else
		outField = "<td class=""highlight"">" & MapXML(tooBig(normal)) & "</td>" & vbcrlf
	End If
'res = SDB.MessageBox(fixed&"->"&normal&"="&outField, mtError, Array(mbOk))	
End Function


Sub CopyToOthers
	Dim UI, Form, Foot, Btn, Btn2, WB, doc
	
	Dim writeChanges

	Set trackList = SDB.SelectedSongList
	If trackList.count=0 Then
		Set trackList = SDB.AllVisibleSongList
	End If

	Set trackList = SDB.SelectedSongList
	If trackList.count = 0 Then
		res = SDB.MessageBox("Select a track.", mtError, Array(mbOk))
		Exit Sub
	End If
	
	If trackList.count > 1 Then
		res = SDB.MessageBox("Select only a single track.", mtError, Array(mbOk))
		Exit Sub
	End If

	dim original : Set original = trackList.Item(0)
	dim SELECT_Clause, FROM_Clause, WHERE_Clause, SQL, Iter
    SELECT_Clause = " SELECT Songs.Id "
    FROM_Clause = " FROM Songs, Artists "
    WHERE_Clause = " WHERE " & match_clause(original)
'    WHERE_Clause = " WHERE artists.artist = '"&fixit(original.artistName)&"' AND " & _
'    			   " songs.IdArtist = artists.id AND songs.songtitle = '"&fixit(original.title)&"'" & _
'    			   " AND NOT (songs.id = "&original.id&")"
    SQL = SELECT_Clause & FROM_Clause & WHERE_Clause
	Set Iter = SDB.Database.OpenSQL(SQL)
	If Iter.EOF Then
		res = SDB.MessageBox("No other matches were found for this song.", mtError, Array(mbOk))
		Exit Sub
	End If

	Set UI = SDB.UI

	' Create the window to be shown
	Set Form = UI.NewForm
	Form.Common.SetRect 50, 50, 500, 400
	Form.Common.MinWidth = 200
	Form.Common.MinHeight = 150
	Form.FormPosition = mmFormScreenCenter
	Form.SavePositionName = "CaseWindow"
	Form.Caption = SDB.Localize("Copy To Others")
	Form.StayOnTop = True

	' Create a panel at the bottom of the window
	Set Foot = UI.NewPanel(Form)
	Foot.Common.Align = mmAlignBottom
	Foot.Common.Height = 35

	' Create a button that closes the window
	Set Btn = UI.NewButton(Foot)
	Btn.Caption = SDB.Localize("&Cancel")
	Btn.Common.SetRect (Foot.Common.Width - 180)/2+95, 9, 85, 24
	Btn.Common.Anchors = mmAnchorRight + mmAnchorBottom
	Btn.UseScript = Script.ScriptPath
	Btn.OnClickFunc = "OnCancel"

	' Create a button that saves the report
	Set Btn2 = UI.NewButton(Foot)
	Btn2.Caption = SDB.Localize("&OK")
	Btn2.Common.SetRect (Foot.Common.Width - 180)/2, 9, 85, 24
	Btn2.Common.Anchors = mmAnchorRight + mmAnchorBottom
	Btn2.UseScript = Script.ScriptPath
	Btn2.OnClickFunc = "OnOK"

	Set WB = UI.NewActiveX(Form, "Shell.Explorer")
	WB.Common.Align = mmAlignClient      ' Fill all client rectangle
	WB.Common.ControlName = "WB"

	Set doc = WB.Interf.Document

	Form.Common.Visible = True                ' Only show the form, don't wait for user input
	SDB.Objects("StatusThingy") = Form  ' Save reference to the form somewhere, otherwise it would simply disappear

	doc.write BuildReport
	doc.close
	SDB.Objects("original") = original
End Sub

Function showRow(original, itm)
	dim strOut
	dim firstLine
	If original.id = itm.id Then
		firstLine = "ORIGINAL:<br>"
	Else
		firstLine = "<br>"
	End If
	strOut = strOut & "<tr class=dark><td colspan=1000><font size=""1""><b>"&firstLine&itm.path & "</b></font></td></tr>" & vbcrlf
	strOut = strOut & "      <tr>" & vbcrlf
	strOut = strOut & outField(original.artistName, itm.artistName)
	strOut = strOut & outField(original.title, itm.title)
	strOut = strOut & outField(original.albumName, itm.albumName)
	strOut = strOut & outField(original.albumArtistName, itm.albumArtistName)
	strOut = strOut & outField(original.year, itm.year)
	strOut = strOut & outField(original.trackOrder, itm.trackOrder)
	strOut = strOut & outField(original.genre, itm.genre)
	strOut = strOut & outField(original.rating, itm.rating)
	strOut = strOut & outField(original.involvedPeople, itm.involvedPeople)
	strOut = strOut & outField(original.originalArtist, itm.originalArtist)
	strOut = strOut & outField(original.originalTitle, itm.originalTitle)
	strOut = strOut & outField(original.originalYear, itm.originalYear)
	strOut = strOut & outField(original.lyricist, itm.lyricist)
	strOut = strOut & outField(original.originalLyricist, itm.originalLyricist)
	strOut = strOut & outField(original.bpm, itm.bpm)
	strOut = strOut & outField(original.isrc, itm.isrc)
	strOut = strOut & outField(original.publisher, itm.publisher)
	strOut = strOut & outField(original.copyright, itm.copyright)
	strOut = strOut & outField(original.encoder, itm.encoder)
	strOut = strOut & outField(original.author, itm.author)
	strOut = strOut & outField(original.comment, itm.comment)
	strOut = strOut & outField(original.lyrics, itm.lyrics)
	strOut = strOut & outField(original.custom1, itm.custom1)
	strOut = strOut & outField(original.custom2, itm.custom2)
	strOut = strOut & outField(original.custom3, itm.custom3)
	strOut = strOut & outField(original.tempo, itm.tempo)
	strOut = strOut & outField(original.occasion, itm.occasion)
	strOut = strOut & outField(original.mood, itm.mood)
	strOut = strOut & outField(original.quality, itm.quality)
	strOut = strOut & "      </tr>" & vbcrlf
	showRow = strOut
End Function

Function BuildReport
	Dim original : Set original = trackList.Item(0)
	Dim strOut : strOut = ""

	strOut = strOut & "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbcrlf
	strOut = strOut & "<html>" & vbcrlf
	strOut = strOut & "  <head>" & vbcrlf
	strOut = strOut & "    <title>" & SDB.Localize("Copy To Others") & "</title>" & vbcrlf
	strOut = strOut & "  </head>" & vbcrlf

	strOut = strOut & "<STYLE TYPE=text/css>" & vbcrlf
	strOut = strOut & "body{font-family:'Verdana',sans-serif; background-color:#FFFFFF; font-size:9pt; color:#000000;}" & vbcrlf
	strOut = strOut & "H1{font-family:'Verdana',sans-serif; font-size:13pt; font-weight:bold; color:#AAAAAA; text-align:left}" & vbcrlf
	strOut = strOut & "P{font-family:'Verdana',sans-serif; font-size:8pt; color:#000000;}" & vbcrlf
	strOut = strOut & "TH{font-family:'Verdana',sans-serif; font-size:9pt; font-weight:bold; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:3px;}" & vbcrlf
	strOut = strOut & "TD{font-family:'Verdana',sans-serif; font-size:8pt; color:#000000; border-color:#000000; border-style: solid; border-left-width:1px; border-right-width:0px; border-top-width:1px; border-bottom-width:1px;}" & vbcrlf
	strOut = strOut & "TD.highlight{font-family:'Verdana',sans-serif; font-size:8pt; background-color:#FFFF77; color:#000000; border-color:#000000; border-style: solid; border-left-width:1px; border-right-width:0px; border-top-width:1px; border-bottom-width:1px;}" & vbcrlf
	strOut = strOut & "TD.highlighter{font-family:'Verdana',sans-serif; font-size:8pt; background-color:#FFFFCC; color:#000000; border-color:#000000; border-style: solid; border-left-width:1px; border-right-width:0px; border-top-width:1px; border-bottom-width:1px;}" & vbcrlf
	strOut = strOut & "TR.dark{background-color:#EEEEEE}" & vbcrlf
	strOut = strOut & "TR.aleft TH{text-align:left}" & vbcrlf
	strOut = strOut & "</STYLE>" & vbcrlf

	strOut = strOut & "  <body>" & vbcrlf
	strOut = strOut & "    <H1>" & SDB.Localize("Copy To Others:") & "</H1>" & vbcrlf
	strOut = strOut & "    <table border=""1"" cellspacing=""0"" cellpadding=""4"" width=""2400"">" & vbcrlf

	strOut = strOut & showRow(original, original)

	dim Iter, itm

	Set Iter = SDB.Database.QuerySongs(" AND "&match_clause(original))
	While Not Iter.EOF
		Set itm = Iter.Item

		strOut = strOut & showRow(original, itm)
		hold.add itm, itm

		Iter.Next
	Wend
	SDB.Objects("hold") = hold
	
	strOut = strOut & "    </table>" & vbcrlf
	strOut = strOut & "  </body>" & vbcrlf
	strOut = strOut & "</html>" & vbcrlf
	BuildReport = strOut
End Function
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

Cool!
Nice to see you again Risser.
You might want to take a look at my duplicate script, link in my signature, with which you can move playhistory, playcount, dateadded and playlist entries between duplicate tracks. It could be of interest.
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

Wow, you're back :D
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
rovingcowboy
Posts: 14163
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Post by rovingcowboy »

it maybe a picky question but does your script ignore the time and the size when it copys the from old to the new.

i have found some songs i redid
from new cdroms had a longer time on them and the size was also larger because of the longer time.

which is why i am wondering this about your script.? :-?
roving cowboy / keith hall. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy A51 5G Android ) 6. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.
Risser
Posts: 184
Joined: Thu Mar 03, 2005 11:28 am

Post by Risser »

There is no check for old or new. It simply looks at the one you have selected and copies the information to every other song that has the exact same Artist and Title.

So, if you select the old, shorter one and select copy to others, it will copy to the new longer one, plus any others that have the same Artist and Title. So, if you have live versions, or versions from different albums, and they are labeled the same, it will copy to those as well. That's why it shows you what it's about to do before it does it.

Like I said, it's cheap, but it does exactly what I need. 8)

Also, right now it doesn't copy stats, like last played, added or playcount, because I don't particularly care about those things. It could be easily updated to include those though.

Peter
rovingcowboy
Posts: 14163
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Post by rovingcowboy »

okay thanks i just did not want to go willy nilly through the script and do all the songs thinking it was doing fine and later find out that it messed up the newer versions by putting the older versions size and time lenght on the new ones.

so it is nice to know i need to watch that first, before i do all the songs. 8)
roving cowboy / keith hall. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy A51 5G Android ) 6. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.
Risser
Posts: 184
Joined: Thu Mar 03, 2005 11:28 am

Post by Risser »

Actually, time & length isn't a problem anyway, because it's intrinisic to the file, not part of the tags. I couldn't change that without actually physically changing the length of the file.

Peter
MCSmarties
Posts: 251
Joined: Tue Dec 06, 2005 8:01 pm

Hmmm...

Post by MCSmarties »

Hey Risser, thanks a lot for tackling the tag-transfer problem!
I'll be sure to test-drive your script this weekend.

If I may say, it seems to me that your script does almost the same as Maaspuck's CopyTags". Maybe you two should think about pairing up?

You're approaching the same subject from different angles, with specific advantages and problems, so a mix of both is bound to make an awesome script... just my 2c.

Unless of course both of you prefer the stimulus of fierce competition! :D
Post Reply