You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.0 KiB
39 lines
1.0 KiB
1 year ago
|
import yaml
|
||
|
import pytube
|
||
|
import tempfile
|
||
|
from functools import lru_cache
|
||
|
import moviepy.editor as mpy
|
||
|
|
||
|
|
||
|
@lru_cache(5)
|
||
|
def get_video(url):
|
||
|
output_dir = tempfile.mktemp()
|
||
|
video = pytube.YouTube(url)
|
||
|
video.streams.filter(res="360p").first().download(filename=output_dir)
|
||
|
return output_dir
|
||
|
|
||
1 year ago
|
|
||
1 year ago
|
@lru_cache(5)
|
||
1 year ago
|
def create_gif_from_video_and_timestamps(video_path, start, end):
|
||
|
video = mpy.VideoFileClip(video_path)
|
||
|
clip: mpy.VideoFileClip = video.subclip(start, end)
|
||
|
output_dir = tempfile.mktemp() + '.mp4'
|
||
|
clip.without_audio().write_videofile(output_dir)
|
||
|
return output_dir
|
||
|
|
||
|
|
||
1 year ago
|
def load_file_and_media_links(file_path):
|
||
|
file = open(file_path)
|
||
1 year ago
|
exercises = yaml.safe_load(file)
|
||
|
for ex in exercises['exercises']:
|
||
|
name = ex['name']
|
||
|
video_url = ex['video']
|
||
|
start = ex['start']
|
||
|
end = ex['end']
|
||
1 year ago
|
|
||
1 year ago
|
video_path = get_video(video_url)
|
||
|
gif = create_gif_from_video_and_timestamps(video_path, start, end)
|
||
|
ex['gif_path'] = gif
|
||
|
|
||
1 year ago
|
return exercises
|