|
14 | 14 | # along with Headphones. If not, see <http://www.gnu.org/licenses/>.
|
15 | 15 |
|
16 | 16 | # NZBGet support added by CurlyMo <curlymoo1@gmail.com> as a part of XBian - XBMC on the Raspberry Pi
|
| 17 | +# t411 support added by a1ex, @likeitneverwentaway on github for maintenance |
17 | 18 |
|
18 | 19 | from base64 import b16encode, b32decode
|
19 | 20 | from hashlib import sha1
|
|
24 | 25 | import subprocess
|
25 | 26 | import unicodedata
|
26 | 27 | import urlparse
|
| 28 | +from json import loads |
27 | 29 |
|
28 | 30 | import os
|
29 | 31 | import re
|
@@ -813,6 +815,19 @@ def send_to_downloader(data, bestqual, album):
|
813 | 815 | torrent_name = helpers.replace_illegal_chars(folder_name) + '.torrent'
|
814 | 816 | download_path = os.path.join(headphones.CONFIG.TORRENTBLACKHOLE_DIR, torrent_name)
|
815 | 817 |
|
| 818 | + # Blackhole for t411 |
| 819 | + if bestqual[2].lower().startswith("http://api.t411"): |
| 820 | + if headphones.CONFIG.MAGNET_LINKS == 2: |
| 821 | + try: |
| 822 | + url = bestqual[2].split('TOKEN')[0] |
| 823 | + token = bestqual[2].split('TOKEN')[1] |
| 824 | + data = request.request_content(url, headers={'Authorization': token}) |
| 825 | + torrent_to_file(download_path, data) |
| 826 | + logger.info('Successfully converted magnet to torrent file') |
| 827 | + except Exception as e: |
| 828 | + logger.error("Error converting magnet link: %s" % str(e)) |
| 829 | + return |
| 830 | + |
816 | 831 | if bestqual[2].lower().startswith("magnet:"):
|
817 | 832 | if headphones.CONFIG.MAGNET_LINKS == 1:
|
818 | 833 | try:
|
@@ -1763,6 +1778,77 @@ def set_proxy(proxy_url):
|
1763 | 1778 | resultlist.append((title, size, url, provider, 'torrent', match))
|
1764 | 1779 | except Exception as e:
|
1765 | 1780 | logger.exception("Unhandled exception in Mininova Parser")
|
| 1781 | + # t411 |
| 1782 | + if headphones.CONFIG.TQUATTRECENTONZE: |
| 1783 | + username = headphones.CONFIG.TQUATTRECENTONZE_USER |
| 1784 | + password = headphones.CONFIG.TQUATTRECENTONZE_PASSWORD |
| 1785 | + API_URL = "http://api.t411.ch" |
| 1786 | + AUTH_URL = API_URL + '/auth' |
| 1787 | + DL_URL = API_URL + '/torrents/download/' |
| 1788 | + provider = "t411" |
| 1789 | + t411_term = term.replace(" ", "%20") |
| 1790 | + SEARCH_URL = API_URL + '/torrents/search/' + t411_term + "?limit=15&cid=395&subcat=623" |
| 1791 | + headers_login = {'username': username, 'password': password} |
| 1792 | + |
| 1793 | + # Requesting content |
| 1794 | + logger.info('Parsing results from t411 using search term: %s' % term) |
| 1795 | + req = request.request_content(AUTH_URL, method='post', data=headers_login) |
| 1796 | + |
| 1797 | + if len(req.split('"')) == 9: |
| 1798 | + token = req.split('"')[7] |
| 1799 | + headers_auth = {'Authorization': token} |
| 1800 | + logger.info('t411 - User %s logged in' % username) |
| 1801 | + else: |
| 1802 | + logger.info('t411 - Login error : %s' % req.split('"')[3]) |
| 1803 | + |
| 1804 | + # Quality |
| 1805 | + if headphones.CONFIG.PREFERRED_QUALITY == 3 or losslessOnly: |
| 1806 | + providerurl = fix_url(SEARCH_URL + "&term[16][]=529&term[16][]=1184") |
| 1807 | + elif headphones.CONFIG.PREFERRED_QUALITY == 1 or allow_lossless: |
| 1808 | + providerurl = fix_url(SEARCH_URL + "&term[16][]=685&term[16][]=527&term[16][]=1070&term[16][]=528&term[16][]=1167&term[16][]=1166&term[16][]=530&term[16][]=529&term[16][]=1184&term[16][]=532&term[16][]=533&term[16][]=1085&term[16][]=534&term[16][]=535&term[16][]=1069&term[16][]=537&term[16][]=538") |
| 1809 | + elif headphones.CONFIG.PREFERRED_QUALITY == 0: |
| 1810 | + providerurl = fix_url(SEARCH_URL + "&term[16][]=685&term[16][]=527&term[16][]=1070&term[16][]=528&term[16][]=1167&term[16][]=1166&term[16][]=530&term[16][]=532&term[16][]=533&term[16][]=1085&term[16][]=534&term[16][]=535&term[16][]=1069&term[16][]=537&term[16][]=538") |
| 1811 | + else: |
| 1812 | + providerurl = fix_url(SEARCH_URL) |
| 1813 | + |
| 1814 | + # Tracker search |
| 1815 | + req = request.request_content(providerurl, headers=headers_auth) |
| 1816 | + req = loads(req) |
| 1817 | + total = req['total'] |
| 1818 | + |
| 1819 | + # Process feed |
| 1820 | + if total == '0': |
| 1821 | + logger.info("No results found from t411 for %s" % term) |
| 1822 | + else: |
| 1823 | + logger.info('Found %s results from t411' % total) |
| 1824 | + torrents = req['torrents'] |
| 1825 | + for torrent in torrents: |
| 1826 | + try: |
| 1827 | + title = torrent['name'] |
| 1828 | + if torrent['seeders'] < minimumseeders: |
| 1829 | + logger.info('Skipping torrent %s : seeders below minimum set' % title) |
| 1830 | + continue |
| 1831 | + id = torrent['id'] |
| 1832 | + size = int(torrent['size']) |
| 1833 | + data = request.request_content(DL_URL + id, headers=headers_auth) |
| 1834 | + |
| 1835 | + # Blackhole |
| 1836 | + if headphones.CONFIG.TORRENT_DOWNLOADER == 0 and headphones.CONFIG.MAGNET_LINKS == 2: |
| 1837 | + url = DL_URL + id + 'TOKEN' + token |
| 1838 | + resultlist.append((title, size, url, provider, 'torrent', True)) |
| 1839 | + |
| 1840 | + # Build magnet |
| 1841 | + else: |
| 1842 | + metadata = bdecode(data) |
| 1843 | + hashcontents = bencode(metadata['info']) |
| 1844 | + digest = sha1(hashcontents).hexdigest() |
| 1845 | + trackers = [metadata["announce"]][0] |
| 1846 | + url = 'magnet:?xt=urn:btih:%s&tr=%s' % (digest, trackers) |
| 1847 | + resultlist.append((title, size, url, provider, 'torrent', True)) |
| 1848 | + |
| 1849 | + except Exception as e: |
| 1850 | + logger.error("Error converting magnet link: %s" % str(e)) |
| 1851 | + return |
1766 | 1852 |
|
1767 | 1853 | # attempt to verify that this isn't a substring result
|
1768 | 1854 | # when looking for "Foo - Foo" we don't want "Foobar"
|
|
0 commit comments