vidme.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #
  2. # This file is part of stov, written by Helmut Pozimski 2012-2017.
  3. #
  4. # stov is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, version 2 of the License.
  7. #
  8. # stov is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with stov. If not, see <http://www.gnu.org/licenses/>.
  15. # -*- coding: utf8 -*-
  16. """ This module implements support for subscriptions from twitch.tv"""
  17. import urllib.parse
  18. import urllib.request
  19. import urllib.error
  20. import logging
  21. from lib_stov import stov_exceptions
  22. from lib_stov import yt_noapi
  23. LOGGER = logging.getLogger("stov")
  24. class Connector(yt_noapi.Connector):
  25. """ Connector class, performing calls to youtube-dl to retrieve
  26. information about videos from vid.me
  27. """
  28. def __init__(self, subscription_type, name, conf, search=""):
  29. yt_noapi.Connector.__init__(self, subscription_type, name, conf,
  30. search)
  31. def _construct_url(self):
  32. """Constructs the URL to request from youtube-dl according to the
  33. subscription type and the given parameters.
  34. """
  35. if self._type == "user":
  36. self._url = "https://vid.me/%s" \
  37. % urllib.parse.quote(self._name)
  38. elif self._type == "search":
  39. raise stov_exceptions.TypeNotSupported()
  40. elif self._type == "playlist":
  41. raise stov_exceptions.TypeNotSupported()
  42. LOGGER.debug(_("Constructed URL for subscription: %s"), self._url)
  43. @staticmethod
  44. def construct_video_url(ytid):
  45. """
  46. Resturns the URL to a specified youtube video
  47. :param ytid: Youtube ID of the video
  48. :type ytid: str
  49. :return: Video URL
  50. :rtype: str
  51. """
  52. url = "https://vid.me/%s" % ytid
  53. return url
  54. @staticmethod
  55. def get_quality_parameter(config):
  56. """Determines which itag value results from codec and resolution
  57. settings and returns it
  58. :param config: configuration object
  59. :type config: lib_stov.configuration.Conf
  60. :return: itag value
  61. :rtype: str
  62. """
  63. LOGGER.debug(_("Trying to determine the itag value for youtube-dl from"
  64. " your quality and codec settings."))
  65. quality_value = ""
  66. if config.values["videocodec"] == "mp4":
  67. if config.values["maxresolution"] == "480p":
  68. quality_value = "hls-2155"
  69. elif config.values["maxresolution"] == "720p":
  70. quality_value = "hls-2297"
  71. elif config.values["maxresolution"] == "1080p":
  72. quality_value = "hls-2265"
  73. if quality_value:
  74. LOGGER.debug(_("Found value: %s."), quality_value)
  75. return quality_value + "/" + config.values["videocodec"] + \
  76. "+bestaudio"
  77. else:
  78. LOGGER.debug(_("Could not determine an itag value "
  79. "from the configuration"))
  80. return "hls-2265" + config.values["videocodec"] + \
  81. "+bestaudio"