Advertisement
sparktank

BDMV Playlist Perl

Feb 28th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.91 KB | None | 0 0
  1. # /usr/bin/perl find-playlist.perl <bluray root dir>
  2. #
  3. # This script will find the playlist that has matching mpls and clipinfo segments.
  4. # The one with the longest number of segments is typically the correct main movie file.
  5. #
  6. # Example:
  7. #
  8. # Create a movie directory (e.g. RED2) and copy BDMV/CLIPINF and BDMV/PLAYLIST to it.
  9. # You should now have a structure like this:
  10. #
  11. #    RED2/BDMV/CLIPINF
  12. #    RED2/BDMV/PLAYLIST
  13. #
  14. # Then execute the script:
  15. #
  16. # /usr/bin/perl find-playlist.perl RED2
  17. #
  18. #
  19.  
  20. my $path = shift;
  21.  
  22. my $clips     = read_m2ts("$path\\BDMV\\CLIPINF", ".clpi");
  23. my $playlists = read_m2ts("$path\\BDMV\\PLAYLIST", ".mpls");
  24.  
  25. foreach my $list (sort {$a <=> $b} keys %{$playlists}) {
  26.   my @clp = @{$playlists->{$list}};
  27.  
  28.   my @playlist = ();
  29.  
  30.   my $next = $clp[0];
  31.   push(@playlist, $next);
  32.   my $last = $next;
  33.   $next = ${$clips->{$last}}[0];
  34.  
  35.   if($next && $next != $last) {
  36.     while ($next && $next != $last) {
  37.       push(@playlist, $next);
  38.       $last = $next;
  39.       $next = ${$clips->{$last}}[0];
  40.     }
  41.   }
  42.  
  43.   my $mpls = join(",",@clp);
  44.   my $cliplist = join(",",@playlist);
  45.  
  46.   if( $mpls eq $cliplist ) {
  47.     printf("$list :\n");
  48.     printf("  mpls     -> $mpls\n");
  49.     printf("  clipinfo -> $cliplist\n");
  50.   }
  51.  
  52. }
  53.  
  54. sub read_m2ts {
  55.  
  56.   my $dir = shift;
  57.   my $ext = shift;
  58.  
  59.   my $out = {};
  60.  
  61.   opendir(DIR, "$dir") || die "can't open $dir";
  62.   my @dir = readdir(DIR);
  63.   closedir DIR;
  64.  
  65.   foreach my $file ( grep{ /$ext$/ } @dir ) {
  66.  
  67.     open(XIN, "<$dir\\$file");
  68.     my @infile = <XIN>;
  69.     chomp @infile;
  70.  
  71.  
  72.     my $tmp = join(" ", @infile);
  73.     my @stuff = $tmp=~m/\d\d\d\d\dM2TS/g;
  74.     my @streams = ();
  75.     foreach my $strm (@stuff) {
  76.       my $a = $strm;
  77.       $a =~s/^0*//;
  78.       $a =~s/M2TS$//;
  79.       push(@streams, $a);
  80.     }
  81.  
  82.     my $fnum = $file;
  83.     $fnum =~s/$ext$//;
  84.     $fnum =~s/^0*//;
  85.     $out->{$fnum}=[@streams];
  86.  
  87.   }
  88.  
  89.   return $out;
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement