protected ContainerPlaylist(Session session, PlaylistContainer container, IntPtr playlistPtr, IntPtr folderId, sp_playlist_type type)
     : base(session, playlistPtr, true)
 {
     this.folderId = folderId;
     this.container = container;
     this.type = type;
 }
Exemple #2
0
        private async void Form1_Load(object sender, EventArgs e)
        {
            while (true)
            {
                var login  = new Login(session);
                var result = login.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    break;
                }
                else if (result == System.Windows.Forms.DialogResult.Cancel)
                {
                    Application.Exit();
                    return;
                }
            }

            pc = await session.PlaylistContainer;
            List <Playlist> playlists = new List <Playlist>(pc.Playlists.Count);

            foreach (var playlist in pc.Playlists)
            {
                playlists.Add(await playlist);
            }

            foreach (var playlist in playlists)
            {
                listView1.Items.Add(new PlaylistListViewItem(playlist));
            }
        }
Exemple #3
0
        /// <summary>
        /// Change playlist container. The response comes as plain XML.
        /// </summary>
        public void SendChangePlaylistContainer(IChannelListener listener, PlaylistContainer playlistContainer, string xml)
        {
            /* Create channel and buffer. */
            Channel.Channel channel = new Channel.Channel("Change-Playlist-Container-Channel", Channel.ChannelType.TYPE_PLAYLIST, listener);
            byte[]          bytes   = Encoding.UTF8.GetBytes(xml);
            ByteBuffer      buffer  = ByteBuffer.Allocate(2 + 16 + 1 + 4 + 4 + 4 + 1 + 1 + bytes.Length);

            /* Append channel id, playlist id and some bytes... */
            buffer.PutShort((short)channel.Id);
            buffer.Put(Hex.ToBytes("00000000000000000000000000000000")); /* 16 bytes */
            buffer.Put((byte)0x00);                                      /* Playlists identifier. */
            buffer.PutInt((int)playlistContainer.Revision);
            buffer.PutInt(playlistContainer.Playlists.Count);
            buffer.PutInt((int)playlistContainer.Checksum);
            buffer.Put((byte)0x00); /* Collaborative */
            buffer.Put((byte)0x03); /* Unknown */
            buffer.Put(bytes);
            buffer.Flip();

            /* Register channel. */
            Channel.Channel.Register(channel);

            /* Send packet. */
            this.SendPacket(Command.COMMAND_CHANGEPLAYLIST, buffer);
        }
Exemple #4
0
        public static void ShutDown()
        {
            bool wasLoggedIn = Session.IsLoggedIn;

            lock (_syncObj)
            {
                if (wasLoggedIn)
                {
                    libspotify.sp_session_player_unload(Session.GetSessionPtr());
                    libspotify.sp_session_logout(Session.GetSessionPtr());
                    try
                    {
                        if (PlaylistContainer.GetSessionContainer() != null)
                        {
                            PlaylistContainer.GetSessionContainer().Dispose();
                        }
                    }
                    catch { }
                }
                if (_mainSignal != null)
                {
                    _mainSignal.Set();
                }
                _shutDown = true;
            }
            if (_programSignal != null)
            {
                _programSignal.WaitOne(2000, false);
            }
        }
Exemple #5
0
        private PlaylistContainer ParsePlaylistContainer()
        {
            PlaylistContainer playlists = new PlaylistContainer();
            string            name;

            /* Go to next element and check if it is a start element. */
            this.Next();
            while (this.reader.IsStartElement())
            {
                name = this.reader.LocalName;

                if (name.Equals("base-version"))
                {
                    this.SkipBaseVersion();
                }
                else if (name.Equals("next-change"))
                {
                    this.ParseNextChange(playlists);
                }
                else
                {
                    throw new XMLParserException("Unexpected element '<" + name + ">'");
                }

                this.Next();
            }

            return(playlists);
        }
Exemple #6
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            session = await Spotify.Task;
            SetupSession();
            while (true)
            {
                var login  = new Login(session);
                var result = login.ShowDialog();
                if (result.HasValue && result.Value)
                {
                    break;
                }
                else if (result.HasValue)
                {
                    Application.Current.Shutdown();
                    return;
                }
            }

            pc = await session.PlaylistContainer;
            List <Playlist> playlists = new List <Playlist>(pc.Playlists.Count);

            foreach (var playlist in pc.Playlists)
            {
                playlists.Add(await playlist);
            }

            Playlists.ItemsSource = playlists;
        }
