mirror of https://gitlab.com/bashrc2/epicyon
Get video transcript
parent
8b15721674
commit
9d97665c95
26
daemon.py
26
daemon.py
|
@ -146,6 +146,7 @@ from media import replace_you_tube
|
|||
from media import replace_twitter
|
||||
from media import attach_media
|
||||
from media import path_is_video
|
||||
from media import path_is_transcript
|
||||
from media import path_is_audio
|
||||
from blocking import import_blocking_file
|
||||
from blocking import export_blocking_file
|
||||
|
@ -8931,6 +8932,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
"""
|
||||
if is_image_file(path) or \
|
||||
path_is_video(path) or \
|
||||
path_is_transcript(path) or \
|
||||
path_is_audio(path):
|
||||
media_str = path.split('/media/')[1]
|
||||
media_filename = base_dir + '/media/' + media_str
|
||||
|
@ -8947,6 +8949,30 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
last_modified_time_str = \
|
||||
last_modified_time.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
||||
|
||||
if media_filename.endswith('.vtt'):
|
||||
media_transcript = None
|
||||
try:
|
||||
with open(media_filename, 'r',
|
||||
encoding='utf-8') as fp_vtt:
|
||||
media_transcript = fp_vtt.read()
|
||||
media_file_type = 'text/vtt'
|
||||
except OSError:
|
||||
print('EX: unable to read media binary ' +
|
||||
media_filename)
|
||||
if media_transcript:
|
||||
self._set_headers_etag(media_filename, media_file_type,
|
||||
media_transcript, None,
|
||||
None, True,
|
||||
last_modified_time_str)
|
||||
self._write(media_transcript)
|
||||
fitness_performance(getreq_start_time,
|
||||
self.server.fitness,
|
||||
'_GET', '_show_media',
|
||||
self.server.debug)
|
||||
return
|
||||
self._404()
|
||||
return
|
||||
|
||||
media_binary = None
|
||||
try:
|
||||
with open(media_filename, 'rb') as av_file:
|
||||
|
|
10
media.py
10
media.py
|
@ -640,7 +640,7 @@ def attach_media(base_dir: str, http_prefix: str,
|
|||
'mediaType': 'text/vtt',
|
||||
'name': system_language,
|
||||
'type': 'Document',
|
||||
'url': http_prefix + '://' + domain + '/' + media_path
|
||||
'url': http_prefix + '://' + domain + '/' + media_path + '.vtt'
|
||||
}
|
||||
post_json['attachment'].append(video_transcript_json)
|
||||
|
||||
|
@ -697,6 +697,14 @@ def path_is_video(path: str) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def path_is_transcript(path: str) -> bool:
|
||||
"""Is the given path a video transcript WebVTT file?
|
||||
"""
|
||||
if path.endswith('.vtt'):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def path_is_audio(path: str) -> bool:
|
||||
"""Is the given path an audio file?
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue