Ejemplo n.º 1
0
        private static IITUserPlaylist findPlaylist(IITPlaylistCollection pl, IITUserPlaylist playlist)
        {
            playlist = null;

            int count = 0;

            while (playlist == null && ++count < 10)
            {
                foreach (IITPlaylist p in pl)
                {
                    if (p.Name == playlistName)
                    {
                        playlist = p as IITUserPlaylist;
                        if (playlist != null)
                        {
                            if (playlist.Kind != ITPlaylistKind.ITPlaylistKindUser ||
                                playlist.Smart ||
                                (playlist.SpecialKind != ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindMusic &&
                                 playlist.SpecialKind != ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindNone))
                            {
                                playlistName = adjust(playlistName);
                                playlist     = null;
                            }
                        }
                        break;
                    }
                }
            }
            return(playlist);
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        public static IITPlaylist GetPlaylist(this IITPlaylistCollection playlists, string name)
        {
            //Is there a better way then to look at all f*****g playlists ?
            foreach (IITPlaylist pl in playlists)
            {
                if (pl.Name == name)
                {
                    return(pl);
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
        public static iTunesLib.IITUserPlaylist GetiTunesPlaylist(iTunesLib.IiTunes iitApp, string strPlaylist)
        {
            IITUserPlaylist       returnPlaylist = null;
            IITPlaylistCollection playlists      = iitApp.LibrarySource.Playlists;
            int numPlaylists = playlists.Count;

            Object podcastfolder = null;

            // find the Dopppler Podcasts folder in iTunes
            foreach (IITPlaylist folder in iitApp.LibrarySource.Playlists)
            {
                if (folder.Name == "Doppler Podcasts")
                {
                    podcastfolder = folder;
                    break;
                }
            }
            if (podcastfolder == null)
            {
                podcastfolder = iitApp.CreateFolder("Doppler Podcasts");
            }


            while (numPlaylists != 0)
            {
                Object      currPlaylist = playlists[numPlaylists];
                IITPlaylist tempPlaylist = (IITPlaylist)currPlaylist;
                // is this a user playlist?
                if (tempPlaylist.Kind == ITPlaylistKind.ITPlaylistKindUser)
                {
                    IITUserPlaylist thisPlaylist = (IITUserPlaylist)currPlaylist;

                    if (thisPlaylist.Name == strPlaylist)
                    {
                        returnPlaylist = thisPlaylist;
                        break;
                    }
                }
                numPlaylists--;
            }
            if (returnPlaylist == null)
            {
                returnPlaylist = (IITUserPlaylist)iitApp.CreatePlaylist(strPlaylist);
                returnPlaylist.set_Parent(ref podcastfolder);
                //returnPlaylist = GetiTunesPlaylist(iitApp, strPlaylist);
            }

            return(returnPlaylist);
        }
Ejemplo n.º 5
0
        /*!
         *
         * \copydoc MediaSoftwareService::GetPlaylists()
         */
        public List <Playlist> GetPlaylists()
        {
            ValidateState();
            IITPlaylistCollection playlists = itunesCom.LibrarySource.Playlists;

            List <Playlist> listOfPlaylists = new List <Playlist>();

            foreach (IITPlaylist playlist in playlists)
            {
                Playlist pl = new Playlist();
                pl.Name         = playlist.Name;
                pl.ID           = playlist.playlistID;
                pl.PlaylistType = playlist.Kind.ToString();
                pl.TrackCount   = playlist.Tracks.Count;
                listOfPlaylists.Add(pl);
            }

            return(listOfPlaylists);
        }
Ejemplo n.º 6
0
        private static void createPlaylist()
        {
            try
            {
                iTunesApp app = new iTunesApp();

                app.ForceToForegroundOnDialog = true;

                //app.SetOptions(); would be nice to kill autoarrange

                IITPlaylistCollection pl       = app.LibrarySource.Playlists;
                IITUserPlaylist       playlist = null;

                playlist = findPlaylist(pl, playlist);

                if (playlist == null)
                {
                    playlist = (IITUserPlaylist)app.CreatePlaylist(playlistName);
                }
                else
                {
                    // remove tracks, how?
                    foreach (IITTrack t in playlist.Tracks)
                    {
                        //t.Delete(); <== ?
                    }
                }

                iTunesLib.IITLibraryPlaylist lp = app.LibraryPlaylist;

                IITTrackCollection itTracks = app.LibraryPlaylist.Tracks;

                Dictionary <string, int> libraryTrackDictionary = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);
                List <string>            libraryTrackFiles      = new List <string>();

                foreach (IITTrack t in itTracks)
                {
                    if (Cancel)
                    {
                        break;
                    }

                    if (t.Kind == ITTrackKind.ITTrackKindFile)
                    {
                        string l = (t as IITFileOrCDTrack).Location;
                        if (l != null)
                        {
                            libraryTrackFiles.Add(l);
                            if (!libraryTrackDictionary.ContainsKey(l))
                            {
                                libraryTrackDictionary.Add(l, t.Index);
                            }
                        }
                    }
                }
                List <string> allTracks = new List <string>();
                foreach (Track t in tracks)
                {
                    allTracks.Add(t.FilePath);
                }

                object oo = (object)(allTracks.ToArray());
                playlist.AddFiles(ref oo);

                Controller.ShowMessage("Completed sending playlist to iTunes.");

                app.Quit();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Clock.DoOnMainThread(ShowError);
            }
            Busy = false;
        }
Ejemplo n.º 7
0
 private static string GetValidPlaylistName(string playlistName, IITPlaylistCollection playlists)
 {
     while (++_attempts < 3)
     {
         var playlist = new object[playlists.Count - 13];
         for (var i = 0; i + 13 < playlists.Count; ++i)
         {
             var plays = playlists[i + 14];
             playlist[i] = plays.Name;
             if (plays.Name.Equals(playlistName, StringComparison.CurrentCultureIgnoreCase))
                 return plays.Name;
         }
         playlistName = ShowDialog("Select one playlist from the dropdown.", "Playlist selector", playlist, playlistName);
     }
     MessageBox.Show("Attempted 3 times with bad playlist name, exiting.", "Exiting", MessageBoxButtons.OK);
     Environment.Exit(0);
     throw new Exception("This thing didn't exit.");
 }
Ejemplo n.º 8
0
        private void LoadPlaylists(object sender, EventArgs e)
        {
            this.playlistCollection = GetiTunesPlaylists();

            for (int i = 1; i <= playlistCollection.Count; i++)
            {
                IITPlaylist currentPlaylist = this.playlistCollection[i];

                PlaylistsListBox.Items.Add(currentPlaylist.Name);
            }

            EnableDisableUIFields(true);
        }
Ejemplo n.º 9
0
        public static CPlaylist LoadPlaylists(iTunesApp itunes)
        {
            CPlaylist             retPlaylist = new CPlaylist(null);
            IITSourceCollection   sources     = itunes.Sources;
            IITPlaylistCollection playlists   = null;
            IITSource             plSource    = null;

            foreach (IITSource source in sources)
            {
                if (source.Kind == ITSourceKind.ITSourceKindLibrary)
                {
                    plSource  = source;
                    playlists = source.Playlists;
                    break;
                }
            }
            foreach (IITPlaylist pl in playlists)
            {
                if (pl.Kind != ITPlaylistKind.ITPlaylistKindUser)
                {
                    continue;
                }
                try
                {
                    IITUserPlaylist upl = (IITUserPlaylist)pl;
                    if (upl.Smart)
                    {
                        continue;
                    }
                    if (upl.SpecialKind == ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindPodcasts)
                    {
                        continue;
                    }
                    string strDir = string.Empty;
                    Stack <IITUserPlaylist> parentStack = new Stack <IITUserPlaylist>();
                    IITUserPlaylist         uplp        = upl.get_Parent();
                    if (uplp != null)
                    {
                        parentStack.Push(uplp);
                        IITUserPlaylist uplc = uplp;
                        do
                        {
                            uplp = uplc.get_Parent();
                            if (uplp != null)
                            {
                                parentStack.Push(uplp);
                                uplc = uplp;
                            }
                        } while (uplp != null);
                    }
                    CPlaylist parentPL   = retPlaylist;
                    bool      bFoundLeaf = false;
                    do
                    {
                        uplp = (parentStack.Count > 0) ? parentStack.Pop() : null;
                        if (uplp == null)
                        {
                            bFoundLeaf = true;
                        }
                        else
                        {
                            CPlaylist childPL = null;
                            foreach (var item in parentPL.Children)
                            {
                                if (item.Name == uplp.Name)
                                {
                                    childPL = item;
                                    break;
                                }
                            }
                            if (childPL != null)
                            {
                                parentPL = childPL;
                            }
                            else
                            {
                                bFoundLeaf = true;
                            }
                        }
                    } while (!bFoundLeaf);
                    while (uplp != null)
                    {
                        CPlaylist plChild = new CPlaylist(uplp, true);
                        parentPL.Children.Add(plChild);
                        parentPL = plChild;
                        uplp     = (parentStack.Count > 0) ? parentStack.Pop() : null;
                    }
                    parentPL.Children.Add(new CPlaylist(upl));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
            return(retPlaylist);
        }
Ejemplo n.º 10
0
        private IITPlaylist GetRecentyPlayed()
        {
            IITPlaylistCollection playlists = itunes.LibrarySource.Playlists;

            return(playlists.get_ItemByName("iDotFm"));
        }