private static void SetWatchlistValues(Video originai, Video updated = null) { DateTime runTime = DateTime.Now; var watchListTag = TagRecord.Create(originai.Id.HasValue ? originai.Id.Value : -1, TagType.WatchList); if (updated == null) { originai.Created = originai.Updated = runTime; originai.AddTag(watchListTag); } else { originai.Updated = runTime; originai.AddTag(watchListTag); if (updated.Tags != null) { foreach (var t in updated.Tags.Values) { originai.AddTag(t); } } } }
private RefreshResults RefreshRecentlyAdded() { var list = Browser.GetRecentlyAddedVideos(); List <Video> added = new List <Video>(); List <Video> duplicates = new List <Video>(); List <Video> failedIds = new List <Video>(); DateTime runTime = DateTime.Now; foreach (Video v in list) { var existing = DataStore.GetExistingVideo(v.Type, v.AmazonId, v.Title); if (existing == null) { v.Created = v.Updated = runTime; v.AddTag(TagRecord.Create(-1, TagType.New)); if ((from i in added where i.AmazonId == v.AmazonId || i.Title == v.Title select i).FirstOrDefault() == null) { try { DataStore.InsertVideo(v); added.Add(v); } catch (Exception e) { failedIds.Add(v); } } else { duplicates.Add(v); } } else { existing.Updated = runTime; DataStore.UpdateVideo(existing); } } RefreshResults result = new RefreshResults(added, failedIds); return(result); }
//gp/video/watchlist/tv/ref=atv_wtlp_tv? page = 1 & sort = DATE_ADDED_DESC //gp/video/watchlist/movie/ref=atv_wtlp_mv?page=1&sort=DATE_ADDED_DESC public List <Video> GetWatchListVideos(VideoType type = VideoType.Movie) { if (!LoggedIn) { Login(); } //AmazonId, Video Dictionary <string, Video> videos = new Dictionary <string, Video>(); //All int ctr = 1; while (true) { bool added = false; string url = CreateWatchListPath(type, ctr++, false); driver.Navigate().GoToUrl(url); if (!driver.PageSource.Contains("Your Lists")) { throw new Exception("Not logged in."); } foreach (var l in driver.FindElementsByTagName("a")) { string link = l.GetAttribute("href"); if (link != null && link.Contains(GP_VIDEO_DETAILS)) { string title = l.FindElement(By.TagName("img")).GetAttribute("alt"); string amazonId = ExtractId(link); if (type == VideoType.TvSeason) { title += $" ({amazonId})"; } videos[amazonId] = new Video() { AmazonId = amazonId, Title = title, Type = type, Url = link }; added = true; } } if (!added) { break; } } List <string> inPrime = new List <string>(); ctr = 1; while (true) { bool added = false; string url = CreateWatchListPath(type, ctr++, true); driver.Navigate().GoToUrl(url); foreach (var l in driver.FindElementsByTagName("a")) { string link = l.GetAttribute("href"); if (link != null && link.Contains(GP_VIDEO_DETAILS)) { inPrime.Add(ExtractId(link)); added = true; } } if (!added) { break; } } var expired = videos.Keys.Except(inPrime); foreach (var ex in expired) { var v = videos[ex]; v.AddTag(TagRecord.Create(-1, TagType.Expired)); } return(videos.Values.ToList()); }