Exemple #1
0
    def movie_magnet_to_stream(self, magnet, args):
        selectedFile = None

        magnet_id = self.upload_magnet(magnet)['id']
        folder_details = self.magnet_status(magnet_id)['links']

        folder_details = [(key, value)
                          for key, value in folder_details.iteritems() if any(
                              value.endswith(ext)
                              for ext in source_utils.COMMON_VIDEO_EXTENSIONS)]

        for torrent_file in folder_details:
            if source_utils.filter_movie_title(
                    torrent_file[1],
                    tools.deaccentString(args['info']['title']),
                    args['info']['year']):
                selectedFile = torrent_file[0]
                break

        if selectedFile is None:
            folder_details = [
                tfile for tfile in folder_details
                if 'sample' not in tfile[1].lower()
            ]
            folder_details = [
                tfile for tfile in folder_details
                if source_utils.cleanTitle(args['info']['title']) in
                source_utils.cleanTitle(tfile[1].lower())
            ]
            if len(folder_details) == 1:
                selectedFile = folder_details[0]
            else:
                return
        self.delete_magnet(magnet_id)
        return self.resolve_hoster(selectedFile)
Exemple #2
0
    def _single_magnet_resolve(self, magnet, args, pack_select=False):

        folder_details = self.direct_download(magnet)['content']
        folder_details = sorted(folder_details,
                                key=lambda i: int(i['size']),
                                reverse=True)
        folder_details = [
            i for i in folder_details
            if source_utils.is_file_ext_valid(i['link'])
        ]

        filter_list = [
            i for i in folder_details
            if source_utils.filter_movie_title(i['path'].split(
                '/')[-1], args['info']['title'], args['info']['year'])
        ]
        if len(filter_list) == 1:
            stream_link = self._fetch_transcode_or_standard(filter_list[0])
            self._handle_add_to_cloud(magnet)
            return stream_link

        filter_list = [
            tfile for tfile in folder_details
            if 'sample' not in tfile['path'].lower()
        ]
        filter_list = [
            tfile for tfile in filter_list
            if source_utils.cleanTitle(args['info']['title']) in
            source_utils.cleanTitle(tfile['path'].lower())
        ]

        if len(filter_list) == 1:
            stream_link = self._fetch_transcode_or_standard(filter_list[0])
            self._handle_add_to_cloud(magnet)
            return stream_link
Exemple #3
0
 def check_episode_string(self, folder_details, episodeStrings):
     for i in folder_details:
         for epstring in episodeStrings:
             if source_utils.cleanTitle(epstring) in \
                     source_utils.cleanTitle(i['name'].replace('&', ' ')):
                 if any(i['link'].endswith(ext) for ext in source_utils.COMMON_VIDEO_EXTENSIONS):
                     return i['link']
     return None
    def movieMagnetToStream(self, magnet, args):

        selectedFile = None
        folder_details = self.direct_download(magnet)['content']
        folder_details = sorted(folder_details,
                                key=lambda i: int(i['size']),
                                reverse=True)
        folder_details = [
            tfile for tfile in folder_details
            if any(tfile['link'].endswith(ext)
                   for ext in source_utils.COMMON_VIDEO_EXTENSIONS)
        ]
        for torrent_file in folder_details:
            if source_utils.filter_movie_title(
                    torrent_file['path'].split('/')[-1], args['title'],
                    args['year']):
                selectedFile = torrent_file
                break

        if selectedFile is None:
            folder_details = [
                tfile for tfile in folder_details
                if 'sample' not in tfile['path'].lower()
            ]
            folder_details = [
                tfile for tfile in folder_details
                if source_utils.cleanTitle(args['title']) in
                source_utils.cleanTitle(tfile['path'].lower())
            ]
            if len(folder_details) == 1:
                selectedFile = folder_details[0]
            else:
                return

        if tools.getSetting('premiumize.transcoded') == 'true':
            if selectedFile['transcode_status'] == 'finished':
                try:
                    if selectedFile[
                            'stream_link'] is not None and tools.getSetting(
                                'premiumize.addToCloud') == 'true':
                        transfer = self.create_transfer(magnet)
                        database.add_premiumize_transfer(transfer['id'])
                except:
                    pass
                return selectedFile['stream_link']
            else:
                pass
        try:
            if selectedFile['link'] is not None and tools.getSetting(
                    'premiumize.addToCloud') == 'true':
                transfer = self.create_transfer(magnet)
                database.add_premiumize_transfer(transfer['id'])
        except:
            pass
        return selectedFile['link']
Exemple #5
0
    def realdebridWorker(self, torrent_list, info):
        try:
            cache_list = []

            hash_list = [i['hash'] for i in torrent_list]

            if len(hash_list) == 0:
                return

            realDebridCache = real_debrid.RealDebrid().checkHash(hash_list)

            for i in torrent_list:
                try:
                    if 'rd' in realDebridCache[i['hash']] and len(
                            realDebridCache[i['hash']]['rd']) >= 1:
                        if 'episodeInfo' in info:
                            episodeStrings, seasonStrings = source_utils.torrentCacheStrings(
                                info)
                            for storage_variant in realDebridCache[
                                    i['hash']]['rd']:
                                if len(storage_variant) > 1:
                                    continue
                                else:
                                    key = list(storage_variant.keys())[0]
                                    filename = storage_variant[key]['filename']
                                    if any(
                                            source_utils.cleanTitle(
                                                episodeString) in
                                            source_utils.cleanTitle(filename)
                                            for episodeString in
                                            episodeStrings):
                                        if any(filename.lower().endswith(
                                                extension)
                                               for extension in source_utils.
                                               COMMON_VIDEO_EXTENSIONS):
                                            cache_list.append(i)
                                            cache_list[-1][
                                                'debrid_provider'] = 'real_debrid'
                                            break
                        else:
                            if len(realDebridCache[i['hash']]['rd']) == 1:
                                i['debrid_provider'] = 'real_debrid'
                                cache_list.append(i)

                except:
                    pass

            self.realdebridCached = cache_list

        except:
            import traceback
            traceback.print_exc()
Exemple #6
0
    def resolve_magnet(self, magnet, args, torrent, pack_select=False):

        if 'showInfo' not in args:
            return self.movie_magnet_to_stream(magnet, args)

        magnet_id = self.upload_magnet(magnet)
        magnet_id = magnet_id['id']

        episodeStrings, seasonStrings = source_utils.torrentCacheStrings(args)

        try:
            folder_details = self.magnet_status(magnet_id)

            if folder_details['status'] != 'Ready':
                return

            folder_details = [{
                'link': key,
                'filename': value
            } for key, value in folder_details['links'].items()]


            if 'extra' not in args['info']['title'] and 'extra' not in args['showInfo']['info']['tvshowtitle'] \
                    and int(args['info']['season']) != 0:
                folder_details = [
                    i for i in folder_details
                    if 'extra' not in source_utils.cleanTitle(
                        i['filename'].replace('&', ' ').lower())
                ]

            if 'special' not in args['info']['title'] and 'special' not in args['showInfo']['info']['tvshowtitle'] \
                    and int(args['info']['season']) != 0:
                folder_details = [
                    i for i in folder_details
                    if 'special' not in source_utils.cleanTitle(
                        i['filename'].replace('&', ' ').lower())
                ]

            streamLink = self.check_episode_string(folder_details,
                                                   episodeStrings)

            if streamLink is None:
                return

            self.delete_magnet(magnet_id)

            return self.resolve_hoster(streamLink)
        except:
            import traceback
            traceback.print_exc()
            pass
Exemple #7
0
    def check_episode_string(self, folder_details, episodeStrings):
        for i in folder_details:
            for epstring in episodeStrings:
                if source_utils.cleanTitle(epstring) in \
                        source_utils.cleanTitle(i['name'].replace('&', ' ')):
                    if any(i['link'].endswith(ext) for ext in source_utils.COMMON_VIDEO_EXTENSIONS):
                        if tools.getSetting('premiumize.transcoded') == 'true':
                            if i['transcode_status'] == 'finished':
                                return i['stream_link']
                            else:
                                pass

                        return i['link']
        return None
Exemple #8
0
    def showPack(self, simpleInfo, allInfo):

        try:
            showTitle = source_utils.cleanTitle(simpleInfo['show_title'])

            url = self.base_link + '%s/%s' % (
                showTitle[:1].lower(), '%s season 1-%s' %
                (showTitle, simpleInfo['no_seasons']))
            url = url.replace(' ', '-')
            results = self.getList(url)

            url = self.base_link + '%s/%s' % (showTitle[:1].lower(),
                                              '%s complete' % showTitle)
            url = url.replace(' ', '-')
            results += self.getList(url)

            results = self.get_info(results, 'show')
            torrent_list = []

            for torrent in results:
                try:
                    if not source_utils.filterShowPack(
                            simpleInfo, torrent['release_title']):
                        continue
                    torrent_list.append(torrent)
                except:
                    continue

            self.threadResults += torrent_list

        except:
            pass
