public async Task <List <PlayableBase> > GetTracks(ProgressDialogController controller)
            {
                var alltracks = SearchTotalResults.Number;

                var resultList = new List <PlayableBase>();
                var counter    = 0;

                for (int i = 0; i < (int)Math.Ceiling((double)alltracks / 50); i++)
                {
                    var tracks = YouTubeApi.GetPlaylistTracks(await YouTubeApi.GetPlaylist(PlaylistId.Text, counter, 50));
                    for (int j = 0; j < tracks.Count; j++)
                    {
                        var track = tracks[j];
                        if (LoadingTracksProcessChanged != null)
                        {
                            LoadingTracksProcessChanged(this, new LoadingTracksEventArgs(counter + j, alltracks, track.Title));
                        }
                        if (await track.CheckIfAvailable())
                        {
                            resultList.Add(await track.ToPlayable());
                        }
                        if (controller.IsCanceled)
                        {
                            return(null);
                        }
                    }
                    counter += 50;
                }
                return(resultList);
            }
Esempio n. 2
0
        public void Search()
        {
            var api = new YouTubeApi();
            var sw = Stopwatch.StartNew();

            var task1 = api.Search("eminem");
            task1.Wait();
            Trace.WriteLine(string.Format("valid youtube search in {0} ms", sw.ElapsedMilliseconds));
            Assert.IsTrue(task1.Result != null && task1.Result.Count > 0);

            sw.Restart();
            var task2 = api.Search("H897g8983r34r&/R(%/&OBIUA=()/G=AD(||||-ojwrej");
            task2.Wait();
            Trace.WriteLine(string.Format("invalid youtube search in {0} ms", sw.ElapsedMilliseconds));
            Assert.IsTrue(task2.Result.Count == 0);
        }
Esempio n. 3
0
        public void UrlDetection()
        {
            var api = new YouTubeApi();
            var sw = Stopwatch.StartNew();

            var task1 = api.CheckForSpecialUrl(VideoTestUrl1);
            task1.Wait();
            Trace.WriteLine(string.Format("detect valid video url and download information in {0} ms", sw.ElapsedMilliseconds));
            Assert.IsTrue(task1.Result.Item1);
            Assert.IsNotNull(task1.Result.Item2);
            Assert.IsNull(task1.Result.Item3);

            sw.Restart();
            var task2 = api.CheckForSpecialUrl(VideoTestUrl2);
            task2.Wait();
            Trace.WriteLine(string.Format("detect valid video url and download information in {0} ms", sw.ElapsedMilliseconds));
            Assert.IsTrue(task2.Result.Item1);
            Assert.IsNotNull(task2.Result.Item2);
            Assert.IsNull(task2.Result.Item3);

            sw.Restart();
            var task3 = api.CheckForSpecialUrl(VideoPlaylistTestUrl);
            task3.Wait();
            Trace.WriteLine(string.Format("detect valid playlist url and download information in {0} ms", sw.ElapsedMilliseconds));
            Assert.IsTrue(task3.Result.Item1);
            Assert.IsNotNull(task3.Result.Item2);
            Assert.IsNotNull(task3.Result.Item3);

            sw.Restart();
            var task4 = api.CheckForSpecialUrl(PlaylistUrl);
            task4.Wait();
            Trace.WriteLine(string.Format("detect valid playlist url and download information in {0} ms", sw.ElapsedMilliseconds));
            Assert.IsTrue(task4.Result.Item1);
            Assert.IsNotNull(task4.Result.Item2);
            Assert.IsNotNull(task4.Result.Item3);

            sw.Restart();
            var task5 = api.CheckForSpecialUrl("garcon");
            Trace.WriteLine(string.Format("detect invalid url in {0} ticks", sw.ElapsedTicks));
            Assert.IsFalse(task5.Result.Item1);
        }