Ejemplo n.º 1
0
        private void GetSubFolders(string startFolder, List <string> folderList)
        {
            // First check if root is a dvd / bluray disk structure
            if (GetDirectoryType(startFolder) != DirectoryType.Normal)
            {
                return;
            }

            DirectoryInfo[] diArr = null;
            try
            {
                DirectoryInfo di = new DirectoryInfo(startFolder);
                diArr = di.GetDirectories();
                foreach (DirectoryInfo folder in diArr)
                {
                    if (folder.Name[0] != '.')
                    {
                        folderList.Add(folder.FullName);

                        // ignore subdirectories of movie folders
                        if (GetDirectoryType(folder.FullName) == DirectoryType.Normal)
                        {
                            GetSubFolders(folder.FullName, folderList);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SDKUtilities.DebugLine("[DVDLibraryImporter] An error occured: " + ex.Message);
                // ignore any permission errors
            }
        }
Ejemplo n.º 2
0
        public void CheckPNaClCompile()
        {
            string root = System.Environment.GetEnvironmentVariable("NACL_SDK_ROOT");

            if (!SDKUtilities.SupportsPNaCl(root))
            {
                Assert.Inconclusive();
            }
            CheckCompile(Strings.PNaClPlatformName);
        }
Ejemplo n.º 3
0
        public override void ProcessDir(string startFolder)
        {
            try
            {
                List <string> dirList  = new List <string>();
                List <string> fileList = new List <string>();
                GetSubFolders(startFolder, ref dirList);

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

                foreach (string currentFolder in dirList)
                {
                    SDKUtilities.DebugLine("[MyMoviesImporter] Checking Folder " + currentFolder);

                    string[] fileNames = null;
                    try
                    {
                        fileNames = Directory.GetFiles(currentFolder, @"*.xml");
                    }
                    catch (Exception ex)
                    {
                        SDKUtilities.DebugLine("Failed to locate files for dir ({0}): {1}", currentFolder, ex.Message);
                        fileNames = null;
                    }

                    if (fileNames != null)
                    {
                        foreach (string filename in fileNames)
                        {
                            SDKUtilities.DebugLine("Checking xml file {0}", filename);
                            if (filename.ToLower().EndsWith(@"mymovies.xml"))
                            {
                                SDKUtilities.DebugLine("ProcessFile called on: {0} in folder {1}", filename, currentFolder);
                                ProcessFile(filename);
                            }

                            if (filename.ToLower().EndsWith(@"titles.xml"))
                            {
                                SDKUtilities.DebugLine("ProcessFile called on {0} in folder {1}", filename, currentFolder);
                                ProcessFile(filename);
                            }
                        }
                    }
                } // loop through the sub folders
            }
            catch (Exception ex)
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] An error occured: " + ex.Message);
            }
        }
Ejemplo n.º 4
0
        private void extractDisksFromXML(XPathNodeIterator nIter, XPathNavigator localNav, OMLSDKTitle newTitle)
        {
            SDKUtilities.DebugLine("[MyMoviesImporter] Scanning for Discs...");
            SDKUtilities.DebugLine("[MyMoviesImporter] {0} entries found", nIter.Count);
            for (int i = 0; i < nIter.Count; i++)
            {
                bool isDoubleSided = (((string)GetChildNodesValue(localNav, "DoubleSided")).CompareTo("False") == 0)
                                     ? false : true;

                string discName          = (string)GetChildNodesValue(localNav, "Name");
                string sideAId           = (string)GetChildNodesValue(localNav, "DiscIdSideA");
                string sideALocation     = (string)GetChildNodesValue(localNav, "LocationSideA");
                string sideALocationType = (string)GetChildNodesValue(localNav, "LocationTypeSideA");
                string changerSlot       = (string)GetChildNodesValue(localNav, "ChangerSlot");

                string sideBId           = string.Empty;
                string sideBLocation     = string.Empty;
                string sideBLocationType = string.Empty;
                if (isDoubleSided)
                {
                    sideBId           = (string)GetChildNodesValue(localNav, "DiscIdSideB");
                    sideBLocation     = (string)GetChildNodesValue(localNav, "LocationSideB");
                    sideBLocationType = (string)GetChildNodesValue(localNav, "LocationTypeSideB");
                }

                SDKUtilities.DebugLine("[MyMoviesImporter] Ok, I've collected some info... now we actually start looking for files");
                IList <OMLSDKDisk> sideAdisks = GetDisksForLocation(sideALocation, sideALocationType);

                int j = 1;
                SDKUtilities.DebugLine("[MyMoviesImporter] Ok, we found {0} possible files", sideAdisks.Count);
                foreach (OMLSDKDisk disk in sideAdisks)
                {
                    disk.Name = string.Format(@"Disk{0}", j++);
                    newTitle.AddDisk(disk);
                }

                if (isDoubleSided)
                {
                    SDKUtilities.DebugLine("[MyMoviesImporter] Whoa... this thing appears to be double-sided (old schooling it huh?)");
                    IList <OMLSDKDisk> sideBdisks = GetDisksForLocation(sideBLocation, sideBLocationType);
                    SDKUtilities.DebugLine("[MyMoviesImporter] We found {0} disks on the B side", sideBdisks.Count);
                    foreach (OMLSDKDisk disk in sideBdisks)
                    {
                        disk.Name = string.Format(@"Disk{0}", j++);
                        newTitle.AddDisk(disk);
                    }
                }

                localNav.MoveToNext("Disc", "");
            }
        }
Ejemplo n.º 5
0
        //
        // the dvid.xml file contains the Name of the movie and the DVDID
        //
        private string GetDVDID(string dvdidXMLFile)
        {
            string dvdid = "";

            try
            {
                XmlReaderSettings xmlSettings = new XmlReaderSettings();
                xmlSettings.IgnoreWhitespace = true;
                using (XmlReader reader = XmlReader.Create(dvdidXMLFile, xmlSettings))
                {
                    reader.MoveToContent();
                    string currentElement = reader.Name;

                    // some dvdid.xml files use upper case, some used mixed case
                    // we cannot read an element based on name because i
                    if (currentElement.ToUpper() == "DISC")
                    {
                        reader.Read();
                        while (!reader.IsStartElement())
                        {
                            reader.Read();                              // skip to next element
                        }
                        currentElement = reader.Name;

                        if (currentElement.ToUpper() == "NAME")
                        {
                            reader.ReadStartElement(reader.Name);
                            //m_DVDName = reader.ReadString();
                            reader.ReadString();
                            reader.Read();
                            while (!reader.IsStartElement())
                            {
                                reader.Read();                              // skip to next element
                            }
                            currentElement = reader.Name;
                            if (currentElement.ToUpper() == "ID")
                            {
                                reader.ReadStartElement(reader.Name);
                                dvdid = reader.ReadString();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SDKUtilities.DebugLine("[DVDLibraryImporter] An error occured: " + ex.Message);
            }
            return(dvdid);
        }
Ejemplo n.º 6
0
        private OMLSDKVideoFormat FormatForExtension(string ext)
        {
            OMLSDKVideoFormat format;

            SDKUtilities.DebugLine("[MyMoviesImporter] Attempting to determine format based on extension {0}", ext);
            try
            {
                format = (OMLSDKVideoFormat)Enum.Parse(typeof(OMLSDKVideoFormat), ext, true);
                SDKUtilities.DebugLine("[MyMoviesImporter] Format appears to be {0}", format);
                return(format);
            }
            catch (Exception ex)
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Format is Unknown.. this means its useless: {0}", ex);
            }
            return(OMLSDKVideoFormat.UNKNOWN);
        }
Ejemplo n.º 7
0
        public override void ProcessFile(string file)
        {
            SDKUtilities.DebugLine("[MyMoviesImporter] created[filename(" + file + ")]");

            currentFile = file;
            if (File.Exists(currentFile))
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(file);
                SDKUtilities.DebugLine("[MyMoviesImporter] file loaded");

                XmlNodeList nodeList = xDoc.SelectNodes("//Titles/Title");
                if (nodeList.Count == 0)
                {
                    nodeList = xDoc.SelectNodes("Title");
                }

                foreach (XmlNode movieNode in nodeList)
                {
                    SDKUtilities.DebugLine("[MyMoviesImporter] Found base Title node");

                    OMLSDKTitle newTitle = new OMLSDKTitle();

                    XPathNavigator navigator = movieNode.CreateNavigator();
                    newTitle.Name = GetChildNodesValue(navigator, "LocalTitle");
                    loadDataFromNavigatorToTitle(ref navigator, ref newTitle);

                    if (ValidateTitle(newTitle, file))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] Validating title");
                        try { AddTitle(newTitle); }
                        catch (Exception e) { SDKUtilities.DebugLine("[MyMoviesImporter] Error adding row: " + e.Message); }
                    }
                    else
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] Error saving row");
                    }
                }
            }
            else
            {
                AddError("[MyMoviesImporter] File not found when trying to load file: {0}", currentFile);
            }
        }
