[twitcasting] Add extractor
[youtube-dl] / youtube_dl / extractor / twitcasting.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5
6 import re
7
8
9 class TwitcastingIE(InfoExtractor):
10     _VALID_URL = r'https?://(?:(?:www|ssl|en|pt|es|ja|ko)\.)?twitcasting\.tv/(?P<uploader_id>[^\/]+)/movie/(?P<video_id>[0-9]+)'
11     _TEST = {
12         'url': 'https://twitcasting.tv/ivetesangalo/movie/2357609',
13         'md5': '745243cad58c4681dc752490f7540d7f',
14         'info_dict': {
15             'id': '2357609',
16             'ext': 'mp4',
17             'title': 'Recorded Live #2357609',
18             'uploader_id': 'ivetesangalo',
19             'description': "Moi! I'm live on TwitCasting from my iPhone.",
20             'thumbnail': r're:^https?://.*\.jpg$',
21         }
22     }
23
24     def _real_extract(self, url):
25         mobj = re.match(self._VALID_URL, url)
26         video_id = mobj.group('video_id')
27         uploader_id = mobj.group('uploader_id')
28
29         webpage = self._download_webpage(url, video_id)
30
31         playlist_url = self._html_search_regex(r'(["\'])(?P<url>http.+?\.m3u8.*?)\1', webpage, name='playlist url', group='url')
32         formats = self._extract_m3u8_formats(playlist_url, video_id, ext='mp4')
33         thumbnail = self._og_search_thumbnail(webpage)
34         title = self._html_search_meta('twitter:title', webpage)
35         description = self._og_search_description(webpage) or self._html_search_meta('twitter:description', webpage)
36         return{
37             'id': video_id,
38             'url': url,
39             'title': title,
40             'description': description,
41             'thumbnail': thumbnail,
42             'uploader_id': uploader_id,
43             'formats': formats,
44         }