|
@@ -22,6 +22,8 @@ import subprocess
|
|
|
import sys
|
|
|
import logging
|
|
|
|
|
|
+from lib_stov import stov_exceptions
|
|
|
+
|
|
|
LOGGER = logging.getLogger("stov")
|
|
|
|
|
|
|
|
@@ -43,7 +45,7 @@ def get_ids(conf, url, title=""):
|
|
|
else:
|
|
|
stderr = open("/dev/null", "w")
|
|
|
if title:
|
|
|
- LOGGER.debug("Executing command: %s %s %s %s %s %s %s",
|
|
|
+ LOGGER.debug(_("Executing command: %s %s %s %s %s %s %s"),
|
|
|
conf.values["youtube-dl"], "--max-downloads",
|
|
|
conf.values["maxvideos"], "--match-title",
|
|
|
title, "--get-id", url)
|
|
@@ -55,7 +57,7 @@ def get_ids(conf, url, title=""):
|
|
|
except subprocess.CalledProcessError as error_message:
|
|
|
video_ids = error_message.output
|
|
|
else:
|
|
|
- LOGGER.debug("Executing command: %s %s %s %s %s",
|
|
|
+ LOGGER.debug(_("Executing command: %s %s %s %s %s"),
|
|
|
conf.values["youtube-dl"], "--max-downloads",
|
|
|
conf.values["maxvideos"], "--get-id", url)
|
|
|
try:
|
|
@@ -84,9 +86,43 @@ def get_title(conf, url):
|
|
|
stderr = sys.stderr
|
|
|
else:
|
|
|
stderr = open("/dev/null", "w")
|
|
|
- LOGGER.debug("Executing command: %s %s %s",
|
|
|
+ LOGGER.debug(_("Executing command: %s %s %s"),
|
|
|
conf.values["youtube-dl"], "--get-title", url)
|
|
|
video_title = subprocess.check_output([
|
|
|
conf.values["youtube-dl"], "--get-title", url], stderr=stderr)
|
|
|
video_title = video_title.decode(sys.stdout.encoding)
|
|
|
return video_title
|
|
|
+
|
|
|
+
|
|
|
+def download_video(conf, url, itag_value, video_codec):
|
|
|
+ """
|
|
|
+ Downloads a video from a specified url using youtube-dl.
|
|
|
+
|
|
|
+ :param conf: configuration object
|
|
|
+ :type conf: lib_stov.configuration.Conf
|
|
|
+ :param url: URL to pass to youtube-dl
|
|
|
+ :type url: str
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ LOGGER.debug(_("Executing command: %s -f %s/%s %s"),
|
|
|
+ conf.values["youtube-dl"], itag_value, video_codec, url)
|
|
|
+ if conf.outputlevel == "default":
|
|
|
+ subprocess.check_call([conf.values["youtube-dl"], "-f %s/%s"
|
|
|
+ % (itag_value, video_codec),
|
|
|
+ "-o", "%(title)s-%(id)s.%(ext)s", url],
|
|
|
+ stderr=sys.stderr,
|
|
|
+ stdout=open("/dev/null", "w"))
|
|
|
+ elif conf.outputlevel == "verbose":
|
|
|
+ subprocess.check_call([conf.values["youtube-dl"], "-f %s/%s"
|
|
|
+ % (itag_value, video_codec),
|
|
|
+ "-o", "%(title)s-%(id)s.%(ext)s", url],
|
|
|
+ stderr=sys.stderr, stdout=sys.stdout)
|
|
|
+ elif conf.outputlevel == "quiet":
|
|
|
+ subprocess.check_call([conf.values["youtube-dl"], "-f %s/%s"
|
|
|
+ % (itag_value, video_codec),
|
|
|
+ "-o", "%(title)s-%(id)s.%(ext)s", url],
|
|
|
+ stderr=open("/dev/null", "w"),
|
|
|
+ stdout=open("/dev/null", "w"))
|
|
|
+ except subprocess.CalledProcessError as error:
|
|
|
+ LOGGER.debug(_("Error while calling youtube-dl: %s"), error.output)
|
|
|
+ raise stov_exceptions.YoutubeDlCallFailed()
|