Private GIT

Skip to content
Snippets Groups Projects
Commit f20a9d2d authored by Adelscott's avatar Adelscott
Browse files

Merge pull request #1 from sarakha63/development

MAJ 
parents 82ec4162 666177ee
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python
from pynma import PyNMA
from .pynma import PyNMA
#!/usr/bin/python
from xml.dom.minidom import parseString
try:
from http.client import HTTPSConnection
except ImportError:
from httplib import HTTPSConnection
try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode
__version__ = "0.1"
__version__ = "1.0"
API_SERVER = 'nma.usk.bz'
API_SERVER = 'www.notifymyandroid.com'
ADD_PATH = '/publicapi/notify'
USER_AGENT="PyNMA/v%s"%__version__
......@@ -18,7 +26,7 @@ def uniq_preserve(seq): # Dave Kirby
def uniq(seq):
# Not order preserving
return {}.fromkeys(seq).keys()
return list({}.fromkeys(seq).keys())
class PyNMA(object):
"""PyNMA(apikey=[], developerkey=None)
......@@ -60,16 +68,17 @@ class PyNMA(object):
if type(developerkey) == str and len(developerkey) == 48:
self._developerkey = developerkey
def push(self, application="", event="", description="", url="", priority=0, batch_mode=False):
def push(self, application="", event="", description="", url="", contenttype=None, priority=0, batch_mode=False, html=False):
"""Pushes a message on the registered API keys.
takes 5 arguments:
- (req) application: application name [256]
- (req) event: event name [1000]
- (req) description: description [10000]
- (opt) url: url [512]
- (opt) contenttype: Content Type (act: None (plain text) or text/html)
- (opt) priority: from -2 (lowest) to 2 (highest) (def:0)
- (opt) batch_mode: call API 5 by 5 (def:False)
- (opt) batch_mode: push to all keys at once (def:False)
- (opt) html: shortcut for contenttype=text/html
Warning: using batch_mode will return error only if all API keys are bad
cf: http://nma.usk.bz/api.php
"""
......@@ -83,6 +92,9 @@ class PyNMA(object):
if url:
datas['url'] = url[:512]
if contenttype == "text/html" or html == True: # Currently only accepted content type
datas['content-type'] = "text/html"
if self._developerkey:
datas['developerkey'] = self._developerkey
......@@ -94,8 +106,7 @@ class PyNMA(object):
res = self.callapi('POST', ADD_PATH, datas)
results[key] = res
else:
for i in range(0, len(self._apikey), 5):
datas['apikey'] = ",".join(self._apikey[i:i+5])
datas['apikey'] = ",".join(self._apikey)
res = self.callapi('POST', ADD_PATH, datas)
results[datas['apikey']] = res
return results
......@@ -110,7 +121,7 @@ class PyNMA(object):
try:
res = self._parse_reponse(resp.read())
except Exception, e:
except Exception as e:
res = {'type': "pynmaerror",
'code': 600,
'message': str(e)
......@@ -124,12 +135,12 @@ class PyNMA(object):
for elem in root.childNodes:
if elem.nodeType == elem.TEXT_NODE: continue
if elem.tagName == 'success':
res = dict(elem.attributes.items())
res = dict(list(elem.attributes.items()))
res['message'] = ""
res['type'] = elem.tagName
return res
if elem.tagName == 'error':
res = dict(elem.attributes.items())
res = dict(list(elem.attributes.items()))
res['message'] = elem.firstChild.nodeValue
res['type'] = elem.tagName
return res
......
......@@ -57,15 +57,15 @@ class LIBERTALIAProvider(generic.TorrentProvider):
if audio_lang == "en" and french==None:
results.append( urllib.urlencode( {
'name': searchString
} ) + "*VO*&cat%5B%5D="+cat+"&[PARAMSTR]=" + searchString +" VO" )
} ) + "*VO*&cat%5B%5D="+cat+"&[PARAMSTR]=" + searchString )
elif audio_lang == "en" and french==None:
results.append( urllib.urlencode( {
'name': searchString
} ) + "*VO*&cat%5B%5D="+cat+"&[PARAMSTR]=" + searchString +" VO" )
} ) + "*VO*&cat%5B%5D="+cat+"&[PARAMSTR]=" + searchString )
elif audio_lang == "fr" or french:
results.append( urllib.urlencode( {
'name': searchString
} ) + "*FRENCH*&cat%5B%5D="+cat+"&[PARAMSTR]=" + searchString +" FRENCH")
} ) + "*FRENCH*&cat%5B%5D="+cat+"&[PARAMSTR]=" + searchString )
else:
results.append( urllib.urlencode( {
'name': searchString
......
......@@ -37,6 +37,7 @@ class XTHORProvider(generic.TorrentProvider):
self.supportsBacklog = True
self.cj = cookielib.CookieJar()
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
......@@ -51,18 +52,13 @@ class XTHORProvider(generic.TorrentProvider):
def getSearchParams(self, searchString, audio_lang, french=None, fullSeason=False):
results = []
if audio_lang == "en" and french==None:
results.append( urllib.urlencode( {
'keywords': searchString ,
} ) + "&cid=43,69&[PARAMSTR]=" + searchString )
results.append("c16=1&c17=1&searchin=title&search=" + searchString )
elif audio_lang == "fr" or french:
results.append( urllib.urlencode( {
'keywords': searchString
} ) + "&cid=42,41&[PARAMSTR]=" + searchString)
results.append("c14=1&c15=1&searchin=title&search=" + searchString)
else:
results.append( urllib.urlencode( {
'keywords': searchString
} ) + "&cid=42,43,41,69&[PARAMSTR]=" + searchString)
results.append("c14=1&c15=1&c16=1&c17=1&searchin=title&search=" + searchString)
#Désactivé car on ne peut pas savoir la langue
#if fullSeason:
# results.append( urllib.urlencode( {
......@@ -116,12 +112,12 @@ class XTHORProvider(generic.TorrentProvider):
self.opener.addheaders = [('User-agent', random.choice(listeUserAgents))]
data = urllib.urlencode({'action':'login','loginbox_membername': login, 'loginbox_password' : password, 'loginbox_remember' : 'true'})
data = urllib.urlencode({'action':'takelogin.php','username': login, 'password' : password, 'submitme' : 'X'})
r = self.opener.open(self.url + '/ajax/login.php',data)
r = self.opener.open(self.url + '/takelogin.php',data)
for index, cookie in enumerate(self.cj):
if (cookie.name == "tsue_member"): self.login_done = True
if (cookie.name == "uid"): self.login_done = True
if not self.login_done and not self.failed_login_logged:
logger.log(u"Unable to login to XTHOR. Please check username and password.", logger.WARNING)
......@@ -139,7 +135,7 @@ class XTHORProvider(generic.TorrentProvider):
results = []
searchUrl = self.url + '?p=torrents&pid=10&search_type=name&' + searchString.replace('!','')
searchUrl = self.url + '/browse.php?' + searchString.replace('!','')
logger.log(u"Search string: " + searchUrl, logger.DEBUG)
......@@ -147,23 +143,25 @@ class XTHORProvider(generic.TorrentProvider):
soup = BeautifulSoup( r)
resultsTable = soup.find("table", { "id" : "torrents_table_classic" })
resultsTable = soup.find("table", { "class" : "table2" })
if resultsTable:
rows = resultsTable.findAll("tr")
for row in rows:
link = row.find("a",href=re.compile("action=details"))
link = row.find("a",href=re.compile("details.php"))
if link:
title = link.text
recherched=searchUrl.split("&[PARAMSTR]=")[1]
recherched=searchUrl.split("&search=")[1]
recherched=recherched.replace(" ","(.*)")
recherched= recherched + "(.*)"
logger.log(u"XTHOR TITLE : " + title, logger.DEBUG)
logger.log(u"XTHOR CHECK MATCH : " + recherched, logger.DEBUG)
if re.match(recherched,title , re.IGNORECASE):
downloadURL = row.find("a",href=re.compile("action=download"))['href']
downloadURL = row.find("a",href=re.compile("download.php"))['href']
downloadURL = self.url + '/'+ downloadURL
logger.log(u"XTHOR DOWNLOAD URL : " + downloadURL, logger.DEBUG)
else:
continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment