Remove karaoke ass generation, now in negromate.songs 1.2
This commit is contained in:
parent
22aad839e3
commit
cf7fff35ae
|
@ -1,7 +1,5 @@
|
|||
import os
|
||||
from shutil import copy
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
|
@ -10,8 +8,6 @@ import srt
|
|||
|
||||
from negromate.songs.loader import load_songs
|
||||
|
||||
from .karaoke_templates import update_karaoke_songs
|
||||
|
||||
|
||||
class SongPage:
|
||||
def __init__(self, song):
|
||||
|
@ -114,9 +110,6 @@ class Builder:
|
|||
todo_context.update(global_context)
|
||||
self.render('todo.html', todo, todo_context)
|
||||
|
||||
template_file = self.template_folder / 'karaoke.ass'
|
||||
update_karaoke_songs(songs, template_file)
|
||||
|
||||
static = self.root_folder / 'static'
|
||||
|
||||
if not static.exists():
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
import os
|
||||
import subprocess
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
|
||||
import ass
|
||||
|
||||
from negromate.songs.utils import needs_change
|
||||
|
||||
|
||||
@contextmanager
|
||||
def Xephyr_env(display=":2", *args, **kwargs):
|
||||
env = os.environ.copy()
|
||||
xephyr = subprocess.Popen(["Xephyr", display])
|
||||
env['DISPLAY'] = display
|
||||
try:
|
||||
yield env
|
||||
finally:
|
||||
xephyr.kill()
|
||||
|
||||
def set_template(template_subtitles, orig_file, target_file=None):
|
||||
if target_file is None:
|
||||
target_file = orig_file
|
||||
|
||||
with open(orig_file, 'r') as orig:
|
||||
subtitles = ass.parse(orig)
|
||||
|
||||
new_events = []
|
||||
for dialogue in template_subtitles.events:
|
||||
new_events.append(dialogue)
|
||||
|
||||
for dialogue in subtitles.events:
|
||||
if dialogue.effect.startswith('code'):
|
||||
continue
|
||||
if dialogue.effect.startswith('template'):
|
||||
continue
|
||||
new_events.append(dialogue)
|
||||
|
||||
subtitles.events = new_events
|
||||
|
||||
with open(target_file, 'w', encoding='utf-8-sig') as target:
|
||||
subtitles.dump_file(target)
|
||||
|
||||
|
||||
def run(command, env, wait=None):
|
||||
program = subprocess.Popen(
|
||||
command,
|
||||
env=env,
|
||||
)
|
||||
if wait is not None:
|
||||
time.sleep(wait)
|
||||
|
||||
|
||||
def apply_template(subtitles, env):
|
||||
run(["aegisub-3.2", subtitles], env=env, wait=2)
|
||||
|
||||
# Si pide confirmación para cargar video ignorar el popup
|
||||
run(["xdotool", "key", "Escape"], env=env, wait=0.1)
|
||||
|
||||
# abrir el menú de automatización, bajar dos y darle a aplicar template
|
||||
run(["xdotool", "key", "alt+u"], env=env, wait=0.1)
|
||||
run(["xdotool", "key", "Down"], env=env, wait=0.1)
|
||||
run(["xdotool", "key", "Down"], env=env, wait=0.1)
|
||||
run(["xdotool", "key", "Return"], env=env, wait=2)
|
||||
|
||||
# guardar
|
||||
run(["xdotool", "key", "ctrl+s"], env=env)
|
||||
|
||||
# cerrar programa
|
||||
run(["xdotool", "key", "ctrl+q"], env=env)
|
||||
|
||||
|
||||
def update_karaoke_songs(songs, template_file):
|
||||
with open(template_file, 'r') as template:
|
||||
template_subtitles = ass.parse(template)
|
||||
|
||||
with Xephyr_env() as env:
|
||||
for song in songs:
|
||||
if song.metadata.get('karaoke'):
|
||||
target = song.path / "{}.karaoke.ass".format(song.path.name)
|
||||
if needs_change(target, (song.ass, template_file)):
|
||||
set_template(
|
||||
template_subtitles=template_subtitles,
|
||||
orig_file=str(song.ass),
|
||||
target_file=str(target)
|
||||
)
|
||||
time.sleep(2)
|
||||
apply_template(str(target), env)
|
||||
time.sleep(2)
|
|
@ -1,4 +1,4 @@
|
|||
webvtt-py
|
||||
Jinja2
|
||||
ass==0.4.4
|
||||
negromate.songs @ git+https://git.negromate.rocks/NegroMate/songs.git@1.0
|
||||
negromate.songs==1.2
|
||||
|
|
Loading…
Reference in New Issue