Ejemplo n.º 1
0
 public OMLSDKDisk(string name, string path, OMLSDKVideoFormat format, string extraOptions)
     : this()
 {
     this.Name = name;
     this.Path = path;
     this.Format = format;
     this.ExtraOptions = string.IsNullOrEmpty(extraOptions) ? null : extraOptions;
 }
Ejemplo n.º 2
0
 public OMLSDKDisk(string name, string path, OMLSDKVideoFormat format, string extraOptions)
     : this()
 {
     this.Name         = name;
     this.Path         = path;
     this.Format       = format;
     this.ExtraOptions = string.IsNullOrEmpty(extraOptions) ? null : extraOptions;
 }
Ejemplo n.º 3
0
        private OMLSDKDisk DiskForFormatAndLocation(OMLSDKVideoFormat format, string location)
        {
            OMLSDKDisk disk = new OMLSDKDisk();

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

            return(disk);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Merges the information from the Notes field with the DVD Profiler Disc data to create the Disk entries for the title
        /// </summary>
        private void MergeDiscInfo(OMLSDKTitle title, OMLSDKVideoFormat dvdProfilerVideoFormat, Dictionary <string, string> discs, string notes)
        {
            if (string.IsNullOrEmpty(notes))
            {
                return;
            }

            var matches        = filepathRegex.Matches(notes);
            int lastDiskNumber = 0;

            foreach (Match m in matches)
            {
                string discNumberString = m.Groups["discNumber"].Value;
                int    discNumber       = Convert.ToInt32(string.IsNullOrEmpty(discNumberString) ? "0" : discNumberString,
                                                          CultureInfo.InvariantCulture);
                if (discNumber == 0)
                {
                    discNumber = lastDiskNumber + 1;
                }
                string sideString = m.Groups["side"].Value;
                if (string.IsNullOrEmpty(sideString))
                {
                    sideString = "a";
                }

                string description;
                string discKey = discNumber.ToString(CultureInfo.InvariantCulture) + sideString.ToLowerInvariant();
                if (!discs.TryGetValue(discKey, out description))
                {
                    // TODO: I18N
                    if (matches.Count == 1)
                    {
                        description = "Movie";
                    }
                    else
                    {
                        description = "Disc " + discKey;
                    }
                }
                string            path            = m.Groups["path"].Value;
                OMLSDKVideoFormat discVideoFormat = GetFormatFromExtension(Path.GetExtension(path), dvdProfilerVideoFormat);

                if (!string.IsNullOrEmpty(path))
                {
                    // validate that the path to the file/directory is valid
                    if (!File.Exists(path) && !Directory.Exists(path))
                    {
                        this.AddError("Invalid path \"" + path + "\" for movie \"" + title.Name + "\"");
                    }
                }

                title.AddDisk(new OMLSDKDisk(description, path, discVideoFormat));
                lastDiskNumber++;
            }
        }
Ejemplo n.º 5
0
        private static OMLSDKVideoFormat GetFormatFromExtension(string extension, OMLSDKVideoFormat defaultFormat)
        {
            if (string.IsNullOrEmpty(extension))
            {
                return(defaultFormat);
            }
            extension = extension.TrimStart('.').ToLowerInvariant();

            foreach (OMLSDKVideoFormat format in Enum.GetValues(typeof(OMLSDKVideoFormat)))
            {
                if (Enum.GetName(typeof(OMLSDKVideoFormat), format).ToLowerInvariant() == extension)
                {
                    return(format);
                }
            }
            return(defaultFormat);
        }
Ejemplo n.º 6
0
        public OMLSDKTitle LoadTitle(XPathNavigator dvdNavigator, bool lookForDiskInfo)
        {
            OMLSDKTitle       title       = new OMLSDKTitle();
            OMLSDKVideoFormat videoFormat = OMLSDKVideoFormat.DVD;
            string            notes       = string.Empty;
            var discs = new Dictionary <string, string>(); // The key is on the form "1a", "10b", etc - the value is the description

            foreach (XPathNavigator dvdElement in dvdNavigator.SelectChildren(XPathNodeType.Element))
            {
                switch (dvdElement.Name)
                {
                case "ID":
                    title.MetadataSourceID = dvdElement.Value;
                    break;

                case "MediaTypes":
                    videoFormat = HandleMediaTypes(dvdElement);
                    break;

                case "UPC":
                    title.UPC = dvdElement.Value;
                    break;

                case "Title":
                    title.Name = dvdElement.Value;
                    break;

                case "OriginalTitle":
                    title.OriginalName = dvdElement.Value;
                    break;

                case "SortTitle":
                    title.SortName = dvdElement.Value;
                    break;

                case "CountryOfOrigin":
                    title.CountryOfOrigin = dvdElement.Value;
                    break;

                /*case "ProductionYear":
                 *  // Set to January first in the appropriate year in lack of better...
                 *  int releaseYear;
                 *  if (TryReadItemInt(dvdElement, out releaseYear))
                 *  {
                 *      title.ReleaseDate = new DateTime(releaseYear, 1, 1);
                 *  }
                 *  break;*/

                // Fix from DVDJunkie
                // http://www.ornskov.dk/forum/index.php?topic=1605.msg12171#msg12171
                case "ProductionYear":
                    string ryear = dvdElement.Value;
                    try
                    {
                        if (!string.IsNullOrEmpty(ryear))
                        {
                            title.ProductionYear = Convert.ToInt32(ryear);
                        }
                    }
                    catch (FormatException) { }
                    break;

                case "Released":
                    string rdate = dvdElement.Value;
                    try
                    {
                        if (!string.IsNullOrEmpty(rdate))
                        {
                            title.ReleaseDate = DateTime.Parse(rdate);
                        }
                    }
                    catch (ArgumentException) { }
                    catch (FormatException) { }
                    break;

                case "RunningTime":
                    int runningTime;
                    if (TryReadItemInt(dvdElement, out runningTime))
                    {
                        title.Runtime = runningTime;
                    }
                    break;

                case "Rating":
                    title.ParentalRating = dvdElement.Value;
                    break;

                case "RatingDetails":
                    title.ParentalRatingReason = dvdElement.Value;
                    break;

                case "Genres":
                    foreach (XPathNavigator genreNavigator in dvdElement.Select("Genre[. != '']"))
                    {
                        title.AddGenre(genreNavigator.Value);
                    }
                    break;

                case "Format":
                    HandleFormat(title, dvdElement);
                    break;

                case "Studios":
                    var studioNavigator = dvdElement.SelectSingleNode("Studio[. != '']");
                    if (studioNavigator != null)
                    {
                        title.Studio = studioNavigator.Value;
                    }
                    break;

                case "Audio":
                    HandleAudio(title, dvdElement);
                    break;

                case "Subtitles":
                    foreach (XPathNavigator subtitleNavigator in dvdElement.SelectChildren("Subtitle", string.Empty))
                    {
                        title.AddSubtitle(subtitleNavigator.Value);
                    }
                    break;

                case "Actors":
                    HandleActors(title, dvdElement);
                    break;

                case "Credits":
                    HandleCredits(title, dvdElement);
                    break;

                case "Review":
                    ReadFilmReview(title, dvdElement);
                    break;

                case "Overview":
                    string synopsis = removeFormattingRegex.Replace(dvdElement.Value, string.Empty);
                    title.Synopsis = removeExtraLinebreaksRegex.Replace(synopsis, "\r\n").Trim();
                    break;

                case "Discs":
                    discs = HandleDiscs(dvdElement);
                    break;

                case "Notes":
                    notes = dvdElement.Value;
                    break;

                case "PurchaseInfo":
                    HandlePurchaseInfo(title, dvdElement);
                    break;
                }
            }
            if (lookForDiskInfo)
            {
                MergeDiscInfo(title, videoFormat, discs, notes);
            }

            ApplyTags(title, dvdNavigator);
            return(title);
        }
Ejemplo n.º 7
0
        private OMLSDKDisk DiskForFormatAndLocation(OMLSDKVideoFormat format, string location)
        {
            OMLSDKDisk disk = new OMLSDKDisk();
            disk.Format = format;
            disk.Path = location;

            return disk;
        }
Ejemplo n.º 8
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.º 9
0
 public OMLSDKDisk(string name, string path, OMLSDKVideoFormat format)
     : this(name, path, format, null)
 {
 }
Ejemplo n.º 10
0
 public OMLSDKDisk(string name, string path, OMLSDKVideoFormat format)
     : this(name, path, format, null)
 {
 }
Ejemplo n.º 11
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);
        }
        /// <summary>
        /// Merges the information from the Notes field with the DVD Profiler Disc data to create the Disk entries for the title
        /// </summary>
        private void MergeDiscInfo(OMLSDKTitle title, OMLSDKVideoFormat dvdProfilerVideoFormat, Dictionary<string, string> discs, string notes)
        {
            if (string.IsNullOrEmpty(notes)) return;

            var matches = filepathRegex.Matches(notes);
            int lastDiskNumber = 0;
            foreach (Match m in matches)
            {
                string discNumberString = m.Groups["discNumber"].Value;
                int discNumber = Convert.ToInt32(string.IsNullOrEmpty(discNumberString) ? "0" : discNumberString,
                                                 CultureInfo.InvariantCulture);
                if (discNumber == 0) discNumber = lastDiskNumber + 1;
                string sideString = m.Groups["side"].Value;
                if (string.IsNullOrEmpty(sideString)) sideString = "a";

                string description;
                string discKey = discNumber.ToString(CultureInfo.InvariantCulture) + sideString.ToLowerInvariant();
                if (!discs.TryGetValue(discKey, out description))
                {
                    // TODO: I18N
                    if (matches.Count == 1) description = "Movie";
                    else description = "Disc " + discKey;
                }
                string path = m.Groups["path"].Value;
                OMLSDKVideoFormat discVideoFormat = GetFormatFromExtension(Path.GetExtension(path), dvdProfilerVideoFormat);

                if (!string.IsNullOrEmpty(path))
                {
                    // validate that the path to the file/directory is valid
                    if (!File.Exists(path) && !Directory.Exists(path))
                    {
                        this.AddError("Invalid path \"" + path + "\" for movie \"" + title.Name + "\"");
                    }
                }

                title.AddDisk(new OMLSDKDisk(description, path, discVideoFormat));
                lastDiskNumber++;
            }
        }
        private static OMLSDKVideoFormat GetFormatFromExtension(string extension, OMLSDKVideoFormat defaultFormat)
        {
            if (string.IsNullOrEmpty(extension)) return defaultFormat;
            extension = extension.TrimStart('.').ToLowerInvariant();

            foreach (OMLSDKVideoFormat format in Enum.GetValues(typeof(OMLSDKVideoFormat)))
            {
                if (Enum.GetName(typeof(OMLSDKVideoFormat), format).ToLowerInvariant() == extension)
                {
                    return format;
                }
            }
            return defaultFormat;
        }