Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="medium"></param>
        /// <param name="spPlaylist"></param>
        public Playlist(SpotiFire.Playlist spPlaylist, Medium medium)
            : base(spPlaylist.Name, medium)
        {
            var link = spPlaylist.GetLink();
            this.AltId = link.ToString();
            link.Dispose();

            this.Master = medium.MasterContainer;
        }
Example #2
0
 /// <summary>
 /// Updates the track with the properties of the given Spotify track
 /// </summary>
 /// <param name="spTrack">The Spotify track to update to</param>
 public void Update(SpotiFire.Track spTrack)
 {
     this.Title = spTrack.Name;
     this.Artist = spTrack.FirstArtist();
     this.Album = spTrack.Album.Name;
     this.AlbumArtist = spTrack.Album.Artist.Name;
     this.DiscNumber = (uint)spTrack.Disc;
     this.TrackNumber = (uint)spTrack.Index;
     this.Duration = spTrack.Duration;
     this.AltId = spTrack.GetLink().ToString();
 }
 /// <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;
 }
 /// <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;
 }
 /// <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;
 }
 /// <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);
         }
     }
 }
Example #7
0
 /// <summary>
 /// Constructs a new Track object
 /// </summary>
 /// <param name="file">The FileInfo object of the music file</param>
 public Track(SpotiFire.Track spTrack)
 {
     this.Update(spTrack);
 }
Example #8
0
 public StarredPlaylist(SpotiFire.Playlist spPlaylist, Medium medium)
     : base(spPlaylist, medium)
 {
 }
        void TrackTracks(SpotiFire.Playlist playlist) {
            if (playlist.IsTrackingTracks())
                return;

            playlist.SetTrackingTracks(true);
            this.AddTracks(playlist);
            playlist.Tracks.CollectionChanged += tracks_CollectionChanged;
        }
 /// <summary>
 /// Called when the image of a playlist is changed
 /// </summary>
 void playlist_ImageChanged(SpotiFire.Playlist sender, PlaylistEventArgs e) {
     throw new NotImplementedException();
 }
 /// <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);
 }
 /// <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");
 }
 /// <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);
 }
        /// <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;
        }
 /// <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);
     }
 }
 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());
         }
     }
 }
 void LogPlaylistSimple(SpotiFire.Playlist playlist, string ev, PlaylistEventArgs e = null) {
     lock (this) {
         Console.WriteLine("= " + ev.ToUpper() + " - " + (playlist.IsLoaded ? playlist.Name : "<unknown>"));
     }
 }
 void AddTracks(SpotiFire.Playlist playlist) {
     this.AddTracks(playlist, playlist.Tracks);
 }
Example #19
0
 internal virtual bool Update(SpotiFire.Playlist spPlaylist)
 {
     this.Name = spPlaylist.Name;
     this.Collaborative = spPlaylist.IsCollaborative;
     return true;
 }
        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");
                }
            }
        }
Example #21
0
 internal override bool Update(SpotiFire.Playlist spPlaylist)
 {
     return false;
 }
        void RemoveTracks(SpotiFire.Playlist playlists, IEnumerable<SpotiFire.Track> tracks) {
            foreach (var track in tracks) {

            }
        }
 /// <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;
 }
 /// <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;
     }
 }