public static PlaylistData ExtractPlaylistData(string html)
        {
            var playlistData = new PlaylistData();
            playlistData.Items = new List<PlaylistDataItem>();
            playlistData.Description = "UK Top 40 singles: http://www.bbc.co.uk/radio1/chart/singles";
            playlistData.Title = string.Format("UK Top 40 {0:D} ", ExtractDate(html));
            playlistData.SearchKeys = new List<string>();

            var regexChartItem = new Regex(@"<td>(?<Position>.*?)</td>.*?<td>(?<Status>.*?)</td>.*?<td>(?<Previous>.*?)</td>.*?<td>(?<Weeks>.*?)</td>.*?<td>(?<Artist>.*?)</td>.*?<td>(?<Title>.*?)</td>", RegexOptions.Singleline);
            var matches = regexChartItem.Matches(html);

            foreach (Match m in matches)
            {
                var item = new PlaylistDataItem()
                {
                    Position = HtmlUtilities.ConvertToText(m.Groups["Position"].Value).ToInt(),
                    Status = HtmlUtilities.ConvertToText(m.Groups["Status"].Value),
                    Weeks = HtmlUtilities.ConvertToText(m.Groups["Weeks"].Value).ToInt(),
                    Previous = HtmlUtilities.ConvertToText(m.Groups["Previous"].Value).ToInt(),
                    Artist = HtmlUtilities.ConvertToText(m.Groups["Artist"].Value),
                    Title = HtmlUtilities.ConvertToText(m.Groups["Title"].Value)
                };

                playlistData.Items.Add(item);

                var searchKey = string.Format("{0} {1}", item.Artist, item.Title);
                playlistData.SearchKeys.Add(searchKey);
            }

            return playlistData;
        }
        public static PlaylistData ExtractPlaylistData(string html)
        {
            var playlistData = new PlaylistData();

            playlistData.Items       = new List <PlaylistDataItem>();
            playlistData.Description = "UK Top 40 singles: http://www.bbc.co.uk/radio1/chart/singles";
            playlistData.Title       = string.Format("UK Top 40 {0:D} ", ExtractDate(html));
            playlistData.SearchKeys  = new List <string>();

            var regexChartItem = new Regex(@"<td>(?<Position>.*?)</td>.*?<td>(?<Status>.*?)</td>.*?<td>(?<Previous>.*?)</td>.*?<td>(?<Weeks>.*?)</td>.*?<td>(?<Artist>.*?)</td>.*?<td>(?<Title>.*?)</td>", RegexOptions.Singleline);
            var matches        = regexChartItem.Matches(html);

            foreach (Match m in matches)
            {
                var item = new PlaylistDataItem()
                {
                    Position = HtmlUtilities.ConvertToText(m.Groups["Position"].Value).ToInt(),
                    Status   = HtmlUtilities.ConvertToText(m.Groups["Status"].Value),
                    Weeks    = HtmlUtilities.ConvertToText(m.Groups["Weeks"].Value).ToInt(),
                    Previous = HtmlUtilities.ConvertToText(m.Groups["Previous"].Value).ToInt(),
                    Artist   = HtmlUtilities.ConvertToText(m.Groups["Artist"].Value),
                    Title    = HtmlUtilities.ConvertToText(m.Groups["Title"].Value)
                };

                playlistData.Items.Add(item);

                var searchKey = string.Format("{0} {1}", item.Artist, item.Title);
                playlistData.SearchKeys.Add(searchKey);
            }

            return(playlistData);
        }
Пример #3
0
        public async Task GetPlaylistData(IPlaylistSource playlistSource, Action <PlaylistData, Exception> callback)
        {
            PlaylistData playlistData = null;
            Exception    err          = null;

            try
            {
                playlistData = await playlistSource.GetPlaylistAsync();
            }
            catch (Exception ex)
            {
                err = ex;
            }

            callback(playlistData, err);
        }