Exemple #9
0
    def singleEpisode(self, simpleInfo, allInfo):

        try:
            showTitle = source_utils.cleanTitle(simpleInfo['show_title'])
            season = simpleInfo['season_number'].zfill(2)
            episode = simpleInfo['episode_number'].zfill(2)

            url = self.base_link + '%s/%s' % (showTitle[:1], '%s s%se%s' %
                                              (showTitle, season, episode))
            url = url.replace(' ', '-')
            results = self.getList(url)
            results = self.get_info(results, 'single')
            torrent_list = []

            for torrent in results:
                try:
                    if not source_utils.filterSingleEpisode(
                            simpleInfo, torrent['release_title']):
                        continue
                    torrent_list.append(torrent)
                except:
                    continue

            self.threadResults += torrent_list
        except:
            pass
Exemple #10
0
    def movie(self, title, year):

        torrent_list = []
        self.get_token()
        title = source_utils.cleanTitle(title)
        url = self.base_link + self.search_string % (tools.quote(
            '%s %s' % (title, year)), self.token)
        response = json.loads(serenRequests().get(url).text)
        if 'error_code' in response:
            pass
        else:
            for i in response['torrent_results']:
                try:
                    torrent = {}
                    torrent['package'] = 'single'
                    torrent['release_title'] = i['title']
                    if not source_utils.filterMovieTitle(
                            torrent['release_title'], title, year):
                        continue
                    torrent['magnet'] = i['download']
                    torrent['seeds'] = i['seeders']
                    torrent['size'] = int((i['size'] / 1024) / 1024)
                    torrent_list.append(torrent)
                except:
                    import traceback
                    traceback.print_exc()
                    continue

        return torrent_list
Exemple #11
0
    def seasonPack(self, simpleInfo, allInfo):

        try:
            showTitle = source_utils.cleanTitle(simpleInfo['show_title'])

            url = self.base_link + self.search_link % tools.quote('%s season %s' % (showTitle, simpleInfo['season_number']))
            results = self.getList(url)
            torrent_list = []

            for torrent in results:
                try:
                    torrent = {}

                    if not source_utils.filterSeasonPack(simpleInfo, torrent['release_title']):
                        continue
                    else:
                        torrent['package'] = 'season'
                        torrent_list.append(torrent)
                except:
                    continue

            self.threadResults += torrent_list

        except:
            import traceback
            traceback.print_exc()
            pass
Exemple #12
0
    def seasonPack(self, simpleInfo, allInfo):

        try:
            showTitle = source_utils.cleanTitle(simpleInfo['show_title'])
            query = '%s season %s' % (showTitle, simpleInfo['season_number'])
            postData = {
                'category': 'TV',
                'orderby': 'seeds-desc',
                'search': query
            }
            url = self.base_link + self.search_link
            response = self.session.post(url, data=postData)
            results = BeautifulSoup(response.text, 'html.parser').find_all(
                'div', {'class': 'torrents_table__torrent_name'})

            results = self.get_info(results, 'season')
            torrent_list = []

            for torrent in results:
                try:
                    if not source_utils.filterSeasonPack(
                            simpleInfo, torrent['release_title']):
                        continue
                    torrent_list.append(torrent)
                except:
                    continue

            self.threadResults += torrent_list
        except:
            import traceback
            traceback.print_exc()
            pass
Exemple #13
0
    def episode(self, simpleInfo, allInfo):

        try:
            showTitle = source_utils.cleanTitle(simpleInfo['show_title'])
            season = simpleInfo['season_number'].zfill(2)
            episode = simpleInfo['episode_number'].zfill(2)

            url = self.base_link + self.search_link % tools.quote_plus('%s s%se%s' % (showTitle, season, episode))
            response = serenRequests().get(url)
            results = BeautifulSoup(response.text, 'html.parser').find_all('tr', {'class': 'forum_header_border'})

            torrent_list = []

            for i in results:
                try:
                    torrent = {}
                    torrent['package'] = 'single'
                    torrent['release_title'] = i.find('a', {'class': 'epinfo'}).text
                    if not source_utils.filterSingleEpisode(simpleInfo, torrent['release_title']):
                        continue

                    torrent['magnet'] = i.find('a', {'class': 'magnet'})['href']
                    size = i.find_all('td')[3].text
                    size = source_utils.de_string_size(size)
                    torrent['size'] = size
                    torrent['seeds'] = 0
                    torrent_list.append(torrent)
                except:
                    continue

            return torrent_list
        except:
            import traceback
            traceback.print_exc()
            pass
