Browse Source

implement support for vid.me (closes #6)

Helmut Pozimski 6 years ago
parent
commit
7535243fd7

+ 2 - 2
lib_stov/generic_video.py

@@ -40,7 +40,7 @@ class Video(object):
         self.downloaded = downloaded
         self.failcnt = int(failcount)
 
-    def download_video(self, directory, itag_value, video_codec, url):
+    def download_video(self, directory, itag_value, url):
         """
         Downloads the video by calling youtube-dl as an external process"
 
@@ -67,7 +67,7 @@ class Video(object):
         if self.downloaded == 0:
             try:
                 youtubedl_wrapper.download_video(self.__conf, url,
-                                                 itag_value, video_codec)
+                                                 itag_value)
             except stov_exceptions.YoutubeDlCallFailed:
                 self.failcnt = int(self.failcnt) + 1
                 return False

+ 29 - 24
lib_stov/program.py

@@ -54,29 +54,34 @@ def add_subscription(conf, database, channel="",
     LOGGER.debug(_("Creating new subscription with the following "
                    "parameters:\nChannel: %s\nSearch: %s\nPlaylist: %s"),
                  channel, search, playlist)
-    if channel and not search:
-        new_subscription = subscription.Sub(subscription_type="user",
-                                            name=channel, conf=conf, site=site)
-    elif channel and search:
-        new_subscription = subscription.Sub(subscription_type="user",
-                                            name=channel,
-                                            search=search,
-                                            conf=conf, site=site)
-    elif not channel and search:
-        new_subscription = subscription.Sub(subscription_type="search",
-                                            name=_("Search_"),
-                                            search=search,
-                                            conf=conf, site=site)
-    elif playlist:
-        if search:
-            LOGGER.error(_("Playlists do not support searching, the search "
-                           "option will be ignored!"))
-        new_subscription = subscription.Sub(subscription_type="playlist",
-                                            name=playlist,
-                                            conf=conf, site=site)
-    else:
-        LOGGER.error(_("None or invalid subscription type given, please check "
-                       "the type option and try again."))
+    try:
+        if channel and not search:
+            new_subscription = subscription.Sub(subscription_type="user",
+                                                name=channel, conf=conf,
+                                                site=site)
+        elif channel and search:
+            new_subscription = subscription.Sub(subscription_type="user",
+                                                name=channel,
+                                                search=search,
+                                                conf=conf, site=site)
+        elif not channel and search:
+            new_subscription = subscription.Sub(subscription_type="search",
+                                                name=_("Search_"),
+                                                search=search,
+                                                conf=conf, site=site)
+        elif playlist:
+            if search:
+                LOGGER.error(_("Playlists do not support searching, the "
+                               "search option will be ignored!"))
+            new_subscription = subscription.Sub(subscription_type="playlist",
+                                                name=playlist,
+                                                conf=conf, site=site)
+        else:
+            LOGGER.error(_("None or invalid subscription type given, please "
+                           "check the type option and try again."))
+            sys.exit(1)
+    except stov_exceptions.TypeNotSupported as error:
+        LOGGER.error(error)
         sys.exit(1)
     try:
         subscription_data = new_subscription.add_sub()
@@ -498,7 +503,7 @@ def initialize_sites(database):
     :param database: database object
     :type database: lib_stov.database.Db
     """
-    supported_sites = ["youtube", "zdf_mediathek", "twitch"]
+    supported_sites = ["youtube", "zdf_mediathek", "twitch", "vidme"]
     sites = database.get_sites()
     for site in supported_sites:
         site_found = False

+ 4 - 1
lib_stov/subscription.py

@@ -22,6 +22,7 @@ from lib_stov import stov_exceptions
 from lib_stov import yt_noapi
 from lib_stov import zdf_mediathek
 from lib_stov import twitch
+from lib_stov import vidme
 
 
 class Sub(object):
@@ -60,6 +61,9 @@ class Sub(object):
         elif site == "twitch":
             self._connector = twitch.Connector(self._type, self._name,
                                                self._conf, self._search)
+        elif site == "vidme":
+            self._connector = vidme.Connector(self._type, self._name,
+                                              self._conf, self._search)
         else:
             raise stov_exceptions.SiteUnsupported()
 
@@ -106,7 +110,6 @@ class Sub(object):
                     video_url = self._connector.construct_video_url(
                         video.site_id)
                     if video.download_video(self._directory, itag_value,
-                                            self._conf.values["videocodec"],
                                             video_url):
                         self.downloaded_videos.append(video)
                     else:

+ 2 - 2
lib_stov/twitch.py

@@ -95,8 +95,8 @@ class Connector(yt_noapi.Connector):
                 quality_value = "1080p"
         if quality_value:
             LOGGER.debug(_("Found value: %s."), quality_value)
-            return quality_value
+            return quality_value + "/" + config.values["videocodec"]
         else:
             LOGGER.debug(_("Could not determine an itag value "
                            "from the configuration"))
-            return "1080p"
+            return "1080p" + "/" + config.values["videocodec"]

+ 94 - 0
lib_stov/vidme.py

@@ -0,0 +1,94 @@
+#
+#   This file is part of stov, written by Helmut Pozimski 2012-2017.
+#
+#   stov is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, version 2 of the License.
+#
+#   stov is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with stov.  If not, see <http://www.gnu.org/licenses/>.
+
+
+# -*- coding: utf8 -*-
+
+""" This module implements support for subscriptions from twitch.tv"""
+
+import urllib.parse
+import urllib.request
+import urllib.error
+import logging
+
+from lib_stov import stov_exceptions
+from lib_stov import yt_noapi
+
+LOGGER = logging.getLogger("stov")
+
+
+class Connector(yt_noapi.Connector):
+    """ Connector class, performing calls to youtube-dl to retrieve
+        information about videos from vid.me
+    """
+    def __init__(self, subscription_type, name, conf, search=""):
+        yt_noapi.Connector.__init__(self, subscription_type, name, conf,
+                                    search)
+
+    def _construct_url(self):
+        """Constructs the URL to request from youtube-dl according to the
+        subscription type and the given parameters.
+        """
+        if self._type == "user":
+            self._url = "https://vid.me/%s" \
+                        % urllib.parse.quote(self._name)
+        elif self._type == "search":
+            raise stov_exceptions.TypeNotSupported()
+        elif self._type == "playlist":
+            raise stov_exceptions.TypeNotSupported()
+        LOGGER.debug(_("Constructed URL for subscription: %s"), self._url)
+
+    @staticmethod
+    def construct_video_url(ytid):
+        """
+        Resturns the URL to a specified youtube video
+
+        :param ytid: Youtube ID of the video
+        :type ytid: str
+        :return: Video URL
+        :rtype: str
+        """
+        url = "https://vid.me/%s" % ytid
+        return url
+
+    @staticmethod
+    def get_quality_parameter(config):
+        """Determines which itag value results from codec and resolution
+        settings and returns it
+
+        :param config: configuration object
+        :type config: lib_stov.configuration.Conf
+        :return: itag value
+        :rtype: str
+        """
+        LOGGER.debug(_("Trying to determine the itag value for youtube-dl from"
+                       " your quality and codec settings."))
+        quality_value = ""
+        if config.values["videocodec"] == "mp4":
+            if config.values["maxresolution"] == "480p":
+                quality_value = "hls-2155"
+            elif config.values["maxresolution"] == "720p":
+                quality_value = "hls-2297"
+            elif config.values["maxresolution"] == "1080p":
+                quality_value = "hls-2265"
+        if quality_value:
+            LOGGER.debug(_("Found value: %s."), quality_value)
+            return quality_value + "/" + config.values["videocodec"] + \
+                "+bestaudio"
+        else:
+            LOGGER.debug(_("Could not determine an itag value "
+                           "from the configuration"))
+            return "hls-2265" + config.values["videocodec"] + \
+                   "+bestaudio"

+ 10 - 8
lib_stov/youtubedl_wrapper.py

@@ -94,32 +94,34 @@ def get_title(conf, url):
     return video_title
 
 
-def download_video(conf, url, itag_value, video_codec):
+def download_video(conf, url, itag_value):
     """
     Downloads a video from a specified url using youtube-dl.
 
     :param conf: configuration object
     :type conf: lib_stov.configuration.Conf
+    :param itag_value: video and audio parameter
+    :type itag_value: str
     :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)
+        LOGGER.debug(_("Executing command: %s -f %s %s"),
+                     conf.values["youtube-dl"], itag_value, url)
         if conf.outputlevel == "default":
-            subprocess.check_call([conf.values["youtube-dl"], "-f %s/%s"
-                                   % (itag_value, video_codec),
+            subprocess.check_call([conf.values["youtube-dl"], "-f %s"
+                                   % itag_value,
                                    "-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),
+            subprocess.check_call([conf.values["youtube-dl"], "-f %s"
+                                   % itag_value,
                                    "-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),
+                                   % itag_value,
                                    "-o", "%(title)s-%(id)s.%(ext)s", url],
                                   stderr=open("/dev/null", "w"),
                                   stdout=open("/dev/null", "w"))

+ 1 - 1
lib_stov/yt_noapi.py

@@ -212,7 +212,7 @@ class Connector(object):
                 itag_value = 38
         if itag_value:
             LOGGER.debug(_("Found value: %s."), itag_value)
-            return str(itag_value)
+            return str(itag_value) + "/" + config.values["videocodec"]
         else:
             LOGGER.debug(_("Could not determine an itag value "
                            "from the configuration"))

+ 2 - 2
lib_stov/zdf_mediathek.py

@@ -139,8 +139,8 @@ class Connector(object):
                 quality_value = "hls-3286"
         if quality_value:
             LOGGER.debug(_("Found value: %s."), quality_value)
-            return quality_value
+            return quality_value + "/" + config.values["videocodec"]
         else:
             LOGGER.debug(_("Could not determine an itag value "
                            "from the configuration"))
-            return "hls-3286"
+            return "hls-3286" + "/" + config.values["videocodec"]