示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
        }