Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- ######################################################
- # Import
- ######################################################
- import sys
- import os
- import re
- import string
- import subprocess
- import cfscrape #cloudflare scrape
- import mechanize
- # enable this for debug log
- #import logging
- #logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
- ######################################################
- # Customized information
- ######################################################
- # login info
- username = ""
- password = ""
- key = "" # for 2FA
- # url & announce url
- url = "https://broadcasthe.net/"
- announce_url = "http://landof.tv/91m0re3jwdez081kthvz0wmge0aud1ct/announce"
- # fast torrent. 1 = on, 0 = off
- fast_torrent = 1
- # torrent output folder / client watch directory
- torrent_output_folder = "/home/ltv/rtorrent.watch/temp/btn/" # Leave trailing slash
- # type of source
- sources = ["HDTV", "WEBRip", "Bluray", "DVDRip", "PDTV", "WEB-DL"]
- ######################################################
- # Preparation
- ######################################################
- input_file_full = sys.argv[1]
- release_name = sys.argv[2]
- input_file = os.path.basename(input_file_full)
- extension = os.path.splitext(input_file)[1]
- # get 2FA key
- #fa = subprocess.Popen(["oathtool", "--totp", "-b", key], stdout=subprocess.PIPE)
- #code, err = fa.communicate()
- #code = code.rstrip()
- # get mediainfo
- p = subprocess.Popen(["mediainfo", input_file_full], stdout=subprocess.PIPE)
- mediainfo, err = p.communicate()
- # make torrent file
- #print "Making torrent file..."
- torrent_output_file = torrent_output_folder + release_name + ".torrent"
- subprocess.Popen(["mktorrent", "-p", "-a", announce_url, input_file_full, "-o", torrent_output_file],
- stdout=subprocess.PIPE).communicate()
- ######################################################
- # Log into BTN
- ######################################################
- # bypassing cloudflare
- s = cfscrape.create_scraper()
- s.get(url)
- # prepare mechanize + pass cookies from cfsrape to mechanize
- br = mechanize.Browser()
- br.set_handle_robots(False)
- #br.set_debug_http(True)
- #br.set_debug_responses(True)
- #br.set_debug_redirects(True)
- br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0')]
- br.set_cookiejar(s.cookies)
- # open BTN's login page
- br.open(url+"login.php")
- # select login form & input user info
- br.select_form(name="loginform")
- br.form["username"] = username
- br.form["password"] = password
- br.form["keeplogged"] = ["1"]
- br.submit()
- # submit the 2FA form
- #br.select_form(nr=0)
- #br.form["code"] = code
- #br.submit()
- #######################################################
- # Upload to BTN
- #######################################################
- # Open upload page
- br.open(url+"upload.php")
- # Select form and fill in autofill
- br.select_form(nr=7)
- br.form["autofill"] = release_name
- br.submit(label="Get Info")
- # Check autofill
- br.select_form(nr=7)
- if br.form["artist"] == "AutoFill Fail" or br.form["title"] == "AutoFill Fail":
- regex = re.match("(.*?)\.S?(\d{1,2})E?(\d{2})\.(.*)", release_name, flags=re.IGNORECASE)
- series_name = regex.group(1).replace(".", " ")
- br.form["artist"] = series_name
- # sys.exit("Autofill failed, please upload manually.")
- # Check source field
- if br.form["media"] == ["---"]:
- for source in sources:
- if source in release_name:
- br.form["media"] = [source]
- # Check scene field
- if br.form["origin"] == ["---"]:
- br.form["origin"] = ["Scene"]
- # Check genre field
- if br.form["tags"] == "":
- br.form["tags"] = "Drama"
- # Add torrent file
- br.form.add_file(open(torrent_output_file), "application/x-bittorrent", torrent_output_file, name="file_input")
- # Add mediainfo
- br.form["release_desc"] = mediainfo
- # Set fast torrent
- if fast_torrent == 1:
- br.find_control("fasttorrent").items[0].selected = True
- # Add container // due to BTN's SD wrong container
- br.form["format"] == [extension]
- # Submit form & upload
- r = br.submit(label="Upload torrent")
- #######################################################
- # Logout & finish
- #######################################################
- br.follow_link(url_regex=r"logout.php")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement