Example #1
0
        return {
            'username': login,
            'password': password,
            'autologin': 1,
            'redirect': '',
            'login': '******'
        }

    def get_download_link(self, url):
        """Tries to find .torrent file download link at forum thread page and return that one."""
        page_soup = self.get_response(
            url,
            referer=url,
            cookies=self.cookies,
            query_string=self.get_auth_query_string(),
            as_soup=True)
        download_link = self.find_links(url,
                                        page_soup,
                                        definite='download\.php')

        if download_link is None:
            LOGGER.debug('Login is required to download torrent file')
            if self.login():
                download_link = self.get_download_link(url)

        return download_link


# With that one we tell torrt to handle links to `nnm-club.me` domain with NNMClubTracker class.
TrackerClassesRegistry.add(NNMClubTracker)
Example #2
0

class NNMClubTracker(GenericPrivateTracker):
    """This class implements .torrent files downloads for http://nnm-club.me tracker."""

    alias = "nnm-club.me"
    login_url = "http://nnm-club.me/forum/login.php"
    auth_qs_param_name = "sid"

    def get_login_form_data(self, login, password):
        """Returns a dictionary with data to be pushed to authorization form."""
        return {"username": login, "password": password, "autologin": 1, "redirect": "", "login": "******"}

    def get_download_link(self, url):
        """Tries to find .torrent file download link at forum thread page and return that one."""
        page_soup = self.get_response(
            url, referer=url, cookies=self.cookies, query_string=self.get_auth_query_string(), as_soup=True
        )
        download_link = self.find_links(url, page_soup, definite="download\.php")

        if download_link is None:
            LOGGER.debug("Login is required to download torrent file")
            if self.login():
                download_link = self.get_download_link(url)

        return download_link


# With that one we tell torrt to handle links to `nnm-club.me` domain with NNMClubTracker class.
TrackerClassesRegistry.add(NNMClubTracker)
Example #3
0
            quality_divs = page_soup.select('div.torrent > div.torrent_c > div')
            for quality_div in quality_divs:
                available_qualities.append(quality_div['id'])

            LOGGER.debug('Available in qualities: %s' % ', '.join(available_qualities))

            if available_qualities:

                prefered_qualities = [quality for quality in self.quality_prefs if quality in available_qualities]
                if not prefered_qualities:
                    LOGGER.debug('Torrent is not available in preferred qualities: %s' % ', '.join(self.quality_prefs))
                else:
                    target_quality = prefered_qualities[0]
                    LOGGER.debug('Trying to get torrent in `%s` quality ...' % target_quality)

                    target_links = page_soup.select('div#%s div.torrent_h a' % target_quality)
                    if target_links:
                        if isinstance(target_links, list):
                            download_link = target_links[0]['href']
                        else:
                            download_link = target_links['href']
                        download_link = self.expand_link(url, download_link)
                    else:
                        LOGGER.debug('Unable to find a link for `%s` quality' % target_quality)

        return download_link


TrackerClassesRegistry.add(AniDUBTracker)
Example #4
0
                url, referer=url, cookies=self.cookies, query_string=self.query_string, as_soup=True
            )
        download_link = self.find_links(url, page_soup, r'dl\.php')
        self.form_token = self.get_form_token(page_soup)
        return download_link

    def get_form_token(self, page_soup):
        form_token_lines = [line for line in page_soup.text.split('\n\t') if line.startswith('form_token')]
        try:
            return form_token_lines[0].split(':')[1][2:-2]
        except IndexError:
            return

    def download_torrent(self, url, referer=None):
        LOGGER.debug('Downloading torrent file from %s ...', url)
        self.before_download(url)
        # rutracker require POST action to download torrent file
        if self.form_token:
            form_data = {'form_token': self.form_token}
        else:
            form_data = None
        response = self.get_response(
            url, form_data=form_data, cookies=self.cookies, query_string=self.get_auth_query_string(), referer=referer
        )
        if response is None:
            return None
        return response.content

# With that one we tell torrt to handle links to `rutracker.org` domain with RutrackerHandler class.
TrackerClassesRegistry.add(RuTrackerTracker)
Example #5
0
        }

    def before_download(self, url):
        """Used to perform some required actions right before .torrent download."""
        self.cookies['bb_dl'] = self.get_id_from_link(
            url)  # A check that user himself have visited torrent's page ;)

    def get_download_link(self, url):
        """Tries to find .torrent file download link at forum thread page and return that one."""
        page_soup = self.get_response(url,
                                      referer=url,
                                      cookies=self.cookies,
                                      query_string=self.query_string,
                                      as_soup=True)
        page_links = self.find_links(url, page_soup)
        download_link = None
        for page_link in page_links:
            if 'dl.rutracker.org' in page_link:
                download_link = page_link
                if 'guest' in download_link:
                    download_link = None
                    LOGGER.debug('Login is required to download torrent file')
                    if self.login():
                        download_link = self.get_download_link(url)
                break
        return download_link


