From 141fde05a6549dbda0600737bef3024414933714 Mon Sep 17 00:00:00 2001 From: gabriel becker Date: Sat, 20 Jan 2024 22:58:15 +1100 Subject: [PATCH] Support entries without video --- open_workout_coach/load_exercises.py | 15 +++++++++------ open_workout_coach/map_yaml_to_database.py | 4 +++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/open_workout_coach/load_exercises.py b/open_workout_coach/load_exercises.py index 77deecb..b0bbc1a 100644 --- a/open_workout_coach/load_exercises.py +++ b/open_workout_coach/load_exercises.py @@ -27,11 +27,14 @@ def load_file_and_media_links(file_path): exercises = yaml.safe_load(file) for ex in exercises['exercises']: name = ex['name'] - video_url = ex['video'] - start = ex['start'] - end = ex['end'] - video_path = get_video(video_url) - gif = create_gif_from_video_and_timestamps(video_path, start, end) - ex['gif_path'] = gif + video_url = ex.get('video') + start = ex.get('start') + end = ex.get('end') + if video_url: + video_path = get_video(video_url) + gif = create_gif_from_video_and_timestamps(video_path, start, end) + ex['gif_path'] = gif + else: + ex['gif_path'] = None return exercises diff --git a/open_workout_coach/map_yaml_to_database.py b/open_workout_coach/map_yaml_to_database.py index 9f4970c..dfb883a 100644 --- a/open_workout_coach/map_yaml_to_database.py +++ b/open_workout_coach/map_yaml_to_database.py @@ -18,6 +18,8 @@ def get_all_media_from_db_by_type(db, media_type): for workout_item in session['workoutItems']: media.append(workout_item[item_key]) media = list(set(media)) + if None in media: + media.remove(None) return media @@ -46,7 +48,7 @@ def refactor_media_paths_in_db(db): db_name = db['name'] for session in db['workoutSessions']: for workout_item in session['workoutItems']: - item_has_video = workout_item['videoPath'] != '' + item_has_video = workout_item['videoPath'] not in ('', None) if item_has_video: new_formatted_path = get_remote_formatted_media_path( media_type='video',