Beispiel #1
0
        public async Task GetEpisodeDetails()
        {
            if (NavigationService.IsNetworkAvailable)
            {
                var index = SelectedEpisode.IndexNumber;
                if (SelectedEpisode != null && Episodes.IsNullOrEmpty())
                {
                    SetProgressBar(AppResources.SysTrayGettingEpisodeDetails);

                    try
                    {
                        if (string.IsNullOrEmpty(SelectedEpisode.SeriesId))
                        {
                            var episode = await ApiClient.GetItemAsync(SelectedEpisode.Id, AuthenticationService.Current.LoggedInUserId);

                            if (episode == null)
                            {
                                await _messageBox.ShowAsync(AppResources.ErrorEpisodeDetails);

                                NavigationService.GoBack();
                                return;
                            }

                            SelectedEpisode = episode;
                        }

                        var query = new EpisodeQuery
                        {
                            UserId   = AuthenticationService.Current.LoggedInUserId,
                            SeasonId = SelectedEpisode.SeasonId,
                            SeriesId = SelectedEpisode.SeriesId,
                            Fields   = new[]
                            {
                                ItemFields.ParentId,
                                ItemFields.Overview,
                                ItemFields.MediaSources,
                            }
                        };

                        //Log.Info("Getting episodes for Season [{0}] ({1}) of TV Show [{2}] ({3})", SelectedSeason.Name, SelectedSeason.Id, SelectedTvSeries.Name, SelectedTvSeries.Id);

                        var episodes = await ApiClient.GetEpisodesAsync(query);

                        Episodes = episodes.Items.OrderBy(x => x.IndexNumber).ToList();
                    }
                    catch (HttpException ex)
                    {
                        Utils.HandleHttpException("GetEpisodeDetails()", ex, NavigationService, Log);
                    }

                    SetProgressBar();
                }

                if (SelectedEpisode != null)
                {
                    SelectedEpisode = Episodes.FirstOrDefault(x => x.IndexNumber == index);
                    CanResume       = SelectedEpisode != null && SelectedEpisode.CanResume;
                }
            }
        }
Beispiel #2
0
        public async void CheckDownloads()
        {
            await Task.Run(async() =>
            {
                try
                {
                    var folder = await FileHelper.GetLocalFolder(true);

                    if (await folder.TryGetItemAsync(Root) == null)
                    {
                        return;
                    }

                    var podcastFolder = await folder.GetFolderAsync(Root);
                    var files         = await podcastFolder.GetFilesAsync();

                    foreach (var file in files)
                    {
                        var fileName = file.Name;
                        var episode  = Episodes.FirstOrDefault(e => e.LocalFilename.ContainsIgnoreCase(fileName));

                        if (episode != null)
                        {
                            episode.IsAlreadyDownloaded = true;
                            episode.UpdateDownloadInfo();
                        }
                    }
                }
                catch
                {
                    // Ignore error
                }
            });
        }
        public static TmdbEpisodeImages GetEpisodeImages(int?id, int season, int episode, bool forceUpdate = false)
        {
            if (id == null)
            {
                return(null);
            }

            // if its in our cache return it
            var episodeImages = Episodes.FirstOrDefault(e => e.Id == id && e.Season == season && e.Episode == episode);

            if (episodeImages != null)
            {
                if (forceUpdate)
                {
                    return(episodeImages);
                }

                // but only if the request is not very old
                if (DateTime.Now.Subtract(new TimeSpan(TraktSettings.TmdbEpisodeImageMaxCacheAge, 0, 0, 0, 0)) < Convert.ToDateTime(episodeImages.RequestAge))
                {
                    return(episodeImages);
                }

                TraktLogger.Info("Episode image cache expired. TMDb ID = '{0}', Season = '{1}', Episode = '{2}', Request Age = '{3}'", id, season, episode, episodeImages.RequestAge);
                RemoveEpisodeImagesFromCache(episodeImages, season, episode);
            }

            // get movie images from tmdb and add to the cache
            episodeImages = TmdbAPI.TmdbAPI.GetEpisodeImages(id.ToString(), season, episode);
            AddEpisodeImagesToCache(episodeImages, id, season, episode);

            return(episodeImages);
        }
        public ToWatchViewModel(
            IReactiveTVShowTimeApiService tvshowtimeApiService,
            IHamburgerMenuService hamburgerMenuService,
            IEventService eventService)
        {
            _tvshowtimeApiService = tvshowtimeApiService;
            _hamburgerMenuService = hamburgerMenuService;
            _eventService         = eventService;

            SelectEpisodeCommand = new RelayCommand <Episode>(SelectEpisode);

            Refresh();

            _eventService.WatchEpisodeEvent
            .Subscribe((episode) =>
            {
                Refresh();
            });

            _eventService.UnwatchEpisodeEvent
            .Subscribe((episode) =>
            {
                Refresh();
            });

            _eventService.FollowShowEvent
            .Subscribe((show) =>
            {
                Refresh();
            });

            _eventService.UnfollowShowEvent
            .Subscribe((show) =>
            {
                var episodeOfTheShow = Episodes.FirstOrDefault(e => e.Show.Id == show.Id);
                if (episodeOfTheShow != null)
                {
                    Episodes.Remove(episodeOfTheShow);
                }
            });
        }
