Exemplo n.º 1
0
	def resolve_magnet(self, magnet_url, info_hash, season, episode, ep_title):
		from resources.lib.modules.source_utils import seas_ep_filter, extras_filter
		try:
			file_url = None
			correct_files = []
			extensions = supported_video_extensions()
			extras_filtering_list = extras_filter()
			data = {'src': magnet_url}
			response = self._post(transfer_directdl_url, data)
			if not 'status' in response or response['status'] != 'success': return None
			valid_results = [i for i in response.get('content') if any(i.get('path').lower().endswith(x) for x in extensions) and not i.get('link', '') == '']
			if len(valid_results) == 0: return
			if season:
				episode_title = re.sub(r'[^A-Za-z0-9-]+', '.', ep_title.replace('\'', '')).lower()
				for item in valid_results:
					if seas_ep_filter(season, episode, item['path'].split('/')[-1]): correct_files.append(item)
					if len(correct_files) == 0: continue
					for i in correct_files:
						compare_link = seas_ep_filter(season, episode, i['path'], split=True)
						compare_link = re.sub(episode_title, '', compare_link)
						if not any(x in compare_link for x in extras_filtering_list):
							file_url = i['link']
							break
			else:
				file_url = max(valid_results, key=lambda x: int(x.get('size'))).get('link', None)
			if file_url:
				if self.store_to_cloud: self.create_transfer(magnet_url)
				return self.add_headers_to_url(file_url)
			else:
				log_utils.log('Premiumize.me: FAILED TO RESOLVE MAGNET %s : ' % magnet_url, __name__, log_utils.LOGWARNING)
		except:
			log_utils.error('Premiumize.me Error RESOLVE MAGNET %s : ' % magnet_url)
			return None
Exemplo n.º 2
0
	def resolve_magnet(self, magnet_url, info_hash, season, episode, ep_title):
		from resources.lib.modules.source_utils import seas_ep_filter, episode_extras_filter
		try:
			file_url = None
			correct_files = []
			extensions = supported_video_extensions()
			extras_filtering_list = episode_extras_filter()
			transfer_id = self.create_transfer(magnet_url)
			transfer_info = self.list_transfer(transfer_id)
			valid_results = [i for i in transfer_info.get('links') if any(i.get('filename').lower().endswith(x) for x in extensions) and not i.get('link', '') == '']
			if len(valid_results) == 0: return
			if season:
				for item in valid_results:
					if seas_ep_filter(season, episode, item['filename']):
						correct_files.append(item)
					if len(correct_files) == 0: continue
					episode_title = re.sub(r'[^A-Za-z0-9-]+', '.', ep_title.replace('\'', '')).lower()
					for i in correct_files:
						compare_link = seas_ep_filter(season, episode, i['filename'], split=True)
						compare_link = re.sub(episode_title, '', compare_link)
						if not any(x in compare_link for x in extras_filtering_list):
							media_id = i['link']
							break
			else:
				media_id = max(valid_results, key=lambda x: x.get('size')).get('link', None)
			if not store_to_cloud: self.delete_transfer(transfer_id)
			file_url = self.unrestrict_link(media_id)
			return file_url
		except:
			log_utils.error()
			if transfer_id: self.delete_transfer(transfer_id)
			return None
