mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Adding captions module for videos.
This commit is contained in:
parent
6c32159af3
commit
8f84d31764
9 changed files with 105 additions and 2 deletions
2
TODO.md
2
TODO.md
|
|
@ -14,3 +14,5 @@ Code TODO
|
|||
=========
|
||||
1. Example plugin based off videos plugin
|
||||
1. Check that videos can be removed or renamed
|
||||
1. Plugin has support for systemd so it can start it's own service
|
||||
1. Plugin has support for cronjobs
|
||||
|
|
|
|||
|
|
@ -6,5 +6,4 @@ Jinja2>=2.10.1
|
|||
mock>=3.0.5
|
||||
psycopg2-binary>=2.8.3
|
||||
pyyaml>=5.1.2
|
||||
youtube-dl>=2019.8.13
|
||||
pytest>=5.2.1
|
||||
48
test/example.en.vtt
Normal file
48
test/example.en.vtt
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
WEBVTT
|
||||
Kind: captions
|
||||
Language: en
|
||||
|
||||
00:00:00.000 --> 00:00:05.269 align:start position:0%
|
||||
|
||||
okay<00:00:01.310><c> welcome</c><00:00:02.310><c> to</c><00:00:02.429><c> this</c><00:00:02.550><c> session</c><00:00:04.130><c> this</c><00:00:05.130><c> is</c>
|
||||
|
||||
00:00:05.269 --> 00:00:05.279 align:start position:0%
|
||||
okay welcome to this session this is
|
||||
|
||||
|
||||
00:00:05.279 --> 00:00:07.760 align:start position:0%
|
||||
okay welcome to this session this is
|
||||
called<00:00:05.879><c> the</c><00:00:05.970><c> kinetic</c><00:00:06.420><c> bunny</c><00:00:06.690><c> need</c><00:00:07.319><c> to</c><00:00:07.529><c> meet</c>
|
||||
|
||||
00:00:07.760 --> 00:00:07.770 align:start position:0%
|
||||
called the kinetic bunny need to meet
|
||||
|
||||
|
||||
00:00:07.770 --> 00:00:11.450 align:start position:0%
|
||||
called the kinetic bunny need to meet
|
||||
the<00:00:07.890><c> virtual</c><00:00:08.280><c> bonnie</c><00:00:08.519><c> emilio</c><00:00:09.380><c> stop</c><00:00:10.380><c> this</c><00:00:11.340><c> is</c>
|
||||
|
||||
00:00:11.450 --> 00:00:11.460 align:start position:0%
|
||||
the virtual bonnie emilio stop this is
|
||||
|
||||
|
||||
00:00:11.460 --> 00:00:15.410 align:start position:0%
|
||||
the virtual bonnie emilio stop this is
|
||||
jana<00:00:11.639><c> car</c><00:00:11.880><c> who</c><00:00:13.700><c> just</c><00:00:14.700><c> to</c><00:00:14.759><c> give</c><00:00:14.940><c> a</c><00:00:14.969><c> little</c><00:00:15.030><c> bit</c>
|
||||
|
||||
00:00:15.410 --> 00:00:15.420 align:start position:0%
|
||||
jana car who just to give a little bit
|
||||
|
||||
|
||||
00:00:15.420 --> 00:00:18.859 align:start position:0%
|
||||
jana car who just to give a little bit
|
||||
of<00:00:15.529><c> background</c><00:00:16.529><c> information</c><00:00:17.390><c> we</c><00:00:18.390><c> come</c><00:00:18.630><c> from</c><00:00:18.750><c> a</c>
|
||||
|
||||
00:00:18.859 --> 00:00:18.869 align:start position:0%
|
||||
of background information we come from a
|
||||
|
||||
|
||||
00:00:18.869 --> 00:00:21.109 align:start position:0%
|
||||
of background information we come from a
|
||||
company<00:00:19.109><c> called</c><00:00:19.199><c> le</c><00:00:19.529><c> code</c><00:00:19.740><c> from</c><00:00:20.550><c> finland</c><00:00:20.939><c> and</c>
|
||||
|
||||
1
wrolpi/plugins/example_plugin/requirements.txt
Normal file
1
wrolpi/plugins/example_plugin/requirements.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
# Add your pip requirements here
|
||||
|
|
@ -71,6 +71,7 @@ def json_statuses_streamer(func):
|
|||
'{"success": "stream-complete"}\n'
|
||||
"""
|
||||
|
||||
@wraps(func)
|
||||
def wrap(*a, **kw):
|
||||
yield from (json.dumps({'status': i}) + '\n' for i in func(*a, **kw))
|
||||
yield json.dumps({'success': 'stream-complete'}) + '\n'
|
||||
|
|
|
|||
20
wrolpi/plugins/videos/captions.py
Executable file
20
wrolpi/plugins/videos/captions.py
Executable file
|
|
@ -0,0 +1,20 @@
|
|||
#! /usr/bin/env python3
|
||||
from typing import Generator
|
||||
|
||||
import webvtt
|
||||
|
||||
|
||||
def get_caption_text(vtt_path: str) -> Generator:
|
||||
for caption in webvtt.read(vtt_path):
|
||||
text = str(caption.text).strip()
|
||||
yield text
|
||||
|
||||
|
||||
def get_unique_caption_lines(vtt_path: str) -> Generator:
|
||||
last_line = None
|
||||
for text in get_caption_text(vtt_path):
|
||||
for line in text.split('\n'):
|
||||
if line and line != last_line:
|
||||
last_line = line
|
||||
yield line
|
||||
|
||||
2
wrolpi/plugins/videos/requirements.txt
Normal file
2
wrolpi/plugins/videos/requirements.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
youtube-dl>=2019.8.13
|
||||
webvtt-py==0.4.2
|
||||
30
wrolpi/plugins/videos/test/test_captions.py
Normal file
30
wrolpi/plugins/videos/test/test_captions.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import unittest
|
||||
|
||||
from wrolpi.plugins.videos import captions
|
||||
|
||||
|
||||
class TestCaption(unittest.TestCase):
|
||||
|
||||
def test_example_en_vtt(self):
|
||||
vtt_path = 'test/example.en.vtt'
|
||||
|
||||
expected = ['okay welcome to this session this is',
|
||||
'okay welcome to this session this is',
|
||||
'okay welcome to this session this is\ncalled the kinetic bunny need to meet',
|
||||
'called the kinetic bunny need to meet',
|
||||
'called the kinetic bunny need to meet\nthe virtual bonnie emilio stop this is',
|
||||
'the virtual bonnie emilio stop this is',
|
||||
'the virtual bonnie emilio stop this is\njana car who just to give a little bit',
|
||||
'jana car who just to give a little bit',
|
||||
'jana car who just to give a little bit\nof background information we come from a',
|
||||
'of background information we come from a',
|
||||
'of background information we come from a\ncompany called le code from finland and']
|
||||
self.assertEqual(list(captions.get_caption_text(vtt_path)), expected)
|
||||
|
||||
expected = ['okay welcome to this session this is',
|
||||
'called the kinetic bunny need to meet',
|
||||
'the virtual bonnie emilio stop this is',
|
||||
'jana car who just to give a little bit',
|
||||
'of background information we come from a',
|
||||
'company called le code from finland and']
|
||||
self.assertEqual(list(captions.get_unique_caption_lines(vtt_path)), expected)
|
||||
|
|
@ -21,7 +21,7 @@ ROOT_CONFIG = {
|
|||
class ClientRoot(object):
|
||||
|
||||
def __init__(self):
|
||||
# Install plugins defined in plugins.plugins
|
||||
# Install plugins defined in user_plugins
|
||||
for name, plugin in PLUGINS.items():
|
||||
setattr(self, name, plugin.ClientRoot())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue