示例#1
0
    def movie_query(self, title, year, single_query=False, caller_name=None):
        title = strip_accents(title)

        if self.caller_name is None:
            if caller_name is None:
                caller_name = get_caller_name()
            self.caller_name = caller_name

        self.title = source_utils.clean_title(title)
        self.year = year

        full_query = '%s %s' % (title, year)
        use_cache_only = self._get_cache(full_query)
        if use_cache_only:
            return self._get_movie_results()
        skip_set_cache = False

        try:
            self._url = self._find_url()
            if self._url is None:
                self._set_cache(full_query)
                return self._get_movie_results()

            movie = lambda query: self._query_thread(query,
                                                     [self.filter_movie_title])
            queries = [movie(self.title + ' ' + self.year)]

            try:
                alternative_title = replace_text_with_int(self.title)
                if self.title != alternative_title:
                    queries.append(movie(alternative_title + ' ' + self.year))
            except:
                pass

            wait_threads(queries)

            if len(
                    self._temp_results
            ) == 0 and not single_query and not self._request.self.has_timeout_exc:
                self._set_cache(full_query)
                skip_set_cache = True
                wait_threads([movie(self.title)])

            if not skip_set_cache:
                self._set_cache(full_query)
            return self._get_movie_results()

        except:
            if not skip_set_cache:
                self._set_cache(full_query)
            return self._get_movie_results()
示例#2
0
    def _get(self, query, filters):
        (results, url) = self._search_core(query.encode('utf-8'))

        threads = []
        for result in results:
            el = result.el
            title = result.title
            for filter in filters:
                custom_filter = False
                packageType = filter.type
                if self._custom_filter is not None:
                    if self._custom_filter.fn(title):
                        custom_filter = True
                        packageType = self._custom_filter.type

                if custom_filter or filter.fn(title):
                    torrent = {}
                    torrent['scraper'] = self.caller_name
                    torrent['hash'] = ''
                    torrent['package'] = packageType
                    torrent['release_title'] = title
                    torrent['size'] = None
                    torrent['seeds'] = None

                    if self._use_thread_for_info:
                        if len(threads) >= 5:
                            break

                        threads.append(
                            threading.Thread(target=self._info_core,
                                             args=(el, torrent, url)))
                        if DEV_MODE:
                            wait_threads(threads)
                            threads = []
                    else:
                        self._info_core(el, torrent, url)

                    if DEV_MODE and len(self._temp_results) > 0:
                        return

        wait_threads(threads)
示例#3
0
    def _get(self, query, filters):
        results = self._search_core(query)

        threads = []
        for result in results:
            el = result.el
            title = result.title
            for filter in filters:
                custom_filter = False
                packageType = filter.type
                if self._custom_filter is not None:
                    if self._custom_filter.fn(title):
                        custom_filter = True
                        packageType = self._custom_filter.type

                if custom_filter or filter.fn(title):
                    torrent = {}
                    torrent['package'] = packageType
                    torrent['release_title'] = title
                    torrent['size'] = None
                    torrent['seeds'] = None

                    if self._use_thread_for_info:
                        if len(threads) >= 5:
                            break

                        threads.append(
                            threading.Thread(target=self._info_core,
                                             args=(el, torrent)))
                        if DEV_MODE:
                            wait_threads(threads)
                            threads = []
                    else:
                        self._info_core(el, torrent)

                    if DEV_MODE and len(self._torrent_list) > 0:
                        return

        wait_threads(threads)
示例#4
0
    def movie_query(self, title, year, caller_name=None):
        if caller_name is None:
            caller_name = get_caller_name()

        self.title = title
        self.year = year

        movie = lambda query: self._query_thread(query,
                                                 [self.filterMovieTitle])

        try:
            wait_threads([movie(title + ' ' + year)])
        except ConnectTimeoutError:
            return []
        except ReadTimeout:
            return []

        if len(self._torrent_list) == 0:
            wait_threads([movie(title)])

        self._movie_notice(caller_name)

        return self._torrent_list