Exemple #7
0
        private async void Form1_Load(object sender, EventArgs e)
        {
            while (true)
            {
                var login = new Login(session);
                var result = login.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                    break;
                else if (result == System.Windows.Forms.DialogResult.Cancel)
                {
                    Application.Exit();
                    return;
                }
            }

            pc = await session.PlaylistContainer;
            List<Playlist> playlists = new List<Playlist>(pc.Playlists.Count);
            foreach (var playlist in pc.Playlists)
            {
                playlists.Add(await playlist);
            }

            foreach (var playlist in playlists)
                listView1.Items.Add(new PlaylistListViewItem(playlist));
        }
Exemple #8
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            session = await Spotify.Task;
            SetupSession();
            while (true)
            {
                var login = new Login(session);
                var result = login.ShowDialog();
                if (result.HasValue && result.Value)
                    break;
                else if (result.HasValue)
                {
                    Application.Current.Shutdown();
                    return;
                }
            }

            pc = await session.PlaylistContainer;
            List<Playlist> playlists = new List<Playlist>(pc.Playlists.Count);
            foreach (var playlist in pc.Playlists)
            {
                playlists.Add(await playlist);
            }

            Playlists.ItemsSource = playlists;
        }
Exemple #9
0
 public static List <PlaylistContainer.PlaylistInfo> GetAllSessionPlaylists()
 {
     waitFor(delegate
     {
         return(PlaylistContainer.GetSessionContainer().IsLoaded &&
                PlaylistContainer.GetSessionContainer().PlaylistsAreLoaded);
     }, REQUEST_TIMEOUT);
     return(PlaylistContainer.GetSessionContainer().GetAllPlaylists());
 }
Exemple #10
0
 public static List <PlaylistContainer.PlaylistInfo> GetPlaylists(PlaylistContainer.PlaylistInfo playlist)
 {
     waitFor(delegate
     {
         return(PlaylistContainer.GetSessionContainer().IsLoaded &&
                PlaylistContainer.GetSessionContainer().PlaylistsAreLoaded);
     }, REQUEST_TIMEOUT);
     return(PlaylistContainer.GetSessionContainer().GetChildren(playlist));
 }
Exemple #11
0
        public PlaylistContainer PlaylistContainer()
        {
            ISpotify connection = GetConnection();

            PlaylistContainer result = connection.PlaylistContainer();

            ReleaseConnection(connection);

            return(result);
        }
Exemple #12
0
 private async void updatePlaylists()
 {
     pc = await session.PlaylistContainer;
     playlistsListView.Items.Clear();
     playlistsListView.Items.Add(new PlayListViewData(await session.Starred,true));
     foreach (Playlist playlist in pc.Playlists)
     {
         playlistsListView.Items.Add(new PlayListViewData(await playlist));
     }
 }
Exemple #13
0
        public bool PlaylistContainerRemovePlaylists(PlaylistContainer playlistContainer, int position, int count)
        {
            ISpotify connection = GetConnection();

            bool result = connection.PlaylistContainerRemovePlaylists(playlistContainer, position, count);

            ReleaseConnection(connection);

            return(result);
        }
Exemple #14
0
        public bool PlaylistContainerAddPlaylists(PlaylistContainer playlistContainer, List <Playlist> playlists, int position)
        {
            ISpotify connection = GetConnection();

            bool result = connection.PlaylistContainerAddPlaylists(playlistContainer, playlists, position);

            ReleaseConnection(connection);

            return(result);
        }
Exemple #15
0
        public bool PlaylistContainerAddPlaylist(PlaylistContainer playlistContainer, Playlist playlist)
        {
            ISpotify connection = GetConnection();

            bool result = connection.PlaylistContainerAddPlaylist(playlistContainer, playlist);

            ReleaseConnection(connection);

            return(result);
        }
Exemple #16
0
        public List <PlaylistContainer.PlaylistInfo> GetAllSessionPlaylists()
        {
            var sessionContainer = PlaylistContainer.GetSessionContainer();

            WaitFor(() =>
            {
                return(sessionContainer.IsLoaded && sessionContainer.PlaylistsAreLoaded);
            }, RequestTimeout);
            return(sessionContainer.GetAllPlaylists());
        }
