Advertisement
zefie

MKV Default Audio Track Switcher

Sep 20th, 2011
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2. $dir = `ls -1 *.mkv`;
  3. $files = split("\n",$dir);
  4.  
  5. foreach ($files as $file) {
  6.     if (strlen($file) <= 0) {
  7.         continue;
  8.     }
  9.  
  10.     echo "Processing ".$file."...\n";
  11.     $sample = `mkvinfo "$file"`;
  12.     $tracks = preg_split("/\| \+ A track/",$sample);
  13.  
  14.     foreach ($tracks as $track) {
  15.         $tag = "|  + Track number: ";
  16.         $meh = strpos($track,$tag);
  17.         if ($meh <= 0) {
  18.             continue;
  19.         }
  20.  
  21.         $meh = $meh + strlen($tag);
  22.         $meh2 = strpos($track,"\n",$meh);
  23.         $trackno = substr($track,$meh,($meh2 - $meh));
  24.  
  25.         $tag = "|  + Enabled: ";
  26.         $meh = strpos($track,$tag);
  27.         if ($meh <= 0) {
  28.             continue;
  29.         }
  30.         $meh = $meh + strlen($tag);
  31.         $meh2 = strpos($track,"\n",$meh);
  32.         $enabled = substr($track,$meh,($meh2 - $meh));
  33.  
  34.         $tag = "|  + Default flag: ";
  35.         $meh = strpos($track,$tag);
  36.         if ($meh <= 0) {
  37.             continue;
  38.         }
  39.         $meh = $meh + strlen($tag);
  40.         $meh2 = strpos($track,"\n",$meh);
  41.         $def = substr($track,$meh,($meh2 - $meh));
  42.  
  43.         $tag = "|  + Language: ";
  44.         $meh = strpos($track,$tag);
  45.         if ($meh <= 0) {
  46.             continue;
  47.         }
  48.         $meh = $meh + strlen($tag);
  49.         $meh2 = strpos($track,"\n",$meh);
  50.         $lang = substr($track,$meh,($meh2 - $meh));
  51.  
  52. //      echo "Track Number: ".$trackno."\n";
  53. //      echo "Enabled: ".$enabled."\n";
  54. //      echo "Default: ".$def."\n";
  55. //      echo "Language: ".$lang."\n";
  56.  
  57.         if ($enabled) {
  58.             if ($lang == "eng" && !$def) {
  59.                 $cmd = 'mkvpropedit "'.$file.'" -e track:'.$trackno.' -s flag-default=1';
  60.                 exec($cmd);
  61.                 echo "Track ".$trackno." is ".$lang.". Set Default.\n";
  62.             }
  63.             if ($lang == "ger" && $def) {
  64.                 $cmd = 'mkvpropedit "'.$file.'" -e track:'.$trackno.' -s flag-default=0';
  65.                 exec($cmd);
  66.                 echo "Track ".$trackno." is ".$lang.". Set not default.\n";
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement