Пример #1
0
    protected virtual void OnBtnQueueSongClicked(object sender, System.EventArgs e)
    {
        HTreeNode theNode = tvLibrary.SelectedNode;

        // Check if node has children
        if (theNode.Nodes.Count > 0)
        {
            // Will add all children to queue
        }
        else
        {
            // Node is a leaf (song)
            SubsonicItem theItem = GetNodeItem(theNode);

            // Confirm that the item is  asong
            if (theItem.itemType == SubsonicItem.SubsonicItemType.Song)
            {
                //slPlaylist.Items.Add(theItem);

                Dictionary <string, string> songId = new Dictionary <string, string>();
                songId.Add("id", theItem.id);
                string streamURL = Subsonic.BuildDirectURL("download.view", songId);

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName  = "vlc";
                proc.StartInfo.Arguments = "--one-instance --playlist-enqueue " + streamURL;
                proc.Start();
            }
        }
    }
Пример #2
0
        private static SubsonicAPI.LoginResult HandleLogin(string host, string username, string password)
        {
            server = host;
            user   = username;

            return(Subsonic.LogIn(server, user, password));
        }
Пример #3
0
        private void UpdateAlbumListView(string theID)
        {
            LastAlbumId = theID;

            MusicFolder FolderContents = Subsonic.GetMusicDirectory(theID);

            lbAlbums.BeginUpdate();
            lbAlbums.Items.Clear();

            if (AlbumListHistory.Peek() != "Root")
            {
                lbAlbums.Items.Add(new MusicFolder("..", AlbumListHistory.Peek()));
            }

            foreach (MusicFolder mf in FolderContents.Folders)
            {
                lbAlbums.Items.Add(mf);
            }

            foreach (Song sg in FolderContents.Songs)
            {
                lbAlbums.Items.Add(sg);
            }

            lbAlbums.EndUpdate();
        }
Пример #4
0
        public void PersistValues()
        {
            var settings  = GetFormSettings();
            var isChanged = Subsonic.IsSettingChanged(settings);

            if (isChanged)
            {
                var saved = Subsonic.SaveSettings(settings);
                if (saved && settings.UseIndexCache)
                {
                    var dialog = MessageBox.Show(
                        @"Settings saved successfully. Do you want to regenerate the local cache file?",
                        @"Regenerate local cache?",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question,
                        MessageBoxDefaultButton.Button2);
                    if (dialog == DialogResult.Yes)
                    {
                        DeleteCacheFile();
                    }
                }

                if (Subsonic.IsInitialized)
                {
                    Subsonic.Refresh();
                }
                else
                {
                    Subsonic.SendNotificationsHandler.Invoke(Subsonic.Initialize()
                        ? Interfaces.Plugin.CallbackType.StorageReady
                        : Interfaces.Plugin.CallbackType.StorageFailed);
                }
            }
        }
Пример #5
0
 public override void Execute(IPlayer player, params string[] parameters)
 {
     foreach (KeyValuePair <String, Song> p in Subsonic.GetNowPlaying())
     {
         ConsoleUtils.UOut(ConsoleColor.Yellow, "{0} => {1} {2}", p.Key, p.Value.Name, p.Value.Id);
     }
 }
Пример #6
0
        public override void Execute(IPlayer player, params string[] parameters)
        {
            if (parameters.Length == 1)
            {
                ConsoleUtils.UOut(ConsoleColor.Red, "You didn't enter a song id. use like this : (/listsongs 213)");
                return;
            }
            string songid = parameters[1];

            try
            {
                Song sg = Subsonic.GetSong(songid);
                if (sg == null)
                {
                    ConsoleUtils.UOut(ConsoleColor.Red, "unable to add song -> song result was null");
                }
                else
                {
                    player.AddSong(sg);
                }
            }
            catch (Exception e)
            {
                //todo log
                ConsoleUtils.UOut(ConsoleColor.Red, "unable to add song");
            }
        }
