Skip to content

Commit

Permalink
Some more CC fixes.
Browse files Browse the repository at this point in the history
And cleaned up some unicode literals in the process.
  • Loading branch information
p0psicles committed May 14, 2016
1 parent da0829e commit 75bac7b
Showing 1 changed file with 50 additions and 25 deletions.
75 changes: 50 additions & 25 deletions sickbeard/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,23 +632,23 @@ def getImages(self):
def makeEpFromFile(self, filepath): # pylint: disable=too-many-locals, too-many-branches, too-many-statements

if not ek(os.path.isfile, filepath):
logger.log(u"{}: That isn't even a real file dude... {}".format
logger.log(u"{0}: That isn't even a real file dude... {1}".format
(self.indexerid, filepath))
return None

logger.log(u"{}: Creating episode object from {}".format
logger.log(u"{0}: Creating episode object from {1}".format
(self.indexerid, filepath), logger.DEBUG)

try:
parse_result = NameParser(showObj=self, tryIndexers=True, parse_method=('normal', 'anime')[self.is_anime]).parse(filepath)
except (InvalidNameException, InvalidShowException) as error:
logger.log(u"{}: {}".format(self.indexerid, error), logger.DEBUG)
logger.log(u"{0}: {1}".format(self.indexerid, error), logger.DEBUG)
return None

episodes = [ep for ep in parse_result.episode_numbers if ep is not None]
if not episodes:
logger.log(u"{}: parse_result: {}".format(self.indexerid, parse_result))
logger.log(u"{}: No episode number found in {}, ignoring it".format
logger.log(u"{0}: parse_result: {1}".format(self.indexerid, parse_result))
logger.log(u"{0}: No episode number found in {1}, ignoring it".format
(self.indexerid, filepath), logger.WARNING)
return None

Expand All @@ -658,7 +658,7 @@ def makeEpFromFile(self, filepath): # pylint: disable=too-many-locals, too-many

sql_l = []
for current_ep in episodes:
logger.log(u"{}: {} parsed to {} {}".format
logger.log(u"{0}: {1} parsed to {2} {3}".format
(self.indexerid, filepath, self.name, episode_num(season, current_ep)), logger.DEBUG)

checkQualityAgain = False
Expand All @@ -671,15 +671,15 @@ def makeEpFromFile(self, filepath): # pylint: disable=too-many-locals, too-many
if not curEp:
raise EpisodeNotFoundException
except EpisodeNotFoundException:
logger.log(u"{}: Unable to figure out what this file is, skipping {}".format
logger.log(u"{0}: Unable to figure out what this file is, skipping {1}".format
(self.indexerid, filepath), logger.ERROR)
continue

else:
# if there is a new file associated with this ep then re-check the quality
if not curEp.location or ek(os.path.normpath, curEp.location) != ek(os.path.normpath, filepath):
logger.log(
u"{}: The old episode had a different file associated with it, re-checking the quality using the new filename {}".format
u"{0}: The old episode had a different file associated with it, re-checking the quality using the new filename {1}".format
(self.indexerid, filepath), logger.DEBUG)
checkQualityAgain = True

Expand All @@ -705,7 +705,7 @@ def makeEpFromFile(self, filepath): # pylint: disable=too-many-locals, too-many
# if they replace a file on me I'll make some attempt at re-checking the quality unless I know it's the same file
if checkQualityAgain and not same_file:
newQuality = Quality.nameQuality(filepath, self.is_anime)
logger.log(u"{}: Since this file has been renamed, I checked {} and found quality {}".format
logger.log(u"{0}: Since this file has been renamed, I checked {1} and found quality {2}".format
(self.indexerid, filepath, Quality.qualityStrings[newQuality]), logger.DEBUG)
if newQuality != Quality.UNKNOWN:
with curEp.lock:
Expand All @@ -722,13 +722,15 @@ def makeEpFromFile(self, filepath): # pylint: disable=too-many-locals, too-many

# if it was snatched and now exists then set the status correctly
if oldStatus == SNATCHED and oldQuality <= newQuality:
logger.log(u"{}: This ep used to be snatched with quality {} but a file exists with quality {} so I'm setting the status to DOWNLOADED".format
logger.log(u"{0}: This ep used to be snatched with quality {1} but a file exists with quality {2} "
u"so I'm setting the status to DOWNLOADED".format
(self.indexerid, Quality.qualityStrings[oldQuality], Quality.qualityStrings[newQuality]), logger.DEBUG)
newStatus = DOWNLOADED

# if it was snatched proper and we found a higher quality one then allow the status change
elif oldStatus == SNATCHED_PROPER and oldQuality < newQuality:
logger.log(u"{}: This ep used to be snatched proper with quality {} but a file exists with quality {} so I'm setting the status to DOWNLOADED".format
logger.log(u"{0}: This ep used to be snatched proper with quality {1} "
u"but a file exists with quality {2} so I'm setting the status to DOWNLOADED".format
(self.indexerid, Quality.qualityStrings[oldQuality], Quality.qualityStrings[newQuality]), logger.DEBUG)
newStatus = DOWNLOADED

Expand Down Expand Up @@ -760,12 +762,12 @@ def loadFromDB(self): # pylint: disable=too-many-branches, too-many-statements
logger.log(str(self.indexerid) + u": Loading show info from database", logger.DEBUG)

main_db_con = db.DBConnection()
sql_results = main_db_con.select("SELECT * FROM tv_shows WHERE indexer_id = ?", [self.indexerid])
sql_results = main_db_con.select(b"SELECT * FROM tv_shows WHERE indexer_id = ?", [self.indexerid])

if len(sql_results) > 1:
raise MultipleShowsInDatabaseException()
elif not sql_results:
logger.log(str(self.indexerid) + ": Unable to find the show in the database")
logger.log(u"{0}: Unable to find the show in the database".format(self.indexerid))
return
else:
self.indexer = int(sql_results[0]["indexer"] or 0)
Expand Down Expand Up @@ -823,10 +825,10 @@ def loadFromDB(self): # pylint: disable=too-many-branches, too-many-statements

# Get IMDb_info from database
main_db_con = db.DBConnection()
sql_results = main_db_con.select("SELECT * FROM imdb_info WHERE indexer_id = ?", [self.indexerid])
sql_results = main_db_con.select(b"SELECT * FROM imdb_info WHERE indexer_id = ?", [self.indexerid])

if not sql_results:
logger.log(str(self.indexerid) + ": Unable to find IMDb show info in the database")
logger.log(u"{0}: Unable to find IMDb show info in the database".format(self.indexerid))
return
else:
self.imdb_info = dict(zip(sql_results[0].keys(), sql_results[0]))
Expand All @@ -839,7 +841,7 @@ def loadFromIndexer(self, cache=True, tvapi=None):
if self.indexer == INDEXER_TVRAGE:
return

logger.log(str(self.indexerid) + u": Loading show info from " + sickbeard.indexerApi(self.indexer).name, logger.DEBUG)
logger.log(u"{0}: Loading show info from {1}".format(self.indexerid, sickbeard.indexerApi(self.indexer).name), logger.DEBUG)

# There's gotta be a better way of doing this but we don't wanna
# change the cache value elsewhere
Expand Down Expand Up @@ -932,13 +934,14 @@ def load_imdb_info(self): # pylint: disable=too-many-branches
self.indexerid, self.imdb_info), logger.DEBUG)

def nextEpisode(self):
logger.log(str(self.indexerid) + ": Finding the episode which airs next", logger.DEBUG)
logger.log(u"{0}: Finding the episode which airs next".format(self.indexerid), logger.DEBUG)

curDate = datetime.date.today().toordinal()
if not self.nextaired or self.nextaired and curDate > self.nextaired:
main_db_con = db.DBConnection()
sql_results = main_db_con.select(
"SELECT airdate, season, episode FROM tv_episodes WHERE showid = ? AND airdate >= ? AND status IN (?,?) ORDER BY airdate ASC LIMIT 1",
b"SELECT airdate, season, episode FROM tv_episodes "
b"WHERE showid = ? AND airdate >= ? AND status IN (?,?) ORDER BY airdate ASC LIMIT 1",
[self.indexerid, datetime.date.today().toordinal(), UNAIRED, WANTED])

if sql_results is None or len(sql_results) == 0:
Expand All @@ -955,11 +958,11 @@ def nextEpisode(self):

def deleteShow(self, full=False):

sql_l = [["DELETE FROM tv_episodes WHERE showid = ?", [self.indexerid]],
["DELETE FROM tv_shows WHERE indexer_id = ?", [self.indexerid]],
["DELETE FROM imdb_info WHERE indexer_id = ?", [self.indexerid]],
["DELETE FROM xem_refresh WHERE indexer_id = ?", [self.indexerid]],
["DELETE FROM scene_numbering WHERE indexer_id = ?", [self.indexerid]]]
sql_l = [[b"DELETE FROM tv_episodes WHERE showid = ?", [self.indexerid]],
[b"DELETE FROM tv_shows WHERE indexer_id = ?", [self.indexerid]],
[b"DELETE FROM imdb_info WHERE indexer_id = ?", [self.indexerid]],
[b"DELETE FROM xem_refresh WHERE indexer_id = ?", [self.indexerid]],
[b"DELETE FROM scene_numbering WHERE indexer_id = ?", [self.indexerid]]]

main_db_con = db.DBConnection()
main_db_con.mass_action(sql_l)
Expand Down Expand Up @@ -1085,7 +1088,7 @@ def refreshDir(self):

def download_subtitles(self, force=False):
if not ek(os.path.isdir, self._location):
logger.log(str(self.indexerid) + ": Show dir doesn't exist, can't download subtitles", logger.DEBUG)
logger.log(u"{0}: Show dir doesn't exist, can't download subtitles".format(self.indexerid), logger.DEBUG)
return

logger.log(u"%s: Downloading subtitles" % self.indexerid, logger.DEBUG)
Expand Down Expand Up @@ -1172,6 +1175,28 @@ def __str__(self):
toReturn += "anime: " + str(self.is_anime) + "\n"
return toReturn

def __unicode__(self):
toReturn = u""
toReturn += u"indexerid: {0}\n".format(self.indexerid)
toReturn += u"indexer: {0}\n".format(self.indexer)
toReturn += u"name: {0}\n".format(self.name)
toReturn += u"location: {0}\n".format(self._location)
if self.network:
toReturn += u"network: {0}\n".format(self.network)
if self.airs:
toReturn += u"airs: {0}\n".format(self.airs)
toReturn += u"status: {0}\n".format(self.status)
toReturn += u"startyear: {0}\n".format(self.startyear)
if self.genre:
toReturn += u"genre: {0}\n".format(self.genre)
toReturn += u"classification: {0}\n".format(self.classification)
toReturn += u"runtime: {0}\n".format(self.runtime)
toReturn += u"quality: {0}\n".format(self.quality)
toReturn += u"scene: {0}\n".format(self.is_scene)
toReturn += u"sports: {0}\n".format(self.is_sports)
toReturn += u"anime: {0}\n".format(self.is_anime)
return toReturn

@staticmethod
def qualitiesToString(qualities=None):
return ', '.join([Quality.qualityStrings[quality] for quality in qualities or [] if quality and quality in Quality.qualityStrings]) or 'None'
Expand All @@ -1192,7 +1217,7 @@ def wantEpisode(self, season, episode, quality, forced_search=False, downCurQual
return False

main_db_con = db.DBConnection()
sql_results = main_db_con.select("SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
sql_results = main_db_con.select(b"SELECT status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?",
[self.indexerid, season, episode])

if not sql_results or not len(sql_results):
Expand Down

0 comments on commit 75bac7b

Please sign in to comment.