Example #1
0
        /// <summary>
        /// Determines if the given <paramref name="filePath"/> represents a MOD audio file.
        /// </summary>
        /// <param name="filePath">The path of the file to be examined.</param>
        /// <returns><c>true</c> if the extension of the given file path is one of the known MOD file extensions,
        /// else <c>false</c>.</returns>
        public static bool IsMODFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return(false);
            }
            string ext = DosPathHelper.GetExtension(filePath).ToLowerInvariant();

            switch (ext)
            {
            case ".mod":
            case ".mo3":
            case ".it":
            case ".xm":
            case ".s3m":
            case ".mtm":
            case ".umx":
                return(true);

            default:
                return(false);
            }
        }
        public static bool CanPlay(IResourceLocator locator, string mimeType)
        {
            // First check the Mime Type
            if (!string.IsNullOrEmpty(mimeType) && !mimeType.StartsWith("audio"))
            {
                return(false);
            }

            using (IResourceAccessor accessor = locator.CreateAccessor())
            {
                if (accessor is VirtualResourceAccessor)
                {
                    return(false);
                }
                if (accessor is AudioCDResourceAccessor || accessor is INetworkResourceAccessor)
                {
                    return(true);
                }
                string             ext      = DosPathHelper.GetExtension(accessor.ResourcePathName).ToLowerInvariant();
                BassPlayerSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <BassPlayerSettings>();
                return(settings.SupportedExtensions.IndexOf(ext) > -1);
            }
        }
Example #3
0
        static async Task <bool> ExtractGameData(ILocalFsResourceAccessor lfsra, IDictionary <Guid, IList <MediaItemAspect> > extractedAspectData, bool forceQuickMode)
        {
            var    categories = ServiceRegistration.Get <IMediaCategoryHelper>().GetMediaCategories(lfsra.CanonicalLocalResourcePath);
            string platform   = categories.FirstOrDefault(s => _platformCategories.ContainsKey(s));

            if (string.IsNullOrEmpty(platform))
            {
                Logger.Warn("GamesMetadataExtractor: Unable to import {0}, no platform categories have been selected", lfsra.LocalFileSystemPath);
                return(false);
            }

            var configurations = ServiceRegistration.Get <ISettingsManager>().Load <CommonSettings>().ConfiguredEmulators;

            if (!HasGameExtension(lfsra.CanonicalLocalResourcePath.BasePathSegment.Path, platform, configurations))
            {
                return(false);
            }

            Logger.Debug("GamesMetadataExtractor: Importing game: '{0}', '{1}'", lfsra.LocalFileSystemPath, platform);
            string   name     = DosPathHelper.GetFileNameWithoutExtension(lfsra.CanonicalLocalResourcePath.BasePathSegment.Path);
            GameInfo gameInfo = new GameInfo()
            {
                GameName = name,
                Platform = platform
            };

            GameMatcher matcher = GameMatcher.Instance;

            if (!forceQuickMode && !await matcher.FindAndUpdateGameAsync(gameInfo).ConfigureAwait(false))
            {
                Logger.Debug("GamesMetadataExtractor: No match found for game: '{0}', '{1}'", lfsra.LocalFileSystemPath, platform);
                gameInfo.GameName = name;
            }
            gameInfo.SetMetadata(extractedAspectData, lfsra);
            return(true);
        }
Example #4
0
        /// <summary>
        /// Returns the information if the specified file name (or path) has a file extension which is
        /// supposed to be supported by this metadata extractor.
        /// </summary>
        /// <param name="fileName">Relative or absolute file path to check.</param>
        /// <returns><c>true</c>, if the file's extension is supposed to be supported, else <c>false</c>.</returns>
        protected static bool HasImageExtension(string fileName)
        {
            string ext = DosPathHelper.GetExtension(fileName).ToLowerInvariant();

            return(IMAGE_FILE_EXTENSIONS.Contains(ext));
        }
