Exemple #1
0
def search(query):
    # Will issue a GET call to http://foo.bar/search?q=query
    # (properly urlencoded)
    resp = provider.GET("http://foo.bar/search", params={
        "q": query,
    })
    return provider.extract_magnets(resp.data)
Exemple #2
0
def search_movie(movie):
    terms = ''
    if _FILTER_MOVIE_ == 'true':
        terms = get_terms(False)

    if _TITLE_VF_ == 'true':
        provider.log.debug('Get FRENCH title from TMDB for %s' %
                           movie['imdb_id'])
        response = provider.GET(
            "%s/movie/%s?api_key=%s&language=fr&external_source=imdb_id&append_to_response=alternative_titles"
            % (TMDB_URL, movie['imdb_id'], TMDB_KEY))
        if response != (None, None):
            response = response.json()
            movie['title'] = unicodedata.normalize('NFKD',
                                                   response['title']).encode(
                                                       'ascii', 'ignore')
            if movie['title'].find(' : ') != -1:
                movie['title'] = movie['title'].split(' : ')[
                    0]  # SPLIT LONG TITLE
                movie['title'] = movie['title'] + ' ' + response[
                    'release_date'].split('-')[0]  # ADD YEAR
            provider.log.info('FRENCH title :  %s' % movie['title'])
        else:
            provider.log.error(
                'Error when calling TMDB. Use quasar movie data.')
    return search(movie['title'], CAT_MOVIE, terms)
Exemple #3
0
def call(method='', params=None):
    global USER_CREDENTIALS, USER_CREDENTIALS_RETRY
    provider.log.info("Call T411 API: %s%s" % (_API_, method))
    if method != '/auth':
        req = provider.GET(
            '%s%s' % (_API_, method),
            headers={'Authorization': USER_CREDENTIALS['token']})
    else:
        req = provider.POST('%s%s' % (_API_, method),
                            data=provider.urlencode(params))
    try:
        if req.getcode() == 200:
            resp = req.json()
            # provider.log.debug('Resp T411 API %s' % resp)
            if 'error' in resp:
                provider.notify(
                    message=resp['error'].encode('utf-8', 'ignore'),
                    header="Quasar [COLOR FF18F6F3]t411[/COLOR] Provider",
                    time=3000,
                    image=_ICON_)
                if (resp['code'] == 202 or resp['code'] == 201
                    ) and method != '/auth' and USER_CREDENTIALS_RETRY > 0:
                    # Force re auth
                    USER_CREDENTIALS_RETRY -= 1
                    provider.log.info('Force re auth T411 API')
                    if _auth(_USERNAME_, _PASSWORD_):
                        return call(method, params)
            if 'torrents' in resp:
                return resp['torrents']
            return resp
        else:
            provider.log.error(req)
    except Exception as e:
        provider.log.error('Resp ERROR API %s' % e)
    return []
Exemple #4
0
def search_season(series):
    terms = ''
    if _FILTER_SERIES_ == 'true':
        terms = get_terms()

    terms += '&term[46][]=936'  # complete season

    if _TITLE_VF_ == 'true':
        # Get the FRENCH title from TMDB
        provider.log.debug('Get FRENCH title from TMDB for %s' %
                           series['imdb_id'])
        response = provider.GET(
            "%s/find/%s?api_key=%s&language=fr&external_source=imdb_id" %
            (TMDB_URL, series['imdb_id'], TMDB_KEY))
        if response != (None, None):
            title = response.json()['tv_results'][0]['name']
            series['title'] = unicodedata.normalize('NFKD', title).encode(
                'ascii', 'ignore')
            provider.log.info('FRENCH title :  %s' % series['title'])
        else:
            provider.log.error(
                'Error when calling TMDB. Use Quasar movie data.')

    real_s = ''

    if series['season'] < 25 or 27 < series['season'] < 31:
        real_s = int(series['season']) + 967
    elif series['season'] == 25:
        real_s = 994
    elif 25 < series['season'] < 28:
        real_s = int(series['season']) + 966

    terms += '&term[45][]=%s' % real_s

    return search(series['title'], CAT_SERIES, terms, season=True)
def torrent2magnet(result, q):
    metainfo = bencode.bdecode(
        provider.GET(result["uri"],
                     params={},
                     headers={
                         'Authorization': token
                     },
                     data=None).data)
    result["info_hash"] = hashlib.sha1(bencode.bencode(
        metainfo['info'])).hexdigest()
    result["trackers"] = [metainfo["announce"]]
    result["is_private"] = True
    q.put(result)
