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.

426 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. if determine_ext(fd['src']) == 'm3u8':
  82. formats.extend(self._extract_m3u8_formats(
  83. fd['src'], video_id, 'mp4', m3u8_id=format_id))
  84. elif determine_ext(fd['src']) == 'f4m':
  85. formats.extend(self._extract_f4m_formats(
  86. fd['src'], video_id, f4m_id=format_id))
  87. else:
  88. formats.append({
  89. 'format_id': format_id,
  90. 'url': src,
  91. 'protocol': fd.get('protocol'),
  92. })
  93. # Check for geoblocking.
  94. # There is a property is_geoprotection, but that's always false
  95. geo_str = sd.get('geoprotection_string')
  96. if geo_str:
  97. try:
  98. http_url = next(
  99. f['url']
  100. for f in formats
  101. if re.match(r'^https?://.*\.mp4$', f['url']))
  102. except StopIteration:
  103. pass
  104. else:
  105. req = HEADRequest(http_url)
  106. self._request_webpage(
  107. req, video_id,
  108. note='Testing for geoblocking',
  109. errnote=((
  110. 'This video seems to be blocked outside of %s. '
  111. 'You may want to try the streaming-* formats.')
  112. % geo_str),
  113. fatal=False)
  114. self._check_formats(formats, video_id)
  115. self._sort_formats(formats)
  116. subtitles = {}
  117. for sub in sd.get('subtitles', []):
  118. sub_src = sub.get('src')
  119. if not sub_src:
  120. continue
  121. subtitles.setdefault(sub.get('lang', 'de-AT'), []).append({
  122. 'url': sub_src,
  123. })
  124. upload_date = unified_strdate(sd.get('created_date'))
  125. entries.append({
  126. '_type': 'video',
  127. 'id': video_id,
  128. 'title': title,
  129. 'formats': formats,
  130. 'subtitles': subtitles,
  131. 'description': sd.get('description'),
  132. 'duration': int_or_none(sd.get('duration_in_seconds')),
  133. 'upload_date': upload_date,
  134. 'thumbnail': sd.get('image_full_url'),
  135. })
  136. return {
  137. '_type': 'playlist',
  138. 'entries': entries,
  139. 'id': playlist_id,
  140. }
  141. class ORFRadioIE(InfoExtractor):
  142. def _real_extract(self, url):
  143. mobj = re.match(self._VALID_URL, url)
  144. station = mobj.group('station')
  145. show_date = mobj.group('date')
  146. show_id = mobj.group('show')
  147. if station == 'fm4':
  148. show_id = '4%s' % show_id
  149. data = self._download_json(
  150. 'http://audioapi.orf.at/%s/api/json/current/broadcast/%s/%s' % (station, show_id, show_date),
  151. show_id
  152. )
  153. def extract_entry_dict(info, title, subtitle):
  154. return {
  155. 'id': info['loopStreamId'].replace('.mp3', ''),
  156. 'url': 'http://loopstream01.apa.at/?channel=%s&id=%s' % (station, info['loopStreamId']),
  157. 'title': title,
  158. 'description': subtitle,
  159. 'duration': (info['end'] - info['start']) / 1000,
  160. 'timestamp': info['start'] / 1000,
  161. 'ext': 'mp3',
  162. 'series': data.get('programTitle')
  163. }
  164. entries = [extract_entry_dict(t, data['title'], data['subtitle']) for t in data['streams']]
  165. return {
  166. '_type': 'playlist',
  167. 'id': show_id,
  168. 'title': data['title'],
  169. 'description': data['subtitle'],
  170. 'entries': entries
  171. }
  172. class ORFFM4IE(ORFRadioIE):
  173. IE_NAME = 'orf:fm4'
  174. IE_DESC = 'radio FM4'
  175. _VALID_URL = r'https?://(?P<station>fm4)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  176. _TEST = {
  177. 'url': 'http://fm4.orf.at/player/20170107/CC',
  178. 'md5': '2b0be47375432a7ef104453432a19212',
  179. 'info_dict': {
  180. 'id': '2017-01-07_2100_tl_54_7DaysSat18_31295',
  181. 'ext': 'mp3',
  182. 'title': 'Solid Steel Radioshow',
  183. 'description': 'Die Mixshow von Coldcut und Ninja Tune.',
  184. 'duration': 3599,
  185. 'timestamp': 1483819257,
  186. 'upload_date': '20170107',
  187. },
  188. 'skip': 'Shows from ORF radios are only available for 7 days.'
  189. }
  190. class ORFOE1IE(ORFRadioIE):
  191. IE_NAME = 'orf:oe1'
  192. IE_DESC = 'Radio Österreich 1'
  193. _VALID_URL = r'https?://(?P<station>oe1)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  194. _TEST = {
  195. 'url': 'http://oe1.orf.at/player/20170108/456544',
  196. 'md5': '34d8a6e67ea888293741c86a099b745b',
  197. 'info_dict': {
  198. 'id': '2017-01-08_0759_tl_51_7DaysSun6_256141',
  199. 'ext': 'mp3',
  200. 'title': 'Morgenjournal',
  201. 'duration': 609,
  202. 'timestamp': 1483858796,
  203. 'upload_date': '20170108',
  204. },
  205. 'skip': 'Shows from ORF radios are only available for 7 days.'
  206. }
  207. class ORFIPTVIE(InfoExtractor):
  208. IE_NAME = 'orf:iptv'
  209. IE_DESC = 'iptv.ORF.at'
  210. _VALID_URL = r'https?://iptv\.orf\.at/(?:#/)?stories/(?P<id>\d+)'
  211. _TEST = {
  212. 'url': 'http://iptv.orf.at/stories/2275236/',
  213. 'md5': 'c8b22af4718a4b4af58342529453e3e5',
  214. 'info_dict': {
  215. 'id': '350612',
  216. 'ext': 'flv',
  217. 'title': 'Weitere Evakuierungen um Vulkan Calbuco',
  218. 'description': 'md5:d689c959bdbcf04efeddedbf2299d633',
  219. 'duration': 68.197,
  220. 'thumbnail': r're:^https?://.*\.jpg$',
  221. 'upload_date': '20150425',
  222. },
  223. }
  224. def _real_extract(self, url):
  225. story_id = self._match_id(url)
  226. webpage = self._download_webpage(
  227. 'http://iptv.orf.at/stories/%s' % story_id, story_id)
  228. video_id = self._search_regex(
  229. r'data-video(?:id)?="(\d+)"', webpage, 'video id')
  230. data = self._download_json(
  231. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  232. video_id)[0]
  233. duration = float_or_none(data['duration'], 1000)
  234. video = data['sources']['default']
  235. load_balancer_url = video['loadBalancerUrl']
  236. abr = int_or_none(video.get('audioBitrate'))
  237. vbr = int_or_none(video.get('bitrate'))
  238. fps = int_or_none(video.get('videoFps'))
  239. width = int_or_none(video.get('videoWidth'))
  240. height = int_or_none(video.get('videoHeight'))
  241. thumbnail = video.get('preview')
  242. rendition = self._download_json(
  243. load_balancer_url, video_id, transform_source=strip_jsonp)
  244. f = {
  245. 'abr': abr,
  246. 'vbr': vbr,
  247. 'fps': fps,
  248. 'width': width,
  249. 'height': height,
  250. }
  251. formats = []
  252. for format_id, format_url in rendition['redirect'].items():
  253. if format_id == 'rtmp':
  254. ff = f.copy()
  255. ff.update({
  256. 'url': format_url,
  257. 'format_id': format_id,
  258. })
  259. formats.append(ff)
  260. elif determine_ext(format_url) == 'f4m':
  261. formats.extend(self._extract_f4m_formats(
  262. format_url, video_id, f4m_id=format_id))
  263. elif determine_ext(format_url) == 'm3u8':
  264. formats.extend(self._extract_m3u8_formats(
  265. format_url, video_id, 'mp4', m3u8_id=format_id))
  266. else:
  267. continue
  268. self._sort_formats(formats)
  269. title = remove_end(self._og_search_title(webpage), ' - iptv.ORF.at')
  270. description = self._og_search_description(webpage)
  271. upload_date = unified_strdate(self._html_search_meta(
  272. 'dc.date', webpage, 'upload date'))
  273. return {
  274. 'id': video_id,
  275. 'title': title,
  276. 'description': description,
  277. 'duration': duration,
  278. 'thumbnail': thumbnail,
  279. 'upload_date': upload_date,
  280. 'formats': formats,
  281. }
  282. class ORFFM4StoryIE(InfoExtractor):
  283. IE_NAME = 'orf:fm4:story'
  284. IE_DESC = 'fm4.orf.at stories'
  285. _VALID_URL = r'https?://fm4\.orf\.at/stories/(?P<id>\d+)'
  286. _TEST = {
  287. 'url': 'http://fm4.orf.at/stories/2865738/',
  288. 'playlist': [{
  289. 'md5': 'e1c2c706c45c7b34cf478bbf409907ca',
  290. 'info_dict': {
  291. 'id': '547792',
  292. 'ext': 'flv',
  293. 'title': 'Manu Delago und Inner Tongue live',
  294. '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.',
  295. 'duration': 1748.52,
  296. 'thumbnail': r're:^https?://.*\.jpg$',
  297. 'upload_date': '20170913',
  298. },
  299. }, {
  300. 'md5': 'c6dd2179731f86f4f55a7b49899d515f',
  301. 'info_dict': {
  302. 'id': '547798',
  303. 'ext': 'flv',
  304. 'title': 'Manu Delago und Inner Tongue live (2)',
  305. 'duration': 1504.08,
  306. 'thumbnail': r're:^https?://.*\.jpg$',
  307. 'upload_date': '20170913',
  308. '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.',
  309. },
  310. }],
  311. }
  312. def _real_extract(self, url):
  313. story_id = self._match_id(url)
  314. webpage = self._download_webpage(url, story_id)
  315. entries = []
  316. all_ids = orderedSet(re.findall(r'data-video(?:id)?="(\d+)"', webpage))
  317. for idx, video_id in enumerate(all_ids):
  318. data = self._download_json(
  319. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  320. video_id)[0]
  321. duration = float_or_none(data['duration'], 1000)
  322. video = data['sources']['q8c']
  323. load_balancer_url = video['loadBalancerUrl']
  324. abr = int_or_none(video.get('audioBitrate'))
  325. vbr = int_or_none(video.get('bitrate'))
  326. fps = int_or_none(video.get('videoFps'))
  327. width = int_or_none(video.get('videoWidth'))
  328. height = int_or_none(video.get('videoHeight'))
  329. thumbnail = video.get('preview')
  330. rendition = self._download_json(
  331. load_balancer_url, video_id, transform_source=strip_jsonp)
  332. f = {
  333. 'abr': abr,
  334. 'vbr': vbr,
  335. 'fps': fps,
  336. 'width': width,
  337. 'height': height,
  338. }
  339. formats = []
  340. for format_id, format_url in rendition['redirect'].items():
  341. if format_id == 'rtmp':
  342. ff = f.copy()
  343. ff.update({
  344. 'url': format_url,
  345. 'format_id': format_id,
  346. })
  347. formats.append(ff)
  348. elif determine_ext(format_url) == 'f4m':
  349. formats.extend(self._extract_f4m_formats(
  350. format_url, video_id, f4m_id=format_id))
  351. elif determine_ext(format_url) == 'm3u8':
  352. formats.extend(self._extract_m3u8_formats(
  353. format_url, video_id, 'mp4', m3u8_id=format_id))
  354. else:
  355. continue
  356. self._sort_formats(formats)
  357. title = remove_end(self._og_search_title(webpage), ' - fm4.ORF.at')
  358. if idx >= 1:
  359. # Titles are duplicates, make them unique
  360. title += ' (' + str(idx + 1) + ')'
  361. description = self._og_search_description(webpage)
  362. upload_date = unified_strdate(self._html_search_meta(
  363. 'dc.date', webpage, 'upload date'))
  364. entries.append({
  365. 'id': video_id,
  366. 'title': title,
  367. 'description': description,
  368. 'duration': duration,
  369. 'thumbnail': thumbnail,
  370. 'upload_date': upload_date,
  371. 'formats': formats,
  372. })
  373. return self.playlist_result(entries)