2323from . import templating as bb
2424from .submission import (Submission , form_field , finalize ,
2525 SubmissionAttributeError )
26- from .tracker import Tracker , TrackerException
26+ from .tracker import Tracker
2727from .scene import is_scene_crc , query_scene_fname
2828
2929
@@ -249,7 +249,6 @@ def _render_tv_specifier(self):
249249 return TvSpecifier (title , guess ['season' ],
250250 guess .get ('episode' , None ))
251251
252-
253252 @form_field ('tags' )
254253 def _render_tags (self ):
255254 # todo: get episode-specific actors (from imdb?)
@@ -269,7 +268,8 @@ def _render_mediainfo_path(self):
269268 contained_files = []
270269 for dp , dns , fns in os .walk (self ['path' ]):
271270 contained_files += [os .path .join (dp , fn ) for fn in fns
272- if os .path .getsize (os .path .join (dp , fn )) > 10 * 2 ** 20 ]
271+ if (os .path .getsize (os .path .join (dp , fn ))
272+ > 10 * 2 ** 20 )]
273273 if len (contained_files ) == 1 :
274274 return contained_files [0 ]
275275
@@ -359,16 +359,14 @@ def _render_source(self):
359359 # TC, SDTV, DVD5, DVD9, HD-DVD
360360
361361 # todo: replace with guess from self['guess']
362- if ('bluray' in self ['path' ].lower () or
363- 'blu-ray' in self ['path' ].lower ()):
364- return 'BluRay'
365- # todo: 3d
366- elif ('web-dl' in self ['path' ].lower () or
367- 'webdl' in self ['path' ].lower ()):
362+ regpath = self ['path' ].lower ().strip ('-' )
363+ if 'bluray' in regpath :
364+ return 'BluRay' # todo: 3d
365+ elif 'webdl' in regpath :
368366 return 'WEB-DL'
369- elif 'webrip' in self [ 'path' ]. lower () :
367+ elif 'webrip' in regpath :
370368 return 'WebRip'
371- elif 'hdtv' in self [ 'path' ]. lower () :
369+ elif 'hdtv' in regpath :
372370 return 'HDTV'
373371 # elif 'dvdscr' in self['path'].lower():
374372 # markers['source'] = 'DVDSCR'
@@ -393,14 +391,15 @@ def _render_container(self):
393391 elif general ['format' ] == 'BDAV' :
394392 return 'm2ts'
395393 else :
396- raise Exception ("Unknown or unsupported container: %r" % (general .format ,))
394+ raise RuntimeError ("Unknown or unsupported container '{}'" .format (
395+ general .format ))
397396
398397 def _render_video_codec (self ):
399398 video_track = self ['tracks' ]['video' ]
400399 # norm_bitrate = (float(bit_rate) /
401400 # (video_track.width*video_track.height))
402401 if (video_track ['codec_id' ] in ('V_MPEG4/ISO/AVC' , 'AVC' , 'avc1' ) or
403- video_track ['format' ] == 'AVC' ):
402+ video_track ['format' ] == 'AVC' ):
404403 if 'x264' in video_track .get ('writing_library' , '' ):
405404 return 'x264'
406405 else :
@@ -419,14 +418,15 @@ def _render_video_codec(self):
419418 elif video_track ['format' ] == 'MPEG Video' :
420419 return 'MPEG-2'
421420 else :
422- raise Exception ("Unknown or unsupported video codec: %r, %r" %
423- (video_track .get ('codec_id' , '[NO CODEC]' ),
424- video_track .get ('writing_library' , '[NO LIBRARY]' )))
421+ msg = "Unknown or unsupported video codec '{}' ({})" .format (
422+ video_track .get ('codec_id' ),
423+ video_track .get ('writing_library' ))
424+ raise RuntimeError (msg )
425425
426426 def _render_audio_codec (self ):
427427 audio_track = self ['tracks' ]['audio' ][0 ] # main audio track
428428 if (audio_track .get ('codec_id_hint' ) == 'MP3' or
429- audio_track ['codec_id' ] in ('MPA1L3' , '55' )):
429+ audio_track ['codec_id' ] in ('MPA1L3' , '55' )):
430430 return 'MP3'
431431 elif audio_track ['codec_id' ].lower ().startswith ('mp4a' ):
432432 return 'AAC'
@@ -439,19 +439,21 @@ def _render_audio_codec(self):
439439
440440 if audio_track ['codec_id' ].startswith ('A_' ):
441441 audio_track ['codec_id' ] = audio_track ['codec_id' ][2 :]
442- audio_codecs = ('AC3' , 'EAC3' , 'DTS' , 'FLAC' , 'AAC' , 'MP3' , 'TRUEHD' , 'PCM' )
442+ audio_codecs = ('AC3' , 'EAC3' , 'DTS' , 'FLAC' , 'AAC' , 'MP3' , 'TRUEHD' ,
443+ 'PCM' )
443444 for c in audio_codecs :
444445 if audio_track ['codec_id' ].startswith (c ):
445446 c = c .replace ('EAC3' , 'AC-3' ) \
446447 .replace ('AC3' , 'AC-3' ) \
447448 .replace ('TRUEHD' , 'True-HD' )
448449 return c
449450
450- raise Exception ("Unknown or unsupported audio codec: %r" %
451- ( audio_track ['codec_id' ], ))
451+ raise ValueError ("Unknown or unsupported audio codec '{}'" . format (
452+ audio_track ['codec_id' ]))
452453
453454 def _render_resolution (self ):
454- resolutions = ('2160p' , '1080p' , '720p' , '1080i' , '720i' , '480p' , '480i' , 'SD' )
455+ resolutions = ('2160p' , '1080p' , '720p' , '1080i' , '720i' ,
456+ '480p' , '480i' , 'SD' )
455457
456458 # todo: replace with regex?
457459 # todo: compare result with mediainfo
@@ -594,7 +596,7 @@ def imdb_link(r):
594596 [b]Writer(s)[/b]: {writers}
595597 [b]Content rating[/b]: {contentrating}""" ).format (
596598 title = s ['episode_title' ],
597- links = ", " .join (bb .link (* l ) for l in links ),
599+ links = ", " .join (bb .link (* l ) for l in links ), # noqa: E741
598600 air_date = s ['air_date' ],
599601 network = s ['network' ],
600602 rating = rating_bb ,
@@ -713,7 +715,7 @@ def imdb_link(r):
713715 [b]Director(s)[/b]: {directors}
714716 [b]Writer(s)[/b]: {writers}
715717 [b]Cast[/b]: {cast}""" ).format (
716- links = ", " .join (bb .link (* l ) for l in links ),
718+ links = ", " .join (bb .link (* l ) for l in links ), # noqa: E741
717719 name = summary ['name' ],
718720 mpaa = summary ['mpaa' ],
719721 rating = bb .format_rating (summary ['rating' ][0 ],
0 commit comments