Skip to content

Commit

Permalink
Clean up torrent411 plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gazpachoking committed Sep 3, 2013
1 parent 18c881e commit d2c311d
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions flexget/plugins/urlrewrite_torrent411.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
# coding: utf-8
import urllib2
from __future__ import unicode_literals, division, absolute_import
import re
import logging
from plugin_urlrewriting import UrlRewritingError
from flexget.plugin import *

from flexget.plugins.plugin_urlrewriting import UrlRewritingError
from flexget.plugin import internet, register_plugin
from flexget.utils.tools import urlopener
from flexget.utils.soup import get_soup

log = logging.getLogger('torrent411')


class UrlRewriteTorrent411(object):
"""torrent411 RSS url_rewrite"""

def url_rewritable(self, feed, entry):
url = entry['url']
# match si ce qui suit 'http://www.t411.me/torrents/' ne contient pas
# '/' comme 'http://www.t411.me/torrents/browse/...' ou
# match si ce qui suit 'http://www.t411.me/torrents/' ne contient pas
# '/' comme 'http://www.t411.me/torrents/browse/...' ou
# 'http://www.t411.me/torrents/download/...'
if re.match(r'^http://www\.t411\.me/torrents/[^/]+(?!/)[^/]+$', url):
return True
return False

def url_rewrite(self, feed, entry):
old_url = entry['url']
entry['url'] = self.parse_download_page(entry['url'], entry['title'], feed)
log.debug('%s rewrited to %s' % (old_url, entry['url']))
entry['url'] = self.parse_download_page(entry['url'])
log.debug('%s rewritten to %s' % (old_url, entry['url']))

@internet(log)
def parse_download_page(self, url, title, feed):
def parse_download_page(self, url):
page = urlopener(url, log)
log.debug('%s opened', url)
try:
soup = get_soup(page)
torrent_url = 'http://www.t411.me'+soup.find(text=u'Télécharger').findParent().get('href')
torrent_url = 'http://www.t411.me' + soup.find(text='Télécharger').findParent().get('href')
except Exception, e:
raise UrlRewritingError(e)

Expand All @@ -41,4 +43,4 @@ def parse_download_page(self, url, title, feed):

return torrent_url

register_plugin(UrlRewriteTorrent411, 'torrent411', groups=['urlrewriter'])
register_plugin(UrlRewriteTorrent411, 'torrent411', groups=['urlrewriter'])

0 comments on commit d2c311d

Please sign in to comment.