Skip to content

Commit

Permalink
replace-omxplayer #comment Ensure using the right language code when …
Browse files Browse the repository at this point in the history
…downloading subtitles.
  • Loading branch information
Tastyep committed Jun 5, 2020
1 parent 0aa593f commit 57f7ea6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions OpenCast/infra/media/downloader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List

import youtube_dl
from youtube_dl import YoutubeDL
from youtube_dl.utils import ISO639Utils

import structlog
from OpenCast.infra.event.downloader import DownloadError, DownloadSuccess
Expand Down Expand Up @@ -29,7 +30,7 @@ def impl():
"quiet": True,
"progress_hooks": [self._dl_logger.log_download_progress],
}
ydl = youtube_dl.YoutubeDL(options)
ydl = YoutubeDL(options)
with ydl: # Download the video
try:
ydl.download([source])
Expand All @@ -49,6 +50,7 @@ def impl():
def download_subtitle(self, url: str, dest: str, lang: str, exts: List[str]):
self._logger.debug("Downloading subtitle", subtitle=dest, lang=lang)

lang = ISO639Utils.long2short(lang)
for ext in exts:
options = {
"skip_download": True,
Expand All @@ -59,7 +61,7 @@ def download_subtitle(self, url: str, dest: str, lang: str, exts: List[str]):
"progress_hooks": [self._dl_logger.log_download_progress],
"quiet": True,
}
ydl = youtube_dl.YoutubeDL(options)
ydl = YoutubeDL(options)
with ydl:
try:
ydl.download([url])
Expand Down Expand Up @@ -103,7 +105,7 @@ def _download_stream_metadata(self, url, options):
"progress_hooks": [self._dl_logger.log_download_progress],
}
)
ydl = youtube_dl.YoutubeDL(options)
ydl = YoutubeDL(options)
with ydl:
try:
return ydl.extract_info(url, download=False)
Expand Down

0 comments on commit 57f7ea6

Please sign in to comment.