2008-05-04 15:05:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-06-19 09:47:02 +00:00
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2008-05-05 11:09:29 +00:00
|
|
|
from datetime import datetime
|
2008-05-04 15:05:41 +00:00
|
|
|
import re
|
|
|
|
import socket
|
|
|
|
from urllib import quote
|
|
|
|
|
2009-10-12 15:18:59 +00:00
|
|
|
from oxlib.cache import readUrl, readUrlUnicode
|
|
|
|
from oxlib import findRe, cache, stripTags, decodeHtml, getTorrentInfo, intValue, normalizeNewlines
|
|
|
|
from oxlib.normalize import normalizeImdbId
|
|
|
|
import oxlib
|
2008-05-04 15:05:41 +00:00
|
|
|
|
2008-05-05 11:09:29 +00:00
|
|
|
from torrent import Torrent
|
2008-05-04 15:05:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _parseResultsPage(data, max_results=10):
|
2008-06-19 09:47:02 +00:00
|
|
|
results=[]
|
|
|
|
regexp = '''<tr><td>(.*?)</td><td>(.*?)<a href="/tor/(.*?)">(.*?)</a>.*?</td>.*?</tr>'''
|
|
|
|
for row in re.compile(regexp, re.DOTALL).findall(data):
|
|
|
|
torrentDate = row[0]
|
|
|
|
torrentExtra = row[1]
|
|
|
|
torrentId = row[2]
|
|
|
|
torrentTitle = decodeHtml(row[3]).strip()
|
|
|
|
torrentLink = "http://www.mininova.org/tor/" + torrentId
|
|
|
|
privateTracker = 'priv.gif' in torrentExtra
|
|
|
|
if not privateTracker:
|
|
|
|
results.append((torrentTitle, torrentLink, ''))
|
|
|
|
return results
|
2008-05-04 15:05:41 +00:00
|
|
|
|
|
|
|
def findMovie(query, max_results=10):
|
2008-06-19 09:47:02 +00:00
|
|
|
'''search for torrents on mininova
|
|
|
|
'''
|
|
|
|
url = "http://www.mininova.org/search/%s/seeds" % quote(query)
|
2009-10-12 11:47:43 +00:00
|
|
|
data = readUrlUnicode(url)
|
2008-06-19 09:47:02 +00:00
|
|
|
return _parseResultsPage(data, max_results)
|
2008-05-04 15:05:41 +00:00
|
|
|
|
|
|
|
def findMovieByImdb(imdbId):
|
2008-06-19 09:47:02 +00:00
|
|
|
'''find torrents on mininova for a given imdb id
|
|
|
|
'''
|
|
|
|
results = []
|
|
|
|
imdbId = normalizeImdbId(imdbId)
|
2009-10-12 11:47:43 +00:00
|
|
|
data = readUrlUnicode("http://www.mininova.org/imdb/?imdb=%s" % imdbId)
|
2008-06-19 09:47:02 +00:00
|
|
|
return _parseResultsPage(data)
|
2008-05-04 15:05:41 +00:00
|
|
|
|
|
|
|
def getId(mininovaId):
|
2008-06-19 09:47:02 +00:00
|
|
|
mininovaId = unicode(mininovaId)
|
|
|
|
d = findRe(mininovaId, "/(\d+)")
|
|
|
|
if d:
|
|
|
|
return d
|
|
|
|
mininovaId = mininovaId.split('/')
|
|
|
|
if len(mininovaId) == 1:
|
|
|
|
return mininovaId[0]
|
|
|
|
else:
|
|
|
|
return mininovaId[-1]
|
2008-05-04 15:05:41 +00:00
|
|
|
|
2008-05-25 10:04:13 +00:00
|
|
|
def exists(mininovaId):
|
2008-06-19 09:47:02 +00:00
|
|
|
mininovaId = getId(mininovaId)
|
2009-10-12 15:18:59 +00:00
|
|
|
data = oxlib.net.readUrl("http://www.mininova.org/tor/%s" % mininovaId)
|
2008-06-19 09:47:02 +00:00
|
|
|
if not data or 'Torrent not found...' in data:
|
|
|
|
return False
|
|
|
|
if 'tracker</a> of this torrent requires registration.' in data:
|
|
|
|
return False
|
|
|
|
return True
|
2008-05-25 10:04:13 +00:00
|
|
|
|
2008-05-04 15:05:41 +00:00
|
|
|
def getData(mininovaId):
|
2008-06-19 09:47:02 +00:00
|
|
|
_key_map = {
|
|
|
|
'by': u'uploader',
|
|
|
|
}
|
|
|
|
mininovaId = getId(mininovaId)
|
|
|
|
torrent = dict()
|
|
|
|
torrent[u'id'] = mininovaId
|
|
|
|
torrent[u'domain'] = 'mininova.org'
|
|
|
|
torrent[u'comment_link'] = "http://www.mininova.org/tor/%s" % mininovaId
|
|
|
|
torrent[u'torrent_link'] = "http://www.mininova.org/get/%s" % mininovaId
|
|
|
|
torrent[u'details_link'] = "http://www.mininova.org/det/%s" % mininovaId
|
2008-05-04 15:05:41 +00:00
|
|
|
|
2009-10-12 11:47:43 +00:00
|
|
|
data = readUrlUnicode(torrent['comment_link']) + readUrlUnicode(torrent['details_link'])
|
2008-06-19 09:47:02 +00:00
|
|
|
if '<h1>Torrent not found...</h1>' in data:
|
|
|
|
return None
|
2008-05-04 15:05:41 +00:00
|
|
|
|
2008-06-19 09:47:02 +00:00
|
|
|
for d in re.compile('<p>.<strong>(.*?):</strong>(.*?)</p>', re.DOTALL).findall(data):
|
|
|
|
key = d[0].lower().strip()
|
|
|
|
key = _key_map.get(key, key)
|
|
|
|
value = decodeHtml(stripTags(d[1].strip()))
|
|
|
|
torrent[key] = value
|
2008-05-04 15:05:41 +00:00
|
|
|
|
2008-06-19 09:47:02 +00:00
|
|
|
torrent[u'title'] = findRe(data, '<title>(.*?):.*?</title>')
|
|
|
|
torrent[u'imdbId'] = findRe(data, 'title/tt(\d{7})')
|
|
|
|
torrent[u'description'] = findRe(data, '<div id="description">(.*?)</div>')
|
|
|
|
if torrent['description']:
|
|
|
|
torrent['description'] = normalizeNewlines(decodeHtml(stripTags(torrent['description']))).strip()
|
2009-10-12 11:47:43 +00:00
|
|
|
t = readUrl(torrent[u'torrent_link'])
|
2008-06-19 09:47:02 +00:00
|
|
|
torrent[u'torrent_info'] = getTorrentInfo(t)
|
|
|
|
return torrent
|
2008-05-04 15:05:41 +00:00
|
|
|
|
2008-05-05 11:09:29 +00:00
|
|
|
class Mininova(Torrent):
|
2008-06-19 09:47:02 +00:00
|
|
|
'''
|
|
|
|
>>> Mininova('123')
|
|
|
|
{}
|
|
|
|
>>> Mininova('1072195')['infohash']
|
|
|
|
'72dfa59d2338e4a48c78cec9de25964cddb64104'
|
|
|
|
'''
|
|
|
|
def __init__(self, mininovaId):
|
|
|
|
self.data = getData(mininovaId)
|
|
|
|
if not self.data:
|
|
|
|
return
|
|
|
|
Torrent.__init__(self)
|
|
|
|
ratio = self.data['share ratio'].split(',')
|
|
|
|
self['seeder'] = -1
|
|
|
|
self['leecher'] = -1
|
|
|
|
if len(ratio) == 2:
|
|
|
|
val = intValue(ratio[0].replace(',','').strip())
|
|
|
|
if val:
|
|
|
|
self['seeder'] = int(val)
|
|
|
|
val = intValue(ratio[1].replace(',','').strip())
|
|
|
|
if val:
|
|
|
|
self['leecher'] = int(val)
|
|
|
|
val = intValue(self.data['downloads'].replace(',','').strip())
|
|
|
|
if val:
|
|
|
|
self['downloaded'] = int(val)
|
|
|
|
else:
|
|
|
|
self['downloaded'] = -1
|
|
|
|
published = self.data['added on']
|
|
|
|
published = published.split(' +')[0]
|
|
|
|
self['published'] = datetime.strptime(published, "%a, %d %b %Y %H:%M:%S")
|
2008-05-05 11:09:29 +00:00
|
|
|
|