Пример #7
0
        private Song GetRandomSong()
        {
            var artists   = Subsonic.GetArtistIndexes();
            var artistKey = artists.Values.OrderBy(r => randomLazy.Next()).FirstOrDefault();
            var albumKey  = Subsonic.GetAlbumIds(artistKey);
            var songs     = GetSongIds(albumKey.OrderBy(rd => randomLazy.Next()).FirstOrDefault());

            return(songs.OrderBy(r => randomLazy.Next()).FirstOrDefault(sng => sng != null));
        }
Пример #8
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            DataTable dtArtists = new DataTable();

            #region fetch data for artists

            Mono.Data.Sqlite.SqliteConnection  cn      = new Mono.Data.Sqlite.SqliteConnection("library.sqlite");
            Mono.Data.Sqlite.SqliteCommand     comm    = new Mono.Data.Sqlite.SqliteCommand(cn);
            Mono.Data.Sqlite.SqliteDataAdapter adapter = new Mono.Data.Sqlite.SqliteDataAdapter(comm);
            comm.CommandText = @"
SELECT  name, id, fetched
FROM    artists
";
            adapter.Fill(dtArtists);

            #endregion

            if (dtArtists.Rows.Count == 0)
            {
                List <SubsonicItem> artists = Subsonic.GetIndexes();

                foreach (SubsonicItem artist in artists)
                {
                    DataRow dr = dtArtists.NewRow();
                    dr["name"]     = artist.name;
                    dr["id"]       = artist.id;
                    dr["feteched"] = DateTime.Now.ToString();
                    dtArtists.Rows.Add(dr);

                    comm             = new Mono.Data.Sqlite.SqliteCommand(cn);
                    comm.CommandText = @"
INSERT INTO artists (name, id, fetched)
VALUES(@name, @id, @fetched);
";
                    comm.Parameters.AddWithValue("@name", artist.name);
                    comm.Parameters.AddWithValue("@id", artist.id);
                    comm.Parameters.AddWithValue("@fetched", DateTime.Now.ToString());

                    if (cn.State != ConnectionState.Open)
                    {
                        cn.Open();
                    }
                    comm.ExecuteNonQuery();
                }

                if (cn.State != ConnectionState.Closed)
                {
                    cn.Close();
                }
            }

            rptArtists.DataSource = dtArtists;
            rptArtists.DataBind();
        }
Пример #9
0
    protected virtual void OnBtnSearchClicked(object sender, System.EventArgs e)
    {
        string search = tbSearch.Text;

        List <SubsonicItem> results = Subsonic.Search(search);

        foreach (SubsonicItem si in results)
        {
            slPlaylist.Items.Add(si);
        }
    }
Пример #10
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            string server   = tbServer.Text;
            string user     = tbUser.Text;
            string password = tbPassword.Text;

            string result = Subsonic.LogIn(server, user, password);

            tbResults.Text = result;

            btnGetSongs.Enabled = true;
        }
Пример #11
0
        public override void Execute(IPlayer player, params string[] parameters)
        {
            if (parameters.Length == 1)
            {
                ConsoleUtils.UOut(ConsoleColor.Red, "You didn't enter an album id. use like this : (/listsongs 211)");
                return;
            }
            string albumid = parameters[1];

            foreach (Song songadong in Subsonic.ListSongsByAlbumId(albumid))
            {
                ConsoleUtils.UOut(ConsoleColor.Yellow, "{0} ({1})", songadong.Name, songadong.Id);
            }
        }
Пример #12
0
        protected void btnLogIn_Click(object sender, System.EventArgs e)
        {
            string server   = "thefij.kicks-ass.net:4040";
            string username = tbUsername.Text;
            string password = tbPassword.Text;

            Subsonic.appName = "IansWebApp";
            string results = Subsonic.LogIn(server, username, password);

            if (results != "")
            {
                Response.Redirect("Library.aspx");
            }
        }
