Exemplo n.º 1
0
        private OMLSDKDisk DiskForFormatAndLocation(OMLSDKVideoFormat format, string location)
        {
            OMLSDKDisk disk = new OMLSDKDisk();

            disk.Format = format;
            disk.Path   = location;

            return(disk);
        }
Exemplo n.º 2
0
        public void GetMovies(string startFolder)
        {
            try
            {
                List <string> moviePaths = new List <string>();


                List <string> dirList  = new List <string>();
                List <string> fileList = new List <string>();
                GetSubFolders(startFolder, dirList);

                // the share or link may not exist nowbb
                if (Directory.Exists(startFolder))
                {
                    dirList.Add(startFolder);
                }

                foreach (string currentFolder in dirList)
                {
                    SDKUtilities.DebugLine("DVDImporter: folder " + currentFolder);
                    if (currentFolder.ToUpperInvariant().Contains("fanart".ToUpperInvariant()))
                    {
                        SDKUtilities.DebugLine("[DVDImporter] Skipping fanart directory");
                    }
                    else
                    {
                        OMLSDKTitle dvd       = GetDVDMetaData(currentFolder);
                        string[]    fileNames = null;
                        try
                        {
                            fileNames = Directory.GetFiles(currentFolder);
                        }
                        catch
                        {
                            fileNames = null;
                        }

                        if (dvd != null)
                        {
                            // if any video files are found in the DVD folder assume they are trailers
                            if (fileNames != null)
                            {
                                foreach (string video in fileNames)
                                {
                                    string extension = Path.GetExtension(video).ToUpper();
                                    if (Enum.IsDefined(typeof(OMLSDKVideoFormat), extension.ToUpperInvariant()))
                                    {
                                        foreach (OMLSDKVideoFormat format in Enum.GetValues(typeof(OMLSDKVideoFormat)))
                                        {
                                            if (Enum.GetName(typeof(OMLSDKVideoFormat), format).ToLowerInvariant() == extension)
                                            {
                                                dvd.AddTrailer(video);
                                            }
                                        }
                                    }
                                }
                            }
                            AddTitle(dvd);
                        }// found dvd
                        else
                        {
                            if (fileNames != null && fileNames.Length > 0)
                            {
                                if (OMLEngine.Settings.OMLSettings.TreatFoldersAsTitles)
                                {
                                    OMLSDKTitle newVideo = new OMLSDKTitle();

                                    // Create the title name
                                    DirectoryInfo di = new DirectoryInfo(currentFolder);
                                    newVideo.Name = "";
                                    if (OMLEngine.Settings.OMLSettings.AddParentFoldersToTitleName)
                                    {
                                        // If AddParentFolderToTitleName is true then check if the parent folder
                                        // Is the startfolder. If not add parent folder to name
                                        DirectoryInfo st = new DirectoryInfo(startFolder);
                                        if (st.Name != di.Parent.Name)
                                        {
                                            newVideo.Name = di.Parent.Name + " - ";
                                        }
                                    }
                                    newVideo.Name += (new DirectoryInfo(currentFolder)).Name;

                                    int diskNumber = 1;
                                    foreach (string video in fileNames)
                                    {
                                        try
                                        {
                                            string extension = Path.GetExtension(video).ToUpper().Substring(1);
                                            extension = extension.Replace("-", "");


                                            if (Enum.IsDefined(typeof(OMLSDKVideoFormat), extension.ToUpperInvariant()))
                                            {
                                                OMLSDKDisk disk = new OMLSDKDisk();
                                                disk.Path   = video;
                                                disk.Format = (OMLSDKVideoFormat)Enum.Parse(typeof(OMLSDKVideoFormat), extension, true);
                                                disk.Name   = string.Format("Disk {0}", diskNumber++);
                                                newVideo.AddDisk(disk);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            SDKUtilities.DebugLine("[DVDLibraryImporter] Problem importing file " + video + " : " + ex.Message);
                                        }
                                    }

                                    if (File.Exists(Path.Combine(currentFolder, "folder.jpg")))
                                    {
                                        newVideo.FrontCoverPath = Path.Combine(currentFolder, "folder.jpg");
                                    }

                                    if (newVideo.Disks.Count > 0)
                                    {
                                        // There is one or more valid disks for this title. Add it.
                                        //string temp = newVideo.BackDropFolder; // This initialises the fanart folder forcing a search for fanart
                                        AddTitle(newVideo);
                                    }
                                }
                                else
                                {
                                    foreach (string video in fileNames)
                                    {
                                        try
                                        {
                                            string extension = Path.GetExtension(video).ToUpper().Substring(1);
                                            extension = extension.Replace("-", "");

                                            if (Enum.IsDefined(typeof(OMLSDKVideoFormat), extension.ToUpperInvariant()))
                                            {
                                                // this isn't 100% safe since there are videoformats that don't map 1-1 to extensions
                                                OMLSDKVideoFormat videoFormat = (OMLSDKVideoFormat)Enum.Parse(typeof(OMLSDKVideoFormat), extension, true);

                                                OMLSDKTitle newVideo = new OMLSDKTitle();
                                                newVideo.Name = GetSuggestedMovieName(Path.GetFileNameWithoutExtension(video));
                                                OMLSDKDisk disk = new OMLSDKDisk();
                                                disk.Path   = video;
                                                disk.Name   = "Disk 1";
                                                disk.Format = videoFormat;

                                                string pathWithNoExtension = Path.GetDirectoryName(video) + "\\" + Path.GetFileNameWithoutExtension(video);
                                                if (File.Exists(pathWithNoExtension + ".jpg"))
                                                {
                                                    newVideo.FrontCoverPath = pathWithNoExtension + ".jpg";
                                                }
                                                else if (File.Exists(video + ".jpg"))
                                                {
                                                    newVideo.FrontCoverPath = video + ".jpg";
                                                }
                                                else if (File.Exists(Path.GetDirectoryName(video) + "\\folder.jpg"))
                                                {
                                                    newVideo.FrontCoverPath = Path.GetDirectoryName(video) + "\\folder.jpg";
                                                }

                                                newVideo.AddDisk(disk);
                                                //string temp = newVideo.BackDropFolder; // This initialises the fanart folder forcing a search for fanart
                                                AddTitle(newVideo);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            SDKUtilities.DebugLine("[DVDLibraryImporter] Problem importing file " + video + " : " + ex.Message);
                                        }
                                    }
                                }
                            }
                        }
                    }
                } // loop through the sub folders
            }
            catch (Exception ex)
            {
                SDKUtilities.DebugLine("[DVDLibraryImporter] An error occured: " + ex.Message);
            }
        }
Exemplo n.º 3
0
        private OMLSDKTitle GetDVDMetaData(string folderName)
        {
            try
            {
                string xmlFile = "";

                DirectoryType dirType = GetDirectoryType(folderName);

                if (dirType != DirectoryType.Normal)
                {
                    string[] xmlFiles = Directory.GetFiles(folderName, "*dvdid.xml");
                    if (xmlFiles.Length > 0)
                    {
                        //xmlFile = Path.GetFileName(xmlFiles[0]); // get the first one
                        xmlFile = xmlFiles[0];
                    }
                    //else
                    //{
                    //    xmlFiles = Directory.GetFiles(folderName, "*xml");
                    //    if (xmlFiles.Length > 0)
                    //        //xmlFile = Path.GetFileName(xmlFiles[0]); // get the first one
                    //        xmlFile = xmlFiles[0]; // get the first one
                    //    else
                    //        xmlFile = "";
                    //}

                    OMLSDKTitle t = null;
                    // xmlFile contains the dvdid - then we need to lookup in the cache folder based on this id
                    if (xmlFile != "" && File.Exists(xmlFile))
                    {
                        string dvdid          = GetDVDID(xmlFile);
                        string xmlDetailsFile = GetDVDCacheFileName(dvdid);
                        t = ReadMetaData(folderName, xmlDetailsFile);
                    }

                    if (t == null)
                    {
                        // for DVDs with no dvdid.xml add a stripped down title with just a suggested name
                        t      = new OMLSDKTitle();
                        t.Name = GetSuggestedMovieName(folderName);
                    }

                    if (!File.Exists(t.FrontCoverPath))
                    {
                        if (File.Exists(folderName + "\\folder.jpg"))
                        {
                            t.FrontCoverPath = folderName + "\\folder.jpg";
                        }
                    }

                    t.ImporterSource = "VMCDVDLibraryPlugin";
                    OMLSDKDisk disk = new OMLSDKDisk();
                    disk.Name = "Disk 1";

                    switch (dirType)
                    {
                    case DirectoryType.BluRay:
                        disk.Format = OMLSDKVideoFormat.BLURAY;
                        disk.Path   = folderName;
                        break;

                    case DirectoryType.HDDvd:
                        disk.Format = OMLSDKVideoFormat.HDDVD;
                        disk.Path   = folderName;
                        break;

                    case DirectoryType.DVD_Flat:
                        disk.Format = OMLSDKVideoFormat.DVD;
                        disk.Path   = folderName;
                        break;

                    case DirectoryType.DVD_Ripped:
                        disk.Format = OMLSDKVideoFormat.DVD;
                        disk.Path   = folderName;
                        break;
                    }

                    t.AddDisk(disk);
                    t.MetadataSourceName = "VMC DVD Library";
                    return(t);
                }
            }
            catch (Exception ex)
            {
                SDKUtilities.DebugLine("[DVDLibraryImporter] An error occured: " + ex.Message);
            }

            return(null);
        }
Exemplo n.º 4
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");
                }
            }
        }
