Ver código fonte

suppress youtube-dl error output in noapi if stov is not run in verbose mode

Helmut Pozimski 9 anos atrás
pai
commit
de06b69e16
2 arquivos alterados com 8 adições e 5 exclusões
  1. 0 1
      TODO
  2. 8 4
      lib_stov/noapi.py

+ 0 - 1
TODO

@@ -3,4 +3,3 @@ TODOs for 1.0:
 * Reintroduce some of the removed debug output
 * Remove python 2 compatibility code, support python 3 only
 * Check with pylint to do coding style improvements before the next release
-* Suppress non-essential youtube-dl errors

+ 8 - 4
lib_stov/noapi.py

@@ -73,6 +73,10 @@ class Connector(object):
     def _fetch_videos(self, existing_videos):
         """Retrieves all the relevant videos in a subscription."""
         videos_list = []
+        if self._conf.outputlevel == "verbose":
+            stderr = sys.stderr
+        else:
+            stderr = open("/dev/null", "w")
         if self._type == "channel" and self._search != "":
             try:
                 video_ids = subprocess.check_output([
@@ -82,7 +86,7 @@ class Connector(object):
                     "--match-title",
                     self._search,
                     "--get-id",
-                    self._url]).strip()
+                    self._url], stderr=stderr).strip()
             except subprocess.CalledProcessError as e:
                 video_ids = e.output.strip()
         else:
@@ -90,7 +94,7 @@ class Connector(object):
                 video_ids = subprocess.check_output([
                     self._conf.values["youtube-dl"], "--max-downloads",
                     self._conf.values["maxvideos"], "--get-id",
-                    self._url]).strip()
+                    self._url], stderr=stderr).strip()
             except subprocess.CalledProcessError as e:
                 video_ids = e.output.strip()
         if len(video_ids) >= 1:
@@ -105,11 +109,11 @@ class Connector(object):
                         video_title = subprocess.check_output([
                             self._conf.values["youtube-dl"], "--get-title",
                             "https://www.youtube.com/watch?v=%s"
-                            % video_id]).strip()
+                            % video_id], stderr=stderr).strip()
                         video_description = subprocess.check_output([
                             self._conf.values["youtube-dl"], "--get-description",
                             "https://www.youtube.com/watch?v=%s"
-                            % video_id]).strip()
+                            % video_id], stderr=stderr).strip()
                     except subprocess.CalledProcessError:
                         raise stov_exceptions.YoutubeDlCallFailed()
                     else: