Skip to content

Commit

Permalink
allow requesting subtitles for url (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
joschahenningsen authored Feb 15, 2023
1 parent ee39814 commit 6f90b89
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions subtitles/subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from transcriber import Transcriber
from tasks import GenerationTask
from worker import Worker

import urllib3

class SubtitleServerService(subtitles_pb2_grpc.SubtitleGeneratorServicer):
"""grpc service for subtitles"""
Expand All @@ -42,7 +42,18 @@ def Generate(self, req: subtitles_pb2.GenerateRequest,
stream_id: str = req.stream_id

logging.debug(f'checking if {source} exists')
if not os.path.isfile(source):

if source.startswith("https://"):
http = urllib3.PoolManager()
try:
r = http.request('GET', source)
except urllib3.exceptions.HTTPError:
context.abort(grpc.StatusCode.NOT_FOUND, f'source url unavailable: {source}')
return
if r.status != 200:
context.abort(grpc.StatusCode.NOT_FOUND, f'source url replies with status {r.status}: {source}')
return
elif not os.path.isfile(source):
context.abort(grpc.StatusCode.NOT_FOUND, f'can not find source file: {source}')
return

Expand Down

0 comments on commit 6f90b89

Please sign in to comment.