Example #5
0
        public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary <Guid, IList <MediaItemAspect> > extractedAspectData, bool importOnly, bool forceQuickMode)
        {
            IFileSystemResourceAccessor fsra = mediaItemAccessor as IFileSystemResourceAccessor;

            if (fsra == null || !fsra.IsFile)
            {
                return(false);
            }
            if (extractedAspectData.ContainsKey(AudioAspect.ASPECT_ID))
            {
                return(false);
            }

            try
            {
                var extension = DosPathHelper.GetExtension(fsra.ResourceName).ToLowerInvariant();
                if (extension != ".ts")
                {
                    return(false);
                }

                using (MediaInfoWrapper mediaInfo = ReadMediaInfo(fsra))
                {
                    // Before we start evaluating the file, check if it is not a video file (
                    if (mediaInfo.IsValid && (mediaInfo.GetVideoCount() != 0 || mediaInfo.GetAudioCount() == 0))
                    {
                        return(false);
                    }
                    string fileName = ProviderPathHelper.GetFileNameWithoutExtension(fsra.Path) ?? string.Empty;
                    MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_TITLE, fileName);
                    MultipleMediaItemAspect providerResourceAspect = MediaItemAspect.CreateAspect(extractedAspectData, ProviderResourceAspect.Metadata);
                    providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_SIZE, fsra.Size);
                    providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, "slimtv/radio");

                    var audioBitrate = mediaInfo.GetAudioBitrate(0);
                    if (audioBitrate.HasValue)
                    {
                        MediaItemAspect.SetAttribute(extractedAspectData, AudioAspect.ATTR_BITRATE, (int)(audioBitrate.Value / 1000)); // We store kbit/s;
                    }
                    var audioChannels = mediaInfo.GetAudioChannels(0);
                    if (audioChannels.HasValue)
                    {
                        MediaItemAspect.SetAttribute(extractedAspectData, AudioAspect.ATTR_CHANNELS, audioChannels.Value);
                    }
                    var audioSampleRate = mediaInfo.GetAudioSampleRate(0);
                    if (audioSampleRate.HasValue)
                    {
                        MediaItemAspect.SetAttribute(extractedAspectData, AudioAspect.ATTR_SAMPLERATE, audioSampleRate.Value);
                    }

                    MediaItemAspect.SetAttribute(extractedAspectData, AudioAspect.ATTR_ENCODING, mediaInfo.GetAudioCodec(0));
                    // MediaInfo returns milliseconds, we need seconds
                    long?time = mediaInfo.GetPlaytime(0);
                    if (time.HasValue && time > 1000)
                    {
                        MediaItemAspect.SetAttribute(extractedAspectData, AudioAspect.ATTR_DURATION, time.Value / 1000);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                // Only log at the info level here - And simply return false. This makes the importer know that we
                // couldn't perform our task here
                ServiceRegistration.Get <ILogger>().Info("RadioRecordingMetadataExtractor: Exception reading resource '{0}' (Text: '{1}')", fsra.CanonicalLocalResourcePath, e.Message);
                return(false);
            }
        }
