Exemple #1
0
 def on_task_input(self, task, config):
     proxy = T411Proxy()
     proxy.set_credential()
     query = T411InputPlugin.build_request_from(config)
     try:
         return proxy.search(query)
     except ApiError as e:
         log.warning("Server send an error message : %d - %s", e.code, e.message)
         return []
Exemple #2
0
    def test_details(self):
        proxy = T411Proxy()
        proxy.rest_client = MockRestClient()
        details = proxy.details(123123)
        assert proxy.rest_client.details_called
        assert details.name == "Mock Title 720p"
        term_ids = [term.id for term in details.terms]
        assert 12 in term_ids
        # Session not still bound! assert details.terms[0].type.id == 7

        proxy.rest_client.details_called = False
        proxy.details(123123)
        assert proxy.rest_client.details_called == False, 'Proxy not used the cache'
Exemple #3
0
def add_credential(username, password):
    """
    Add (or update) credential into database
    :param username:
    :param password:
    :return:
    """
    proxy = T411Proxy()
    is_new = proxy.add_credential(username=username, password=password)
    if is_new:
        console('Credential successfully added')
    else:
        console('Credential successfully updated')
Exemple #4
0
 def test_offline_proxy(self):
     proxy = T411Proxy()
     proxy.rest_client = MockRestClient()
     assert not proxy.has_cached_criterias()
     proxy.synchronize_database()
     assert proxy.has_cached_criterias()
     assert 'cartoons' in proxy.all_category_names()
     query = FriendlySearchQuery()
     query.expression = "Mickey"
     query.category_name = "cartoons"
     query.term_names.append("Antivirus")
     assert proxy.search(query)[0]['t411_torrent_id'] == 123123
     assert (11, 123) in proxy.rest_client.last_query['terms']
     assert proxy.rest_client.last_query['category_id'] == 14
     assert proxy.rest_client.last_query['expression'] == 'Mickey'
Exemple #5
0
def print_terms(category_name=None, term_type_name=None):
    proxy = T411Proxy()
    proxy.set_credential()
    formatting_main = '%-60s %-5s %-5s'
    formatting_sub = '     %-55s %-5s %-5s'
    console(formatting_main % ('Name', 'PID', 'ID'))

    if term_type_name:
        console("Not yet implemented !")
    else:
        with Session() as session:
            categories = proxy.find_categories(category_name=category_name, is_sub_category=True, session=session)
            for category in categories:
                console(formatting_main % (category.name, category.parent_id, category.id))
                for term_type in category.term_types:
                    console(formatting_main % (term_type.name, '', term_type.id))
                    for term in term_type.terms:
                        console(formatting_sub % (term.name, term_type.id, term.id))
Exemple #6
0
    def on_task_metainfo(self, task, config):
        proxy = T411Proxy()
        proxy.set_credential()
        for entry in task.entries:
            if entry.get('t411_torrent_id') is None:
                continue

            # entry.register_lazy_func(T411LookupPlugin.lazy_lookup, T411LookupPlugin.torrent_details_map)
            T411LookupPlugin.lazy_lookup(entry)
            if entry.get('t411_terms', eval_lazy=True) is not None:
                video_quality = proxy.parse_terms_to_quality(entry.get('t411_terms'))
                entry_quality = entry.get('quality')
                if video_quality is None:
                    log.info('Torrent %i hasn\'t video quality description, pass.', entry.get('t411_torrent_id'))
                    continue
                if entry_quality.source.name == 'unknown' or config == 'override':
                    entry_quality.source = video_quality.source
                if entry_quality.resolution.name == 'unknown' or config == 'override':
                    entry_quality.resolution = video_quality.resolution
Exemple #7
0
    def lazy_lookup(entry):
        string_torrent_id = entry.get('t411_torrent_id')
        if string_torrent_id is None:
            log.warning('Looking up T411 for entry pass, no t411_torrent_id found.')

        torrent_id = int(string_torrent_id)
        proxy = T411Proxy()
        proxy.set_credential()
        with Session() as session:
            try:
                log.info("Lookup torrent details for %d", torrent_id)
                bind_details = proxy.details(torrent_id, session=session)
                unbind_details = [dict([
                    ('term_type_name', term.type.name),
                    ('term_type_id', term.type.id),
                    ('term_id', term.id),
                    ('term_name', term.name)]) for term in bind_details.terms]
                entry['t411_terms'] = unbind_details
            except ApiError as e:
                log.warning("Server send an error message : %d - %s", e.code, e.message)
Exemple #8
0
def print_categories(parent_category_name=None):
    """
    Print category and its sub-categories
    :param parent_category_name: if None, all categories will be displayed
    :return:
    """
    proxy = T411Proxy()
    proxy.set_credential()
    with Session() as session:
        if parent_category_name is None:
            categories = proxy.main_categories(session=session)
        else:
            categories = proxy.find_categories(parent_category_name, session=session)
        formatting_main = '%-30s %-5s %-5s'
        formatting_sub = '     %-25s %-5s %-5s'
        console(formatting_main % ('Category name', 'PID', 'ID'))
        for category in categories:
            console(formatting_main % (category.name, category.parent_id, category.id))
            for sub_category in category.sub_categories:
                console(formatting_sub % (sub_category.name, sub_category.parent_id, sub_category.id))
Exemple #9
0
    def search(cls, entry=None, config=None, task=None):
        proxy = T411Proxy()
        proxy.set_credential()

        query = T411InputPlugin.build_request_from(config)
        if entry.get('series_season'):
            query.add_season_term(entry['series_season'])
            query.add_episode_term(entry['series_episode'])
            search_strings = escape_query([entry['series_name']])
        else:
            search_strings = entry.get('search_strings', [entry['title']])
            search_strings = escape_query(search_strings)

        produced_entries = set()
        for search_string in search_strings:
            query.expression = search_string
            try:
                search_result = proxy.search(query)
                produced_entries.update(search_result)
            except ApiError as e:
                log.warning("Server send an error message : %d - %s", e.code, e.message)

        return produced_entries