Пример #4
0
        private PlaylistData CreateTestlist()
        {
            var playlistData = new PlaylistData();

            playlistData.Items       = new List <PlaylistDataItem>();
            playlistData.Description = "Test playlist";
            playlistData.Title       = string.Format("{0} playlist", Query);
            playlistData.SearchKeys  = new List <string>();

            var item1 = new PlaylistDataItem()
            {
                Artist = "Above & Beyond",
                Title  = "Lonely Girl"
            };

            var item2 = new PlaylistDataItem()
            {
                Artist = "Schiller",
                Title  = "I Feel You"
            };

            var item3 = new PlaylistDataItem()
            {
                Artist = "Radiohead",
                Title  = "Creep"
            };

            var item4 = new PlaylistDataItem()
            {
                Artist = "Avril Lavigne",
                Title  = "Nobody's Home"
            };

            playlistData.Items.Add(item1);
            playlistData.Items.Add(item2);
            playlistData.Items.Add(item3);
            playlistData.Items.Add(item4);

            foreach (var item in playlistData.Items)
            {
                var searchKey = string.Format("{0} {1}", item.Artist, item.Title);
                playlistData.SearchKeys.Add(searchKey);
            }

            return(playlistData);
        }
        private PlaylistData CreateTestlist()
        {
            var playlistData = new PlaylistData();
            playlistData.Items = new List<PlaylistDataItem>();
            playlistData.Description = "Test playlist";
            playlistData.Title = string.Format("{0} playlist", Query);
            playlistData.SearchKeys = new List<string>();

            var item1 = new PlaylistDataItem()
            {
                Artist = "Above & Beyond",
                Title = "Lonely Girl"
            };

            var item2 = new PlaylistDataItem()
            {
                Artist = "Schiller",
                Title = "I Feel You"
            };

            var item3 = new PlaylistDataItem()
            {
                Artist = "Radiohead",
                Title = "Creep"
            };

            var item4 = new PlaylistDataItem()
            {
                Artist = "Avril Lavigne",
                Title = "Nobody's Home"
            };

            playlistData.Items.Add(item1);
            playlistData.Items.Add(item2);
            playlistData.Items.Add(item3);
            playlistData.Items.Add(item4);

            foreach (var item in playlistData.Items)
            {
                var searchKey = string.Format("{0} {1}", item.Artist, item.Title);
                playlistData.SearchKeys.Add(searchKey);
            }

            return playlistData;
        }
Пример #6
0
        public async void GetBBCPlaylistData(Action <PlaylistData, Exception> callback)
        {
            var          testFileUri  = new Uri("ms-appx:///Assets/TestChart.html");
            PlaylistData playlistData = null;
            Exception    err          = null;

            try
            {
                var file = await StorageFile.GetFileFromApplicationUriAsync(testFileUri);

                var html = await FileIO.ReadTextAsync(file);

                playlistData = BBCTop40PlaylistSource.ExtractPlaylistData(html);
            }
            catch (Exception ex)
            {
                err = ex;
            }
            callback(playlistData, err);
        }
        private PlaylistData CreatePlaylistDataFromEchoNestResponse(PlaylistResponse searchResponse)
        {
            var playlistData = new PlaylistData();
            playlistData.Items = new List<PlaylistDataItem>();
            playlistData.Description = Query;
            playlistData.Title = string.Format("{0} playlist", Query);
            playlistData.SearchKeys = new List<string>();

            foreach (var song in searchResponse.Songs)
            {
                var item = new PlaylistDataItem();
                item.Artist = song.ArtistName;
                item.Title = song.Title;
                playlistData.Items.Add(item);

                var searchKey = string.Format("{0} {1}", item.Artist, item.Title);
                playlistData.SearchKeys.Add(searchKey);
            }

            return playlistData;
        }
        private PlaylistData CreateEchonestPlaylist(string apiKey)
        {
            var seedArtists = new TermList();

            seedArtists.Add(Query);

            StaticArgument staticArgument = new StaticArgument
            {
                Results = 40,
                Artist = seedArtists,
                Type = "artist-radio"
            };

            using (var session = new EchoNestSession(apiKey))
            {
                PlaylistResponse searchResponse = session.Query<Static>().Execute(staticArgument);
                var playlistData = new PlaylistData();
                playlistData.Items = new List<PlaylistDataItem>();
                playlistData.Description = Query;
                playlistData.Title = string.Format("{0} playlist", Query);
                playlistData.SearchKeys = new List<string>();

                foreach (var song in searchResponse.Songs)
                {
                    var item = new PlaylistDataItem();
                    item.Artist = song.ArtistName;
                    item.Title = song.Title;
                    playlistData.Items.Add(item);

                    var searchKey = string.Format("{0} {1}", item.Artist, item.Title);
                    playlistData.SearchKeys.Add(searchKey);
                }

                return playlistData;
            }
        }
