Browse Source

remove time-consuming --match-title option for youtube-dl, titles will be checked internally instead

Helmut Pozimski 6 years ago
parent
commit
10e58f1ed5
3 changed files with 24 additions and 33 deletions
  1. 8 1
      lib_stov/subscription.py
  2. 15 30
      lib_stov/youtubedl_wrapper.py
  3. 1 2
      lib_stov/yt_noapi.py

+ 8 - 1
lib_stov/subscription.py

@@ -18,6 +18,8 @@
 
 """This module takes care of managing subscriptions."""
 
+import logging
+
 from lib_stov import stov_exceptions
 from lib_stov import yt_noapi
 from lib_stov import zdf_mediathek
@@ -25,6 +27,9 @@ from lib_stov import twitch
 from lib_stov import vidme
 
 
+LOGGER = logging.getLogger("stov")
+
+
 class Sub(object):
     """This class constructs a object that stores all the attributes that define
     a subscription and performs the necessary operations on it.
@@ -83,11 +88,13 @@ class Sub(object):
         """Checks if the subscription is enabled and the video matches the
         search string defined for the subscription"""
         if not self.disabled:
+            LOGGER.debug(_("Matching parameter %s with title %s"),
+                         self._search, video.title)
             if self._search != "" and self._conf.values["check_title"]\
                     == "yes":
                 return self._search in video.title
             else:
-                return True
+                return self._search.lower() in video.title.lower()
         else:
             return False
 

+ 15 - 30
lib_stov/youtubedl_wrapper.py

@@ -27,15 +27,13 @@ from lib_stov import stov_exceptions
 LOGGER = logging.getLogger("stov")
 
 
-def get_ids(conf, url, title="", reverse=False):
+def get_ids(conf, url, reverse=False):
     """
     Retrieves the IDs
     :param conf: configuration object
     :type conf: lib_stov.configuration.Conf
     :param url: URL to pass to youtube-dl
     :type url: str
-    :param title: optional title to match
-    :type title: str
     :param reverse: look up a playlist in reverse order to get \
     the recent videos first
     :type reverse: bool
@@ -47,35 +45,22 @@ def get_ids(conf, url, title="", reverse=False):
         stderr = sys.stderr
     else:
         stderr = open("/dev/null", "w")
-    if title:
-        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)
-        try:
+    LOGGER.debug(_("Executing command: %s %s %s %s %s %s"),
+                 conf.values["youtube-dl"], "--max-downloads",
+                 conf.values["maxvideos"], "-i", "--get-id", url)
+    try:
+        if reverse:
             video_ids = subprocess.check_output(
                 [conf.values["youtube-dl"], "--max-downloads",
-                 conf.values["maxvideos"], "--match-title",
-                 title, "-i", "--get-id", url], stderr=stderr)
-        except subprocess.CalledProcessError as error_message:
-            video_ids = error_message.output
-    else:
-        LOGGER.debug(_("Executing command: %s %s %s %s %s %s"),
-                     conf.values["youtube-dl"], "--max-downloads",
-                     conf.values["maxvideos"], "-i", "--get-id", url)
-        try:
-            if reverse:
-                video_ids = subprocess.check_output(
-                    [conf.values["youtube-dl"], "--max-downloads",
-                     conf.values["maxvideos"], "-i", "--playlist-reverse",
-                     "--get-id", url], stderr=stderr)
-            else:
-                video_ids = subprocess.check_output(
-                    [conf.values["youtube-dl"], "--max-downloads",
-                     conf.values["maxvideos"],
-                     "-i", "--get-id", url], stderr=stderr)
-        except subprocess.CalledProcessError as error_message:
-            video_ids = error_message.output
+                 conf.values["maxvideos"], "-i", "--playlist-reverse",
+                 "--get-id", url], stderr=stderr)
+        else:
+            video_ids = subprocess.check_output(
+                [conf.values["youtube-dl"], "--max-downloads",
+                conf.values["maxvideos"],
+                "-i", "--get-id", url], stderr=stderr)
+    except subprocess.CalledProcessError as error_message:
+        video_ids = error_message.output
     video_ids = video_ids.decode(sys.stdout.encoding).strip()
     for video in video_ids.split("\n"):
         videos_list.append(video)

+ 1 - 2
lib_stov/yt_noapi.py

@@ -121,8 +121,7 @@ class Connector(object):
         """Retrieves all the relevant videos in a subscription."""
         videos_list = []
         if self._type == "user" and self._search:
-            video_ids = youtubedl_wrapper.get_ids(self._conf, self._url,
-                                                  self._search)
+            video_ids = youtubedl_wrapper.get_ids(self._conf, self._url)
         elif self._type == "playlist":
             video_ids = youtubedl_wrapper.get_ids(self._conf, self._url,
                                                   reverse=True)