From a106a35d42219a04340ddb362ce93cad87540a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Midb=C3=B8e?= Date: Sun, 23 Sep 2018 16:29:41 +0200 Subject: [PATCH] Moved checks for sufficient info in order to move series or movie to the class. Homelocation in now a class function for each movie and series class. --- src/core.py | 25 ++++--------------------- src/video.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/core.py b/src/core.py index 8d06822..387a8b5 100755 --- a/src/core.py +++ b/src/core.py @@ -272,28 +272,11 @@ def scan_folder(path): return videos -def movingToCollege(video, home_path): - video.home = titlecase(home_path) - def pickforgirlscouts(video): - if isinstance(video, Movie): - if video.title != None and video.year != None: - home_path = '{} ({})'.format(video.title, video.year) - try: - movingToCollege(video, home_path) - return True - except: - return False - - elif isinstance(video, Episode): - if video.series != None and video.season != None and video.episode != None and type(video.episode) != list: - # Handle the list problems - home_path = '{} S{:02d}E{:02d}'.format(str(video.series), str(video.season), str(video.episode)) - try: - movingToCollege(video, home_path) - return True - except: - return False + if video.sufficientInfo(): + video.moveLocation() + print(video.home) + return True return False diff --git a/src/video.py b/src/video.py index 3c46eda..c75b297 100644 --- a/src/video.py +++ b/src/video.py @@ -7,6 +7,7 @@ from guessit import guessit import os +from titlecase import titlecase import hashlib, tvdb_api #: Video extensions @@ -165,6 +166,17 @@ class Episode(Video): def fromname(cls, name): return cls.fromguess(name, guessit(name, {'type': 'episode'})) + @classmethod + def sufficientInfo(self): + return None not in [self.series, self.season, self.episode] and list not in [type(self.series), type(self.episode)] + + @classmethod + def moveLocation(self): + series = titlecase(self.series) + grandParent = '{}/{} {:02d}'.format(series, series, self.season) + parent = '{} S{:02d}E{:02d}'.format(series, self.season, self.episode) + self.home = os.path.join(grandParent, parent, self.name) + def __repr__(self): if self.year is None: return '<%s [%r, %dx%s]>' % (self.__class__.__name__, self.series, self.season, self.episode) @@ -204,6 +216,17 @@ class Movie(Video): def fromname(cls, name): return cls.fromguess(name, guessit(name, {'type': 'movie'})) + @classmethod + def sufficientInfo(self): + return None not in [self.title, self.year] + + @classmethod + def moveLocation(self): + title = titlecase(self.title) + parent = '{} ({})'.format(title, self.year) + self.home = os.path.join(parent, self.name) + + def __repr__(self): if self.year is None: return '<%s [%r]>' % (self.__class__.__name__, self.title)