Exemple #1
0
 // Collection/DVD/Actors/*
 private void HandleActors(OMLSDKTitle title, XPathNavigator actorsNavigator)
 {
     foreach (XPathNavigator actorNavigator in actorsNavigator.SelectChildren("Actor", string.Empty))
     {
         string role     = actorNavigator.GetAttribute("Role", string.Empty) ?? string.Empty;
         string fullName = ReadFullName(actorNavigator);
         if (!string.IsNullOrEmpty(fullName)) // Skip dividers
         {
             title.AddActingRole(fullName, role);
         }
     }
 }
Exemple #2
0
        public static OMLSDKTitle TitleFromAmazonItem(Item amazonItem)
        {
            try
            {
                OMLSDKTitle t = new OMLSDKTitle();

                t.Name = amazonItem.ItemAttributes.Title;
                if (!String.IsNullOrEmpty(amazonItem.ASIN.ToString()))
                {
                    t.UPC = amazonItem.ASIN.ToString();
                }
                t.Synopsis = AmazonItemDescriptionToString(amazonItem);

                if (amazonItem.ItemAttributes.Actor != null)
                {
                    foreach (string actor in amazonItem.ItemAttributes.Actor)
                    {
                        t.AddActingRole(actor, "");
                    }
                }

                if (amazonItem.ItemAttributes.Director != null)
                {
                    foreach (string director in amazonItem.ItemAttributes.Director)
                    {
                        t.AddDirector(new OMLSDKPerson(director));
                    }
                }

                if (amazonItem.ItemAttributes.AudienceRating != null)
                {
                    t.ParentalRating = AmazonRatingToString(amazonItem.ItemAttributes.AudienceRating);
                }

                if (amazonItem.ItemAttributes.RunningTime != null)
                {
                    t.Runtime = Convert.ToInt32(amazonItem.ItemAttributes.RunningTime.Value);
                }

                if (amazonItem.ItemAttributes.TheatricalReleaseDate != null)
                {
                    t.ReleaseDate = AmazonYearToDateTime(amazonItem.ItemAttributes.TheatricalReleaseDate);
                }

                if (amazonItem.DetailPageURL != null)
                {
                    t.OfficialWebsiteURL = amazonItem.DetailPageURL;
                }

                if (amazonItem.ItemAttributes.Studio != null)
                {
                    t.Studio = amazonItem.ItemAttributes.Studio;
                }

                if (amazonItem.ItemAttributes.AspectRatio != null)
                {
                    t.AspectRatio = amazonItem.ItemAttributes.AspectRatio;
                }

                // add only the genres that we have in our list otherwise we get too much crap
                if (amazonItem.Subjects != null)
                {
                    foreach (string subject in amazonItem.Subjects)
                    {
                        if (Properties.Settings.Default.Genres.Contains(subject))
                        {
                            t.AddGenre(subject);
                        }
                    }
                }

                if (amazonItem.LargeImage.URL != null)
                {
                    t.FrontCoverPath = amazonItem.LargeImage.URL;// title.ImageUrl;
                }

                //DownloadImage(t, amazonItem);

                return(t);
            }
            catch
            {
                return(null);
            }
        }