Exemple #14
0
    def singleEpisode(self, simpleInfo, allInfo):

        try:
            showTitle = source_utils.cleanTitle(simpleInfo['show_title'])
            season = simpleInfo['season_number'].zfill(2)
            episode = simpleInfo['episode_number'].zfill(2)

            url = self.base_link + self.search_link % tools.quote('%s s%se%s' % (showTitle, season, episode))
            results = self.getList(url)

            torrent_list = []

            for torrent in results:
                try:
                    if not source_utils.filterSingleEpisode(simpleInfo, torrent['release_title']):
                        continue
                    else:
                        torrent['package'] = 'single'
                        torrent_list.append(torrent)
                except:
                    continue

            self.threadResults += torrent_list
        except:
            import traceback
            traceback.print_exc()
            pass
Exemple #15
0
    def showPack(self, simpleInfo, allInfo):

        try:
            showTitle = source_utils.cleanTitle(simpleInfo['show_title'])

            url = self.base_link + self.search_link % tools.quote('%s season 1-%s' % (showTitle, simpleInfo['no_seasons']))
            results = self.getList(url)

            url = self.base_link + self.search_link % tools.quote('%s complete' % showTitle)
            results += self.getList(url)

            torrent_list = []

            for i in results:
                try:
                    if not source_utils.filterShowPack(simpleInfo, i['release_title']):
                        continue
                    else:
                        i['package'] = 'show'
                        torrent_list.append(i)
                except:
                    continue

            self.threadResults += torrent_list

        except:
            import traceback
            traceback.print_exc()
            pass
    def magnetToLink(self, torrent, args):
        try:
            if torrent['package'] == 'single':
                return self.singleMagnetToLink(torrent['magnet'])

            hash = str(
                re.findall(r'btih:(.*?)&', torrent['magnet'])[0].lower())
            hashCheck = self.checkHash(hash)
            torrent = self.addMagnet(torrent['magnet'])
            episodeStrings, seasonStrings = source_utils.torrentCacheStrings(
                args)
            file_key = None
            for storage_variant in hashCheck[hash]['rd']:
                if len(storage_variant) > 1:
                    continue
                else:
                    key = list(storage_variant.keys())[0]
                    filename = storage_variant[key]['filename']

                    if any(
                            source_utils.cleanTitle(episodeString) in
                            source_utils.cleanTitle(filename)
                            for episodeString in episodeStrings):
                        if any(filename.lower().endswith(extension)
                               for extension in
                               source_utils.COMMON_VIDEO_EXTENSIONS):
                            file_key = key
                            break
            if file_key == None:
                self.deleteTorrent(torrent['id'])
                return None

            self.torrentSelect(torrent['id'], file_key)

            link = self.torrentInfo(torrent['id'])
            link = self.unrestrict_link(link['links'][0])
            if link.endswith('rar'):
                link = None

            if tools.getSetting('rd.autodelete') == 'true':
                self.deleteTorrent(torrent['id'])
            return link
        except:
            import traceback
            traceback.print_exc()
            self.deleteTorrent(torrent['id'])
            return None
Exemple #17
0
 def check_episode_string(folder_details, episode_strings):
     for i in folder_details:
         for epstring in episode_strings:
             if epstring in source_utils.cleanTitle(i['filename'].replace(
                     '&', ' ').lower()) and any(
                         i['filename'].endswith(ext)
                         for ext in source_utils.COMMON_VIDEO_EXTENSIONS):
                 return i['link']
     return None
Exemple #18
0
    def episode(self, simpleInfo, allInfo):
        logging.warning(simpleInfo)
        torrent_list = []
        show_title = source_utils.cleanTitle(simpleInfo['show_title'])
        year = simpleInfo['year']
        country = simpleInfo['country']
        show_string_list = [
            show_title,
            '%s %s' % (show_title, year),
            '%s %s' % (show_title, country)
        ]
        response = serenRequests().get(self.base_link + self.search_link)
        show_list = BeautifulSoup(response.text,
                                  'html.parser').find_all('option')
        show_id = None
        for show in show_list:
            if source_utils.cleanTitle(show.text.lower()) in [
                    i.lower() for i in show_string_list
            ]:
                show_id = show['value']

        if show_id is None: return

        response = serenRequests().get(self.base_link +
                                       self.feed_url % show_id)
        torrents = BeautifulSoup(response.text, 'html.parser').find_all('item')
        for item in torrents:
            try:
                if '%sx%s' % (simpleInfo['season_number'],
                              simpleInfo['episode_number'].zfill(2)
                              ) in item.find('title').text:
                    torrent = {}
                    torrent['package'] = 'single'
                    torrent['release_title'] = re.findall(
                        r'<tv:raw_title>(.*?)</tv:raw_title>', str(item))[0]
                    torrent['magnet'] = re.findall(r'<link/>(.*?)<guid',
                                                   str(item))[0]
                    torrent['seeds'] = 0
                    torrent_list.append(torrent)
            except:
                pass

        return torrent_list
