Example #1
0
        public int Load(bool ForceFromInternet = false)
        {
            try
            {
                this.CompletionLevel = MetaCompletionLevel.Loading;
                string filenameNoExtension = Filename.Substring(0, Filename.LastIndexOf("."));
                // if there is already a nfo file, skip it
                string path = new FileInfo(Filename).Directory.FullName;
                this.NfoFile = filenameNoExtension + ".nfo";
                if (!ForceFromInternet && File.Exists(this.NfoFile))
                {
                    // load nfo
                    LoadFromNfo();
                    return(1);
                }
                else
                {
                    this.FileInfo = VideoFileMeta.Load(Filename);
                    // lookup
                    if (LoadFromTheTvDb())
                    {
                        Save();
                    }
                    return(2);
                }
            }
            finally
            {
                if (this.Episodes == null || this.Episodes.Length == 0)
                {
                    this.CompletionLevel = MetaCompletionLevel.None;
                }
                else
                {
                    this.CompletionLevel = MetaCompletionLevel.Full;
                    if (Settings.AutoRenameEpisodes)
                    {
                        RenameEpisode();
                    }
                }

                if (this.Episodes != null && this.Episodes.Length > 0)
                {
                    this.Rating = (from e in this.Episodes select e.Rating).Average();
                }
            }
        }
Example #2
0
 public static VideoFileMeta Load(XElement Element)
 {
     try
     {
         VideoFileMeta meta = new VideoFileMeta();
         // load video track
         if (Element.Element("streamdetails").Element("video") != null)
         {
             VideoTrack video = new VideoTrack();
             if (NfoLoader.Load <VideoTrack>(video, Element.Element("streamdetails").Element("video")))
             {
                 meta.Video = video;
             }
         }
         // load audio tracks
         foreach (XElement eleAudio in Element.Element("streamdetails").Elements("audio"))
         {
             AudioTrack audio = new AudioTrack();
             if (NfoLoader.Load <AudioTrack>(audio, eleAudio))
             {
                 meta.Audio = meta.Audio.Union(new AudioTrack[] { audio }).ToArray();
             }
         }
         // load subtitle tracks
         foreach (XElement eleSubtitle in Element.Element("streamdetails").Elements("subtitle"))
         {
             SubtitleTrack subtitle = new SubtitleTrack();
             if (NfoLoader.Load <SubtitleTrack>(subtitle, eleSubtitle))
             {
                 meta.Subtitles = meta.Subtitles.Union(new SubtitleTrack[] { subtitle }).ToArray();
             }
         }
         return(meta);
     }
     catch (Exception) { return(null); }
 }
Example #3
0
 public static VideoFileMeta Load(XElement Element)
 {
     try
     {
         VideoFileMeta meta = new VideoFileMeta();
         // load video track
         if (Element.Element("streamdetails").Element("video") != null)
         {
             VideoTrack video = new VideoTrack();
             if (NfoLoader.Load<VideoTrack>(video, Element.Element("streamdetails").Element("video")))
                 meta.Video = video;
         }
         // load audio tracks
         foreach(XElement eleAudio in Element.Element("streamdetails").Elements("audio"))
         {
             AudioTrack audio = new AudioTrack();
             if (NfoLoader.Load<AudioTrack>(audio, eleAudio))
                 meta.Audio = meta.Audio.Union(new AudioTrack[] { audio }).ToArray();
         }
         // load subtitle tracks
         foreach (XElement eleSubtitle in Element.Element("streamdetails").Elements("subtitle"))
         {
             SubtitleTrack subtitle = new SubtitleTrack();
             if (NfoLoader.Load<SubtitleTrack>(subtitle, eleSubtitle))
                 meta.Subtitles = meta.Subtitles.Union(new SubtitleTrack[] { subtitle }).ToArray();
         }
         return meta;
     }
     catch (Exception) { return null; }
 }
Example #4
0
 public TvEpisodeMeta(string Filename) : base(Filename)
 {
     this.FileInfo = VideoFileMeta.Load(Filename);
 }
