# # This file is part of stov, written by Helmut Pozimski 2012-2021. # # 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 logging import urllib.error import urllib.parse import urllib.request 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 twitch.tv """ def __init__(self, subscription_type, name, search=""): """Populates the object with all necessary data.""" yt_noapi.Connector.__init__(self, subscription_type, name, search) self._url = "" self._title = "" def _construct_url(self): """ Constructs the URL for the subscription to retrieve data from. """ if self._type == "user": self._url = "https://www.twitch.tv/%s/videos/all" \ % 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) def _fetch_title(self): """Sets the title of a subscription""" self._title = self._name if self._search != "": self._title += _(" search %s") % self._search @staticmethod def construct_video_url(ytid): """ Resturns the URL to a specified twitch video :param ytid: Twitch ID of the video :type ytid: str :return: Video URL :rtype: str """ ytid = ytid.split("v")[1] url = "https://www.twitch.tv/videos/%s" % ytid return url