diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a0a2ee --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.blend* \ No newline at end of file diff --git a/Makefile b/Makefile index e9a6091..9aa809d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ VER=$(shell cat ./version.txt) +DEMO=$(shell realpath ./demo.blend) build: update zip btt-$(VER).zip ./__init__.py ./blender_manifest.toml @@ -9,3 +10,5 @@ update: server: python3 -m http.server -d ./docs/ +demo: + flatpak run org.blender.Blender $(DEMO) \ No newline at end of file diff --git a/README.md b/README.md index eff0be7..436743c 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,18 @@ [Converter](https://moixllik.github.io/btt/converter) `.srt` and `.vtt` to `.btt` ``` -file=./subtitle.btt +@channel=1; +@font_size=120.0; +@color=#ff0000ff; +@use_box=1; +@box_color=#000000ff; + +file=./subtitles.btt; start=00:00:00+0; end=00:00:03+0; -channel=1; -font_size=120.0; -color=#ff0000ff; location=0.3 0.3; align_x=left; align_y=bottom; -use_box=1; -box_color=#000000ff; wrap_width=0.5; Blender Video Text Tracks Videos diff --git a/__init__.py b/__init__.py index 01d594c..6fe001d 100644 --- a/__init__.py +++ b/__init__.py @@ -65,45 +65,62 @@ def subtitles_active(count): scene["frame_final_end"] = frame_final_end return strip +def subtitles_strip_prop(strip, name, value): + match name: + case "start": + strip.frame_start = subtitles_from_time(value) + case "end": + frame_final_end = subtitles_from_time(value) + strip.frame_final_end = frame_final_end + bpy.context.scene["frame_final_end"] = frame_final_end + case "channel": + strip.channel = int(value) + case "location": + x, y = value.split(" ") + strip.location = (float(x), float(y)) + case "align_x": + strip.align_x = value.upper() + case "align_y": + strip.align_y = value.upper() + case "font_size": + strip.font_size = float(value) + case "use_box": + strip.use_box = True + case "wrap_width": + strip.wrap_width = float(value) + case "color": + strip.color = subtitles_from_rgba(value) + case "box_color": + strip.box_color = subtitles_from_rgba(value) + case _: + return True + +def subtitles_scene_props(scene, strip): + for name in scene.keys(): + if name[0] == '@': + value = scene[name] + subtitles_strip_prop(strip, name[1:], value) + def subtitles_props(strip, source): + scene = bpy.context.scene props = source.split(";\n") if isinstance(props, list): for prop in props[:-1]: name, value = prop.strip().split("=") name = name.strip() value = value.strip() - match name: - case "start": - strip.frame_start = subtitles_from_time(value) - case "end": - frame_final_end = subtitles_from_time(value) - strip.frame_final_end = frame_final_end - bpy.context.scene["frame_final_end"] = frame_final_end - case "channel": - strip.channel = int(value) - case "location": - x, y = value.split(" ") - strip.location = (float(x), float(y)) - case "align_x": - strip.align_x = value.upper() - case "align_y": - strip.align_y = value.upper() - case "font_size": - strip.font_size = float(value) - case "use_box": - strip.use_box = True - case "wrap_width": - strip.wrap_width = float(value) - case "color": - strip.color = subtitles_from_rgba(value) - case "box_color": - strip.box_color = subtitles_from_rgba(value) - case _: - strip[name] = value - - strip.text = props[-1] - + + if name[0] == '@': + scene[name] = value + elif subtitles_strip_prop(strip, name, value): + strip[name] = value + + if len(props[-1]) > 0: + strip.text = props[-1] + subtitles_scene_props(scene,strip) + else: + bpy.context.scene.sequence_editor.sequences.remove(strip) def subtitles_strip_text(count, source): strip = subtitles_active(count) diff --git a/docs/index.html b/docs/index.html index 0ae11f1..9f07aed 100644 --- a/docs/index.html +++ b/docs/index.html @@ -22,19 +22,20 @@

Blender Video Text Tracks

BTT File

- For example: ./subtitles.btt + For example: ./subtitles.btt
-        file=./subtitles.btt
+        @channel=1;
+@font_size=120.0;
+@color=#ff0000ff;
+@use_box=1;
+@box_color=#000000ff;
+
+file=./subtitles.btt;
 start=00:00:00+0;
 end=00:00:03+0;
-channel=1;
-font_size=120.0;
-color=#ff0000ff;
 location=0.3 0.3;
 align_x=left;
 align_y=bottom;
-use_box=1;
-box_color=#000000ff;
 wrap_width=0.5;
 Blender Video Text Tracks
 Videos
diff --git a/docs/subtitles.btt b/docs/subtitles.btt
new file mode 100644
index 0000000..6ba5e1e
--- /dev/null
+++ b/docs/subtitles.btt
@@ -0,0 +1,17 @@
+@channel=1;
+@font_size=120.0;
+@color=#ff0000ff;
+@use_box=1;
+@box_color=#000000ff;
+
+file=./subtitles.btt;
+start=00:00:00+0;
+end=00:00:03+0;
+location=0.3 0.3;
+align_x=left;
+align_y=bottom;
+wrap_width=0.5;
+Blender Video Text Tracks
+Videos
+with
+Subtitles
\ No newline at end of file
diff --git a/version.txt b/version.txt
index 17e51c3..d917d3e 100644
--- a/version.txt
+++ b/version.txt
@@ -1 +1 @@
-0.1.1
+0.1.2