Exemplo n.º 3
0
    def resolve_magnet_pack(self, media_id, season, episode, ep_title):
        from resources.lib.modules.source_utils import seas_ep_filter, episode_extras_filter
        try:
            file_url = None
            correct_files = []

            extensions = supported_video_extensions()
            extras_filtering_list = episode_extras_filter()

            data = {'src': media_id}
            response = self._post(transfer_directdl, data)
            if not 'status' in response or response['status'] != 'success':
                return None

            valid_results = [
                i for i in response.get('content')
                if any(i.get('path').lower().endswith(x)
                       for x in extensions) and not i.get('link', '') == ''
            ]
            if len(valid_results) == 0:
                return

            for item in valid_results:
                if seas_ep_filter(
                        season, episode,
                        re.sub('[^A-Za-z0-9]+', '.',
                               unquote(item['path'].split('/')[-1])).lower()):
                    correct_files.append(item)
                if len(correct_files) == 0:
                    continue

                episode_title = re.sub('[^A-Za-z0-9-]+', '.',
                                       ep_title.replace('\'', '')).lower()

                for i in correct_files:
                    compare_link = re.sub('[^A-Za-z0-9-]+', '.',
                                          unquote(i['path'].replace(
                                              "\'", ''))).lower()
                    compare_link = seas_ep_filter(season,
                                                  episode,
                                                  compare_link,
                                                  split=True)
                    compare_link = re.sub(episode_title, '', compare_link)

                    if not any(x in compare_link
                               for x in extras_filtering_list):
                        file_url = i['link']
                        break

            if file_url:
                return self.add_headers_to_url(file_url)

        except Exception as e:
            log_utils.log('Error resolve_magnet_pack: %s' % str(e), __name__,
                          log_utils.LOGDEBUG)
            return None
Exemplo n.º 4
0
    def resolve_magnet_pack(self, media_id, info_hash, season, episode,
                            ep_title):
        from resources.lib.modules.source_utils import seas_ep_filter, episode_extras_filter
        try:
            info_hash = info_hash.lower()
            torrent_id = None
            rd_url = None
            match = False
            extensions = supported_video_extensions()
            extras_filtering_list = episode_extras_filter()
            info_hash = info_hash.lower()
            torrent_files = self._get(check_cache_url + '/' + info_hash)
            if not info_hash in torrent_files:
                return None
            torrent_id = self.create_transfer(media_id)
            torrent_files = torrent_files[info_hash]['rd']
            for item in torrent_files:
                video_only = self.video_only(item, extensions)
                if not video_only:
                    continue
                correct_file_check = False
                item_values = [i['filename'] for i in item.values()]
                for value in item_values:
                    correct_file_check = seas_ep_filter(
                        season, episode,
                        re.sub('[^A-Za-z0-9]+', '.', unquote(value)).lower())
                    if correct_file_check:
                        break
                if not correct_file_check:
                    continue
                torrent_keys = item.keys()
                if len(torrent_keys) == 0:
                    continue
                torrent_keys = ','.join(torrent_keys)
                self.select_file(torrent_id, torrent_keys)
                torrent_info = self.torrent_info(torrent_id)
                selected_files = [(idx, i) for idx, i in enumerate(
                    [i for i in torrent_info['files'] if i['selected'] == 1])]
                correct_files = []
                correct_file_check = False
                for value in selected_files:
                    checker = re.sub('[^A-Za-z0-9]+', '.',
                                     unquote(value[1]['path'])).lower()
                    correct_file_check = seas_ep_filter(
                        season, episode, checker)
                    if correct_file_check:
                        correct_files.append(value[1])
                        break

                if len(correct_files) == 0:
                    continue

                episode_title = re.sub('[^A-Za-z0-9-]+', '.',
                                       ep_title.replace("\'", '')).lower()

                for i in correct_files:
                    compare_link = re.sub('[^A-Za-z0-9-]+', '.',
                                          unquote(i['path'].replace(
                                              "\'", ''))).lower()
                    compare_link = seas_ep_filter(season,
                                                  episode,
                                                  compare_link,
                                                  split=True)
                    compare_link = re.sub(episode_title, '', compare_link)

                    if any(x in compare_link for x in extras_filtering_list):
                        continue
                    else:
                        match = True
                        break

                if match:
                    index = [
                        i[0] for i in selected_files
                        if i[1]['path'] == correct_files[0]['path']
                    ][0]

                rd_link = torrent_info['links'][index]
                rd_url = self.unrestrict_link(rd_link)

                # should we be deleting torrents?  isn't this our cloud account?
                self.delete_torrent(torrent_id)

                return rd_url

            self.delete_torrent(torrent_id)
        except Exception as e:
            if torrent_id: self.delete_torrent(torrent_id)
            log_utils.log('Real-Debrid Error: RESOLVE MAGNET PACK | %s' % e,
                          __name__, log_utils.LOGDEBUG)
            raise