Example #6
0
        /// <summary>
        /// Returns the information if the specified file name (or path) has a file extension which is
        /// supposed to be supported by this metadata extractor.
        /// </summary>
        /// <param name="fileName">Relative or absolute file path to check.</param>
        /// <returns><c>true</c>, if the file's extension is supposed to be supported, else <c>false</c>.</returns>
        protected static bool HasAudioExtension(string fileName)
        {
            string ext = DosPathHelper.GetExtension(fileName).ToLowerInvariant();

            return(AUDIO_EXTENSIONS.Contains(ext));
        }
        public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary <Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode)
        {
            try
            {
                VideoResult result = null;
                IFileSystemResourceAccessor fsra = mediaItemAccessor as IFileSystemResourceAccessor;
                if (fsra != null && fsra.IsDirectory && fsra.ResourceExists("VIDEO_TS"))
                {
                    IFileSystemResourceAccessor fsraVideoTs = fsra.GetResource("VIDEO_TS");
                    if (fsraVideoTs != null && fsraVideoTs.ResourceExists("VIDEO_TS.IFO"))
                    {
                        // Video DVD
                        using (MediaInfoWrapper videoTsInfo = ReadMediaInfo(fsraVideoTs.GetResource("VIDEO_TS.IFO")))
                        {
                            if (!videoTsInfo.IsValid || videoTsInfo.GetVideoCount() == 0)
                            {
                                return(false); // Invalid video_ts.ifo file
                            }
                            result = VideoResult.CreateDVDInfo(fsra.ResourceName, videoTsInfo);
                        }
                        // Iterate over all video files; MediaInfo finds different audio/video metadata for each .ifo file
                        ICollection <IFileSystemResourceAccessor> files = fsraVideoTs.GetFiles();
                        if (files != null)
                        {
                            foreach (IFileSystemResourceAccessor file in files)
                            {
                                string lowerPath = (file.ResourcePathName ?? string.Empty).ToLowerInvariant();
                                if (!lowerPath.EndsWith(".ifo") || lowerPath.EndsWith("video_ts.ifo"))
                                {
                                    continue;
                                }
                                using (MediaInfoWrapper mediaInfo = ReadMediaInfo(file))
                                {
                                    // Before we start evaluating the file, check if it is a video at all
                                    if (mediaInfo.IsValid && mediaInfo.GetVideoCount() == 0)
                                    {
                                        continue;
                                    }
                                    result.AddMediaInfo(mediaInfo);
                                }
                            }
                        }
                    }
                }
                else if (mediaItemAccessor.IsFile)
                {
                    string filePath = mediaItemAccessor.ResourcePathName;
                    if (!HasVideoExtension(filePath))
                    {
                        return(false);
                    }
                    using (MediaInfoWrapper fileInfo = ReadMediaInfo(mediaItemAccessor))
                    {
                        // Before we start evaluating the file, check if it is a video at all
                        if (!fileInfo.IsValid || (fileInfo.GetVideoCount() == 0 && !IsWorkaroundRequired(filePath)))
                        {
                            return(false);
                        }

                        string mediaTitle = DosPathHelper.GetFileNameWithoutExtension(mediaItemAccessor.ResourceName);
                        result = VideoResult.CreateFileInfo(mediaTitle, fileInfo);
                    }
                    using (Stream stream = mediaItemAccessor.OpenRead())
                        result.MimeType = MimeTypeDetector.GetMimeType(stream);
                }
                if (result != null)
                {
                    result.UpdateMetadata(extractedAspectData);

                    ILocalFsResourceAccessor disposeLfsra = null;
                    try
                    {
                        ILocalFsResourceAccessor lfsra = mediaItemAccessor as ILocalFsResourceAccessor;
                        if (lfsra == null && !forceQuickMode)
                        { // In case forceQuickMode, we only want local browsing
                            IResourceAccessor ra = mediaItemAccessor.Clone();
                            try
                            {
                                lfsra        = StreamedResourceToLocalFsAccessBridge.GetLocalFsResourceAccessor(ra);
                                disposeLfsra = lfsra; // Remember to dispose the extra resource accessor instance
                            }
                            catch (Exception)
                            {
                                ra.Dispose();
                            }
                        }
                        if (lfsra != null)
                        {
                            string localFsPath = lfsra.LocalFileSystemPath;
                            ExtractMatroskaTags(localFsPath, extractedAspectData, forceQuickMode);
                            ExtractThumbnailData(localFsPath, extractedAspectData, forceQuickMode);
                        }
                    }
                    finally
                    {
                        if (disposeLfsra != null)
                        {
                            disposeLfsra.Dispose();
                        }
                    }
                    return(true);
                }
            }
            catch (Exception e)
            {
                // Only log at the info level here - And simply return false. This lets the caller know that we
                // couldn't perform our task here.
                ServiceRegistration.Get <ILogger>().Info("VideoMetadataExtractor: Exception reading resource '{0}' (Text: '{1}')", mediaItemAccessor.CanonicalLocalResourcePath, e.Message);
            }
            return(false);
        }
Example #8
0
        protected static bool HasGameExtension(string fileName, string platform, List <EmulatorConfiguration> configurations)
        {
            string ext = DosPathHelper.GetExtension(fileName).ToLowerInvariant();

            return(configurations.Any(c => c.Platforms.Contains(platform) && (c.FileExtensions.Count == 0 || c.FileExtensions.Contains(ext, StringComparer.InvariantCultureIgnoreCase))));
        }