Example #5
0
        private bool LoadFromTheMovieDb(bool ForceRefresh = false)
        {
            try
            {
                Logger.Log("Loading from TheMovieDb: {0}", this.Filename);
                TheMovieDb.TmdbApi api        = new TheMovieDb.TmdbApi("1f5e5026bd038bfcfe62261e6da0634f");
                string             foldername = "";
                foreach (Match match in Regex.Matches(Filename, @"(?<=((\\|/)))[^\\/]+(?=(\\|/))"))
                {
                    foldername = match.Value;
                }

                // see if there is year in the foldername
                string year = null;
                if (Regex.IsMatch(foldername, @"(?<=(\())[\d]{4}(?=(\)))"))
                {
                    year = Regex.Match(foldername, @"(?<=(\())[\d]{4}(?=(\)))").Value;
                }

                string movieTitle = Regex.Match(foldername, @"^[^(\[]+").Value.Trim();
                string matchTitle = Regex.Replace(movieTitle.ToLower(), "[^a-z0-9]", "");
                string searchStr  = movieTitle.Replace(" - ", " ").Replace(".", " ").Replace("_", " ");
                Logger.Log("Searching Str: {0}", searchStr);
                IEnumerable <TheMovieDb.TmdbMovie> results = api.MovieSearch(searchStr, ForceRefresh);
                string[]             names = (from r in results select r.Name).ToArray();
                TheMovieDb.TmdbMovie movie = null;
                foreach (TheMovieDb.TmdbMovie result in results)
                {
                    Logger.Log("Search result: {0} ({1})", result.Name, result.Released);
                    if (movie == null)
                    {
                        movie = result;
                    }
                    List <string> resultMatchTitles = new string[] { Regex.Replace(result.Name.ToLower(), "[^a-z0-9]", "") }.ToList();
                    if (!String.IsNullOrEmpty(result.AlternativeName))
                    {
                        resultMatchTitles.Add(Regex.Replace(result.AlternativeName.ToLower(), "[^a-z0-9]", ""));
                    }
                    if (year != null && result.Released != null && Regex.Match(result.Released, @"[\d]{4}").Value == year)
                    {
                        // likely to be this
                        if (resultMatchTitles.Contains(matchTitle))
                        {
                            // exact match!!!
                            movie = result;
                            break;
                        }
                    }
                    else if (String.IsNullOrEmpty(year) && resultMatchTitles.Contains(matchTitle))     // if year is specified, then the year MUST match
                    {
                        movie = result;
                    }
                }

                if (movie != null)
                {
                    Logger.Log("Found movie id: {0}", movie.Id);
                    // get complete data
                    movie = api.GetMovieInfo(movie.Id, ForceRefresh);

                    MatchCollection tags = Regex.Matches(foldername, @"(?<=(\[))[^\]]+(?=(\]))");
                    this.Tags = new string[tags.Count];
                    for (int i = 0; i < tags.Count; i++)
                    {
                        this.Tags[i] = tags[i].Value;
                    }

                    this.Actors        = (from c in movie.Cast ?? new List <TheMovieDb.TmdbCastPerson>() where new string[] { "acting", "actor", "actors" }.Contains(c.Department.ToLower()) select new KeyValuePair <string, string>(c.Name, c.Character)).ToArray();
                    this.Directors     = (from c in movie.Cast ?? new List <TheMovieDb.TmdbCastPerson>() where new string[] { "directing", "director" }.Contains(c.Department.ToLower()) select c.Name).ToArray();
                    this.Writers       = (from c in movie.Cast ?? new List <TheMovieDb.TmdbCastPerson>() where new string[] { "writing", "writer" }.Contains(c.Department.ToLower()) select c.Name).ToArray();
                    this.Genres        = (from g in movie.Genres ?? new List <TheMovieDb.TmdbGenre>() select g.Name).ToArray();
                    this.Id            = movie.ImdbId;
                    this.Mpaa          = movie.Certification;
                    this.OriginalTitle = movie.OriginalName ?? movie.Name;
                    //this.Outline = movie.Overview;
                    this.Plot   = movie.Overview;
                    this.Rating = float.Parse(movie.Rating ?? "0");
                    int runtime = 0;
                    if (int.TryParse(movie.Runtime, out runtime))
                    {
                        this.Runtime = runtime * 60;     // convert to seconds
                    }
                    this.SortTitle = movie.Name;
                    this.TagLine   = movie.Tagline;
                    this.Title     = movie.Name;
                    this.Trailer   = movie.Trailer;
                    this.Votes     = int.Parse(movie.Votes ?? "0");
                    if (Regex.IsMatch(movie.Released ?? "", @"[\d]{4}"))
                    {
                        this.Year = int.Parse(Regex.Match(movie.Released, @"[\d]{4}").Value ?? "0");
                    }
                    if (Regex.IsMatch(movie.Released ?? "", @"[\d]{4}-[\d]{2}-[\d]{2}"))
                    {
                        this.ReleaseDate = DateTime.ParseExact(Regex.Match(movie.Released, @"[\d]{4}-[\d]{2}-[\d]{2}").Value, "yyyy-MM-dd", new CultureInfo("en-us"));
                    }

                    List <TheMovieDb.TmdbImage> posters = (from p in movie.Posters ?? new List <TheMovieDb.TmdbImage>() where p.ImageInfo.Size == "mid" select p).ToList();
                    if (posters != null && posters.Count > 0)
                    {
                        this.PosterUrl = posters[0].ImageInfo.Url;
                        if (posters.Count > 1 && this.Tags != null && this.Tags.Length > 0)
                        {
                            this.PosterUrl = posters[1].ImageInfo.Url;
                        }
                    }

                    // backgrounds
                    TheMovieDb.TmdbImage[] backdrops = (from bd in movie.Backdrops ?? new List <TheMovieDb.TmdbImage>() where bd.ImageInfo.Size == "w1280" select bd).ToArray();
                    if (backdrops.Length > 0)
                    {
                        this.FanArtUrls = new string[backdrops.Length];
                        for (int i = 0; i < backdrops.Length; i++)
                        {
                            this.FanArtUrls[i] = backdrops[i].ImageInfo.Url;
                        }
                    }

                    // movie file meta
                    this.FileInfo = VideoFileMeta.Load(Filename);

                    // rename it.
                    MovieRenamer.Rename(this);

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message + Environment.NewLine + ex.StackTrace);
            }
            return(false);
        }