コード例 #1
0
    def sources(self, url, hostDict, hostprDict):
        sources = []
        if url is None: return

        hostDict = hostDict + hostprDict

        for href in url:
            for host in hostDict:
                if host in href:
                    quality = source_utils.getQuality(
                        source_utils.cleanTitle(href))
                    sources.append({
                        'source': host,
                        'quality': quality,
                        'language': 'en',
                        'url': href,
                        'info': '',
                        'direct': False,
                        'debridonly': True
                    })

        return sources
コード例 #2
0
    def getTorrent(self, info, provider):
        # Extract provider name from Tuple
        provider_name = provider[1].upper()
        # Begin Scraping Torrent Sources
        start_time = time.time()
        try:

            self.remainingProviders.append(provider_name)
            providerModule = __import__('%s.%s' % (provider[0], provider[1]),
                                        fromlist=[''])

            if 'episodeInfo' in info:
                simpleInfo = self.buildSimpleShowInfo(info)
                allTorrents = providerModule.sources().episode(
                    simpleInfo, info)

            else:
                try:
                    allTorrents = providerModule.sources().movie(
                        info['title'], info['year'], info['imdb'])
                except:
                    allTorrents = providerModule.sources().movie(
                        info['title'], info['year'])

            if allTorrents is None:
                self.remainingProviders.remove(provider_name)
                return

            if self.canceled: raise Exception

            if len(allTorrents) > 0:

                # Begin filling in optional dictionary returns
                for torrent in allTorrents:
                    try:
                        torrent['type'] = 'torrent'
                        torrent['info'] = torrent.get('info', '')
                        if torrent['info'] == '':
                            torrent['info'] = source_utils.getInfo(
                                torrent['release_title'])
                        torrent['quality'] = torrent.get('quality', '')
                        if torrent['quality'] not in approved_qualities:
                            torrent['quality'] = source_utils.getQuality(
                                torrent['release_title'])
                        torrent['hash'] = torrent.get('hash', '')
                        if torrent['hash'] == '':
                            torrent['hash'] = re.findall(
                                r'btih:(.*?)\&', torrent['magnet'])[0]
                        torrent['hash'] = torrent['hash'].lower()
                        torrent['size'] = torrent.get('size', '')
                        if torrent['size'] == '':
                            torrent['size'] = 0
                        else:
                            torrent['size'] = self.torrent_filesize(
                                torrent, info)
                        torrent['source'] = provider_name

                    except:
                        import traceback
                        traceback.print_exc()
                        continue

                class_hashes = [i['hash'].lower() for i in self.allTorrents]
                pre_duplicate = allTorrents
                allTorrents = []

                for pre in pre_duplicate:
                    if not pre['hash'].lower() in class_hashes:
                        allTorrents.append(pre)
                    else:
                        self.duplicates_amount += 1
                tools.log('%s scrape took %s seconds' %
                          (provider_name, time.time() - start_time))
                start_time = time.time()

                # Check Debrid Providers for cached copies
                self.storeTorrentResults(self.trakt_id, allTorrents)

                if self.canceled: raise Exception

                self.torrentCacheSources += TorrentCacheCheck(
                ).torrentCacheCheck(allTorrents, info)
                self.allTorrents += allTorrents

                tools.log('%s cache check took %s seconds' %
                          (provider_name, time.time() - start_time))

            self.remainingProviders.remove(provider_name)

            return

        except Exception as e:
            tools.log('%s - %s' % (provider_name, e), 'error')
            try:
                self.remainingProviders.remove(provider_name)
            except:
                pass

            return