Пример #13
0
        public static SubsonicSettings ReadSettingsFromFile(string settingsFilename)
        {
            var settings = new SubsonicSettings();

            try
            {
                if (!File.Exists(settingsFilename))
                {
                    return(Subsonic.GetCurrentSettings());
                }

                using (var reader = new StreamReader(settingsFilename))
                {
                    var protocolText = AesEncryption.Decrypt(reader.ReadLine(), Passphrase);

                    settings.Protocol = protocolText.Equals("HTTP")
                        ? SubsonicSettings.ConnectionProtocol.Http
                        : SubsonicSettings.ConnectionProtocol.Https;
                    settings.Host      = AesEncryption.Decrypt(reader.ReadLine(), Passphrase);
                    settings.Port      = AesEncryption.Decrypt(reader.ReadLine(), Passphrase);
                    settings.BasePath  = AesEncryption.Decrypt(reader.ReadLine(), Passphrase);
                    settings.Username  = AesEncryption.Decrypt(reader.ReadLine(), Passphrase);
                    settings.Password  = AesEncryption.Decrypt(reader.ReadLine(), Passphrase);
                    settings.Transcode = AesEncryption.Decrypt(reader.ReadLine(), Passphrase) == "Y";
                    settings.Auth      = AesEncryption.Decrypt(reader.ReadLine(), Passphrase) == "HexPass"
                        ? SubsonicSettings.AuthMethod.HexPass
                        : SubsonicSettings.AuthMethod.Token;
                    settings.BitRate = AesEncryption.Decrypt(reader.ReadLine(), Passphrase);

                    if (string.IsNullOrEmpty(settings.BitRate))
                    {
                        settings.BitRate = "Unlimited";
                    }

                    settings.UseIndexCache = AesEncryption.Decrypt(reader.ReadLine(), Passphrase) == "Y";

                    return(settings);
                }
            }
            catch (Exception ex)
            {
                const string caption = "Error while trying to load settings";
                MessageBox.Show($@"An error occurred while trying to load the settings file! Reverting to defaults...

Exception: {ex}",
                                caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(Subsonic.GetCurrentSettings());
            }
        }
Пример #14
0
        private void ButtonPing_Click(object sender, EventArgs e)
        {
            var settings = GetFormSettings();

            var pingResult = Subsonic.PingServer(settings);

            if (pingResult)
            {
                const string text    = "The server responded normally";
                const string caption = "Ping response OK";
                MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                const string text    = "The server did not respond to Ping as expected!";
                const string caption = "Ping response not OK";
                MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #15
0
        private static void EnterMainLoop()
        {
            string Argument    = "";
            bool   exitProgram = false;

            ThePlayer.SongFinished += HandleSongFinished;

            while (!exitProgram)
            {
                string ln = Console.ReadLine();

                if (ln.StartsWith("/"))
                {
                    if (ln.StartsWith("/exit"))   //todo : yuck.
                    {
                        exitProgram = true;
                        continue;
                    }
                    CliCommandFactory.Execute(ThePlayer, ln);
                }
                else
                {
                    if (!string.IsNullOrEmpty(ln))
                    {
                        Subsonic.AddChatMessage(ln);
                    }
                }
                //todo : messages should be fetched async so we get more of a live chat idea
                //todo : i keep seeing the whole message log. this sucks
                IOrderedEnumerable <ChatMessage> messages = Subsonic.GetChatMessages(LastMsgDate).OrderBy(cm => cm.Date);

                foreach (var msg in messages)
                {
                    if (msg.Date >= LastMsgDate)
                    {
                        ConsoleUtils.UOut(ConsoleColor.Cyan, msg.ToString());
                    }
                }
                LastMsgDate = messages.Max(msg => msg.Date);
            }
            ThePlayer.Stop();
        }
Пример #16
0
        public override void Execute(IPlayer player, params string[] parameters)
        {
            if (parameters.Length == 1)
            {
                ConsoleUtils.UOut(ConsoleColor.Red, "You didn't enter an artist/band name. use like this : (/listalbums rammstein) (/listalbums the cure)");
                return;
            }
            string artistName = String.Join(" ", parameters.ToList().Skip(1)).ToLowerInvariant();

            foreach (KeyValuePair <string, string> artist in Subsonic.GetArtistIndexes())
            {
                if (artist.Key.ToLowerInvariant().Contains(artistName))
                {
                    foreach (var album in Subsonic.ListAlbums(artist.Value))
                    {
                        ConsoleUtils.UOut(ConsoleColor.Yellow, "({0}) {1} - {2}", artist.Key, album.Key, album.Value);
                    }
                }
            }
        }
Пример #17
0
        private void UpdateAll()
        {
            var currentSettings = Subsonic.GetCurrentSettings();

            TextBoxHostname.Text = currentSettings.Host;
            TextBoxPort.Text     = currentSettings.Port;
            TextBoxPath.Text     = currentSettings.BasePath;
            TextBoxUsername.Text = currentSettings.Username;
            TextBoxPassword.Text = currentSettings.Password;

            CheckBoxTranscode.Checked    = currentSettings.Transcode;
            ComboBoxBitrate.SelectedItem =
                string.IsNullOrEmpty(currentSettings.BitRate)
                    ? "128K"
                    : currentSettings.BitRate;
            ComboBoxBitrate.Enabled = CheckBoxTranscode.Checked;

            ComboBoxProtocol.SelectedItem = currentSettings.Protocol.ToFriendlyString();
            ComboBoxAuth.SelectedIndex    = (int)currentSettings.Auth;
        }
Пример #18
0
    protected virtual void OnBtnLogin2Clicked(object sender, System.EventArgs e)
    {
        string server    = tbServer.Text;
        string user      = tbUsername.Text;
        string passw0rdd = tbPaassw0rd.Text;

        string loginResult = Subsonic.LogIn(server, user, passw0rdd);

        Console.WriteLine("Login Result: " + loginResult);

        SubsonicItem thisLibrary = Subsonic.MyLibrary;

        foreach (SubsonicItem artist in thisLibrary.children)
        {
            HTreeNode artistNode = new HTreeNode(artist.name);
            tvLibrary.Nodes.Add(artistNode);

            // Adding a dummy node for the artist
            artistNode.Nodes.Add(new HTreeNode(""));
        }
    }
Пример #19
0
        private void PersistValues()
        {
            var settings  = GetFormSettings();
            var isChanged = Subsonic.IsSettingChanged(settings);

            if (!isChanged)
            {
                return;
            }

            var saved = Subsonic.SaveSettings(settings);

            if (Subsonic.IsInitialized)
            {
                Subsonic.Refresh();
            }
            else
            {
                Subsonic.SendNotificationsHandler.Invoke(Subsonic.Initialize()
                   ? Interfaces.Plugin.CallbackType.StorageReady
                   : Interfaces.Plugin.CallbackType.StorageFailed);
            }
        }
Пример #20
0
        private void btnGetSongs_Click(object sender, EventArgs e)
        {
            artists = Subsonic.GetIndexes();
            tvArtists.BeginUpdate();

            string firstLetter = "";
            int    treeIndex   = -1;

            foreach (KeyValuePair <string, string> kvp in artists)
            {
                string thisFirstLetter = GetFirstLetter(kvp.Key);
                if (thisFirstLetter != firstLetter)
                {
                    firstLetter = thisFirstLetter;
                    tvArtists.Nodes.Add(firstLetter);
                    treeIndex++;
                }

                tvArtists.Nodes[treeIndex].Nodes.Add(kvp.Key);
            }

            tvArtists.EndUpdate();
        }
Пример #21
0
        private WaveStream CreateInputStream()
        {
            WaveChannel32 inputStream;

            Stream stream = Subsonic.StreamSong(currentSong.id);

            // Try to move this filling of memory stream into the background...
            Stream ms = new MemoryStream();

            byte[] buffer = new byte[32768];
            int    read;

            while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
            {
                playerThread.ReportProgress(50);

                ms.Write(buffer, 0, read);
            }

            ms.Position = 0;

            WaveStream mp3Reader          = new Mp3FileReader(ms);
            WaveStream pcmStream          = WaveFormatConversionStream.CreatePcmStream(mp3Reader);
            WaveStream blockAlignedStream = new BlockAlignReductionStream(pcmStream);

            inputStream = new WaveChannel32(blockAlignedStream);

            // we are not going into a mixer so we don't need to zero pad
            //((WaveChannel32)inputStream).PadWithZeroes = false;
            volumeStream = inputStream;

            //var meteringStream = new MeteringStream(inputStream, inputStream.WaveFormat.SampleRate / 10);
            //meteringStream.StreamVolume += new EventHandler<StreamVolumeEventArgs>(meteringStream_StreamVolume);

            return(volumeStream);
        }
Пример #22
0
        /// <summary>
        /// Method that plays whatever the current song is
        /// </summary>
        private void playSong()
        {
            skipThis = false;
            Stream stream = Subsonic.StreamSong(currentSong.id);

            // Try to move this filling of memory stream into the background...
            Stream ms = new MemoryStream();

            byte[] buffer = new byte[32768];
            int    read;

            while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
            {
                playerThread.ReportProgress(50);

                ms.Write(buffer, 0, read);
            }

            ms.Position = 0;
            Mp3FileReader mp3Reader          = new Mp3FileReader(ms);
            WaveStream    blockAlignedStream =
                new BlockAlignReductionStream(
                    WaveFormatConversionStream.CreatePcmStream(mp3Reader));
            WaveOut waveOut;

            waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback());
            waveOut.Init(blockAlignedStream);
            waveOut.Play();
            playState = PlaybackState.Playing;
            bool songEnd = false;

            while (playState != PlaybackState.Stopped && !songEnd && !skipThis)
            {
                if (waveOut.PlaybackState == PlaybackState.Stopped)
                {
                    songEnd = true;
                }
                else
                {
                    switch (playState)
                    {
                    case PlaybackState.Paused:
                        waveOut.Pause();
                        break;

                    case PlaybackState.Playing:
                        if (waveOut.PlaybackState != PlaybackState.Playing)
                        {
                            waveOut.Play();
                        }
                        else
                        {
                            int progress = (int)(100.0 * mp3Reader.CurrentTime.TotalSeconds / mp3Reader.TotalTime.TotalSeconds);
                            playerThread.ReportProgress(progress);
                            Thread.Sleep(100);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            //if (playState == PlaybackState.Stopped)
            waveOut.Stop();
            //waveOut.Dispose();
        }
Пример #23
0
        private static IEnumerable <Song> GetSongIds(string albumKey)
        {
            MusicFolder albumContens = Subsonic.GetMusicDirectory(albumKey);

            return(albumContens.Songs);
        }
Пример #24
0
        public void Play()
        {
            if (State == PlayState.Playing)
            {
                Stop();
            }

            if (_playThread == null)
            {
                _playThread = new Thread(new ThreadStart(ProgressThread));
            }

            if (State == PlayState.Paused)
            {
                Pause();
            }
            else if (PlayQueue.Count > 0)
            {
                State = PlayState.Playing;
                if (CurrentSong == null)
                {
                    CurrentSong = PlayQueue.Dequeue();
                    PlayedSongs.Enqueue(CurrentSong);
                }
            }
            else
            {
                //nothing to play
                Stop();
            }

            if (State == PlayState.Playing)
            {
                if (CurrentSong == null)
                {
                    CurrentSong = PlayQueue.Peek();
                }
                if (!CurrentSong.IsPlayable || (!Config.Instance.PlayWavs && CurrentSong.FileType.ToLowerInvariant() == "wav"))
                {
                    Console.ResetColor();
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.Out.WriteLine("cannot play song. skipping.");
                    Console.ResetColor();
                    Skip();
                    return;
                }

                State = PlayState.Playing;
                ConsoleUtils.UOut(ConsoleColor.DarkGreen, "downloading...");
                //todo : this should happen in a background thread.
                byte[] songBytes = Subsonic.PreloadSong(CurrentSong.Id);
                _hgcFile = GCHandle.Alloc(songBytes, GCHandleType.Pinned);
                ConsoleUtils.UOut(ConsoleColor.DarkGreen, "download complete.");

                _currentSongChannel = Bass.BASS_StreamCreateFile(_hgcFile.AddrOfPinnedObject(), 0, songBytes.Length, BASSFlag.BASS_SAMPLE_FLOAT);
                Bass.BASS_ChannelPlay(_currentSongChannel, false);

                if (!_playThread.IsAlive)
                {
                    if (_playThread.ThreadState == ThreadState.Running)
                    {
                        _playThread.Join();
                    }
                    _playThread = new Thread(new ThreadStart(ProgressThread));
                    _playThread.Start();
                }
            }
        }