Esempio n. 1
0
        /// <summary>
        /// Scans a bluray folder and returns a BDInfo object
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private static BDInfoExt ScanWorker(string path)
        {
            BDPlayerBuilder.LogInfo("Scanning bluray structure: {0}", path);
            BDInfoExt bluray = new BDInfoExt(path.ToUpper(), true); // For title selection we need all information here, but this can cause quite big delays for remote resources!

            bluray.Scan();
            return(bluray);
        }
        public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary<Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode)
        {
            try
              {
            IResourceAccessor ra = mediaItemAccessor.Clone();
            try
            {
              using (ILocalFsResourceAccessor fsra = StreamedResourceToLocalFsAccessBridge.GetLocalFsResourceAccessor(ra))
            if (fsra != null && fsra.IsDirectory && fsra.ResourceExists("BDMV"))
            {
              IFileSystemResourceAccessor fsraBDMV = fsra.GetResource("BDMV");
              if (fsraBDMV != null && fsraBDMV.ResourceExists("index.bdmv"))
              {
                // BluRay
                MediaItemAspect mediaAspect;
                if (!extractedAspectData.TryGetValue(MediaAspect.ASPECT_ID, out mediaAspect))
                  extractedAspectData[MediaAspect.ASPECT_ID] = mediaAspect = new MediaItemAspect(MediaAspect.Metadata);
                MediaItemAspect videoAspect;
                if (!extractedAspectData.TryGetValue(VideoAspect.ASPECT_ID, out videoAspect))
                  extractedAspectData[VideoAspect.ASPECT_ID] = new MediaItemAspect(VideoAspect.Metadata);

                mediaAspect.SetAttribute(MediaAspect.ATTR_MIME_TYPE, "video/bluray"); // BluRay disc

                string bdmvDirectory = fsra.LocalFileSystemPath;
                BDInfoExt bdinfo = new BDInfoExt(bdmvDirectory);
                mediaAspect.SetAttribute(MediaAspect.ATTR_TITLE, bdinfo.GetTitle() ?? mediaItemAccessor.ResourceName);
                return true;
              }
            }
            }
            catch
            {
              ra.Dispose();
              throw;
            }
            return false;
              }
              catch
              {
            // Only log at the info level here - And simply return false. This makes the importer know that we
            // couldn't perform our task here
            if (mediaItemAccessor != null)
              ServiceRegistration.Get<ILogger>().Info("BluRayMetadataExtractor: Exception reading source '{0}'", mediaItemAccessor.ResourcePathName);
            return false;
              }
        }
    public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary<Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode)
    {
      try
      {
        if (!(mediaItemAccessor is IFileSystemResourceAccessor))
          return false;

        using (LocalFsResourceAccessorHelper rah = new LocalFsResourceAccessorHelper(mediaItemAccessor))
        {
          ILocalFsResourceAccessor lfsra = rah.LocalFsResourceAccessor;
          if (!lfsra.IsFile && lfsra.ResourceExists("BDMV"))
          {
            IFileSystemResourceAccessor fsraBDMV = lfsra.GetResource("BDMV");
            if (fsraBDMV != null && fsraBDMV.ResourceExists("index.bdmv"))
            {
              // This line is important to keep in, if no VideoAspect is created here, the MediaItems is not detected as Video! 
              MediaItemAspect.GetOrCreateAspect(extractedAspectData, VideoAspect.Metadata);
              MediaItemAspect mediaAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, MediaAspect.Metadata);

              mediaAspect.SetAttribute(MediaAspect.ATTR_MIME_TYPE, "video/bluray"); // BluRay disc

              using (lfsra.EnsureLocalFileSystemAccess())
              {
                BDInfoExt bdinfo = new BDInfoExt(lfsra.LocalFileSystemPath);
                string title = bdinfo.GetTitle();
                mediaAspect.SetAttribute(MediaAspect.ATTR_TITLE, title ?? mediaItemAccessor.ResourceName);

                // Check for BD disc thumbs
                FileInfo thumbnail = bdinfo.GetBiggestThumb();
                if (thumbnail != null)
                {
                  try
                  {
                    using (FileStream fileStream = new FileStream(thumbnail.FullName, FileMode.Open, FileAccess.Read))
                    using (MemoryStream resized = (MemoryStream)ImageUtilities.ResizeImage(fileStream, ImageFormat.Jpeg, MAX_COVER_WIDTH, MAX_COVER_HEIGHT))
                    {
                      MediaItemAspect.SetAttribute(extractedAspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, resized.ToArray());
                    }
                  }
                    // Decoding of invalid image data can fail, but main MediaItem is correct.
                  catch
                  {
                  }
                }
              }
              return true;
            }
          }
        }
        return false;
      }
      catch
      {
        // Only log at the info level here - And simply return false. This makes the importer know that we
        // couldn't perform our task here
        if (mediaItemAccessor != null)
          ServiceRegistration.Get<ILogger>().Info("BluRayMetadataExtractor: Exception reading source '{0}'", mediaItemAccessor.ResourcePathName);
        return false;
      }
    }