Пример #9
0
        private PlaylistData CreateEchonestPlaylist(string apiKey)
        {
            var seedArtists = new TermList();

            seedArtists.Add(Query);

            StaticArgument staticArgument = new StaticArgument
            {
                Results = 40,
                Artist  = seedArtists,
                Type    = "artist-radio"
            };

            using (var session = new EchoNestSession(apiKey))
            {
                PlaylistResponse searchResponse = session.Query <Static>().Execute(staticArgument);
                var playlistData = new PlaylistData();
                playlistData.Items       = new List <PlaylistDataItem>();
                playlistData.Description = Query;
                playlistData.Title       = string.Format("{0} playlist", Query);
                playlistData.SearchKeys  = new List <string>();

                foreach (var song in searchResponse.Songs)
                {
                    var item = new PlaylistDataItem();
                    item.Artist = song.ArtistName;
                    item.Title  = song.Title;
                    playlistData.Items.Add(item);

                    var searchKey = string.Format("{0} {1}", item.Artist, item.Title);
                    playlistData.SearchKeys.Add(searchKey);
                }

                return(playlistData);
            }
        }
Пример #10
0
 PlaylistData CreatePlaylistDataFromArtistAndTitle(string artist, string title)
 {
     var playlistData = new PlaylistData();
     playlistData.Items = new List<PlaylistDataItem>();
     var searchKey = string.Format("{0} - {1}", artist, title);
     playlistData.Description = searchKey;
     playlistData.Title = searchKey;
     playlistData.SearchKeys = new List<string>();
     var item = new PlaylistDataItem();
     item.Artist = artist;
     item.Title = title;
     playlistData.Items.Add(item);
     playlistData.SearchKeys.Add(searchKey);
     return playlistData;
 }
Пример #11
0
        void UpdateVideoInfo(IDataService service, PlaylistData playlistData, int selectedIndex = -1)
        {
            service.GetVideoInfo(playlistData, (videos, err) =>
             {
                 if (err == null)
                 {
                     foreach (var video in videos)
                     {
                         PlaylistItems[video.Index].VideoId = video.VideoId;
                         PlaylistItems[video.Index].Thumbnail = video.ThumbnailUrl;
                         PlaylistItems[video.Index].VideoId = video.VideoId;
                     }

                     if (selectedIndex > 0 && selectedIndex < PlaylistItems.Count)
                     {
                         this.SelectedItem = PlaylistItems[selectedIndex];
                     }
                 }
                 else
                 {
                    /// if there is an error should create a property and bind to it for better practices
                    System.Diagnostics.Debug.WriteLine(err.ToString());
                 }
             });
        }
Пример #12
0
 void UpdatePlaylist(IDataService service, PlaylistData playlistData, int selectedIndex = -1)
 {
     var playlistItems = new ObservableCollection<PlaylistItemViewModel>();
     foreach (var item in playlistData.Items)
     {
         playlistItems.Add(new PlaylistItemViewModel(item));
     }
     this._playlistData = playlistData;
     this.PlaylistItems = playlistItems;
     this.UpdateVideoInfo(service, playlistData, selectedIndex);
 }
Пример #13
0
        public IList<VideoInfo> GetMockVideoInfo(PlaylistData playlistData)
        {
            var ds = new MockDataService();
            var completion = new ManualResetEvent(false);
            IList<VideoInfo> result = null;

            ds.GetVideoInfo(playlistData, (videoInfo, err) =>
            {
                result = videoInfo;
                completion.Set();
            });

            completion.WaitOne();
            return result;
        }