Beispiel #1
0
    def _search_request(self, url, query):
        search = url.search
        if self._imdb is not None:
            search = search.replace('search_string=', 'search_imdb=')
            original_query = query
            query = self._imdb
            if getattr(self.scraper, 'simple_info', None) is not None:
                if self.scraper.show_title_fallback is not None and self.scraper.show_title_fallback in query:
                    original_query = original_query[len(self.scraper.
                                                        show_title_fallback):]
                else:
                    original_query = original_query[len(self.scraper.show_title
                                                        ):]
                search += '&search_string=%s' % core.quote_plus(
                    original_query.strip())

        search_url = url.base + search % (core.quote_plus(query),
                                          self._get_token(url))
        response = self._request.get(search_url)

        if response.status_code != 200:
            tools.log('No response from %s' % url, 'error')
            return []

        response = core.json.loads(response.text)

        if 'error_code' in response:
            return []
        else:
            return response['torrent_results']
Beispiel #2
0
    def _search_request(self, url, query):
        query = self._imdb
        if not self.is_movie_query():
            query += ':' + self.scraper.season_x + ':' + self.scraper.episode_x

        params = 'language=english|debridoptions=nodownloadlinks,nocatalog'
        if self._pm_apikey:
            params += '|premiumize=' + self._pm_apikey
        if self._rd_apikey:
            params += '|realdebrid=' + self._rd_apikey
        if self._ad_apikey:
            params += '|alldebrid=' + self._ad_apikey

        request_url = url.base + '/' + core.quote_plus(params) + (
            url.search % core.quote_plus(query))
        response = self._request.get(request_url)

        if response.status_code != 200:
            return []

        try:
            results = core.json.loads(response.text)
        except Exception as e:
            self._request.exc_msg = 'Failed to parse json: %s' % response.text
            return []

        if not results or 'streams' not in results or len(
                results['streams']) == 0:
            return []
        else:
            return results['streams']
Beispiel #3
0
    def search(self, hoster_url, query):
        search_path = hoster_url.search % core.quote_plus(query)
        search_url = '%s%s' % (hoster_url.base, search_path)

        response = self._request.get(search_url)
        if response.status_code != 200:
            return None

        results = response.text
        results = core.json.loads(results)

        if results is None or results.get('error', None) or len(
                results['results']) == 0:
            return []

        results = results['results']
        hoster_results = []
        for result in results:
            title = result['release']
            urls = []

            if result.get('links', None) is None or len(result['links']) == 0:
                continue

            for link_key in result['links'].keys():
                for url in result['links'][link_key]:
                    urls.append(url)

            hoster_results.append(core.HosterResult(title=title, urls=urls))

        return hoster_results
Beispiel #4
0
    def _search_request(self, url, query, page=1, prev_total=0):
        if page > 10:
            return []

        query = core.quote_plus(self._imdb.replace('tt', ''))
        response = self._request.get(url.base + (url.search % query) +
                                     ('&page=%s' % page))

        if response.status_code != 200:
            return []

        try:
            results = core.json.loads(response.text)
        except Exception as e:
            self._request.exc_msg = 'Failed to parse json: %s' % response.text
            return []

        if not results or not results.get('torrents', None) or len(
                results['torrents']) == 0:
            return []

        torrents = results['torrents']
        total = len(torrents) + prev_total
        if total < results['torrents_count']:
            more_results = self._search_request(url, None, page + 1, total)
            torrents += more_results

        return torrents
Beispiel #5
0
    def search(self, hoster_url, query, search_id=None):
        search_path = hoster_url.search % core.quote_plus(query)
        search_url = '%s%s' % (hoster_url.base, search_path)

        
        response = self._request.get(search_url)
        if response.status_code != 200:
            return None

        result_content = response.text
        posts = result_content.split('<div class="post">')[1:]
        results = []

        for post in posts:
            title = core.re.findall(r"href=\"http://scene-rls\.net/.*title=\"Permalink to (.*?)\"", post)[0]
            link_matches = core.re.findall(r"\"(https?:\/\/(www\.)?(.*?)\/.*?)\"", result_content)

            urls = []
            for match in link_matches:
                urls.append(match[0])

            hoster_result = core.HosterResult(title=title, urls=urls)
            results.append(hoster_result)

        return results
Beispiel #6
0
    def _search_request(self, url, query):
        query = core.quote_plus(self._imdb)
        response = self._request.get(url.base + (url.search % query))

        if response.status_code != 200:
            return []

        results = core.json.loads(response.text)

        if len(results) == 0 or results[0]['id'] == '0':
            return []
        else:
            return results
