Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_failed(self):
video_id = '12323123123'
with self.assertRaises(DownloadException):
self.download.get_captions(video_id)
def test_video_does_not_exist(self):
self.download = Download(
{'urls': ['12323123123'], 'pattern': 'elephants', 'e': False, 'v': False})
with self.assertRaises(DownloadException):
self.download.get_captions()
def get_result(self, video_id: str, language: str = 'en') -> int:
opts = self.opts
if language:
opts['subtitleslangs'] = [*opts.get('subtitleslangs', []), language]
with youtube_dl.YoutubeDL(opts) as ydl:
try:
return ydl.download([self.get_url_from_video_id(video_id)])
except youtube_dl.utils.DownloadError as err:
raise DownloadException(
"Unable to download captions: {0}".format(str(err)))
except youtube_dl.utils.ExtractorError as err:
raise DownloadException(
"Unable to extract captions: {0}".format(str(err)))
except Exception as err:
raise DownloadException(
"Unknown exception downloading and extracting captions: {0}".format(
str(err)))
def get_result(self, video_id: str, language: str = 'en') -> int:
opts = self.opts
if language:
opts['subtitleslangs'] = [*opts.get('subtitleslangs', []), language]
with youtube_dl.YoutubeDL(opts) as ydl:
try:
return ydl.download([self.get_url_from_video_id(video_id)])
except youtube_dl.utils.DownloadError as err:
raise DownloadException(
"Unable to download captions: {0}".format(str(err)))
except youtube_dl.utils.ExtractorError as err:
raise DownloadException(
"Unable to extract captions: {0}".format(str(err)))
except Exception as err:
raise DownloadException(
"Unknown exception downloading and extracting captions: {0}".format(
str(err)))
def get_result(self, video_id: str) -> int:
self.opts['outtmpl'] = 'subtitle_' + \
hashlib.md5(str(video_id).encode('utf-8')).hexdigest()
with youtube_dl.YoutubeDL(self.opts) as ydl:
try:
return ydl.download([video_id]) # J
except youtube_dl.utils.DownloadError as err:
raise DownloadException(
"Unable to download captions: {0}".format(str(err)))
except youtube_dl.utils.ExtractorError as err:
raise DownloadException(
"Unable to extract captions: {0}".format(str(err)))
except Exception as err:
raise DownloadException(
"Unknown exception downloading and extracting captions: {0}".format(
str(err)))
def get_result(self, video_id: str) -> int:
self.opts['outtmpl'] = 'subtitle_' + \
hashlib.md5(str(video_id).encode('utf-8')).hexdigest()
with youtube_dl.YoutubeDL(self.opts) as ydl:
try:
return ydl.download([video_id]) # J
except youtube_dl.utils.DownloadError as err:
raise DownloadException(
"Unable to download captions: {0}".format(str(err)))
except youtube_dl.utils.ExtractorError as err:
raise DownloadException(
"Unable to extract captions: {0}".format(str(err)))
except Exception as err:
raise DownloadException(
"Unknown exception downloading and extracting captions: {0}".format(
str(err)))