Exemple #6
0
def search_episode(episode):
    terms = ''
    if _FILTER_SERIES_ == 'true':
        terms = get_terms()

    provider.log.info(
        "Search episode : name %(title)s, season %(season)02d, episode %(episode)02d"
        % episode)
    if _TITLE_VF_ == 'true':
        # Get the FRENCH title from TMDB
        provider.log.debug('Get FRENCH title from TMDB for %s' %
                           episode['imdb_id'])
        response = provider.GET(
            "%s/find/%s?api_key=%s&language=fr&external_source=imdb_id" %
            (TMDB_URL, episode['imdb_id'], TMDB_KEY))
        if response != (None, None):
            title = response.json()['tv_results'][0]['name']
            episode['title'] = unicodedata.normalize('NFKD', title).encode(
                'ascii', 'ignore')
            provider.log.info('FRENCH title :  %s' % episode['title'])
        else:
            provider.log.error(
                'Error when calling TMDB. Use Quasar movie data.')

    if episode['season']:
        real_s = ''
        if episode['season'] < 25 or 27 < episode['season'] < 31:
            real_s = int(episode['season']) + 967
        if episode['season'] == 25:
            real_s = 994
        if 25 < episode['season'] < 28:
            real_s = int(episode['season']) + 966
        terms += '&term[45][]=%s' % real_s

    if episode['episode']:
        real_ep = ''
        if episode['episode'] == 16:
            real_ep = 954
        elif episode['episode'] == 17:
            real_ep = 953
        elif episode['episode'] < 9:
            real_ep = int(episode['episode']) + 936
        elif 8 < episode['episode'] < 31:
            real_ep = int(episode['episode']) + 937
        elif 30 < episode['episode'] < 61:
            real_ep = int(episode['episode']) + 1057
        terms += '&term[46][]=%s' % real_ep

    return search(episode['title'], CAT_SERIES, terms, episode=True)
def search_general(info):
    category = {"movie": 0, "show": 433, "anime": 637, "general": 0}
    info["extra"] = settings.value.get("extra",
                                       "")  # add the extra information
    if not "query_filter" in info:
        info["query_filter"] = ""
    info["query"] = cleanQuery(info["query"])
    query = filters.type_filtering(
        info, '+')  # check type filter and set-up filters.title
    url_search = "%s/torrents/search/%s&?limit=100&cid=%s%s" % (
        settings.value["url_address"], query, category[info["type"]],
        info["query_filter"])
    provider.log.info(url_search)
    data = provider.GET(url_search,
                        params={},
                        headers={'Authorization': token},
                        data=None)
    return extract_torrents(data.json())
Exemple #8
0
def torrent2magnet(t, token):
    try:
        torrent_details = {}
        if _TORRENT_DETAILS_ == 'true':
            details_url = '/torrents/details/%s' % t["id"]
            torrent_details = call(details_url)
        torrent_url = '/torrents/download/%s' % t["id"]
        provider.log.info('%s%s' % (_API_, torrent_url))
        resp_torrent = provider.GET('%s%s' % (_API_, torrent_url),
                                    headers={'Authorization': token})
        if resp_torrent.data:
            torrent = resp_torrent.data
            metadata = bencode.bdecode(torrent)
            hash_contents = bencode.bencode(metadata['info'])
            hashsha1 = hashlib.sha1(hash_contents)
            digest = hashsha1.hexdigest()
            # b32hash = base64.b32encode(hashsha1.digest())
            trackers = [metadata['announce']]
            params = {
                'xt': 'urn:btih:%s' % digest,
                'dn': urllib.quote_plus(metadata['info']['name']),
                'tr': urllib.quote_plus(metadata['announce'])
            }

            name = t['name'].encode('utf-8', 'ignore')
            date = strptime(t['added'], '%Y-%m-%d %H:%M:%S')
            languages = get_languages(name)
            resolution = get_resolution(name)

            if _TORRENT_DETAILS_ == 'true' and 'terms' in torrent_details:
                if u'Vid\xe9o - Qualit\xe9' in torrent_details['terms']:
                    resolution = get_resolution(
                        torrent_details['terms']
                        [u'Vid\xe9o - Qualit\xe9'].encode('utf-8', 'ignore'))
                if u'Vid\xe9o - Langue' in torrent_details['terms']:
                    languages = torrent_details['terms'][
                        u'Vid\xe9o - Langue'].encode('utf-8', 'ignore')

            return {
                "id":
                t["id"],
                "uri":
                "magnet:?xt=%s&dn=%s&tr=%s" %
                (params['xt'], params['dn'], params['tr']),
                "size":
                int(t['size']),
                "seeds":
                int(t['seeders']),
                "peers":
                int(t['leechers']),
                "name":
                name,
                "trackers":
                trackers,
                "info_hash":
                digest,
                "resolution":
                resolution,
                "languages":
                languages,
                "added":
                '%s' % date.tm_year
                # "added": '[%s-%s]' % (date.tm_year, str(date.tm_mon).zfill(2))
            }
    except Exception as e:
        provider.log.error('Error torrent2magnet : %s' % e)
    provider.log.warn('No Result !')
    return {}