orf.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. clean_html,
  8. determine_ext,
  9. float_or_none,
  10. HEADRequest,
  11. int_or_none,
  12. orderedSet,
  13. remove_end,
  14. str_or_none,
  15. strip_jsonp,
  16. unescapeHTML,
  17. unified_strdate,
  18. url_or_none,
  19. )
  20. class ORFTVthekIE(InfoExtractor):
  21. IE_NAME = 'orf:tvthek'
  22. IE_DESC = 'ORF TVthek'
  23. _VALID_URL = r'https?://tvthek\.orf\.at/(?:[^/]+/)+(?P<id>\d+)'
  24. _TESTS = [{
  25. 'url': 'http://tvthek.orf.at/program/Aufgetischt/2745173/Aufgetischt-Mit-der-Steirischen-Tafelrunde/8891389',
  26. 'playlist': [{
  27. 'md5': '2942210346ed779588f428a92db88712',
  28. 'info_dict': {
  29. 'id': '8896777',
  30. 'ext': 'mp4',
  31. 'title': 'Aufgetischt: Mit der Steirischen Tafelrunde',
  32. 'description': 'md5:c1272f0245537812d4e36419c207b67d',
  33. 'duration': 2668,
  34. 'upload_date': '20141208',
  35. },
  36. }],
  37. 'skip': 'Blocked outside of Austria / Germany',
  38. }, {
  39. 'url': 'http://tvthek.orf.at/topic/Im-Wandel-der-Zeit/8002126/Best-of-Ingrid-Thurnher/7982256',
  40. 'info_dict': {
  41. 'id': '7982259',
  42. 'ext': 'mp4',
  43. 'title': 'Best of Ingrid Thurnher',
  44. 'upload_date': '20140527',
  45. '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".',
  46. },
  47. 'params': {
  48. 'skip_download': True, # rtsp downloads
  49. },
  50. 'skip': 'Blocked outside of Austria / Germany',
  51. }, {
  52. 'url': 'http://tvthek.orf.at/topic/Fluechtlingskrise/10463081/Heimat-Fremde-Heimat/13879132/Senioren-betreuen-Migrantenkinder/13879141',
  53. 'only_matching': True,
  54. }, {
  55. 'url': 'http://tvthek.orf.at/profile/Universum/35429',
  56. 'only_matching': True,
  57. }]
  58. def _real_extract(self, url):
  59. playlist_id = self._match_id(url)
  60. webpage = self._download_webpage(url, playlist_id)
  61. data_jsb = self._parse_json(
  62. self._search_regex(
  63. r'<div[^>]+class=(["\']).*?VideoPlaylist.*?\1[^>]+data-jsb=(["\'])(?P<json>.+?)\2',
  64. webpage, 'playlist', group='json'),
  65. playlist_id, transform_source=unescapeHTML)['playlist']['videos']
  66. entries = []
  67. for sd in data_jsb:
  68. video_id, title = sd.get('id'), sd.get('title')
  69. if not video_id or not title:
  70. continue
  71. video_id = compat_str(video_id)
  72. formats = []
  73. for fd in sd['sources']:
  74. src = url_or_none(fd.get('src'))
  75. if not src:
  76. continue
  77. format_id_list = []
  78. for key in ('delivery', 'quality', 'quality_string'):
  79. value = fd.get(key)
  80. if value:
  81. format_id_list.append(value)
  82. format_id = '-'.join(format_id_list)
  83. ext = determine_ext(src)
  84. if ext == 'm3u8':
  85. m3u8_formats = self._extract_m3u8_formats(
  86. src, video_id, 'mp4', m3u8_id=format_id, fatal=False)
  87. if any('/geoprotection' in f['url'] for f in m3u8_formats):
  88. self.raise_geo_restricted()
  89. formats.extend(m3u8_formats)
  90. elif ext == 'f4m':
  91. formats.extend(self._extract_f4m_formats(
  92. src, video_id, f4m_id=format_id, fatal=False))
  93. else:
  94. formats.append({
  95. 'format_id': format_id,
  96. 'url': src,
  97. 'protocol': fd.get('protocol'),
  98. })
  99. # Check for geoblocking.
  100. # There is a property is_geoprotection, but that's always false
  101. geo_str = sd.get('geoprotection_string')
  102. if geo_str:
  103. try:
  104. http_url = next(
  105. f['url']
  106. for f in formats
  107. if re.match(r'^https?://.*\.mp4$', f['url']))
  108. except StopIteration:
  109. pass
  110. else:
  111. req = HEADRequest(http_url)
  112. self._request_webpage(
  113. req, video_id,
  114. note='Testing for geoblocking',
  115. errnote=((
  116. 'This video seems to be blocked outside of %s. '
  117. 'You may want to try the streaming-* formats.')
  118. % geo_str),
  119. fatal=False)
  120. self._check_formats(formats, video_id)
  121. self._sort_formats(formats)
  122. subtitles = {}
  123. for sub in sd.get('subtitles', []):
  124. sub_src = sub.get('src')
  125. if not sub_src:
  126. continue
  127. subtitles.setdefault(sub.get('lang', 'de-AT'), []).append({
  128. 'url': sub_src,
  129. })
  130. upload_date = unified_strdate(sd.get('created_date'))
  131. thumbnails = []
  132. preview = sd.get('preview_image_url')
  133. if preview:
  134. thumbnails.append({
  135. 'id': 'preview',
  136. 'url': preview,
  137. 'preference': 0,
  138. })
  139. image = sd.get('image_full_url')
  140. if not image and len(data_jsb) == 1:
  141. image = self._og_search_thumbnail(webpage)
  142. if image:
  143. thumbnails.append({
  144. 'id': 'full',
  145. 'url': image,
  146. 'preference': 1,
  147. })
  148. entries.append({
  149. '_type': 'video',
  150. 'id': video_id,
  151. 'title': title,
  152. 'formats': formats,
  153. 'subtitles': subtitles,
  154. 'description': sd.get('description'),
  155. 'duration': int_or_none(sd.get('duration_in_seconds')),
  156. 'upload_date': upload_date,
  157. 'thumbnails': thumbnails,
  158. })
  159. return {
  160. '_type': 'playlist',
  161. 'entries': entries,
  162. 'id': playlist_id,
  163. }
  164. class ORFRadioIE(InfoExtractor):
  165. def _real_extract(self, url):
  166. mobj = re.match(self._VALID_URL, url)
  167. show_date = mobj.group('date')
  168. show_id = mobj.group('show')
  169. data = self._download_json(
  170. 'http://audioapi.orf.at/%s/api/json/current/broadcast/%s/%s'
  171. % (self._API_STATION, show_id, show_date), show_id)
  172. entries = []
  173. for info in data['streams']:
  174. loop_stream_id = str_or_none(info.get('loopStreamId'))
  175. if not loop_stream_id:
  176. continue
  177. title = str_or_none(data.get('title'))
  178. if not title:
  179. continue
  180. start = int_or_none(info.get('start'), scale=1000)
  181. end = int_or_none(info.get('end'), scale=1000)
  182. duration = end - start if end and start else None
  183. entries.append({
  184. 'id': loop_stream_id.replace('.mp3', ''),
  185. 'url': 'https://loopstream01.apa.at/?channel=%s&id=%s' % (self._LOOP_STATION, loop_stream_id),
  186. 'title': title,
  187. 'description': clean_html(data.get('subtitle')),
  188. 'duration': duration,
  189. 'timestamp': start,
  190. 'ext': 'mp3',
  191. 'series': data.get('programTitle'),
  192. })
  193. return {
  194. '_type': 'playlist',
  195. 'id': show_id,
  196. 'title': data.get('title'),
  197. 'description': clean_html(data.get('subtitle')),
  198. 'entries': entries,
  199. }
  200. class ORFFM4IE(ORFRadioIE):
  201. IE_NAME = 'orf:fm4'
  202. IE_DESC = 'radio FM4'
  203. _VALID_URL = r'https?://(?P<station>fm4)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>4\w+)'
  204. _API_STATION = 'fm4'
  205. _LOOP_STATION = 'fm4'
  206. _TEST = {
  207. 'url': 'http://fm4.orf.at/player/20170107/4CC',
  208. 'md5': '2b0be47375432a7ef104453432a19212',
  209. 'info_dict': {
  210. 'id': '2017-01-07_2100_tl_54_7DaysSat18_31295',
  211. 'ext': 'mp3',
  212. 'title': 'Solid Steel Radioshow',
  213. 'description': 'Die Mixshow von Coldcut und Ninja Tune.',
  214. 'duration': 3599,
  215. 'timestamp': 1483819257,
  216. 'upload_date': '20170107',
  217. },
  218. 'skip': 'Shows from ORF radios are only available for 7 days.',
  219. 'only_matching': True,
  220. }
  221. class ORFNOEIE(ORFRadioIE):
  222. IE_NAME = 'orf:noe'
  223. IE_DESC = 'Radio Niederösterreich'
  224. _VALID_URL = r'https?://(?P<station>noe)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  225. _API_STATION = 'noe'
  226. _LOOP_STATION = 'oe2n'
  227. _TEST = {
  228. 'url': 'https://noe.orf.at/player/20200423/NGM',
  229. 'only_matching': True,
  230. }
  231. class ORFWIEIE(ORFRadioIE):
  232. IE_NAME = 'orf:wien'
  233. IE_DESC = 'Radio Wien'
  234. _VALID_URL = r'https?://(?P<station>wien)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  235. _API_STATION = 'wie'
  236. _LOOP_STATION = 'oe2w'
  237. _TEST = {
  238. 'url': 'https://wien.orf.at/player/20200423/WGUM',
  239. 'only_matching': True,
  240. }
  241. class ORFBGLIE(ORFRadioIE):
  242. IE_NAME = 'orf:burgenland'
  243. IE_DESC = 'Radio Burgenland'
  244. _VALID_URL = r'https?://(?P<station>burgenland)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  245. _API_STATION = 'bgl'
  246. _LOOP_STATION = 'oe2b'
  247. _TEST = {
  248. 'url': 'https://burgenland.orf.at/player/20200423/BGM',
  249. 'only_matching': True,
  250. }
  251. class ORFOOEIE(ORFRadioIE):
  252. IE_NAME = 'orf:oberoesterreich'
  253. IE_DESC = 'Radio Oberösterreich'
  254. _VALID_URL = r'https?://(?P<station>ooe)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  255. _API_STATION = 'ooe'
  256. _LOOP_STATION = 'oe2o'
  257. _TEST = {
  258. 'url': 'https://ooe.orf.at/player/20200423/OGMO',
  259. 'only_matching': True,
  260. }
  261. class ORFSTMIE(ORFRadioIE):
  262. IE_NAME = 'orf:steiermark'
  263. IE_DESC = 'Radio Steiermark'
  264. _VALID_URL = r'https?://(?P<station>steiermark)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  265. _API_STATION = 'stm'
  266. _LOOP_STATION = 'oe2st'
  267. _TEST = {
  268. 'url': 'https://steiermark.orf.at/player/20200423/STGMS',
  269. 'only_matching': True,
  270. }
  271. class ORFKTNIE(ORFRadioIE):
  272. IE_NAME = 'orf:kaernten'
  273. IE_DESC = 'Radio Kärnten'
  274. _VALID_URL = r'https?://(?P<station>kaernten)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  275. _API_STATION = 'ktn'
  276. _LOOP_STATION = 'oe2k'
  277. _TEST = {
  278. 'url': 'https://kaernten.orf.at/player/20200423/KGUMO',
  279. 'only_matching': True,
  280. }
  281. class ORFSBGIE(ORFRadioIE):
  282. IE_NAME = 'orf:salzburg'
  283. IE_DESC = 'Radio Salzburg'
  284. _VALID_URL = r'https?://(?P<station>salzburg)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  285. _API_STATION = 'sbg'
  286. _LOOP_STATION = 'oe2s'
  287. _TEST = {
  288. 'url': 'https://salzburg.orf.at/player/20200423/SGUM',
  289. 'only_matching': True,
  290. }
  291. class ORFTIRIE(ORFRadioIE):
  292. IE_NAME = 'orf:tirol'
  293. IE_DESC = 'Radio Tirol'
  294. _VALID_URL = r'https?://(?P<station>tirol)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  295. _API_STATION = 'tir'
  296. _LOOP_STATION = 'oe2t'
  297. _TEST = {
  298. 'url': 'https://tirol.orf.at/player/20200423/TGUMO',
  299. 'only_matching': True,
  300. }
  301. class ORFVBGIE(ORFRadioIE):
  302. IE_NAME = 'orf:vorarlberg'
  303. IE_DESC = 'Radio Vorarlberg'
  304. _VALID_URL = r'https?://(?P<station>vorarlberg)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  305. _API_STATION = 'vbg'
  306. _LOOP_STATION = 'oe2v'
  307. _TEST = {
  308. 'url': 'https://vorarlberg.orf.at/player/20200423/VGUM',
  309. 'only_matching': True,
  310. }
  311. class ORFOE3IE(ORFRadioIE):
  312. IE_NAME = 'orf:oe3'
  313. IE_DESC = 'Radio Österreich 3'
  314. _VALID_URL = r'https?://(?P<station>oe3)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  315. _API_STATION = 'oe3'
  316. _LOOP_STATION = 'oe3'
  317. _TEST = {
  318. 'url': 'https://oe3.orf.at/player/20200424/3WEK',
  319. 'only_matching': True,
  320. }
  321. class ORFOE1IE(ORFRadioIE):
  322. IE_NAME = 'orf:oe1'
  323. IE_DESC = 'Radio Österreich 1'
  324. _VALID_URL = r'https?://(?P<station>oe1)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  325. _API_STATION = 'oe1'
  326. _LOOP_STATION = 'oe1'
  327. _TEST = {
  328. 'url': 'http://oe1.orf.at/player/20170108/456544',
  329. 'md5': '34d8a6e67ea888293741c86a099b745b',
  330. 'info_dict': {
  331. 'id': '2017-01-08_0759_tl_51_7DaysSun6_256141',
  332. 'ext': 'mp3',
  333. 'title': 'Morgenjournal',
  334. 'duration': 609,
  335. 'timestamp': 1483858796,
  336. 'upload_date': '20170108',
  337. },
  338. 'skip': 'Shows from ORF radios are only available for 7 days.'
  339. }
  340. class ORFIPTVIE(InfoExtractor):
  341. IE_NAME = 'orf:iptv'
  342. IE_DESC = 'iptv.ORF.at'
  343. _VALID_URL = r'https?://iptv\.orf\.at/(?:#/)?stories/(?P<id>\d+)'
  344. _TEST = {
  345. 'url': 'http://iptv.orf.at/stories/2275236/',
  346. 'md5': 'c8b22af4718a4b4af58342529453e3e5',
  347. 'info_dict': {
  348. 'id': '350612',
  349. 'ext': 'flv',
  350. 'title': 'Weitere Evakuierungen um Vulkan Calbuco',
  351. 'description': 'md5:d689c959bdbcf04efeddedbf2299d633',
  352. 'duration': 68.197,
  353. 'thumbnail': r're:^https?://.*\.jpg$',
  354. 'upload_date': '20150425',
  355. },
  356. }
  357. def _real_extract(self, url):
  358. story_id = self._match_id(url)
  359. webpage = self._download_webpage(
  360. 'http://iptv.orf.at/stories/%s' % story_id, story_id)
  361. video_id = self._search_regex(
  362. r'data-video(?:id)?="(\d+)"', webpage, 'video id')
  363. data = self._download_json(
  364. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  365. video_id)[0]
  366. duration = float_or_none(data['duration'], 1000)
  367. video = data['sources']['default']
  368. load_balancer_url = video['loadBalancerUrl']
  369. abr = int_or_none(video.get('audioBitrate'))
  370. vbr = int_or_none(video.get('bitrate'))
  371. fps = int_or_none(video.get('videoFps'))
  372. width = int_or_none(video.get('videoWidth'))
  373. height = int_or_none(video.get('videoHeight'))
  374. thumbnail = video.get('preview')
  375. rendition = self._download_json(
  376. load_balancer_url, video_id, transform_source=strip_jsonp)
  377. f = {
  378. 'abr': abr,
  379. 'vbr': vbr,
  380. 'fps': fps,
  381. 'width': width,
  382. 'height': height,
  383. }
  384. formats = []
  385. for format_id, format_url in rendition['redirect'].items():
  386. if format_id == 'rtmp':
  387. ff = f.copy()
  388. ff.update({
  389. 'url': format_url,
  390. 'format_id': format_id,
  391. })
  392. formats.append(ff)
  393. elif determine_ext(format_url) == 'f4m':
  394. formats.extend(self._extract_f4m_formats(
  395. format_url, video_id, f4m_id=format_id))
  396. elif determine_ext(format_url) == 'm3u8':
  397. formats.extend(self._extract_m3u8_formats(
  398. format_url, video_id, 'mp4', m3u8_id=format_id))
  399. else:
  400. continue
  401. self._sort_formats(formats)
  402. title = remove_end(self._og_search_title(webpage), ' - iptv.ORF.at')
  403. description = self._og_search_description(webpage)
  404. upload_date = unified_strdate(self._html_search_meta(
  405. 'dc.date', webpage, 'upload date'))
  406. return {
  407. 'id': video_id,
  408. 'title': title,
  409. 'description': description,
  410. 'duration': duration,
  411. 'thumbnail': thumbnail,
  412. 'upload_date': upload_date,
  413. 'formats': formats,
  414. }
  415. class ORFFM4StoryIE(InfoExtractor):
  416. IE_NAME = 'orf:fm4:story'
  417. IE_DESC = 'fm4.orf.at stories'
  418. _VALID_URL = r'https?://fm4\.orf\.at/stories/(?P<id>\d+)'
  419. _TEST = {
  420. 'url': 'http://fm4.orf.at/stories/2865738/',
  421. 'playlist': [{
  422. 'md5': 'e1c2c706c45c7b34cf478bbf409907ca',
  423. 'info_dict': {
  424. 'id': '547792',
  425. 'ext': 'flv',
  426. 'title': 'Manu Delago und Inner Tongue live',
  427. '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.',
  428. 'duration': 1748.52,
  429. 'thumbnail': r're:^https?://.*\.jpg$',
  430. 'upload_date': '20170913',
  431. },
  432. }, {
  433. 'md5': 'c6dd2179731f86f4f55a7b49899d515f',
  434. 'info_dict': {
  435. 'id': '547798',
  436. 'ext': 'flv',
  437. 'title': 'Manu Delago und Inner Tongue live (2)',
  438. 'duration': 1504.08,
  439. 'thumbnail': r're:^https?://.*\.jpg$',
  440. 'upload_date': '20170913',
  441. '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.',
  442. },
  443. }],
  444. }
  445. def _real_extract(self, url):
  446. story_id = self._match_id(url)
  447. webpage = self._download_webpage(url, story_id)
  448. entries = []
  449. all_ids = orderedSet(re.findall(r'data-video(?:id)?="(\d+)"', webpage))
  450. for idx, video_id in enumerate(all_ids):
  451. data = self._download_json(
  452. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  453. video_id)[0]
  454. duration = float_or_none(data['duration'], 1000)
  455. video = data['sources']['q8c']
  456. load_balancer_url = video['loadBalancerUrl']
  457. abr = int_or_none(video.get('audioBitrate'))
  458. vbr = int_or_none(video.get('bitrate'))
  459. fps = int_or_none(video.get('videoFps'))
  460. width = int_or_none(video.get('videoWidth'))
  461. height = int_or_none(video.get('videoHeight'))
  462. thumbnail = video.get('preview')
  463. rendition = self._download_json(
  464. load_balancer_url, video_id, transform_source=strip_jsonp)
  465. f = {
  466. 'abr': abr,
  467. 'vbr': vbr,
  468. 'fps': fps,
  469. 'width': width,
  470. 'height': height,
  471. }
  472. formats = []
  473. for format_id, format_url in rendition['redirect'].items():
  474. if format_id == 'rtmp':
  475. ff = f.copy()
  476. ff.update({
  477. 'url': format_url,
  478. 'format_id': format_id,
  479. })
  480. formats.append(ff)
  481. elif determine_ext(format_url) == 'f4m':
  482. formats.extend(self._extract_f4m_formats(
  483. format_url, video_id, f4m_id=format_id))
  484. elif determine_ext(format_url) == 'm3u8':
  485. formats.extend(self._extract_m3u8_formats(
  486. format_url, video_id, 'mp4', m3u8_id=format_id))
  487. else:
  488. continue
  489. self._sort_formats(formats)
  490. title = remove_end(self._og_search_title(webpage), ' - fm4.ORF.at')
  491. if idx >= 1:
  492. # Titles are duplicates, make them unique
  493. title += ' (' + str(idx + 1) + ')'
  494. description = self._og_search_description(webpage)
  495. upload_date = unified_strdate(self._html_search_meta(
  496. 'dc.date', webpage, 'upload date'))
  497. entries.append({
  498. 'id': video_id,
  499. 'title': title,
  500. 'description': description,
  501. 'duration': duration,
  502. 'thumbnail': thumbnail,
  503. 'upload_date': upload_date,
  504. 'formats': formats,
  505. })
  506. return self.playlist_result(entries)