Пример #1
0
        public static List <string[]> DownloadYoutube(string cmd, string sender, MatrixRoom room)
        {
            JObject[]       videos = Downloaders.YoutubeGetData(cmd);
            List <string[]> output = new List <string[]>(videos.Length);
            List <Task>     tasks  = new List <Task> ();

            foreach (JObject data in videos)
            {
                //Check Length
                int seconds = data["duration"].ToObject <int>();
                int max     = int.Parse(Configuration.Config["youtube"]["maxlength"]);
                if (seconds > max)
                {
                    throw new Exception("Video exceeds duration limit of " + Math.Round(max / 60f, 1) + " minutes");
                }
                string filename = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(data["fulltitle"].ToObject <string>()));
                Task   t        = new Task(() => { Downloaders.YoutubeDownload(data["webpage_url"].ToObject <string>(), filename); });
                t.Start();
                tasks.Add(t);
                output.Add(new string[2] {
                    filename + ".ogg", data["title"].ToObject <string>()
                });
            }
            System.Threading.Tasks.Task.WaitAll(tasks.ToArray(), TimeSpan.FromSeconds(20 * videos.Length));
            return(output);
        }