Пример #1
0
        public static void DownloadTrack(string cmd, string sender, MatrixRoom room)
        {
            try
            {
                List <string[]> videos = new List <string[]>();
                if (Downloaders.YoutubeGetIDFromURL(cmd) != "")
                {
                    videos = DownloadYoutube(cmd, sender, room);
                }
                else if (Uri.IsWellFormedUriString(cmd, UriKind.Absolute))
                {
                    videos = new List <string[]>();
                    videos.Add(DownloadGeneric(cmd, sender, room));
                }
                else
                {
                    room.SendNotice("Sorry, that type of URL isn't supported right now :/");
                    return;
                }

                Program.MPCClient.RequestLibraryUpdate();
                //Program.MPCClient.Idle("update");//Wait for it to start
                Program.MPCClient.Idle("update");                //Wait for it to finish

                foreach (string[] res in videos)
                {
                    Program.MPCClient.AddFile(res[0]);
                }

                Program.MPCClient.Status();

                                #if DEBUG
                Console.WriteLine(JObject.FromObject(Program.MPCClient.lastStatus));
                                #endif

                int position = Program.MPCClient.lastStatus.playlistlength;
                if (position == 1)
                {
                    Program.MPCClient.Play();
                    room.SendNotice("Started playing " + videos[0][1] + " | " + Configuration.Config["mpc"]["streamurl"]);
                }
                else
                {
                    room.SendNotice(videos[0][1] + " has been queued at position " + position + ".");
                }
            }
            catch (Exception e) {
                room.SendNotice("There was an issue with that request, " + sender + ": " + e.Message);
                Console.Error.WriteLine(e);
            }
        }