Ejemplo n.º 8
0
 private void GetSubFolders(string startFolder, ref List <string> folderList)
 {
     DirectoryInfo[] diArr = null;
     try
     {
         DirectoryInfo di = new DirectoryInfo(startFolder);
         diArr = di.GetDirectories();
         foreach (DirectoryInfo folder in diArr)
         {
             SDKUtilities.DebugLine("Got a child Folder {0}", folder.Name);
             folderList.Add(folder.FullName);
             GetSubFolders(folder.FullName, ref folderList);
         }
     }
     catch (Exception ex)
     {
         SDKUtilities.DebugLine("[MyMoviesImporter] An error occured getting folder info for folder ({0}): {1}", startFolder, ex.Message);
     }
 }
Ejemplo n.º 9
0
        private IList <string> GetVideoFilesForFolder(string folder)
        {
            SDKUtilities.DebugLine("[MyMoviesImporter] Looking for video files in a folder, {0} folder in fact.", folder);
            List <string> fileNames = new List <string>();

            if (Directory.Exists(folder))
            {
                string[] files = Directory.GetFiles(folder);
                Array.Sort(files);
                foreach (string fName in files)
                {
                    SDKUtilities.DebugLine("[MyMoviesImporter] Found file {0}, I don't (yet) care what file type, just throw it on the stack", fName);
                    fileNames.Add(Path.GetFullPath(fName));
                }
            }
            else
            {
                AddError("[MyMoviesImporter] Disc entry specified folder ({0}) but that folder doesn't appear to exist", folder);
            }
            return(fileNames);
        }