Esempio n. 4
0
 /// <summary>
 /// Scans a bluray folder and returns a BDInfo object
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 private static BDInfoExt ScanWorker(string path)
 {
   BDPlayerBuilder.LogInfo("Scanning bluray structure: {0}", path);
   BDInfoExt bluray = new BDInfoExt(path.ToUpper(), true); // For title selection we need all information here, but this can cause quite big delays for remote resources!
   bluray.Scan();
   return bluray;
 }
    public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary<Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode)
    {
      try
      {
        IResourceAccessor ra = mediaItemAccessor.Clone();
        try
        {
          using (ILocalFsResourceAccessor fsra = StreamedResourceToLocalFsAccessBridge.GetLocalFsResourceAccessor(ra))
            if (fsra != null && fsra.IsDirectory && fsra.ResourceExists("BDMV"))
            {
              IFileSystemResourceAccessor fsraBDMV = fsra.GetResource("BDMV");
              if (fsraBDMV != null && fsraBDMV.ResourceExists("index.bdmv"))
              {
                // This line is important to keep in, if no VideoAspect is created here, the MediaItems is not detected as Video! 
                MediaItemAspect.GetOrCreateAspect(extractedAspectData, VideoAspect.Metadata);
                MediaItemAspect mediaAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, MediaAspect.Metadata);

                mediaAspect.SetAttribute(MediaAspect.ATTR_MIME_TYPE, "video/bluray"); // BluRay disc

                string bdmvDirectory = fsra.LocalFileSystemPath;
                BDInfoExt bdinfo = new BDInfoExt(bdmvDirectory);
                string title = bdinfo.GetTitle();
                mediaAspect.SetAttribute(MediaAspect.ATTR_TITLE, title ?? mediaItemAccessor.ResourceName);

                // Check for BD disc thumbs
                FileInfo thumbnail = bdinfo.GetBiggestThumb();
                if (thumbnail != null)
                {
                  byte[] binary = new byte[thumbnail.Length];
                  using (FileStream fileStream = new FileStream(thumbnail.FullName, FileMode.Open, FileAccess.Read))
                  using (BinaryReader binaryReader = new BinaryReader(fileStream))
                    binaryReader.Read(binary, 0, binary.Length);

                  MediaItemAspect.SetAttribute(extractedAspectData, ThumbnailLargeAspect.ATTR_THUMBNAIL, binary);
                }
                return true;
              }
            }
        }
        catch
        {
          ra.Dispose();
          throw;
        }
        return false;
      }
      catch
      {
        // Only log at the info level here - And simply return false. This makes the importer know that we
        // couldn't perform our task here
        if (mediaItemAccessor != null)
          ServiceRegistration.Get<ILogger>().Info("BluRayMetadataExtractor: Exception reading source '{0}'", mediaItemAccessor.ResourcePathName);
        return false;
      }
    }
