You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

427 lines
15 KiB

10 years ago
10 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. determine_ext,
  8. float_or_none,
  9. HEADRequest,
  10. int_or_none,
  11. orderedSet,
  12. remove_end,
  13. strip_jsonp,
  14. unescapeHTML,
  15. unified_strdate,
  16. url_or_none,
  17. )
  18. class ORFTVthekIE(InfoExtractor):
  19. IE_NAME = 'orf:tvthek'
  20. IE_DESC = 'ORF TVthek'
  21. _VALID_URL = r'https?://tvthek\.orf\.at/(?:[^/]+/)+(?P<id>\d+)'
  22. _TESTS = [{
  23. 'url': 'http://tvthek.orf.at/program/Aufgetischt/2745173/Aufgetischt-Mit-der-Steirischen-Tafelrunde/8891389',
  24. 'playlist': [{
  25. 'md5': '2942210346ed779588f428a92db88712',
  26. 'info_dict': {
  27. 'id': '8896777',
  28. 'ext': 'mp4',
  29. 'title': 'Aufgetischt: Mit der Steirischen Tafelrunde',
  30. 'description': 'md5:c1272f0245537812d4e36419c207b67d',
  31. 'duration': 2668,
  32. 'upload_date': '20141208',
  33. },
  34. }],
  35. 'skip': 'Blocked outside of Austria / Germany',
  36. }, {
  37. 'url': 'http://tvthek.orf.at/topic/Im-Wandel-der-Zeit/8002126/Best-of-Ingrid-Thurnher/7982256',
  38. 'info_dict': {
  39. 'id': '7982259',
  40. 'ext': 'mp4',
  41. 'title': 'Best of Ingrid Thurnher',
  42. 'upload_date': '20140527',
  43. 'description': 'Viele Jahre war Ingrid Thurnher das "Gesicht" der ZIB 2. Vor ihrem Wechsel zur ZIB 2 im Jahr 1995 moderierte sie unter anderem "Land und Leute", "Österreich-Bild" und "Niederösterreich heute".',
  44. },
  45. 'params': {
  46. 'skip_download': True, # rtsp downloads
  47. },
  48. 'skip': 'Blocked outside of Austria / Germany',
  49. }, {
  50. 'url': 'http://tvthek.orf.at/topic/Fluechtlingskrise/10463081/Heimat-Fremde-Heimat/13879132/Senioren-betreuen-Migrantenkinder/13879141',
  51. 'only_matching': True,
  52. }, {
  53. 'url': 'http://tvthek.orf.at/profile/Universum/35429',
  54. 'only_matching': True,
  55. }]
  56. def _real_extract(self, url):
  57. playlist_id = self._match_id(url)
  58. webpage = self._download_webpage(url, playlist_id)
  59. data_jsb = self._parse_json(
  60. self._search_regex(
  61. r'<div[^>]+class=(["\']).*?VideoPlaylist.*?\1[^>]+data-jsb=(["\'])(?P<json>.+?)\2',
  62. webpage, 'playlist', group='json'),
  63. playlist_id, transform_source=unescapeHTML)['playlist']['videos']
  64. entries = []
  65. for sd in data_jsb:
  66. video_id, title = sd.get('id'), sd.get('title')
  67. if not video_id or not title:
  68. continue
  69. video_id = compat_str(video_id)
  70. formats = []
  71. for fd in sd['sources']:
  72. src = url_or_none(fd.get('src'))
  73. if not src:
  74. continue
  75. format_id_list = []
  76. for key in ('delivery', 'quality', 'quality_string'):
  77. value = fd.get(key)
  78. if value:
  79. format_id_list.append(value)
  80. format_id = '-'.join(format_id_list)
  81. ext = determine_ext(src)
  82. if ext == 'm3u8':
  83. formats.extend(self._extract_m3u8_formats(
  84. src, video_id, 'mp4', m3u8_id=format_id, fatal=False))
  85. elif ext == 'f4m':
  86. formats.extend(self._extract_f4m_formats(
  87. src, video_id, f4m_id=format_id, fatal=False))
  88. else:
  89. formats.append({
  90. 'format_id': format_id,
  91. 'url': src,
  92. 'protocol': fd.get('protocol'),
  93. })
  94. # Check for geoblocking.
  95. # There is a property is_geoprotection, but that's always false
  96. geo_str = sd.get('geoprotection_string')
  97. if geo_str:
  98. try:
  99. http_url = next(
  100. f['url']
  101. for f in formats
  102. if re.match(r'^https?://.*\.mp4$', f['url']))
  103. except StopIteration:
  104. pass
  105. else:
  106. req = HEADRequest(http_url)
  107. self._request_webpage(
  108. req, video_id,
  109. note='Testing for geoblocking',
  110. errnote=((
  111. 'This video seems to be blocked outside of %s. '
  112. 'You may want to try the streaming-* formats.')
  113. % geo_str),
  114. fatal=False)
  115. self._check_formats(formats, video_id)
  116. self._sort_formats(formats)
  117. subtitles = {}
  118. for sub in sd.get('subtitles', []):
  119. sub_src = sub.get('src')
  120. if not sub_src:
  121. continue
  122. subtitles.setdefault(sub.get('lang', 'de-AT'), []).append({
  123. 'url': sub_src,
  124. })
  125. upload_date = unified_strdate(sd.get('created_date'))
  126. entries.append({
  127. '_type': 'video',
  128. 'id': video_id,
  129. 'title': title,
  130. 'formats': formats,
  131. 'subtitles': subtitles,
  132. 'description': sd.get('description'),
  133. 'duration': int_or_none(sd.get('duration_in_seconds')),
  134. 'upload_date': upload_date,
  135. 'thumbnail': sd.get('image_full_url'),
  136. })
  137. return {
  138. '_type': 'playlist',
  139. 'entries': entries,
  140. 'id': playlist_id,
  141. }
  142. class ORFRadioIE(InfoExtractor):
  143. def _real_extract(self, url):
  144. mobj = re.match(self._VALID_URL, url)
  145. station = mobj.group('station')
  146. show_date = mobj.group('date')
  147. show_id = mobj.group('show')
  148. if station == 'fm4':
  149. show_id = '4%s' % show_id
  150. data = self._download_json(
  151. 'http://audioapi.orf.at/%s/api/json/current/broadcast/%s/%s' % (station, show_id, show_date),
  152. show_id
  153. )
  154. def extract_entry_dict(info, title, subtitle):
  155. return {
  156. 'id': info['loopStreamId'].replace('.mp3', ''),
  157. 'url': 'http://loopstream01.apa.at/?channel=%s&id=%s' % (station, info['loopStreamId']),
  158. 'title': title,
  159. 'description': subtitle,
  160. 'duration': (info['end'] - info['start']) / 1000,
  161. 'timestamp': info['start'] / 1000,
  162. 'ext': 'mp3',
  163. 'series': data.get('programTitle')
  164. }
  165. entries = [extract_entry_dict(t, data['title'], data['subtitle']) for t in data['streams']]
  166. return {
  167. '_type': 'playlist',
  168. 'id': show_id,
  169. 'title': data['title'],
  170. 'description': data['subtitle'],
  171. 'entries': entries
  172. }
  173. class ORFFM4IE(ORFRadioIE):
  174. IE_NAME = 'orf:fm4'
  175. IE_DESC = 'radio FM4'
  176. _VALID_URL = r'https?://(?P<station>fm4)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  177. _TEST = {
  178. 'url': 'http://fm4.orf.at/player/20170107/CC',
  179. 'md5': '2b0be47375432a7ef104453432a19212',
  180. 'info_dict': {
  181. 'id': '2017-01-07_2100_tl_54_7DaysSat18_31295',
  182. 'ext': 'mp3',
  183. 'title': 'Solid Steel Radioshow',
  184. 'description': 'Die Mixshow von Coldcut und Ninja Tune.',
  185. 'duration': 3599,
  186. 'timestamp': 1483819257,
  187. 'upload_date': '20170107',
  188. },
  189. 'skip': 'Shows from ORF radios are only available for 7 days.'
  190. }
  191. class ORFOE1IE(ORFRadioIE):
  192. IE_NAME = 'orf:oe1'
  193. IE_DESC = 'Radio Österreich 1'
  194. _VALID_URL = r'https?://(?P<station>oe1)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  195. _TEST = {
  196. 'url': 'http://oe1.orf.at/player/20170108/456544',
  197. 'md5': '34d8a6e67ea888293741c86a099b745b',
  198. 'info_dict': {
  199. 'id': '2017-01-08_0759_tl_51_7DaysSun6_256141',
  200. 'ext': 'mp3',
  201. 'title': 'Morgenjournal',
  202. 'duration': 609,
  203. 'timestamp': 1483858796,
  204. 'upload_date': '20170108',
  205. },
  206. 'skip': 'Shows from ORF radios are only available for 7 days.'
  207. }
  208. class ORFIPTVIE(InfoExtractor):
  209. IE_NAME = 'orf:iptv'
  210. IE_DESC = 'iptv.ORF.at'
  211. _VALID_URL = r'https?://iptv\.orf\.at/(?:#/)?stories/(?P<id>\d+)'
  212. _TEST = {
  213. 'url': 'http://iptv.orf.at/stories/2275236/',
  214. 'md5': 'c8b22af4718a4b4af58342529453e3e5',
  215. 'info_dict': {
  216. 'id': '350612',
  217. 'ext': 'flv',
  218. 'title': 'Weitere Evakuierungen um Vulkan Calbuco',
  219. 'description': 'md5:d689c959bdbcf04efeddedbf2299d633',
  220. 'duration': 68.197,
  221. 'thumbnail': r're:^https?://.*\.jpg$',
  222. 'upload_date': '20150425',
  223. },
  224. }
  225. def _real_extract(self, url):
  226. story_id = self._match_id(url)
  227. webpage = self._download_webpage(
  228. 'http://iptv.orf.at/stories/%s' % story_id, story_id)
  229. video_id = self._search_regex(
  230. r'data-video(?:id)?="(\d+)"', webpage, 'video id')
  231. data = self._download_json(
  232. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  233. video_id)[0]
  234. duration = float_or_none(data['duration'], 1000)
  235. video = data['sources']['default']
  236. load_balancer_url = video['loadBalancerUrl']
  237. abr = int_or_none(video.get('audioBitrate'))
  238. vbr = int_or_none(video.get('bitrate'))
  239. fps = int_or_none(video.get('videoFps'))
  240. width = int_or_none(video.get('videoWidth'))
  241. height = int_or_none(video.get('videoHeight'))
  242. thumbnail = video.get('preview')
  243. rendition = self._download_json(
  244. load_balancer_url, video_id, transform_source=strip_jsonp)
  245. f = {
  246. 'abr': abr,
  247. 'vbr': vbr,
  248. 'fps': fps,
  249. 'width': width,
  250. 'height': height,
  251. }
  252. formats = []
  253. for format_id, format_url in rendition['redirect'].items():
  254. if format_id == 'rtmp':
  255. ff = f.copy()
  256. ff.update({
  257. 'url': format_url,
  258. 'format_id': format_id,
  259. })
  260. formats.append(ff)
  261. elif determine_ext(format_url) == 'f4m':
  262. formats.extend(self._extract_f4m_formats(
  263. format_url, video_id, f4m_id=format_id))
  264. elif determine_ext(format_url) == 'm3u8':
  265. formats.extend(self._extract_m3u8_formats(
  266. format_url, video_id, 'mp4', m3u8_id=format_id))
  267. else:
  268. continue
  269. self._sort_formats(formats)
  270. title = remove_end(self._og_search_title(webpage), ' - iptv.ORF.at')
  271. description = self._og_search_description(webpage)
  272. upload_date = unified_strdate(self._html_search_meta(
  273. 'dc.date', webpage, 'upload date'))
  274. return {
  275. 'id': video_id,
  276. 'title': title,
  277. 'description': description,
  278. 'duration': duration,
  279. 'thumbnail': thumbnail,
  280. 'upload_date': upload_date,
  281. 'formats': formats,
  282. }
  283. class ORFFM4StoryIE(InfoExtractor):
  284. IE_NAME = 'orf:fm4:story'
  285. IE_DESC = 'fm4.orf.at stories'
  286. _VALID_URL = r'https?://fm4\.orf\.at/stories/(?P<id>\d+)'
  287. _TEST = {
  288. 'url': 'http://fm4.orf.at/stories/2865738/',
  289. 'playlist': [{
  290. 'md5': 'e1c2c706c45c7b34cf478bbf409907ca',
  291. 'info_dict': {
  292. 'id': '547792',
  293. 'ext': 'flv',
  294. 'title': 'Manu Delago und Inner Tongue live',
  295. 'description': 'Manu Delago und Inner Tongue haben bei der FM4 Soundpark Session live alles gegeben. Hier gibt es Fotos und die gesamte Session als Video.',
  296. 'duration': 1748.52,
  297. 'thumbnail': r're:^https?://.*\.jpg$',
  298. 'upload_date': '20170913',
  299. },
  300. }, {
  301. 'md5': 'c6dd2179731f86f4f55a7b49899d515f',
  302. 'info_dict': {
  303. 'id': '547798',
  304. 'ext': 'flv',
  305. 'title': 'Manu Delago und Inner Tongue live (2)',
  306. 'duration': 1504.08,
  307. 'thumbnail': r're:^https?://.*\.jpg$',
  308. 'upload_date': '20170913',
  309. 'description': 'Manu Delago und Inner Tongue haben bei der FM4 Soundpark Session live alles gegeben. Hier gibt es Fotos und die gesamte Session als Video.',
  310. },
  311. }],
  312. }
  313. def _real_extract(self, url):
  314. story_id = self._match_id(url)
  315. webpage = self._download_webpage(url, story_id)
  316. entries = []
  317. all_ids = orderedSet(re.findall(r'data-video(?:id)?="(\d+)"', webpage))
  318. for idx, video_id in enumerate(all_ids):
  319. data = self._download_json(
  320. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  321. video_id)[0]
  322. duration = float_or_none(data['duration'], 1000)
  323. video = data['sources']['q8c']
  324. load_balancer_url = video['loadBalancerUrl']
  325. abr = int_or_none(video.get('audioBitrate'))
  326. vbr = int_or_none(video.get('bitrate'))
  327. fps = int_or_none(video.get('videoFps'))
  328. width = int_or_none(video.get('videoWidth'))
  329. height = int_or_none(video.get('videoHeight'))
  330. thumbnail = video.get('preview')
  331. rendition = self._download_json(
  332. load_balancer_url, video_id, transform_source=strip_jsonp)
  333. f = {
  334. 'abr': abr,
  335. 'vbr': vbr,
  336. 'fps': fps,
  337. 'width': width,
  338. 'height': height,
  339. }
  340. formats = []
  341. for format_id, format_url in rendition['redirect'].items():
  342. if format_id == 'rtmp':
  343. ff = f.copy()
  344. ff.update({
  345. 'url': format_url,
  346. 'format_id': format_id,
  347. })
  348. formats.append(ff)
  349. elif determine_ext(format_url) == 'f4m':
  350. formats.extend(self._extract_f4m_formats(
  351. format_url, video_id, f4m_id=format_id))
  352. elif determine_ext(format_url) == 'm3u8':
  353. formats.extend(self._extract_m3u8_formats(
  354. format_url, video_id, 'mp4', m3u8_id=format_id))
  355. else:
  356. continue
  357. self._sort_formats(formats)
  358. title = remove_end(self._og_search_title(webpage), ' - fm4.ORF.at')
  359. if idx >= 1:
  360. # Titles are duplicates, make them unique
  361. title += ' (' + str(idx + 1) + ')'
  362. description = self._og_search_description(webpage)
  363. upload_date = unified_strdate(self._html_search_meta(
  364. 'dc.date', webpage, 'upload date'))
  365. entries.append({
  366. 'id': video_id,
  367. 'title': title,
  368. 'description': description,
  369. 'duration': duration,
  370. 'thumbnail': thumbnail,
  371. 'upload_date': upload_date,
  372. 'formats': formats,
  373. })
  374. return self.playlist_result(entries)