1.

Solve : Rename nearly 21k files according to XML File?

Answer»

Hi Everyone,

Just found this forums and have a problem that I hope someone can resolve for me.

I have a large collection of music which I have been using on a media centre for a while now, but its time to upgrade and update to a newer player, and thats the problem, the old player appears to have RIPPED CD's to the hard drive but named them funny and stored the correct name details and metadata in an XML, so when I now look at the new player I get file name such as AD1346.mp3 instead of the song name which with so many songs is impossible to go through manually.

XML File is like:-


13046

the 13046 is the file name but in reallity the file is called A0013046.mp3

I am looking for somesort of way of getting a rename program to look at this XML, update the filename and metadata to the correct format for a media player

Any Idea's would be greatly appreciated

Chris

Microsoft supplies an object which allows you to extract the information from an XML file. You will need to use VBScript.

Code: [Select]Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.load("c:\temp\Songs.xml")

Set colNodes = xmlDoc.getElementsByTagName("Song")
For Each node In colNodes
Set objNamedNodeMap = node.attributes
artist = objNamedNodeMap.getNamedItem("Artist").text
title = objNamedNodeMap.getNamedItem("Title").text
srchArtist = objNamedNodeMap.getNamedItem("SearchArtist").text
srchTitle = objNamedNodeMap.getNamedItem("SearchTitle").text
style = objNamedNodeMap.getNamedItem("Styles").text

For Each child In xmlDoc.documentElement.childNodes
filename = xmlDoc.getElementsByTagName("Audio").item(0).text
Next

WScript.Echo "Artist-" & artist
WScript.Echo "Title-" & title
WScript.Echo "Srch Artist-" & srchArtist
WScript.Echo "Srch Ttirle-" & srchTitle
WScript.Echo "Style-" & style
WScript.Echo "Filename-" & "AD" & filename
Next

The snippet is simply a template. It is based on the information that was posted. It might need tweaking if the XML file has more nodes than posted. I put your song xml data into a file called songs.xml for testing purposes.

There is also a downloadable object named CDDBControl.dll (Google can find it) that can be used to extract the metadata from the music files. Assuming the metadata was updated, this could be used in a Vbscript not using the xml file.

Good luck.


Hi,

Sorry I think I have been missunderstood, the XML File already exists with this data, the problem is that the music files as they are do not include this info, ithey are named things like AD00001.wma, the progeam I have then looks at the XML file to get the artist data etc.

I am looking for a way to reverse this so need something to look at the XML file to get the information, then inject it into the appropriate music file, something like:-

It looks into the XML File and get this:-


13046

Then with this info it looks for music file called AD0013046.wma and renames to artist-song.wma and injects the info also into the file properties for it if this makes sence.

The details in the XML are as above for them music, is it was a small amount I would have done manually, but with 21k I was thinking there has to be a better way

Thanks.1. What is it you want help with, parsing the xml file, or "injecting" the metadata into the wma file? (do you mean tagging it?) Or both?

2. How was the xml file produced? By some program? What is its name?

3. Is each music file associated with 2 lines in the xml file thus:

[line 1]
[line 2] 13046


Hi,

I have the XML Data with all the names and music info layed out as


13046

There are currently 21k files named AD00001.wma up to just below 21k which as missing this info, what I am looking to do is take the information from this XML file and inject it into the music files.

I am looking to use a program called Media Maestro LSX which Can take info from Media Player and Itunes to create a home jukebox, but as it stands media player does not know what these music files are due to the data being held in seperate files, so I need a way to get this info back into the files.

ThanksQuote from: chrism on November 20, 2011, 05:01:33 AM

it looks for music file called AD0013046.wma

It was an .mp3 file before!

Hi,

Sorry yes, MP3 was a mistake, they are all .wma filesThis was difficult because no parent node was shown in the sample XML. So I MADE one up called Music.

There was also an error in the original script which has been corrected. Also the rename logic has been added. The script rename the AD files on disk using a combination of the artist and title name. The files are renamed on the disk. If you need to update the ID3 tag info let us know.