Exemple #19
0
    def resolve_magnet(self, magnet, args, torrent, pack_select):

        if 'showInfo' not in args:
            return self._single_magnet_resolve(magnet, args)

        episodeStrings, seasonStrings = source_utils.torrentCacheStrings(args)

        try:

            folder_details = self.direct_download(magnet)['content']

            if pack_select is not False and pack_select is not None:
                streamLink = self.user_select(folder_details)
                return streamLink

            if 'extra' not in args['info']['title'] and 'extra' not in args['showInfo']['info']['tvshowtitle'] \
                    and int(args['info']['season']) != 0:
                folder_details = [i for i in folder_details if
                                  'extra' not in
                                  source_utils.cleanTitle(i['path'].split('/')[-1].replace('&', ' ').lower())]

            if 'special' not in args['info']['title'] and 'special' not in args['showInfo']['info']['tvshowtitle'] \
                    and int(args['info']['season']) != 0:
                folder_details = [i for i in folder_details if
                                  'special' not in
                                  source_utils.cleanTitle(i['path'].split('/')[-1].replace('&', ' ').lower())]

            streamLink = self.check_episode_string(folder_details, episodeStrings)

        except:
            import traceback
            traceback.print_exc()
            return

        try:
            if streamLink is not None and tools.getSetting('premiumize.addToCloud') == 'true':
                transfer = self.create_transfer(magnet)
                database.add_premiumize_transfer(transfer['id'])
        except:
            pass

        return streamLink
Exemple #20
0
 def movie(self, title, year):
     title = source_utils.cleanTitle(title)
     url = self.base_link + '%s/' % title[:1].lower() + (
         '%s-%s' % (title.lower(), year)).replace(' ', '-')
     results = self.getList(url)
     results = self.get_info(results, 'single')
     torrent_list = []
     for torrent in results:
         try:
             if not source_utils.filterMovieTitle(torrent['release_title'],
                                                  title, year):
                 continue
             torrent_list.append(torrent)
         except:
             continue
     return torrent_list
Exemple #21
0
    def movie(self, title, year):
        title = source_utils.cleanTitle(title)

        url = self.base_link + self.search_link % tools.quote('%s %s' % (title, year))
        results = self.getList(url)

        torrent_list = []
        for i in results:
            try:
                if source_utils.filterMovieTitle(i['release_title'], title, year):
                    i['package'] = 'single'
                    torrent_list.append(i)
                else:
                    continue
            except:
                import traceback
                traceback.print_exc()
                continue
        return torrent_list
Exemple #22
0
    def showPack(self, simpleInfo, allInfo):

        try:
            showTitle = source_utils.cleanTitle(simpleInfo['show_title'])

            url = self.base_link + self.search_link + tools.quote(
                '%s season 1-%s' % (showTitle, simpleInfo['no_seasons']))
            response = serenRequests().get(url, timeout=10)
            try:
                if response.status_code != 200:
                    return
            except:
                return
            webpage = BeautifulSoup(response.text, 'html.parser')
            results = webpage.find_all('tr')

            url = self.base_link + self.search_link + tools.quote(
                '%s complete' % showTitle)
            response = serenRequests().get(url)
            webpage = BeautifulSoup(response.text, 'html.parser')
            results += webpage.find_all('tr')

            torrent_list = []

            for i in results:
                try:
                    torrent = {}
                    torrent['package'] = 'pack'
                    torrent['release_title'] = i.find('a', {'class', 'detLink'}).text
                    if not source_utils.filterShowPack(simpleInfo, torrent['release_title']):
                        continue
                    torrent['magnet'] = i.find_all('a')[3]['href']
                    if 'magnet:?' not in torrent['magnet']:
                        torrent['magnet'] = self.magnet_request(torrent['magnet'])
                    torrent['seeds'] = int(i.find_all('td')[2].text)
                    torrent_list.append(torrent)
                except:
                    continue

            self.threadResults += torrent_list

        except:
            pass
    def buildSimpleShowInfo(self, info):

        simpleInfo = {}

        simpleInfo['show_title'] = info['showInfo']['info']['originaltitle']
        simpleInfo['episode_title'] = info['episodeInfo']['info'][
            'originaltitle']
        simpleInfo['year'] = info['showInfo']['info']['year']
        simpleInfo['season_number'] = str(
            info['episodeInfo']['info']['season'])
        simpleInfo['episode_number'] = str(
            info['episodeInfo']['info']['episode'])
        simpleInfo['show_aliases'] = info['showInfo']['info']['showaliases']
        if '.' in simpleInfo['show_title']:
            simpleInfo['show_aliases'].append(
                source_utils.cleanTitle(simpleInfo['show_title'].replace(
                    '.', '')))
        simpleInfo['country'] = info['showInfo']['info']['country']
        simpleInfo['no_seasons'] = str(info['showInfo']['info']['seasonCount'])

        return simpleInfo
    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