Esempio n. 6
0
 /// <summary>
 /// Scans a bluray folder and returns a BDInfo object
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 private static BDInfoExt ScanWorker(string path)
 {
     BDPlayerBuilder.LogInfo("Scanning bluray structure: {0}", path);
       BDInfoExt bluray = new BDInfoExt(path.ToUpper(), false); // We do not need all information here, only the playlists
       bluray.ScanPlaylists();
       return bluray;
 }
Esempio n. 7
0
        /// <summary>
        /// Returns wether a choice was made and changes the file path
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns>True if playback should continue, False if user cancelled.</returns>
        private bool DoFeatureSelection(ref string filePath)
        {
            try
            {
                // If we have chosen a specific playlist, build the path directly without scanning the complete structure again
                if (_manualTitleSelection != null && !string.IsNullOrEmpty(_playlistFolder))
                {
                    filePath = Path.Combine(_playlistFolder, _manualTitleSelection.Name);
                    GetChapters(_manualTitleSelection);
                    _manualTitleSelection = null;
                    return(true);
                }

                ScanProcess  scanner = ScanWorker;
                IAsyncResult result  = scanner.BeginInvoke(filePath, null, scanner);
                result.AsyncWaitHandle.WaitOne();
                BDInfoExt bluray = scanner.EndInvoke(result);

                // Store all playlist files for title selection
                _bdTitles = bluray.PlaylistFiles.Values.Where(p => p.IsValid && !p.HasLoops).Distinct().ToList();
                int counter = 0;
                _bdTitleNames   = _bdTitles.Select(t => FormatTitle(t, ++counter)).ToArray();
                _playlistFolder = bluray.DirectoryPLAYLIST.FullName;

                List <TSPlaylistFile> allPlayLists = _bdTitles.OrderByDescending(p => p.TotalLength).ToList();

                // Feature selection logic
                TSPlaylistFile listToPlay;
                if (allPlayLists.Count == 0)
                {
                    BDPlayerBuilder.LogInfo("No valid playlists found, use default INDEX.BDMV.");
                    return(true);
                }
                if (allPlayLists.Count == 1)
                {
                    // if we have only one playlist to show just move on
                    BDPlayerBuilder.LogInfo("Found one valid playlist {0}.", allPlayLists[0].Name);
                    listToPlay = allPlayLists[0];
                }
                else
                {
                    // Show selection dialog
                    BDPlayerBuilder.LogInfo("Found {0} playlists, title selection available.", allPlayLists.Count);

                    // first make an educated guess about what the real features are (more than one chapter, no loops and longer than one hour)
                    // todo: make a better filter on the playlists containing the real features
                    List <TSPlaylistFile> playLists = allPlayLists.Where(p => (p.Chapters.Count > 1 || p.TotalLength >= MINIMAL_FULL_FEATURE_LENGTH) && !p.HasLoops).ToList();

                    // if the filter yields zero results just list all playlists
                    if (playLists.Count == 0)
                    {
                        playLists = allPlayLists;
                    }

                    listToPlay = playLists[0];
                }

                BDPlayerBuilder.LogInfo("Using playlist {0}.", listToPlay.Name);
                for (int idx = 0; idx < _bdTitles.Count; idx++)
                {
                    if (_bdTitles[idx] != listToPlay)
                    {
                        continue;
                    }
                    _currentTitleName = _bdTitleNames[idx];
                    break;
                }

                GetChapters(listToPlay);

                // Combine the chosen file path (playlist)
                filePath = Path.Combine(bluray.DirectoryPLAYLIST.FullName, listToPlay.Name);
                return(true);
            }
            catch (Exception e)
            {
                BDPlayerBuilder.LogError("Exception while reading bluray structure {0} {1}", e.Message, e.StackTrace);
                return(true);
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Scans a bluray folder and returns a BDInfo object
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 private BDInfoExt ScanWorker(string path)
 {
     BDPlayerBuilder.LogInfo("Scanning bluray structure: {0}", path);
       BDInfoExt bluray = new BDInfoExt(path.ToUpper());
       bluray.Scan();
       return bluray;
 }