iTunesPlaylistTests.cs :  » Development » iTuner » iTunerTests » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » iTuner 
iTuner » iTunerTests » iTunesPlaylistTests.cs
//************************************************************************************************
// Copyright  2010 Steven M. Cohn. All Rights Reserved.
//
//************************************************************************************************

namespace iTunerTests{
  using System;
  using System.Collections.Generic;
  using System.Runtime.InteropServices;
  using Microsoft.VisualStudio.TestTools.UnitTesting;
  using iTuner.iTunes;
  using iTunesLib;


  [TestClass]
  public class iTunesPlaylistTests : TestBase
  {

    /*
     * index,ID,name        Kind    Visible  Smart  SpecialKind
     * ---------------------------- ----------- ------- ------- --------------
     [1:18468] Library        Library    False
     [2:27639] Music        User    True  True  Music
     [3:36326] Movies        User    True  True  Movies
     [5:36332] TV Shows        User    True  True  TVShows
     [6:27630] Podcasts        User    True  False  Podcasts
    [11:36374] Purchased      User    True  False  PurchasedMusic
    [14:36371] Genius        User    True  True  None
    [28:27611] iTunes DJ      User    True  False  PartyShuffle
    [29:36570] My Devices      User    True  True  Folder
    [30:36487] Classical Music    User    True  True  None
    [31:27606] Music Videos      User    True  True  None
    [32:27186] My Top Rated      User    True  True  None
    [33:27599] Recently Added    User    True  True  None
    [34:27220] Recently Played    User    True  True  None
    [35:27192] Top 25 Most Played  User    True  True  None
    [36:36566] Ben          User    True  False  None
    [37:36559] ituner        User    True  False  None
     * 
     * 
     * library: "C:\\Users\\cohns\\Music\\iTunes\\iTunes Music Library.xml"
     * 
     *  Library      Visible=false  Master=true        All Items=true
     *  Music      DKind=4      Music=true        All Items=true    Smart Info
     *  Moves      DKind=2      Movies=true        All Items=true    Smart Info
     *  TV Shows    DKind=3      TV Shows=true      All Items=true    Smart Info
     *  Podcasts    DKind=10    Podcasts=true      All Items=true
     * -Purchased    DKind=19    Purchased Music=true  All Items=true
     *  Genius      DKind=26                All Items=true
     *  iTunes DJ    DKind=22    Party Shuffle=true    All Items=true
     * -My Devices            Folder=true        All Items=true
     * -Classical Music                      All Items=true    Smart Info
     * -Music Videos                      All Items=true    Smart Info
     * -My Top Rated                      All Items=true    Smart Info
     * -Recently Added                      All Items=true    Smart Info
     * -Recently Played                      All Items=true    Smart Info
     * -Top 25 Most Played                    All Items=true    Smart Info
     * -Ben                            All Items=true
     * -ituner                          All Items=true
      */

    [TestMethod]
    public void DumpPlaylists ()
    {
      iTunesAppClass itunes = new iTunesAppClass();
      IITPlaylistCollection playlists = itunes.LibrarySource.Playlists;

      foreach (IITPlaylist playlist in playlists)
      {
        if (playlist.Kind == ITPlaylistKind.ITPlaylistKindUser)
        {
          IITUserPlaylist ulist = (IITUserPlaylist)playlist;

          Console.WriteLine(String.Format(
            "[{0}:{1}] {2} - Kind:{3}, Visible:{4}, Smart:{5}, {6}",
            ulist.Index, ulist.playlistID,
            ulist.Name, ulist.Kind.ToString(), ulist.Visible,
            ulist.Smart, ulist.SpecialKind
            ));
        }
        else
        {
          Console.WriteLine(String.Format(
            "[{0}:{1}] {2} - Kind:{3}, Visible:{4}",
            playlist.Index, playlist.playlistID,
            playlist.Name, playlist.Kind.ToString(), playlist.Visible
            ));
        }
      }

      Console.WriteLine();
      Console.WriteLine("Filtered:");
      Console.WriteLine();

      foreach (IITPlaylist playlist in playlists)
      {
        if ((playlist.Kind != ITPlaylistKind.ITPlaylistKindUser) ||
          playlist.Name.Equals("Genius"))
        {
          continue;
        }

        IITUserPlaylist ulist = (IITUserPlaylist)playlist;

        if ((ulist.SpecialKind == ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindNone) ||
          (ulist.SpecialKind == ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindPurchases) ||
          (ulist.SpecialKind == ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindFolder))
        {
          Console.WriteLine(ulist.Name);
        }
      }

      itunes.Quit();
      Marshal.ReleaseComObject(itunes);
      itunes = null;
    }


    [TestMethod]
    public void LibraryTracks ()
    {
      Controller controller = new Controller();
      TrackCollection tracks = controller.LibraryPlaylist.Tracks;

      PersistentIDCollection pids = new PersistentIDCollection();
      //List<int> tids = new List<int>();

      watch.Start();

      foreach (Track track in tracks.Values)
      {
        if (track != null)
        {
          pids.Add(track.PersistentID);
          //tids.Add(track.trackID);
          track.Dispose();
        }
      }

      watch.Stop();
      Console.WriteLine(String.Format("Found {0} tracks", pids.Count));
      Console.WriteLine(String.Format("Completed in {0} ms", watch.GetElapsedMilliseconds()));

      tracks.Dispose();
      tracks = null;

      controller.Dispose();
      controller = null;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.