From 886bd2c4c8c99402c3b8c031129bf67fcdec225e Mon Sep 17 00:00:00 2001 From: lance allen Date: Sun, 16 Oct 2016 17:46:06 -0700 Subject: [PATCH] adding some additional setup files and updating readme --- cron.txt | 2 ++ readme.md | 54 ++++++++++++++++++++++++++++++++++++------------ requirements.txt | 4 ++++ thepirate.py | 30 +++++++++++++-------------- 4 files changed, 62 insertions(+), 28 deletions(-) create mode 100644 cron.txt create mode 100644 requirements.txt diff --git a/cron.txt b/cron.txt new file mode 100644 index 0000000..64b9d96 --- /dev/null +++ b/cron.txt @@ -0,0 +1,2 @@ +# +*/5 * * * * /opt/thepirate/thepirate-satellite.py diff --git a/readme.md b/readme.md index 0ac8683..7a910de 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,12 @@ # The Pirate -#####Command line torrent downloader with [Pushbullet](https://pushbullet.com) notifications. +#####Command line torrent downloader with [Pushbullet](https://pushbullet.com) notifications. -Add torrents to your Transmission download queue from anywhere, either via Pushbullet magnet link push or [remote procedure calls](https://trac.transmissionbt.com/wiki/rpc) direct to the machine. +Add torrents to your Transmission download queue from anywhere, either via Pushbullet magnet link push or [remote procedure calls](https://trac.transmissionbt.com/wiki/rpc) direct to the machine. - -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.org) 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 HTML pages of the desired torrent with --url, and direct magnet links and torrent files with --file. @@ -21,7 +21,7 @@ This script was written in Python version 2.7. Version 3 compatibility requires * Client setup * Server setup -#### Client Side (thepirate) +## Client Side 3 external Python libraries needed. Please ensure the following are installed to the system @@ -32,41 +32,69 @@ This script was written in Python version 2.7. Version 3 compatibility requires > TIP: If pip is installed, just run the following as root: ``` -$ pip install transmissionrpc requests beautifulsoup4 +$ pip install -r requirements.txt ``` Then edit the thepirate.py file, and change the __rpcserver__ variable to the server's IP/hostname (if not localhost) +``` +$ vim thepirate.py +# edit line 30, rpcserver variable +``` + -#### Server Side (transmission-daemon and thepirate-satellite.py) +## Server Side -Transmission-daemon needs to be installed for downloading torrents and TCP/9091 needs to be opened on the computer's firewall +### Transmission + +Transmission-daemon needs to be installed for downloading torrents. RHEL/CentOS/Fedora (yum) ``` -$ yum install transmission-daemon transmission-cli -$ firewall-cmd --add-port=9091/tcp --permanent +$ yum install transmission-daemon transmission-cli ``` Debian/Ubuntu (apt) ``` $ apt-get install transmission-daemon transmission-cli +``` + +Make sure the server running Transmission (if not localhost) is accepting traffic on port 9091/tcp and RPC is enabled in the Transmission settings.json file. Set your whitelist to your LAN subnet. Read about configuring Transmission [here](https://trac.transmissionbt.com/wiki/EditConfigFiles). + +![img](img/transmissionrpc_config.png) + +### Firewall + +Open up the Transmission port if the server is not localhost. + +Firewalld +``` +$ firewall-cmd --add-port=9091/tcp --permanent +``` + +IPTables +``` $ iptables -A INPUT -p tcp --dport 9091 -j ACCEPT ``` +### thepirate-satellite + [pushbullet.py](https://github.com/randomchars/pushbullet.py) is needed for Pushbullet notifications. You also need transmissionrpc on the server side so it can clear completed torrents. ``` -$ pip install pushbullet.py transmissionrpc +$ pip install -r requirements.txt ``` -Put your PushBullet API key in api variable in the script and set a cron job to run thepirate-satellite.py every X minutes. +Put your PushBullet API key in the api variable in the script and set a cron job to run thepirate-satellite.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. Set your whitelist to your LAN subnet. Read about configuring Transmission [here](https://trac.transmissionbt.com/wiki/EditConfigFiles). +``` +$ vim thepirate-satellite.py +# edit line 26, variable api +$ crontab cron.txt +``` -![img](img/transmissionrpc_config.png) ### Usage diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8c789ba --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +beautifulsoup4==4.4.1 +requests==2.10.0 +transmissionrpc==0.11 +pushbullet.py==0.10.0 diff --git a/thepirate.py b/thepirate.py index f5d3e46..6c4db58 100755 --- a/thepirate.py +++ b/thepirate.py @@ -25,17 +25,17 @@ import transmissionrpc ################################################## # Variables +# Torrent server IP; can be any machine running transmission-daemon +# with a firewall inbound allowed to TCP/9091 (transmissionrpc) +rpcserver = [] + # Dictionaries/Arrays for storing search results tpb_search_results = {} tpb_torrent_links = [] user_torrent_selection = "" # Current/working PirateBay URL -tpb = "https://thepiratebay.se" - -# Torrent server IP; can be any machine running transmission-daemon -# with a firewall inbound allowed to TCP/9091 (transmissionrpc) -rpcserver = [] +tpb = "https://thepiratebay.org" # Squelch HTTPS insecure warnings requests.packages.urllib3.disable_warnings() @@ -76,7 +76,7 @@ def Check_Transmission_Listener(): print "[!] Transmission-daemon not listening on {}!".format(rpcserver[0]) exit(2) -#2 +#2 def Get_Search_URL(): """ Takes input string to search for on TPB. @@ -102,7 +102,7 @@ def Get_Search_URL(): tpb_torrent_page_source = requests.get(tpb_search_url, verify=False).text #Use requests lib to fetch page source for bs4 parsing Get_Torrent_Links(tpb_torrent_page_source) #Run Get_Torrent_Links function, passing page source for BS4 parsing - + #3 def Get_Torrent_Links(source): """ @@ -118,7 +118,7 @@ def Get_Torrent_Links(source): for link in tpb_torrent_page_soup.find_all('a'): #Find all anchor elements in page source if link.get('href').startswith('/torrent'): #Only get links with /torrent as they're valid torrent pages tpb_torrent_links.append(link.get('href')) #Set the results to tpb_torrent_links array - + #If -t is supplied, bypass this section of code and go on to download the top torrent if args.arg_take_top and tpb_torrent_links: Download_Torrent_From_URL("{}/{}".format(tpb, tpb_torrent_links[0])) @@ -138,7 +138,7 @@ def Get_Torrent_Links(source): args.arg_search_string = '' Get_Search_URL() #Loop back to script start -#4 +#4 def Get_User_Selection(): """ Asks for selection of torrent @@ -158,20 +158,20 @@ def Get_User_Selection(): #Exit script elif selection == 99: print "\nBye.\n" - exit() + exit() #If valid number, move to next function to add to queue - elif selection in tpb_search_results: + elif selection in tpb_search_results: user_torrent_selection = tpb_search_results[selection] #Updates variable based on key provided above, matches it with tpb_search_results dict Download_Torrent_From_URL("{}/{}".format(tpb, user_torrent_selection)) #If anything other than 98, 99, or valid key number entered, loop back to selection input - else: + else: print "\nNot a valid number" Get_User_Selection() #If number isn't used, loop back to selection input except ValueError: print "\nThat is not a digit." Get_User_Selection() - + #5 def Download_Torrent_From_URL(tpb_torrent_url): """ @@ -189,7 +189,7 @@ def Download_Torrent_From_URL(tpb_torrent_url): print "\n[+] Adding magnet link for torrent:\n\n{}".format(tpb_torrent_url) transmissionrpc.Client(rpcserver[0]).add_torrent(tpb_magnet_link) print "\n[.] Done!\n" - exit(0) - + exit(0) + if __name__ == "__main__": Check_Transmission_Listener()