Sample Test Data:
Code: [Select]<?xml version="1.0" encoding="utf-8"?>
<Music>
<Song Artist="artist here " Title="thesongname here" SearchArtist="artist name" SearchTitle=" title" Styles="70s">
<Audio>13046</Audio>
</Song>
<Song Artist="Traffic" Title="The Low Spark Of High Heeled Boys" SearchArtist="Traffic" SearchTitle="The Low Spark Of High Heeled Boys" Styles="70s">
<Audio>66666</Audio>
</Song>
<Song Artist="Beatles" Title="Beatles VI" SearchArtist="Beatles" SearchTitle="Beatles VI" Styles="60s">
<Audio>45678</Audio>
</Song>
</Music>

The is the new script:
Code: [Select]Set xmlDoc = CreateObject("Microsoft.XMLDOM")
Set fso = CreateObject("Scripting.FileSystemObject")

xmlDoc.async = False
xmlDoc.load("c:\temp\Songs.xml")

Set colNodes = xmlDoc.getElementsByTagName("Music/Song")
For Each node In colNodes

Set colAttrib = node.attributes
artist = colAttrib.getNamedItem("Artist").text
title = colAttrib.getNamedItem("Title").text
srchArtist = colAttrib.getNamedItem("SearchArtist").text
srchTitle = colAttrib.getNamedItem("SearchTitle").text
style = colAttrib.getNamedItem("Styles").text

filename = "AD" & xmlDoc.getElementsByTagName("Audio").item(i).text & ".wma"

WScript.Echo "Artist-" & artist
WScript.Echo "Title-" & title
WScript.Echo "Srch Artist-" & srchArtist
WScript.Echo "Srch Title-" & srchTitle
WScript.Echo "Style-" & style
WScript.Echo "Filename-" & filename
WScript.Echo"--------------------------------------------"

Set f = fso.GetFile(filename)
f.Name = artist & "-" & title & ".wma"
i=i+1
Next

Save this into the same folder where the songs and XML file live. Save with a VBS extension and RUN as cscript scriptname.vbs There might be some excessive code in the script. It will not harm anything.

Recommend you test this out in a test directory before going live. Testing turned up no errors.


Please help
(1) i have one xml with lots many tags
(2) i have many audio files with random generated number as a name and that name is in XML file
(3) please tell me how can i rename those audio files with one of tag details present in xml file. i have to search that audio file as the name of the audio file is present in xml and under that section i will use one of the tag to rename it

example
-
-
Gambardella, Matthew
XML Developer's Guide
Computer
44.95
2000-10-01
An in-depth look at creating applications with XML.

-
Ralls, Kim
Midnight Rain
Fantasy
5.95
2000-12-16
A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.

-
Corets, Eva
Maeve Ascendant
Fantasy
5.95
2000-11-17
After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society.

-
Corets, Eva
Oberon's Legacy
Fantasy
5.95
2001-03-10
In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant.

-
Corets, Eva
The Sundered Grail
Fantasy
5.95
2001-09-10
The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy.

-
Randall, Cynthia
LOVER Birds
Romance
4.95
2000-09-02
When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled.

-
Thurman, Paula
Splish Splash
Romance
4.95
2000-11-02
A deep sea diver finds true love twenty thousand leagues beneath the sea.

-
Knorr, Stefan
Creepy Crawlies
Horror
4.95
2000-12-06
An anthology of horror stories about roaches, centipedes, scorpions and other insects.

-
Kress, Peter
Paradox Lost
Science Fiction
6.95
2000-11-02
After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum.

-
O'Brien, Tim
Microsoft .NET: The Programming Bible
Computer
36.95
2000-12-09
Microsoft's .NET initiative is explored in detail in this deep programmer's reference.

-
O'Brien, Tim
MSXML3: A Comprehensive Guide
Computer
36.95
2000-12-01
The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more.

-
Galos, Mike
Visual Studio 7: A Comprehensive Guide
Computer
49.95
2001-04-16
Microsoft Visual Studio 7 is explored in depth, looking at how Visual Basic, Visual C++, C#, and ASP+ are integrated into a comprehensive development environment.



(a)audio file name is >> bk101.mov which is defined as a book id in xml file , now i want to change it to computer.wav (which is in genre tag under book id tag of bk101)

thank you You revived a 4 year old thread. You need to start your own thread.


Discussion

No Comment Found