Ejemplo n.º 10
0
 public MyMoviesImporter() : base()
 {
     SDKUtilities.DebugLine("[MyMoviesImporter] created");
 }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
 public DVDLibraryImporter()
     : base()
 {
     SDKUtilities.DebugLine("[DVDLibraryImporter] created");
 }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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");
                }
            }
        }
Ejemplo n.º 17
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
        }
Ejemplo n.º 18
0
        public bool SearchForMovie(string movieName, int maxResults)
        {
            movieName = CleanString(movieName);

            foundTitle = null;
            List <string> possibleIds = new List <string>();

            if (dvdsByName.ContainsKey(movieName))
            {
                possibleIds.Add(dvdsByName[movieName]);
            }
            else if (dvdsBySortName.ContainsKey(movieName))
            {
                possibleIds.Add(dvdsBySortName[movieName]);
            }
            else
            {
                foreach (string key in dvdsByName.Keys)
                {
                    if (key.StartsWith(movieName, StringComparison.OrdinalIgnoreCase))
                    {
                        possibleIds.Add(dvdsByName[key]);
                    }
                }
            }

            // try the sort names if none of the other names panned out
            if (possibleIds.Count == 0)
            {
                foreach (string key in dvdsBySortName.Keys)
                {
                    if (key.StartsWith(movieName, StringComparison.OrdinalIgnoreCase))
                    {
                        possibleIds.Add(dvdsBySortName[key]);
                    }
                }
            }

            IEnumerable <string> unusedPossibleIds = SDKUtilities.GetUniqueMetaIds(possibleIds, this.PluginName);

            foreach (string possibleId in unusedPossibleIds)
            {
                var navigator = document.CreateNavigator();

                foreach (XPathNavigator dvd in navigator.Select("/Collection/DVD|/DVD")) // Allow both collection file and single profile export
                {
                    foreach (XPathNavigator child in dvd.SelectChildren(XPathNodeType.Element))
                    {
                        if (child.Name == "ID")
                        {
                            if (child.Value == possibleId)
                            {
                                child.MoveToParent();

                                DVDProfilerImporter importer = new DVDProfilerImporter();
                                foundTitle = importer.LoadTitle(child, false);
                                importer.GetImagesForNewTitle(foundTitle);
                            }
                        }

                        if (foundTitle != null)
                        {
                            break;
                        }
                    }

                    if (foundTitle != null)
                    {
                        break;
                    }
                }

                // we only care about the first one for now
                break;
            }

            return(foundTitle != null);
        }
