Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# primitive verification of torrents, just make sure we didn't get a text file or something
if file_name.endswith(GenericProvider.TORRENT):
try:
parser = createParser(file_name)
if parser:
# pylint: disable=protected-access
# Access to a protected member of a client class
mime_type = parser._getMimeType()
try:
parser.stream._input.close()
except Exception:
pass
if mime_type == 'application/x-bittorrent':
return True
except Exception as e:
logger.log(u"Failed to validate torrent file: " + ex(e), logger.DEBUG)
logger.log(u"Result is not a valid torrent file", logger.DEBUG)
return False
return True
indexer_api_params = sickbeard.indexerApi(self.indexer).api_params.copy()
if not cache:
indexer_api_params['cache'] = False
if indexer_lang:
indexer_api_params['language'] = indexer_lang
if self.show.dvdorder != 0:
indexer_api_params['dvdorder'] = True
t = sickbeard.indexerApi(self.indexer).indexer(**indexer_api_params)
my_ep = t[self.show.indexerid][season][episode]
except (sickbeard.indexer_error, IOError) as e:
logger.log(u'' + sickbeard.indexerApi(self.indexer).name + u' threw up an error: ' + ex(e), logger.DEBUG)
# if the episode is already valid just log it, if not throw it up
if self.name:
logger.log(u'' + sickbeard.indexerApi(self.indexer).name +
u' timed out but we have enough info from other sources, allowing the error', logger.DEBUG)
return
else:
logger.log(u'' + sickbeard.indexerApi(self.indexer).name + u' timed out, unable to create the episode',
logger.ERROR)
return False
except (sickbeard.indexer_episodenotfound, sickbeard.indexer_seasonnotfound):
logger.log(u'Unable to find the episode on ' + sickbeard.indexerApi(
self.indexer).name + u'... has it been removed? Should I delete from db?', logger.DEBUG)
# if I'm no longer on the Indexers but I once was then delete myself from the DB
if self.indexerid != -1:
self.delete_episode()
return
if self.location != '':
if self.status == UNKNOWN and sickbeard.helpers.isMediaFile(self.location):
logger.log(u'7 Status changes from ' + str(self.status) + u' to ' + str(
Quality.statusFromName(self.location, anime=self.show.is_anime)), logger.DEBUG)
self.status = Quality.statusFromName(self.location, anime=self.show.is_anime)
nfo_file = replace_extension(self.location, 'nfo')
logger.log(str(self.show.indexerid) + u': Using NFO name ' + nfo_file, logger.DEBUG)
if ek(os.path.isfile, nfo_file):
try:
show_xml = ETree.ElementTree(file=nfo_file)
except (SyntaxError, ValueError) as e:
logger.log(u'Error loading the NFO, backing up the NFO and skipping for now: ' + ex(e),
logger.ERROR)
try:
ek(os.rename, nfo_file, nfo_file + '.old')
except Exception as e:
logger.log(u"Failed to rename your episode's NFO file - "
u'you need to delete it or fix it: ' + ex(e), logger.ERROR)
raise NoNFOException('Error in NFO format')
for ep_details in list(show_xml.iter('episodedetails')):
if ep_details.findtext('season') is None or int(ep_details.findtext('season')) != self.season or \
ep_details.findtext('episode') is None or int(ep_details.findtext('episode')) != self.episode:
logger.log(u'{id}: NFO has an block for a different episode - '
u'wanted {ep_wanted} but got {ep_found}'.format
(id=self.show.indexerid, ep_wanted=episode_num(self.season, self.episode),
ep_found=episode_num(ep_details.findtext('season'),
ep_details.findtext('episode'))), logger.DEBUG)
# get file list
media_files = helpers.listMediaFiles(self.location)
logger.log(u'%s: Found files: %s' %
(self.indexerid, media_files), logger.DEBUG)
# create TVEpisodes from each media file (if possible)
sql_l = []
for media_file in media_files:
cur_episode = None
logger.log(str(self.indexerid) + u': Creating episode from ' + media_file, logger.DEBUG)
try:
cur_episode = self.make_ep_from_file(ek(os.path.join, self.location, media_file))
except (ShowNotFoundException, EpisodeNotFoundException) as e:
logger.log(u'Episode ' + media_file + u' returned an exception: ' + ex(e), logger.ERROR)
continue
except EpisodeDeletedException:
logger.log(u'The episode deleted itself when I tried making an object for it', logger.DEBUG)
if cur_episode is None:
continue
# see if we should save the release name in the db
ep_file_name = ek(os.path.basename, cur_episode.location)
ep_file_name = ek(os.path.splitext, ep_file_name)[0]
try:
parse_result = NameParser(False, showObj=self, tryIndexers=True).parse(ep_file_name)
except (InvalidNameException, InvalidShowException):
parse_result = None
try:
torrent_name = re.findall('dn=([^&]+)', result.url)[0]
except Exception:
torrent_name = 'NO_DOWNLOAD_NAME'
if len(torrent_hash) == 32:
torrent_hash = b16encode(b32decode(torrent_hash)).upper()
if not torrent_hash:
logger.log(u"Unable to extract torrent hash from magnet: " + ex(result.url), logger.ERROR)
return urls, filename
urls = [x.format(torrent_hash=torrent_hash, torrent_name=torrent_name) for x in self.btCacheURLS]
except Exception:
logger.log(u"Unable to extract torrent hash or name from magnet: " + ex(result.url), logger.ERROR)
return urls, filename
else:
urls = [result.url]
if self.providerType == GenericProvider.TORRENT:
filename = ek(os.path.join, sickbeard.TORRENT_DIR, sanitize_filename(result.name) + '.' + self.providerType)
elif self.providerType == GenericProvider.NZB:
filename = ek(os.path.join, sickbeard.NZB_DIR, sanitize_filename(result.name) + '.' + self.providerType)
return urls, filename
self.status = Quality.statusFromName(self.location, anime=self.show.is_anime)
nfo_file = replace_extension(self.location, 'nfo')
logger.log(str(self.show.indexerid) + u': Using NFO name ' + nfo_file, logger.DEBUG)
if ek(os.path.isfile, nfo_file):
try:
show_xml = ETree.ElementTree(file=nfo_file)
except (SyntaxError, ValueError) as e:
logger.log(u'Error loading the NFO, backing up the NFO and skipping for now: ' + ex(e),
logger.ERROR)
try:
ek(os.rename, nfo_file, nfo_file + '.old')
except Exception as e:
logger.log(u"Failed to rename your episode's NFO file - "
u'you need to delete it or fix it: ' + ex(e), logger.ERROR)
raise NoNFOException('Error in NFO format')
for ep_details in list(show_xml.iter('episodedetails')):
if ep_details.findtext('season') is None or int(ep_details.findtext('season')) != self.season or \
ep_details.findtext('episode') is None or int(ep_details.findtext('episode')) != self.episode:
logger.log(u'{id}: NFO has an block for a different episode - '
u'wanted {ep_wanted} but got {ep_found}'.format
(id=self.show.indexerid, ep_wanted=episode_num(self.season, self.episode),
ep_found=episode_num(ep_details.findtext('season'),
ep_details.findtext('episode'))), logger.DEBUG)
continue
if ep_details.findtext('title') is None or ep_details.findtext('aired') is None:
raise NoNFOException('Error in NFO format (missing episode title or airdate)')
self.name = ep_details.findtext('title')
urls = []
filename = u''
if result.url.startswith('magnet'):
try:
torrent_hash = re.findall(r'urn:btih:([\w]{32,40})', result.url)[0].upper()
try:
torrent_name = re.findall('dn=([^&]+)', result.url)[0]
except Exception:
torrent_name = 'NO_DOWNLOAD_NAME'
if len(torrent_hash) == 32:
torrent_hash = b16encode(b32decode(torrent_hash)).upper()
if not torrent_hash:
logger.log(u"Unable to extract torrent hash from magnet: " + ex(result.url), logger.ERROR)
return urls, filename
urls = [x.format(torrent_hash=torrent_hash, torrent_name=torrent_name) for x in self.btCacheURLS]
except Exception:
logger.log(u"Unable to extract torrent hash or name from magnet: " + ex(result.url), logger.ERROR)
return urls, filename
else:
urls = [result.url]
if self.providerType == GenericProvider.TORRENT:
filename = ek(os.path.join, sickbeard.TORRENT_DIR, sanitize_filename(result.name) + '.' + self.providerType)
elif self.providerType == GenericProvider.NZB:
filename = ek(os.path.join, sickbeard.NZB_DIR, sanitize_filename(result.name) + '.' + self.providerType)
return urls, filename
'notification[from_screen_name]': title,
'notification[message]': msg.encode('utf-8'),
'notification[from_remote_service_id]': int(time.time())
})
# send the request to boxcar
try:
req = urllib2.Request(curUrl)
handle = urllib2.urlopen(req, data)
handle.close()
except urllib2.HTTPError, e:
# if we get an error back that doesn't have an error code then who knows what's really happening
if not hasattr(e, 'code'):
logger.log(u"Boxcar notification failed. Error code: " + ex(e), logger.ERROR)
return False
else:
logger.log(u"Boxcar notification failed. Error code: " + str(e.code), logger.WARNING)
# HTTP status 404 if the provided email address isn't a Boxcar user.
if e.code == 404:
logger.log(u"Username is wrong/not a boxcar email. Boxcar will send an email to it", logger.WARNING)
return False
# For HTTP status code 401's, it is because you are passing in either an invalid token, or the user has not added your service.
elif e.code == 401:
# If the user has already added your service, we'll return an HTTP status code of 401.
if subscribe:
logger.log(u"Already subscribed to service", logger.ERROR)
# i dont know if this is true or false ... its neither but i also dont know how we got here in the first place