Thursday, 25 December 2014

Using loop in reading iTunes XML VB



Is it possible to read all the tracks in iTunes XML using a loop syntax? I am trying to get the play count of all the songs and save it in a notepad. Also, i want to get the sum of all the play count in a specific artist and also the total play count of all the songs in a specific album. related to my previous question here: Reading XML in VB


This is a sample of iTunes' XML.



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://ift.tt/vvUEPL">
<plist version="1.0">
<dict>
<key>Major Version</key><integer>1</integer>
<key>Minor Version</key><integer>1</integer>
<key>Date</key><date>2014-08-24T05:21:40Z</date>
<key>Application Version</key><string>11.3.1</string>
<key>Features</key><integer>5</integer>
<key>Show Content Ratings</key><true/>
<key>Music Folder</key><string>file://localhost/C:/Users/Mon%20Tolentino/Music/iTunes/iTunes%20Media/</string>
<key>Library Persistent ID</key><string>15CDC06EC711077D</string>
<key>Tracks</key>
<dict>
<key>766</key>
<dict>
<key>Track ID</key><integer>766</integer>
<key>Name</key><string>Say Something</string>
<key>Artist</key><string>A Great Big World</string>
<key>Album Artist</key><string>A Great Big World</string>
<key>Composer</key><string>Ian Axel, Chad Vaccarino, Mike Campbell</string>
<key>Album</key><string>Is There Anybody Out There?</string>
<key>Grouping</key><string>Indie</string>
<key>Genre</key><string>Pop</string>
<key>Kind</key><string>AAC audio file</string>
<key>Size</key><integer>8639959</integer>
<key>Total Time</key><integer>233289</integer>
<key>Disc Number</key><integer>1</integer>
<key>Disc Count</key><integer>1</integer>
<key>Track Number</key><integer>5</integer>
<key>Track Count</key><integer>13</integer>
<key>Year</key><integer>2013</integer>
<key>BPM</key><integer>94</integer>
<key>Date Modified</key><date>2014-05-25T15:58:35Z</date>
<key>Date Added</key><date>2014-05-18T10:09:13Z</date>
<key>Bit Rate</key><integer>256</integer>
<key>Sample Rate</key><integer>44100</integer>
<key>Play Count</key><integer>33</integer>
<key>Play Date</key><integer>3491589574</integer>
<key>Play Date UTC</key><date>2014-08-22T13:59:34Z</date>
<key>Skip Count</key><integer>7</integer>
<key>Skip Date</key><date>2014-08-15T15:15:43Z</date>
<key>Release Date</key><date>2013-11-04T12:00:00Z</date>
<key>Rating</key><integer>60</integer>
<key>Album Rating</key><integer>60</integer>
<key>Album Rating Computed</key><true/>
<key>Artwork Count</key><integer>1</integer>
<key>Sort Album Artist</key><string>A Great Big World</string>
<key>Sort Artist</key><string>A Great Big World</string>
<key>Persistent ID</key><string>50A143EFFA8BEA97</string>
<key>Track Type</key><string>File</string>
<key>Location</key><string>file://localhost/C:/Users/Mon%20Tolentino/Music/iTunes/iTunes%20Media/Music/A%20Great%20Big%20World/Is%20There%20Anybody%20Out%20There_/05%20Say%20Something.m4a</string>
<key>File Folder Count</key><integer>5</integer>
<key>Library Folder Count</key><integer>1</integer>
</dict>


and this is how i search for a specific track on XML. (as for this example, this is the code i use if i'm trying to check if the song is explicit or not



Dim Search = From TrackQuery In iTunesXML...<dict>
Where TrackQuery.Elements("key").Any(Function(Name) Name.Value = "Name" _
AndAlso (CType(Name.NextNode, XElement).Value = Title)) _
Where TrackQuery.Elements("key").Any(Function(AlbumArtist) AlbumArtist.Value = "Album Artist" _
AndAlso (CType(AlbumArtist.NextNode, XElement).Value = Artist2)) _
And TrackQuery.Elements("key").Any(Function(Explicit) Explicit.Value = "Explicit" _
AndAlso (CType(Explicit.NextNode, XElement).Name = "true"))
Dim IsExplicit As Boolean = Search.Any()


so.. the problem is.. is it possible to have a code the do something like this:



- get the play count of each track
- get the total play count of each artist
- get the total play count of each album

No comments:

Post a Comment