font size, fix path fallback

This commit is contained in:
j 2024-08-30 17:16:03 +02:00
parent 401203cd83
commit 48055c1907

14
edit.py
View file

@ -95,12 +95,12 @@ def sort_clips(edit, sort):
def get_pandora_media_path(oshash): def get_pandora_media_path(oshash):
h = oshash h = oshash
path = '/srv/pandora/data/media/' + '/'.join([h[:2], h[2:4], h[4:6], h[6:]]) prefix = '/srv/pandora/data/media/' + '/'.join([h[:2], h[2:4], h[4:6], h[6:]])
path = glob('%s/data.*' % path) path = glob('%s/data.*' % prefix)
if path: if path:
path = path[0] path = path[0]
else: else:
path = ox.sorted_strings(glob('%s/*.mp4' % path))[-1] path = ox.sorted_strings(glob('%s/*.mp4' % prefix))[-1]
return path return path
def cache_clips(api, videos, use_source=False, use_pandora=False): def cache_clips(api, videos, use_source=False, use_pandora=False):
@ -127,7 +127,7 @@ def cache_clips(api, videos, use_source=False, use_pandora=False):
print(url, out) print(url, out)
api.save_url(url, out) api.save_url(url, out)
def make_title(title): def make_title(title, font_size=30):
from PIL import Image, ImageFont, ImageDraw from PIL import Image, ImageFont, ImageDraw
title_mp4 = "cache/title_%s.mp4" % hashlib.sha1(title.encode()).hexdigest() title_mp4 = "cache/title_%s.mp4" % hashlib.sha1(title.encode()).hexdigest()
title_png = title_mp4.replace('.mp4', '.png') title_png = title_mp4.replace('.mp4', '.png')
@ -135,7 +135,7 @@ def make_title(title):
width = 852 width = 852
height = 480 height = 480
image = Image.new("RGB", (width, height), "black") image = Image.new("RGB", (width, height), "black")
font = ImageFont.truetype("/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-Bold.ttf", size=30) font = ImageFont.truetype("/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/Roboto-Bold.ttf", size=font_size)
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
_, _, font_width, font_height = font.getbbox(title) _, _, font_width, font_height = font.getbbox(title)
new_width = (width - font_width) / 2 new_width = (width - font_width) / 2
@ -174,6 +174,8 @@ if __name__ == '__main__':
help="resolution of streams to download i.e. 480, 240, 96 default 480", default=480) help="resolution of streams to download i.e. 480, 240, 96 default 480", default=480)
parser.add_argument('-t', '--title', dest='title', type=str, parser.add_argument('-t', '--title', dest='title', type=str,
help="title", default="") help="title", default="")
parser.add_argument('', '--font-size', dest='font_size', type=int,
help="title font size", default=30)
parser.add_argument('-c', '--config', dest='config', parser.add_argument('-c', '--config', dest='config',
help='config.json containing config', help='config.json containing config',
default='~/.ox/client.json') default='~/.ox/client.json')
@ -241,7 +243,7 @@ if __name__ == '__main__':
position = 0 position = 0
clips = sort_clips(edit, sort_by) clips = sort_clips(edit, sort_by)
if opts.title: if opts.title:
clips.insert(0, make_title(opts.title)) clips.insert(0, make_title(opts.title, opts.font_size))
for clip in clips: for clip in clips:
if clip.get("titletext"): if clip.get("titletext"):
videos.append(clip) videos.append(clip)