Exemplo n.º 5
0
    def resolve_magnet(self, magnet_url, info_hash, season, episode, ep_title):
        from resources.lib.modules.source_utils import seas_ep_filter, extras_filter
        try:
            file_url = None
            media_id = None
            failed_reason = 'Unknown'
            correct_files = []
            extensions = supported_video_extensions()
            extras_filtering_list = extras_filter()
            transfer_id = self.create_transfer(magnet_url)
            transfer_info = self.list_transfer(transfer_id)
            # log_utils.log('transfer_info=%s' % transfer_info)
            # valid_results = [i for i in transfer_info.get('links') if any(i.get('filename').lower().endswith(x) for x in extensions) and not i.get('link', '') == ''] #.m2ts file extension is not in "filename" so this fails
            invalids = [
                '.rar', '.zip', '.iso', '.part', '.png', '.jpg', '.bmp',
                '.gif', '.txt'
            ]
            valid_results = [
                i for i in transfer_info.get('links') if not any(
                    i.get('filename').lower().endswith(x)
                    for x in invalids) and not i.get('link', '') == ''
            ]
            if len(valid_results) == 0:
                failed_reason = 'No valid video extension found'
                raise Exception()

            if season:
                for item in valid_results:
                    if '.m2ts' in str(item.get('files')):
                        log_utils.log(
                            'AllDebrid: Can not resolve .m2ts season disk episode',
                            level=log_utils.LOGDEBUG)
                        failed_reason = '.m2ts season disk incapable of determining episode'
                        continue
                    if seas_ep_filter(season, episode, item['filename']):
                        correct_files.append(item)
                    if len(correct_files) == 0:
                        failed_reason = 'no matching episode found'
                        continue
                    episode_title = re.sub(r'[^A-Za-z0-9-]+', '.',
                                           ep_title.replace('\'', '')).lower()
                    for i in correct_files:
                        compare_link = seas_ep_filter(season,
                                                      episode,
                                                      i['filename'],
                                                      split=True)
                        compare_link = re.sub(episode_title, '', compare_link)
                        if not any(x in compare_link
                                   for x in extras_filtering_list):
                            media_id = i['link']
                            break
            else:
                media_id = max(valid_results,
                               key=lambda x: x.get('size')).get('link', None)
                # log_utils.log('media_id=%s' % media_id)
            if not self.store_to_cloud: self.delete_transfer(transfer_id)
            if not media_id:
                log_utils.log(
                    'AllDebrid: FAILED TO RESOLVE MAGNET %s : (%s)' %
                    (magnet_url, failed_reason), __name__,
                    log_utils.LOGWARNING)
                return None
            file_url = self.unrestrict_link(media_id)
            if not file_url:
                log_utils.log(
                    'AllDebrid: FAILED TO UNRESTRICT MAGNET %s : ' %
                    magnet_url, __name__, log_utils.LOGWARNING)
            return file_url
        except:
            if failed_reason != 'Unknown':
                log_utils.log('AllDebrid: Error RESOLVE MAGNET %s : (%s)' %
                              (magnet_url, failed_reason))
            else:
                log_utils.error('AllDebrid: Error RESOLVE MAGNET %s : ' %
                                magnet_url)
            if transfer_id: self.delete_transfer(transfer_id)
            return None
