Advertisement
Guest User

Untitled

a guest
Feb 5th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. #!/usr/bin/python
  2. ######################################################
  3. # Import
  4. ######################################################
  5. import sys
  6. import os
  7. import re
  8. import string
  9. import subprocess
  10. import cfscrape #cloudflare scrape
  11. import mechanize
  12. # enable this for debug log
  13. #import logging
  14. #logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
  15.  
  16. ######################################################
  17. # Customized information
  18. ######################################################
  19. # login info
  20. username = ""
  21. password = ""
  22. key = "" # for 2FA
  23.  
  24. # url & announce url
  25. url = "https://broadcasthe.net/"
  26. announce_url = "http://landof.tv/91m0re3jwdez081kthvz0wmge0aud1ct/announce"
  27.  
  28. # fast torrent. 1 = on, 0 = off
  29. fast_torrent = 1
  30.  
  31. # torrent output folder / client watch directory
  32. torrent_output_folder = "/home/ltv/rtorrent.watch/temp/btn/" # Leave trailing slash
  33.  
  34. # type of source
  35. sources = ["HDTV", "WEBRip", "Bluray", "DVDRip", "PDTV", "WEB-DL"]
  36.  
  37. ######################################################
  38. # Preparation
  39. ######################################################
  40. input_file_full = sys.argv[1]
  41. release_name = sys.argv[2]
  42. input_file = os.path.basename(input_file_full)
  43. extension = os.path.splitext(input_file)[1]
  44.  
  45. # get 2FA key
  46. #fa = subprocess.Popen(["oathtool", "--totp", "-b", key], stdout=subprocess.PIPE)
  47. #code, err = fa.communicate()
  48. #code = code.rstrip()
  49.  
  50. # get mediainfo
  51. p = subprocess.Popen(["mediainfo", input_file_full], stdout=subprocess.PIPE)
  52. mediainfo, err = p.communicate()
  53.  
  54. # make torrent file
  55. #print "Making torrent file..."
  56. torrent_output_file = torrent_output_folder + release_name + ".torrent"
  57. subprocess.Popen(["mktorrent", "-p", "-a", announce_url, input_file_full, "-o", torrent_output_file],
  58. stdout=subprocess.PIPE).communicate()
  59.  
  60. ######################################################
  61. # Log into BTN
  62. ######################################################
  63. # bypassing cloudflare
  64. s = cfscrape.create_scraper()
  65. s.get(url)
  66.  
  67. # prepare mechanize + pass cookies from cfsrape to mechanize
  68. br = mechanize.Browser()
  69. br.set_handle_robots(False)
  70. #br.set_debug_http(True)
  71. #br.set_debug_responses(True)
  72. #br.set_debug_redirects(True)
  73. br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0')]
  74. br.set_cookiejar(s.cookies)
  75.  
  76. # open BTN's login page
  77. br.open(url+"login.php")
  78.  
  79. # select login form & input user info
  80. br.select_form(name="loginform")
  81. br.form["username"] = username
  82. br.form["password"] = password
  83. br.form["keeplogged"] = ["1"]
  84. br.submit()
  85.  
  86. # submit the 2FA form
  87. #br.select_form(nr=0)
  88. #br.form["code"] = code
  89. #br.submit()
  90.  
  91. #######################################################
  92. # Upload to BTN
  93. #######################################################
  94. # Open upload page
  95. br.open(url+"upload.php")
  96.  
  97. # Select form and fill in autofill
  98. br.select_form(nr=7)
  99. br.form["autofill"] = release_name
  100. br.submit(label="Get Info")
  101.  
  102. # Check autofill
  103. br.select_form(nr=7)
  104. if br.form["artist"] == "AutoFill Fail" or br.form["title"] == "AutoFill Fail":
  105. regex = re.match("(.*?)\.S?(\d{1,2})E?(\d{2})\.(.*)", release_name, flags=re.IGNORECASE)
  106. series_name = regex.group(1).replace(".", " ")
  107. br.form["artist"] = series_name
  108. # sys.exit("Autofill failed, please upload manually.")
  109.  
  110. # Check source field
  111. if br.form["media"] == ["---"]:
  112. for source in sources:
  113. if source in release_name:
  114. br.form["media"] = [source]
  115.  
  116. # Check scene field
  117. if br.form["origin"] == ["---"]:
  118. br.form["origin"] = ["Scene"]
  119.  
  120. # Check genre field
  121. if br.form["tags"] == "":
  122. br.form["tags"] = "Drama"
  123.  
  124. # Add torrent file
  125. br.form.add_file(open(torrent_output_file), "application/x-bittorrent", torrent_output_file, name="file_input")
  126.  
  127. # Add mediainfo
  128. br.form["release_desc"] = mediainfo
  129.  
  130. # Set fast torrent
  131. if fast_torrent == 1:
  132. br.find_control("fasttorrent").items[0].selected = True
  133.  
  134. # Add container // due to BTN's SD wrong container
  135. br.form["format"] == [extension]
  136.  
  137. # Submit form & upload
  138. r = br.submit(label="Upload torrent")
  139.  
  140. #######################################################
  141. # Logout & finish
  142. #######################################################
  143. br.follow_link(url_regex=r"logout.php")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement