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