From 297c4a2785339eb0fef9750348f78ccd6a4b3e95 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Fri, 23 Jun 2017 23:13:58 +0100 Subject: [PATCH] Add MagnetDL torrent provider. DRY refactor download_file with getURL. --- CHANGES.md | 1 + gui/slick/images/providers/magnetdl.png | Bin 0 -> 969 bytes sickbeard/helpers.py | 186 ++++++++++-------------- sickbeard/providers/__init__.py | 5 +- sickbeard/providers/magnetdl.py | 103 +++++++++++++ 5 files changed, 183 insertions(+), 112 deletions(-) create mode 100644 gui/slick/images/providers/magnetdl.png create mode 100644 sickbeard/providers/magnetdl.py diff --git a/CHANGES.md b/CHANGES.md index ea9022e2..10bdfe15 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -50,6 +50,7 @@ * Add option to limit WebDL propers to original release group under Config/Search/Media Search * Change add IPv4 config option when enabling IPv6. * Add autoProcessTV/onTxComplete.bat to improve Windows clients Deluge, qBittorrent, Tranmission, and uTorrent +* Add MagnetDL torrent provider * Add Skytorrents torrent provider * Change do not have shows checked by default on import page. To re-enable import shows checked by default, 1) On config page 'Save' 2) Stop SG 3) Find 'import_default_checked_shows' in config.ini and set '1' 4) Start SG diff --git a/gui/slick/images/providers/magnetdl.png b/gui/slick/images/providers/magnetdl.png new file mode 100644 index 0000000000000000000000000000000000000000..3040b1adb30faff52a2d4ceaa74fedc510850ce7 GIT binary patch literal 969 zcmV;)12+7LP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!T{D2PPF+v2h;^Rj6+H|Ct1`!JUU8xZK9 zTWL$NGzJx|NdF276-p@-N}=Uuxx>q4-9BuPoV86uOgPDt=Opj>ojiHT$1>{PCA=wS zSovq?#+l@JS{NNd^CR|Cv4Br2&Y!WViwes0+WH`OoB&wwwuD%l8h(_erYuT6-G-VS z9(Wbt0d|)MG&>#M-vdv%t5N31LDebYyydOtmIGepMhTfTcia@m9K=h%P0;Q0gqG)p z`u!WA4t35(mv0JjzOBV`?mEa44`b$o<(>=vZ+<#Nmc(Cd+Pe*%5#Fea^TgXY4$SEx z7&sq;{&UeVrv;;t&p~~>C%PP&#@#-s$xOzQoo0~cf?U;8o;S=#e4tD4L5m;&ec4fX z$@4{}*BVrLuLT?Khk=W+&?oJLAz>?e9N8zKUg)ltXvpJCfxRt-i}rL5x=!rEcxD_P zZQYFfz8t88sZ=Et&i%f93u=9RFqILD_LKfFp4yIO-1!t+Br&>}8mT_5z3*x!EcejUq&?aN4vTn@tc1sz zAdEGz3OBbblTxba6b8cn9Ut~@La}%~3d#(}1&`ABbSCFGY&nUT%}ImibR<4BYgZH) zAJ-@vPe)+l&Pj}Ze-u;SCZjy-C?%r1x2Zw%0xjw%=w#Ip{qzG&ZH5&E%`aXl@_)Gv zXSUUm)z{S`@7Ft&. + +import re +import traceback + +from . import generic +from sickbeard import logger +from sickbeard.bs4_parser import BS4Parser +from sickbeard.helpers import tryInt +from lib.unidecode import unidecode + + +class MagnetDLProvider(generic.TorrentProvider): + + def __init__(self): + + generic.TorrentProvider.__init__(self, 'MagnetDL', cache_update_freq=6) + + self.url_base = 'http://www.magnetdl.com/' + + self.urls = {'config_provider_home_uri': self.url_base, + 'browse': self.url_base + 'download/tv/', 'search': self.url_base + 'search/?m=1&q=%s'} + + self.minseed, self.minleech = 2 * [None] + + def _search_provider(self, search_params, **kwargs): + + results = [] + + items = {'Cache': [], 'Season': [], 'Episode': [], 'Propers': []} + + rc = dict((k, re.compile('(?i)' + v)) for (k, v) in {'info': '^/file/', 'get': '^magnet:'}.items()) + + for mode in search_params.keys(): + for search_string in search_params[mode]: + search_url = self.urls['browse'] + if 'Cache' != mode: + search_string = isinstance(search_string, unicode) and unidecode(search_string) or search_string + search_url = self.urls['search'] % re.sub('[.\s]+', ' ', search_string) + + html = self.get_url(search_url) + + cnt = len(items[mode]) + try: + if not html or self._has_no_results(html): + raise generic.HaltParseException + + with BS4Parser(html, features=['html5lib', 'permissive']) as soup: + torrent_table = soup.find('table', attrs={'class': 'download'}) + torrent_rows = [] if not torrent_table else torrent_table.find_all('tr') + + if 2 > len(torrent_rows): + raise generic.HaltParseException + + head = None + for tr in torrent_rows[1:]: + cells = tr.find_all('td') + if 5 > len(cells): + continue + try: + head = head if None is not head else self._header_row(tr) + seeders, leechers, size = [tryInt(n, n) for n in [ + cells[head[x]].get_text().strip() for x in 'seed', 'leech', 'size']] + if self._peers_fail(mode, seeders, leechers): + continue + + info = tr.find('a', href=rc['info']) + title = (info.attrs.get('title') or info.get_text()).strip() + download_url = self._link(tr.find('a', href=rc['get'])['href']) + except (AttributeError, TypeError, ValueError, KeyError): + continue + + if title and download_url: + items[mode].append((title, download_url, seeders, self._bytesizer(size))) + + except generic.HaltParseException: + pass + except (StandardError, Exception): + logger.log(u'Failed to parse. Traceback: %s' % traceback.format_exc(), logger.ERROR) + + self._log_search(mode, len(items[mode]) - cnt, search_url) + + results = self._sort_seeding(mode, results + items[mode]) + + return results + + +provider = MagnetDLProvider()