Exemple #17
0
        public void PlaylistContainerInstantiation()
        {
            var options = new PlaylistContainerOptions();

            SetPlaylistContainerOptions(options);
            var playlist_container = new PlaylistContainer("-1", "-1", options);

            AssertPlaylistContainer(playlist_container, options);
            AssertPlaylistContainer(playlist_container, playlist_container.GetOptions());
        }
Exemple #18
0
        //HostingEnviroment word gebruikt voor het storen van fotos
        public CustomerController(IWebHostEnvironment hostingEnviroment)
        {
            songDAL           = new SongDAL();
            userDAL           = new UserDAL();
            playlistDAL       = new PlaylistDAL();
            songContainer     = new SongContainer(songDAL);
            userContainer     = new UserContainer(userDAL);
            playlistContainer = new PlaylistContainer(playlistDAL);
            songViewModel     = new SongViewModel();
            song = new Song();

            this.hostingEnviroment = hostingEnviroment;
        }
Exemple #19
0
        private void ParseNextChange(object obj)
        {
            string name;

            /* Go to next element and check if it is a start element. */
            this.Next();
            while (this.reader.IsStartElement())
            {
                name = this.reader.LocalName;

                if (name.Equals("change"))
                {
                    this.ParseChange(obj);
                }
                else if (name.Equals("rid"))
                {
                    this.GetElementString();                 /* Skip. */
                }
                else if (name.Equals("version"))
                {
                    string[] parts = this.GetElementString().Split(',');

                    if (obj is Playlist)
                    {
                        Playlist playlist = (Playlist)obj;

                        playlist.Revision        = long.Parse(parts[0]);
                        playlist.Checksum        = long.Parse(parts[2]);
                        playlist.IsCollaborative = (int.Parse(parts[3]) == 1);
                    }
                    else if (obj is PlaylistContainer)
                    {
                        PlaylistContainer playlists = (PlaylistContainer)obj;

                        playlists.Revision = long.Parse(parts[0]);
                        playlists.Checksum = long.Parse(parts[2]);
                    }
                    else
                    {
                        throw new XMLParserException("Unexpected object '" + obj + "'");
                    }
                }
                else
                {
                    throw new XMLParserException("Unexpected element '<" + name + ">'");
                }

                this.Next();
            }
        }
Exemple #20
0
        public static PlaylistContainer GetUserPlaylists(IntPtr userPtr)
        {
            IntPtr ptr = IntPtr.Zero;

            ptr = libspotify.sp_session_publishedcontainer_for_user_create(Session.GetSessionPtr(), GetUserCanonicalNamePtr(userPtr));
            PlaylistContainer c = PlaylistContainer.Get(ptr);

            waitFor(delegate
            {
                return(c.IsLoaded &&
                       c.PlaylistsAreLoaded);
            }, REQUEST_TIMEOUT);
            return(c);
        }
Exemple #21
0
        private bool TryStartPlaylistUnlocked(String playlistName, bool random)
        {
            PlaylistContainer pc = GetPlaylistContainer();

            _currentlyPlayingPlaylist = null;
            if (pc == null)
            {
                return(false);
            }
            if (playlistName.Equals(FavoriteName))
            {
                lock (_session)
                {
                    _currentlyPlayingPlaylist = _session.StarredCreate();
                }
            }
            else
            {
                for (int i = 0; i < pc.NumPlaylists(); i++)
                {
                    Playlist list = pc.Playlist(i);
                    if (list.Name().Equals(playlistName))
                    {
                        _currentlyPlayingPlaylist = list;
                        break;
                    }
                }
            }
            if (_currentlyPlayingPlaylist == null)
            {
                return(false);
            }
            _playingOrder = Enumerable.Range(0, _currentlyPlayingPlaylist.NumTracks()).ToList();
            if (random)
            {
                List <int> straightPlayingOrder = _playingOrder.ToList();
                Random     rndGen = new Random();
                _playingOrder.Clear();
                while (straightPlayingOrder.Any())
                {
                    int index = rndGen.Next(straightPlayingOrder.Count);
                    _playingOrder.Add(straightPlayingOrder[index]);
                    straightPlayingOrder.RemoveAt(index);
                }
            }
            _currentTrackNum = 0;

            ResumeUnlocked();
            return(true);
        }
Exemple #22
0
        private List <String> GetPlaylistsUnlocked(PlaylistContainer pc)
        {
            _session.FlushCaches();
            List <String> playlists = new List <String>();

            playlists.Add(FavoriteName);
            for (int i = 0; i < pc.NumPlaylists(); i++)
            {
                if (!pc.Playlist(i).Name().Equals(String.Empty))
                {
                    playlists.Add(pc.Playlist(i).Name());
                }
            }
            return(playlists);
        }
Exemple #23
0
    public static void SavePlaylist(PlaylistContainer playlists)
    {
        DirectoryInfo dataPath = new DirectoryInfo(Application.dataPath).Parent;

        string jsonData = JsonUtility.ToJson(playlists, true);

        Debug.Log(jsonData);

        string filePath = Path.Combine(dataPath.FullName, _PlaylistFileName);

        if (File.Exists(filePath))
        {
            File.Delete(filePath);
        }
        File.WriteAllText(filePath, jsonData);
    }
Exemple #24
0
 public List <String> GetPlaylists()
 {
     if (_isValid)
     {
         _loggedInHandle.WaitOne();
         PlaylistContainer pc = GetPlaylistContainer();
         if (pc == null)
         {
             return(new List <String>());
         }
         lock (_session)
         {
             return(GetPlaylistsUnlocked(pc));
         }
     }
     return(new List <string>());
 }
Exemple #25
0
 static void AssertPlaylistContainer(PlaylistContainer playlistContainer, PlaylistContainerOptions options)
 {
     AssertContainer(playlistContainer, options);
     Assert.AreEqual(playlistContainer.StorageMedium, options.StorageMedium);
     Assert.AreEqual(playlistContainer.LongDescription, options.LongDescription);
     Assert.AreEqual(playlistContainer.Description, options.Description);
     Assert.AreEqual(playlistContainer.Date, options.Date);
     Assert.AreEqual(playlistContainer.Language, options.Language);
     Assert.IsTrue(playlistContainer.Artists.IsReadOnly);
     Assert.IsTrue(playlistContainer.Genres.IsReadOnly);
     Assert.IsTrue(playlistContainer.Contributors.IsReadOnly);
     Assert.IsTrue(playlistContainer.Rights.IsReadOnly);
     CollectionAssert.AreEqual(playlistContainer.Artists, options.Artists);
     CollectionAssert.AreEqual(playlistContainer.Genres, options.Genres);
     CollectionAssert.AreEqual(playlistContainer.Contributors, options.Contributors);
     CollectionAssert.AreEqual(playlistContainer.Rights, options.Rights);
 }
Exemple #26
0
        private void SavePlaylist(string file)
        {
            var container = new PlaylistContainer {
                Files = Files.ToArray(), Shuffle = Shuffle
            };

            try
            {
                using (var stream = File.Open(file, FileMode.Create, FileAccess.ReadWrite))
                {
                    serializerService.Serialize(container, stream);
                    stream.Flush(true);
                }
            }
            catch (Exception e)
            {
                LogException(e, MethodBase.GetCurrentMethod());
            }
        }
Exemple #27
0
        protected override void LoadComplete()
        {
            base.LoadComplete();
            game.LoadComponentSingleFile(progress = new ProgressContainer
            {
                Depth    = -1,
                Position = new Vector2(192, 614),
                Width    = 1536,
            }, Add);

            game.LoadComponentSingleFile(triangles = new Triangles {
                Velocity = 2.5f
            }, Add);
            game.LoadComponentSingleFile(coverContainer = new CoverContainer()
            {
                Position = new Vector2(192, 140),
                Size     = new Vector2(350),
            }, Add);
            game.LoadComponentSingleFile(new TitleContainer(Anchor.BottomLeft)
            {
                Position      = new Vector2(550, 140),
                TextSize      = 100,
                Font          = "Exo2.0-Bold",
                PreferredText = MetadataTypes.TitleUnicode,
                Width         = 1176,
            }, Add);
            game.LoadComponentSingleFile(new TitleContainer(Anchor.TopLeft)
            {
                Position        = new Vector2(550, 345),
                TextSize        = 70,
                Font            = "Exo2.0-Medium",
                PreferredText   = MetadataTypes.ArtistUnicode,
                Width           = 1176,
                Colour          = new Color4(200, 200, 200, 255),
                TransitionDelay = 75,
            }, Add);
            game.LoadComponentSingleFile(new Visualisation
            {
                Position = new Vector2(192, 614),
                Size     = new Vector2(1536, 460),
            }, Add);
            game.LoadComponentSingleFile(playlist = new PlaylistContainer(), Add);
        }