示例#5
0
            def query_results():
                if DEV_MODE:
                    if self.caller_name != 'eztv':
                        wait_threads([
                            self._season(self.show_title +
                                         ' S%s' % self.season_xx)
                        ])
                    else:
                        wait_threads([
                            self._episode(self.show_title + ' S%sE%s' %
                                          (self.season_xx, self.episode_xx))
                        ])
                    return

                # specials
                if self.season_x == '0':
                    wait_threads([
                        self._episode_special(self.show_title +
                                              ' %s' % self.episode_title)
                    ])
                    #self._set_cache(full_query)
                    return

                queries = [
                    self._episode(self.show_title + ' S%sE%s' %
                                  (self.season_xx, self.episode_xx))
                ]

                if single_query:
                    #self._set_cache(full_query)
                    wait_threads(queries)
                    return

                if exact_pack:
                    queries = queries + [
                        self._season_and_pack(self.show_title +
                                              '.S%s.' % self.season_xx)
                    ]
                else:
                    queries = queries + [
                        self._season(self.show_title + ' Season ' +
                                     self.season_x),
                        self._season(self.show_title +
                                     ' S%s' % self.season_xx),
                        self._pack(self.show_title + ' Seasons'),
                        self._season_and_pack(self.show_title + ' Complete')
                    ]

                if simple_info.get('isanime', False) and simple_info.get(
                        'absolute_number', None) is not None:
                    queries.insert(
                        0,
                        self._episode(self.show_title +
                                      ' %s' % simple_info['absolute_number']))

                if self._use_thread_for_info:
                    wait_threads([queries[0]])
                else:
                    wait_threads(queries)
示例#6
0
    def episode_query(self,
                      simple_info,
                      auto_query=True,
                      single_query=False,
                      caller_name=None,
                      exact_pack=False):
        simple_info['show_title'] = strip_accents(simple_info['show_title'])

        if self.caller_name is None:
            if caller_name is None:
                caller_name = get_caller_name()
            self.caller_name = caller_name

        simple_info['show_aliases'] = list(set(simple_info['show_aliases']))
        if '.' in simple_info['show_title']:
            no_dot_show_title = simple_info['show_title'].replace('.', '')
            simple_info['show_aliases'].append(no_dot_show_title)

        for alias in simple_info['show_aliases']:
            if '.' in alias:
                simple_info['show_aliases'].append(alias.replace('.', ''))

        self.simple_info = simple_info
        self.year = simple_info['year']
        self.country = simple_info['country']
        self.show_title = source_utils.clean_title(simple_info['show_title'])
        if self.year in self.show_title:
            self.show_title_fallback = re.sub(
                r'\s+', ' ', self.show_title.replace(self.year, ''))
        else:
            self.show_title_fallback = None

        self.episode_title = source_utils.clean_title(
            simple_info['episode_title'])
        self.season_x = simple_info['season_number']
        self.episode_x = simple_info['episode_number']
        self.season_xx = self.season_x.zfill(2)
        self.episode_xx = self.episode_x.zfill(2)

        #full_query = '%s %s %s %s %s' % (self.show_title, self.year, self.season_xx, self.episode_xx, self.episode_title)
        # use_cache_only = self._get_cache(full_query)
        # if use_cache_only:
        #     return self._get_episode_results()

        try:
            self._url = self._find_url()
            if self._url is None:
                #self._set_cache(full_query)
                return self._get_episode_results()

            if auto_query is False:
                wait_threads([self._episode('')])
                #self._set_cache(full_query)
                return self._get_episode_results()

            def query_results():
                if DEV_MODE:
                    if self.caller_name != 'eztv':
                        wait_threads([
                            self._season(self.show_title +
                                         ' S%s' % self.season_xx)
                        ])
                    else:
                        wait_threads([
                            self._episode(self.show_title + ' S%sE%s' %
                                          (self.season_xx, self.episode_xx))
                        ])
                    return

                # specials
                if self.season_x == '0':
                    wait_threads([
                        self._episode_special(self.show_title +
                                              ' %s' % self.episode_title)
                    ])
                    #self._set_cache(full_query)
                    return

                queries = [
                    self._episode(self.show_title + ' S%sE%s' %
                                  (self.season_xx, self.episode_xx))
                ]

                if single_query:
                    #self._set_cache(full_query)
                    wait_threads(queries)
                    return

                if exact_pack:
                    queries = queries + [
                        self._season_and_pack(self.show_title +
                                              '.S%s.' % self.season_xx)
                    ]
                else:
                    queries = queries + [
                        self._season(self.show_title + ' Season ' +
                                     self.season_x),
                        self._season(self.show_title +
                                     ' S%s' % self.season_xx),
                        self._pack(self.show_title + ' Seasons'),
                        self._season_and_pack(self.show_title + ' Complete')
                    ]

                if simple_info.get('isanime', False) and simple_info.get(
                        'absolute_number', None) is not None:
                    queries.insert(
                        0,
                        self._episode(self.show_title +
                                      ' %s' % simple_info['absolute_number']))

                if self._use_thread_for_info:
                    wait_threads([queries[0]])
                else:
                    wait_threads(queries)

            query_results()
            if len(self._temp_results
                   ) == 0 and self.show_title_fallback is not None:
                self.show_title = self.show_title_fallback
                self.simple_info['show_title'] = self.show_title_fallback
                query_results()

            #self._set_cache(full_query)
            return self._get_episode_results()

        except:
            #self._set_cache(full_query)
            return self._get_episode_results()
示例#7
0
    def episode_query(self,
                      simple_info,
                      auto_query=True,
                      single_query=False,
                      caller_name=None):
        if caller_name is None:
            caller_name = get_caller_name()

        if '.' in simple_info['show_title']:
            no_dot_show_title = simple_info['show_title'].replace('.', '')
            simple_info['show_aliases'].append(
                source_utils.cleanTitle(no_dot_show_title))
            simple_info['show_aliases'] = list(set(
                simple_info['show_aliases']))
            simple_info['show_title'] = no_dot_show_title

        self.simple_info = simple_info
        self.year = simple_info['year']
        self.country = simple_info['country']
        self.show_title = source_utils.cleanTitle(simple_info['show_title'])
        self.episode_title = source_utils.cleanTitle(
            simple_info['episode_title'])
        self.season_x = simple_info['season_number']
        self.episode_x = simple_info['episode_number']
        self.season_xx = self.season_x.zfill(2)
        self.episode_xx = self.episode_x.zfill(2)

        if auto_query is False:
            wait_threads([self._episode('')])
            self._episode_notice(caller_name)
            return self._torrent_list

        # specials
        if self.season_x == '0':
            wait_threads([
                self._episode_special(self.show_title +
                                      ' %s' % self.episode_title)
            ])
            self._episode_notice(caller_name)
            return self._torrent_list

        try:
            wait_threads([
                self._episode(self.show_title + ' S%sE%s' %
                              (self.season_xx, self.episode_xx))
            ])
        except ConnectTimeoutError:
            return []
        except ReadTimeout:
            return []

        if single_query or DEV_MODE:
            self._episode_notice(caller_name)
            return self._torrent_list

        queries = [
            self._season(self.show_title + ' Season ' + self.season_x),
            self._season(self.show_title + ' S%s' % self.season_xx),
            self._pack(self.show_title + ' Seasons'),
            self._season_and_pack(self.show_title + ' Complete')
        ]

        if self._use_thread_for_info:
            wait_threads([queries[0]])
        else:
            wait_threads(queries)

        self._episode_notice(caller_name)

        return self._torrent_list