Exemplo n.º 6
0
	def resolve_magnet(self, magnet_url, info_hash, season, episode, title):
		from resources.lib.modules.source_utils import seas_ep_filter, extras_filter
		from resources.lib.cloud_scrapers.cloud_utils import cloud_check_title
		try:
			torrent_id = None
			rd_url = None
			match = False
			reason = ''
			extensions = supported_video_extensions()
			extras_filtering_list = extras_filter()
			info_hash = info_hash.lower()
			if not season: compare_title = re.sub(r'[^A-Za-z0-9]+', '.', title.replace('\'', '').replace('&', 'and').replace('%', '.percent')).lower()
			torrent_files = self._get(check_cache_url + '/' + info_hash)
			if not info_hash in torrent_files: return None
			torrent_id = self.add_magnet(magnet_url) # add_magent() returns id
			torrent_files = torrent_files[info_hash]['rd']
			torrent_files = [item for item in torrent_files if self.video_only(item, extensions)]
			if not season:
				m2ts_check = self.m2ts_check(torrent_files)
				if m2ts_check: m2ts_key, torrent_files = self.m2ts_key_value(torrent_files) 
			for item in torrent_files:
				try:
					correct_file_check = False
					item_values = [i['filename'] for i in item.values()]
					if season:
						for value in item_values:
							if '.m2ts' in value:
								log_utils.log('Real-Debrid: Can not resolve .m2ts season disk episode', level=log_utils.LOGDEBUG)
								continue
							correct_file_check = seas_ep_filter(season, episode, value)
							if correct_file_check: break
						if not correct_file_check:
							reason = value + '  :no matching video filename'
							continue
					elif not m2ts_check:
						for value in item_values:
							filename = re.sub(r'[^A-Za-z0-9]+', '.', value.replace('\'', '').replace('&', 'and').replace('%', '.percent')).lower()
							filename_info = filename.replace(compare_title, '') 
							if any(x in filename_info for x in extras_filtering_list): continue
							aliases = self.get_aliases(title)
							correct_file_check = cloud_check_title(title, aliases, filename)
							if correct_file_check: break
						if not correct_file_check:
							reason = filename + '  :no matching video filename'
							continue
					torrent_keys = item.keys()
					if len(torrent_keys) == 0: continue
					torrent_keys = ','.join(torrent_keys)
					self.add_torrent_select(torrent_id, torrent_keys)
					torrent_info = self.torrent_info(torrent_id)
					if 'error' in torrent_info: continue
					selected_files = [(idx, i) for idx, i in enumerate([i for i in torrent_info['files'] if i['selected'] == 1])]
					if season:
						correct_files = []
						append = correct_files.append
						correct_file_check = False
						for value in selected_files:
							correct_file_check = seas_ep_filter(season, episode, value[1]['path'])
							if correct_file_check:
								append(value[1])
								break
						if len(correct_files) == 0: continue
						episode_title = re.sub(r'[^A-Za-z0-9]+', '.', title.replace("\'", '').replace('&', 'and').replace('%', '.percent')).lower()
						for i in correct_files:
							compare_link = seas_ep_filter(season, episode, i['path'], split=True)
							compare_link = re.sub(episode_title, '', compare_link)
							if any(x in compare_link for x in extras_filtering_list): continue
							else:
								match = True
								break
						if match:
							index = [i[0] for i in selected_files if i[1]['path'] == correct_files[0]['path']][0]
							break
					elif m2ts_check:
						match, index = True, [i[0] for i in selected_files if i[1]['id'] == m2ts_key][0]
					else:
						match = False
						for value in selected_files:
							filename = re.sub(r'[^A-Za-z0-9]+', '.', value[1]['path'].rsplit('/', 1)[1].replace('\'', '').replace('&', 'and').replace('%', '.percent')).lower()
							filename_info = filename.replace(compare_title, '') 
							if any(x in filename_info for x in extras_filtering_list): continue
							aliases = self.get_aliases(title)
							match = cloud_check_title(title, aliases, filename)
							if match:
								index = value[0]
								break
						if match: break
				except:
					log_utils.error()
			if match:
				rd_link = torrent_info['links'][index]
				file_url = self.unrestrict_link(rd_link)
				if file_url.endswith('rar'): file_url = None
				if not any(file_url.lower().endswith(x) for x in extensions): file_url = None
				if not self.store_to_cloud: self.delete_torrent(torrent_id)
				return file_url
			else:
				log_utils.log('Real-Debrid: FAILED TO RESOLVE MAGNET : "%s": %s' % (magnet_url, reason), __name__, log_utils.LOGWARNING)
			self.delete_torrent(torrent_id)
		except:
			log_utils.error('Real-Debrid: Error RESOLVE MAGNET %s : ' % magnet_url)
			if torrent_id: self.delete_torrent(torrent_id)
			return None
 def resolve_magnet(self, magnet_url, info_hash, season, episode, ep_title):
     from resources.lib.modules.source_utils import seas_ep_filter, episode_extras_filter
     try:
         torrent_id = None
         rd_url = None
         match = False
         extensions = supported_video_extensions()
         extras_filtering_list = episode_extras_filter()
         info_hash = info_hash.lower()
         torrent_files = self._get(check_cache_url + '/' + info_hash)
         if not info_hash in torrent_files: return None
         torrent_id = self.add_magnet(magnet_url)
         torrent_info = self.torrent_info(torrent_id)
         torrent_files = torrent_files[info_hash]['rd']
         for item in torrent_files:
             try:
                 video_only = self.video_only(item, extensions)
                 if not video_only: continue
                 if season:
                     correct_file_check = False
                     item_values = [i['filename'] for i in item.values()]
                     for value in item_values:
                         correct_file_check = seas_ep_filter(
                             season, episode, value)
                         if correct_file_check: break
                     if not correct_file_check: continue
                 torrent_keys = item.keys()
                 if len(torrent_keys) == 0: continue
                 torrent_keys = ','.join(torrent_keys)
                 self.add_torrent_select(torrent_id, torrent_keys)
                 torrent_info = self.torrent_info(torrent_id)
                 status = torrent_info.get('status')
                 if 'error' in torrent_info: continue
                 selected_files = [(idx, i) for idx, i in enumerate([
                     i for i in torrent_info['files'] if i['selected'] == 1
                 ])]
                 if season:
                     correct_files = []
                     correct_file_check = False
                     for value in selected_files:
                         correct_file_check = seas_ep_filter(
                             season, episode, value[1]['path'])
                         if correct_file_check:
                             correct_files.append(value[1])
                             break
                     if len(correct_files) == 0: continue
                     episode_title = re.sub(r'[^A-Za-z0-9-]+', '.',
                                            ep_title.replace("\'",
                                                             '')).lower()
                     for i in correct_files:
                         compare_link = seas_ep_filter(season,
                                                       episode,
                                                       i['path'],
                                                       split=True)
                         compare_link = re.sub(episode_title, '',
                                               compare_link)
                         if any(x in compare_link
                                for x in extras_filtering_list):
                             continue
                         else:
                             match = True
                             break
                     if match:
                         index = [
                             i[0] for i in selected_files
                             if i[1]['path'] == correct_files[0]['path']
                         ][0]
                         break
                 else:
                     match, index = True, 0
             except:
                 log_utils.error()
         if match:
             rd_link = torrent_info['links'][index]
             rd_url = self.unrestrict_link(rd_link)
             if rd_url.endswith('rar'): rd_url = None
             if not store_to_cloud: self.delete_torrent(torrent_id)
             return rd_url
         self.delete_torrent(torrent_id)
     except Exception as e:
         if torrent_id: self.delete_torrent(torrent_id)
         log_utils.log(
             'Real-Debrid Error: RESOLVE MAGNET %s | %s' % (magnet_url, e),
             __name__, log_utils.LOGDEBUG)
         return None