Example #9
0
        public async Task <bool> TryExtractMetadataAsync(IResourceAccessor mediaItemAccessor, IDictionary <Guid, IList <MediaItemAspect> > extractedAspectData, bool forceQuickMode)
        {
            string fileName = mediaItemAccessor.ResourceName;

            if (!HasImageExtension(fileName))
            {
                return(false);
            }
            if (DosPathHelper.GetFileNameWithoutExtension(fileName).ToLowerInvariant() == "folder")
            {
                return(false); //Ignore folder images
            }
            bool refresh = false;

            if (extractedAspectData.ContainsKey(ImageAspect.ASPECT_ID))
            {
                refresh = true;
            }

            try
            {
                IFileSystemResourceAccessor fsra = mediaItemAccessor as IFileSystemResourceAccessor;
                if (!refresh)
                {
                    MultipleMediaItemAspect providerResourceAspect = MediaItemAspect.CreateAspect(extractedAspectData, ProviderResourceAspect.Metadata);
                    providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_RESOURCE_INDEX, 0);
                    providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_TYPE, ProviderResourceAspect.TYPE_PRIMARY);

                    if (!(mediaItemAccessor is IFileSystemResourceAccessor))
                    {
                        return(false);
                    }

                    providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_SIZE, fsra.Size);
                    if (!forceQuickMode)
                    {
                        // Open a stream for media item to detect mimeType.
                        using (Stream mediaStream = fsra.OpenRead())
                        {
                            string mimeType = MimeTypeDetector.GetMimeType(mediaStream) ?? DEFAULT_MIMETYPE;
                            providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, mimeType);
                        }
                    }
                    else
                    {
                        string mimeType = MimeTypeDetector.GetMimeTypeFromExtension(fileName) ?? DEFAULT_MIMETYPE;
                        providerResourceAspect.SetAttribute(ProviderResourceAspect.ATTR_MIME_TYPE, mimeType);
                    }
                }

                MediaItemAspect mediaAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, MediaAspect.Metadata);
                mediaAspect.SetAttribute(MediaAspect.ATTR_ISVIRTUAL, false);
                MediaItemAspect imageAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, ImageAspect.Metadata);

                if (!refresh)
                {
                    mediaAspect.SetAttribute(MediaAspect.ATTR_TITLE, ProviderPathHelper.GetFileNameWithoutExtension(fileName));

                    if (!forceQuickMode)
                    {
                        // Extract EXIF information from media item.
                        using (ExifMetaInfo.ExifMetaInfo exif = new ExifMetaInfo.ExifMetaInfo(fsra))
                        {
                            mediaAspect.SetAttribute(MediaAspect.ATTR_RECORDINGTIME, exif.OriginalDate != DateTime.MinValue ? exif.OriginalDate : fsra.LastChanged);
                            mediaAspect.SetAttribute(MediaAspect.ATTR_COMMENT, StringUtils.TrimToNull(exif.ImageDescription));

                            if (exif.PixXDim.HasValue)
                            {
                                imageAspect.SetAttribute(ImageAspect.ATTR_WIDTH, (int)exif.PixXDim);
                            }
                            if (exif.PixYDim.HasValue)
                            {
                                imageAspect.SetAttribute(ImageAspect.ATTR_HEIGHT, (int)exif.PixYDim);
                            }
                            imageAspect.SetAttribute(ImageAspect.ATTR_MAKE, StringUtils.TrimToNull(exif.EquipMake));
                            imageAspect.SetAttribute(ImageAspect.ATTR_MODEL, StringUtils.TrimToNull(exif.EquipModel));
                            if (exif.ExposureBias.HasValue)
                            {
                                imageAspect.SetAttribute(ImageAspect.ATTR_EXPOSURE_BIAS, ((double)exif.ExposureBias).ToString());
                            }
                            imageAspect.SetAttribute(ImageAspect.ATTR_EXPOSURE_TIME, exif.ExposureTime);
                            imageAspect.SetAttribute(ImageAspect.ATTR_FLASH_MODE, StringUtils.TrimToNull(exif.FlashMode));
                            if (exif.FNumber.HasValue)
                            {
                                imageAspect.SetAttribute(ImageAspect.ATTR_FNUMBER, string.Format("F {0}", (double)exif.FNumber));
                            }
                            imageAspect.SetAttribute(ImageAspect.ATTR_ISO_SPEED, StringUtils.TrimToNull(exif.ISOSpeed));
                            imageAspect.SetAttribute(ImageAspect.ATTR_ORIENTATION, (Int32)(exif.OrientationType ?? 0));
                            imageAspect.SetAttribute(ImageAspect.ATTR_METERING_MODE, exif.MeteringMode.ToString());

                            if (exif.Latitude.HasValue && exif.Longitude.HasValue)
                            {
                                imageAspect.SetAttribute(ImageAspect.ATTR_LATITUDE, exif.Latitude);
                                imageAspect.SetAttribute(ImageAspect.ATTR_LONGITUDE, exif.Longitude);
                            }
                        }
                    }
                    else
                    {
                        mediaAspect.SetAttribute(MediaAspect.ATTR_RECORDINGTIME, fsra.LastChanged);
                        imageAspect.SetAttribute(ImageAspect.ATTR_ORIENTATION, 0);
                    }

                    byte[] thumbData;
                    // We only want to create missing thumbnails here, so check for existing ones first
                    if (MediaItemAspect.TryGetAttribute(extractedAspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, out thumbData) && thumbData != null)
                    {
                        return(true);
                    }

                    using (LocalFsResourceAccessorHelper rah = new LocalFsResourceAccessorHelper(mediaItemAccessor))
                        using (rah.LocalFsResourceAccessor.EnsureLocalFileSystemAccess())
                        {
                            string localFsResourcePath = rah.LocalFsResourceAccessor.LocalFileSystemPath;
                            if (localFsResourcePath != null)
                            {
                                // Thumbnail extraction
                                IThumbnailGenerator generator = ServiceRegistration.Get <IThumbnailGenerator>();
                                ImageType           imageType;
                                if (generator.GetThumbnail(localFsResourcePath, forceQuickMode, out thumbData, out imageType))
                                {
                                    MediaItemAspect.SetAttribute(extractedAspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, thumbData);
                                }
                            }
                        }
                    return(true);
                }
                else
                {
                    bool   updated   = false;
                    double?latitude  = imageAspect.GetAttributeValue <double?>(ImageAspect.ATTR_LATITUDE);
                    double?longitude = imageAspect.GetAttributeValue <double?>(ImageAspect.ATTR_LONGITUDE);
                    if (!forceQuickMode && IncludeGeoLocationDetails && latitude.HasValue && longitude.HasValue &&
                        string.IsNullOrEmpty(imageAspect.GetAttributeValue <string>(ImageAspect.ATTR_COUNTRY)))
                    {
                        var geoCoordinate = new GeoCoordinate(latitude.Value, longitude.Value);
                        var lookupResult  = await GeoLocationService.Instance.TryLookupAsync(geoCoordinate).ConfigureAwait(false);

                        if (lookupResult.Success)
                        {
                            CivicAddress locationInfo = lookupResult.Result;
                            imageAspect.SetAttribute(ImageAspect.ATTR_CITY, locationInfo.City);
                            imageAspect.SetAttribute(ImageAspect.ATTR_STATE, locationInfo.StateProvince);
                            imageAspect.SetAttribute(ImageAspect.ATTR_COUNTRY, locationInfo.CountryRegion);
                            updated = true;
                        }
                    }

                    byte[] thumbData;
                    // We only want to create missing thumbnails here, so check for existing ones first
                    if (MediaItemAspect.TryGetAttribute(extractedAspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, out thumbData) && thumbData != null)
                    {
                        return(updated);
                    }

                    using (LocalFsResourceAccessorHelper rah = new LocalFsResourceAccessorHelper(mediaItemAccessor))
                        using (rah.LocalFsResourceAccessor.EnsureLocalFileSystemAccess())
                        {
                            string localFsResourcePath = rah.LocalFsResourceAccessor.LocalFileSystemPath;
                            if (localFsResourcePath != null)
                            {
                                // In quick mode only allow thumbs taken from cache.
                                bool cachedOnly = forceQuickMode;
                                // Thumbnail extraction
                                IThumbnailGenerator generator = ServiceRegistration.Get <IThumbnailGenerator>();
                                ImageType           imageType;
                                if (generator.GetThumbnail(localFsResourcePath, cachedOnly, out thumbData, out imageType))
                                {
                                    MediaItemAspect.SetAttribute(extractedAspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, thumbData);
                                    updated = true;
                                }
                            }
                        }
                    return(updated);
                }
            }
            catch (Exception e)
            {
                // Only log at the info level here - And simply return false. This makes the importer know that we
                // couldn't perform our task here.
                ServiceRegistration.Get <ILogger>().Info("ImageMetadataExtractor: Exception reading resource '{0}' (Text: '{1}')", mediaItemAccessor.CanonicalLocalResourcePath, e.Message);
            }
            return(false);
        }