Exemple #3
0
        public bool SearchForMovie(string movieName, int maxResults)
        {
            if (_xmlFile == null)
            {
                Initialize(PluginName, null);
            }
            if (_xmlFile == null)
            {
                return(false);
            }

            if (!File.Exists(_xmlFile))
            {
                return(false);
            }
            DataSet ds = new DataSet();

            ds.ReadXml(_xmlFile);
            movieName = movieName.ToLowerInvariant();
            List <DataRow> dvds = (from dvd in ds.Tables["DVD"].AsEnumerable()
                                   where dvd.Field <String>("Title").ToLowerInvariant().Contains(movieName)
                                   select dvd).ToList <DataRow>();

            List <OMLSDKTitle> dvdList = new List <OMLSDKTitle>();

            foreach (DataRow dr in dvds)
            {
                OMLSDKTitle t = new OMLSDKTitle();
                t.Name = (String)dr["Title"];

                t.ParentalRating  = (String)dr["Rating"];
                t.Synopsis        = (String)dr["Overview"];
                t.CountryOfOrigin = (String)dr["CountryOfOrigin"];
                t.UPC             = (String)dr["UPC"];
                t.OriginalName    = (String)dr["OriginalTitle"];
                t.SortName        = (String)dr["SortTitle"];

                int runTime;
                if (int.TryParse((String)dr["RunningTime"], out runTime))
                {
                    t.Runtime = runTime;
                }
                DateTime dtReleased;
                if (DateTime.TryParse((String)dr["Released"], out dtReleased))
                {
                    t.ReleaseDate = dtReleased;
                }
                int prodYr;
                if (int.TryParse((String)dr["ProductionYear"], out prodYr))
                {
                    t.ProductionYear = prodYr;
                }

                t.FrontCoverPath = Path.Combine(DVDProfilerImageDir, (String)dr["ID"] + @"f.jpg");
                t.BackCoverPath  = Path.Combine(DVDProfilerImageDir, (String)dr["ID"] + @"b.jpg");

                if (ds.Relations.Contains("DVD_Format"))
                {
                    DataRow Format = dr.GetChildRows("DVD_Format")[0];
                    t.VideoStandard   = (String)Format["FormatVideoStandard"];
                    t.VideoResolution = (String)Format["FormatAspectRatio"];
                }

                if (ds.Relations.Contains("DVD_Genres") && ds.Relations.Contains("Genres_Genre"))
                {
                    DataRow genres = dr.GetChildRows("DVD_Genres")[0];
                    foreach (DataRow gen in genres.GetChildRows("Genres_Genre"))
                    {
                        String genre = (String)gen[0];
                        t.Genres.Add(genre);
                    }
                }

                if (ds.Relations.Contains("DVD_Actors") && ds.Relations.Contains("Actors_Actor"))
                {
                    DataRow actors = dr.GetChildRows("DVD_Actors")[0];
                    foreach (DataRow actor in actors.GetChildRows("Actors_Actor"))
                    {
                        String fullName = String.Format(@"{0} {1}", actor["FirstName"], actor["LastName"]);
                        t.AddActingRole(fullName, (String)actor["Role"]);
                    }
                }

                if (ds.Relations.Contains("DVD_Credits") && ds.Relations.Contains("Credits_Credit"))
                {
                    DataRow credits = dr.GetChildRows("DVD_Credits")[0];
                    foreach (DataRow credit in credits.GetChildRows("Credits_Credit"))
                    {
                        String CreditType = (String)credit["CreditType"];
                        String fullName   = String.Format(@"{0} {1}", credit["FirstName"], credit["LastName"]);
                        if (CreditType == "Direction")
                        {
                            t.AddDirector(new OMLSDKPerson(fullName));
                        }
                        else if (CreditType == "Writing")
                        {
                            t.AddWriter(new OMLSDKPerson(fullName));
                        }
                        else if (CreditType == "Production")
                        {
                            t.AddProducer(new OMLSDKPerson(fullName));
                        }
                    }
                }

                List <String> _studios = new List <String>();
                if (ds.Relations.Contains("DVD_Studios") && ds.Relations.Contains("Studios_Studio"))
                {
                    DataRow studios = dr.GetChildRows("DVD_Studios")[0];
                    foreach (DataRow studio in studios.GetChildRows("Studios_Studio"))
                    {
                        _studios.Add((String)studio[0]);
                    }
                }
                t.Studio = String.Join("; ", _studios.ToArray <String>());
                dvdList.Add(t);
            }
            _searchResult = new DVDProfilerSearchResult(dvdList, dvds.Count, dvds.Count);
            bool rslt = (dvds.Count > 0);

            ds.Dispose(); ds = null;
            return(rslt);
        }
