Esempio n. 1
0
        private static string DownloadAlternateEpisodeXML(RecordedShow recordedShow)
        {
            var url = databases[0].baseUrl + databases[0].episodeUrl;

            url = url.Replace("$apikey", recordedShow.apiKey);
            url = url.Replace("$this_series_id", recordedShow.alternateSeriesId);
            url = url.Replace("$this_series_lang", recordedShow.language);
            Log("DownloadAlternateEpisodeXML from {0}", url);
            return(new WebClient().DownloadString(url));
        }
Esempio n. 2
0
        private static RecordedShow CreateShow(string path)
        {
            var item = ShellFile.FromFilePath(path);

            var newShow = new RecordedShow
            {
                originalFilename = item.Name,

                seriesName      = item.Properties.System.Title.Value,
                episodeName     = item.Properties.System.RecordedTV.EpisodeName.Value,
                description     = item.Properties.System.RecordedTV.ProgramDescription.Value,
                stationCallSign = item.Properties.System.RecordedTV.StationCallSign.Value
            };

            try { newShow.episodeFirstAired = ((DateTime)item.Properties.System.RecordedTV.OriginalBroadcastDate.Value).ToString("yyyy-MM-dd"); } catch { }

            var xml  = DownloadSeriesXML(newShow.seriesName);
            var xDoc = XDocument.Parse(xml);

            try
            {
                var seriesIds = xDoc.XPathSelectElements("/Data/Series/seriesid");
                if (seriesIds.Count() == 0)
                {
                    newShow.showType = RecordedShow.ShowType.MOVIE;
                }

                for (int i = 0; i < seriesIds.Count(); i++)
                {
                    if (i == 0)
                    {
                        newShow.seriesId = newShow.id = seriesIds.ElementAt(i).Value;
                    }
                    else if (i == 1)
                    {
                        newShow.alternateSeriesId = seriesIds.ElementAt(i).Value;
                    }
                }
            }
            catch { newShow.showType = RecordedShow.ShowType.MOVIE; }
            try { newShow.language = xDoc.XPathSelectElement("/Data/Series/language").Value; } catch { }
            try { newShow.network = xDoc.XPathSelectElement("/Data/Series/Network").Value; } catch { }
            try { newShow.imdbId = xDoc.XPathSelectElement("/Data/Series/IMDB_ID").Value; } catch { }
            try { newShow.zap2itId = xDoc.XPathSelectElement("/Data/Series/zap2it_id").Value; } catch { }
            try { newShow.seriesFirstAired = xDoc.XPathSelectElement("/Data/Series/FirstAired").Value; } catch { }

            if (newShow.showType == RecordedShow.ShowType.TVSHOW && newShow.episodeName != null)
            {
                xml  = DownloadEpisodeXML(newShow);
                xDoc = XDocument.Parse(xml);

                foreach (var episode in xDoc.XPathSelectElements("/Data/Episode"))
                {
                    if (episode.XPathSelectElement("EpisodeName").Value.ToLower().Equals(newShow.episodeName.ToLower()))
                    {
                        newShow.episodeNumber = episode.XPathSelectElement("EpisodeNumber").Value;
                        newShow.seasonNumber  = episode.XPathSelectElement("SeasonNumber").Value;
                        break;
                    }
                }

                if (newShow.episodeNumber == null && newShow.seasonNumber == null)
                {
                    foreach (var episode in xDoc.XPathSelectElements("/Data/Episode"))
                    {
                        if (episode.XPathSelectElement("FirstAired").Value.Equals(newShow.episodeFirstAired))
                        {
                            newShow.episodeNumber = episode.XPathSelectElement("EpisodeNumber").Value;
                            newShow.seasonNumber  = episode.XPathSelectElement("SeasonNumber").Value;
                            break;
                        }
                    }
                }

                if (newShow.episodeNumber == null && newShow.seasonNumber == null)
                {
                    try
                    {
                        xml  = DownloadAlternateEpisodeXML(newShow);
                        xDoc = XDocument.Parse(xml);

                        foreach (var episode in xDoc.XPathSelectElements("/Data/Episode"))
                        {
                            if (episode.XPathSelectElement("EpisodeName").Value.ToLower().Equals(newShow.episodeName.ToLower()))
                            {
                                newShow.episodeNumber = episode.XPathSelectElement("EpisodeNumber").Value;
                                newShow.seasonNumber  = episode.XPathSelectElement("SeasonNumber").Value;
                                break;
                            }
                        }

                        if (newShow.episodeNumber == null && newShow.seasonNumber == null)
                        {
                            foreach (var episode in xDoc.XPathSelectElements("/Data/Episode"))
                            {
                                if (episode.XPathSelectElement("FirstAired").Value.Equals(newShow.episodeFirstAired))
                                {
                                    newShow.episodeNumber = episode.XPathSelectElement("EpisodeNumber").Value;
                                    newShow.seasonNumber  = episode.XPathSelectElement("SeasonNumber").Value;
                                    break;
                                }
                            }
                        }
                    }
                    catch { Log("Could not download DownloadAlternateEpisodeXML()"); }
                }
            }

            if (newShow.episodeNumber != null && newShow.seasonNumber != null)
            {
                newShow.recommendedFilename = newShow.seriesName.Replace(':', '-') + " - S" + newShow.SeasonNumber + "E" + newShow.EpisodeNumber + ".wtv";
            }
            else
            {
                newShow.recommendedFilename = newShow.originalFilename;
            }

            return(newShow);
        }