Example #10
0
        public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary <Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode)
        {
            try
            {
                VideoResult result = null;
                IFileSystemResourceAccessor fsra = mediaItemAccessor as IFileSystemResourceAccessor;
                if (fsra == null)
                {
                    return(false);
                }
                if (!fsra.IsFile && fsra.ResourceExists("VIDEO_TS"))
                {
                    IFileSystemResourceAccessor fsraVideoTs = fsra.GetResource("VIDEO_TS");
                    if (fsraVideoTs != null && fsraVideoTs.ResourceExists("VIDEO_TS.IFO"))
                    {
                        // Video DVD
                        using (MediaInfoWrapper videoTsInfo = ReadMediaInfo(fsraVideoTs.GetResource("VIDEO_TS.IFO")))
                        {
                            if (!videoTsInfo.IsValid || videoTsInfo.GetVideoCount() == 0)
                            {
                                return(false); // Invalid video_ts.ifo file
                            }
                            result = VideoResult.CreateDVDInfo(fsra.ResourceName, videoTsInfo);
                        }
                        // Iterate over all video files; MediaInfo finds different audio/video metadata for each .ifo file
                        ICollection <IFileSystemResourceAccessor> files = fsraVideoTs.GetFiles();
                        if (files != null)
                        {
                            foreach (IFileSystemResourceAccessor file in files)
                            {
                                string lowerPath = (file.ResourcePathName ?? string.Empty).ToLowerInvariant();
                                if (!lowerPath.EndsWith(".ifo") || lowerPath.EndsWith("video_ts.ifo"))
                                {
                                    continue;
                                }
                                using (MediaInfoWrapper mediaInfo = ReadMediaInfo(file))
                                {
                                    // Before we start evaluating the file, check if it is a video at all
                                    if (mediaInfo.IsValid && mediaInfo.GetVideoCount() == 0)
                                    {
                                        continue;
                                    }
                                    result.AddMediaInfo(mediaInfo);
                                }
                            }
                        }
                    }
                }
                else if (fsra.IsFile)
                {
                    string filePath = fsra.ResourcePathName;
                    if (!HasVideoExtension(filePath))
                    {
                        return(false);
                    }
                    using (MediaInfoWrapper fileInfo = ReadMediaInfo(fsra))
                    {
                        // Before we start evaluating the file, check if it is a video at all
                        if (!fileInfo.IsValid || (fileInfo.GetVideoCount() == 0 && !IsWorkaroundRequired(filePath)))
                        {
                            return(false);
                        }

                        string mediaTitle = DosPathHelper.GetFileNameWithoutExtension(fsra.ResourceName);
                        result = VideoResult.CreateFileInfo(mediaTitle, fileInfo);
                    }
                    using (Stream stream = fsra.OpenRead())
                        result.MimeType = MimeTypeDetector.GetMimeType(stream, DEFAULT_MIMETYPE);
                }
                if (result != null)
                {
                    result.UpdateMetadata(extractedAspectData);

                    using (LocalFsResourceAccessorHelper rah = new LocalFsResourceAccessorHelper(mediaItemAccessor))
                    {
                        ILocalFsResourceAccessor lfsra = rah.LocalFsResourceAccessor;
                        if (lfsra != null)
                        {
                            MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_SIZE, lfsra.Size);
                            MediaItemAspect.SetAttribute(extractedAspectData, MediaAspect.ATTR_RECORDINGTIME, lfsra.LastChanged);
                            ExtractMatroskaTags(lfsra, extractedAspectData, forceQuickMode);
                            ExtractMp4Tags(lfsra, extractedAspectData, forceQuickMode);
                            ExtractThumbnailData(lfsra, extractedAspectData, forceQuickMode);
                        }
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                // Only log at the info level here - And simply return false. This lets the caller know that we
                // couldn't perform our task here.
                ServiceRegistration.Get <ILogger>().Info("VideoMetadataExtractor: Exception reading resource '{0}' (Text: '{1}')", mediaItemAccessor.CanonicalLocalResourcePath, e.Message);
            }
            return(false);
        }
Example #11
0
        protected string CreateArguments(EmulatorConfiguration emulatorConfiguration, string gamePath)
        {
            if (emulatorConfiguration.IsNative)
            {
                return(emulatorConfiguration.Arguments);
            }

            string format    = emulatorConfiguration.UseQuotes ? "\"{0}\"" : "{0}";
            string arguments = emulatorConfiguration.Arguments ?? "";

            arguments = arguments.Replace(EmulatorConfiguration.WILDCARD_GAME_DIRECTORY, string.Format(format, DosPathHelper.GetDirectory(gamePath)));
            if (!arguments.Contains(EmulatorConfiguration.WILDCARD_GAME_PATH) && !arguments.Contains(EmulatorConfiguration.WILDCARD_GAME_PATH_NO_EXT))
            {
                return(string.Format("{0} {1}", arguments.TrimEnd(), string.Format(format, gamePath)));
            }
            return(arguments.Replace(EmulatorConfiguration.WILDCARD_GAME_PATH, string.Format(format, gamePath))
                   .Replace(EmulatorConfiguration.WILDCARD_GAME_PATH_NO_EXT, string.Format(format, DosPathHelper.GetFileNameWithoutExtension(gamePath))));
        }
Example #12
0
 public bool TryStart()
 {
     try
     {
         string path      = CreatePath(_emulatorConfiguration, _gamePath);
         string arguments = CreateArguments(_emulatorConfiguration, _gamePath);
         ServiceRegistration.Get <ILogger>().Debug("EmulatorProcess: Starting '{0} {1}'", path, arguments);
         _process           = new Process();
         _process.StartInfo = new ProcessStartInfo(path, arguments);
         _process.StartInfo.WorkingDirectory = string.IsNullOrEmpty(_emulatorConfiguration.WorkingDirectory) ? DosPathHelper.GetDirectory(_emulatorConfiguration.Path) : _emulatorConfiguration.WorkingDirectory;
         _process.EnableRaisingEvents        = true;
         _process.Exited += OnExited;
         bool result = _process.Start();
         if (result && !_emulatorConfiguration.IsNative && _mappedKey != null && _mappedKey != Key.None)
         {
             _inputHandler = new InputHandler(_process.Id, _mappedKey);
             _inputHandler.MappedKeyPressed += OnMappedKeyPressed;
         }
         return(result);
     }
     catch (Exception ex)
     {
         ServiceRegistration.Get <ILogger>().Error("EmulatorProcess: Error starting process", ex);
         return(false);
     }
 }
Example #13
0
        protected bool IsPathValid(ResourcePath resourcePath)
        {
            string chosenPath = LocalFsResourceProviderBase.ToDosPath(resourcePath);

            return(DosPathHelper.GetFileName(chosenPath) != null);
        }
        protected bool HasOpticalDiscFileExtension(string fileName)
        {
            string ext = DosPathHelper.GetExtension(fileName).ToLowerInvariant();

            return(OPTICAL_DISC_FILE_EXT.Contains(ext));
        }
        protected bool HasImageExtension(string fileName)
        {
            string ext = DosPathHelper.GetExtension(fileName).ToLowerInvariant();

            return(_imageExtensions.Contains(ext));
        }