]> git.mdlowis.com Git - proto/atv.git/commitdiff
added subtitles and script to generate them using whisper
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 26 Mar 2024 03:08:06 +0000 (23:08 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 26 Mar 2024 03:08:06 +0000 (23:08 -0400)
atv/assets/index.html
atv/bin/atv-gensubs [new file with mode: 0644]
atv/bin/atv-index [new file with mode: 0644]
atv/lib/atv/database.rb

index f6fad0f639475c3a4cb1237bd5e082c41e18e71b..01f261b0b6a69e05ad370737f8627070e0cba174 100644 (file)
 <body>
 
 <video id="Video" width="100%" height="100%" src="" autoplay muted playsinline>
+    <track id="SubtitleTrack"
+        label="English"
+        kind="subtitles"
+        srclang="en"
+        src=""
+        default />
 </video>
 
 <div class="badge" style="left: 1em;">
@@ -69,6 +75,7 @@ const updatePlayer = (prev)=>{
     if (diffTooBig || srcChanged || playStateChanged || chanChanged)
     {
         Video.src = current["curr"]["path"] + "#t=" + elapsed;
+        SubtitleTrack.src = current["curr"]["path"] + ".vtt";
         if (current["playing"])
         {
             Video.play();
diff --git a/atv/bin/atv-gensubs b/atv/bin/atv-gensubs
new file mode 100644 (file)
index 0000000..f8c0464
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/env ruby
+
+TYPES = "{mp4,ogg,webm,avi}"
+FILES = ARGV.map {|f| Dir.glob("#{f}/**/*.#{TYPES}") }.flatten
+FILES.each do |f|
+  if not File.exist? "#{f}.vtt"
+    puts f
+    system("whisper \"#{f}\" --model small.en --language en -f vtt --threads 4 > \"#{f}.vtt.tmp\"")
+    FileUtils.mv("#{f}.vtt.tmp", "#{f}.vtt")
+  end
+end
diff --git a/atv/bin/atv-index b/atv/bin/atv-index
new file mode 100644 (file)
index 0000000..094ced7
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/env ruby
+
+TYPES = "{mp4,ogg,webm}"
+FILES = ARGV.map {|f| Dir.glob("#{f}/**/*.#{TYPES}") }.flatten
+FILES.each do |f|
+end
+
index abd613ea01520d3a5ffca6605215f64625f721e8..829376c5aef1d88432cb9ded11fbbc215f91cb9c 100644 (file)
@@ -53,7 +53,7 @@ module ATV
     def scan()
       # scan for videos
       @dirs.each do |dir|
-        Dir.glob("#{@root}/#{dir}/**/*.{mp4,webm,ogg}").each do |f|
+        Dir.glob("#{@root}/#{dir}/**/*.{mp4,m4v,webm,ogg}").each do |f|
           short_path = f.sub("#{@root}/", '')
           next if @data[short_path]
           puts f