|
@@ -34,10 +34,10 @@ LOGGER = logging.getLogger("stov")
|
|
|
|
|
|
class YtChannel(object):
|
|
|
"""Stores the relevant attributes of a youtube channel."""
|
|
|
- def __init__(self):
|
|
|
- self.type = ""
|
|
|
- self.title = ""
|
|
|
- self.videos = []
|
|
|
+ def __init__(self, _type, title, videos=[]):
|
|
|
+ self.type = _type
|
|
|
+ self.title = title
|
|
|
+ self.videos = videos
|
|
|
|
|
|
|
|
|
class YtVideo(object):
|
|
@@ -129,7 +129,7 @@ class Connector(object):
|
|
|
video_exists = False
|
|
|
if existing_videos:
|
|
|
for existing_video in existing_videos:
|
|
|
- if video_id == existing_video.ytid:
|
|
|
+ if video_id == existing_video.site_id:
|
|
|
video_exists = True
|
|
|
break
|
|
|
if not video_exists:
|
|
@@ -153,8 +153,66 @@ class Connector(object):
|
|
|
"""
|
|
|
self._fetch_title()
|
|
|
videos = self._fetch_videos(existing_videos)
|
|
|
- channel = YtChannel()
|
|
|
- channel.title = self._title
|
|
|
- channel.videos = videos
|
|
|
- channel.type = self._type
|
|
|
+ channel = YtChannel(self._type, self._title, videos)
|
|
|
return channel
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def costruct_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://www.youtube.com/watch?v=%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."))
|
|
|
+ itag_value = 0
|
|
|
+ if config.values["videocodec"] == "flv":
|
|
|
+ if config.values["maxresolution"] == "240p":
|
|
|
+ itag_value = 5
|
|
|
+ elif config.values["maxresolution"] == "270p":
|
|
|
+ itag_value = 6
|
|
|
+ elif config.values["maxresolution"] == "360p":
|
|
|
+ itag_value = 34
|
|
|
+ elif config.values["maxresolution"] == "480p":
|
|
|
+ itag_value = 35
|
|
|
+ elif config.values["videocodec"] == "webm":
|
|
|
+ if config.values["maxresolution"] == "360p":
|
|
|
+ itag_value = 43
|
|
|
+ elif config.values["maxresolution"] == "480p":
|
|
|
+ itag_value = 44
|
|
|
+ elif config.values["maxresolution"] == "720p":
|
|
|
+ itag_value = 45
|
|
|
+ elif config.values["maxresolution"] == "1080p":
|
|
|
+ itag_value = 46
|
|
|
+ elif config.values["videocodec"] == "mp4":
|
|
|
+ if config.values["maxresolution"] == "360p":
|
|
|
+ itag_value = 18
|
|
|
+ elif config.values["maxresolution"] == "720p":
|
|
|
+ itag_value = 22
|
|
|
+ elif config.values["maxresolution"] == "1080p":
|
|
|
+ itag_value = 37
|
|
|
+ elif config.values["maxresolution"] == "3072p":
|
|
|
+ itag_value = 38
|
|
|
+ if itag_value:
|
|
|
+ LOGGER.debug(_("Found value: %s."), itag_value)
|
|
|
+ return str(itag_value)
|
|
|
+ else:
|
|
|
+ LOGGER.debug(_("Could not determine an itag value "
|
|
|
+ "from the configuration"))
|
|
|
+ return "38"
|