NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 80 81 82 83 84 … 93 Next »
itunes xml files

 
  • 0 Vote(s) - 0 Average
itunes xml files
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#1
2005-01-02, 06:48 AM
ok this question is for kingarglye (or anyone else who knows). im trying to write a method to read in a itunes xml file, which looks something like
[b Wrote:Quote[/b] ]<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1...">
<plist version="1.0">
<dict>
<key>Major Version</key><integer>1</integer>
<key>Minor Version</key><integer>1</integer>
<key>Application Version</key><string>4.6</string>
<key>Music Folder</key><string>file://localhost/E:/MP3s/</string>
<key>Library Persistent ID</key><string>B4B76FD9C797EE78</string>
<key>Tracks</key>
<dict>
<key>35</key>
<dict>
<key>Track ID</key><integer>35</integer>
<key>Name</key><string>Caramel Prisoner</string>
<key>Artist</key><string>Air</string>
<key>Album</key><string>10,000HZ Legend</string>
<key>Genre</key><string>Electronic</string>
<key>Kind</key><string>MPEG audio file</string>
<key>Size</key><integer>4770296</integer>
<key>Total Time</key><integer>298109</integer>
<key>Track Number</key><integer>11</integer>
<key>Date Modified</key><date>2004-01-19T19:20:45Z</date>
<key>Date Added</key><date>2003-10-17T17:51:51Z</date>
<key>Bit Rate</key><integer>128</integer>
<key>Sample Rate</key><integer>44100</integer>
<key>Play Count</key><integer>2</integer>
<key>Play Date</key><integer>-1112527749</integer>
<key>Play Date UTC</key><date>2004-11-04T18:59:07Z</date>
<key>Location</key><string>file://localhost/E:/MP3s/Air/10,000HZ%20Legend/11%20Caramel%20Prisoner.mp3/</string>
<key>File Folder Count</key><integer>4</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>
which i will store two values in a sortedarray. Key=35 which will be the key (dah), and object will be the file string. but since itunes doesnt use something like
<files>
<key>
<artist></artist>
<filename></filename>
</key>
</files>
so i cant use .getchildnodes for each Key node. which well is the only way i know to iterate thru a xml file.

