Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for link in soup.findAll('a', attrs={'href': re.compile(r'^/url')}):
# Extract correct url from google internal link
href = 'http://google.com' + link['href']
args = parse_qs(urlparse(href).query)
href = args['q'][0]
# import IPython; IPython.embed()
# import sys
# sys.exit(1)
# href = link['href'].lstrip('/url?q=').split('&')[0]
# Test if entry with this url would be recognized by some urlrewriter
log.trace('Checking if %s is known by some rewriter' % href)
fake_entry = {'title': entry['title'], 'url': href}
urlrewriting = plugin.get('urlrewriting', self)
if urlrewriting.url_rewritable(task, fake_entry):
log.debug('--> rewriting %s (known url pattern)' % href)
entry['url'] = href
return
else:
log.debug('<-- ignoring %s (unknown url pattern)' % href)
raise UrlRewritingError('Unable to resolve')
def _generate_search_value(self, entry):
"""
Find the TVDB name for searching myepisodes with.
myepisodes.com is backed by tvrage, so this will not be perfect.
Return: myepisode id or None
"""
search_value = entry['series_name']
# Get the series name from thetvdb to increase match chance on myepisodes
if entry.get('tvdb_series_name'):
search_value = entry['tvdb_series_name']
else:
try:
series = plugin.get('api_tvdb', self).lookup_series(
name=entry['series_name'], tvdb_id=entry.get('tvdb_id')
)
search_value = series.name
except LookupError:
log.warning(
'Unable to lookup series `%s` from tvdb, using raw name.', entry['series_name']
)
return search_value
def lookup_movie(title, session, identifiers=None):
try:
imdb_lookup = plugin.get('imdb_lookup', 'movie_list').lookup
except DependencyError:
imdb_lookup = None
try:
tmdb_lookup = plugin.get('tmdb_lookup', 'movie_list').lookup
except DependencyError:
tmdb_lookup = None
if not (imdb_lookup or tmdb_lookup):
return
entry = Entry(title=title)
if identifiers:
for identifier in identifiers:
for key, value in identifier.items():
entry[key] = value
try:
imdb_lookup(entry, session=session)
# IMDB lookup raises PluginError instead of the normal ValueError
except PluginError:
tmdb_lookup(entry)
def on_task_download(self, task, config):
# If the download plugin is not enabled, we need to call it to get
# our temp .torrent files
if config['action'] == 'add' and 'download' not in task.config:
download = plugin.get('download', self)
download.get_temp_files(task, handle_magnets=True, fail_html=True)
session: optionally specify a session to use, if specified, returned Movie will be live in that session
:param language: Specify title lookup language
:param session: sqlalchemy Session in which to do cache lookups/storage. commit may be called on a passed in
session. If not supplied, a session will be created automatically.
:return: The :class:`TMDBMovie` object populated with data from tmdb
:raises: :class:`LookupError` if a match cannot be found or there are other problems with the lookup
"""
# Populate tmdb config
get_tmdb_config()
if smart_match and not (title or tmdb_id or imdb_id):
# If smart_match was specified, parse it into a title and year
title_parser = plugin.get('parsing', 'api_tmdb').parse_movie(smart_match)
title = title_parser.name
year = title_parser.year
if not (title or tmdb_id or imdb_id):
raise LookupError('No criteria specified for TMDb lookup')
id_str = ''.format(
title, year, tmdb_id, imdb_id
)
logger.debug('Looking up TMDb information for {}', id_str)
movie = None
if imdb_id or tmdb_id:
ors = []
if tmdb_id:
ors.append(TMDBMovie.id == tmdb_id)
if imdb_id:
ors.append(TMDBMovie.imdb_id == imdb_id)
def tmdb_lookup(self, search):
tmdb = plugin.get('api_tmdb', self).lookup(tmdb_id=search)
result = {
'title': '%s (%s)' % (tmdb.name, tmdb.year),
'imdb_id': tmdb.imdb_id,
'tmdb_id': tmdb.id,
'movie_name': tmdb.name,
'movie_year': tmdb.year,
}
return result
diff = expires - datetime.now()
hours, remainder = divmod(diff.seconds, 3600)
hours += diff.days * 24
minutes, _ = divmod(remainder, 60)
logger.info(
'`{}`: timeframe waiting for {:02d}h:{:02d}min. Currently best is `{}`.',
episode.series.name,
hours,
minutes,
best['title'],
)
# add best entry to backlog (backlog is able to handle duplicate adds)
plugin.get('backlog', self).add_backlog(task, best, session=object_session(episode))
return True
def on_task_download(self, task, config):
for entry in task.accepted:
if 'file' not in entry and 'download' not in task.config:
# If the download plugin is not enabled, we need to call it to get
# our temp .torrent files
plugin.get('download', self).get_temp_files(
task, handle_magnets=True, fail_html=True
)
'app_id': 'flexget',
}
for search_string in entry.get('search_strings', [entry['title']]):
params.pop('search_string', None)
params.pop('search_imdb', None)
params.pop('search_tvdb', None)
if entry.get('movie_name') and entry.get('imdb_id'):
params['search_imdb'] = entry.get('imdb_id')
else:
query = normalize_scene(search_string)
query_url_fragment = query.encode('utf8')
params['search_string'] = query_url_fragment
if config['use_tvdb']:
plugin.get('thetvdb_lookup', self).lazy_series_lookup(entry, 'en')
params['search_tvdb'] = entry.get('tvdb_id')
log.debug('Using tvdb id %s', entry.get('tvdb_id'))
response = self.get(params=params)
if not response:
continue
# error code 10 and 20 just mean no results were found
if response.get('error_code') in [10, 20]:
searched_string = (
params.get('search_string')
or 'imdb={0}'.format(params.get('search_imdb'))
or 'tvdb={0}'.format(params.get('tvdb_id'))
)
log.debug(
'No results found for %s. Message from rarbg: %s',
with Session() as session:
series = session.query(Series).filter(Series.name == name).first()
if not series:
raise ValueError('Unknown series `%s`' % name)
def remove_entity(entity):
if not series.begin:
series.identified_by = (
'' # reset identified_by flag so that it will be recalculated
)
session.delete(entity)
log.debug('Entity `%s` from series `%s` removed from database.', identifier, name)
return [release.title for release in entity.downloaded_releases]
name_to_parse = '{} {}'.format(series.name, identifier)
parsed = plugin.get('parsing', 'series.db').parse_series(name_to_parse, name=series.name)
if not parsed.valid:
raise ValueError(
'Invalid identifier for series `{}`: `{}`'.format(series.name, identifier)
)
removed = False
if parsed.season_pack:
season = (
session.query(Season)
.filter(Season.season == parsed.season)
.filter(Season.series_id == series.id)
.first()
)
if season:
removed = True
downloaded_releases = remove_entity(season)