Beispiel #5
0
        public async void CheckDownloads()
        {
            await Task.Run(async() =>
            {
                try
                {
                    var folder = await FileHelper.GetLocalFolder(true);

                    if (await folder.TryGetItemAsync(Root) == null)
                    {
                        return;
                    }

                    var podcastFolder = await folder.GetFolderAsync(Root);
                    var files         = await podcastFolder.GetFilesAsync();

                    foreach (var file in files)
                    {
                        var fileName = file.Name;
                        // #45 File name could have been truncated while previously saved. i.e. Filename123.mp3 could be saved as Filename12.mp3)
                        // The extension prevent from matching files in the collection so remove it
                        var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
                        var episode = Episodes.FirstOrDefault(e => e.LocalFilename.ContainsIgnoreCase(fileNameWithoutExtension));

                        if (episode != null)
                        {
                            episode.IsAlreadyDownloaded = true;
                            episode.UpdateDownloadInfo();
                        }
                    }
                }
                catch
                {
                    // Ignore error
                }
            });
        }
Beispiel #6
0
        async Task ParseAsync(Windows.Data.Xml.Dom.XmlDocument document, bool notify, bool checkDownloads)
        {
            try
            {
                GetLocalImage();

                var channel = document.GetElementsByTagName("channel")[0];

                var tempList = new List <Episode>();

                foreach (var currentItem in channel.ChildNodes)
                {
                    if (currentItem.NodeName != "item")
                    {
                        continue;
                    }

                    var item = currentItem as Windows.Data.Xml.Dom.XmlElement;

                    var episode = new Episode
                    {
                        Link             = item.GetChildNodeTextValue("link", ""),
                        Title            = item.GetChildNodeTextValue("title", "").Sanitize(),
                        Subtitle         = item.GetChildNodeTextValue("itunes:subtitle", "").Sanitize(),
                        Author           = item.GetChildNodeTextValue("itunes:author", "").Sanitize(),
                        Summary          = item.GetChildNodeTextValue("description", "").SanitizeAsHTML(),
                        Enclosure        = item.GetChildNodeAttribute("enclosure", "url", ""),
                        PictureUrl       = item.GetChildNodeAttribute("itunes:image", "href", ""),
                        DeclaredDuration = item.GetChildNodeTextValue("itunes:duration", ""),
                        Keywords         = item.GetChildNodeTextValue("itunes:keywords", ""),
                        PublicationDate  = item.GetChildNodeTextValue("pubDate", "").TryParseAsDateTime(),
                        PodcastFeedUrl   = FeedUrl
                    };

                    var    length = item.GetChildNodeAttribute("enclosure", "length", "");
                    double estimatedLength;
                    if (Double.TryParse(length, out estimatedLength))
                    {
                        episode.EstimatedFileSize = estimatedLength;
                    }

                    if (!episode.DeclaredDuration.Contains(":"))
                    {
                        episode.DeclaredDuration = "";
                    }

                    var itunesSummary = item.GetChildNodeTextValue("itunes:summary", "").SanitizeAsHTML();

                    if (itunesSummary.Length > episode.Summary.Length)
                    {
                        episode.Summary = itunesSummary;
                    }

                    var contentSummary = item.GetChildNodeTextValue("content:encoded", "").SanitizeAsHTML();

                    if (contentSummary.Length > episode.Summary.Length)
                    {
                        episode.Summary = contentSummary;
                    }

                    if (string.IsNullOrEmpty(episode.Author))
                    {
                        episode.Author = Title;
                    }

                    if (string.IsNullOrEmpty(episode.Enclosure))
                    {
                        episode.Enclosure = episode.Link;
                    }

                    if (string.IsNullOrEmpty(episode.PictureUrl))
                    {
                        episode.PictureUrl = LocalImage;
                    }

                    episode.Clean();

                    tempList.Add(episode);
                }

                var addedEpisodes = new List <Episode>();
                var indexToInject = 0;

                foreach (var episode in tempList.OrderByDescending(e => e.PublicationDate))
                {
                    var inLibraryEpisode = Episodes.FirstOrDefault(e => e.Enclosure == episode.Enclosure);
                    if (inLibraryEpisode != null)
                    {
                        inLibraryEpisode.Author            = episode.Author;
                        inLibraryEpisode.DeclaredDuration  = episode.DeclaredDuration;
                        inLibraryEpisode.Keywords          = episode.Keywords;
                        inLibraryEpisode.Link              = episode.Link;
                        inLibraryEpisode.PictureUrl        = episode.PictureUrl;
                        inLibraryEpisode.PodcastFeedUrl    = episode.PodcastFeedUrl;
                        inLibraryEpisode.Title             = episode.Title;
                        inLibraryEpisode.Subtitle          = episode.Subtitle;
                        inLibraryEpisode.Summary           = episode.Summary;
                        inLibraryEpisode.PublicationDate   = episode.PublicationDate;
                        inLibraryEpisode.EstimatedFileSize = episode.EstimatedFileSize;
                        continue;
                    }

                    await DispatchManager.RunOnDispatcherAsync(() =>
                    {
                        Episodes.Insert(indexToInject, episode);
                    });

                    indexToInject++;
                    addedEpisodes.Add(episode);

                    if (notify && IsInLibrary && LocalSettings.Instance.Notifications)
                    {
                        Messenger.Notify(string.Format(LocalSettings.Instance.NotificationMessage, episode.Title), Title, "", LocalImage);
                    }
                }

                if (addedEpisodes.Count > 0 && IsInLibrary && AppSettings.Instance.AutomaticallyAddNewEpisodeToPlaylist)
                {
                    await DispatchManager.RunOnDispatcherAsync(() =>
                    {
                        var reversedAddedEpisodes = addedEpisodes.OrderBy(e => e.PublicationDate).ToList();
                        if (Playlist.CurrentPlaylist != null)
                        {
                            Playlist.CurrentPlaylist.AddEpisodes(reversedAddedEpisodes);
                        }
                        else
                        {
                            Playlist.EpisodesToAdd.AddRange(reversedAddedEpisodes);
                        }
                    });
                }

                LocalSettings.Instance.NewEpisodesCount += addedEpisodes.Count;

                if (checkDownloads)
                {
                    CheckForAutomaticDownloads();
                }

                if (toExecuteWhenReady != null)
                {
                    toExecuteWhenReady();
                    toExecuteWhenReady = null;
                }
            }
            catch
            {
                await Messenger.ErrorAsync(StringsHelper.Error_UnableToParseRSS + " (" + Title + ")");
            }
        }
Beispiel #7
0
 public Episode GetEpisodeByEnclosure(string enclosure)
 {
     return(Episodes.FirstOrDefault(e => e.Enclosure == enclosure));
 }
Beispiel #8
0
        public override void WireMessages()
        {
            Messenger.Default.Register <NotificationMessage>(this, m =>
            {
                if (m.Notification.Equals(Constants.Messages.ClearEpisodesMsg))
                {
                    Episodes.Clear();
                }

                if (m.Notification.Equals(Constants.Messages.RefreshResumeMsg))
                {
                    var id    = (string)m.Sender;
                    var ticks = (long)m.Target;
                    if (id == SelectedEpisode.Id)
                    {
                        if (SelectedEpisode.UserData == null)
                        {
                            SelectedEpisode.UserData = new UserItemDataDto();
                        }

                        SelectedEpisode.UserData.PlaybackPositionTicks = ticks;

                        SelectedEpisode.HasPlayed();

                        CanResume = SelectedEpisode.CanResume;
                    }
                }
            });

            Messenger.Default.Register <SyncNotificationMessage>(this, m =>
            {
                if (m.Notification.Equals(Constants.Messages.SyncJobFinishedMsg))
                {
                    switch (m.ItemType.ToLower())
                    {
                    case "episode":
                        if (SelectedEpisode != null && SelectedEpisode.Id == m.ItemId)
                        {
                            SelectedEpisode.IsSynced = true;
                        }

                        if (!Episodes.IsNullOrEmpty())
                        {
                            var episode = Episodes.FirstOrDefault(x => x.Id == m.ItemId);
                            if (episode != null)
                            {
                                episode.IsSynced = true;
                            }
                        }
                        break;

                    case "season":
                        if (SelectedSeason != null)
                        {
                            SelectedSeason.IsSynced = true;
                        }

                        if (!Seasons.IsNullOrEmpty())
                        {
                            var season = Seasons.FirstOrDefault(x => x.Id == m.ItemId);
                            if (season != null)
                            {
                                season.IsSynced = true;
                            }
                        }
                        break;

                    case "series":
                        if (SelectedTvSeries != null)
                        {
                            SelectedTvSeries.IsSynced = true;
                        }
                        break;
                    }
                }
            });
        }
Beispiel #9
0
 /// <summary>
 /// Gets a specific episode.
 /// </summary>
 /// <param name="season">Season number to get.</param>
 /// <param name="episode">Episode number to get.</param>
 /// <returns>A TvdbEpisode representing the episode or null if one doesn't exist.</returns>
 public TvdbEpisode GetEpisode(uint season, uint episode)
 {
     Debug.WriteLine("-> TvdbDetailedSeries::GetEpisode season=\"" + season + "\" episode=\"" + episode + "\" Called");
     return(Episodes.FirstOrDefault(tvdbEpisode => tvdbEpisode.EpisodeNumber == episode && tvdbEpisode.SeasonNumber == season));
 }