From bd56539103121863b811ed43c6afd5fd574547be Mon Sep 17 00:00:00 2001 From: Ruud Date: Mon, 24 Jun 2013 22:31:50 +0200 Subject: [PATCH] Yifi cleanup --- .../core/providers/torrent/yify/__init__.py | 2 +- .../core/providers/torrent/yify/main.py | 38 +++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/couchpotato/core/providers/torrent/yify/__init__.py b/couchpotato/core/providers/torrent/yify/__init__.py index d5080ae0..f7477519 100644 --- a/couchpotato/core/providers/torrent/yify/__init__.py +++ b/couchpotato/core/providers/torrent/yify/__init__.py @@ -11,7 +11,7 @@ config = [{ 'subtab': 'providers', 'list': 'torrent_providers', 'name': 'Yify', - 'description': 'Small HD movies, encoded by Yify.', + 'description': 'Free provider, less accurate. Small HD movies, encoded by Yify.', 'wizard': False, 'options': [ { diff --git a/couchpotato/core/providers/torrent/yify/main.py b/couchpotato/core/providers/torrent/yify/main.py index 5c741a5b..1b8b584b 100644 --- a/couchpotato/core/providers/torrent/yify/main.py +++ b/couchpotato/core/providers/torrent/yify/main.py @@ -1,18 +1,14 @@ from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode -from couchpotato.core.helpers.variable import tryInt, cleanHost +from couchpotato.core.helpers.variable import tryInt from couchpotato.core.logger import CPLog from couchpotato.core.providers.torrent.base import TorrentProvider -from couchpotato.environment import Env -import re -import time import traceback -from pprint import pprint log = CPLog(__name__) class Yify(TorrentProvider): - + urls = { 'test' : 'https://yify-torrents.com/api', 'search' : 'https://yify-torrents.com/api/list.json?keywords=%s&quality=%s', @@ -21,19 +17,31 @@ class Yify(TorrentProvider): http_time_between_calls = 1 #seconds - def _search(self, movie, quality, results): - try: - data = self.getJsonData(self.urls['search'] % (movie['library']['title'], quality['identifier'])) - except: - log.error('Search on Yify (%s) failed (could not decode JSON)', params) - return + def search(self, movie, quality): + + if not quality.get('hd', False): + return [] + + return super(Yify, self).search(movie, quality) + + def _searchOnTitle(self, title, movie, quality, results): + + data = self.getJsonData(self.urls['search'] % (title, quality['identifier'])) if data: try: - for result in data: + for result in data.get('MovieList'): + + try: + title = result['TorrentUrl'].split('/')[-1][:-8].replace('_', '.').strip('._') + title = title.replace('.-.', '-') + title = title.replace('..', '.') + except: + continue + results.append({ 'id': result['MovieID'], - 'name': result['MovieTitle'], + 'name': title, 'url': result['TorrentUrl'], 'detail_url': self.urls['detail'] % result['MovieID'], 'size': self.parseSize(result['Size']), @@ -43,4 +51,4 @@ class Yify(TorrentProvider): except: log.error('Failed getting results from %s: %s', (self.getName(), traceback.format_exc())) - +