changing end function for also accepting URL

master
lalanza808 9 years ago
parent c5d4bcbd51
commit a46e70a70f

@ -43,7 +43,7 @@ for torrent in t.get_torrents():
# Add new torrents # Add new torrents
pushes = pb.get_pushes() pushes = pb.get_pushes()
for push in pushes[1]: for push in pushes[1]:
if push['body'].startswith('magnet:?'): if push['body'].startswith('https://thepiratebay'):
system('/opt/pirate/pirate.py --link {}'.format(str(push['body']))) system('/opt/pirate/pirate.py --url {}'.format(str(push['body'])))
pb.delete_push(push['iden']) pb.delete_push(push['iden'])

@ -37,7 +37,7 @@ tpb = "https://thepiratebay.se"
# Torrent server IP; can be any machine running transmission-daemon # Torrent server IP; can be any machine running transmission-daemon
# with a firewall inbound allowed to TCP/9091 (transmissionrpc) # with a firewall inbound allowed to TCP/9091 (transmissionrpc)
rpcserver = 'localhost' rpcserver = '10.1.1.28'
# Squelch HTTPS insecure warnings # 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('--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() args = parser.parse_args()
@ -72,7 +74,7 @@ def checkTransmission():
print "\n\nLater bro." print "\n\nLater bro."
exit(1) exit(1)
except transmissionrpc.error.TransmissionError: except transmissionrpc.error.TransmissionError:
print "[!] Transmission-daemon not running!" print "[!] Transmission-daemon not running on {}!".format(rpcserver)
exit(2) exit(2)
@ -82,8 +84,11 @@ def getSearchURL():
Formats string into proper url Formats string into proper url
Gets HTML source of search page for use in the next function Gets HTML source of search page for use in the next function
""" """
if args.link: if args.file:
transmissionrpc.Client(rpcserver).add_torrent(args.link) transmissionrpc.Client(rpcserver).add_torrent(args.file)
exit(0)
elif args.url:
downloadTorrent(args.url)
exit(0) exit(0)
elif args.searcharg: elif args.searcharg:
searchString = 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 -t is supplied, bypass this section of code and go on to download the top torrent
if args.top and links: if args.top and links:
downloadTorrent(links[0]) downloadTorrent("{}/{}".format(tpb, links[0]))
else: else:
for number,link in enumerate(links): #Enumerate the array so the numbers start at 0 for number,link in enumerate(links): #Enumerate the array so the numbers start at 0
results.update({number:link}) #Append results to results dictionary results.update({number:link}) #Append results to results dictionary
@ -152,7 +157,7 @@ def chooseTorrent():
exit() #Quit script exit() #Quit script
elif selection in results: #If selection exists, set value to 'choice' variable 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 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 else: #If anything other than 98, 99, or valid key number entered, loop back to selection input
print "\nNot a valid number" print "\nNot a valid number"
chooseTorrent() chooseTorrent()
@ -162,14 +167,14 @@ def chooseTorrent():
chooseTorrent() chooseTorrent()
def downloadTorrent(torrent): def downloadTorrent(torrentURL):
""" """
Grabs the first magnet link and initiates the download using the transmissionrpc python library Grabs the first magnet link and initiates the download using the transmissionrpc python library
""" """
magnetLinks = [] magnetLinks = []
torrentPage = requests.get("{}/{}".format(tpb, torrent), verify=False) torrentPage = requests.get(torrentURL, verify=False)
torrentPageSoup = bs4.BeautifulSoup(torrentPage.content) torrentPageSoup = bs4.BeautifulSoup(torrentPage.content)
for link in torrentPageSoup.find_all('a'): for link in torrentPageSoup.find_all('a'):
@ -178,7 +183,7 @@ def downloadTorrent(torrent):
magnetLink = magnetLinks[0] 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) transmissionrpc.Client(rpcserver).add_torrent(magnetLink)

@ -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). 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 $ 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) #### 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 $ 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). 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).

Loading…
Cancel
Save