Esempio n. 1
0
 /// <summary>
 /// Introduce a playlist to the environment. This sets the Known value of the playlist
 /// to true and binds the necessary events.
 /// TODO: move content-related change binds to somewhere else, so they are only called
 /// when we already have a touchee representation of the playlist
 /// </summary>
 void Introduce(SpotiFire.Playlist playlist)
 {
     playlist.SetKnown(true);
     playlist.ImageChanged     += playlist_ImageChanged;
     playlist.MetadataUpdated  += playlist_MetadataUpdated;
     playlist.Renamed          += playlist_Renamed;
     playlist.UpdateInProgress += playlist_UpdateInProgress;
 }
Esempio n. 2
0
        /// <summary>
        /// Called when a playlist is removed
        /// </summary>
        void playlist_Renamed(SpotiFire.Playlist sender, PlaylistEventArgs e)
        {
            var toucheePlaylist = GetToucheePlaylist(sender);

            if (toucheePlaylist != null)
            {
                toucheePlaylist.Update(sender);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Forget a playlist. This sets the Known value of the Playlist to false and unbinds
 /// all the events.
 /// </summary>
 void Forget(SpotiFire.Playlist playlist)
 {
     playlist.SetKnown(false);
     playlist.ImageChanged             -= playlist_ImageChanged;
     playlist.MetadataUpdated          -= playlist_MetadataUpdated;
     playlist.Renamed                  -= playlist_Renamed;
     playlist.UpdateInProgress         -= playlist_UpdateInProgress;
     playlist.StateChanged             -= playlist_StateChanged;
     playlist.Tracks.CollectionChanged -= tracks_CollectionChanged;
 }
Esempio n. 4
0
        /// <summary>
        /// Removes the playlist
        /// </summary>
        /// <param name="playlist">The playlist to remove</param>
        void RemovePlaylist(SpotiFire.Playlist playlist)
        {
            var toucheePlaylist = GetToucheePlaylist(playlist);

            if (toucheePlaylist != null)
            {
                toucheePlaylist.Dispose();
            }
            Forget(playlist);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates or updates the Touchee data for the given SpotiFire playlist
        /// </summary>
        /// <param name="playlist">The SpotiFire playlist that should be created or updated</param>
        /// <returns>The resulting Touchee Playlist</returns>
        Spotify.Media.Playlist CreateOrUpdate(SpotiFire.Playlist playlist)
        {
            var toucheePlaylist = GetToucheePlaylist(playlist);

            // Process only 'real' playlists
            if (playlist.Type != PlaylistType.Playlist)
            {
                //Log("IGNORING PLAYLIST: " + playlist.Type.ToString());
                return(null);
            }

            // Collect some vars
            var isAlbum   = playlist.IsAlbum();
            var isStarred = playlist == _session.Starred;

            // Playlist is an Album, so should not be seen as playlist, but the tracks need to be added to the library
            if (isAlbum && !isStarred)
            {
                // This playlist is not known yet, so the tracks for this playlist should be tracked.
                // This can occur more than once!
                if (toucheePlaylist == null)
                {
                    //LogPlaylistSimple(playlist, "album");
                    this.TrackTracks(playlist);
                }
                // If the playlist is known, it means that the playlist "has become an album".
                // So we delete the playlist. The track events are already bound
                else
                {
                    //LogPlaylistSimple(playlist, "playlist became album");
                    toucheePlaylist.Dispose();
                }
            }

            // Playlist is actually a playlist and not yet present
            else if (toucheePlaylist == null)
            {
                //LogPlaylistSimple(playlist, "create");
                toucheePlaylist = isStarred
                    ? new StarredPlaylist(playlist, Touchee.Medium.Local)
                    : new Spotify.Media.Playlist(playlist, Touchee.Medium.Local);
                toucheePlaylist.Save();
                this.TrackTracks(playlist);
            }

            // We have to update the playlist
            else
            {
                //LogPlaylistSimple(playlist, "update");
                toucheePlaylist.Update(playlist);
            }

            return(toucheePlaylist);
        }
Esempio n. 6
0
 /// <summary>
 /// Called when an update action of a introduced playlist is started or has ended.
 /// If the playlist is in the playlist container and the update is completed,
 /// the playlist will be stored / updated.
 /// </summary>
 void playlist_UpdateInProgress(SpotiFire.Playlist sender, PlaylistEventArgs e)
 {
     lock (sender) {
         //LogPlaylist(sender, "update in progress", e);
         sender.SetUpdateInProgress(!e.UpdateComplete);
         if (this.IsInSession(sender) && e.UpdateComplete)
         {
             CreateOrUpdate(sender);
         }
     }
 }
Esempio n. 7
0
        void TrackTracks(SpotiFire.Playlist playlist)
        {
            if (playlist.IsTrackingTracks())
            {
                return;
            }

            playlist.SetTrackingTracks(true);
            this.AddTracks(playlist);
            playlist.Tracks.CollectionChanged += tracks_CollectionChanged;
        }
Esempio n. 8
0
 public static void SetKnown(this SpotiFire.Playlist playlist, bool known)
 {
     if (known)
     {
         if (!playlist.IsKnown())
         {
             _playlistStatus[playlist] = new PlaylistHandlerStatus();
         }
     }
     else
     {
         _playlistStatus.Remove(playlist);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Called when a playlist is added to the playlist container.
 /// When the playlist is fully loaded, the playlist is 'introduced', meaning events
 /// changing the meta-data of this playlist will be tracked.
 /// If no pending changes are present, the playlist will be stored.
 /// Also, every playlist that is added will have its state changes tracked.
 /// </summary>
 void AddPlaylist(SpotiFire.Playlist playlist)
 {
     lock (playlist) {
         //LogPlaylist(playlist, "added");
         if (playlist.IsFullyLoaded())
         {
             Introduce(playlist);
             if (!playlist.HasPendingChanges)
             {
                 CreateOrUpdate(playlist);
             }
         }
         playlist.StateChanged += playlist_StateChanged;
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Called when the state of a playlist changes.
 /// If the playlist is in the playlist container and fully loaded, it introduces the
 /// playlist if that has not happened before.
 /// If no pending changes are present and no update is in progress, the playlist
 /// will be stored / updated.
 /// </summary>
 void playlist_StateChanged(SpotiFire.Playlist sender, PlaylistEventArgs e)
 {
     lock (sender) {
         //LogPlaylist(sender, "state changed");
         if (this.IsInSession(sender) && sender.IsFullyLoaded())
         {
             if (!sender.IsKnown())
             {
                 Introduce(sender);
             }
             if (!sender.HasPendingChanges && !sender.IsUpdateInProgress())
             {
                 CreateOrUpdate(sender);
             }
         }
     }
 }
Esempio n. 11
0
 void LogPlaylist(SpotiFire.Playlist playlist, string ev, PlaylistEventArgs e = null)
 {
     lock (this) {
         Console.WriteLine(ev.ToUpper());
         Console.WriteLine("  Playlist: " + (playlist.IsLoaded ? playlist.Name : "<unknown>"));
         Console.WriteLine("  - Loaded:             " + playlist.IsLoaded.ToString());
         Console.WriteLine("  - Known:              " + playlist.IsKnown().ToString());
         if (playlist.IsLoaded)
         {
             Console.WriteLine("  - IsCollaborative:    " + playlist.IsCollaborative.ToString());
             Console.WriteLine("  - HasPendingChanges:  " + playlist.HasPendingChanges.ToString());
             Console.WriteLine("  - IsUpdateInProgress: " + playlist.IsUpdateInProgress().ToString());
             Console.WriteLine("  - AllTracksLoaded:    " + playlist.AllTracksLoaded().ToString());
         }
         if (e != null)
         {
             Console.WriteLine("  - Update completed:   " + e.UpdateComplete.ToString());
         }
     }
 }
Esempio n. 12
0
        void AddTracks(SpotiFire.Playlist playlist, IEnumerable <SpotiFire.Track> tracks)
        {
            var toucheePlaylist = GetToucheePlaylist(playlist);

            foreach (var track in tracks)
            {
                lock (_trackUsage) {
                    var toucheeTrack = Spotify.Media.Track.FindOrDefaultByAltID <Spotify.Media.Track>(track.GetLink().ToString());

                    // Track does not exist in Touchee yet, so we add save it and add it to the master container
                    if (toucheeTrack == null)
                    {
                        toucheeTrack = new Spotify.Media.Track(track);
                        _trackUsage[toucheeTrack] = 1;
                        toucheeTrack.Save();
                        _masterPlaylist.Add(toucheeTrack);
                    }

                    // Track already exists, so we up the track usage counter
                    else
                    {
                        _trackUsage[toucheeTrack] = _trackUsage[toucheeTrack] + 1;
                    }


                    // Add to the playlist
                    if (toucheePlaylist != null)
                    {
                        toucheePlaylist.Add(toucheeTrack);
                    }

                    _trackCount++;
                    if (_trackCount % 50 == 0)
                    {
                        Log(_trackCount.ToString() + " Spotify tracks found");
                    }
                }
            }
        }
Esempio n. 13
0
 public static void SetTrackingTracks(this SpotiFire.Playlist playlist, bool tracking)
 {
     _playlistStatus[playlist].TrackingTracks = tracking;
 }
Esempio n. 14
0
 public static bool IsTrackingTracks(this SpotiFire.Playlist playlist)
 {
     return(playlist.IsKnown() && _playlistStatus[playlist].TrackingTracks);
 }
Esempio n. 15
0
 void RemoveTracks(SpotiFire.Playlist playlists, IEnumerable <SpotiFire.Track> tracks)
 {
     foreach (var track in tracks)
     {
     }
 }
Esempio n. 16
0
 void AddTracks(SpotiFire.Playlist playlist)
 {
     this.AddTracks(playlist, playlist.Tracks);
 }
Esempio n. 17
0
 /// <summary>
 /// Gets the Touchee Playlist corresponding to eht given SpotiFire playlist
 /// </summary>
 /// <param name="playlist">The SpotiFire playlist to look for</param>
 /// <returns>The corresponding Touchee playlist, or null of none is found</returns>
 Spotify.Media.Playlist GetToucheePlaylist(SpotiFire.Playlist playlist)
 {
     return(playlist.Type == PlaylistType.Playlist
         ? Spotify.Media.Playlist.FindOrDefaultByAltID <Spotify.Media.Playlist>(playlist.GetLink().ToString())
         : null);
 }
Esempio n. 18
0
 /// <summary>
 /// Called when the image of a playlist is changed
 /// </summary>
 void playlist_ImageChanged(SpotiFire.Playlist sender, PlaylistEventArgs e)
 {
     throw new NotImplementedException();
 }
Esempio n. 19
0
 public static void SetUpdateInProgress(this SpotiFire.Playlist playlist, bool inProgress)
 {
     _playlistStatus[playlist].UpdateInProgress = inProgress;
 }
Esempio n. 20
0
 public static bool IsKnown(this SpotiFire.Playlist playlist)
 {
     return(_playlistStatus.ContainsKey(playlist));
 }
Esempio n. 21
0
 /// <summary>
 /// Checks whether the given playlist is present in the session
 /// </summary>
 /// <param name="playlist">The playlist to check</param>
 /// <returns>True if the playlist resides in the PlaylistContainer, otherwise false</returns>
 bool IsInSession(SpotiFire.Playlist playlist)
 {
     return(_session.PlaylistContainer.Playlists.Contains(playlist) || playlist == _session.Starred);
 }
Esempio n. 22
0
 /// <summary>
 /// Called when the metadata of one or more tracks of a playlist is changed.
 /// </summary>
 void playlist_MetadataUpdated(SpotiFire.Playlist sender, PlaylistEventArgs e)
 {
     //LogPlaylist(sender, "metadata updated");
 }
Esempio n. 23
0
 void LogPlaylistSimple(SpotiFire.Playlist playlist, string ev, PlaylistEventArgs e = null)
 {
     lock (this) {
         Console.WriteLine("= " + ev.ToUpper() + " - " + (playlist.IsLoaded ? playlist.Name : "<unknown>"));
     }
 }
Esempio n. 24
0
 public static bool IsUpdateInProgress(this SpotiFire.Playlist playlist)
 {
     return(playlist.IsKnown() && _playlistStatus[playlist].UpdateInProgress);
 }