コード例 #1
0
    def search(cls, task, entry, config=None):
        proxy = T411Proxy()
        proxy.set_credential()
        query = T411InputPlugin.build_request_from(config)

        entries = set()
        search_strings = []
        for search_string in entry.get('search_strings', [entry['title']]):
            search_strings.append(search_string)
            # Escaping some expression Grey's -> Grey, Marvel's -> Marvel etc
            short_search_string = re.sub("'", "", search_string)
            if search_string != short_search_string:
                search_strings.append(short_search_string)
                very_short_search_string = re.sub("'[a-z]", "", search_string)
                if short_search_string != very_short_search_string:
                    search_strings.append(very_short_search_string)

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

        return entries
コード例 #2
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 []
コード例 #3
0
ファイル: test_t411.py プロジェクト: cyberguard/Flexget
    def test_details(self):
        proxy = T411Proxy()
        proxy.rest_client = MockRestClient()
        details = proxy.details(123123)
        assert proxy.rest_client.details_called == True
        assert details.name == "Mock Title 720p"
        assert details.terms[0].id == 12
        # 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'
コード例 #4
0
ファイル: test_t411.py プロジェクト: edetaillac/Flexget
    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'
コード例 #5
0
ファイル: t411.py プロジェクト: edetaillac/Flexget
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')
コード例 #6
0
ファイル: test_t411.py プロジェクト: edetaillac/Flexget
 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'
コード例 #7
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))
コード例 #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))
コード例 #9
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
コード例 #10
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)
コード例 #11
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