Ejemplo n.º 19
0
        private OMLSDKVideoFormat GetVideoFormatForLocation(string location, string locationType)
        {
            SDKUtilities.DebugLine("[MyMoviesImporter] You want the format for what exactly? {0}", location);
            int type = Int32.Parse(locationType);

            switch (type)
            {
            case 1:
                //online folder
                if (Directory.Exists(location))
                {
                    if (SDKUtilities.IsBluRay(location))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] Nice.. you appear to have a bluray drive (or file, you sneaky dog)");
                        return(OMLSDKVideoFormat.BLURAY);
                    }

                    if (SDKUtilities.IsHDDVD(location))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] Ah.. hddvd nice (yeah last year... you know these lost the format war right?)");
                        return(OMLSDKVideoFormat.HDDVD);
                    }

                    if (SDKUtilities.IsDVD(location))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] Here be a dvd or video_ts folder (does it really matter which?)");
                        return(OMLSDKVideoFormat.DVD);
                    }
                    // unable to determine disc, there must be a file flagged as a folder... go check for files
                }
                break;

            case 2:
                // online file
                SDKUtilities.DebugLine("[MyMoviesImporter] File time!");
                string extension = Path.GetExtension(location);
                extension = extension.Substring(1);
                extension.Replace("-", string.Empty);
                OMLSDKVideoFormat format;
                try
                {
                    format = (OMLSDKVideoFormat)Enum.Parse(typeof(OMLSDKVideoFormat), extension, true);
                    SDKUtilities.DebugLine("[MyMoviesImporter] Ok, I looked for the format and all I got was the lame comment line {0}", format);
                }
                catch (Exception ex)
                {
                    AddError("[MyMoviesImporter] Error parsing format for extension: {0}, {1}", extension, ex);
                    format = OMLSDKVideoFormat.UNKNOWN;
                }

                return(format);

            case 3:
                // offline dvd
                break;

            case 4:
                // dvd changer
                break;

            case 5:
            // media changer of some kind, treat as 4
            default:
                return(OMLSDKVideoFormat.UNKNOWN);
            }

            return(OMLSDKVideoFormat.UNKNOWN);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        private void InitializeSettings(XmlTextReader settingsXml)
        {
            XmlTextReader dvdProfilerSettings = null;
            bool          disposeReader       = false;

            try
            {
                if (settingsXml != null)
                {
                    dvdProfilerSettings = settingsXml;
                }
                else
                {
                    string path = Path.Combine(SDKUtilities.PluginsDirectory, "DVDProfilerSettings.xml");
                    if (File.Exists(path))
                    {
                        disposeReader       = true;
                        dvdProfilerSettings = new XmlTextReader(path);
                    }
                }


                if (dvdProfilerSettings != null)
                {
                    while (dvdProfilerSettings.Read())
                    {
                        if (dvdProfilerSettings.NodeType != XmlNodeType.Element)
                        {
                            continue;
                        }
                        switch (dvdProfilerSettings.Name)
                        {
                        case "imagesPath":
                            imagesPath = (dvdProfilerSettings.ReadInnerXml());
                            break;

                        case "tag":
                            string tagName         = dvdProfilerSettings.GetAttribute("name");
                            string tagExcludedName = dvdProfilerSettings.GetAttribute("excludedName");
                            string tagXPath        = dvdProfilerSettings.GetAttribute("xpath");
                            if (string.IsNullOrEmpty(tagName) && string.IsNullOrEmpty(tagExcludedName))
                            {
                                SDKUtilities.DebugLine("[DVDProfilerImporter] Tag setting missing name");
                                AddError("Tag missing name or excludeName attribute in DVDProfilerSettings.xml");
                            }
                            if (string.IsNullOrEmpty(tagXPath))
                            {
                                SDKUtilities.DebugLine("[DVDProfilerImporter] Tag setting missing xpath");
                                AddError("Tag missing xpath attribute in DVDProfilerSettings.xml");
                            }
                            if (!string.IsNullOrEmpty(tagXPath))
                            {
                                try
                                {
                                    tagDefinitions.Add(new TagDefinition
                                    {
                                        Name         = tagName,
                                        ExcludedName = tagExcludedName,
                                        XPath        = XPathExpression.Compile(tagXPath)
                                    });
                                }
                                catch (ArgumentException e)
                                {
                                    initializationErrors.Add(e);
                                }
                                catch (XPathException e)
                                {
                                    initializationErrors.Add(e);
                                }
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SDKUtilities.DebugLine("[DVDProfilerImporter] Unable to open DVDProfilerSettings.xml file: {0}",
                                       e.Message);
                initializationErrors.Add(e);
            }
            finally
            {
                if (disposeReader && dvdProfilerSettings != null)
                {
                    dvdProfilerSettings.Close();
                }
            }
        }
Ejemplo n.º 22
0
        private string FindFinalImagePath(string imagePath)
        {
            SDKUtilities.DebugLine("[MyMoviesImporter] Attempting to determine cover image based on path {0}", imagePath);
            if (File.Exists(imagePath))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] Imagepath {0} appears to be valid", imagePath);
                return(imagePath);
            }

            string possibleImagePath = Path.Combine(Path.GetDirectoryName(currentFile),
                                                    imagePath);

            SDKUtilities.DebugLine("[MyMoviesImporter] Checking for {0} as a possible image", possibleImagePath);
            if (File.Exists(possibleImagePath))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] {0} appears correct, well use it", possibleImagePath);
                return(possibleImagePath);
            }

            string possibleDefaultImagePath = Path.Combine(Path.GetDirectoryName(currentFile),
                                                           "folder.jpg");

            SDKUtilities.DebugLine("[MyMoviesImporter] Checking for {0} as a possible image", possibleDefaultImagePath);
            if (File.Exists(possibleDefaultImagePath))
            {
                SDKUtilities.DebugLine("[MyMoviesImporter] {0} appears correct, well use it", possibleDefaultImagePath);
                return(possibleDefaultImagePath);
            }

            string[] imageFiles = Directory.GetFiles(Path.GetDirectoryName(currentFile), "*.jpg");
            SDKUtilities.DebugLine("[MyMoviesImporter] We found {0} jpg files to check", imageFiles.Length);
            if (imageFiles.Length > 0)
            {
                if (imageFiles.Length == 1)
                {
                    SDKUtilities.DebugLine("[MyMoviesImporter] Only 1 file was found, we'll assume it is the cover file {0}",
                                           Path.Combine(Path.GetDirectoryName(currentFile), imageFiles[0]));
                    return(Path.Combine(Path.GetDirectoryName(currentFile), imageFiles[0]));
                }

                SDKUtilities.DebugLine("[MyMoviesImporter] Looping through each file to check it for possible cover art");
                foreach (string imageFilename in imageFiles)
                {
                    SDKUtilities.DebugLine("[MyMoviesImporter] Found file: {0}", imageFilename);
                    if (imageFilename.ToLower().Contains("front"))
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] This file appears to contain the word front in it, we'll use it {0}",
                                               Path.Combine(Path.GetDirectoryName(currentFile), imageFilename));
                        return(Path.Combine(Path.GetDirectoryName(currentFile), imageFilename));
                    }

                    if (imageFilename.ToLower().CompareTo(currentFile.ToLower()) == 0)
                    {
                        SDKUtilities.DebugLine("[MyMoviesImporter] This file appears to have the same name as the video file, we'll use it {0}",
                                               Path.Combine(Path.GetDirectoryName(currentFile), imageFilename));
                        return(Path.Combine(Path.GetDirectoryName(currentFile), imageFilename));
                    }
                }
            }
            SDKUtilities.DebugLine("[MyMoviesImporter] No image files found, I guess this title doesn't have any cover art files");
            return(string.Empty);
        }
