protected MultimediaDriveHandler(DriveInfo driveInfo, IEnumerable<MediaItem> mediaItems, MultiMediaType mediaType) : base(driveInfo) { _mediaType = mediaType; _mediaItemsSubViewSpecification = new StaticViewSpecification( driveInfo.VolumeLabel + " (" + DriveUtils.GetDriveNameWithoutRootDirectory(driveInfo) + ")", new Guid[] {}, new Guid[] {}); foreach (MediaItem item in mediaItems) _mediaItemsSubViewSpecification.AddMediaItem(item); }
protected MultimediaDriveHandler(DriveInfo driveInfo, IEnumerable <MediaItem> mediaItems, MultiMediaType mediaType) : base(driveInfo) { _mediaType = mediaType; _mediaItemsSubViewSpecification = new StaticViewSpecification( driveInfo.VolumeLabel + " (" + DriveUtils.GetDriveNameWithoutRootDirectory(driveInfo) + ")", new Guid[] {}, new Guid[] {}); foreach (MediaItem item in mediaItems) { _mediaItemsSubViewSpecification.AddMediaItem(item); } }
protected MultimediaDriveHandler(DriveInfo driveInfo, IEnumerable <Guid> necessaryMIATypeIds, IEnumerable <Guid> optionalMIATypeIds, MultiMediaType mediaType) : base(driveInfo) { _mediaType = mediaType; string drive = driveInfo.Name; drive = drive.Substring(0, 2); // Clip potential '\\' at the end string directory = "/" + drive + "/"; _mediaItemsSubViewSpecification = new LocalDirectoryViewSpecification(driveInfo.VolumeLabel + " (" + DriveUtils.GetDriveNameWithoutRootDirectory(driveInfo) + ")", ResourcePath.BuildBaseProviderPath(LocalFsResourceProviderBase.LOCAL_FS_RESOURCE_PROVIDER_ID, directory), necessaryMIATypeIds, optionalMIATypeIds); }
/// <summary> /// Detects if the directory of the given <paramref name="resourcePath"/> contains video, image or audio media files and /// returns <see cref="MediaItem"/> instances for those files. /// </summary> /// <param name="resourcePath">The resource path instance for the directory to be examined.</param> /// <param name="videoMIATypeIds">Ids of the media item aspects to be extracted from video items.</param> /// <param name="imageMIATypeIds">Ids of the media item aspects to be extracted from image items.</param> /// <param name="audioMIATypeIds">Ids of the media item aspects to be extracted from audio items.</param> /// <param name="mediaItems">Returns a collection of media items in the given <paramref name="resourcePath"/> or <c>null</c>, /// if the return value is <see cref="MultiMediaType.None"/>.</param> /// <returns>Type of media items found.</returns> public static MultiMediaType DetectMultimedia(ResourcePath resourcePath, IEnumerable <Guid> videoMIATypeIds, IEnumerable <Guid> imageMIATypeIds, IEnumerable <Guid> audioMIATypeIds, out ICollection <MediaItem> mediaItems) { try { mediaItems = new List <MediaItem>(); IMediaAccessor mediaAccessor = ServiceRegistration.Get <IMediaAccessor>(); IEnumerable <Guid> meIds = mediaAccessor.GetMetadataExtractorsForMIATypes(videoMIATypeIds.Union(imageMIATypeIds).Union(audioMIATypeIds)); using (IResourceAccessor ra = new ResourceLocator(resourcePath).CreateAccessor()) { IFileSystemResourceAccessor directoryRA = ra as IFileSystemResourceAccessor; if (ra != null) { AddLocalMediaItemsRecursive(directoryRA, mediaItems, meIds, mediaAccessor); } } MultiMediaType result = MultiMediaType.None; foreach (MediaItem item in mediaItems) { // Check the type of our extracted media items MultiMediaType itemType = GetTypeOfMediaItem(item); if (result == MultiMediaType.None) // Initialize the result type with the type of the first media item { result = itemType; } else if (result != itemType) // Check if we have different item types { result = MultiMediaType.Diverse; break; } } return(result); } catch (Exception e) { ServiceRegistration.Get <ILogger>().Warn("Error while detecting the media items in resource {0}", e, resourcePath); mediaItems = null; return(MultiMediaType.None); } }
/// <summary> /// Detects if the directory of the given <paramref name="resourcePath"/> contains video, image or audio media files. /// </summary> /// <param name="resourcePath">The resource path instance for the directory to be examined.</param> /// <param name="videoMIATypeIds">Ids of the media item aspects to be extracted from video items.</param> /// <param name="imageMIATypeIds">Ids of the media item aspects to be extracted from image items.</param> /// <param name="audioMIATypeIds">Ids of the media item aspects to be extracted from audio items.</param> /// if the return value is <see cref="MultiMediaType.None"/>.</param> /// <returns>Type of media items found.</returns> public static MultiMediaType DetectMultimedia(ResourcePath resourcePath, IEnumerable <Guid> videoMIATypeIds, IEnumerable <Guid> imageMIATypeIds, IEnumerable <Guid> audioMIATypeIds) { try { MultiMediaType result = MultiMediaType.None; IMediaAccessor mediaAccessor = ServiceRegistration.Get <IMediaAccessor>(); IEnumerable <Guid> meIds = mediaAccessor.GetMetadataExtractorsForMIATypes(videoMIATypeIds.Union(imageMIATypeIds).Union(audioMIATypeIds)); using (IResourceAccessor ra = new ResourceLocator(resourcePath).CreateAccessor()) { IFileSystemResourceAccessor directoryRA = ra as IFileSystemResourceAccessor; if (ra != null) { DetectMultimediaTypeRecursive(directoryRA, meIds, mediaAccessor, ref result); } } return(result); } catch (Exception e) { ServiceRegistration.Get <ILogger>().Warn("Error while detecting the media items in resource {0}", e, resourcePath); return(MultiMediaType.None); } }
/// <summary> /// Creates a <see cref="MultimediaDriveHandler"/> if the drive of the given <paramref name="driveInfo"/> contains one or more /// media item files. /// </summary> /// <param name="driveInfo">Drive info object for the drive to examine.</param> /// <param name="videoMIATypeIds">Media item aspect types to be extracted from the video items. The given MIAs will be present /// in all created instance's video items.</param> /// <param name="imageMIATypeIds">Media item aspect types to be extracted from the image items. The given MIAs will be present /// in all created instance's image items.</param> /// <param name="audioMIATypeIds">Media item aspect types to be extracted from the audio items. The given MIAs will be present /// in all created instance's audio items.</param> /// <returns><see cref="MultimediaDriveHandler"/> instance for the multimedia CD/DVD/BD or <c>null</c>, if the given drive doesn't contain /// media items.</returns> public static MultimediaDriveHandler TryCreateMultimediaCDDriveHandler(DriveInfo driveInfo, IEnumerable <Guid> videoMIATypeIds, IEnumerable <Guid> imageMIATypeIds, IEnumerable <Guid> audioMIATypeIds) { string drive = driveInfo.Name; if (string.IsNullOrEmpty(drive) || drive.Length < 2) { return(null); } drive = drive.Substring(0, 2); // Clip potential '\\' at the end string directory = drive + "\\"; MultiMediaType mediaType = MultimediaDirectory.DetectMultimedia(directory, videoMIATypeIds, imageMIATypeIds, audioMIATypeIds); if (mediaType == MultiMediaType.None) { return(null); } IEnumerable <Guid> necessaryMIATypeIds = Consts.NECESSARY_BROWSING_MIAS; IEnumerable <Guid> optionalMIATypeIds = videoMIATypeIds.Union(imageMIATypeIds).Union(audioMIATypeIds).Except(necessaryMIATypeIds); return(new MultimediaDriveHandler(driveInfo, necessaryMIATypeIds, optionalMIATypeIds, mediaType)); }
/// <summary> /// Detects media type of all media items which are found in the directory to the given <paramref name="directoryRA"/> or in any sub directory. /// </summary> /// <param name="directoryRA">Directory resource to be recursively examined.</param> /// <param name="metadataExtractorIds">Ids of the metadata extractors to be applied to the resources. /// See <see cref="IMediaAccessor.LocalMetadataExtractors"/>.</param> /// <param name="mediaAccessor">The media accessor of the system.</param> /// <param name="type">The media type detected.</param> public static void DetectMultimediaTypeRecursive(IFileSystemResourceAccessor directoryRA, IEnumerable <Guid> metadataExtractorIds, IMediaAccessor mediaAccessor, ref MultiMediaType type) { if (type == MultiMediaType.Diverse) { return; } ICollection <IFileSystemResourceAccessor> fileRAs = FileSystemResourceNavigator.GetFiles(directoryRA, false); if (fileRAs != null) { foreach (IFileSystemResourceAccessor fileRA in fileRAs) { try { using (fileRA) { MediaItem item = mediaAccessor.CreateLocalMediaItem(fileRA, metadataExtractorIds); if (item != null) { MultiMediaType itemType = GetTypeOfMediaItem(item); if (type == MultiMediaType.None) // Initialize the result type with the type of the first media item { type = itemType; } else if (type != itemType) // Check if we have different item types { type = MultiMediaType.Diverse; return; } } } } catch (Exception e) { ServiceRegistration.Get <ILogger>().Info("MultimediaDirectoy: Error while detection of media type of file '{0}': {1}", fileRA.Path, e.Message); } } } ICollection <IFileSystemResourceAccessor> directoryRAs = FileSystemResourceNavigator.GetChildDirectories(directoryRA, false); if (directoryRAs != null) { foreach (IFileSystemResourceAccessor subDirectoryRA in directoryRAs) { try { using (subDirectoryRA) { DetectMultimediaTypeRecursive(subDirectoryRA, metadataExtractorIds, mediaAccessor, ref type); if (type == MultiMediaType.Diverse) { return; } } } catch (Exception e) { ServiceRegistration.Get <ILogger>().Info("MultimediaDirectoy: Error while detection of media type of folder '{0}': {1}", subDirectoryRA.Path, e.Message); } } } }