Browse Source

youtubedl-wrapper: Only put subprocess call in try block

Helmut Pozimski 3 years ago
parent
commit
bf6622ced4
1 changed files with 16 additions and 16 deletions
  1. 16 16
      lib_stov/youtubedl_wrapper.py

+ 16 - 16
lib_stov/youtubedl_wrapper.py

@@ -18,12 +18,12 @@
 
 """ Provides a wrapper around youtube-dl"""
 
+import logging
 import subprocess
 import sys
-import logging
 
-from lib_stov import stov_exceptions
 from lib_stov import configuration
+from lib_stov import stov_exceptions
 
 LOGGER = logging.getLogger("stov")
 
@@ -97,21 +97,21 @@ def download_video(url):
     :type url: str
     """
     conf = configuration.Conf.get_instance()
-    try:
-        youtube_dl_format = "%s[height=%s]+%s/%s+best" % \
-                            (conf.get_value("video_codec"),
-                             conf.get_value("video_height"),
-                             conf.get_value("audio_quality"),
-                             conf.get_value("video_codec"))
-        LOGGER.debug(_("Executing command: %s -f %s %s"),
-                     conf.values["youtube-dl"], youtube_dl_format, url)
+    youtube_dl_format = "%s[height=%s]+%s/%s+best" % \
+                        (conf.get_value("video_codec"),
+                         conf.get_value("video_height"),
+                         conf.get_value("audio_quality"),
+                         conf.get_value("video_codec"))
+    LOGGER.debug(_("Executing command: %s -f %s %s"),
+                 conf.values["youtube-dl"], youtube_dl_format, url)
+    stderr = open("/dev/null", "w")
+    stdout = sys.stdout
+    if conf.outputlevel == "verbose":
+        stderr = sys.stderr
+    elif conf.outputlevel == "quiet":
+        stdout = open("/dev/null", "w")
         stderr = open("/dev/null", "w")
-        stdout = sys.stdout
-        if conf.outputlevel == "verbose":
-            stderr = sys.stderr
-        elif conf.outputlevel == "quiet":
-            stdout = open("/dev/null", "w")
-            stderr = open("/dev/null", "w")
+    try:
         subprocess.check_call([conf.values["youtube-dl"], "-f %s"
                                % youtube_dl_format,
                                "-o", "%(title)s-%(id)s.%(ext)s", url],