Exemple #25
0
    def singleEpisode(self, simpleInfo, allInfo):

        try:
            showTitle = source_utils.cleanTitle(simpleInfo['show_title'])
            season = simpleInfo['season_number'].zfill(2)
            episode = simpleInfo['episode_number'].zfill(2)

            url = self.base_link + self.search_link + tools.quote('%s s%se%s' % (showTitle, season, episode))
            response = serenRequests().get(url, timeout=10)
            webpage = BeautifulSoup(response.text, 'html.parser')
            results = webpage.find_all('tr')
            torrent_list = []

            page_limit = 2
            torrent_list = []

            for x in range(1, page_limit):
                for i in results:
                    try:
                        torrent = {}
                        torrent['package'] = 'single'
                        torrent['release_title'] = i.find('a', {'class', 'detLink'}).text

                        if not source_utils.filterSingleEpisode(simpleInfo, torrent['release_title']):
                            continue

                        torrent['magnet'] = i.find_all('a')[3]['href']
                        if 'magnet:?' not in torrent['magnet']:
                            torrent['magnet'] = self.magnet_request(torrent['magnet'])
                        torrent['seeds'] = int(i.find_all('td')[2].text)
                        torrent_list.append(torrent)
                    except:
                        import traceback
                        traceback.print_exc()
                        continue

                self.threadResults += torrent_list
        except:
            pass
    def buildHosterVariables(self, info, type):

        if type == 'tvshow':
            imdb = info['showInfo']['ids']['imdb']
            tvdb = info['showInfo']['ids']['tvdb']
            title = info['showInfo']['info']['tvshowtitle']
            localtitle = ''
            aliases = info['showInfo']['info']['showaliases']
            if '.' in title:
                aliases.append(source_utils.cleanTitle(title.replace('.', '')))
            year = info['showInfo']['info']['year']
            return imdb, tvdb, title, localtitle, aliases, year

        elif type == 'episode':
            imdb = info['episodeInfo']['ids']['imdb']
            tvdb = info['episodeInfo']['ids']['tvdb']
            title = info['episodeInfo']['info']['title']
            premiered = info['episodeInfo']['info']['premiered']
            season = str(info['episodeInfo']['info']['season'])
            episode = str(info['episodeInfo']['info']['episode'])
            return imdb, tvdb, title, premiered, season, episode
        elif type == 'movie':
            imdb = info['ids']['imdb']
            title = info['title']
            localtitle = info['title']
            aliases = []
            year = info['year']
            return imdb, title, localtitle, aliases, year
        elif type == 'sources':
            hostprDict = [
                host[0]
                for debrid in self.hosterDomains['premium'].itervalues()
                for host in debrid
            ]
            hostDict = self.hosterDomains['free']
            return hostDict, hostprDict
    def magnetToLink(self, torrent, args):
        try:
            if torrent['package'] == 'single':
                return self.singleMagnetToLink(torrent['magnet'])

            hash = str(
                re.findall(r'btih:(.*?)&', torrent['magnet'])[0].lower())
            hashCheck = self.checkHash(hash)
            torrent = self.addMagnet(torrent['magnet'])
            episodeStrings, seasonStrings = source_utils.torrentCacheStrings(
                args)
            key_list = []
            for storage_variant in hashCheck[hash]['rd']:
                file_inside = False
                key_list = []
                bad_storage = False

                for key, value in storage_variant.items():
                    filename = storage_variant[key]['filename']
                    if not any(
                            filename.endswith(extension) for extension in
                            source_utils.COMMON_VIDEO_EXTENSIONS):
                        bad_storage = True
                        continue
                    else:
                        key_list.append(key)
                        if any(
                                source_utils.cleanTitle(episodeString) in
                                source_utils.cleanTitle(filename)
                                for episodeString in episodeStrings):
                            file_inside = True

                if file_inside is False or bad_storage is True:
                    continue
                else:
                    break

            if len(key_list) == 0:
                self.deleteTorrent(torrent['id'])
                return None

            key_list = ','.join(key_list)

            self.torrentSelect(torrent['id'], key_list)

            link = self.torrentInfo(torrent['id'])

            file_index = None
            for idx, i in enumerate(
                [i for i in link['files'] if i['selected'] == 1]):
                if any(
                        source_utils.cleanTitle(episodeString) in
                        source_utils.cleanTitle(i['path'].split('/')[-1])
                        for episodeString in episodeStrings):
                    file_index = idx

            if file_index is None:
                self.deleteTorrent(torrent['id'])
                return None

            link = link['links'][file_index]
            link = self.unrestrict_link(link)

            if link.endswith('rar'):
                link = None

            if tools.getSetting('rd.autodelete') == 'true':
                self.deleteTorrent(torrent['id'])
            return link
        except:
            import traceback
            traceback.print_exc()
            self.deleteTorrent(torrent['id'])
            return None
Exemple #28
0
    def episode(self, simpleInfo, allInfo):
        logging.warning('1')
        torrent_list = []
        self.get_token()
        show_title = simpleInfo['show_title'].replace('.', '')
        show_title = source_utils.cleanTitle(show_title)
        season = simpleInfo['season_number'].zfill(2)
        episode = simpleInfo['episode_number'].zfill(2)
        season_pack_query = '%s s%s' % (show_title, season)
        single_episode_query = '%s s%se%s' % (show_title, season, episode)

        url = self.base_link + self.search_string % (
            tools.quote(season_pack_query), self.token)
        tools.log(url)
        response = json.loads(serenRequests().get(url).text)
        for i in response:
            tools.log(i)
        if 'error_code' in response:
            tools.log(str(response))
            pass
        else:
            for i in response['torrent_results']:
                try:
                    torrent = {}
                    torrent['package'] = 'season'
                    torrent['release_title'] = i['title']
                    if not source_utils.filterSeasonPack(
                            simpleInfo, torrent['release_title']):
                        continue
                    torrent['magnet'] = i['download']
                    torrent['seeds'] = i['seeders']
                    torrent['size'] = int((i['size'] / 1024) / 1024)
                    torrent_list.append(torrent)
                except Exception as e:
                    logging.warning(e)
                    #import traceback
                    #traceback.print_exc()
                    continue

        time.sleep(2)

        url = self.base_link + self.search_string % (
            tools.quote(single_episode_query), self.token)
        response = json.loads(serenRequests().get(url).text)

        if 'error_code' in response:
            pass
        else:
            for i in response['torrent_results']:
                try:
                    torrent = {}
                    torrent['package'] = 'single'
                    torrent['release_title'] = i['title']
                    if not source_utils.filterSingleEpisode(
                            simpleInfo, torrent['release_title']):
                        continue
                    torrent['magnet'] = i['download']
                    torrent['seeds'] = i['seeders']
                    torrent['size'] = int((i['size'] / 1024) / 1024)
                    torrent_list.append(torrent)
                except Exception as e:
                    logging.warning(e)
                    #import traceback
                    #traceback.print_exc()
                    continue
        for i in torrent_list:
            tools.log(i)
        return torrent_list
Exemple #29
0
    def magnetToStream(self, magnet, args, pack_select):

        if 'episodeInfo' not in args:
            return self.movieMagnetToStream(magnet, args)

        episodeStrings, seasonStrings = source_utils.torrentCacheStrings(args)
        showInfo = args['showInfo']['info']
        showTitle = showInfo['tvshowtitle']

        transfer = self.create_transfer(magnet)
        transfer_id = transfer['id']
        database.add_premiumize_transfer(transfer_id)
        transfers = self.list_transfers()
        folder_id = None
        sub_folder_id = None
        try:
            for i in transfers['transfers']:
                if i['id'] == transfer_id:
                    folder_id = i['folder_id']
            if folder_id is None: raise Exception

            folder_details = self.list_folder(folder_id)

            if pack_select is not False and pack_select is not None:
                streamLink = self.user_select(folder_details, transfer_id)
                return streamLink

            streamLink = self.check_episode_string(folder_details, episodeStrings)

            if streamLink is None:

                for item in folder_details:
                    # Check for old Usenet standards
                    if source_utils.cleanTitle(item['name']) == source_utils.cleanTitle(showTitle):
                        folder_details = self.list_folder(item['id'])

                for item in folder_details:
                    if item['type'] != 'folder':
                        continue
                    for seasonStr in seasonStrings:
                        if source_utils.cleanTitle(seasonStr)\
                                in source_utils.cleanTitle(item['name'].replace('&', ' ')):
                            sub_folder_id = item['id']

                if sub_folder_id is not None:
                    folder_details = self.list_folder(sub_folder_id)
                    if not pack_select == "True":
                        streamLink = self.check_episode_string(folder_details, episodeStrings)
                    else:
                        name_list = [file['name'] for file in folder_details]
                        selection = tools.showDialog.select(tools.addonName + ": Select Episode", name_list)
                        streamLink = folder_details[selection]['link']
                else:
                    pass

        except:
            import traceback
            traceback.print_exc()
            self.delete_transfer(transfer_id)
            database.remove_premiumize_transfer(transfer_id)
            return


        if streamLink is None:
            self.delete_transfer(transfer_id)
            database.remove_premiumize_transfer(transfer_id)

        return streamLink
    def real_debrid_downloader(self, torrent_object, args):
        from resources.lib.common import source_utils
        tools.log('REAL DEBRID CACHE ASSIST STARTING')
        tools.showDialog.notification(
            tools.addonName,
            'Cache Assist is attempting to build a torrent source')
        current_percent = 0
        episodeStrings, seasonStrings = source_utils.torrentCacheStrings(args)
        debrid = real_debrid.RealDebrid()
        magnet = debrid.addMagnet(torrent_object['magnet'])
        info = debrid.torrentInfo(magnet['id'])
        torrent_id = info['id']
        file_key = None
        database.add_assist_torrent(torrent_id, 'real_debrid', 'queued',
                                    torrent_object['release_title'],
                                    str(current_percent))
        for file in info['files']:
            filename = file['path']
            key = file['id']
            if any(
                    source_utils.cleanTitle(episodeString) in
                    source_utils.cleanTitle(filename)
                    for episodeString in episodeStrings):
                if any(filename.lower().endswith(extension)
                       for extension in source_utils.COMMON_VIDEO_EXTENSIONS):
                    file_key = key
                    break

        debrid.torrentSelect(torrent_id, file_key)
        downloading_status = ['queued', 'downloading']
        current_percent = 0
        timestamp = time.time()
        while not monitor.abortRequested():
            if monitor.waitForAbort(120):
                break
            try:
                info = debrid.torrentInfo(torrent_id)
                if info['status'] == 'downloaded':
                    tools.showDialog.notification(
                        tools.addonName + ': %s' % self.title,
                        'New cached sources have been created for %s' %
                        self.title,
                        time=5000)
                    database.add_assist_torrent(
                        torrent_id, 'real_debrid', 'finished',
                        torrent_object['release_title'], str(current_percent))
                    debrid.deleteTorrent(torrent_id)
                    break
                if info['status'] in downloading_status:
                    if info['progress'] == current_percent:
                        if timestamp == (time.time() + 10800):
                            database.add_assist_torrent(
                                torrent_id, 'real_debrid', 'failed',
                                torrent_object['release_title'],
                                str(current_percent))
                            debrid.deleteTorrent(torrent_id)
                            tools.showDialog.notification(
                                tools.addonName,
                                'Cache assist for %s has failed due to no progress'
                                % self.title)
                            break
                        continue

                    else:
                        database.add_assist_torrent(
                            torrent_id, 'real_debrid', 'downloading',
                            torrent_object['release_title'],
                            str(current_percent))
                        current_percent = info['progress']
                    continue
                else:
                    database.add_assist_torrent(
                        torrent_id, 'real_debrid', 'failed',
                        torrent_object['release_title'], str(current_percent))
                    debrid.deleteTorrent(torrent_id)
                    tools.log(
                        'Could not create cache for magnet- %s' %
                        torrent_object['magnet'], 'info')
                    tools.showDialog.notification(
                        tools.addonName,
                        'Cache assist for %s has failed according to Real Debrid'
                        % self.title)
                    break
            except:
                debrid.deleteTorrent(torrent_id)