logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

tubitv.py (3763B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. sanitized_Request,
  9. urlencode_postdata,
  10. )
  11. class TubiTvIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?tubitv\.com/(?:video|movies|tv-shows)/(?P<id>[0-9]+)'
  13. _LOGIN_URL = 'http://tubitv.com/login'
  14. _NETRC_MACHINE = 'tubitv'
  15. _GEO_COUNTRIES = ['US']
  16. _TESTS = [{
  17. 'url': 'http://tubitv.com/video/283829/the_comedian_at_the_friday',
  18. 'md5': '43ac06be9326f41912dc64ccf7a80320',
  19. 'info_dict': {
  20. 'id': '283829',
  21. 'ext': 'mp4',
  22. 'title': 'The Comedian at The Friday',
  23. 'description': 'A stand up comedian is forced to look at the decisions in his life while on a one week trip to the west coast.',
  24. 'uploader_id': 'bc168bee0d18dd1cb3b86c68706ab434',
  25. },
  26. }, {
  27. 'url': 'http://tubitv.com/tv-shows/321886/s01_e01_on_nom_stories',
  28. 'only_matching': True,
  29. }, {
  30. 'url': 'http://tubitv.com/movies/383676/tracker',
  31. 'only_matching': True,
  32. }, {
  33. 'url': 'https://tubitv.com/movies/560057/penitentiary?start=true',
  34. 'info_dict': {
  35. 'id': '560057',
  36. 'ext': 'mp4',
  37. 'title': 'Penitentiary',
  38. 'description': 'md5:8d2fc793a93cc1575ff426fdcb8dd3f9',
  39. 'uploader_id': 'd8fed30d4f24fcb22ec294421b9defc2',
  40. 'release_year': 1979,
  41. },
  42. 'params': {
  43. 'skip_download': True,
  44. },
  45. }]
  46. def _login(self):
  47. username, password = self._get_login_info()
  48. if username is None:
  49. return
  50. self.report_login()
  51. form_data = {
  52. 'username': username,
  53. 'password': password,
  54. }
  55. payload = urlencode_postdata(form_data)
  56. request = sanitized_Request(self._LOGIN_URL, payload)
  57. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  58. login_page = self._download_webpage(
  59. request, None, False, 'Wrong login info')
  60. if not re.search(r'id="tubi-logout"', login_page):
  61. raise ExtractorError(
  62. 'Login failed (invalid username/password)', expected=True)
  63. def _real_initialize(self):
  64. self._login()
  65. def _real_extract(self, url):
  66. video_id = self._match_id(url)
  67. video_data = self._download_json(
  68. 'http://tubitv.com/oz/videos/%s/content' % video_id, video_id)
  69. title = video_data['title']
  70. formats = self._extract_m3u8_formats(
  71. self._proto_relative_url(video_data['url']),
  72. video_id, 'mp4', 'm3u8_native')
  73. self._sort_formats(formats)
  74. thumbnails = []
  75. for thumbnail_url in video_data.get('thumbnails', []):
  76. if not thumbnail_url:
  77. continue
  78. thumbnails.append({
  79. 'url': self._proto_relative_url(thumbnail_url),
  80. })
  81. subtitles = {}
  82. for sub in video_data.get('subtitles', []):
  83. sub_url = sub.get('url')
  84. if not sub_url:
  85. continue
  86. subtitles.setdefault(sub.get('lang', 'English'), []).append({
  87. 'url': self._proto_relative_url(sub_url),
  88. })
  89. return {
  90. 'id': video_id,
  91. 'title': title,
  92. 'formats': formats,
  93. 'subtitles': subtitles,
  94. 'thumbnails': thumbnails,
  95. 'description': video_data.get('description'),
  96. 'duration': int_or_none(video_data.get('duration')),
  97. 'uploader_id': video_data.get('publisher_id'),
  98. 'release_year': int_or_none(video_data.get('year')),
  99. }