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;
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="trackPIDs"></param>

        public ExportDialog(Controller controller, PersistentIDCollection trackPIDs)
            : this()
        {
            this.controller = controller;
            this.trackPIDs  = trackPIDs;

            this.percentageCompleted = 0;

            this.Encoders = controller.Encoders;

            if (!String.IsNullOrEmpty(trackPIDs.Album))
            {
                detailBlock.Text = String.Format(
                    Resx.ExportingAlbum, trackPIDs.Count, trackPIDs.Album, trackPIDs.Artist);
            }
            else if (!String.IsNullOrEmpty(trackPIDs.Artist))
            {
                detailBlock.Text = String.Format(
                    Resx.ExportingArtist, trackPIDs.Count, trackPIDs.Artist);
            }
            else
            {
                detailBlock.Text = String.Format(
                    Resx.ExportingPlaylist, trackPIDs.Count, trackPIDs.Name);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="trackPIDs"></param>
        public ExportDialog(Controller controller, PersistentIDCollection trackPIDs)
            : this()
        {
            this.controller = controller;
            this.trackPIDs = trackPIDs;

            this.percentageCompleted = 0;

            this.Encoders = controller.Encoders;

            if (!String.IsNullOrEmpty(trackPIDs.Album))
            {
                detailBlock.Text = String.Format(
                    Resx.ExportingAlbum, trackPIDs.Count, trackPIDs.Album, trackPIDs.Artist);
            }
            else if (!String.IsNullOrEmpty(trackPIDs.Artist))
            {
                detailBlock.Text = String.Format(
                    Resx.ExportingArtist, trackPIDs.Count, trackPIDs.Artist);
            }
            else
            {
                detailBlock.Text = String.Format(
                    Resx.ExportingPlaylist, trackPIDs.Count, trackPIDs.Name);
            }
        }
Exemple #4
0
        private IPlaylistWriter writer; // playlist writer

        #endregion Fields

        #region Constructors

        //========================================================================================
        // Constructor
        //========================================================================================
        /// <summary>
        /// Initialize a new instance of this scanner.
        /// </summary>
        /// <param name="itunes">The iTunesAppClass to use.</param>
        /// <param name="exportPIDs">
        /// The list of persistent track IDs.  When exporting multiple playlists, this list
        /// should include all tracks from all playlists where each track indicates its own
        /// source playlist.  This allows comprehensive/overall feedback for UI progress bars.
        /// </param>
        /// <param name="encoder">The encoder to use to convert tracks.</param>
        /// <param name="playlistFormat">
        /// The playlist output format or PlaylistFactory.NoFormat for no playlist file.
        /// </param>
        /// <param name="location">
        /// The target root directory path to which all entries will be copied or converted.
        /// </param>
        /// <param name="pathFormat">
        /// The path format string as specified in FolderFormts.xml or null for title only.
        /// </param>
        /// <param name="isSynchronized">
        /// True if target location should be synchronized, removing entries in the target
        /// location that are not included in the exportPIDs collection.
        /// </param>
        public ExportScanner(
            Controller controller, PersistentIDCollection exportPIDs,
            Encoder encoder, string playlistFormat, string location, string pathFormat,
            bool isSynchronized)
        {
            base.name = Resx.I_ScanExport;
            base.description = isSynchronized ? Resx.ScanSynchronize : Resx.ScanExport;
            base.controller = controller;

            this.exportPIDs = exportPIDs;
            this.encoder = encoder;
            this.expectedType = encoder.ExpectedType;
            this.playlistFormat = playlistFormat;
            this.playlistName = exportPIDs.Name;
            this.location = location;
            this.createSubdirectories = (pathFormat != null);
            this.pathFormat = pathFormat ?? PathHelper.GetPathFormat(FlatPathFormat);
            this.isSynchronized = isSynchronized;

            this.exports = null;
            this.writer = null;

            this.slim = new ReaderWriterLockSlim();
            this.waitSyncRoot = null;
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void DoExportArtist(object sender, EventArgs e)
        {
            string artist = controller.CurrentTrack.Artist;

            PersistentIDCollection list = librarian.Catalog.FindTracksByArtist(artist);

            list.Artist = artist;
            list.Name   = artist;

            DoExport(list);
        }
Exemple #6
0
        private void DoFixAlbum(object sender, EventArgs e)
        {
            string album  = controller.CurrentTrack.Album;
            string artist = controller.CurrentTrack.Artist;

            PersistentIDCollection list = librarian.Catalog.FindTracksByAlbum(album, artist);

            list.Album  = album;
            list.Artist = artist;
            list.Name   = album;

            librarian.FixInformation(list);
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void DoExportPlaylist(object sender, EventArgs e)
        {
            using (var playlist = controller.CurrentPlaylist)
            {
                PersistentIDCollection list =
                    librarian.Catalog.FindTracksByPlaylist(playlist.PersistentID);

                list.Name = controller.CurrentPlaylist.Name;

                DoExport(list);

                list.Clear();
            }
        }
Exemple #8
0
        private void DoFixTrack(object sender, EventArgs e)
        {
            string album  = controller.CurrentTrack.Album;
            string artist = controller.CurrentTrack.Artist;

            var list = new PersistentIDCollection
            {
                controller.CurrentTrack.PersistentID
            };

            list.Album  = album;
            list.Artist = artist;
            list.Name   = album;

            librarian.FixInformation(list);
        }
Exemple #9
0
        private void DoExport(PersistentIDCollection list)
        {
            if (IsOpaque && !IsPinned)
            {
                Hide();
            }

            try
            {
                exportDialog = new ExportDialog(controller, list);
                exportDialog.ShowDialog();
            }
            finally
            {
                exportDialog = null;
            }
        }
Exemple #10
0
        public void FindCatalogedTracksByPlaylist()
        {
            // FlatCatalog

            ICatalog catalog = new FlatCatalog();

            catalog.Initialize(libraryXMLPath);
            Console.WriteLine(String.Format("new FlatCatalog() -> {0} ms", watch.GetSplitMilliseconds()));

            var tracks = new List <IITTrack>();

            PersistentID           pid           = GetPlaylistPersistentID("ituner");
            PersistentIDCollection persistentIDs = catalog.FindTracksByPlaylist(pid);

            foreach (PersistentID persistentID in persistentIDs)
            {
                IITTrack itrack = itunes.LibraryPlaylist.Tracks.get_ItemByPersistentID(
                    persistentID.HighBits, persistentID.LowBits);

                tracks.Add(itrack);
            }

            Console.WriteLine(String.Format("FindTracksByPlaylist -> {0} ms", watch.GetSplitMilliseconds()));

            Assert.IsNotNull(persistentIDs);
            Assert.AreNotEqual(0, persistentIDs.Count);
            Console.WriteLine(String.Format("Found {0} tracks", persistentIDs.Count));

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

            // iTunes

            watch.Reset();
            watch.Start();

            IITTrackCollection itracks =
                itunes.LibrarySource.Playlists.get_ItemByName("ituner").Tracks;

            Console.WriteLine(String.Format("get_ItemByName -> {0} ms", watch.GetSplitMilliseconds()));

            watch.Stop();
            Console.WriteLine(String.Format("Completed in {0} ms", watch.GetElapsedMilliseconds()));
        }
Exemple #11
0
        /// <summary>
        /// Release managed resources
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void DoClosed(object sender, EventArgs e)
        {
            if (percentageCompleted > 0)
            {
                controller.Librarian.ProgressChanged -= new ProgressChangedEventHandler(DoProgressChanged);
            }

            this.Closed  -= new EventHandler(DoClosed);
            this.Closing -= new CancelEventHandler(DoClosing);

            if (percentageCompleted == 100)
            {
                string location = PathHelper.CleanDirectoryPath(locationBox.Text.Trim());

                if (!String.IsNullOrEmpty(location))
                {
                    Settings.Default.ExportPlaylistFormat = ((ComboBoxItem)playlistBox.SelectedItem).Tag as string;
                    Settings.Default.ExportSubdirectories = (bool)treeCheck.IsChecked;
                    Settings.Default.ExportLocation       = location;
                    Settings.Default.Save();
                }
            }

            controller = null;
            trackPIDs  = null;

            // clear the encoderBox UI control
            encoderBox.SelectedItem = null;

            foreach (ComboBoxItem item in encoderBox.Items)
            {
                item.Content = null;
            }

            encoderBox.Items.Clear();

            // dispose the encoders collection
            encoders.Dispose();
            encoders = null;
        }
Exemple #12
0
        /// <summary>
        /// Export the specified tracks to a given USB MP3 player, synchronizing the
        /// contents of the specified location.
        /// </summary>
        /// <param name="list"></param>
        /// <param name="location"></param>
        /// <param name="pathFormat"></param>
        public void Export(PersistentIDCollection list, string location, string pathFormat)
        {
            if (disabled.Contains(Resx.I_ScanExport))
            {
                return;
            }

            Encoder mp3Encoder = null;
            foreach (Encoder encoder in controller.Encoders)
            {
                // skip the Null encoder that's automatically added to controller.Encoders
                if (!encoder.IsEmpty)
                {
                    if (encoder.Format.Equals("MP3"))
                    {
                        mp3Encoder = encoder;
                    }
                }
            }

            if (mp3Encoder != null)
            {
                lock (sync)
                {
                    disabled.Add(Resx.I_ScanDuplicates);
                    disabled.Add(Resx.I_ScanFileWatch);
                    disabled.Add(Resx.I_ScanMaintenance);
                }

                IScanner scanner = new ExportScanner(
                    controller, list,
                    mp3Encoder,
                    PlaylistFactory.NoFormat,
                    location, pathFormat, true);

                scanner.Completed = (Action)delegate
                {
                    Encoder mp3 = mp3Encoder;
                    lock (sync)
                    {
                        disabled.Remove(Resx.I_ScanDuplicates);
                        disabled.Remove(Resx.I_ScanFileWatch);
                        disabled.Remove(Resx.I_ScanMaintenance);
                    }
                    mp3 = null;
                };

                AddScanner(scanner);
            }

            // [foo] dispose this reference but do not release underlying instance passed to Librarian
            //mp3Encoder.Dispose(false);
        }
Exemple #13
0
        public void FlatTerseComparisons()
        {
            // create two playlists, both name "Ben" and use this to test that we can
            // find the extensions in the first one

            ICatalog flat = new FlatCatalog();

            flat.Initialize(libraryXMLPath);

            ICatalog terse = new TerseCatalog();

            terse.Initialize(libraryXMLPath);

            PersistentID pid = GetPlaylistPersistentID("Ben");

            // FindExtensionsByPlaylist()

            StringCollection flatExtensions = flat.FindExtensionsByPlaylist(pid);

            Assert.IsNotNull(flatExtensions);
            Assert.AreNotEqual(0, flatExtensions.Count);

            StringCollection terseExtensions = terse.FindExtensionsByPlaylist(pid);

            Assert.IsNotNull(terseExtensions);
            Assert.AreNotEqual(0, terseExtensions.Count);

            Assert.AreEqual(flatExtensions.Count, terseExtensions.Count);

            foreach (string ext in terseExtensions)
            {
                Assert.IsTrue(flatExtensions.Contains(ext));
            }

            Console.WriteLine("FindExtensionsByPlaylist() OK");

            // FindPlaylistName()

            string name = flat.FindPlaylistName(pid);

            Assert.AreEqual("Ben", name);

            name = terse.FindPlaylistName(pid);
            Assert.AreEqual("Ben", name);

            Console.WriteLine("FindPlaylistName() OK");

            // FindTracksByAlbum()

            PersistentIDCollection flatTracks =
                flat.FindTracksByAlbum("Greatest Hits", "Alice Cooper");

            Assert.IsNotNull(flatTracks);
            Assert.AreNotEqual(0, flatTracks.Count);

            PersistentIDCollection terseTracks =
                terse.FindTracksByAlbum("Greatest Hits", "Alice Cooper");

            Assert.IsNotNull(terseTracks);
            Assert.AreNotEqual(0, terseTracks.Count);

            Assert.AreEqual(flatTracks.Count, terseTracks.Count);

            foreach (PersistentID id in terseTracks)
            {
                Assert.IsTrue(flatTracks.Contains(id));
            }

            Console.WriteLine("FindTracksByAlbum() OK");

            // FindTracksByArtist()

            flatTracks = flat.FindTracksByArtist("Alice Cooper");
            Assert.IsNotNull(flatTracks);
            Assert.AreNotEqual(0, flatTracks.Count);

            terseTracks = terse.FindTracksByArtist("Alice Cooper");
            Assert.IsNotNull(terseTracks);
            Assert.AreNotEqual(0, terseTracks.Count);

            Assert.AreEqual(flatTracks.Count, terseTracks.Count);

            foreach (PersistentID id in terseTracks)
            {
                Assert.IsTrue(flatTracks.Contains(id));
            }

            Console.WriteLine("FindTracksByArtist() OK");

            // FindTracksByPlaylist()

            pid = GetPlaylistPersistentID("My Top Rated");

            flatTracks = flat.FindTracksByPlaylist(pid);
            Assert.IsNotNull(flatTracks);
            Assert.AreNotEqual(0, flatTracks.Count);

            terseTracks = terse.FindTracksByPlaylist(pid);
            Assert.IsNotNull(terseTracks);
            Assert.AreNotEqual(0, terseTracks.Count);

            Assert.AreEqual(flatTracks.Count, terseTracks.Count);

            foreach (PersistentID id in terseTracks)
            {
                Assert.IsTrue(flatTracks.Contains(id));
            }

            Console.WriteLine("FindTracksByPlaylist() OK");
        }
Exemple #14
0
        /// <summary>
        /// Export the specified tracks to a given directory using the specified encoder.
        /// </summary>
        /// <param name="tracks"></param>
        /// <param name="encoder"></param>
        /// <param name="location"></param>
        /// <param name="createSubdir"></param>
        public void Export(
            PersistentIDCollection list, Encoder encoder,
            string playlistFormat, string location, bool createSubdirectories)
        {
            lock (sync)
            {
                disabled.Add(Resx.I_ScanDuplicates);
                disabled.Add(Resx.I_ScanFileWatch);
                disabled.Add(Resx.I_ScanMaintenance);
            }

            string pathFormat = null;
            if (createSubdirectories)
            {
                pathFormat = PathHelper.GetPathFormat(ExportScanner.DefaultPathFormat);
            }

            IScanner scanner = new ExportScanner(
                controller, list, encoder, playlistFormat, location, pathFormat, false);

            scanner.Completed = (Action)delegate
            {
                lock (sync)
                {
                    disabled.Remove(Resx.I_ScanDuplicates);
                    disabled.Remove(Resx.I_ScanFileWatch);
                    disabled.Remove(Resx.I_ScanMaintenance);
                }
            };

            AddScanner(scanner);
        }
Exemple #15
0
        public void FindCatalogedTracksByArtist()
        {
            // FlatCatalog

            ICatalog catalog = new FlatCatalog();

            catalog.Initialize(libraryXMLPath);
            Console.WriteLine(String.Format("new FlatCatalog() -> {0} ms", watch.GetSplitMilliseconds()));

            PersistentIDCollection trackIDs = catalog.FindTracksByArtist("Guster");

            Console.WriteLine(String.Format("FindTracksByArtist/Flat -> {0} ms", watch.GetSplitMilliseconds()));

            Assert.IsNotNull(trackIDs);
            Assert.AreNotEqual(0, trackIDs.Count);
            Console.WriteLine(String.Format("Found {0} tracks", trackIDs.Count));
            ReportPrivateDelta();

            // TerseCatalog

            catalog = new TerseCatalog();
            catalog.Initialize(libraryXMLPath);
            Console.WriteLine(String.Format("new TerseCatalog() -> {0} ms", watch.GetSplitMilliseconds()));

            trackIDs = catalog.FindTracksByArtist("Guster");
            Console.WriteLine(String.Format("FindTracksByArtist/Terse -> {0} ms", watch.GetSplitMilliseconds()));

            Assert.IsNotNull(trackIDs);
            Assert.AreNotEqual(0, trackIDs.Count);
            Console.WriteLine(String.Format("Found {0} tracks", trackIDs.Count));
            ReportPrivateDelta();

            // Controller

            using (var controller = new Controller())
            {
                System.Threading.Thread.Sleep(2000);                 // let the controller initialize

                trackIDs = new PersistentIDCollection();
                foreach (Track track in controller.LibraryPlaylist.Tracks.Values)
                {
                    if ((track != null) && !String.IsNullOrEmpty(track.Artist))
                    {
                        if (track.Artist.Equals("Guster"))
                        {
                            trackIDs.Add(track.PersistentID);
                        }
                    }
                }
            }

            Console.WriteLine(String.Format("FindTracksByArtist/Controller -> {0} ms", watch.GetSplitMilliseconds()));

            // iTunes

            trackIDs = new PersistentIDCollection();
            foreach (IITTrack track in itunes.LibraryPlaylist.Tracks)
            {
                if ((track != null) && !String.IsNullOrEmpty(track.Artist))
                {
                    if (track.Artist.Equals("Guster"))
                    {
                        trackIDs.Add(GetPersistentID(track));
                    }
                }
            }

            Console.WriteLine(String.Format("FindTracksByArtist/iTunes -> {0} ms", watch.GetSplitMilliseconds()));

            Assert.IsNotNull(trackIDs);
            Assert.AreNotEqual(0, trackIDs.Count);
            Console.WriteLine(String.Format("Found {0} tracks", trackIDs.Count));
            ReportPrivateDelta();
        }
        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;
        }
        //----------------------------------------------------------------------------------------
        /// <summary>
        /// Invoked when the Sync button is pressed, starts the synchronization process.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DoSync(object sender, RoutedEventArgs e)
        {
            string text = String.Format(Resx.SyncWarningText, selector.Location);

            MessageBoxResult result = MessageWindow.Show(
                null, text, Resx.SyncWarningCaption,
                MessageBoxButton.OKCancel, MessageWindowImage.Warning, MessageBoxResult.Cancel);

            if (result != MessageBoxResult.OK)
            {
                e.Handled = true;
                return;
            }

            countBox.Visibility = Visibility.Hidden;
            playlistBox.IsEnabled = false;
            selector.IsEnabled = false;
            syncButton.Visibility = Visibility.Collapsed;
            progressPanel.Visibility = Visibility.Visible;

            string format = PathHelper.GetPathFormat(selector.FormatTag);
            bool withPlaylist = format.Contains("playlist");

            PlaylistCollection selectedPlaylists = new PlaylistCollection();
            selectedPlaylists.AddRange(playlists.FindAll(p => p.IsSelected == true));

            PersistentIDCollection list = new PersistentIDCollection();
            foreach (Playlist playlist in selectedPlaylists.Values)
            {
                if (playlist != null)
                {
                    PersistentID pid = playlist.PersistentID;

                    PersistentIDCollection tracks =
                        controller.Librarian.Catalog.FindTracksByPlaylist(pid);

                    if (withPlaylist)
                    {
                        // Cannot modify a value type (PersistentID) from within a foreach loop
                        // or the .ForEach extension method, so we need to recreate each pid
                        // to set the playlist name.  Unfortunate design consequence...
                        foreach (PersistentID track in tracks)
                        {
                            PersistentID tid = track;
                            tid.PlaylistName = playlist.Name;
                            list.Add(tid);
                        }
                    }
                    else
                    {
                        list.AddRange(tracks);
                    }
                }
            }

            // show iTunes incase a protection fault occurs; otherwise you cannot see the
            // dialog if iTunes is minimized as a Taskbar toolbar
            controller.ShowiTunes();

            controller.Librarian.ProgressChanged += new ProgressChangedEventHandler(DoProgressChanged);
            controller.Librarian.Export(list, selector.Location, format);
        }
Exemple #18
0
        public void FindCatalogedTracksByAlbum()
        {
            // FlatCatalog

            ICatalog catalog = new FlatCatalog();

            catalog.Initialize(libraryXMLPath);
            Console.WriteLine(String.Format("new FlatCatalog() -> {0} ms", watch.GetSplitMilliseconds()));

            PersistentIDCollection trackIDs = catalog.FindTracksByAlbum("Ganging Up on the Sun", "Guster");

            Console.WriteLine(String.Format("FindTracksByAlbum -> {0} ms", watch.GetSplitMilliseconds()));

            Assert.IsNotNull(trackIDs);
            Assert.AreNotEqual(0, trackIDs.Count);
            Console.WriteLine(String.Format("Found {0} tracks", trackIDs.Count));

            ReportPrivateDelta();

            // TerseCatalog

            catalog = new TerseCatalog();
            catalog.Initialize(libraryXMLPath);
            Console.WriteLine(String.Format("new TerseCatalog() -> {0} ms", watch.GetSplitMilliseconds()));

            trackIDs = catalog.FindTracksByAlbum("Ganging Up on the Sun", "Guster");
            Console.WriteLine(String.Format("FindTracksByAlbum -> {0} ms", watch.GetSplitMilliseconds()));

            Assert.IsNotNull(trackIDs);
            Assert.AreNotEqual(0, trackIDs.Count);
            Console.WriteLine(String.Format("Found {0} tracks", trackIDs.Count));

            ReportPrivateDelta();

            // Controller

            using (var controller = new Controller())
            {
                System.Threading.Thread.Sleep(2000);                 // let the controller initialize

                List <Track> tracks = new List <Track>();
                foreach (PersistentID persistentID in trackIDs)
                {
                    Track track = controller.LibraryPlaylist.GetTrack(persistentID);
                    tracks.Add(track);
                }

                Console.WriteLine(String.Format("Tracks[] -> {0} ms", watch.GetSplitMilliseconds()));

                // iTunes

                List <Track> tracks2 = new List <Track>();
                foreach (PersistentID persistentID in trackIDs)
                {
                    IITTrack itrack = itunes.LibraryPlaylist.Tracks.get_ItemByPersistentID(
                        persistentID.HighBits, persistentID.LowBits);

                    Track track = new Track(itrack);
                    tracks2.Add(track);
                }

                Console.WriteLine(String.Format("ITracks[] -> {0} ms", watch.GetSplitMilliseconds()));

                Assert.AreNotEqual(0, tracks.Count);
            }
        }
Exemple #19
0
        /// <summary>
        /// Retrieves a list of all tracks by the specified artist.
        /// </summary>
        /// <param name="artist">The name of the artist.</param>
        /// <returns></returns>
        public override PersistentIDCollection FindTracksByArtist(string artist)
        {
            if (!isReady)
            {
                return new PersistentIDCollection();
            }

            artist = artist.Trim().ToLower();

            // find the <plist><dict><key>Tracks</key><dict> root node
            var trackRoot =
                from node in root
                    .Element(ns + "dict")
                    .Elements(ns + "key")
                where node.Value == "Tracks"
                select node.NextNode;

            // Tracks/dict is the container for all tracks where each is a key/dict pair
            // collect all dict elements related to specified artist

            var artistTracks =
                from node in ((XElement)trackRoot.Single())
                    .Elements(ns + "dict")
                    .Elements(ns + "key")
                where (node.Value == "Artist")
                    //|| node.Value == "Album Artist"
                    //|| node.Value == "Composer")
                    && ((XElement)node.NextNode).Value.Trim().ToLower() == artist
                select node.Parent;

            // collect all persistent IDs from these dict elements
            var tracks =
                from node in artistTracks.Elements(ns + "key")
                where node.Value == "Persistent ID"
                select PersistentID.Parse(((XElement)node.NextNode).Value);

            PersistentIDCollection list = new PersistentIDCollection(tracks.ToList<PersistentID>());

            return list;
        }
        /// <summary>
        /// Release managed resources
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DoClosed(object sender, EventArgs e)
        {
            if (percentageCompleted > 0)
            {
                controller.Librarian.ProgressChanged -= new ProgressChangedEventHandler(DoProgressChanged);
            }

            this.Closed -= new EventHandler(DoClosed);
            this.Closing -= new CancelEventHandler(DoClosing);

            if (percentageCompleted == 100)
            {
                string location = PathHelper.CleanDirectoryPath(locationBox.Text.Trim());

                if (!String.IsNullOrEmpty(location))
                {
                    Settings.Default.ExportPlaylistFormat = ((ComboBoxItem)playlistBox.SelectedItem).Tag as string;
                    Settings.Default.ExportSubdirectories = (bool)treeCheck.IsChecked;
                    Settings.Default.ExportLocation = location;
                    Settings.Default.Save();
                }
            }

            controller = null;
            trackPIDs = null;

            // clear the encoderBox UI control
            encoderBox.SelectedItem = null;

            foreach (ComboBoxItem item in encoderBox.Items)
            {
                item.Content = null;
            }

            encoderBox.Items.Clear();

            // dispose the encoders collection
            encoders.Dispose();
            encoders = null;
        }
Exemple #21
0
        //----------------------------------------------------------------------------------------

        /// <summary>
        /// Invoked when the Sync button is pressed, starts the synchronization process.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void DoSync(object sender, RoutedEventArgs e)
        {
            string text = String.Format(Resx.SyncWarningText, selector.Location);

            MessageBoxResult result = MessageWindow.Show(
                null, text, Resx.SyncWarningCaption,
                MessageBoxButton.OKCancel, MessageWindowImage.Warning, MessageBoxResult.Cancel);

            if (result != MessageBoxResult.OK)
            {
                e.Handled = true;
                return;
            }

            countBox.Visibility      = Visibility.Hidden;
            playlistBox.IsEnabled    = false;
            selector.IsEnabled       = false;
            syncButton.Visibility    = Visibility.Collapsed;
            progressPanel.Visibility = Visibility.Visible;

            string format       = PathHelper.GetPathFormat(selector.FormatTag);
            bool   withPlaylist = format.Contains("playlist");

            var list = new PersistentIDCollection();

            using (var selectedPlaylists = new PlaylistCollection())
            {
                selectedPlaylists.AddRange(playlists.FindAll(p => p.IsSelected == true));

                foreach (Playlist playlist in selectedPlaylists.Values)
                {
                    if (playlist != null)
                    {
                        PersistentID pid = playlist.PersistentID;

                        PersistentIDCollection tracks =
                            controller.Librarian.Catalog.FindTracksByPlaylist(pid);

                        if (withPlaylist)
                        {
                            // Cannot modify a value type (PersistentID) from within a foreach loop
                            // or the .ForEach extension method, so we need to recreate each pid
                            // to set the playlist name.  Unfortunate design consequence...
                            foreach (PersistentID track in tracks)
                            {
                                PersistentID tid = track;
                                tid.PlaylistName = playlist.Name;
                                list.Add(tid);
                            }
                        }
                        else
                        {
                            list.AddRange(tracks);
                        }
                    }
                }
            }

            // show iTunes incase a protection fault occurs; otherwise you cannot see the
            // dialog if iTunes is minimized as a Taskbar toolbar
            controller.ShowiTunes();

            controller.Librarian.ProgressChanged += new ProgressChangedEventHandler(DoProgressChanged);
            controller.Librarian.Export(list, selector.Location, format);
        }
Exemple #22
0
 /// <summary>
 /// Verifies playlists in the catalog against a list of known existing playlists.
 /// </summary>
 /// <param name="playlistPIDs">
 /// A collection of existing playlist persistent IDs; any playlist not referenced
 /// in the list will be removed from the catalog.
 /// </param>
 public abstract void RefreshPlaylists(PersistentIDCollection playlistPIDs);
Exemple #23
0
        /// <summary>
        /// Retrieves a list of all tracks found in the given playlist.
        /// </summary>
        /// <param name="playlistID">The unique PersistentID of the playlist to examine.</param>
        /// <returns></returns>
        /// <remarks>
        /// iTunes allows users to create multiple playlists with the same name.  So we
        /// must use the PersistentID of the playlist instead of its canonical name.
        /// </remarks>
        public override PersistentIDCollection FindTracksByPlaylist(PersistentID playlistID)
        {
            if (!isReady)
            {
                return new PersistentIDCollection();
            }

            // find the <plist><dict><key>Playlists</key><array> root node
            var playlistRoot =
                from node in root
                    .Element(ns + "dict")
                    .Elements(ns + "key")
                where node.Value == "Playlists"
                select node.NextNode;

            // find the parent <array><dict> node of the named playlist
            // <array><dict><key>Name</key><string>Library</string>
            var playlistNodes =
                from node in ((XElement)playlistRoot.Single())
                    .Elements(ns + "dict")
                    .Elements(ns + "key")
                where node.Value == "Playlist Persistent ID"
                    && ((XElement)node.NextNode).Value == (string)playlistID
                select node.Parent;

            // collect all Track ID values from this playlist
            var trackIDs =
                from node in ((XElement)playlistNodes.Single())
                    .Elements(ns + "array")
                    .Elements(ns + "dict")
                    .Elements(ns + "key")
                where node.Value == "Track ID"
                select node.NextNode;

            // find the <plist><dict><key>Tracks</key><dict> root node
            var trackRoot =
                from node in root
                    .Element(ns + "dict")
                    .Elements(ns + "key")
                where node.Value == "Tracks"
                select node.NextNode;

            // join tracks on trackID to extract the persistent IDs
            var tracks =
                from node in
                    (from node in ((XElement)trackRoot.Single()).Elements(ns + "key")
                     join id in trackIDs on ((XElement)node).Value equals ((XElement)id).Value
                     select ((XElement)node.NextNode)
                    ).Elements(ns + "key")
                where ((XElement)node).Value == "Persistent ID"
                select PersistentID.Parse(((XElement)node.NextNode).Value);

            PersistentIDCollection list = new PersistentIDCollection(tracks.ToList<PersistentID>());
            return list;
        }
        /// <summary>
        /// Removes a playlist from the catalog.
        /// </summary>
        private void RemovePlaylist()
        {
            PersistentIDCollection playlistPIDs = new PersistentIDCollection();
            foreach (Playlist playlist in controller.Playlists.Values)
            {
                if (playlist != null)
                {
                    playlistPIDs.Add(playlist.PersistentID);
                    playlist.Dispose();
                }
            }

            if (playlistPIDs.Count > 0)
            {
                catalog.RefreshPlaylists(playlistPIDs);
            }
        }
        /// <summary>
        /// Adds one or more tracks to an existing playlist in the catalog.
        /// </summary>
        private void AddTracksToPlaylist()
        {
            PersistentID playlistPID = controller.GetPersistentID(action.PlaylistOID);
            if (!playlistPID.IsEmpty)
            {
                PersistentIDCollection trackPIDs = new PersistentIDCollection();

                ObjectIDCollection trackOIDs = action.TrackOIDs;
                foreach (ObjectID trackOID in trackOIDs)
                {
                    PersistentID trackPID = controller.GetPersistentID(trackOID);
                    if (!trackPID.IsEmpty)
                    {
                        trackPID.TransientID = trackOID.TrackID;
                        trackPIDs.Add(trackPID);
                    }
                }

                if (trackPIDs.Count > 0)
                {
                    catalog.AddTracksToPlaylist(trackPIDs, playlistPID);
                }
            }
        }
Exemple #26
0
 /// <summary>
 /// Adds a track entry to the specified playlist.
 /// </summary>
 /// <param name="playlistPID"></param>
 /// <param name="trackPIDs"></param>
 public override void AddTracksToPlaylist(
     PersistentIDCollection trackPIDs, PersistentID playlistPID)
 {
 }
Exemple #27
0
 /// <summary>
 /// Verifies playlists in the catalog against a list of known existing playlists.
 /// </summary>
 /// <param name="playlistPIDs">
 /// A collection of existing playlist persistent IDs; any playlist not referenced
 /// in the list will be removed from the catalog.
 /// </param>
 public override void RefreshPlaylists(PersistentIDCollection playlistPIDs)
 {
 }
Exemple #28
0
 /// <summary>
 /// Adds one or more tracks to the specified playlist.
 /// </summary>
 /// <param name="playlistPID"></param>
 /// <param name="trackPIDs"></param>
 public abstract void AddTracksToPlaylist(
     PersistentIDCollection trackPIDs, PersistentID playlistPID);
Exemple #29
0
        /// <summary>
        /// Scan all tracks in the given playlist.
        /// </summary>
        /// <param name="list"></param>
        private void ScanTracks(PersistentIDCollection pids)
        {
            foreach (PersistentID persistentID in pids)
            {
                if (base.isActive)
                {
                    using (Track track = libraryPlaylist.GetTrack(persistentID))
                    {
                        if ((track != null) && (track.Kind == TrackKind.File))
                        {
                            //Logger.WriteLine(base.name, "ScanTrying " + track.MakeKey());

                            if (String.IsNullOrEmpty(track.Location) || !File.Exists(track.Location))
                            {
                                Logger.WriteLine(base.name,
                                    "Deleting phantom track " + track.MakeKey());

                                try
                                {
                                    if (ScannerBase.isLive)
                                    {
                                        // deletes library entry but not physical media file
                                        track.Delete();
                                    }
                                }
                                catch (Exception exc)
                                {
                                    Logger.WriteLine(base.name,
                                        String.Format("Error deleting phantom {0}, {1}, {2}",
                                        track.Artist, track.Name, track.Album), exc);
                                }
                            }
                        }
                    }

                    count++;
                    base.ProgressPercentage = (int)((double)count / (double)total * 100.0);
                }
                else
                {
                    Logger.WriteLine(base.name, "Phantom scanner cancelled while scanning");
                    break;
                }
            }
        }
Exemple #30
0
        /// <summary>
        /// Get a lits of iTunes Tracks given a list of track IDs.
        /// </summary>
        /// <param name="trackIDs"></param>
        /// <returns></returns>
        protected TrackCollection GetTracks(PersistentIDCollection persistentIDs)
        {
            TrackCollection tracks = new TrackCollection();

            foreach (PersistentID persistentID in persistentIDs)
            {
                Track track = controller.LibraryPlaylist.GetTrack(persistentID);
                if (track != null)
                {
                    tracks.Add(track);
                }
            }

            return tracks;
        }
Exemple #31
0
        public void FindCatalogedTracksByArtist()
        {
            // FlatCatalog

            ICatalog catalog = new FlatCatalog();
            catalog.Initialize(libraryXMLPath);
            Console.WriteLine(String.Format("new FlatCatalog() -> {0} ms", watch.GetSplitMilliseconds()));

            PersistentIDCollection trackIDs = catalog.FindTracksByArtist("Guster");
            Console.WriteLine(String.Format("FindTracksByArtist/Flat -> {0} ms", watch.GetSplitMilliseconds()));

            Assert.IsNotNull(trackIDs);
            Assert.AreNotEqual(0, trackIDs.Count);
            Console.WriteLine(String.Format("Found {0} tracks", trackIDs.Count));
            ReportPrivateDelta();

            // TerseCatalog

            catalog = new TerseCatalog();
            catalog.Initialize(libraryXMLPath);
            Console.WriteLine(String.Format("new TerseCatalog() -> {0} ms", watch.GetSplitMilliseconds()));

            trackIDs = catalog.FindTracksByArtist("Guster");
            Console.WriteLine(String.Format("FindTracksByArtist/Terse -> {0} ms", watch.GetSplitMilliseconds()));

            Assert.IsNotNull(trackIDs);
            Assert.AreNotEqual(0, trackIDs.Count);
            Console.WriteLine(String.Format("Found {0} tracks", trackIDs.Count));
            ReportPrivateDelta();

            // Controller

            trackIDs = new PersistentIDCollection();
            foreach (Track track in controller.LibraryPlaylist.Tracks.Values)
            {
                if ((track != null) && !String.IsNullOrEmpty(track.Artist))
                {
                    if (track.Artist.Equals("Guster"))
                    {
                        trackIDs.Add(track.PersistentID);
                    }
                }
            }

            Console.WriteLine(String.Format("FindTracksByArtist/Controller -> {0} ms", watch.GetSplitMilliseconds()));

            // iTunes

            trackIDs = new PersistentIDCollection();
            foreach (IITTrack track in itunes.LibraryPlaylist.Tracks)
            {
                if ((track != null) && !String.IsNullOrEmpty(track.Artist))
                {
                    if (track.Artist.Equals("Guster"))
                    {
                        trackIDs.Add(GetPersistentID(track));
                    }
                }
            }

            Console.WriteLine(String.Format("FindTracksByArtist/iTunes -> {0} ms", watch.GetSplitMilliseconds()));

            Assert.IsNotNull(trackIDs);
            Assert.AreNotEqual(0, trackIDs.Count);
            Console.WriteLine(String.Format("Found {0} tracks", trackIDs.Count));
            ReportPrivateDelta();
        }