Exemple #4
0
        private OMLSDKTitle ReadMetaData(string movieFolder, string dvdCacheXMLFile)
        {
            OMLSDKTitle t = new OMLSDKTitle();

            try
            {
                if (File.Exists(dvdCacheXMLFile))
                {
                    XmlReaderSettings xmlSettings = new XmlReaderSettings();
                    xmlSettings.IgnoreWhitespace = false;
                    using (XmlReader reader = XmlReader.Create(dvdCacheXMLFile, xmlSettings))
                    {
                        bool bFound = reader.ReadToFollowing("MDR-DVD");
                        if (!bFound)
                        {
                            return(null);
                        }

                        bFound = reader.ReadToFollowing("dvdTitle");
                        if (!bFound)
                        {
                            return(null);
                        }
                        t.Name = reader.ReadString().Trim();

                        bFound = reader.ReadToFollowing("studio");
                        if (bFound)
                        {
                            t.Studio = reader.ReadString().Trim();
                        }

                        bFound = reader.ReadToFollowing("leadPerformer");
                        if (bFound)
                        {
                            string   leadPerformer = reader.ReadString();
                            string[] actors        = leadPerformer.Split(new char[] { ';', ',', '|' });
                            foreach (string actor in actors)
                            {
                                t.AddActingRole(actor.Trim(), "");
                            }
                        }

                        bFound = reader.ReadToFollowing("director");
                        if (bFound)
                        {
                            string   directorList = reader.ReadString();
                            string[] directors    = directorList.Split(new char[] { ';', ',', '|' });
                            foreach (string director in directors)
                            {
                                t.AddDirector(new OMLSDKPerson(director.Trim()));
                            }
                        }

                        bFound = reader.ReadToFollowing("MPAARating");
                        if (bFound)
                        {
                            t.ParentalRating = reader.ReadString().Trim();
                        }

                        bFound = reader.ReadToFollowing("language");
                        if (bFound)
                        {
                            t.AddAudioTrack(reader.ReadString().Trim());
                        }

                        bFound = reader.ReadToFollowing("releaseDate");
                        if (bFound)
                        {
                            string   releaseDate = reader.ReadString().Trim();
                            DateTime dt;
                            if (DateTime.TryParse(releaseDate, out dt))
                            {
                                t.ReleaseDate = dt;
                            }
                        }

                        bFound = reader.ReadToFollowing("genre");
                        if (bFound)
                        {
                            string   genreList = reader.ReadString();
                            string[] genres    = genreList.Split(new char[] { ';', ',', '|' });
                            foreach (string genre in genres)
                            {
                                t.AddGenre(genre.Trim());
                            }
                        }

                        string imageFileName = "";
                        bFound = reader.ReadToFollowing("largeCoverParams");
                        if (bFound)
                        {
                            imageFileName = reader.ReadString().Trim();
                            if (!File.Exists(imageFileName) && File.Exists(movieFolder + "\\folder.jpg"))
                            {
                                imageFileName = movieFolder + "\\folder.jpg";
                            }
                        }
                        else if (File.Exists(movieFolder + "\\folder.jpg"))
                        {
                            imageFileName = movieFolder + "\\folder.jpg";
                        }

                        t.FrontCoverPath = imageFileName;

                        bFound = reader.ReadToFollowing("duration");
                        if (bFound)
                        {
                            int runtime;
                            if (Int32.TryParse(reader.ReadString(), out runtime))
                            {
                                t.Runtime = runtime;
                            }
                        }

                        bFound = reader.ReadToFollowing("synopsis");
                        if (bFound)
                        {
                            t.Synopsis = reader.ReadString().Trim();
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                SDKUtilities.DebugLine("[DVDLibraryImporter] An error occured: " + ex.Message);
                return(null);
            }

            return(t);
        }
Exemple #5
0
        public override void ProcessFile(string file)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(file);

            XmlNodeList nodeList = xDoc.SelectNodes("//movielist/movie");

            foreach (XmlNode movieNode in nodeList)
            {
                OMLSDKTitle    newTitle = new OMLSDKTitle();
                XPathNavigator nav      = movieNode.CreateNavigator();

                newTitle.MetadataSourceID = GetChildNodesValue(nav, "id");
                if (nav.MoveToChild("coverfront", ""))
                {
                    newTitle.FrontCoverPath = nav.Value;
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("coverback", ""))
                {
                    newTitle.BackCoverPath = nav.Value;
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("country", ""))
                {
                    if (nav.MoveToChild("displayname", ""))
                    {
                        newTitle.CountryOfOrigin = nav.Value;
                        nav.MoveToParent();
                    }
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("title", ""))
                {
                    newTitle.Name = nav.Value;
                    nav.MoveToParent();
                }

                /*if (nav.MoveToChild("plot", ""))
                 * {
                 *  newTitle.Synopsis = nav.Value;
                 *  nav.MoveToParent();
                 * }*/

                // Fix from DVDJunkie
                // http://www.ornskov.dk/forum/index.php?topic=1605.msg12171#msg12171
                if (nav.MoveToChild("plot", ""))
                {
                    string plot = nav.Value;
                    plot = plot.Replace("<B>", "");
                    plot = plot.Replace("<b>", "");
                    plot = plot.Replace("</B>", "");
                    plot = plot.Replace("</b>", "");
                    plot = plot.Replace("<I>", "");
                    plot = plot.Replace("<i>", "");
                    plot = plot.Replace("</I>", "");
                    plot = plot.Replace("</i>", "");

                    newTitle.Synopsis = plot;
                    nav.MoveToParent();
                }

                /*if (nav.MoveToChild("releasedate", ""))
                 * {
                 *  XPathNavigator localNav = nav.CreateNavigator();
                 *  //XmlNode rdYear = nav.SelectSingleNode("year");
                 *  //XmlNode rdMonth = nav.SelectSingleNode("month");
                 *  //XmlNode rdDay = nav.SelectSingleNode("day");
                 *
                 *  //if (rdYear != null && rdMonth != null && rdDay != null)
                 *  //{
                 *  //    DateTime rd = new DateTime(Int32.Parse(rdYear.InnerText),
                 *  //                               Int32.Parse(rdMonth.InnerText),
                 *  //                               Int32.Parse(rdDay.InnerText));
                 *
                 *  //    if (rd != null)
                 *  //        newTitle.ReleaseDate = rd;
                 *  //}
                 *  nav.MoveToParent();
                 * }*/

                // Fix from DVDJunkie
                // http://www.ornskov.dk/forum/index.php?topic=1605.msg12171#msg12171
                //hwh 12-7-09
                if (nav.MoveToChild("releasedate", ""))
                {
                    XPathNavigator localNav = nav.CreateNavigator();
                    string         rdate    = GetChildNodesValue(localNav, "date");
                    try
                    {
                        if (!string.IsNullOrEmpty(rdate))
                        {
                            newTitle.ProductionYear = Convert.ToInt32(rdate);
                        }
                    }
                    catch (FormatException) { }
                    nav.MoveToParent();
                }

                //hwh 12-7-09
                if (nav.MoveToChild("dvdreleasedate", ""))
                {
                    XPathNavigator localNav = nav.CreateNavigator();
                    string         rdate    = GetChildNodesValue(localNav, "date");
                    try
                    {
                        if (!string.IsNullOrEmpty(rdate))
                        {
                            newTitle.ReleaseDate = DateTime.Parse(rdate);
                        }
                    }
                    catch (ArgumentException) { }
                    catch (FormatException) { }
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("mpaarating", ""))
                {
                    newTitle.ParentalRating = GetChildNodesValue(nav, "displayname");
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("upc", ""))
                {
                    newTitle.UPC = nav.Value;
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("runtimeminutes", ""))
                {
                    //newTitle.Runtime = nav.ValueAsInt;
                    newTitle.Runtime = ConvertStringToInt(nav.Value);
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("genres", ""))
                {
                    XPathNodeIterator genreIter = nav.SelectChildren("genre", "");
                    if (nav.MoveToFirstChild())
                    {
                        XPathNavigator localNav = nav.CreateNavigator();
                        nav.MoveToParent();

                        for (int i = 0; i < genreIter.Count; i++)
                        {
                            newTitle.AddGenre(GetChildNodesValue(localNav, "displayname"));
                            localNav.MoveToNext("genre", "");
                        }
                    }
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("cast", ""))
                {
                    XPathNodeIterator starIter = nav.SelectChildren("star", "");
                    if (nav.MoveToFirstChild())
                    {
                        XPathNavigator localNav = nav.CreateNavigator();
                        nav.MoveToParent();

                        for (int i = 0; i < starIter.Count; i++)
                        {
                            string         role      = GetChildNodesValue(localNav, "role");
                            XPathNavigator personNav = localNav.SelectSingleNode("person");
                            if (personNav != null)
                            {
                                string name = GetChildNodesValue(personNav, "displayname");
                                if (!string.IsNullOrEmpty(role) && !string.IsNullOrEmpty(name))
                                {
                                    newTitle.AddActingRole(name, role);
                                }
                            }
                            localNav.MoveToNext("star", "");
                        }
                    }
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("crew", ""))
                {
                    XPathNodeIterator crewMemberIter = nav.SelectChildren("crewmember", "");
                    if (nav.MoveToFirstChild())
                    {
                        XPathNavigator localNav = nav.CreateNavigator();
                        nav.MoveToParent();

                        for (int i = 0; i < crewMemberIter.Count; i++)
                        {
                            string         role  = GetChildNodesValue(localNav, "role");
                            XPathNavigator cmNav = localNav.SelectSingleNode("person");
                            if (cmNav != null)
                            {
                                string name = GetChildNodesValue(cmNav, "displayname");
                                if (!string.IsNullOrEmpty(role) && !string.IsNullOrEmpty(name))
                                {
                                    switch (role.ToLower())
                                    {
                                    case "director":
                                        newTitle.AddDirector(new OMLSDKPerson(name));
                                        break;

                                    case "writer":
                                        newTitle.AddWriter(new OMLSDKPerson(name));
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                            localNav.MoveToNext("crewmember", "");
                        }
                    }
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("subtitles", ""))
                {
                    XPathNodeIterator subtitleIter = nav.SelectChildren("subtitle", "");
                    if (nav.MoveToFirstChild())
                    {
                        XPathNavigator localNav = nav.CreateNavigator();
                        nav.MoveToParent();

                        for (int i = 0; i < subtitleIter.Count; i++)
                        {
                            newTitle.AddSubtitle(GetChildNodesValue(localNav, "displayname"));
                            localNav.MoveToNext("subtitle", "");
                        }
                    }
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("audios", ""))
                {
                    XPathNodeIterator audioIter = nav.SelectChildren("audio", "");
                    if (nav.MoveToFirstChild())
                    {
                        XPathNavigator localNav = nav.CreateNavigator();
                        nav.MoveToParent();

                        for (int i = 0; i < audioIter.Count; i++)
                        {
                            newTitle.AddAudioTrack(GetChildNodesValue(localNav, "displayname"));
                            localNav.MoveToNext("audio", "");
                        }
                    }
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("studios", ""))
                {
                    XPathNodeIterator studioIter = nav.SelectChildren("studio", "");
                    if (nav.MoveToFirstChild())
                    {
                        XPathNavigator localNav = nav.CreateNavigator();
                        nav.MoveToParent();

                        for (int i = 0; i < studioIter.Count; i++)
                        {
                            newTitle.Studio = GetChildNodesValue(localNav, "displayname");
                            localNav.MoveToNext("studio", "");
                        }
                    }
                    nav.MoveToParent();
                }

                if (nav.MoveToChild("links", ""))
                {
                    XPathNodeIterator linkIter = nav.SelectChildren("link", "");
                    if (nav.MoveToFirstChild())
                    {
                        XPathNavigator localNav = nav.CreateNavigator();
                        nav.MoveToParent();

                        for (int i = 0; i < linkIter.Count; i++)
                        {
                            string type = GetChildNodesValue(localNav, "urltype");
                            if (!string.IsNullOrEmpty(type))
                            {
                                if (type.ToUpper().CompareTo("MOVIE") == 0)
                                {
                                    string path = GetChildNodesValue(localNav, "url");
                                    if (!string.IsNullOrEmpty(path))
                                    {
                                        try
                                        {
                                            FileInfo fi = new FileInfo(path);
                                            if (fi.Exists)
                                            {
                                                string ext = fi.Extension.Substring(1);
                                                if (!string.IsNullOrEmpty(ext))
                                                {
                                                    if (IsSupportedFormat(ext))
                                                    {
                                                        OMLSDKDisk disk = new OMLSDKDisk();
                                                        disk.Format = (OMLSDKVideoFormat)Enum.Parse(typeof(OMLSDKVideoFormat), ext, true);
                                                        disk.Path   = path;
                                                        disk.Name   = GetChildNodesValue(localNav, "description");
                                                        newTitle.AddDisk(disk);
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            SDKUtilities.DebugLine("MovieCollectorzPlugin: {0}", ex);
                                        }
                                    }
                                }
                            }
                            localNav.MoveToNext("link", "");
                        }
                    }
                }

                if (ValidateTitle(newTitle))
                {
                    try
                    {
                        AddTitle(newTitle);
                    }
                    catch (Exception e)
                    {
                        SDKUtilities.DebugLine("[MovieCollectorzPlugin] Error adding row: " + e.Message);
                    }
                }
                else
                {
                    SDKUtilities.DebugLine("[MovieCollectorzPlugin] Error saving row");
                }
            }
        }
Exemple #6
0
        public override void ProcessFile(string file)
        {
            OMLSDKTitle newTitle = new OMLSDKTitle();
            String      fPath    = Path.GetDirectoryName(file);

            newTitle.Name = Path.GetFileNameWithoutExtension(file);
            IDictionary         meta;
            DvrmsMetadataEditor editor = new DvrmsMetadataEditor(file);

            meta = editor.GetAttributes();
            foreach (string item in meta.Keys)
            {
                MetadataItem attr = (MetadataItem)meta[item];
                switch (item)
                {
                case DvrmsMetadataEditor.Title:
                    string sTitle = (string)attr.Value;
                    sTitle = sTitle.Trim();
                    if (!String.IsNullOrEmpty(sTitle))
                    {
                        newTitle.Name = sTitle;
                    }
                    newTitle.ImporterSource     = @"DVRMSImporter";
                    newTitle.MetadataSourceName = @"DVR-MS";
                    OMLSDKDisk disk = new OMLSDKDisk();
                    string     ext  = Path.GetExtension(file).Substring(1).Replace(@"-", @"");
                    disk.Format = (OMLSDKVideoFormat)Enum.Parse(typeof(OMLSDKVideoFormat), ext, true);
                    SDKUtilities.DebugLine("[DVRMSPlugin] Adding file: " + Path.GetFullPath(file));
                    disk.Path = Path.GetFullPath(file);
                    disk.Name = @"Disk 1";
                    newTitle.AddDisk(disk);
                    //newTitle.FileLocation = file;
                    if (!String.IsNullOrEmpty(newTitle.AspectRatio))
                    {
                        newTitle.AspectRatio = @"Widescreen";
                    }
                    //string ext = Path.GetExtension(file).Substring(1).Replace(@"-", @"");
                    //newTitle.VideoFormat = (VideoFormat)Enum.Parse(typeof(VideoFormat), ext, true);
                    string cover = fPath + @"\" + Path.GetFileNameWithoutExtension(file) + @".jpg";
                    if (File.Exists(cover))
                    {
                        SDKUtilities.DebugLine("[DVRMSPlugin] Setting CoverArt: " + Path.GetFullPath(cover));
                        newTitle.FrontCoverPath = Path.GetFullPath(cover);
                        //newTitle.FrontCoverPath = cover;
                    }
                    else
                    {
                        SDKUtilities.DebugLine("[DVRMSPlugin] No coverart found");
                    }
                    break;

                case DvrmsMetadataEditor.MediaOriginalBroadcastDateTime:
                    string sDT = (string)attr.Value;
                    if (!String.IsNullOrEmpty(sDT))
                    {
                        DateTime dt;
                        if (DateTime.TryParse(sDT, out dt))
                        {
                            newTitle.ReleaseDate = dt;
                        }
                    }
                    break;

                case DvrmsMetadataEditor.Genre:
                    if (!String.IsNullOrEmpty((string)attr.Value))
                    {
                        string   sGenre = (string)attr.Value;
                        string[] gen    = sGenre.Split(',');
                        newTitle.Genres.Clear();
                        foreach (string genre in gen)
                        {
                            string uGenre = genre.ToUpper().Trim();
                            if (String.IsNullOrEmpty(uGenre))
                            {
                                continue;
                            }
                            if (uGenre.StartsWith(@"MOVIE"))
                            {
                                continue;
                            }
                            uGenre = genre.Trim();
                            newTitle.AddGenre(uGenre);
                        }
                    }
                    break;

                case DvrmsMetadataEditor.Duration:
                    Int64 rTime = (long)attr.Value;
                    rTime            = rTime / 600 / 1000000;
                    newTitle.Runtime = (int)rTime;
                    break;

                case DvrmsMetadataEditor.ParentalRating:
                    if (!String.IsNullOrEmpty((string)attr.Value))
                    {
                        newTitle.ParentalRating = (string)attr.Value;
                    }
                    break;

                case DvrmsMetadataEditor.Credits:
                    string persona = (string)attr.Value;
                    persona += @";;;;";
                    string[] credits = persona.Split(';');
                    string[] cast    = credits[0].Split('/');
                    foreach (string nm in cast)
                    {
                        if (!String.IsNullOrEmpty(nm))
                        {
                            newTitle.AddActingRole(nm, "");
                        }
                    }
                    string[] dirs = credits[1].Split('/');
                    if (dirs.Length > 0)
                    {
                        if (!String.IsNullOrEmpty(dirs[0]))
                        {
                            string nm = dirs[0];
                            newTitle.AddDirector(new OMLSDKPerson(nm));
                        }
                    }

                    break;

                case DvrmsMetadataEditor.SubtitleDescription:
                    newTitle.Synopsis = (string)attr.Value;
                    break;
                }
                attr = null;
            }

            if (ValidateTitle(newTitle))
            {
                try
                {
                    if (String.IsNullOrEmpty(newTitle.Name))
                    {
                        newTitle.Name               = Path.GetFileNameWithoutExtension(file);
                        newTitle.ImporterSource     = @"DVRMSImporter";
                        newTitle.MetadataSourceName = @"DVR-MS";
                        OMLSDKDisk disk = new OMLSDKDisk();
                        disk.Name = @"Disk 1";
                        disk.Path = file;
                        //newTitle.FileLocation = file;
                        string ext = Path.GetExtension(file).Substring(1).Replace(@"-", @"");
                        //newTitle.VideoFormat = (VideoFormat)Enum.Parse(typeof(VideoFormat), ext, true);
                        disk.Format = (OMLSDKVideoFormat)Enum.Parse(typeof(OMLSDKVideoFormat), ext, true);
                        newTitle.AddDisk(disk);
                        string cover = fPath + @"\" + Path.GetFileNameWithoutExtension(file) + @".jpg";
                        if (File.Exists(Path.GetFullPath(cover)))
                        {
                            SDKUtilities.DebugLine("[DVRMSPlugin] Setting CoverArt: " + Path.GetFullPath(cover));
                            newTitle.FrontCoverPath = cover;
                        }
                        else
                        {
                            SDKUtilities.DebugLine("[DVRMSPlugin] No coverart found");
                        }
                    }
                    if (String.IsNullOrEmpty(newTitle.AspectRatio))
                    {
                        newTitle.AspectRatio = @"Widescreen";
                    }
                    if (String.IsNullOrEmpty(newTitle.ParentalRating))
                    {
                        newTitle.ParentalRating = @"--";
                    }
                    AddTitle(newTitle);
                }
                catch (Exception e)
                {
                    Trace.WriteLine("[DVRMSPlugin] Error adding row: " + e.Message);
                }
            }
            else
            {
                Trace.WriteLine("[DVRMSPlugin] Error saving row");
            }
        }
Exemple #7
0
        private void loadDataFromNavigatorToTitle(ref XPathNavigator navigator, ref OMLSDKTitle newTitle)
        {
            SDKUtilities.DebugLine("[MyMoviesImporter] Loading data for a new title");
            newTitle.MetadataSourceID = GetChildNodesValue(navigator, "WebServiceID");

            #region covers
            SDKUtilities.DebugLine("[MyMoviesImporter] Scanning for {0} node", "Covers");
            if (navigator.MoveToChild("Covers", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Covers found, processing");
                SDKUtilities.DebugLine("[MyMoviesImporter] Scanning for {0} node", "Front");
                if (navigator.MoveToChild("Front", ""))
                {
                    string imagePath      = navigator.Value;
                    string finalImagePath = FindFinalImagePath(imagePath);
                    SDKUtilities.DebugLine("[MyMoviesImporter] Final image path is: {0}", finalImagePath);
                    if (File.Exists(finalImagePath))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] This file appears to be valid, we'll set it on the title");
                        newTitle.FrontCoverPath = finalImagePath;
                    }
                    navigator.MoveToParent();
                }
                SDKUtilities.DebugLine("[MyMoviesImporter] Scanning for {0} node", "Back");
                if (navigator.MoveToChild("Back", ""))
                {
                    string imagePath = navigator.Value;
                    if (File.Exists(imagePath))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] Found Back cover image");
                        newTitle.BackCoverPath = imagePath;
                    }
                    navigator.MoveToParent();
                }

                navigator.MoveToParent();
            }
            #endregion

            newTitle.Synopsis = GetChildNodesValue(navigator, "Description");

            #region production year
            if (navigator.MoveToChild("ProductionYear", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Found production year, I hope the format is something we can read");
                try
                {
                    string year = navigator.Value;
                    if (!string.IsNullOrEmpty(year))
                    {
                        DateTime rls_date = new DateTime(int.Parse(year), 1, 1);
                        if (rls_date != null)
                        {
                            SDKUtilities.DebugLine("[MyMoviesImporter] Got it, loading the production year");
                            newTitle.ReleaseDate = rls_date;
                        }
                    }
                    navigator.MoveToParent();
                }
                catch (Exception e)
                {
                    navigator.MoveToParent();
                    SDKUtilities.DebugLine("[MyMoviesImporter] error reading ProductionYear: " + e.Message);
                }
            }
            #endregion

            #region parental rating (mpaa rating)
            if (navigator.MoveToChild("ParentalRating", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Scanning for the ParentalRating");
                if (navigator.HasChildren)
                {
                    string ratingId = GetChildNodesValue(navigator, "Value");
                    if (!string.IsNullOrEmpty(ratingId))
                    {
                        int mmRatingId;
                        if (int.TryParse(ratingId, out mmRatingId))
                        {
                            switch (mmRatingId)
                            {
                            case 0:
                                SDKUtilities.DebugLine("[MyMoviesImporter] This appears to be unrated");
                                newTitle.ParentalRating = "Unrated";
                                break;

                            case 1:
                                SDKUtilities.DebugLine("[MyMoviesImporter] This appears to be rated G");
                                newTitle.ParentalRating = "G";
                                break;

                            case 2:
                                SDKUtilities.DebugLine("[MyMoviesImporter] I have no idea what rating this is");
                                break;

                            case 3:
                                SDKUtilities.DebugLine("[MyMoviesImporter] This appears to be rated PG");
                                newTitle.ParentalRating = "PG";
                                break;

                            case 4:
                                SDKUtilities.DebugLine("[MyMoviesImporter] This appears to be rated PG13");
                                newTitle.ParentalRating = "PG13";
                                break;

                            case 5:
                                SDKUtilities.DebugLine("[MyMoviesImporter] I have NO idea what rating this is");
                                break;

                            case 6:
                                SDKUtilities.DebugLine("[MyMoviesImporter] This appears to be rated R");
                                newTitle.ParentalRating = "R";
                                break;
                            }
                        }
                        else
                        {
                            SDKUtilities.DebugLine("[MyMoviesImporter] Error parsing rating: {0} not a number", ratingId);
                        }
                    }
                    string ratingReason = GetChildNodesValue(navigator, "Description");
                    if (!string.IsNullOrEmpty(ratingReason))
                    {
                        newTitle.ParentalRatingReason = ratingReason;
                    }
                }
                navigator.MoveToParent();
            }
            #endregion

            newTitle.Runtime = Int32.Parse(GetChildNodesValue(navigator, "RunningTime"));

            #region persons
            if (navigator.MoveToChild("Persons", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Beginning the long, painful process of scanning people");
                if (navigator.HasChildren)
                {
                    XPathNodeIterator nIter = navigator.SelectChildren("Person", "");
                    if (navigator.MoveToFirstChild())
                    {
                        XPathNavigator localNav = navigator.CreateNavigator();
                        navigator.MoveToParent();
                        for (int i = 0; i < nIter.Count; i++)
                        {
                            string name = GetChildNodesValue(localNav, "Name");
                            string role = GetChildNodesValue(localNav, "Role");
                            string type = GetChildNodesValue(localNav, "Type");

                            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(type))
                            {
                                switch (type)
                                {
                                case "Actor":
                                    SDKUtilities.DebugLine("[MyMoviesImporter] actor {0}, {1}", name, role);

                                    newTitle.AddActingRole(name, role);
                                    break;

                                case "Director":
                                    SDKUtilities.DebugLine("[MyMoviesImporter] director {0}", name);

                                    newTitle.AddDirector(new OMLSDKPerson(name));
                                    break;

                                default:
                                    break;
                                }
                            }
                            localNav.MoveToNext("Person", "");
                        }
                    }
                }
                navigator.MoveToParent();
            }
            #endregion

            #region studio (s)
            if (navigator.MoveToChild("Studios", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Ahh... Studios (pssst.. we only copy the last entry from here... dont tell anyone)");
                if (navigator.HasChildren)
                {
                    XPathNodeIterator nIter = navigator.SelectChildren("Studio", "");
                    if (navigator.MoveToFirstChild())
                    {
                        XPathNavigator localNav = navigator.CreateNavigator();
                        navigator.MoveToParent();
                        for (int i = 0; i < nIter.Count; i++)
                        {
                            newTitle.Studio = localNav.Value;
                        }
                    }
                }
                navigator.MoveToParent();
            }
            #endregion

            newTitle.CountryOfOrigin = GetChildNodesValue(navigator, "Country");
            newTitle.AspectRatio     = GetChildNodesValue(navigator, "AspectRatio");
            newTitle.VideoStandard   = GetChildNodesValue(navigator, "VideoStandard");
            newTitle.OriginalName    = GetChildNodesValue(navigator, "OriginalTitle");
            newTitle.SortName        = GetChildNodesValue(navigator, "SortTitle");

            #region genres
            if (navigator.MoveToChild("Genres", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Genres... good old genres");
                XPathNodeIterator nIter = navigator.SelectChildren("Genre", "");
                if (navigator.MoveToFirstChild())
                {
                    XPathNavigator localNav = navigator.CreateNavigator();
                    navigator.MoveToParent();
                    for (int i = 0; i < nIter.Count; i++)
                    {
                        newTitle.AddGenre(localNav.Value);
                        localNav.MoveToNext("Genre", "");
                    }
                }
                navigator.MoveToParent();
            }
            #endregion

            #region audio tracks
            if (navigator.MoveToChild("AudioTracks", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] AudioTracks.. yeah, like you can even change them anyway");
                XPathNodeIterator nIter = navigator.SelectChildren("AudioTrack", "");
                if (navigator.MoveToFirstChild())
                {
                    XPathNavigator localNav = navigator.CreateNavigator();
                    navigator.MoveToParent();
                    for (int i = 0; i < nIter.Count; i++)
                    {
                        string audioLanguage = localNav.GetAttribute("Language", "");
                        string audioType     = localNav.GetAttribute("Type", "");
                        string audioChannels = localNav.GetAttribute("Channels", "");

                        if (!string.IsNullOrEmpty(audioLanguage))
                        {
                            string audioTrackString = audioLanguage;
                            if (!string.IsNullOrEmpty(audioType))
                            {
                                audioTrackString += string.Format(", {0}", audioType);
                            }

                            if (!string.IsNullOrEmpty(audioChannels))
                            {
                                audioTrackString += string.Format(", {0}", audioChannels);
                            }

                            SDKUtilities.DebugLine("[MyMoviesImporter] Got one: {0}, {1}, {2}", audioLanguage, audioType, audioChannels);
                            newTitle.AddAudioTrack(audioTrackString);
                        }
                        localNav.MoveToNext("AudioTrack", "");
                    }
                }
                navigator.MoveToParent();
            }
            #endregion

            #region watched status (Submitted by yodine from our forums)
            if (navigator.MoveToChild("Watched", ""))
            {
                navigator.MoveToParent(); // move back, we just wanted to know this field existed.
                SDKUtilities.DebugLine("[MyMoviesImporter] Found Watched status. Trying to decode");
                string watched = GetChildNodesValue(navigator, "Watched");
                if (!string.IsNullOrEmpty(watched))
                {
                    if (Boolean.Parse(watched))
                    {
                        newTitle.WatchedCount++;
                    }
                }
            }
            #endregion

            #region subtitles
            if (navigator.MoveToChild("Subtitles", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Subtitles here we come!");
                if (navigator.GetAttribute("NotPresent", "").CompareTo("False") == 0)
                {
                    XPathNodeIterator nIter = navigator.SelectChildren("Subtitle", "");
                    if (navigator.MoveToFirstChild())
                    {
                        XPathNavigator localNav = navigator.CreateNavigator();
                        navigator.MoveToParent();
                        for (int i = 0; i < nIter.Count; i++)
                        {
                            string subtitleLanguage = localNav.GetAttribute("Language", "");
                            if (!string.IsNullOrEmpty(subtitleLanguage))
                            {
                                SDKUtilities.DebugLine("[MyMoviesImporter] Subtitle {0}", subtitleLanguage);
                                newTitle.AddSubtitle(subtitleLanguage);
                            }

                            localNav.MoveToNext("Subtitle", "");
                        }
                    }
                }
                navigator.MoveToParent();
            }
            #endregion

            #region discs
            if (navigator.MoveToChild("Discs", ""))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Discs... ok here is the good one, we'll passing this off to some other method to handle.");
                XPathNodeIterator nIter = navigator.SelectChildren("Disc", "");
                if (navigator.MoveToFirstChild())
                {
                    XPathNavigator localNav = navigator.CreateNavigator();
                    extractDisksFromXML(nIter, localNav, newTitle);
                    navigator.MoveToParent();
                }
                navigator.MoveToParent();
            }
            #endregion
        }