Exemplo n.º 5
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");
            }
        }
Exemplo n.º 6
0
        public bool ValidateTitle(OMLSDKTitle title_to_validate, string file)
        {
            SDKUtilities.DebugLine("[MyMoviesImporter] This is the part where we validate (or not) your shiny new title, wouldn't want you to drive off the lot with it untested now would we");
            if (title_to_validate.Disks.Count == 0)
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Whoa... you dont appear to have any discs... lets double check that");
                string directoryName = Path.GetDirectoryName(file);
                if (Directory.Exists(directoryName))
                {
                    if (SDKUtilities.IsBluRay(directoryName))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] its a bluray, adding a new disk");
                        title_to_validate.AddDisk(new OMLSDKDisk("Disk1", directoryName, OMLSDKVideoFormat.BLURAY));
                        return(true);
                    }

                    if (SDKUtilities.IsHDDVD(directoryName))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] its an hddvd, adding a new disk");
                        title_to_validate.AddDisk(new OMLSDKDisk("Disk1", directoryName, OMLSDKVideoFormat.HDDVD));
                        return(true);
                    }

                    if (SDKUtilities.IsDVD(directoryName))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] its a dvd, adding a new disk");
                        title_to_validate.AddDisk(new OMLSDKDisk("Disk1", directoryName, OMLSDKVideoFormat.DVD));
                        return(true);
                    }

                    string[] files = Directory.GetFiles(directoryName);
                    SDKUtilities.DebugLine("[MyMoviesImporter] You have {0} files in the current location {1}", files.Length, directoryName);

                    /* patch from KingManon to limit files only to those of valid file types */
                    string        localExt;
                    List <string> newFiles          = new List <string>();
                    List <string> allowedExtensions = new List <string>(Enum.GetNames(typeof(OMLSDKVideoFormat)));
                    foreach (string singleFile in files)
                    {
                        localExt = Path.GetExtension(singleFile).Substring(1);
                        if (allowedExtensions.Contains(localExt.ToUpper()))
                        {
                            newFiles.Add(singleFile);
                        }
                    }
                    files = newFiles.ToArray();

                    Array.Sort(files);
                    for (int i = 0; i < files.Length; i++)
                    {
                        string ext = Path.GetExtension(files[i]).Substring(1);
                        try
                        {
                            if (new List <string>(Enum.GetNames(typeof(OMLSDKVideoFormat))).Contains(ext.ToUpper()))
                            {
                                OMLSDKVideoFormat format;
                                try
                                {
                                    SDKUtilities.DebugLine("[MyMoviesImporter] Checking file for format {0}", files[i]);
                                    format = (OMLSDKVideoFormat)Enum.Parse(typeof(OMLSDKVideoFormat), ext, true);
                                    OMLSDKDisk disk = new OMLSDKDisk();
                                    disk.Name   = string.Format("Disk{0}", i + 1);
                                    disk.Path   = Path.Combine(directoryName, files[i]);
                                    disk.Format = format;
                                    title_to_validate.AddDisk(disk);
                                }
                                catch (Exception)
                                {
                                    AddError("[MyMoviesImporter] Unable to determine format for extension: {0}", ext);
                                }
                            }
                        }
                        catch
                        {
                            SDKUtilities.DebugLine("[MyMoviesImporter] Yeah, no extention on file ({0}), skip it!", files[i]);
                            // didnt get the extension, its not a valid file, skip it
                        }
                    }
                    if (title_to_validate.Disks.Count == 0)
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] No disks found on the title, we'll skip it");
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 7
0
        private IList <OMLSDKDisk> GetDisksForLocation(string location, string locationType)
        {
            SDKUtilities.DebugLine("[MyMoviesImporter] GetDisksForLocation({0}) of type {1}", location, locationType);
            List <OMLSDKDisk> disks = new List <OMLSDKDisk>();

            if (!string.IsNullOrEmpty(location))
            {
                if (location.CompareTo(".") == 0)
                {
                    SDKUtilities.DebugLine("[MyMoviesImporter] Your disk entry appears to be either empty or contain a '.', we're gonna look in the current directory");
                    location = Path.GetDirectoryName(currentFile);
                    SDKUtilities.DebugLine("[MyMoviesImporter] New Location: {0}", location);
                }

                string fullPath = Path.GetFullPath(location);
                SDKUtilities.DebugLine("[MyMoviesImporter] And we think the full path is: {0}", fullPath);

                int iLocationType = int.Parse(locationType);
                switch (iLocationType)
                {
                case 1:
                    // online folder
                    SDKUtilities.DebugLine("[MyMoviesImporter] We think this is a directory");
                    if (Directory.Exists(fullPath))
                    {
                        if (SDKUtilities.IsDVD(fullPath))
                        {
                            SDKUtilities.DebugLine("[MyMoviesImporter] its dvd");
                            OMLSDKDisk disk = DiskForFormatAndLocation(OMLSDKVideoFormat.DVD, fullPath);
                            disks.Add(disk);
                            break;
                        }

                        if (SDKUtilities.IsBluRay(fullPath))
                        {
                            SDKUtilities.DebugLine("[MyMoviesImporter] its bluray");
                            OMLSDKDisk disk = DiskForFormatAndLocation(OMLSDKVideoFormat.BLURAY, fullPath);
                            disks.Add(disk);
                            break;
                        }

                        if (SDKUtilities.IsHDDVD(fullPath))
                        {
                            SDKUtilities.DebugLine("[MyMoviesImporter] its hddvd");
                            OMLSDKDisk disk = DiskForFormatAndLocation(OMLSDKVideoFormat.HDDVD, fullPath);
                            disks.Add(disk);
                            break;
                        }

                        SDKUtilities.DebugLine("[MyMoviesImporter] no idea, searching for files in {0}", location);
                        IList <string> files = GetVideoFilesForFolder(location);
                        foreach (string fileName in files)
                        {
                            string ext = Path.GetExtension(fileName);
                            ext = ext.Substring(1);
                            ext = ext.Replace("-", string.Empty);
                            OMLSDKVideoFormat format = FormatForExtension(ext);
                            if (format != OMLSDKVideoFormat.UNKNOWN)
                            {
                                SDKUtilities.DebugLine("[MyMoviesImporter] got one, its {0} (at: {1})", fileName, format);
                                OMLSDKDisk disk = DiskForFormatAndLocation(format, fileName);
                                disks.Add(disk);
                            }
                        }
                        break;
                    }
                    else
                    {
                        AddError("[MyMoviesImporter] Location {0} is of type folder but the folder doesn't appear to exist", fullPath);
                    }
                    break;

                case 2:
                    // online file
                    SDKUtilities.DebugLine("[MyMoviesImporter] We think this is a file");
                    if (File.Exists(fullPath))
                    {
                        string ext = Path.GetExtension(fullPath);
                        ext = ext.Substring(1);
                        ext.Replace("-", string.Empty);
                        OMLSDKVideoFormat format = FormatForExtension(ext);

                        if (format != OMLSDKVideoFormat.UNKNOWN)
                        {
                            SDKUtilities.DebugLine("[MyMoviesImporter] Ok, found something here, it appears to be {0} with a format if {1}", fullPath, format);
                            OMLSDKDisk disk = DiskForFormatAndLocation(format, fullPath);
                            disks.Add(disk);
                        }
                    }
                    else
                    {
                        AddError("[MyMoviesImporter] Location {0} is of type file but the file doesn't appear to exist", fullPath);
                    }
                    break;

                case 3:
                    SDKUtilities.DebugLine("[MyMoviesImporter] Seriously... mymovies says this is an offline disk... how are we supposed to import an offline disk?\nQuick, point us to your nearest dvd shelf!");
                    OMLSDKDisk t3disk = new OMLSDKDisk();
                    t3disk.Format = OMLSDKVideoFormat.OFFLINEDVD;
                    disks.Add(t3disk);
                    // offline dvd
                    break;

                case 4:
                    // dvd changer
                    SDKUtilities.DebugLine("[MyMoviesImporter] Do you see any dvd changers around here?  Cause I dont!");
                    OMLSDKDisk t4disk = new OMLSDKDisk();
                    t4disk.Format = OMLSDKVideoFormat.OFFLINEDVD;
                    disks.Add(t4disk);
                    break;

                case 5:
                    // media changer of some kind, treat as 4
                    SDKUtilities.DebugLine("[MyMoviesImporter] Ah, upgraded to a Media Changer hey? Nice... TO BAD WE DONT SUPPORT THOSE!");
                    OMLSDKDisk t5disk = new OMLSDKDisk();
                    t5disk.Format = OMLSDKVideoFormat.OFFLINEDVD;
                    disks.Add(t5disk);
                    break;

                default:
                    // no idea...
                    AddError("[MyMoviesImporter] I have NO idea what type of video is available at {0}", location);
                    break;
                }
            }
            SDKUtilities.DebugLine("[MyMoviesImporter] Ok, I got nothing... hopefully the double-check in the validate method will find something");
            return(disks);
        }