private void PopulateCollection(JObject response) { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { try { string id = ""; foreach (JObject entry in response["feed"]["entry"]) { Entry newent = new Entry(); newent.PlaylistID = plentry.Id; newent.EntryID = (string)entry["id"]["$t"]; string[] splittat = { "playlist:" }; newent.EntryID = newent.EntryID.Split(splittat, StringSplitOptions.None)[1].Split(':')[1]; newent.Id = (string)entry["media$group"]["yt$videoid"]["$t"]; newent.Title = (string)entry["title"]["$t"]; newent.ImageSource = (string)entry["media$group"]["media$thumbnail"][0]["url"]; string dura = (string)entry["media$group"]["yt$duration"]["seconds"]; newent.Duration = TimeSpan.FromSeconds(double.Parse(dura)); foreach (JObject jo in entry["link"]) { string src; if ((string)jo["type"] == "text/html" && (string)jo["rel"] == "alternate") { src = (string)jo["href"]; string[] src_split = src.Split('&'); newent.Source = src_split[0]; break; } } if (newent.Source == null) { throw new WebException("Cant get Video Address from API"); } id = newent.Id; string filename = plentry.Id + "\\" + id + ".mp3"; string offline = "Not Synced"; SolidColorBrush col = new SolidColorBrush(Colors.Red); if (ISOHelper.FileExists(filename)) { offline = "Available offline"; col.Color = Colors.Green; } newent.AvailablityColor = col; newent.Offline = offline; tracklistentry.Add(newent); } } catch (Exception ex) { ErrorLogging.Log(this.GetType().ToString(), ex.Message, "ViewModelTracklist", "probablyJSONResponse"); } }); completed = true; }
public void GetApiResponse() { string filename = "cache/" + plentry.Id + ".json"; if (ISOHelper.FileExists(filename)) { apijson = JObject.Parse(ISOHelper.ReadFromFile(filename)); PopulateCollection(apijson); } else { string url = plentry.Source + "&alt=json" + "&fields=entry(id,title,link,media:group(yt:videoid,media:thumbnail,yt:duration))" + "&access_token=" + IsolatedStorageSettings.ApplicationSettings["access_token"]; GET(url); } }
private void GetApiResponse() { string filename; IsolatedStorageSettings.ApplicationSettings.TryGetValue("cache_filename", out filename); if (ISOHelper.FileExists(filename)) { apijson = JObject.Parse(ISOHelper.ReadFromFile(filename)); PopulateCollection(apijson); } else { string url = "https://gdata.youtube.com/feeds/mobile/users/default/playlists?" + "v=2&alt=json" + "&fields=author,entry(yt:playlistId,content,title,yt:countHint,updated,media:group(media:thumbnail))" + "&access_token=" + IsolatedStorageSettings.ApplicationSettings["access_token"]; GET(url); } }
void MainPage_Loaded(object sender, RoutedEventArgs e) { ToggleProgressBar("Loading..."); string filename; IsolatedStorageSettings.ApplicationSettings.TryGetValue("cache_filename", out filename); webBrowser1.IsScriptEnabled = true; if (Network.IsConnected()) { TimeSpan token_validity; DateTime request_time; int token_expires_in = 0; string refresh_token; IsolatedStorageSettings.ApplicationSettings.TryGetValue("request_time", out request_time); IsolatedStorageSettings.ApplicationSettings.TryGetValue("expires_in", out token_expires_in); IsolatedStorageSettings.ApplicationSettings.TryGetValue("refresh_token", out refresh_token); token_validity = DateTime.Now - request_time; navigate_clear = true; if (refresh_token != null && token_validity.TotalSeconds < token_expires_in) { auth.RefreshToken(); } else if (refresh_token != null) { auth.RefreshToken(); } else { webBrowser1.Navigate(new Uri(auth.getAuthURI(), UriKind.Absolute)); } } else if (ISOHelper.FileExists(filename)) { NavigationService.Navigate(new Uri("/Pages/Playlist.xaml", UriKind.Relative)); } else { MessageBox.Show("No connectivity to internet and no cache available"); ToggleProgressBar("No connectivity"); } }
private void DoOfflineSync() { if (App.GlobalOfflineSync.SOURCES.Count > 0) { proindicator.IsVisible = true; proindicator.Text = "Download Failed. Already in progress"; return; } //OfflineSyncExt.DestinationInfo dinfo = new FileDownloader.DestinationInfo(); using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) { if (!iso.DirectoryExists(plentry.Id)) { iso.CreateDirectory(plentry.Id); } } int select = 0; if (listBox1.SelectedIndex > -1) { select = listBox1.SelectedIndex; } for (int i = 0; i < viewmodel.tracklistentry.Count; i++) { if (select == viewmodel.tracklistentry.Count) { select = 0; } var listEntry = viewmodel.tracklistentry[select]; string filename = plentry.Id + "\\" + listEntry.Id + ".mp3"; if (ISOHelper.FileExists(filename)) { select++; continue; } //dinfo.Title = listEntry.Title; //dinfo.Source = listEntry.Source; //dinfo.Destination = filename; App.GlobalOfflineSync.SOURCES.Add(listEntry); select++; } try { if (App.GlobalOfflineSync.SOURCES.Count > 0) { App.GlobalOfflineSync.Cancelled = false; App.GlobalOfflineSync.Next(); } else { System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { proindicator.IsVisible = true; proindicator.Text = "Sync Completed."; }); } } catch (Exception e) { //ErrorLogging.Log(e.Message); ErrorLogging.Log(this.GetType().ToString(), e.Message, "TracklistSyncError", string.Empty); } }