Exemplo n.º 8
0
    def resolve_magnet(self, magnet_url, info_hash, season, episode, title):
        from resources.lib.modules.source_utils import seas_ep_filter, extras_filter
        try:
            torrent_id = None
            rd_url = None
            match = False
            extensions = supported_video_extensions()
            extras_filtering_list = extras_filter()
            info_hash = info_hash.lower()
            torrent_files = self._get(check_cache_url + '/' + info_hash)
            if not info_hash in torrent_files: return None
            torrent_id = self.add_magnet(magnet_url)  # add_magent() returns id
            torrent_files = torrent_files[info_hash]['rd']
            torrent_files = [
                item for item in torrent_files
                if self.video_only(item, extensions)
            ]
            # log_utils.log('torrent_files=%s' % torrent_files)

            if not season:
                m2ts_check = self.m2ts_check(torrent_files)
                if m2ts_check:
                    m2ts_key, torrent_files = self.m2ts_key_value(
                        torrent_files)
            for item in torrent_files:
                try:
                    correct_file_check = False
                    item_values = [i['filename'] for i in item.values()]
                    if season:
                        for value in item_values:
                            correct_file_check = seas_ep_filter(
                                season, episode, value)
                            # log_utils.log('correct_file_check=%s' % correct_file_check)

                            if correct_file_check: break
                        if not correct_file_check: continue
                    elif not m2ts_check:
                        compare_title = re.sub(r'[^A-Za-z0-9]+', '.',
                                               title.replace('\'',
                                                             '')).lower()
                        for value in item_values:
                            filename = re.sub(r'[^A-Za-z0-9]+', '.',
                                              value.replace('\'', '')).lower()
                            if any(x in filename
                                   for x in extras_filtering_list):
                                continue
                            correct_file_check = re.search(
                                compare_title, filename)
                            if correct_file_check: break
                        if not correct_file_check: continue
                    torrent_keys = item.keys()
                    if len(torrent_keys) == 0: continue
                    torrent_keys = ','.join(torrent_keys)
                    self.add_torrent_select(torrent_id, torrent_keys)
                    torrent_info = self.torrent_info(torrent_id)
                    if 'error' in torrent_info: continue
                    selected_files = [(idx, i) for idx, i in enumerate([
                        i for i in torrent_info['files'] if i['selected'] == 1
                    ])]
                    if season:
                        correct_files = []
                        correct_file_check = False
                        for value in selected_files:
                            correct_file_check = seas_ep_filter(
                                season, episode, value[1]['path'])
                            # log_utils.log('correct_file_check=%s' % correct_file_check)
                            if correct_file_check:
                                correct_files.append(value[1])
                                break
                        if len(correct_files) == 0: continue
                        # episode_title = re.sub(r'[^A-Za-z0-9-]+', '.', title.replace("\'", '')).lower()
                        episode_title = re.sub(r'[^A-Za-z0-9]+', '.',
                                               title.replace("\'",
                                                             '')).lower()
                        for i in correct_files:
                            compare_link = seas_ep_filter(season,
                                                          episode,
                                                          i['path'],
                                                          split=True)
                            # log_utils.log('compare_link=%s' % compare_link)
                            compare_link = re.sub(episode_title, '',
                                                  compare_link)
                            if any(x in compare_link
                                   for x in extras_filtering_list):
                                continue
                            else:
                                match = True
                                break
                        if match:
                            index = [
                                i[0] for i in selected_files
                                if i[1]['path'] == correct_files[0]['path']
                            ][0]
                            break
                    elif m2ts_check:
                        match, index = True, [
                            i[0] for i in selected_files
                            if i[1]['id'] == m2ts_key
                        ][0]
                    else:
                        match = False
                        compare_title = re.sub(r'[^A-Za-z0-9]+', '.',
                                               title.replace('\'',
                                                             '')).lower()
                        for value in selected_files:
                            filename = re.sub(
                                r'[^A-Za-z0-9]+', '.',
                                value[1]['path'].replace('\'', '')).lower()
                            if any(x in filename
                                   for x in extras_filtering_list):
                                continue
                            match = re.search(compare_title, filename)
                            if match:
                                index = value[0]
                                break
                        if match: break
                except:
                    log_utils.error()
            if match:
                rd_link = torrent_info['links'][index]
                file_url = self.unrestrict_link(rd_link)
                if file_url.endswith('rar'): file_url = None
                if not any(file_url.lower().endswith(x) for x in extensions):
                    file_url = None
                if not store_to_cloud: self.delete_torrent(torrent_id)
                return file_url
            else:
                log_utils.log(
                    'Real-Debrid FAILED TO RESOLVE MAGNET : %s' % magnet_url,
                    __name__, log_utils.LOGWARNING)
            self.delete_torrent(torrent_id)
        except:
            log_utils.error('Real-Debrid Error RESOLVE MAGNET %s : ' %
                            magnet_url)
            if torrent_id: self.delete_torrent(torrent_id)
            return None