Ejemplo n.º 23
0
        // these 2 methods must be called in sequence
        public bool Initialize(string provider, Dictionary <string, string> parameters)
        {
            dvdsByName     = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            dvdsById       = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            dvdsBySortName = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            if (!string.IsNullOrEmpty(collectionPath) && File.Exists(collectionPath))
            {
                using (XmlTextReader reader = new XmlTextReader(collectionPath))
                {
                    document = new XPathDocument(reader);

                    var navigator = document.CreateNavigator();

                    foreach (XPathNavigator dvd in navigator.Select("/Collection/DVD|/DVD")) // Allow both collection file and single profile export
                    {
                        string name     = null;
                        string id       = null;
                        string sortName = null;

                        foreach (XPathNavigator dvdElement in dvd.SelectChildren(XPathNodeType.Element))
                        {
                            if (dvdElement.Name == "ID")
                            {
                                id = dvdElement.Value;
                            }
                            else if (dvdElement.Name == "Title")
                            {
                                name = dvdElement.Value;
                            }
                            else if (dvdElement.Name == "SortTitle")
                            {
                                sortName = dvdElement.Value;
                            }

                            if (name != null && id != null && sortName != null)
                            {
                                name = CleanString(SDKUtilities.GetFolderNameString(name));

                                if (dvdsByName.ContainsKey(name))
                                {
                                    name += " " + Guid.NewGuid().ToString();
                                }

                                dvdsByName.Add(name, id);

                                sortName = CleanString(SDKUtilities.GetFolderNameString(sortName));

                                if (dvdsBySortName.ContainsKey(sortName))
                                {
                                    sortName += " " + Guid.NewGuid().ToString();
                                }

                                dvdsBySortName.Add(sortName, id);

                                if (!dvdsById.ContainsKey(id))
                                {
                                    dvdsById.Add(id, name);
                                }

                                break;
                            }
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 24
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");
            }
        }