public override List <ChapterInfo> GetStreams(string location, int numtitle) { ChapterInfo pgc = new ChapterInfo(); pgc.Chapters = new List <ChapterEntry>(); pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location); pgc.SourceName = location; pgc.Title = Path.GetFileNameWithoutExtension(location); pgc.SourceType = "Blu-Ray"; pgc.Extractor = Application.ProductName + " " + Application.ProductVersion; FileInfo fileInfo = new FileInfo(location); OnStreamDetected(pgc); TSPlaylistFile mpls = new TSPlaylistFile(fileInfo); //Dictionary<string, TSStreamClipFile> clips = new Dictionary<string,TSStreamClipFile>(); mpls.Scan(); foreach (double d in mpls.Chapters) { pgc.Chapters.Add(new ChapterEntry() { Name = string.Empty, Time = new TimeSpan((long)(d * (double)TimeSpan.TicksPerSecond)) }); } pgc.Duration = new TimeSpan((long)(mpls.TotalLength * (double)TimeSpan.TicksPerSecond)); foreach (TSStreamClip clip in mpls.StreamClips) { clip.StreamClipFile.Scan(); foreach (TSStream stream in clip.StreamClipFile.Streams.Values) { if (stream.IsVideoStream) { pgc.FramesPerSecond = (double)((TSVideoStream)stream).FrameRateEnumerator / (double)((TSVideoStream)stream).FrameRateDenominator; break; } } if (pgc.FramesPerSecond != 0) { break; } } OnChaptersLoaded(pgc); OnExtractionComplete(); return(new List <ChapterInfo>() { pgc }); }
private void GetChapters(TSPlaylistFile playlistFile) { if (playlistFile == null || playlistFile.Chapters == null) { return; } _chapterTimestamps = playlistFile.Chapters.ToArray(); _chapterNames = new string[_chapterTimestamps.Length]; for (int c = 0; c < _chapterNames.Length; c++) { _chapterNames[c] = GetChapterName(c + 1); } }
private bool BDROMOnPlaylistFileScanError(TSPlaylistFile playlistFile, Exception exception) { var message = string.Format("Error occurred while scanning playlist file {0}", playlistFile.Name); #if DEBUG_SCAN_ERRORS Logger.Warn(message, exception); return(true); #else throw new PlaylistFileScanException(message, exception) { PlaylistFile = playlistFile }; #endif }
public static Playlist Transform(TSPlaylistFile playlistFile) { return(new Playlist { FileName = playlistFile.Name, FullPath = playlistFile.FullName, FileSize = playlistFile.FileSize, Length = TimeSpan.FromMilliseconds(playlistFile.TotalLength * 1000), StreamClips = StreamClipTransformer.Transform(playlistFile.StreamClips), Tracks = TrackTransformer.Transform(playlistFile.SortedStreams), Chapters = ChapterTransformer.Transform(playlistFile.Chapters), HasDuplicateStreamClips = playlistFile.HasDuplicateClips, HasLoops = playlistFile.HasLoops }); }
/// <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 GetLengthFromPlaylist(string filePath) { try { //bool ChecklistToPlay = false; Func <string, BDInfo> scanner = scanWorker; IAsyncResult result = scanner.BeginInvoke(filePath, null, scanner); BDInfo bluray = scanner.EndInvoke(result); // Put the bluray info into a member variable (for later use) currentMediaInfo = bluray; List <TSPlaylistFile> allPlayLists = bluray.PlaylistFiles.Values.Where(p => p.IsValid).OrderByDescending(p => p.TotalLength).Distinct().ToList(); // find movie lenght from selection logger.Info("Found {0} playlists, showing selection dialog.", 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 >= MinimalFullFeatureLength) && !p.HasLoops).ToList(); // if the filter yields zero results just list all playlists if (playLists.Count == 0) { playLists = allPlayLists; } // Take first movie Length TSPlaylistFile playList = playLists[0]; _duration = (int)playList.TotalLength * 1000; // put the choosen playlist into our member variable for later use currentPlaylistFile = playLists[0]; return(true); } catch (Exception e) { logger.Error("Exception while reading bluray structure {0} {1}", e.Message, e.StackTrace); return(false); } }
/// <summary> /// Sets the current title. /// </summary> /// <param name="title">Title</param> public override void SetTitle(string title) { bool found = false; int idx; for (idx = 0; idx < Titles.Length; idx++) { if (Titles[idx] == title) { found = true; break; } } if (!found) { return; } _manualTitleSelection = _bdTitles[idx]; Shutdown(true); SetMediaItem(_resourceLocator, Titles[idx]); }
/// <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); } BDInfoExt bluray; try { bluray = ScanWorker(filePath); } catch (Exception) { // If our parsing of BD structure fails, the splitter might still be able to handle the BDMV directly, so return "success" here. return(true); } // 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(false); } }
private string FormatTitle(TSPlaylistFile playlist, int counter) { return(string.Format("{0} Title {1} - {2}", _mediaItemTitle, counter, FormatLength(playlist.TotalLength))); }
public override List <ChapterInfo> GetStreams(string location) { ChapterInfo pgc = new ChapterInfo(); pgc.Chapters = new List <Chapter>(); pgc.SourceHash = ChapterExtractor.ComputeMD5Sum(location); pgc.SourceName = location; pgc.Title = Path.GetFileNameWithoutExtension(location); pgc.SourceType = "Blu-Ray"; DirectoryInfo DirectoryBDMV = GetDirectoryBDMV(location); if (DirectoryBDMV == null) { throw new Exception("Unable to locate BD structure."); } DirectoryInfo DirectoryRoot = DirectoryBDMV.Parent; DirectoryInfo DirectoryBDJO = GetDirectory("BDJO", DirectoryBDMV, 0); DirectoryInfo DirectoryCLIPINF = GetDirectory("CLIPINF", DirectoryBDMV, 0); DirectoryInfo DirectoryPLAYLIST = GetDirectory("PLAYLIST", DirectoryBDMV, 0); DirectoryInfo DirectorySNP = GetDirectory("SNP", DirectoryRoot, 0); DirectoryInfo DirectorySTREAM = GetDirectory("STREAM", DirectoryBDMV, 0); DirectoryInfo DirectorySSIF = GetDirectory("SSIF", DirectorySTREAM, 0); Dictionary <string, TSStreamClipFile> StreamClipFiles = new Dictionary <string, TSStreamClipFile>(); Dictionary <string, TSStreamFile> StreamFiles = new Dictionary <string, TSStreamFile>(); if (DirectorySTREAM != null) { FileInfo[] files = DirectorySTREAM.GetFiles("*.m2ts"); if (files.Length == 0) { files = DirectoryPLAYLIST.GetFiles("*.M2TS"); } foreach (FileInfo file in files) { StreamFiles.Add(file.Name.ToUpper(), new TSStreamFile(file)); } } if (DirectoryCLIPINF != null) { FileInfo[] files = DirectoryCLIPINF.GetFiles("*.clpi"); if (files.Length == 0) { files = DirectoryPLAYLIST.GetFiles("*.CLPI"); } foreach (FileInfo file in files) { StreamClipFiles.Add(file.Name.ToUpper(), new TSStreamClipFile(file)); } } FileInfo fileInfo = new FileInfo(location); TSPlaylistFile mpls = new TSPlaylistFile(fileInfo); mpls.Scan(StreamFiles, StreamClipFiles); int count = 1; foreach (double d in mpls.Chapters) { pgc.Chapters.Add(new Chapter() { Name = "Chapter " + count.ToString("D2"), Time = new TimeSpan((long)(d * (double)TimeSpan.TicksPerSecond)) }); count++; } pgc.Duration = new TimeSpan((long)(mpls.TotalLength * (double)TimeSpan.TicksPerSecond)); foreach (TSStreamClip clip in mpls.StreamClips) { clip.StreamClipFile.Scan(); foreach (TSStream stream in clip.StreamClipFile.Streams.Values) { if (stream.IsVideoStream) { pgc.FramesPerSecond = VideoUtil.ConvertFPSFractionToDouble(((TSVideoStream)stream).FrameRateEnumerator, ((TSVideoStream)stream).FrameRateDenominator); break; } } if (pgc.FramesPerSecond != 0) { break; } } if (pgc.Duration.TotalSeconds > MainForm.Instance.Settings.ChapterCreatorMinimumLength) { OnStreamDetected(pgc); OnChaptersLoaded(pgc); } else { pgc = null; } OnExtractionComplete(); return(new List <ChapterInfo>() { pgc }); }
/// <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 GetLengthFromPlaylist(string filePath) { try { //bool ChecklistToPlay = false; Func<string, BDInfo> scanner = scanWorker; IAsyncResult result = scanner.BeginInvoke(filePath, null, scanner); BDInfo bluray = scanner.EndInvoke(result); // Put the bluray info into a member variable (for later use) currentMediaInfo = bluray; List<TSPlaylistFile> allPlayLists = bluray.PlaylistFiles.Values.Where(p => p.IsValid).OrderByDescending(p => p.TotalLength).Distinct().ToList(); // find movie lenght from selection logger.Info("Found {0} playlists, showing selection dialog.", 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 >= MinimalFullFeatureLength) && !p.HasLoops).ToList(); // if the filter yields zero results just list all playlists if (playLists.Count == 0) { playLists = allPlayLists; } // Take first movie Length TSPlaylistFile playList = playLists[0]; _duration = (int)playList.TotalLength * 1000; // put the choosen playlist into our member variable for later use currentPlaylistFile = playLists[0]; return true; } catch (Exception e) { logger.Error("Exception while reading bluray structure {0} {1}", e.Message, e.StackTrace); return false; } }
protected bool BDROM_PlaylistFileScanError(TSPlaylistFile playlistFile, Exception ex) { logger.Debug("Playlist File Scan Error"); scanfailed = true; return(false); }