Titlecase the homepath and try except creating hash for filename.

This commit is contained in:
2018-09-20 23:25:47 +02:00
parent 1fc62479be
commit 4b09d6cd2c

View File

@@ -13,6 +13,7 @@ import logging
import tvdb_api import tvdb_api
import click import click
from pprint import pprint from pprint import pprint
from titlecase import titlecase
import env_variables as env import env_variables as env
@@ -72,12 +73,15 @@ def scan_video(path):
video.size = os.path.getsize(path) video.size = os.path.getsize(path)
# hash of name # hash of name
if isinstance(video, Movie): try:
hash_str = ''.join([video.title, str(video.year) or '']) if isinstance(video, Movie):
elif isinstance(video, Episode): hash_str = ''.join([video.title, str(video.year) or ''])
hash_str = ''.join([video.series, str(video.season), str(video.episode)]) elif isinstance(video, Episode):
videoHash = hashlib.md5(hash_str.encode()).hexdigest() hash_str = ''.join([video.series, str(video.season), str(video.episode)])
video.hash = videoHash videoHash = hashlib.md5(hash_str.encode()).hexdigest()
video.hash = videoHash
except:
print(video)
return video return video
@@ -96,7 +100,6 @@ def scan_subtitle(path):
return subtitle return subtitle
def scan_videos(path): def scan_videos(path):
"""Scan `path` for videos and their subtitles. """Scan `path` for videos and their subtitles.
@@ -118,7 +121,7 @@ def scan_videos(path):
# setup progress bar # setup progress bar
path_children = 0 path_children = 0
for _ in os.walk(path): path_children += 1 for _ in os.walk(path): path_children += 1
with click.progressbar(length=path_children, show_pos=True, label='Searching folders for videos') as bar: with click.progressbar(length=path_children, show_pos=True, label='Collecting videos') as bar:
# walk the path # walk the path
videos = [] videos = []
@@ -270,7 +273,7 @@ def scan_folder(path):
return videos return videos
def movingToCollege(video, home_path): def movingToCollege(video, home_path):
video.home = home_path video.home = titlecase(home_path)
def pickforgirlscouts(video): def pickforgirlscouts(video):
if isinstance(video, Movie): if isinstance(video, Movie):
@@ -281,14 +284,14 @@ def pickforgirlscouts(video):
elif isinstance(video, Episode): elif isinstance(video, Episode):
if video.series != None and video.season != None and video.episode != None and type(video.episode) != list: if video.series != None and video.season != None and video.episode != None and type(video.episode) != list:
home_path = '{} S{:02d}E{:02d}'.format(video.series, video.season, video.episode) home_path = '{} S{}E{}'.format(str(video.series), str(video.season), str(video.episode))
movingToCollege(video, home_path) movingToCollege(video, home_path)
return True return True
return False return False
def main(): def main():
path = '/mnt/rescue/' path = '/mnt/mainframe/'
videos = scan_folder(path) videos = scan_folder(path)
@@ -310,8 +313,8 @@ def main():
's' if len(videos) > 1 else '' 's' if len(videos) > 1 else ''
)) ))
for video in civilian: for video in scout:
print(video) print('{} lives: {}'.format(video, video.home))
if __name__ == '__main__': if __name__ == '__main__':
main() main()