Compare commits

..

No commits in common. 'feb00df8c5fe90db2ee4628c89aac0546d645297' and '3313298fa289f7c45831e4fd90f963f84d24b4c5' have entirely different histories.

  1. 9
      create_open_workout_database.py
  2. 0
      exercise_config.py
  3. 4
      load_exercises.py
  4. 29
      map_yaml_to_database.py
  5. 6
      open_workout_coach/__init__.py
  6. 27
      open_workout_coach/__main__.py
  7. 0
      open_workout_coach/cli.py
  8. 17
      readme.md
  9. 4
      requirements.txt

9
open_workout_coach/create_open_workout_database.py → create_open_workout_database.py

@ -69,12 +69,8 @@ def get_item_id():
start += 1 start += 1
def create_item( def create_item(name, workout_time, n_repetitions, description=None, preparation_time=5, video_path=None):
name, workout_time=30, n_repetitions=None, description=None,
preparation_time=5, video_path=None, break_time=5
):
is_video_mode = True if video_path else False is_video_mode = True if video_path else False
is_time_mode = False if n_repetitions else True
new_item = dict(WOPRKOUT_ITEM) new_item = dict(WOPRKOUT_ITEM)
new_item_content = { new_item_content = {
@ -83,14 +79,13 @@ def create_item(
'elapsedTime': 0, 'elapsedTime': 0,
'imagePath': '', 'imagePath': '',
'isImagePathExternal': False, 'isImagePathExternal': False,
'isTimeMode': is_time_mode, 'isTimeMode': True,
'isVideoMode': is_video_mode, 'isVideoMode': is_video_mode,
'prepTime': preparation_time, 'prepTime': preparation_time,
'repetitionCount': n_repetitions, 'repetitionCount': n_repetitions,
'videoPath': video_path, 'videoPath': video_path,
"orderNr": next(get_item_id()), "orderNr": next(get_item_id()),
"workoutItemId": 0, "workoutItemId": 0,
"breakTime": break_time,
"workoutSessionId": 1, "workoutSessionId": 1,
'workoutTime': workout_time 'workoutTime': workout_time
} }

0
open_workout_coach/exercise_config.py → exercise_config.py

4
open_workout_coach/load_exercises.py → load_exercises.py

@ -13,14 +13,13 @@ def get_video(url):
return output_dir return output_dir
@lru_cache(5)
def create_gif_from_video_and_timestamps(video_path, start, end): def create_gif_from_video_and_timestamps(video_path, start, end):
video = mpy.VideoFileClip(video_path) video = mpy.VideoFileClip(video_path)
clip: mpy.VideoFileClip = video.subclip(start, end) clip: mpy.VideoFileClip = video.subclip(start, end)
output_dir = tempfile.mktemp() + '.mp4' output_dir = tempfile.mktemp() + '.mp4'
clip.without_audio().write_videofile(output_dir) clip.without_audio().write_videofile(output_dir)
return output_dir return output_dir
def load_file_and_media_links(file_path): def load_file_and_media_links(file_path):
file = open(file_path) file = open(file_path)
@ -30,6 +29,7 @@ def load_file_and_media_links(file_path):
video_url = ex['video'] video_url = ex['video']
start = ex['start'] start = ex['start']
end = ex['end'] end = ex['end']
video_path = get_video(video_url) video_path = get_video(video_url)
gif = create_gif_from_video_and_timestamps(video_path, start, end) gif = create_gif_from_video_and_timestamps(video_path, start, end)
ex['gif_path'] = gif ex['gif_path'] = gif

29
open_workout_coach/map_yaml_to_database.py → map_yaml_to_database.py

@ -3,7 +3,8 @@ import tempfile
import zipfile import zipfile
import os import os
from open_workout_coach.create_open_workout_database import create_workout_session, create_item, create_workout_database from load_exercises import load_file_and_media_links
from create_open_workout_database import create_workout_session, create_item, create_workout_database
ITEM_KEY_MEDIA_TYPE_MAP = { ITEM_KEY_MEDIA_TYPE_MAP = {
@ -84,29 +85,37 @@ def map_config_to_workout_file(config):
items = [ items = [
create_item( create_item(
name=item['name'], name=item['name'],
workout_time=item.get('duration'), workout_time=30,
n_repetitions=item.get('repetitions'), n_repetitions=1,
description=item.get('description'), description=None,
preparation_time=item.get('preparation'), preparation_time=5,
break_time=item.get('break'), video_path=item['gif_path']
video_path=item.get('gif_path')
) )
for item in config['exercises'] for item in config['exercises']
] ]
sessions = [create_workout_session(items)] * config['n_sessions'] sessions = [create_workout_session(items)] * 30
db = create_workout_database(config['name'], sessions) db = create_workout_database(config['name'], sessions)
return db return db
def process_config_into_workout_file(config, output_destination = None): def process_config_into_workout_file(config, output_file = None):
db = map_config_to_workout_file(config) db = map_config_to_workout_file(config)
videos = get_all_media_from_db_by_type(db, media_type='video') videos = get_all_media_from_db_by_type(db, media_type='video')
images = get_all_media_from_db_by_type(db, media_type='image') images = get_all_media_from_db_by_type(db, media_type='image')
db = refactor_media_paths_in_db(db) db = refactor_media_paths_in_db(db)
output_file_name = f"{output_destination or '.'}/{db['name']}.zip" output_file_name = output_file or f"{db['name']}.zip"
save_workout_file( save_workout_file(
output_files=output_file_name, output_files=output_file_name,
db_file=db, db_file=db,
video_files=videos, video_files=videos,
) )
FILE = 'data/input/samples/exercises.yaml'
if __name__ == '__main__':
config = load_file_and_media_links(FILE)
process_config_into_workout_file(config)

6
open_workout_coach/__init__.py

@ -1,6 +0,0 @@
from . import (
load_exercises,
map_yaml_to_database,
create_open_workout_database,
exercise_config
)

27
open_workout_coach/__main__.py

@ -1,27 +0,0 @@
import click
from open_workout_coach.load_exercises import load_file_and_media_links
from open_workout_coach.map_yaml_to_database import process_config_into_workout_file
@click.group("cli")
def cli():
pass
@cli.command()
@click.argument('input_path', type=click.Path(exists=True))
@click.argument('output_destination', type=click.Path(exists=True))
def create_plan(input_path, output_destination):
"""
Creates a openworkout plan from the input yaml file.
"""
config = load_file_and_media_links(file_path=input_path)
process_config_into_workout_file(config=config, output_destination=output_destination)
FILE = 'data/input/samples/exercises.yaml'
if __name__ == '__main__':
cli()

0
open_workout_coach/cli.py

17
readme.md

@ -3,16 +3,15 @@ Creates a workout plan form an yaml file that can be imported to <img src="https
Inputs can be of format Inputs can be of format
```yaml ```yaml
name: name of workout plan
n_sessions: 1
exercises: exercises:
- name: Shoulder Stretch (Up-Left) - name: nomoney
start: 209 video: "https://www.youtube.com/watch?v=etAwQ4jzyNY"
end: 212 start: 74
video: https://www.youtube.com/watch?v=TSIbzfcnv_8 end: 80
break: 0 - name: plank shoulder tap
duration: 10 video: "https://www.youtube.com/watch?v=etAwQ4jzyNY"
preparation: 3 start: 113
end: 116
``` ```
The script will download the video and create short clips. The script will download the video and create short clips.

4
requirements.txt

@ -1,6 +1,4 @@
pyyaml pyyaml
pytube pytube
moviepy moviepy
imageio imageio
ffmpeg-python
click
Loading…
Cancel
Save