# # 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 . # -*- 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"