Beispiel #7
0
    def search_with_id(self, hoster_url, query, search_id=None, retry=True):
        if search_id is None:
            search_id = '%s.php' % core.get_config('r1')
            if search_id is None and core.AWS_ADMIN:
                search_id = self._get_search_id(hoster_url)

        if search_id is None:
            return []

        response = self._request.get(hoster_url.base)
        if response.status_code != 200:
            return None

        home_page = response.text
        code = core.re.findall(r'data-code-rlsbb="(.*?)"', home_page)[0]

        search_path = hoster_url.search % (search_id, core.quote_plus(query),
                                           code)
        search_url = '%s%s' % (hoster_url.base, search_path)

        results = self._request.get(search_url).text

        try:
            results = core.json.loads(results)
        except:
            if not self.parse_tried:
                search_id = self.parse_search_id(home_page)
            elif not retry or not core.AWS_ADMIN:
                return []
            else:
                retry = False
                search_id = self._get_search_id(hoster_url)

            return self.search_with_id(hoster_url,
                                       query,
                                       search_id=search_id,
                                       retry=retry)

        results = results['results']
        if results is None or len(results) == 0:
            return []

        result = results[0]
        title = result['post_title']

        result_url = 'https://%s/%s' % (result['domain'], result['post_name'])
        return (title, result_url)
Beispiel #8
0
    def _search_request(self, url, query):
        query = core.quote_plus(self._imdb)
        response = self._request.get(url.base + (url.search % query))

        if response.status_code != 200:
            return []

        try:
            results = core.json.loads(response.text)
        except Exception as e:
            self._request.exc_msg = 'Failed to parse json: %s' % response.text
            return []

        if len(results) == 0 or results[0]['id'] == '0':
            return []
        else:
            return results
Beispiel #9
0
    def _search_request(self, url, query, force_token_refresh=False):
        (token, cookies) = core.database.get(self._get_token_and_cookies,
                                             0 if force_token_refresh else 1,
                                             url)
        if not token:
            return []

        headers = {'x-request-token': token, 'cookie': cookies}

        query = core.quote_plus(query)
        data = {
            'query': query,
            'offset': 0,
            'limit': 99,
            'filters[field]': 'seeds',
            'filters[sort]': 'desc',
            'filters[time]': 4,
            'filters[category]': 3 if self.is_movie_query() else 4,
            'filters[adult]': False,
            'filters[risky]': False
        }

        response = self._request.post(url.base + url.search,
                                      data,
                                      headers=headers)

        if response.status_code != 200:
            if not force_token_refresh:
                return self._search_request(url,
                                            query,
                                            force_token_refresh=True)
            core.tools.log('No response from %s' % url, 'error')
            return []

        response = core.json.loads(response.text)

        if response['error']:
            return []
        else:
            return response['content']
Beispiel #10
0
 def _search_request(self, url, query):
     query_first_letter = query.decode('utf-8')[0].lower()
     query = core.quote_plus(query).replace('+', '-').lower()
     search_url = url.base + url.search % (query_first_letter, query)
     headers = { 'Accept': 'text/html' }
     return self._request.get(search_url, headers=headers)
Beispiel #11
0
    def _search_request(self,
                        url,
                        query,
                        force_token_refresh=False,
                        too_many_requests_max_retries=2,
                        no_results_max_retries=2):
        token = core.database.get(self._get_token,
                                  0 if force_token_refresh else 1, url)

        search = url.search
        if self._imdb is not None:
            search = search.replace('search_string=', 'search_imdb=')
            original_query = query
            query = self._imdb

            if not self.is_movie_query():
                if self.scraper.show_title_fallback is not None and self.scraper.show_title_fallback in query:
                    search_string = original_query[len(self.scraper.
                                                       show_title_fallback):]
                else:
                    search_string = original_query[len(self.scraper.show_title
                                                       ):]

                if len(search_string.strip()) == 0:
                    return []

                search += '&search_string=%s' % core.quote_plus(
                    search_string.strip())

        search_url = url.base + search % (core.quote_plus(query), token)
        response = self._request.get(search_url)

        if response.status_code != 200:
            core.tools.log('No response from %s' % search_url, 'notice')
            return []

        response = core.json.loads(response.text)

        if 'error_code' in response:
            error_code = response['error_code']

            # unauthenticated/expired
            if error_code == 1 or error_code == 2:
                return self._search_request(url,
                                            original_query,
                                            force_token_refresh=True)
            # too many requests per second
            elif error_code == 5 and too_many_requests_max_retries > 0:
                core.time.sleep(2)
                core.tools.log(
                    'Retrying after too many requests error from %s' %
                    search_url, 'info')
                too_many_requests_max_retries -= 1
                return self._search_request(url, original_query,
                                            force_token_refresh,
                                            too_many_requests_max_retries,
                                            no_results_max_retries)
            # no results found
            elif core.DEV_MODE and error_code == 20 and no_results_max_retries > 0:
                core.time.sleep(25)
                core.tools.log(
                    'Retrying after no results from %s' % search_url, 'info')
                no_results_max_retries -= 1
                return self._search_request(url, original_query,
                                            force_token_refresh,
                                            too_many_requests_max_retries,
                                            no_results_max_retries)

            core.tools.log(
                'Error response from %s: %s' %
                (search_url, core.json.dumps(response)), 'info')
            return []

        else:
            return response['torrent_results']