Skip to content

Instantly share code, notes, and snippets.

@teopost
Last active April 10, 2017 20:03
Show Gist options
  • Save teopost/ceabe188f8d108102e1233bd95bd036f to your computer and use it in GitHub Desktop.
Save teopost/ceabe188f8d108102e1233bd95bd036f to your computer and use it in GitHub Desktop.
Corsaro Nero command line search tool
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'teopost'
import argparse
import mechanize
import re
import urllib
from lxml import html
import httplib2
from sys import argv, exit
from json import dumps
from config import *
browser = mechanize.Browser()
def quote_argument(argument):
return '%s' % (
argument
.replace('\\', '\\\\')
.replace('"', '\\"')
.replace('?', '\\?')
.replace('!', '\\!')
.replace('#', '\\#')
.replace('$', '\\$')
.replace('&', '\\&')
.replace('|', '\\|')
.replace('`', '\\`')
)
def download(magnet_link):
# Replace hostname, transmission-username and transmission-password
url = transmission_url
username = transmission_usename
password = transmission_password
h = httplib2.Http(".cache")
h.add_credentials(username, password)
resp, content = h.request(url, "GET")
headers = { "X-Transmission-Session-Id": resp['x-transmission-session-id'] }
body = dumps( { "method": "torrent-add",
"arguments": { "filename": magnet_link } } )
response, content = h.request(url, 'POST', headers=headers, body=body)
if str(content).find("success") == -1:
print("Magnet Link: " + magnet_link)
print("Answer: " + content)
print("No 'success' here!")
print("Press Enter to Exit.")
input()
def get_magnet_link(url):
# browser = mechanize.Browser()
page=browser.open(url)
text = page.read()
tree = html.fromstring(text)
return tree.xpath('//*[@id="dlform"]/a/@href')[0]
def go(search_string):
url="http://ilcorsaronero.info/argh.php?search=" + urllib.pathname2url(search_string)
# browser = mechanize.Browser()
page=browser.open(url)
text = page.read()
tree = html.fromstring(text)
print '==========================='
for rows in tree.xpath('//table/tr')[3:]:
if rows.xpath('td[1]/a/text()'):
if rows.xpath('td[1]/a/text()')[0].strip() != 'Screener':
col1=rows.xpath('td[1]/a/text()')[0]
col2=rows.xpath('td[2]/a/text()')[0]
col3=rows.xpath('td[3]/font/text()')[0]
col4=rows.xpath('td[4]/form/a/@href')[0]
col5=rows.xpath('td[5]/font/text()')[0]
col6=rows.xpath('td[6]/font/text()')[0]
col7=rows.xpath('td[7]/font/text()')[0]
col8=get_magnet_link(col4)
#col8=''
print 'Name: ' + col1 + ' - ' + col2
print 'Size: ' + col3
print 'Page: ' + col4
print 'Date: ' + col5
print 'Seed: ' + col6 + ', ' + 'Leech: ' + col7
print 'Magn: ' + col8
print "----"
print 'Magn quoted:' + quote_argument(col8)
print '----------------------------'
#download(col8)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--search_string", help="Movie to search")
parser.add_argument("-d", "--download", help="Magnet link")
parser.add_argument("-t", "--type", help="Movie type (es: [m]ovie, [s]eries)")
args = parser.parse_args()
if args.download:
download(args.download)
if args.search_string:
go(args.search_string)
if __name__ == '__main__':
main()
transmission_url = 'http://sample.com:9091/transmission/rpc'
transmission_usename = 'user'
transmission_password = 'password'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment