Beispiel #1
0
    def download_subtitles(
        self,
        searchurl,
        link,
        filename,
        ):

        referer = searchurl.replace('_', ' ')
        utils.communicator.updategui.emit('Saving subtitles for %s...'
                % filename, 'success')
        return utils.download_url_content(link, referer)
Beispiel #2
0
    def download_subtitles(
        self,
        searchurl,
        link,
        filename,
        ):

        referer = searchurl.replace('_', ' ')
        utils.communicator.updategui.emit('Saving subtitles for %s...'
                % filename, 'success')
        return utils.download_url_content(link, referer)
Beispiel #3
0
    def _query(self, filename):
        utils.communicator.updategui.emit('Searching Addic7ed.com for %s'
                 % filename, 'info')
        guessed_file_data = utils.guess_file_data(filename)
        name = guessed_file_data.get('name')
        season = guessed_file_data.get('season')
        episode = guessed_file_data.get('episode')
        teams = guessed_file_data.get('teams')

        lang_url = LANGUAGES[self.lang][0]
        searchurl = '%s/serie/%s/%s/%s/%s' % (self.host, name, season,
                episode, lang_url)

        name = name.lower().replace(' ', '_')
        teams = set(teams)
        logger.debug('[Addic7ed] Searched URL for %s:  %s'
                          % (filename, searchurl))
        best_match = None

        page_html = utils.download_url_content(searchurl)
        if not page_html.strip():
            return (searchurl, None)
        soup = BeautifulSoup(page_html)
        release_pattern = \
            re.compile('Version (.+), ([0-9]+).([0-9])+ MBs')

        try:
            sub_list = soup.findAll('td', {'class': 'NewsTitle','colspan': '3'})
            result = []

            for subs in sub_list:
                subteams = \
                    release_pattern.match(subs.contents[1].strip()).groups()[0].lower()
                subteams = self._listTeams([subteams], ['.', '_', ' '])
                langs_html = subs.find_next('td', {'class': 'language'})
                statusTD = langs_html.find_next('td')
                status = statusTD.text.strip()
                links = statusTD.find_next('td').find_all('a')
                link = '%s%s' % ('http://www.addic7ed.com',
                                 links[len(links) - 1]['href'])
                logger.debug('[Addic7ed] Team from website: %s'
                                  % subteams)
                logger.debug('[Addic7ed] Team from file: %s'
                                  % teams)

                b = {}
                b['link'] = link

                if status == 'Completed':
                    b['completed'] = 1
                    sub_quality = subs.parent.parent.find_all('a',
                            {'class': 'buttonDownload'})[0].text
                    if sub_quality == u'original' or sub_quality \
                        == u'most updated':
                        b['best_match'] = 1
                    else:
                        b['best_match'] = 0
                else:
                    b['completed'] = 0

                if subteams.issubset(teams):
                    b['overlap'] = len(set.intersection(teams,
                            subteams))
                else:
                    b['overlap'] = 0
                result.append(b)
        except:
            utils.communicator.updategui.emit('Following unknown exception occured:\n%s'
                     % traceback.format_exc(), 'error')
        else:
            if result:
                # Sort the results found by completed, overlapping, best_match

                best_match = sorted(result, key=itemgetter('completed',
                                    'overlap', 'best_match'),
                                    reverse=True)[0]
                logger.debug('A best match subtitle for %s found at %s'
                                   % (searchurl, best_match.get('link',
                                  None)))
        return (searchurl, best_match.get('link') if best_match else None)
Beispiel #4
0
    def _query(self, filename):
        utils.communicator.updategui.emit('Searching Addic7ed.com for %s'
                 % filename, 'info')
        guessed_file_data = utils.guess_file_data(filename)
        name = guessed_file_data.get('name')
        season = guessed_file_data.get('season')
        episode = guessed_file_data.get('episode')
        teams = guessed_file_data.get('teams')

        lang_url = LANGUAGES[self.lang][0]
        searchurl = '%s/serie/%s/%s/%s/%s' % (self.host, name, season,
                episode, lang_url)

        name = name.lower().replace(' ', '_')
        teams = set(teams)
        logger.debug('[Addic7ed] Searched URL for %s:  %s'
                          % (filename, searchurl))
        best_match = None

        page_html = utils.download_url_content(searchurl)
        if not page_html.strip():
            return (searchurl, None)
        soup = BeautifulSoup(page_html)
        release_pattern = \
            re.compile('Version (.+), ([0-9]+).([0-9])+ MBs')

        try:
            sub_list = soup.findAll('td', {'class': 'NewsTitle','colspan': '3'})
            result = []

            for subs in sub_list:
                subteams = \
                    release_pattern.match(subs.contents[1].strip()).groups()[0].lower()
                subteams = self._listTeams([subteams], ['.', '_', ' '])
                langs_html = subs.find_next('td', {'class': 'language'})
                statusTD = langs_html.find_next('td')
                status = statusTD.text.strip()
                links = statusTD.find_next('td').find_all('a')
                link = '%s%s' % ('http://www.addic7ed.com',
                                 links[len(links) - 1]['href'])
                logger.debug('[Addic7ed] Team from website: %s'
                                  % subteams)
                logger.debug('[Addic7ed] Team from file: %s'
                                  % teams)

                b = {}
                b['link'] = link

                if status == 'Completed':
                    b['completed'] = 1
                    sub_quality = subs.parent.parent.find_all('a',
                            {'class': 'buttonDownload'})[0].text
                    if sub_quality == u'original' or sub_quality \
                        == u'most updated':
                        b['best_match'] = 1
                    else:
                        b['best_match'] = 0
                else:
                    b['completed'] = 0

                if subteams.issubset(teams):
                    b['overlap'] = len(set.intersection(teams,
                            subteams))
                else:
                    b['overlap'] = 0
                result.append(b)
        except:
            utils.communicator.updategui.emit('Following unknown exception occured:\n%s'
                     % traceback.format_exc(), 'error')
        else:
            if result:
                # Sort the results found by completed, overlapping, best_match

                best_match = sorted(result, key=itemgetter('completed',
                                    'overlap', 'best_match'),
                                    reverse=True)[0]
                logger.debug('A best match subtitle for %s found at %s'
                                   % (searchurl, best_match.get('link',
                                  None)))
        return (searchurl, best_match.get('link') if best_match else None)