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.

425 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. }
  163. entries = [extract_entry_dict(t, data['title'], data['subtitle']) for t in data['streams']]
  164. return {
  165. '_type': 'playlist',
  166. 'id': show_id,
  167. 'title': data['title'],
  168. 'description': data['subtitle'],
  169. 'entries': entries
  170. }
  171. class ORFFM4IE(ORFRadioIE):
  172. IE_NAME = 'orf:fm4'
  173. IE_DESC = 'radio FM4'
  174. _VALID_URL = r'https?://(?P<station>fm4)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  175. _TEST = {
  176. 'url': 'http://fm4.orf.at/player/20170107/CC',
  177. 'md5': '2b0be47375432a7ef104453432a19212',
  178. 'info_dict': {
  179. 'id': '2017-01-07_2100_tl_54_7DaysSat18_31295',
  180. 'ext': 'mp3',
  181. 'title': 'Solid Steel Radioshow',
  182. 'description': 'Die Mixshow von Coldcut und Ninja Tune.',
  183. 'duration': 3599,
  184. 'timestamp': 1483819257,
  185. 'upload_date': '20170107',
  186. },
  187. 'skip': 'Shows from ORF radios are only available for 7 days.'
  188. }
  189. class ORFOE1IE(ORFRadioIE):
  190. IE_NAME = 'orf:oe1'
  191. IE_DESC = 'Radio Österreich 1'
  192. _VALID_URL = r'https?://(?P<station>oe1)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  193. _TEST = {
  194. 'url': 'http://oe1.orf.at/player/20170108/456544',
  195. 'md5': '34d8a6e67ea888293741c86a099b745b',
  196. 'info_dict': {
  197. 'id': '2017-01-08_0759_tl_51_7DaysSun6_256141',
  198. 'ext': 'mp3',
  199. 'title': 'Morgenjournal',
  200. 'duration': 609,
  201. 'timestamp': 1483858796,
  202. 'upload_date': '20170108',
  203. },
  204. 'skip': 'Shows from ORF radios are only available for 7 days.'
  205. }
  206. class ORFIPTVIE(InfoExtractor):
  207. IE_NAME = 'orf:iptv'
  208. IE_DESC = 'iptv.ORF.at'
  209. _VALID_URL = r'https?://iptv\.orf\.at/(?:#/)?stories/(?P<id>\d+)'
  210. _TEST = {
  211. 'url': 'http://iptv.orf.at/stories/2275236/',
  212. 'md5': 'c8b22af4718a4b4af58342529453e3e5',
  213. 'info_dict': {
  214. 'id': '350612',
  215. 'ext': 'flv',
  216. 'title': 'Weitere Evakuierungen um Vulkan Calbuco',
  217. 'description': 'md5:d689c959bdbcf04efeddedbf2299d633',
  218. 'duration': 68.197,
  219. 'thumbnail': r're:^https?://.*\.jpg$',
  220. 'upload_date': '20150425',
  221. },
  222. }
  223. def _real_extract(self, url):
  224. story_id = self._match_id(url)
  225. webpage = self._download_webpage(
  226. 'http://iptv.orf.at/stories/%s' % story_id, story_id)
  227. video_id = self._search_regex(
  228. r'data-video(?:id)?="(\d+)"', webpage, 'video id')
  229. data = self._download_json(
  230. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  231. video_id)[0]
  232. duration = float_or_none(data['duration'], 1000)
  233. video = data['sources']['default']
  234. load_balancer_url = video['loadBalancerUrl']
  235. abr = int_or_none(video.get('audioBitrate'))
  236. vbr = int_or_none(video.get('bitrate'))
  237. fps = int_or_none(video.get('videoFps'))
  238. width = int_or_none(video.get('videoWidth'))
  239. height = int_or_none(video.get('videoHeight'))
  240. thumbnail = video.get('preview')
  241. rendition = self._download_json(
  242. load_balancer_url, video_id, transform_source=strip_jsonp)
  243. f = {
  244. 'abr': abr,
  245. 'vbr': vbr,
  246. 'fps': fps,
  247. 'width': width,
  248. 'height': height,
  249. }
  250. formats = []
  251. for format_id, format_url in rendition['redirect'].items():
  252. if format_id == 'rtmp':
  253. ff = f.copy()
  254. ff.update({
  255. 'url': format_url,
  256. 'format_id': format_id,
  257. })
  258. formats.append(ff)
  259. elif determine_ext(format_url) == 'f4m':
  260. formats.extend(self._extract_f4m_formats(
  261. format_url, video_id, f4m_id=format_id))
  262. elif determine_ext(format_url) == 'm3u8':
  263. formats.extend(self._extract_m3u8_formats(
  264. format_url, video_id, 'mp4', m3u8_id=format_id))
  265. else:
  266. continue
  267. self._sort_formats(formats)
  268. title = remove_end(self._og_search_title(webpage), ' - iptv.ORF.at')
  269. description = self._og_search_description(webpage)
  270. upload_date = unified_strdate(self._html_search_meta(
  271. 'dc.date', webpage, 'upload date'))
  272. return {
  273. 'id': video_id,
  274. 'title': title,
  275. 'description': description,
  276. 'duration': duration,
  277. 'thumbnail': thumbnail,
  278. 'upload_date': upload_date,
  279. 'formats': formats,
  280. }
  281. class ORFFM4StoryIE(InfoExtractor):
  282. IE_NAME = 'orf:fm4:story'
  283. IE_DESC = 'fm4.orf.at stories'
  284. _VALID_URL = r'https?://fm4\.orf\.at/stories/(?P<id>\d+)'
  285. _TEST = {
  286. 'url': 'http://fm4.orf.at/stories/2865738/',
  287. 'playlist': [{
  288. 'md5': 'e1c2c706c45c7b34cf478bbf409907ca',
  289. 'info_dict': {
  290. 'id': '547792',
  291. 'ext': 'flv',
  292. 'title': 'Manu Delago und Inner Tongue live',
  293. '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.',
  294. 'duration': 1748.52,
  295. 'thumbnail': r're:^https?://.*\.jpg$',
  296. 'upload_date': '20170913',
  297. },
  298. }, {
  299. 'md5': 'c6dd2179731f86f4f55a7b49899d515f',
  300. 'info_dict': {
  301. 'id': '547798',
  302. 'ext': 'flv',
  303. 'title': 'Manu Delago und Inner Tongue live (2)',
  304. 'duration': 1504.08,
  305. 'thumbnail': r're:^https?://.*\.jpg$',
  306. 'upload_date': '20170913',
  307. '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.',
  308. },
  309. }],
  310. }
  311. def _real_extract(self, url):
  312. story_id = self._match_id(url)
  313. webpage = self._download_webpage(url, story_id)
  314. entries = []
  315. all_ids = orderedSet(re.findall(r'data-video(?:id)?="(\d+)"', webpage))
  316. for idx, video_id in enumerate(all_ids):
  317. data = self._download_json(
  318. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  319. video_id)[0]
  320. duration = float_or_none(data['duration'], 1000)
  321. video = data['sources']['q8c']
  322. load_balancer_url = video['loadBalancerUrl']
  323. abr = int_or_none(video.get('audioBitrate'))
  324. vbr = int_or_none(video.get('bitrate'))
  325. fps = int_or_none(video.get('videoFps'))
  326. width = int_or_none(video.get('videoWidth'))
  327. height = int_or_none(video.get('videoHeight'))
  328. thumbnail = video.get('preview')
  329. rendition = self._download_json(
  330. load_balancer_url, video_id, transform_source=strip_jsonp)
  331. f = {
  332. 'abr': abr,
  333. 'vbr': vbr,
  334. 'fps': fps,
  335. 'width': width,
  336. 'height': height,
  337. }
  338. formats = []
  339. for format_id, format_url in rendition['redirect'].items():
  340. if format_id == 'rtmp':
  341. ff = f.copy()
  342. ff.update({
  343. 'url': format_url,
  344. 'format_id': format_id,
  345. })
  346. formats.append(ff)
  347. elif determine_ext(format_url) == 'f4m':
  348. formats.extend(self._extract_f4m_formats(
  349. format_url, video_id, f4m_id=format_id))
  350. elif determine_ext(format_url) == 'm3u8':
  351. formats.extend(self._extract_m3u8_formats(
  352. format_url, video_id, 'mp4', m3u8_id=format_id))
  353. else:
  354. continue
  355. self._sort_formats(formats)
  356. title = remove_end(self._og_search_title(webpage), ' - fm4.ORF.at')
  357. if idx >= 1:
  358. # Titles are duplicates, make them unique
  359. title += ' (' + str(idx + 1) + ')'
  360. description = self._og_search_description(webpage)
  361. upload_date = unified_strdate(self._html_search_meta(
  362. 'dc.date', webpage, 'upload date'))
  363. entries.append({
  364. 'id': video_id,
  365. 'title': title,
  366. 'description': description,
  367. 'duration': duration,
  368. 'thumbnail': thumbnail,
  369. 'upload_date': upload_date,
  370. 'formats': formats,
  371. })
  372. return self.playlist_result(entries)