# With that one we tell torrt to handle links to `rutracker.org` domain with RutrackerHandler class.
TrackerClassesRegistry.add(RuTrackerTracker)
Example #6
0
            else:
                target_quality = preferred_qualities[0]
                LOGGER.debug('Trying to get torrent in `%s` quality ...', target_quality)

                return available_qualities[target_quality]

        return None

    @staticmethod
    def sanitize_quality(quality_str):
        """
        Turn passed quality_str into common format in order to simplify comparison.
        Examples:

        * `sanitize_quality('WEBRip 1080p')` -> 'webrip1080p'
        * `sanitize_quality('WEBRip-1080p')` -> 'webrip1080p'
        * `sanitize_quality('WEBRip_1080p')` -> 'webrip1080p'
        * `sanitize_quality('')` -> ''
        * `sanitize_quality(None)` -> ''

        :type quality_str: Optional[str]
        :param quality_str: originally extracted quality string with non-word characters
        :return: quality string without non-word characters in lower-case
        """
        if quality_str:
            return REGEX_NON_WORD.sub('', quality_str).lower()
        return ''


TrackerClassesRegistry.add(AnilibriaTracker)
Example #7
0
                prefered_qualities = [
                    quality for quality in self.quality_prefs
                    if quality in available_qualities
                ]
                if not prefered_qualities:
                    LOGGER.debug(
                        'Torrent is not available in preferred qualities: %s',
                        ', '.join(self.quality_prefs))
                else:
                    target_quality = prefered_qualities[0]
                    LOGGER.debug('Trying to get torrent in `%s` quality ...',
                                 target_quality)

                    target_links = page_soup.select('div#%s div.torrent_h a' %
                                                    target_quality)
                    if target_links:
                        if isinstance(target_links, list):
                            download_link = target_links[0]['href']
                        else:
                            download_link = target_links['href']
                        download_link = self.expand_link(url, download_link)
                    else:
                        LOGGER.debug('Unable to find a link for `%s` quality',
                                     target_quality)

        return download_link


TrackerClassesRegistry.add(AniDUBTracker)
Example #8
0
                    url,
                    div.select('div.torrent-fourth-col a.torrent-download-link'
                               )[0]['href'])
                available_qualities[quality] = link
            else:
                LOGGER.warning('Cannot extract quality from `%s`', quality_str)

        LOGGER.debug('Available in qualities: %s',
                     ', '.join(available_qualities.keys()))

        if available_qualities:
            preferred_qualities = [
                quality for quality in self.quality_prefs
                if quality in available_qualities
            ]
            if not preferred_qualities:
                LOGGER.debug(
                    'Torrent is not available in preferred qualities: %s',
                    ', '.join(self.quality_prefs))
            else:
                target_quality = preferred_qualities[0]
                LOGGER.debug('Trying to get torrent in `%s` quality ...',
                             target_quality)

                return available_qualities[target_quality]

        return None


TrackerClassesRegistry.add(AnilibriaTracker)
Example #9
0
    def get_login_form_data(self, login, password):
        index_page = self.get_response(url=(self.login_url % {'domain': self.alias}))
        soup_response = self.make_page_soup(index_page.text)
        sid = soup_response.find(attrs={'name': 'sid'}).get('value')
        self.cookies = index_page.cookies
        self.login_url += '&sid=%s' % sid
        return {'username': login, 'password': password, 'autologin': '******',
                'redirect': 'index.php', 'sid': sid, 'login': six.u('Вход')}

    def get_download_link(self, url):
        """Tries to find .torrent file download link at forum thread page and return that one."""
        page_soup = self.get_response(
            url, referer=url, cookies=self.cookies, query_string=self.query_string, as_soup=True
        )

        domain = self.extract_domain(url)
        is_anonymous = self.find_links(url, page_soup, r'\./ucp\.php\?mode=login') is not None

        if not self.logged_in or is_anonymous:
            self.logged_in = False
            self.login(domain)
            page_soup = self.get_response(
                url, referer=url, cookies=self.cookies, query_string=self.query_string, as_soup=True
            )
        download_tag = page_soup.find('a', text='Скачать торрент')
        if download_tag:
            return self.expand_link(url, download_tag['href'])


TrackerClassesRegistry.add(CasstudioTracker)
Example #10
0
class KinozalTracker(GenericPrivateTracker):
    """This class implements .torrent files downloads for http://kinozal.tv/ tracker."""

    alias = 'kinozal.tv'
    login_url = 'http://%(domain)s/takelogin.php'
    auth_cookie_name = 'uid'
    mirrors = ['kinozal.me']
    encoding = 'cp1251'

    def get_login_form_data(self, login, password):
        """Returns a dictionary with data to be pushed to authorization form."""
        return {'username': login, 'password': password, 'returnto': ''}

    def get_id_from_link(self, url):
        """Returns forum thread identifier from full thread URL."""
        return url.split('=')[1]

    def get_download_link(self, url):
        """Tries to find .torrent file download link at forum thread page and return that one."""

        response = self.get_response(url, cookies=self.cookies)

        page_soup = self.make_page_soup(response.text)
        expected_link = '/download.+\=%s' % self.get_id_from_link(url)
        download_link = self.find_links(url, page_soup, definite=expected_link)
        return download_link


TrackerClassesRegistry.add(KinozalTracker)