Esempio n. 1
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable <ShowID> GetID(string name, string language = "en")
        {
            var list = Utils.GetXML("http://www.thetvdb.com/api/GetSeries.php?seriesname={0}&language={1}".FormatWith(Utils.EncodeURL(name), !string.IsNullOrWhiteSpace(language) ? language : "en"), timeout: 120000);
            var prev = new List <string>();

            foreach (var show in list.Descendants("Series"))
            {
                var id = new ShowID(this);

                id.ID       = show.GetValue("seriesid");
                id.Title    = show.GetValue("SeriesName");
                id.Language = show.GetValue("language");
                id.URL      = "http://thetvdb.com/?tab=series&id=" + id.ID;
                id.Cover    = show.GetValue("banner");

                if (!string.IsNullOrWhiteSpace(id.Cover))
                {
                    id.Cover = "http://thetvdb.com/banners/_cache/" + id.Cover;
                }

                if (!prev.Contains(id.ID))
                {
                    prev.Add(id.ID);

                    yield return(id);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable <ShowID> GetID(string name, string language = "en")
        {
            var json = Utils.GetJSON("http://api.themoviedb.org/3/search/tv?api_key=" + Key + "&query=" + Utils.EncodeURL(name));

            if (json["total_results"] == 0)
            {
                yield break;
            }

            foreach (var show in json["results"])
            {
                var id = new ShowID(this);

                id.ID       = ((int)show["id"]).ToString();
                id.URL      = Site + "tv/" + id.ID;
                id.Title    = (string)show["name"] + (show["first_air_date"] != null ? " (" + ((string)show["first_air_date"]).Substring(0, 4) + ")" : string.Empty);
                id.Language = "en";

                if (show["poster_path"] != null)
                {
                    id.Cover = "http://image.tmdb.org/t/p/original" + (string)show["poster_path"];
                }
                else if (show["backdrop_path"] != null)
                {
                    id.Cover = "http://image.tmdb.org/t/p/original" + (string)show["backdrop_path"];
                }

                yield return(id);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable <ShowID> GetID(string name, string language = "en")
        {
            var html  = Utils.GetHTML("http://www.tv.com/search?q=" + Utils.EncodeURL(name));
            var shows = html.DocumentNode.SelectNodes("//div/h4/a");

            if (shows == null)
            {
                yield break;
            }

            foreach (var show in shows)
            {
                var id = new ShowID(this);

                id.URL      = Site.TrimEnd('/') + HtmlEntity.DeEntitize(show.GetAttributeValue("href"));
                id.ID       = Regex.Match(id.URL, @"/shows/([^/]+)/").Groups[1].Value;
                id.Title    = HtmlEntity.DeEntitize(show.InnerText);
                id.Cover    = show.GetNodeAttributeValue("../../../a/img", "src");
                id.Language = "en";

                if (string.IsNullOrWhiteSpace(id.ID))
                {
                    continue;
                }

                yield return(id);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable <ShowID> GetID(string name, string language = "en")
        {
            var html  = Utils.GetHTML("http://www.episodeworld.com/search/?searchlang=" + LanguageIDs[language] + "&searchitem=" + Utils.EncodeURL(name));
            var shows = html.DocumentNode.SelectNodes("//table[@id='list']/tr/td[3]/a/b");

            if (shows == null)
            {
                var title = html.DocumentNode.GetTextValue("//div[@class='orangecorner_content']//h1");
                if (!string.IsNullOrWhiteSpace(title))
                {
                    var id = new ShowID(this);

                    id.URL      = Site.TrimEnd('/') + HtmlEntity.DeEntitize(html.DocumentNode.GetNodeAttributeValue("//td[@class='boxes']/a[contains(text(), 'All Seasons')]", "href"));
                    id.ID       = Regex.Match(id.URL, @"show/([^/$]+)").Groups[1].Value;
                    id.Title    = HtmlEntity.DeEntitize(title);
                    id.Language = language;

                    yield return(id);
                }

                yield break;
            }

            foreach (var show in shows)
            {
                var id = new ShowID(this);

                id.URL      = Site.TrimEnd('/') + HtmlEntity.DeEntitize(show.GetNodeAttributeValue("..", "href"));
                id.ID       = Regex.Match(id.URL, @"show/([^/$]+)").Groups[1].Value;
                id.Title    = HtmlEntity.DeEntitize(show.InnerText);
                id.Language = language;

                yield return(id);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable <ShowID> GetID(string name, string language = "en")
        {
            var result = Utils.GetJSON("http://api.tvmaze.com/search/shows?q=" + Utils.EncodeURL(name));

            foreach (var entry in result)
            {
                var show = entry["show"];
                var id   = new ShowID(this);

                id.ID       = ((int)show["id"]).ToString();
                id.URL      = show["url"];
                id.Title    = show["name"] + (show["premiered"] != null ? " (" + ((string)show["premiered"]).Substring(0, 4) + ")" : string.Empty);
                id.Language = "en";

                if (show["image"] != null)
                {
                    if (show["image"]["original"] != null)
                    {
                        id.Cover = show["image"]["original"];
                    }
                    else if (show["image"]["medium"] != null)
                    {
                        id.Cover = show["image"]["medium"];
                    }
                }

                yield return(id);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable <ShowID> GetID(string name, string language = "en")
        {
            var json = Utils.GetJSON(SignURL("http://app.imdb.com/find?q=" + Utils.EncodeURL(name)));

            foreach (var result in json["data"]["results"])
            {
                foreach (var show in result["list"])
                {
                    if (show["type"] != "tv_series")
                    {
                        continue;
                    }

                    var id = new ShowID(this);

                    id.URL      = "http://www.imdb.com/title/" + (string)show["tconst"] + "/";
                    id.ID       = ((string)show["tconst"]).Substring(2);
                    id.Title    = (string)show["title"] + " (" + (string)show["year"] + ")";
                    id.Language = "en";

                    try { id.Cover = (string)show["image"]["url"]; } catch { }

                    yield return(id);
                }
            }
        }
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable<ShowID> GetID(string name, string language = "en")
        {
            var result = Utils.GetJSON("http://api.tvmaze.com/search/shows?q=" + Utils.EncodeURL(name));

            foreach (var entry in result)
            {
                var show = entry["show"];
                var id = new ShowID(this);

                id.ID       = ((int)show["id"]).ToString();
                id.URL      = show["url"];
                id.Title    = show["name"] + (show["premiered"] != null ? " (" + ((string)show["premiered"]).Substring(0, 4) + ")" : string.Empty);
                id.Language = "en";

                if (show["image"] != null)
                {
                    if (show["image"]["original"] != null)
                    {
                        id.Cover = show["image"]["original"];
                    }
                    else if (show["image"]["medium"] != null)
                    {
                        id.Cover = show["image"]["medium"];
                    }
                }

                yield return id;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable <ShowID> GetID(string name, string language = "en")
        {
            var list = Utils.GetXML("http://anisearch.outrance.pl/?task=search&query=" + Utils.EncodeURL(name));

            foreach (var show in list.Descendants("anime"))
            {
                var id = new ShowID(this);

                try
                {
                    id.Title    = show.Descendants("title").First(t => t.Attribute("lang").Value == "en").Value;
                    id.Language = "en";
                }
                catch
                {
                    try
                    {
                        id.Title    = show.Descendants("title").First(t => t.Attribute("lang").Value == language).Value;
                        id.Language = language;
                    }
                    catch
                    {
                        id.Title    = show.GetValue("title");
                        id.Language = "en";
                    }
                }

                id.ID  = show.Attribute("aid").Value;
                id.URL = Site + "perl-bin/animedb.pl?show=anime&aid=" + id.ID;

                yield return(id);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable <ShowID> GetID(string name, string language = "en")
        {
            var list = Utils.GetXML("http://services.tvrage.com/myfeeds/search.php?key={0}&show={1}".FormatWith(Key, Utils.EncodeURL(name)), timeout: 120000);

            foreach (var show in list.Descendants("show"))
            {
                var id = new ShowID(this);

                id.ID       = show.GetValue("showid");
                id.Title    = show.GetValue("name");
                id.Cover    = "http://images.tvrage.com/shows/4/{0}.jpg".FormatWith(id.ID);
                id.Language = "en";
                id.URL      = show.GetValue("link");

                yield return(id);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable <ShowID> GetID(string name, string language = "en")
        {
            var json = (dynamic)JsonConvert.DeserializeObject(Utils.GetFastURL("https://www.googleapis.com/freebase/v1/search?query=" + Utils.EncodeURL(name) + "&filter=" + Utils.EncodeURL("(all type:/tv/tv_program)") + "&output=" + Utils.EncodeURL("(/common/topic/image /tv/tv_program/air_date_of_first_episode)")));

            if (json["result"] == null || json["result"].Count == 0)
            {
                yield break;
            }

            foreach (var show in json["result"])
            {
                var id = new ShowID(this);

                id.ID       = ((string)show["mid"]).Substring(3);
                id.URL      = Site + "m/" + id.ID;
                id.Title    = (string)show["name"] + (show["output"]["/tv/tv_program/air_date_of_first_episode"]["/tv/tv_program/air_date_of_first_episode"] != null ? " (" + ((string)show["output"]["/tv/tv_program/air_date_of_first_episode"]["/tv/tv_program/air_date_of_first_episode"][0]).Substring(0, 4) + ")" : string.Empty);
                id.Cover    = show["output"]["/common/topic/image"]["/common/topic/image"] != null ? "https://usercontent.googleapis.com/freebase/v1/image" + (string)show["output"]["/common/topic/image"]["/common/topic/image"][0]["mid"] + "?maxwidth=2048" : null;
                id.Language = "en";

                yield return(id);
            }
        }
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable <ShowID> GetID(string name, string language = "en")
        {
            var list = Utils.GetXML("http://cdn.animenewsnetwork.com/encyclopedia/api.xml?anime=~" + Utils.EncodeURL(name));

            foreach (var show in list.Descendants("anime"))
            {
                int eps;
                if (!int.TryParse(GetDescendantItemValue(show, "info", "type", "Number of episodes"), out eps) || eps == 0)
                {
                    continue;
                }

                var id = new ShowID(this);

                id.Title    = GetDescendantItemValue(show, "info", "type", "Main title");
                id.Language = "en";
                id.ID       = show.Attribute("id").Value;
                id.URL      = Site + "encyclopedia/anime.php?id=" + id.ID;
                id.Cover    = GetDescendantItemAttribute(show, "info", "type", "Picture", "src");

                yield return(id);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable<ShowID> GetID(string name, string language = "en")
        {
            var json = Utils.GetJSON(SignURL("http://app.imdb.com/find?q=" + Utils.EncodeURL(name)));
            
            foreach (var result in json["data"]["results"])
            {
                foreach (var show in result["list"])
                {
                    if (show["type"] != "tv_series") continue;

                    var id = new ShowID(this);

                    id.URL      = "http://www.imdb.com/title/" + (string)show["tconst"] + "/";
                    id.ID       = ((string)show["tconst"]).Substring(2);
                    id.Title    = (string)show["title"] + " (" + (string)show["year"] + ")";
                    id.Language = "en";

                    try { id.Cover = (string)show["image"]["url"]; } catch { }

                    yield return id;
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Identifies the name of the show.
        /// </summary>
        /// <param name="name">The name of the show.</param>
        /// <param name="ep">The episode.</param>
        /// <param name="askRemote">if set to <c>true</c> lab.rolisoft.net's API will be asked to identify a show after the local database failed.</param>
        /// <returns>
        /// A tuple containing the show's and episode's title and airdate.
        /// </returns>
        private static Tuple <string, string, DateTime, TVShow, Episode> IdentifyShow(string name, ShowEpisode ep, bool askRemote = false)
        {
            var title = string.Empty;
            var date  = DateTime.MinValue;
            var match = false;
            var ltvsh = default(TVShow);
            var lepis = default(Episode);

            // try to find show in local database

            foreach (var show in Database.TVShows.Values.ToList())
            {
                var titleMatch   = ShowNames.Parser.GenerateTitleRegex(show.Title, show).Match(name);
                var releaseRegex = string.Empty;
                var releaseMatch = show.Data.TryGetValue("regex", out releaseRegex) && !string.IsNullOrWhiteSpace(releaseRegex) ? Regex.Match(name, releaseRegex) : null;

                if ((titleMatch.Success && titleMatch.Value == name) || (releaseMatch != null && releaseMatch.Success && releaseMatch.Value == name))
                {
                    if (ep == null)
                    {
                        match = true;
                        ltvsh = show;
                        name  = show.Title;

                        break;
                    }
                    else if (ep.AirDate != null)
                    {
                        var episode = show.Episodes.Where(x => x.Airdate.ToOriginalTimeZone(x.Show.TimeZone).Date == ep.AirDate.Value.Date).ToList();
                        if (episode.Count != 0)
                        {
                            match = true;
                            ltvsh = show;
                            name  = show.Title;
                            lepis = episode[0];
                            title = episode[0].Title;
                            date  = episode[0].Airdate;

                            ep.Season  = episode[0].Season;
                            ep.Episode = episode[0].Number;

                            break;
                        }
                    }
                    else
                    {
                        Episode episode;
                        if (show.EpisodeByID.TryGetValue(ep.Season * 1000 + ep.Episode, out episode))
                        {
                            match = true;
                            ltvsh = show;
                            name  = show.Title;
                            lepis = episode;
                            title = episode.Title;
                            date  = episode.Airdate;

                            break;
                        }
                    }
                }
            }

            // try to find show in the local cache of the list over at lab.rolisoft.net

            if (!match)
            {
                if (AllKnownTVShows.Count == 0)
                {
                    var path = Path.Combine(Signature.InstallPath, @"misc\tvshows");

                    if (File.Exists(path) && new FileInfo(path).Length != 0)
                    {
                        using (var fs = File.OpenRead(path))
                            using (var br = new BinaryReader(fs))
                            {
                                var ver = br.ReadByte();
                                var upd = br.ReadUInt32();
                                var cnt = br.ReadUInt32();

                                AllKnownTVShows = new List <KnownTVShow>();

                                for (var i = 0; i < cnt; i++)
                                {
                                    var show = new KnownTVShow();

                                    show.Title      = br.ReadString();
                                    show.Slug       = br.ReadString();
                                    show.Database   = br.ReadString();
                                    show.DatabaseID = br.ReadString();

                                    AllKnownTVShows.Add(show);
                                }
                            }
                    }
                    else
                    {
                        try { GetAllKnownTVShows(); } catch { }
                    }
                }

                var slug    = Utils.CreateSlug(name);
                var matches = new List <KnownTVShow>();

                foreach (var show in AllKnownTVShows)
                {
                    if (show.Slug == slug)
                    {
                        matches.Add(show);
                    }
                }

                if (matches.Count != 0 && ep == null)
                {
                    match = true;
                    name  = matches[0].Title;
                }
                else if (matches.Count != 0 && ep != null)
                {
                    TVShow local = null;

                    foreach (var mtch in matches)
                    {
                        foreach (var show in Database.TVShows.Values)
                        {
                            if (show.Source == mtch.Database && show.SourceID == mtch.DatabaseID)
                            {
                                local = show;
                                break;
                            }
                        }
                    }

                    if (local != null)
                    {
                        match = true;
                        name  = local.Title;

                        if (ep.AirDate != null)
                        {
                            var eps = local.Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                ltvsh = eps[0].Show;
                                title = eps[0].Title;
                                lepis = eps[0];
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = local.Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                ltvsh = eps[0].Show;
                                title = eps[0].Title;
                                lepis = eps[0];
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                    else if (ShowIDCache.ContainsKey(name) && TVShowCache.ContainsKey(name))
                    {
                        match = true;
                        name  = ShowIDCache[name].Title;

                        if (ep.AirDate != null)
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                    else if (askRemote)
                    {
                        var guide = Updater.CreateGuide(matches[0].Database);
                        var data  = guide.GetData(matches[0].DatabaseID);

                        ShowIDCache[name] = new ShowID {
                            Title = data.Title
                        };

                        match = true;
                        name  = data.Title;

                        TVShowCache[name] = data;

                        if (ep.AirDate != null)
                        {
                            var eps = data.Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = data.Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                }
            }

            // try to find show in cache

            if (!match && ShowIDCache.ContainsKey(name))
            {
                match = true;
                name  = ShowIDCache[name].Title;

                if (ep != null)
                {
                    if (TVShowCache.ContainsKey(name))
                    {
                        if (ep.AirDate != null)
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                    else
                    {
                        match = false;
                    }
                }
            }

            // try to identify show using lab.rolisoft.net's API

            if (!match && askRemote)
            {
                var req = Remote.API.GetShowInfo(name, new[] { "Title", "Source", "SourceID" });

                if (req.Success)
                {
                    if (ep == null)
                    {
                        ShowIDCache[name] = new ShowID {
                            Title = req.Title
                        };

                        match = true;
                        name  = req.Title;
                    }
                    else
                    {
                        var guide = Updater.CreateGuide(req.Source);
                        var data  = guide.GetData(req.SourceID);

                        ShowIDCache[name] = new ShowID {
                            Title = data.Title
                        };

                        match = true;
                        name  = data.Title;

                        TVShowCache[name] = data;

                        if (ep.AirDate != null)
                        {
                            var eps = data.Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = data.Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                }
            }

            // return

            return(match
                   ? new Tuple <string, string, DateTime, TVShow, Episode>(name, title, date, ltvsh, lepis)
                   : null);
        }
Esempio n. 14
0
        public int CompareTo(RoundInfo other)
        {
            int showCompare = ShowID.CompareTo(other.ShowID);

            return(showCompare != 0 ? showCompare : Round.CompareTo(other.Round));
        }
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable<ShowID> GetID(string name, string language = "en")
        {
            var list = Utils.GetXML("http://cdn.animenewsnetwork.com/encyclopedia/api.xml?anime=~" + Utils.EncodeURL(name));

            foreach (var show in list.Descendants("anime"))
            {
                int eps;
                if (!int.TryParse(GetDescendantItemValue(show, "info", "type", "Number of episodes"), out eps) || eps == 0)
                {
                    continue;
                }

                var id = new ShowID(this);

                id.Title    = GetDescendantItemValue(show, "info", "type", "Main title");
                id.Language = "en";
                id.ID       = show.Attribute("id").Value;
                id.URL      = Site + "encyclopedia/anime.php?id=" + id.ID;
                id.Cover    = GetDescendantItemAttribute(show, "info", "type", "Picture", "src");

                yield return id;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable<ShowID> GetID(string name, string language = "en")
        {
            var list = Utils.GetXML("http://anisearch.outrance.pl/?task=search&query=" + Utils.EncodeURL(name));

            foreach (var show in list.Descendants("anime"))
            {
                var id = new ShowID();

                try
                {
                    id.Title = show.Descendants("title").First(t => t.Attribute("lang").Value == "en").Value;
                    id.Language = "en";
                }
                catch
                {
                    try
                    {
                        id.Title = show.Descendants("title").First(t => t.Attribute("lang").Value == language).Value;
                        id.Language = language;
                    }
                    catch
                    {
                        id.Title = show.GetValue("title");
                        id.Language = "en";
                    }
                }

                id.ID  = show.Attribute("aid").Value;
                id.URL = Site + "perl-bin/animedb.pl?show=anime&aid=" + id.ID;

                yield return id;
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable<ShowID> GetID(string name, string language = "en")
        {
            var html  = Utils.GetHTML("http://www.episodeworld.com/search/?searchlang=" + LanguageIDs[language] + "&searchitem=" + Utils.EncodeURL(name));
            var shows = html.DocumentNode.SelectNodes("//table[@id='list']/tr/td[3]/a/b");

            if (shows == null)
            {
                var title = html.DocumentNode.GetTextValue("//div[@class='orangecorner_content']//h1");
                if (!string.IsNullOrWhiteSpace(title))
                {
                    var id  = new ShowID(this);

                    id.URL      = Site.TrimEnd('/') + HtmlEntity.DeEntitize(html.DocumentNode.GetNodeAttributeValue("//td[@class='boxes']/a[contains(text(), 'All Seasons')]", "href"));
                    id.ID       = Regex.Match(id.URL, @"show/([^/$]+)").Groups[1].Value;
                    id.Title    = HtmlEntity.DeEntitize(title);
                    id.Language = language;

                    yield return id;
                }

                yield break;
            }

            foreach (var show in shows)
            {
                var id  = new ShowID(this);

                id.URL      = Site.TrimEnd('/') + HtmlEntity.DeEntitize(show.GetNodeAttributeValue("..", "href"));
                id.ID       = Regex.Match(id.URL, @"show/([^/$]+)").Groups[1].Value;
                id.Title    = HtmlEntity.DeEntitize(show.InnerText);
                id.Language = language;

                yield return id;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Identifies the name of the show.
        /// </summary>
        /// <param name="name">The name of the show.</param>
        /// <param name="ep">The episode.</param>
        /// <param name="askRemote">if set to <c>true</c> lab.rolisoft.net's API will be asked to identify a show after the local database failed.</param>
        /// <returns>
        /// A tuple containing the show's and episode's title and airdate.
        /// </returns>
        private static Tuple<string, string, DateTime> IdentifyShow(string name, ShowEpisode ep, bool askRemote = false)
        {
            var title = string.Empty;
            var date  = DateTime.MinValue;
            var match = false;

            // try to find show in local database

            foreach (var show in Database.TVShows)
            {
                var titleMatch   = ShowNames.Parser.GenerateTitleRegex(show.Value.Name).Match(name);
                var releaseMatch = !string.IsNullOrWhiteSpace(show.Value.Release) ? Regex.Match(name, show.Value.Release) : null;

                if ((titleMatch.Success && titleMatch.Value == name) || (releaseMatch != null && releaseMatch.Success && releaseMatch.Value == name))
                {
                    if (ep == null)
                    {
                        match = true;
                        name  = show.Value.Name;

                        break;
                    }
                    else if (ep.AirDate != null)
                    {
                        var episode = Database.Episodes.Where(x => x.ShowID == show.Value.ShowID && x.Airdate.ToOriginalTimeZone(x.Show.Data.Get("timezone")).Date == ep.AirDate.Value.Date).ToList();
                        if (episode.Count != 0)
                        {
                            match = true;
                            name  = show.Value.Name;
                            title = episode[0].Name;
                            date  = episode[0].Airdate;

                            ep.Season  = episode[0].Season;
                            ep.Episode = episode[0].Number;

                            break;
                        }
                    }
                    else
                    {
                        var episode = Database.Episodes.Where(x => x.EpisodeID == ep.Episode + (ep.Season * 1000) + (show.Value.ShowID * 100 * 1000)).ToList();
                        if (episode.Count != 0)
                        {
                            match = true;
                            name  = show.Value.Name;
                            title = episode[0].Name;
                            date  = episode[0].Airdate;

                            break;
                        }
                    }
                }
            }

            // try to find show in the local cache of the list over at lab.rolisoft.net

            if (!match)
            {
                if (AllKnownTVShows.Count == 0)
                {
                    var fn = Path.Combine(Path.GetTempPath(), "AllKnownTVShows.bin");

                    if (File.Exists(fn) && new FileInfo(fn).Length != 0)
                    {
                        using (var file = File.OpenRead(fn))
                        {
                            try { AllKnownTVShows = Serializer.Deserialize<List<KnownTVShow>>(file); } catch { }
                        }
                    }
                    else
                    {
                        try { GetAllKnownTVShows(); } catch { }
                    }
                }

                var slug    = Utils.CreateSlug(name);
                var matches = new List<KnownTVShow>();

                foreach (var show in AllKnownTVShows)
                {
                    if (show.Slug == slug)
                    {
                        matches.Add(show);
                    }
                }

                if (matches.Count != 0 && ep == null)
                {
                    match = true;
                    name  = matches[0].Title;
                }
                else if (matches.Count != 0 && ep != null)
                {
                    Tables.TVShow local = null;

                    foreach (var mtch in matches)
                    {
                        foreach (var show in Database.TVShows.Values)
                        {
                            if (show.Data.Get("grabber") == mtch.Database && show.Data.Get(mtch.Database + ".id") == mtch.DatabaseID)
                            {
                                local = show;
                                break;
                            }
                        }
                    }

                    if (local != null)
                    {
                        match = true;
                        name  = local.Name;

                        if (ep.AirDate != null)
                        {
                            var eps = local.Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Name;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = local.Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Name;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                    else if (ShowIDCache.ContainsKey(name) && TVShowCache.ContainsKey(name))
                    {
                        match = true;
                        name  = ShowIDCache[name].Title;

                        if (ep.AirDate != null)
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                    else if (askRemote)
                    {
                        var guide = Updater.CreateGuide(matches[0].Database);
                        var data  = guide.GetData(matches[0].DatabaseID);

                        ShowIDCache[name] = new ShowID { Title = data.Title };

                        match = true;
                        name  = data.Title;

                        TVShowCache[name] = data;

                        if (ep.AirDate != null)
                        {
                            var eps = data.Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = data.Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                }
            }

            // try to find show in cache

            if (!match && ShowIDCache.ContainsKey(name))
            {
                match = true;
                name  = ShowIDCache[name].Title;

                if (ep != null)
                {
                    if (TVShowCache.ContainsKey(name))
                    {
                        if (ep.AirDate != null)
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                    else
                    {
                        match = false;
                    }
                }
            }

            // try to identify show using lab.rolisoft.net's API

            if (!match && askRemote)
            {
                var req = Remote.API.GetShowInfo(name, new[] { "Title", "Source", "SourceID" });

                if (req.Success)
                {
                    if (ep == null)
                    {
                        ShowIDCache[name] = new ShowID { Title = req.Title };

                        match = true;
                        name  = req.Title;
                    }
                    else
                    {
                        var guide = Updater.CreateGuide(req.Source);
                        var data  = guide.GetData(req.SourceID);

                        ShowIDCache[name] = new ShowID { Title = data.Title };

                        match = true;
                        name  = data.Title;

                        TVShowCache[name] = data;

                        if (ep.AirDate != null)
                        {
                            var eps = data.Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = data.Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                }
            }

            // return

            return match
                   ? new Tuple<string, string, DateTime>(name, title, date)
                   : null;
        }
Esempio n. 19
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable<ShowID> GetID(string name, string language = "en")
        {
            var list = Utils.GetXML("http://services.tvrage.com/myfeeds/search.php?key={0}&show={1}".FormatWith(Key, Utils.EncodeURL(name)), timeout: 120000);

            foreach (var show in list.Descendants("show"))
            {
                var id = new ShowID(this);

                id.ID       = show.GetValue("showid");
                id.Title    = show.GetValue("name");
                id.Cover    = "http://images.tvrage.com/shows/4/{0}.jpg".FormatWith(id.ID);
                id.Language = "en";
                id.URL      = show.GetValue("link");

                yield return id;
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable<ShowID> GetID(string name, string language = "en")
        {
            var list = Utils.GetXML("http://www.thetvdb.com/api/GetSeries.php?seriesname={0}&language={1}".FormatWith(Utils.EncodeURL(name), language), timeout: 120000);
            var prev = new List<string>();

            foreach (var show in list.Descendants("Series"))
            {
                var id = new ShowID();

                id.ID       = show.GetValue("seriesid");
                id.Title    = show.GetValue("SeriesName");
                id.Language = show.GetValue("language");
                id.URL      = "http://thetvdb.com/?tab=series&id=" + id.ID;
                id.Cover    = show.GetValue("banner");

                if (!string.IsNullOrWhiteSpace(id.Cover))
                {
                    id.Cover = "http://thetvdb.com/banners/_cache/" + id.Cover;
                }

                if (!prev.Contains(id.ID))
                {
                    prev.Add(id.ID);

                    yield return id;
                }
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Adds the specified TV show to the database.
        /// </summary>
        /// <param name="sid">The show ID to add to the database.</param>
        /// <param name="callback">The status callback.</param>
        /// <returns>Added TV show or <c>null</c>.</returns>
        public static TVShow Add(ShowID sid, Action <int, string> callback = null)
        {
            Log.Info("Adding " + sid.Guide.Name + "/" + sid.ID + "...");

            var st = DateTime.Now;

            if (callback != null)
            {
                callback(0, "Downloading guide from " + sid.Guide.Name + "...");
            }

            TVShow tv;

            try
            {
                tv = sid.Guide.GetData(sid.ID, sid.Language);

                if (tv.Episodes.Count == 0)
                {
                    Log.Error("Downloaded guide for " + tv.Title + " (" + sid.Guide.Name + "/" + sid.ID + ") has no episodes.");

                    if (callback != null)
                    {
                        callback(-1, "No episodes listed for this show on " + sid.Guide.Name + ".");
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                if (ex is ThreadAbortException)
                {
                    Log.Warn("Thread aborted while downloading data from guide for " + sid.Guide.Name + "/" + sid.ID + ".", ex);
                    return(null);
                }

                Log.Error("Error while downloading data from guide for " + sid.Guide.Name + "/" + sid.ID + ".", ex);

                if (callback != null)
                {
                    callback(-1, "Error while downloading data: " + ex.Message);
                }

                return(null);
            }

            if (TVShows.Values.FirstOrDefault(x => x.Title == tv.Title) != null)
            {
                Log.Error("Duplicate entry detected for " + tv.Title + " (" + sid.Guide.Name + "/" + sid.ID + ").");

                if (callback != null)
                {
                    callback(-1, tv.Title + " is already in your database.");
                }

                return(null);
            }

            foreach (var tvs in TVShows.Values)
            {
                tvs.RowID++;
                tvs.SaveData();
            }

            tv.RowID       = 0;
            tv.ID          = TVShows.Values.Count > 0 ? TVShows.Values.Max(x => x.ID) + 1 : 1;
            tv.Data        = new Dictionary <string, string>();
            tv.Directory   = Path.Combine(DataPath, Utils.CreateSlug(tv.Title, false));
            tv.EpisodeByID = new Dictionary <int, Episode>();

            if (Directory.Exists(tv.Directory))
            {
                tv.Directory += "-" + tv.Source.ToLower();
            }

            if (Directory.Exists(tv.Directory))
            {
                tv.Directory += "-" + Utils.Rand.Next();
            }

            try
            {
                Directory.CreateDirectory(tv.Directory);
            }
            catch (Exception ex)
            {
                Log.Error("Error while creating directory db\\" + Path.GetFileName(tv.Directory) + " for " + tv.Title + " (" + sid.Guide.Name + "/" + sid.ID + ").", ex);

                if (callback != null)
                {
                    callback(-1, "Error while creating database.");
                }

                return(null);
            }

            foreach (var ep in tv.Episodes)
            {
                ep.Show = tv;
                ep.ID   = ep.Number + (ep.Season * 1000) + (tv.ID * 1000 * 1000);

                tv.EpisodeByID[ep.Number + (ep.Season * 1000)] = ep;

                if (!string.IsNullOrWhiteSpace(tv.AirTime) && ep.Airdate != Utils.UnixEpoch)
                {
                    try { ep.Airdate = DateTime.Parse(ep.Airdate.ToString("yyyy-MM-dd ") + tv.AirTime).ToLocalTimeZone(tv.TimeZone); } catch { }
                }
            }

            try
            {
                tv.Save();
                tv.SaveTracking();
            }
            catch (Exception ex)
            {
                Log.Error("Error while saving database to db\\" + Path.GetFileName(tv.Directory) + " for " + tv.Title + " (" + sid.Guide.Name + "/" + sid.ID + ").", ex);

                if (callback != null)
                {
                    callback(-1, "Error while saving to database.");
                }

                return(null);
            }

            TVShows[tv.ID] = tv;
            DataChange     = DateTime.Now;

            if (tv.Language == "en")
            {
                Updater.UpdateRemoteCache(tv);
            }

            if (callback != null)
            {
                callback(1, "Show added successfully.");
            }

            Log.Debug("Successfully added " + tv.Title + " (" + sid.Guide.Name + "/" + sid.ID + ") in " + (DateTime.Now - st).TotalSeconds + "s.");

            return(tv);
        }
Esempio n. 22
0
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable<ShowID> GetID(string name, string language = "en")
        {
            var html  = Utils.GetHTML("http://www.tv.com/search?q=" + Utils.EncodeURL(name));
            var shows = html.DocumentNode.SelectNodes("//div/h4/a");

            if (shows == null)
            {
                yield break;
            }

            foreach (var show in shows)
            {
                var id  = new ShowID(this);
                
                id.URL      = Site.TrimEnd('/') + HtmlEntity.DeEntitize(show.GetAttributeValue("href"));
                id.ID       = Regex.Match(id.URL, @"/shows/([^/]+)/").Groups[1].Value;
                id.Title    = HtmlEntity.DeEntitize(show.InnerText);
                id.Cover    = show.GetNodeAttributeValue("../../../a/img", "src");
                id.Language = "en";

                if (string.IsNullOrWhiteSpace(id.ID))
                {
                    continue;
                }

                yield return id;
            }
        }
        /// <summary>
        /// Gets the ID of a TV show in the database.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="language">The preferred language of the data.</param>
        /// <returns>ID.</returns>
        public override IEnumerable<ShowID> GetID(string name, string language = "en")
        {
            var json = (dynamic)JsonConvert.DeserializeObject(Utils.GetFastURL("https://www.googleapis.com/freebase/v1/search?query=" + Utils.EncodeURL(name) + "&filter=" + Utils.EncodeURL("(all type:/tv/tv_program)") + "&output=" + Utils.EncodeURL("(/common/topic/image /tv/tv_program/air_date_of_first_episode)")));

            if (json["result"] == null || json["result"].Count == 0)
            {
                yield break;
            }

            foreach (var show in json["result"])
            {
                var id = new ShowID(this);

                id.ID       = ((string)show["mid"]).Substring(3);
                id.URL      = Site + "m/" + id.ID;
                id.Title    = (string)show["name"] + (show["output"]["/tv/tv_program/air_date_of_first_episode"]["/tv/tv_program/air_date_of_first_episode"] != null ? " (" + ((string)show["output"]["/tv/tv_program/air_date_of_first_episode"]["/tv/tv_program/air_date_of_first_episode"][0]).Substring(0, 4) + ")" : string.Empty);
                id.Cover    = show["output"]["/common/topic/image"]["/common/topic/image"] != null ? "https://usercontent.googleapis.com/freebase/v1/image" + (string)show["output"]["/common/topic/image"]["/common/topic/image"][0]["mid"] + "?maxwidth=2048" : null;
                id.Language = "en";
                
                yield return id;
            }
        }