]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/twitcasting.py
Update upstream source from tag 'upstream/2019.09.28'
[youtubedl] / youtube_dl / extractor / twitcasting.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import urlencode_postdata
6
7 import re
8
9
10 class TwitCastingIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:[^/]+\.)?twitcasting\.tv/(?P<uploader_id>[^/]+)/movie/(?P<id>\d+)'
12 _TESTS = [{
13 'url': 'https://twitcasting.tv/ivetesangalo/movie/2357609',
14 'md5': '745243cad58c4681dc752490f7540d7f',
15 'info_dict': {
16 'id': '2357609',
17 'ext': 'mp4',
18 'title': 'Live #2357609',
19 'uploader_id': 'ivetesangalo',
20 'description': "Moi! I'm live on TwitCasting from my iPhone.",
21 'thumbnail': r're:^https?://.*\.jpg$',
22 },
23 'params': {
24 'skip_download': True,
25 },
26 }, {
27 'url': 'https://twitcasting.tv/mttbernardini/movie/3689740',
28 'info_dict': {
29 'id': '3689740',
30 'ext': 'mp4',
31 'title': 'Live playing something #3689740',
32 'uploader_id': 'mttbernardini',
33 'description': "I'm live on TwitCasting from my iPad. password: abc (Santa Marinella/Lazio, Italia)",
34 'thumbnail': r're:^https?://.*\.jpg$',
35 },
36 'params': {
37 'skip_download': True,
38 'videopassword': 'abc',
39 },
40 }]
41
42 def _real_extract(self, url):
43 mobj = re.match(self._VALID_URL, url)
44 video_id = mobj.group('id')
45 uploader_id = mobj.group('uploader_id')
46
47 video_password = self._downloader.params.get('videopassword')
48 request_data = None
49 if video_password:
50 request_data = urlencode_postdata({
51 'password': video_password,
52 })
53 webpage = self._download_webpage(url, video_id, data=request_data)
54
55 title = self._html_search_regex(
56 r'(?s)<[^>]+id=["\']movietitle[^>]+>(.+?)</',
57 webpage, 'title', default=None) or self._html_search_meta(
58 'twitter:title', webpage, fatal=True)
59
60 m3u8_url = self._search_regex(
61 (r'data-movie-url=(["\'])(?P<url>(?:(?!\1).)+)\1',
62 r'(["\'])(?P<url>http.+?\.m3u8.*?)\1'),
63 webpage, 'm3u8 url', group='url')
64
65 formats = self._extract_m3u8_formats(
66 m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native',
67 m3u8_id='hls')
68
69 thumbnail = self._og_search_thumbnail(webpage)
70 description = self._og_search_description(
71 webpage, default=None) or self._html_search_meta(
72 'twitter:description', webpage)
73
74 return {
75 'id': video_id,
76 'title': title,
77 'description': description,
78 'thumbnail': thumbnail,
79 'uploader_id': uploader_id,
80 'formats': formats,
81 }