Exemple #28
0
    public static PlaylistContainer LoadPlaylists()
    {
        DirectoryInfo     dataPath          = new DirectoryInfo(Application.dataPath).Parent;
        PlaylistContainer playlistContainer = null;
        string            jsonData          = null;
        string            filePath          = Path.Combine(dataPath.FullName, _PlaylistFileName);

        if (File.Exists(filePath))
        {
            jsonData = File.ReadAllText(filePath);
            if (string.IsNullOrEmpty(jsonData))
            {
                playlistContainer = new PlaylistContainer();
            }
            playlistContainer = JsonUtility.FromJson <PlaylistContainer>(jsonData);
        }
        else
        {
            playlistContainer = new PlaylistContainer();
        }
        Debug.Log("LoadPlaylists: " + jsonData);
        return(playlistContainer);
    }
Exemple #29
0
        public bool PlaylistContainerAddPlaylist(PlaylistContainer playlistContainer, Playlist playlist)
        {
            ISpotify connection = GetConnection();

            bool result = connection.PlaylistContainerAddPlaylist(playlistContainer, playlist);

            ReleaseConnection(connection);

            return result;
        }
Exemple #30
0
        protected override void OnLoad(EventArgs e)
        {
            if (settings.UpdatesInterestedIn != UserSettings.UpdateType.None)
            {
                updater.CheckForNewVersion();
            }

            if (downloadedUpdate)
            {
                this.Close();
                return;
            }
            SpotifyController.Initialize();
            var appKeyBytes = Properties.Resources.spotify_appkey;

            LoadBufferWindowCommands();
            KeyManager = BufferHotkeyManager.LoadFromTextFile(this);
            string username = "", password = "";
            // the first one controls the loop, the second is the response from Libspotify's login call
            bool isLoggedIn = false, logInResponse = false;

            while (!isLoggedIn)
            {
                using (LoginWindow logon = new LoginWindow())
                {
                    var response = logon.ShowDialog();
                    if (response != DialogResult.OK)
                    {
                        this.Close();
                        output.OutputMessage(StringStore.ExitingProgram);
                        return;
                    }
                    username = logon.Username;
                    password = logon.Password;
                }
                try
                {
                    output.OutputMessage(StringStore.LoggingIn);
                    logInResponse = SpotifyController.Login(appKeyBytes, username, password);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(StringStore.ErrorDuringLoad + "\\r\\nInitialization: " + ex.Message, StringStore.Oops, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }
                if (logInResponse)
                {
                    output.OutputMessage(StringStore.LoggedInToSpotify);
                    UserSettings.Instance.Username = username;
                    UserSettings.Save();
                    spotify.SetPrivateSession(UserSettings.Instance.StartInPrivateSession);
                    isLoggedIn = true;
                }
                else
                {
                    var reason = spotify.GetLoginError().Message;
                    MessageBox.Show(reason, StringStore.LogInFailure, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            output.OutputMessage(StringStore.LoadingPlaylists, false);
            var playlists = LoadUserPlaylists();

            if (playlists == null)
            {
                return;
            }

            var playlistsBuffer = Buffers[1] as PlaylistContainerBufferList;

            if (playlistsBuffer == null)
            {
                throw new NullReferenceException("PlaylistsBuffer is null");
            }

            playlistsBuffer.Clear();
            playlists.ForEach(p =>
            {
                playlistsBuffer.Add(new PlaylistBufferItem(p));
            });
            // we put a reference to the session container on the playlists buffer
            // so that it can subscribe to playlist added and removed events and in future maybe other things
            playlistsBuffer.Model = PlaylistContainer.GetSessionContainer();

            output.OutputMessage(String.Format("{0} {1}", playlists.Count, StringStore.PlaylistsLoaded), false);
            Buffers.CurrentListIndex = 1; // start on the playllists list
            output.OutputBufferListState(Buffers, NavigationDirection.None, false);
        }
 /// <summary>
 /// Add a playlist to a playlist container.
 /// </summary>
 /// <param name="playlistContainer">A <see cref="Sharpotify.Media.PlaylistContainer"/> to add the playlist to.</param>
 /// <param name="playlist">The <see cref="Playlist"/> to be added.</param>
 /// <returns></returns>
 public bool PlaylistContainerAddPlaylist(PlaylistContainer playlistContainer, Playlist playlist)
 {
     return this.PlaylistContainerAddPlaylist(playlistContainer, playlist, playlistContainer.Playlists.Count);
 }
 /// <summary>
 /// Add a playlist to a playlist container.
 /// </summary>
 /// <param name="playlistContainer">The playlist container.</param>
 /// <param name="playlist">The playlist to be added.</param>
 /// <param name="position">The target position of the added playlist.</param>
 /// <returns></returns>
 public bool PlaylistContainerAddPlaylist(PlaylistContainer playlistContainer, Playlist playlist, int position)
 {
     List<Playlist> playlists = new List<Playlist>();
     playlists.Add(playlist);
     return this.PlaylistContainerAddPlaylists(playlistContainer, playlists, position);
 }
        /// <summary>
        /// Add multiple playlists to a playlist container.
        /// </summary>
        /// <param name="playlistContainer">The playlist container.</param>
        /// <param name="playlists">A List of playlists to be added.</param>
        /// <param name="position">The target position of the added playlists.</param>
        /// <returns></returns>
        public bool PlaylistContainerAddPlaylists(PlaylistContainer playlistContainer, List<Playlist> playlists, int position)
        {
            string user = this.session.StringUsername;
            long timestamp = DateTime.Now.Ticks;
            /* Add the playlists for new checksum calculation. */
            playlistContainer.Playlists.InsertRange(position, playlists);

            /* Build a comma separated list of tracks and append '01' to every id!. */
            string playlistList = "";

            for(int i = 0; i < playlists.Count; i++){
                playlistList += ((i > 0)?",":"") + playlists[i].Id + "02";
            }

            /* Create XML builder. */
            string xml = @"
                <change>
                    <ops>
                        <add>
                            <i> + " + position.ToString() + @"</i>
                            <items>" + playlistList + @"</items>
                        </add>
                    </ops>
                    <time>" + timestamp.ToString() + @"</time>
                    <user>" + user + @"</user>
                </change>
                <version>" +
                           (playlistContainer.Revision + 1).ToString("0000000000")+ "," +
                    playlistContainer.Playlists.Count.ToString("0000000000") + "," +
                    playlistContainer.Checksum.ToString("0000000000") + ",0</version>";

            /* Remove the playlists because we need to validate the checksum again. */
            playlistContainer.Playlists.RemoveRange(position, playlists.Count);

            /* Create channel callback */
            ChannelCallback callback = new ChannelCallback();

            /* Send change playlist request. */
            try
            {
                this.protocol.SendChangePlaylistContainer(callback, playlistContainer, xml);
            }
            catch(ProtocolException)
            {
                return false;
            }

            /* Get response. */
            byte[] data = callback.Get(this.timeout);

            /* Check confirmation. */
            PlaylistConfirmation confirmation = XMLPlaylistParser.ParsePlaylistConfirmation(data);

            if(confirmation == null)
            {
                return false;
            }

            /* Add the tracks, since operation was successful. */
            playlistContainer.Playlists.InsertRange(position, playlists);

            /* Set new revision. */
            playlistContainer.Revision = confirmation.Revision;

            return true;
        }
 /// <summary>
 /// Remove a playlist from a playlist container.
 /// </summary>
 /// <param name="playlistContainer">The playlist container.</param>
 /// <param name="position">The position of the playlist to remove.</param>
 /// <returns></returns>
 public bool PlaylistContainerRemovePlaylist(PlaylistContainer playlistContainer, int position)
 {
     return this.PlaylistContainerRemovePlaylists(playlistContainer, position, 1);
 }
        /// <summary>
        /// Remove multiple playlists from a playlist container.
        /// </summary>
        /// <param name="playlistContainer">The playlist container.</param>
        /// <param name="position">The position of the tracks to remove.</param>
        /// <param name="count">The number of track to remove.</param>
        /// <returns></returns>
        public bool PlaylistContainerRemovePlaylists(PlaylistContainer playlistContainer, int position, int count)
        {
            string user      = this.session.StringUsername;
            long   timestamp = DateTime.Now.Ticks;

            /* Create a sublist view (important!). */
            List<Playlist> playlists = new List<Playlist>();
            playlists = playlistContainer.Playlists.GetRange(position, count);

            /* First remove the playlist(s) to calculate the new checksum. */
            playlistContainer.Playlists.RemoveRange(position, count);

            /* Create XML builder. */
            string xml = @"
                <change>
                    <ops>
                        <del>
                            <i>" + position.ToString() + @"</i>
                            <k>" + count.ToString() + @"</k>
                        </del>
                    </ops>
                    <time>" + timestamp.ToString() + @"</time>
                    <user>" + user + @"</user>
                </change>
                <version>" + (playlistContainer.Revision + 1).ToString("0000000000") + "," +
                    playlistContainer.Playlists.Count.ToString("0000000000") + "," +
                    playlistContainer.Checksum.ToString("0000000000") + ",0</version>";

            /* Add the playlist(s) again, because we need the old checksum for sending. */
            playlistContainer.Playlists.InsertRange(position, playlists);

            /* Create channel callback */
            ChannelCallback callback = new ChannelCallback();

            /* Send change playlist request. */
            try{
                this.protocol.SendChangePlaylistContainer(callback, playlistContainer, xml.ToString());
            }
            catch(ProtocolException){
                return false;
            }

            /* Get response. */
            byte[] data = callback.Get(this.timeout);

            /* Check confirmation. */
            PlaylistConfirmation confirmation = XMLPlaylistParser.ParsePlaylistConfirmation(data);

            if(confirmation == null)
            {
                return false;
            }

            /* Remove the playlist(s), since operation was successful. */
            playlistContainer.Playlists.RemoveRange(position, count);

            /* Set new revision. */
            playlistContainer.Revision = confirmation.Revision;

            return true;
        }
 private void LoadPlaylists()
 {
     _playlistContainer = new PlaylistContainer();
     _playlistContainer.Load(_playlistContainerStore);
     _playlistContainer.Save(Directories);
 }
Exemple #37
0
 public PlaylistContainerBufferList(string nameIn, PlaylistContainer playlistContainerIn)
     : this(nameIn)
 {
     this.Model = playlistContainerIn;
     SetupEvents();
 }
Exemple #38
0
        public bool PlaylistContainerAddPlaylists(PlaylistContainer playlistContainer, List<Playlist> playlists, int position)
        {
            ISpotify connection = GetConnection();

            bool result = connection.PlaylistContainerAddPlaylists(playlistContainer, playlists, position);

            ReleaseConnection(connection);

            return result;
        }
Exemple #39
0
 public PlaylistCollection(PlaylistContainer playlistContainer)
 {
     UnmanagedPlaylistContainer = playlistContainer;
 }
        private PlaylistContainer ParsePlaylistContainer()
        {
            PlaylistContainer playlists = new PlaylistContainer();
            string name;

            /* Go to next element and check if it is a start element. */
            this.Next();
            while (this.reader.IsStartElement())
            {
                name = this.reader.LocalName;

                if (name.Equals("base-version"))
                {
                    this.SkipBaseVersion();
                }
                else if (name.Equals("next-change"))
                {
                    this.ParseNextChange(playlists);
                }
                else
                    throw new XMLParserException("Unexpected element '<" + name + ">'");

                this.Next();
            }

            return playlists;
        }
Exemple #41
0
        public bool PlaylistContainerRemovePlaylists(PlaylistContainer playlistContainer, int position, int count)
        {
            ISpotify connection = GetConnection();

            bool result = connection.PlaylistContainerRemovePlaylists(playlistContainer, position, count);

            ReleaseConnection(connection);

            return result;
        }
 internal static IContainerPlaylist Get(Session session, PlaylistContainer container, IntPtr playlistPtr, IntPtr folderId, sp_playlist_type type)
 {
     KeyGen key = new KeyGen(playlistPtr, folderId, type);
     ContainerPlaylist playlist;
     lock (playlistsLock)
     {
         if (!playlists.ContainsKey(key))
         {
             playlists.Add(key, new ContainerPlaylist(session, container, playlistPtr, folderId, type));
         }
         playlist = playlists[key];
         playlist.AddRef();
     }
     return new ContainerPlaylistWrapper(playlist);
 }