Ejemplo n.º 1
0
    def findSubtitles(self, contentToDownload):
        contentName = contentToDownload.title
        searchResults = []

        resultsPage = self.urlHandler.request(
            SUBSCENTER_PAGES.DOMAIN,
            SUBSCENTER_PAGES.SEARCH % contentName.replace(' ', '+'))

        moviesInfo = Utils.getregexresults(
            SUBSCENTER_REGEX.SEARCH_RESULTS_PARSER, resultsPage, True)

        for movieInfo in moviesInfo:
            movieCode = movieInfo['Code']
            movieType = movieInfo['Type']
            movieName = movieInfo['MovieName']

            try:
                movieNameInEnglish = movieName.split(' / ')[1]
            except ValueError:
                movieNameInEnglish = movieName

            if movieType == 'movie' == contentToDownload.movieOrSeries:
                allVersions = self.getMovieVersions(movieNameInEnglish)
                if None != contentToDownload.torrents:
                    for versionDict in allVersions:
                        for torrent in contentToDownload.torrents:
                            if Utils.versionMatching(torrent.get('name'), versionDict.get('VerSum')):
                                searchResults.extend((torrent, versionDict))
                else:
                    searchResults.extend(allVersions)

            elif movieType == 'series' == contentToDownload.movieOrSeries:
                for episode in self.getEpisodes(movieNameInEnglish, movieCode):
                    if (episode.get('season') == contentToDownload.season and episode.get(
                            'episode') == contentToDownload.episodeNumber) or (episode.get(
                            'season') == contentToDownload.season and contentToDownload.wholeSeasonFlag) or contentToDownload.wholeSeriesFlag:
                        allVersions = self.getEpisodeVersions(episode)
                        if None != contentToDownload.torrents:
                            for versionDict in allVersions:
                                for torrent in contentToDownload.torrents:
                                    if Utils.versionMatching(torrent.get('name'), versionDict.get('VerSum')):
                                        searchResults.extend((torrent, versionDict))

                        else:
                            searchResults.extend(allVersions)

        return searchResults
Ejemplo n.º 2
0
def getMatches(torrents, subs):
    matches = []
    for torrent in torrents:
        for sub in subs:
            if Utils.versionMatching(torrent.get('name'), sub.get('VerSum')):
                matches.append((torrent, sub))
                break
    return matches
Ejemplo n.º 3
0
def downloadContent(contentToDownload):
    uTorrentClient = UTorrentClient()
    matchingTorrent, matchingSubtitle = contentToDownload.match[0]
    uTorrentClient.add_url(matchingTorrent.get('link'))
    torrentList = uTorrentClient.list()
    for torrent in torrentList[1].get('torrents'):
        torrentFile = TorrentFile(torrent)
        if Utils.versionMatching(torrentFile.name, matchingTorrent.get('name')):
            torrentPath = torrentFile.path
            a = uTorrentClient.getfiles(torrentFile.hash)
            contnerFileName = sorted(uTorrentClient.getfiles(torrentFile.hash)[1].get('files')[1], key=lambda x: x[1])[-1][0]
            break
    SubtitleSite.downloadSubtitle(matchingSubtitle, torrentPath, contnerFileName)