so i have to test, if key = tracks. then read thru the <dict> and then key again then the dict again, then filename. just with the multiple key and dict tags makes this hard. like icant use
foreach xmlnode in getnode("dict/dict&quotWink.childnodes
blah blah blah
since the key is outside the dict tags.

after i have all the songs in a sorted array, theres another tag below which is <key>playlists</key>
which is similar to the tracks one, just refer to keys is all.

now does anyone know how the best way to read thru one of these files and build up this sorted array, once i have that method, the playlist method shud be just an alteration on that one.

cheers. reven.
jasonf
Offline

Member

Posts: 121
Threads: 7
Joined: Oct 2004
#2
2005-01-02, 01:48 PM
What a weird representation of data they chose to use.....

Anyways, the .NextSibling property of the XmlNode is probably going to be your friend here.  XPath too.

First, get a object for the <key>Tracks</key> node.  Then you can get the following <dict> node.

Sample code (not tested):
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
XmlNode keyTracks = doc.SelectSingleNode("/plist/dict/key[text()='Tracks']");

XmlNode dictTracks = null;
if (keyTracks != null)
  dictTracks = keyTracks.NextSibling;
[/QUOTE]

At this point, I'm assuming that the dict will have multiple tracks in it, so get a Node List of all of the &lt;key&gt; elements that are in the dict, and then you can use NextSibling to get the &lt;dict&gt; element for each track.

Sample code (not tested):
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
XmlNodeList tracks = dictTracks.SelectNodes("key");

foreach (XmlNode track in tracks)
{
  XmlNode dictTrack = track.NextSibling;

  XmlNode tmp = null;
  tmp = dictTrack.SelectSingleNode("key[text()='Name']);
  if (tmp != null)
     string trackName = tmp.NextSibling.InnerText;

  tmp = dictTrack.SelectSingleNode("key[text()='Location']);
  if (tmp != null)
     string trackLocation = tmp.NextSibling.InnerText;

}
[/QUOTE]
JasonF
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#3
2005-01-02, 01:59 PM
thanks jason, yeah its a wierd dtd. ill have a look at it later on. but your code looks like it will work. i found the itunes sdk, but it said on the website &quot;you must check the check box to say you agree to the terms before you can download ....&quot;, of course i had the checkbox checked, tried about 5 times, tried without it checked, err they must be using some scripting norton wants to block. anyways i thought it would be quicker if i did it myself (well the code in my music, not extra dll required).

and yeah there are multiple tracks, one after another.
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#4
2005-01-02, 02:22 PM
wait, i think this wont work, well needs to a little editing, the xml file looks like
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"><key>Tracks</key>
<dict>
<key>35</key>
<dict>
<key>Track ID</key><integer>35</integer>
<key>Name</key><string>Caramel Prisoner</string>
<key>Artist</key><string>Air</string>
<key>Album</key><string>10,000HZ Legend</string>
<key>Genre</key><string>Electronic</string>
<key>Kind</key><string>MPEG audio file</string>
<key>Size</key><integer>4770296</integer>
<key>Total Time</key><integer>298109</integer>
<key>Track Number</key><integer>11</integer>
<key>Date Modified</key><date>2004-01-19T19:20:45Z</date>
<key>Date Added</key><date>2003-10-17T17:51:51Z</date>
<key>Bit Rate</key><integer>128</integer>
<key>Sample Rate</key><integer>44100</integer>
<key>Play Count</key><integer>2</integer>
<key>Play Date</key><integer>-1112527749</integer>
<key>Play Date UTC</key><date>2004-11-04T18:59:07Z</date>
<key>Location</key><string>file://localhost/E:/MP3s/Air/10,000HZ%20Legend/11%20Caramel%20Prisoner.mp3/</string>
<key>File Folder Count</key><integer>4</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>
<key>36</key>
<dict>
<key>Track ID</key><integer>36</integer>
<key>Name</key><string>Don't Be Light</string>
<key>Artist</key><string>Air</string>
<key>Album</key><string>10,000HZ Legend</string>
<key>Genre</key><string>Electronic</string>
<key>Kind</key><string>MPEG audio file</string>
<key>Size</key><integer>6065134</integer>
<key>Total Time</key><integer>379062</integer>
<key>Track Number</key><integer>10</integer>
<key>Date Modified</key><date>2004-01-19T19:20:45Z</date>
<key>Date Added</key><date>2003-10-17T17:51:51Z</date>
<key>Bit Rate</key><integer>128</integer>
<key>Sample Rate</key><integer>44100</integer>
<key>Location</key><string>file://localhost/E:/MP3s/Air/10,000HZ%20Legend/10%20Don't%20Be%20Light.mp3/</string>
<key>File Folder Count</key><integer>4</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>
<key>37</key>
<dict>
<key>Track ID</key><integer>37</integer>
<key>Name</key><string>Electronic Performers</string>
<key>Artist</key><string>Air</string>
<key>Album</key><string>10,000HZ Legend</string>
<key>Genre</key><string>Electronic</string>
<key>Kind</key><string>MPEG audio file</string>
<key>Size</key><integer>5372157</integer>
<key>Total Time</key><integer>335725</integer>
<key>Track Number</key><integer>1</integer>
<key>Date Modified</key><date>2004-01-19T19:20:45Z</date>
<key>Date Added</key><date>2003-10-17T17:51:51Z</date>
<key>Bit Rate</key><integer>128</integer>
<key>Sample Rate</key><integer>44100</integer>
<key>Play Count</key><integer>2</integer>
<key>Play Date</key><integer>-1136892557</integer>
<key>Play Date UTC</key><date>2004-01-27T18:58:59Z</date>
<key>Location</key><string>file://localhost/E:/MP3s/Air/10,000HZ%20Legend/01%20Electronic%20Performers.mp3/</string>
<key>File Folder Count</key><integer>4</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>[/QUOTE]

so the &lt;key&gt;35&lt;/key&gt; is the files reference number (well key, dah) and this is before every file. this key is what i will use in the sortedlist as the key object, and the filename as the object in the sortedlist.

the playlists
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"><key>1923</key>
<dict>
<key>Track ID</key><integer>1923</integer>
<key>Name</key><string>Monster Mash</string>
<key>Artist</key><string>Bobby Pickett</string>
<key>Album</key><string>The Original Monster Mash</string>
<key>Genre</key><string>Toby</string>
<key>Kind</key><string>MPEG audio file</string>
<key>Size</key><integer>3234644</integer>
<key>Total Time</key><integer>202135</integer>
<key>Year</key><integer>1988</integer>
<key>Date Modified</key><date>2004-10-30T18:50:07Z</date>
<key>Date Added</key><date>2004-10-30T19:41:08Z</date>
<key>Bit Rate</key><integer>128</integer>
<key>Sample Rate</key><integer>44100</integer>
<key>Play Count</key><integer>4</integer>
<key>Play Date</key><integer>-1110280681</integer>
<key>Play Date UTC</key><date>2004-11-30T19:10:15Z</date>
<key>Rating</key><integer>20</integer>
<key>Location</key><string>file://localhost/E:/MP3s/Bobby%20Pickett/The%20Original%20Monster%20Mash/Monster%20Mash.mp3/</string>
<key>File Folder Count</key><integer>4</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>
</dict>
<key>Playlists</key>
<array>
<dict>
<key>Name</key><string>Library</string>
<key>Master</key><true/>
<key>Playlist ID</key><integer>1924</integer>
<key>Playlist Persistent ID</key><string>B5B76FD9C797EE78</string>
<key>All Items</key><true/>
<key>Playlist Items</key>
<array>
<dict>
<key>Track ID</key><integer>886</integer>
</dict>
<dict>
<key>Track ID</key><integer>99</integer>
</dict>
<dict>
<key>Track ID</key><integer>1053</integer>
</dict>
<dict>
<key>Track ID</key><integer>1041</integer>
</dict>
<dict>
<key>Track ID</key><integer>1049</integer>
</dict>
<dict>
<key>Track ID</key><integer>1043</integer>
</dict>
<dict>
<key>Track ID</key><integer>1045</integer>
</dict>
<dict>
<key>Track ID</key><integer>1047</integer>
</dict>
<dict>
<key>Track ID</key><integer>1052</integer>
</dict>
<dict>
<key>Track ID</key><integer>1051</integer>
</dict>
[/QUOTE]
so the &lt;key&gt;35&lt;/key&gt; is what the playlists points to.

boy who came up with this? they should be fired.
jasonf
Offline

Member

Posts: 121
Threads: 7
Joined: Oct 2004
#5
2005-01-02, 02:40 PM
If you look at the foreach loop, the &quot;track&quot; variable actually points to the &lt;key&gt;35&lt;/key&gt; element (&quot;tracks&quot; will be a list of all of the &lt;key&gt;xx&lt;/key&gt; elements).

So getting the track number is simply: track.InnerText
JasonF
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#6
2005-01-02, 02:46 PM
ok thanks, kinda new to xml, so forgive my stupidity, and its 3:49am.
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#7
2005-01-02, 03:02 PM
ok ive got:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">XmlNode keyTracks = doc.SelectSingleNode("/plist/dict/key[text()='Tracks']");

XmlNode dictTracks = null;
if (keyTracks != null)
dictTracks = keyTracks.NextSibling;

XmlNodeList tracks = dictTracks.SelectNodes("key");

foreach (XmlNode track in tracks)
{
XmlNode dictTrack = track.NextSibling;
string trackLocation = "";

XmlNode tmp = null;

tmp = dictTrack.SelectSingleNode("key[text()='Location']");
if (tmp != null)
trackLocation = tmp.NextSibling.InnerText;

if(track.InnerText != null &amp;&amp; trackLocation.Length > 0)
files.Add(track.InnerText,trackLocation);

}[/QUOTE]

just wondering if i should use a while around
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (keyTracks != null)
dictTracks = keyTracks.NextSibling;[/QUOTE]
something like
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while(keyTracks.NextSibling != null){
XmlNodeList tracks = dictTracks.SelectNodes("key");

foreach (XmlNode track in tracks)
{
XmlNode dictTrack = track.NextSibling;
string trackName;
string trackLocation = "";

XmlNode tmp = null;

tmp = dictTrack.SelectSingleNode("key[text()='Location']");
if (tmp != null)
trackLocation = tmp.NextSibling.InnerText;

if(track.InnerText != null &amp;&amp; trackLocation.Length > 0)
files.Add(track.InnerText,trackLocation);

}
}[/QUOTE]
to iterate thru the tracks in /plist/dict/key[text()='Tracks'



jasonf
Offline

Member

Posts: 121
Threads: 7
Joined: Oct 2004
#8
2005-01-02, 05:01 PM
In this case, keyTracks refers to the single &quot;node&quot; that contains within it all of the different tracks (which are pulled out into dictTracks).  I use this terminology loosely, because the base data is not nested, but we're using NextSibling to sort of simulate getting children.

To be safe, you'll need to make sure that dictTracks is not null before trying to use it.  But, there should be no reason to use a while loop as you described, because the foreach loop should take care of that purpose.

To illustrate:

keyTracks will contain:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"><key>Tracks</key>[/QUOTE]

dictTracks will contain:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"><dict>
<key>35</key>
<dict>
<key>Track ID</key><integer>35</integer>
<key>Name</key><string>Caramel Prisoner</string>
<key>Artist</key><string>Air</string>
<key>Album</key><string>10,000HZ Legend</string>
<key>Genre</key><string>Electronic</string>
<key>Kind</key><string>MPEG audio file</string>
<key>Size</key><integer>4770296</integer>
<key>Total Time</key><integer>298109</integer>
<key>Track Number</key><integer>11</integer>
<key>Date Modified</key><date>2004-01-19T19:20:45Z</date>
<key>Date Added</key><date>2003-10-17T17:51:51Z</date>
<key>Bit Rate</key><integer>128</integer>
<key>Sample Rate</key><integer>44100</integer>
<key>Play Count</key><integer>2</integer>
<key>Play Date</key><integer>-1112527749</integer>
<key>Play Date UTC</key><date>2004-11-04T18:59:07Z</date>
<key>Location</key><string>file://localhost/E:/MP3s/Air/10,000HZ%20Legend/11%20Caramel%20Prisoner.mp3/</string>
<key>File Folder Count</key><integer>4</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>
<key>36</key>
<dict>
<key>Track ID</key><integer>36</integer>
<key>Name</key><string>Don't Be Light</string>
<key>Artist</key><string>Air</string>
<key>Album</key><string>10,000HZ Legend</string>
<key>Genre</key><string>Electronic</string>
<key>Kind</key><string>MPEG audio file</string>
<key>Size</key><integer>6065134</integer>
<key>Total Time</key><integer>379062</integer>
<key>Track Number</key><integer>10</integer>
<key>Date Modified</key><date>2004-01-19T19:20:45Z</date>
<key>Date Added</key><date>2003-10-17T17:51:51Z</date>
<key>Bit Rate</key><integer>128</integer>
<key>Sample Rate</key><integer>44100</integer>
<key>Location</key><string>file://localhost/E:/MP3s/Air/10,000HZ%20Legend/10%20Don't%20Be%20Light.mp3/</string>
<key>File Folder Count</key><integer>4</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>
</dict>[/QUOTE]

tracks will contain:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"><key>35</key>
<key>36</key>[/QUOTE]

as you iterate tracks with foreach, track will then contain:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"><key>35</key>[/QUOTE]

and then dictTrack will contain:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"><dict>
<key>Track ID</key><integer>35</integer>
<key>Name</key><string>Caramel Prisoner</string>
<key>Artist</key><string>Air</string>
<key>Album</key><string>10,000HZ Legend</string>
<key>Genre</key><string>Electronic</string>
<key>Kind</key><string>MPEG audio file</string>
<key>Size</key><integer>4770296</integer>
<key>Total Time</key><integer>298109</integer>
<key>Track Number</key><integer>11</integer>
<key>Date Modified</key><date>2004-01-19T19:20:45Z</date>
<key>Date Added</key><date>2003-10-17T17:51:51Z</date>
<key>Bit Rate</key><integer>128</integer>
<key>Sample Rate</key><integer>44100</integer>
<key>Play Count</key><integer>2</integer>
<key>Play Date</key><integer>-1112527749</integer>
<key>Play Date UTC</key><date>2004-11-04T18:59:07Z</date>
<key>Location</key><string>file://localhost/E:/MP3s/Air/10,000HZ%20Legend/11%20Caramel%20Prisoner.mp3/</string>
<key>File Folder Count</key><integer>4</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>[/QUOTE]
JasonF
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#9
2005-01-02, 07:23 PM
ok i got the loading tracks part done, now im onto the playlists, im sure this code is fine, but theres a bug (possibly with memory).
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">XmlNode keyPlaylists = doc.SelectSingleNode("/plist/dict/key[text()='Playlists']");

XmlNode dictPlaylists = null;
if (keyPlaylists != null)
dictPlaylists = keyPlaylists.NextSibling;

foreach(XmlNode node in dictPlaylists.ChildNodes)
{
string name = node.SelectSingleNode("key[text()='Name']").NextSibling.InnerText;
stream.WriteLine(name);

XmlNodeList playlists = node.SelectSingleNode("array").SelectNodes("dict");

foreach (XmlNode track in playlists)
{
string tracknumber = "";
XmlNode tmp = track.SelectSingleNode("key[text()='Track ID']");
if (tmp != null)
tracknumber = tmp.NextSibling.InnerText;

if(tracknumber.Length > 0)
{
stream.WriteLine("name: "+name +"; " + tracknumber);
}
}
}
stream.Flush();
stream.Close();[/QUOTE]
the stream is just so i know what is being added, for debugging. and well heres how i know something is going wrong:
the last lines of the file shows this
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">name: My Top Rated; 819
name: My Top Rated; 1328
name: My Top Rated; 1734
name: My Top Rated; 1420
name: My [/QUOTE]
which for some reason the stream just stops writing, i tried removing the
stream.WriteLine(&quot;name: &quot;+name +&quot;; &quot; + tracknumber);
code, as i thought the error might be in there, but the
stream.WriteLine(name);
ensures each playlist name is written, but when the above line is removed the resulting file is blank. but with the above code added the name appears fine, just cuts out half way thru about 80% of the playlists. also it was reading a bit further on at first, now dropped about 10 songs, and xml file is fine, i check it at both places, no reason to stop. but the troubling thing is the half written line.

i tried throwing a try catch{stream.writeline(e.message)} around it to see if i  could find the error, but it was never reported.  gbpvr reports no errors in the log files.

any ideas?

itunes is really pissing me off. [Image: mad.gif]



jasonf
Offline

Member

Posts: 121
Threads: 7
Joined: Oct 2004
#10
2005-01-02, 08:06 PM
What exactly is stream?  A StreamWriter?  It looks like you're hitting the end of a buffer, and it's not allocating more space.

System.IO.StreamWriter stream = new System.IO.StreamWriter(filename);
JasonF
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (2): 1 2 Next »


Possibly Related Threads…
Thread Author Replies Views Last Post
  Loading Local Video Files Syler 25 6,914 2021-03-07, 09:20 PM
Last Post: Syler
  sabnzbd plugin to show processed files Wakalaka 1 2,008 2013-03-12, 06:48 AM
Last Post: psycik
  Building a list of files in media folders (npvr Music and Videos) bgowland 2 1,934 2012-02-05, 10:29 AM
Last Post: bgowland
  Extracting data from XML files ACTCMS 4 2,423 2012-01-24, 12:16 AM
Last Post: sub
  NPVR batch files mvallevand 4 3,298 2010-11-27, 07:40 PM
Last Post: mvallevand
  uploading files to wiki pastro 3 1,776 2009-01-26, 02:27 AM
Last Post: Fatman_do
  iTunes Plugin BerkA 2 2,138 2008-05-04, 09:29 PM
Last Post: BerkA
  IRecordingSource - GBPVR locks files? blackpaw 6 2,577 2008-04-01, 04:09 AM
Last Post: blackpaw
  Skin Files - and Popup skin files psycik 1 1,315 2007-12-09, 03:16 PM
Last Post: sub
  audio files sjbirk 3 1,891 2007-10-16, 03:02 AM
Last Post: sub

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode