Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3. //
  4. // Torrent folder post processing thingamajiggy.
  5. //
  6. //
  7. // Edit these vars to suit your directory structure and file paths //////////////
  8.  
  9. $wput = "/usr/bin/wput";
  10. $user = "user";
  11. $pass = "password";
  12. $host = "servername";
  13.  
  14. $MYSQLHOST = "ruri";
  15. $MYSQLUSER = "root";
  16. $MYSQLPASS = "mysqlpassword";
  17. $MYSQLDB   = "announce";
  18. $db = mysql_connect($MYSQLHOST, $MYSQLUSER , $MYSQLPASS);
  19.  
  20. mysql_select_db($MYSQLDB, $db) or die(mysql_error($db));
  21.  
  22.  
  23.  
  24. $toplevels = array(             // change the 2nd part to suit your dir names
  25.     'tv'     => 'tv.eps',
  26.     'movie'  => 'movies',
  27.     'x264'   => 'x264',
  28.     'applications'  => 'applications',
  29.     'games' => 'games',
  30.     'wii'   => 'wii'
  31.     );
  32.  
  33. // Don't edit blow this line if you're clueless ////////////////////////////////
  34.  
  35. $dir = trim($argv[1]);
  36.  
  37. //
  38. // Match TV Eps based on 'SxxExx'
  39. //
  40. if($ok = preg_match('/(.*)\.S([0-9]+)E([0-9]+)/i', $dir, $m)) {
  41.     $tld = $toplevels['tv'];
  42.     $name = str_replace('.', ' ', $m[1]) .'/Season '. preg_replace('/^0+/', '', $m[2]);
  43.     $destdir = "/$tld/". $name ."/";
  44. }
  45. //
  46. // Match movies based on 'DVDRIP/DVDSCR/CAM/XVID/DIVX/BDRIP'
  47. //
  48. else if($ok = preg_match('/DVDRIP|DVDSCR|CAM|XVID|DIVX|BDRIP/i', $dir, $m)) {
  49.     $tld = $toplevels['movie'];
  50.     $destdir = "/$tld/";
  51. }
  52. //
  53. // Match movies based on 'x264'
  54. //
  55. else if($ok = preg_match('/x264/i', $dir, $m)) {
  56.     $tld = $toplevels['x264'];
  57.     $destdir = "/$tld/";
  58. }
  59.  
  60. else if($ok = preg_match('/ISO|Razor1911|RELOADED|FLT|DEViANCE|SKIDROW/i', $dir, $m)) {
  61.     $tld = $toplevels['games'];
  62.     $destdir = "/$tld/";
  63.  
  64. }else if($ok = preg_match('/Wii|WII|wii/i',$dir,$m)) {
  65.     $tld = $toplevels['wii'];
  66.     $destdir = "/$tld/";
  67. } else {
  68.     $rld = $toplevels['applications'];
  69.     $destdir = "/$tld/";
  70. //
  71. // Perform the desired action(s) if a match was found
  72. //
  73. if($ok) {
  74.     echo $destdir;
  75.     exec("$wput '$dir' 'ftp://$user:$pass@$host$destdir' 2>&1", $output, $retval);
  76.     $sqldir = '"' . $dir . '"';
  77.     $query = "insert into downloads (name,printed) VALUES($sqldir,0)";
  78.     mysql_query($query);
  79.  
  80.     if($retval == 0) {
  81.         echo "Successfully uploaded $dir to $destdir.\n";
  82.     } else {
  83.         echo "FAILED to upload $dir to $destdir:\n";
  84.         foreach($output as $line)
  85.                 echo $line ."\n";
  86.     }
  87. } else {
  88.  
  89.   echo "NO MATCH for ". $dir ." :(\n";
  90. }
  91.  
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement