diff --git a/pirate-remote.py b/pirate-remote.py index 41b7218..a431119 100644 --- a/pirate-remote.py +++ b/pirate-remote.py @@ -43,7 +43,7 @@ for torrent in t.get_torrents(): # Add new torrents pushes = pb.get_pushes() for push in pushes[1]: - if push['body'].startswith('magnet:?'): - system('/opt/pirate/pirate.py --link {}'.format(str(push['body']))) + if push['body'].startswith('https://thepiratebay'): + system('/opt/pirate/pirate.py --url {}'.format(str(push['body']))) pb.delete_push(push['iden']) diff --git a/pirate.py b/pirate.py index 2badd05..694fad9 100755 --- a/pirate.py +++ b/pirate.py @@ -37,7 +37,7 @@ tpb = "https://thepiratebay.se" # Torrent server IP; can be any machine running transmission-daemon # with a firewall inbound allowed to TCP/9091 (transmissionrpc) -rpcserver = 'localhost' +rpcserver = '10.1.1.28' # Squelch HTTPS insecure warnings @@ -52,7 +52,9 @@ parser.add_argument('--search', '-s', dest='searcharg', help='The string to sear parser.add_argument('--top', '-t', dest='top', action='store_true', help='Automatically grab the torrent with most seeds', required=False) -parser.add_argument('--link', '-l', dest='link', help='Direct link to magnet or torrent file', required=False) +parser.add_argument('--file', '-l', dest='file', help='Direct link to magnet or torrent file', required=False) + +parser.add_argument('--url', '-u', dest='url', help='HTML page of the torrent file', required=False) args = parser.parse_args() @@ -72,7 +74,7 @@ def checkTransmission(): print "\n\nLater bro." exit(1) except transmissionrpc.error.TransmissionError: - print "[!] Transmission-daemon not running!" + print "[!] Transmission-daemon not running on {}!".format(rpcserver) exit(2) @@ -82,8 +84,11 @@ def getSearchURL(): Formats string into proper url Gets HTML source of search page for use in the next function """ - if args.link: - transmissionrpc.Client(rpcserver).add_torrent(args.link) + if args.file: + transmissionrpc.Client(rpcserver).add_torrent(args.file) + exit(0) + elif args.url: + downloadTorrent(args.url) exit(0) elif args.searcharg: searchString = args.searcharg @@ -115,7 +120,7 @@ def analyzeURL(source): #If -t is supplied, bypass this section of code and go on to download the top torrent if args.top and links: - downloadTorrent(links[0]) + downloadTorrent("{}/{}".format(tpb, links[0])) else: for number,link in enumerate(links): #Enumerate the array so the numbers start at 0 results.update({number:link}) #Append results to results dictionary @@ -152,7 +157,7 @@ def chooseTorrent(): exit() #Quit script elif selection in results: #If selection exists, set value to 'choice' variable choice = results[selection] #Updates variable based on key provided above, matches it with results dict - downloadTorrent(choice) + downloadTorrent("{}/{}".format(tpb, choice)) else: #If anything other than 98, 99, or valid key number entered, loop back to selection input print "\nNot a valid number" chooseTorrent() @@ -162,14 +167,14 @@ def chooseTorrent(): chooseTorrent() -def downloadTorrent(torrent): +def downloadTorrent(torrentURL): """ Grabs the first magnet link and initiates the download using the transmissionrpc python library """ magnetLinks = [] - torrentPage = requests.get("{}/{}".format(tpb, torrent), verify=False) + torrentPage = requests.get(torrentURL, verify=False) torrentPageSoup = bs4.BeautifulSoup(torrentPage.content) for link in torrentPageSoup.find_all('a'): @@ -178,7 +183,7 @@ def downloadTorrent(torrent): magnetLink = magnetLinks[0] - print "\n[+] Adding magnet link for torrent:\n\n{}".format(torrent) + print "\n[+] Adding magnet link for torrent:\n\n{}".format(torrentURL) transmissionrpc.Client(rpcserver).add_torrent(magnetLink) diff --git a/readme.md b/readme.md index dab5721..c3f3470 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ Command line torrent downloader with [Pushbullet](https://pushbullet.com) notifi Default behavior parses HTML pages on [ThePirateBay](https://thepiratebay.se) based on a search string provided, then passes the magnet link to a locally running Transmission-Daemon (localhost or same LAN). -Can also add direct links with --link. +Can also add direct HTML pages of the desired torrent with --url, and direct magnet links and torrent files with --file. ---- @@ -26,7 +26,7 @@ If pip is installed, just run the following as root: $ pip install transmissionrpc requests beautifulsoup4 ``` -Then edit the pirate.py file, and change the //rpcserver// variable to the server's IP/hostname (if not localhost) +Then edit the pirate.py file, and change the __rpcserver__ variable to the server's IP/hostname (if not localhost) #### Server Side (transmission-daemon and pirate-remote.py) @@ -53,7 +53,7 @@ $ iptables -A INPUT -p tcp --dport 9091 -j ACCEPT $ pip install pushbullet.py ``` -Put your PushBullet API key in api variable in the script and set a cron job to run //pirate-remote.py// every X minutes. +Put your PushBullet API key in api variable in the script and set a cron job to run pirate-remote.py every X minutes. Make sure the server running Transmission (if not localhost) is accepting traffic on TCP/9091 and RPC is enabled in the Transmission settings.json file. Read about configuring Transmission [here](https://trac.transmissionbt.com/wiki/EditConfigFiles).