Advertisement
Guest User

Untitled

a guest
Nov 28th, 2010
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.23 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. ##### trackerautoUP 1.06 - An Unrar And AutoUpload Script #####
  3.  
  4. #########################################################
  5. ##################BEGIN CONFIGURATION###################
  6. #########################################################
  7.  
  8. ###################Fasttorrent######################
  9. #Enter 0 For No, 1 For Yes
  10. my $fasttorrent = 1;
  11.  
  12. ###################Full Anounce URL######################
  13. #Ex. my $announce = "http://tracker.tracker.net:34000/PASSKEY/announce"
  14. my $announce = "";
  15.  
  16. ####################tracker Login Info#######################
  17. my $username = "";
  18. my $password = "";
  19.  
  20. ###############Output Folder For Media###################
  21. #Ex. /home/gonephishin/data/tvshows/uploads/
  22. my $output_folder = "";
  23.  
  24. ###############Output Folder For Info####################
  25. #This Directory Is Used To Backup Scene .nfos And
  26. #To Store mediainfo Output Files
  27. #Ex. /home/gonephishin/nfobackup/
  28. my $nfo_folder = "";
  29.  
  30. ###############Output Folder For Torrents################
  31. #DO NOT USE YOUR CLIENT'S WATCH DIRECTORY FOR THIS
  32. #THIS IS IMPORTANT AS SOME CLIENTS DO NOT LEAVE THE
  33. #TORRENT FILE IN THE WATCH DIRECTORY (DELUGE) AND WE NEED
  34. #THE FILE IN ORDER TO FILL OUT THE UPLOAD FORM
  35. #Ex. /home/gonephishin/torrentfilesbackup/
  36. my $torrent_output = "";
  37.  
  38. ###############Client Watch Directory####################
  39. #Once The .torrent File Is Created It Will Be Copied
  40. #To Your Client's Watch Folder
  41. #Ex. /home/gonephishin/watch/tvshows/uploads/
  42. my $client_watch = "";
  43.  
  44. #########################################################
  45. ##################END OF CONFIGURATION###################
  46. ###########DO NOT EDIT BELOW THIS LINE UNLESS############
  47. ###############YOU KNOW WHAT YOU ARE DOING###############
  48. #########################################################
  49.  
  50. use strict;
  51. use warnings;
  52. use WWW::Mechanize;
  53.  
  54. #########################################################
  55. ###################Check Variables#######################
  56. #########################################################
  57.  
  58. if (!$announce) {
  59. print "No Announce URL In Configuration, Please Fix This\n";
  60. exit 0;
  61. }
  62. if (!$username) {
  63. print "No BTN Username In Configuration, Please Fix This\n";
  64. exit 0;
  65. }
  66. if (!$password) {
  67. print "No BTN Password In Configuration, Please Fix This\n";
  68. exit 0;
  69. }
  70. if (!$output_folder) {
  71. print "No Output Directory In Configuration, Please Fix This\n";
  72. exit 0;
  73. }
  74. if (!$nfo_folder) {
  75. print "No Info Directory In Configuration, Please Fix This\n";
  76. exit 0;
  77. }
  78. if (!$torrent_output) {
  79. print "No Torrent Output Directory In Configuration, Please Fix This\n";
  80. exit 0;
  81. }
  82. if (!$client_watch) {
  83. print "No Client Watch Directory In Configuration, Please Fix This\n";
  84. exit 0;
  85. }
  86. if ($torrent_output eq $client_watch) {
  87. print "Torrent Output Directory And Client Watch Directory Cannot Be The Same, Please Fix This\n";
  88. exit 0;
  89. }
  90.  
  91. #########################################################
  92. ###################File Preperation######################
  93. #########################################################
  94.  
  95. ###################Get Directory Name####################
  96. my $numArgs = $#ARGV; #Retrieves Directory From User Input
  97. my $show_dir = ''; #Declares Directory Name
  98. if ($numArgs == -1) { #If No Directory Is Supplied, Warns User And Quit Script
  99. print "Need Directory Parameter\n";
  100. print "Correct Syntax Is:\n";
  101. print "perl btnautoup.pl /path/to/directory/\n";
  102. exit 0;
  103. }
  104. foreach $numArgs ($#ARGV) { #If Multiple Directories Were Supplied, Only Use Last One
  105. $show_dir = $ARGV[$numArgs];
  106. }
  107.  
  108. ###################Remove Trailing Slashes From Directory Variables####################
  109. $show_dir =~ s/\/$//;
  110. $output_folder =~ s/\/$//;
  111. $torrent_output =~ s/\/$//;
  112. $client_watch =~ s/\/$//;
  113. $nfo_folder =~ s/\/$//;
  114.  
  115. ###################Get Release Name From Directory####################
  116. my $release_name = "$show_dir"; #Declares Release Name
  117. if ($show_dir =~ /.*\/(.*)/) { #Removes Path Up To Last Directory To Retrieve Release Name
  118. $release_name = $1; #Sets Release Name To Regex Output
  119. }
  120.  
  121. ###################Find The Rar File####################
  122. opendir(DIR, $show_dir); #Opens The Directory
  123. my @tempfiles = grep(/\.rar$/,readdir(DIR)); #Scans for files ending in .rar
  124. closedir(DIR); #Closes The Directory
  125. my $rar_file = $tempfiles[0]; #Chooses First .rar File Found
  126. $rar_file = "$show_dir\/$rar_file"; #Adds Full Path To Rar File Name
  127.  
  128. ###################Find The NFO File####################
  129. opendir(DIR, $show_dir); #Opens The Directory
  130. @tempfiles = grep(/\.nfo$/,readdir(DIR)); #Scans for files ending in .nfo
  131. closedir(DIR); #Closes The Directory
  132. my $nfo_name = $tempfiles[0]; #Chooses First .nfo File Found
  133. my $nfo_file = "$show_dir\/$nfo_name"; #Adds Full Path To Rar File Name
  134.  
  135. ###################Backup The NFO File####################
  136. print "Backing Up $nfo_name, Please Wait.\n"; #Alerts The User That We Are Going To Backup The Scene NFO File
  137. `cp -f \"$nfo_file\" \"$nfo_folder\/$nfo_name\"`; #Copies The NFO File To The Backup Directory
  138.  
  139. ###################Retrieve The Extracted File Name####################
  140. my $output_file = `unrar l \"$rar_file\"|grep -E \'\(avi|mkv\)\'`; #Retrieves Name Of Extracted File From .rar File
  141. $output_file =~ /\ (.*?)(\.avi|\.mkv)/i; #Parses unrar Output
  142. $output_file = $1 . $2; #Combines File Name And Extension
  143. $output_file = "$output_folder\/$output_file"; #Adds Full Path To Output File
  144.  
  145. ###################Unrar The File####################
  146. my $rar_command = "unrar e \"$rar_file\" \"$output_folder\""; #Creates The Command Used To Unrar The Episode
  147. print "Unraring $output_file, Please Wait.\n"; #Alerts The User That We Are Going To Unrar
  148. `$rar_command`; #Unrars The File
  149.  
  150. ###################Mediainfo Extraction####################
  151. my $media_info_file = "$nfo_folder\/$release_name.mediainfo.nfo"; #Sets Name For MediaInfo Output
  152. my $media_info_command = "mediainfo --LogFile=\"$media_info_file\" \"$output_file\""; #Writes Command To Extract MediaInfo
  153. print "Getting MediaInfo for $release_name, Please Wait.\n"; #Alerts The User That We Are Going To Unrar
  154. `$media_info_command`; #Gets MediaInfo
  155.  
  156. ###################Mediainfo Parsing####################
  157. my $privacy_command = "/usr/bin/perl -p -i -e \"s/\Q$output_folder\E/PathRemoved/g\" \"$media_info_file\""; #Writes Command To Remove Full File Path From MediaInfo Output
  158. print "Removing File Path From MediaInfo for $release_name, Please Wait.\n"; #Alerts The User That We Are Going To Unrar
  159. `$privacy_command`; #Fixes MediaInfo
  160. open (MNFO, "$media_info_file"); #Opens The MediaInfo File
  161. my $media_info_data = join("", <MNFO>); #Loads The Contents Of The MediaInfo File
  162. close MNFO; #Closes The MediaInfo File
  163.  
  164. ###################Make The Torrent File####################
  165. my $torrent_name = "$release_name.[BTN].torrent"; #Sets Name For Torrent File
  166. my $torrent_file = "$torrent_output\/$torrent_name"; #Sets Full Path For Torrent File
  167. my $torrent_command = "mktorrent -p -a \"$announce\" -o \"$torrent_file\" \"$output_file\""; #Creates The Command Used To Create A Torrent
  168. print "Making $torrent_name, Please Wait.\n"; #Alerts The User That We Are Going To Make A Torrent
  169. `$torrent_command`; #Creates The .torrent File
  170.  
  171. ###################Adding Torrent To Client####################
  172. my $client_file = "$client_watch\/$torrent_name"; #Sets Full Path For Client File
  173. print "Adding $torrent_name To Client, Please Wait.\n"; #Alerts The User That We Are Going To Add The Torrent To The Client
  174. `cp -f \"$torrent_file\" \"$client_file\"`; #Copies The Torrent File To The Client Directory
  175.  
  176. #########################################################
  177. ####################Torrent Upload#######################
  178. #########################################################
  179.  
  180. ###################Login To BTN##########################
  181. my $mech = WWW::Mechanize->new( autocheck => 1 ); #Initializes WWW::Mechanize
  182. $mech->get("https://broadcasthe.net/login.php"); #Retrieves The Login Page
  183. print "Logging Into BTN, Please Wait.\n"; #Alerts The User
  184. $mech->submit_form( #Logs Us Into BTN
  185. form_number => 0,
  186. fields => {
  187. username => "$username",
  188. password => "$password",
  189. }
  190. );
  191. ###################Autofill Upload Form##################
  192. $mech->get("https://broadcasthe.net/upload.php"); #Loads Upload Page Into Mech
  193. print "Using BTN Autofill, Please Wait.\n"; #Alerts The User
  194. $mech->form_id('upload_table'); #Selects The Upload Table As The Current Form
  195. $mech->field('autofill', $release_name); #Enters The Scene Name Into Autofill
  196. $mech->click_button(value => 'Get Info'); #Clicks Autofill And Retrieves Completed Form
  197.  
  198. ###################Submit Upload Form##################
  199. print "Uploading Torrent To BTN, Please Wait.\n"; #Alerts The User
  200. $mech->form_id('upload_table'); #The Upload Page Has Been Reloaded So We Need To Select The Form Again
  201. my $yearcheck = $mech->value('year'); #Retrieves The Autofill Value For The Year Field
  202. my $genrecheck = $mech->value('tags'); #Retrieves The Autofill Value For The Genre Field
  203. my $tvtitlecheck = $mech->value('title'); #Retrieves The Autofill Value For The TV Title Field
  204. if (!$yearcheck) {
  205. $mech->field('year', '2010'); #If Autofill Did Not Enter A Year, Enters 2010 As A Default
  206. }
  207. if (!$genrecheck) {
  208. $mech->field('tags', 'Unknown'); #If Autofill Did Not Enter A Year, Enters Unknown As A Default
  209. }
  210. if (!$tvtitlecheck) {
  211. print "Autofill Didn't Parse This Scene Release Correctly\n"; #If Autofill Did Not Enter A TV Title, Warns User And Quits
  212. print "This Usually Occurs On Shows That Are Not In SXXEXX Format\n";
  213. print "Please Use The .mediainfo.nfo And .torrent Files To Upload This Release Manually\n";
  214. exit 0;
  215. }
  216. $mech->field('file_input', $torrent_file); #Inputs The .torrent File
  217. $mech->field('release_desc', $media_info_data); #Adds The MediaInfo Data To The NFO Text Field
  218. my $form = $mech->current_form(); #Chooses The Current Form, Needed For Next Command
  219. if ($fasttorrent) {
  220. $form->find_input('fasttorrent')->check(); #Chooses The Fasttorrent Option If Specified In Config.
  221. }
  222. $mech->click(); #Clicks Upload Torrent
  223.  
  224. ###################Logout Of BTN##################
  225. $mech->get("https://broadcasthe.net/"); #Loads The Home Page
  226. print "Logging Out Of BTN, Please Wait.\n"; #Alerts The User
  227. $mech->follow_link(url_regex => qr/logout\.php/); #Logs Us Out
  228.  
  229. print "All Finished!\n"; #Alerts The User
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement