orf.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. entries.append({
  132. '_type': 'video',
  133. 'id': video_id,
  134. 'title': title,
  135. 'formats': formats,
  136. 'subtitles': subtitles,
  137. 'description': sd.get('description'),
  138. 'duration': int_or_none(sd.get('duration_in_seconds')),
  139. 'upload_date': upload_date,
  140. 'thumbnail': sd.get('image_full_url'),
  141. })
  142. return {
  143. '_type': 'playlist',
  144. 'entries': entries,
  145. 'id': playlist_id,
  146. }
  147. class ORFRadioIE(InfoExtractor):
  148. def _real_extract(self, url):
  149. mobj = re.match(self._VALID_URL, url)
  150. show_date = mobj.group('date')
  151. show_id = mobj.group('show')
  152. data = self._download_json(
  153. 'http://audioapi.orf.at/%s/api/json/current/broadcast/%s/%s'
  154. % (self._API_STATION, show_id, show_date), show_id)
  155. entries = []
  156. for info in data['streams']:
  157. loop_stream_id = str_or_none(info.get('loopStreamId'))
  158. if not loop_stream_id:
  159. continue
  160. title = str_or_none(data.get('title'))
  161. if not title:
  162. continue
  163. start = int_or_none(info.get('start'), scale=1000)
  164. end = int_or_none(info.get('end'), scale=1000)
  165. duration = end - start if end and start else None
  166. entries.append({
  167. 'id': loop_stream_id.replace('.mp3', ''),
  168. 'url': 'http://loopstream01.apa.at/?channel=%s&id=%s' % (self._LOOP_STATION, loop_stream_id),
  169. 'title': title,
  170. 'description': clean_html(data.get('subtitle')),
  171. 'duration': duration,
  172. 'timestamp': start,
  173. 'ext': 'mp3',
  174. 'series': data.get('programTitle'),
  175. })
  176. return {
  177. '_type': 'playlist',
  178. 'id': show_id,
  179. 'title': data.get('title'),
  180. 'description': clean_html(data.get('subtitle')),
  181. 'entries': entries,
  182. }
  183. class ORFFM4IE(ORFRadioIE):
  184. IE_NAME = 'orf:fm4'
  185. IE_DESC = 'radio FM4'
  186. _VALID_URL = r'https?://(?P<station>fm4)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>4\w+)'
  187. _API_STATION = 'fm4'
  188. _LOOP_STATION = 'fm4'
  189. _TEST = {
  190. 'url': 'http://fm4.orf.at/player/20170107/4CC',
  191. 'md5': '2b0be47375432a7ef104453432a19212',
  192. 'info_dict': {
  193. 'id': '2017-01-07_2100_tl_54_7DaysSat18_31295',
  194. 'ext': 'mp3',
  195. 'title': 'Solid Steel Radioshow',
  196. 'description': 'Die Mixshow von Coldcut und Ninja Tune.',
  197. 'duration': 3599,
  198. 'timestamp': 1483819257,
  199. 'upload_date': '20170107',
  200. },
  201. 'skip': 'Shows from ORF radios are only available for 7 days.',
  202. 'only_matching': True,
  203. }
  204. class ORFNOEIE(ORFRadioIE):
  205. IE_NAME = 'orf:noe'
  206. IE_DESC = 'Radio Niederösterreich'
  207. _VALID_URL = r'https?://(?P<station>noe)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  208. _API_STATION = 'noe'
  209. _LOOP_STATION = 'oe2n'
  210. _TEST = {
  211. 'url': 'https://noe.orf.at/player/20200423/NGM',
  212. 'only_matching': True,
  213. }
  214. class ORFWIEIE(ORFRadioIE):
  215. IE_NAME = 'orf:wien'
  216. IE_DESC = 'Radio Wien'
  217. _VALID_URL = r'https?://(?P<station>wien)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  218. _API_STATION = 'wie'
  219. _LOOP_STATION = 'oe2w'
  220. _TEST = {
  221. 'url': 'https://wien.orf.at/player/20200423/WGUM',
  222. 'only_matching': True,
  223. }
  224. class ORFBGLIE(ORFRadioIE):
  225. IE_NAME = 'orf:burgenland'
  226. IE_DESC = 'Radio Burgenland'
  227. _VALID_URL = r'https?://(?P<station>burgenland)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  228. _API_STATION = 'bgl'
  229. _LOOP_STATION = 'oe2b'
  230. _TEST = {
  231. 'url': 'https://burgenland.orf.at/player/20200423/BGM',
  232. 'only_matching': True,
  233. }
  234. class ORFOOEIE(ORFRadioIE):
  235. IE_NAME = 'orf:oberoesterreich'
  236. IE_DESC = 'Radio Oberösterreich'
  237. _VALID_URL = r'https?://(?P<station>ooe)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  238. _API_STATION = 'ooe'
  239. _LOOP_STATION = 'oe2o'
  240. _TEST = {
  241. 'url': 'https://ooe.orf.at/player/20200423/OGMO',
  242. 'only_matching': True,
  243. }
  244. class ORFSTMIE(ORFRadioIE):
  245. IE_NAME = 'orf:steiermark'
  246. IE_DESC = 'Radio Steiermark'
  247. _VALID_URL = r'https?://(?P<station>steiermark)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  248. _API_STATION = 'stm'
  249. _LOOP_STATION = 'oe2st'
  250. _TEST = {
  251. 'url': 'https://steiermark.orf.at/player/20200423/STGMS',
  252. 'only_matching': True,
  253. }
  254. class ORFKTNIE(ORFRadioIE):
  255. IE_NAME = 'orf:kaernten'
  256. IE_DESC = 'Radio Kärnten'
  257. _VALID_URL = r'https?://(?P<station>kaernten)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  258. _API_STATION = 'ktn'
  259. _LOOP_STATION = 'oe2k'
  260. _TEST = {
  261. 'url': 'https://kaernten.orf.at/player/20200423/KGUMO',
  262. 'only_matching': True,
  263. }
  264. class ORFSBGIE(ORFRadioIE):
  265. IE_NAME = 'orf:salzburg'
  266. IE_DESC = 'Radio Salzburg'
  267. _VALID_URL = r'https?://(?P<station>salzburg)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  268. _API_STATION = 'sbg'
  269. _LOOP_STATION = 'oe2s'
  270. _TEST = {
  271. 'url': 'https://salzburg.orf.at/player/20200423/SGUM',
  272. 'only_matching': True,
  273. }
  274. class ORFTIRIE(ORFRadioIE):
  275. IE_NAME = 'orf:tirol'
  276. IE_DESC = 'Radio Tirol'
  277. _VALID_URL = r'https?://(?P<station>tirol)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  278. _API_STATION = 'tir'
  279. _LOOP_STATION = 'oe2t'
  280. _TEST = {
  281. 'url': 'https://tirol.orf.at/player/20200423/TGUMO',
  282. 'only_matching': True,
  283. }
  284. class ORFVBGIE(ORFRadioIE):
  285. IE_NAME = 'orf:vorarlberg'
  286. IE_DESC = 'Radio Vorarlberg'
  287. _VALID_URL = r'https?://(?P<station>vorarlberg)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  288. _API_STATION = 'vbg'
  289. _LOOP_STATION = 'oe2v'
  290. _TEST = {
  291. 'url': 'https://vorarlberg.orf.at/player/20200423/VGUM',
  292. 'only_matching': True,
  293. }
  294. class ORFOE3IE(ORFRadioIE):
  295. IE_NAME = 'orf:oe3'
  296. IE_DESC = 'Radio Österreich 3'
  297. _VALID_URL = r'https?://(?P<station>oe3)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  298. _API_STATION = 'oe3'
  299. _LOOP_STATION = 'oe3'
  300. _TEST = {
  301. 'url': 'https://oe3.orf.at/player/20200424/3WEK',
  302. 'only_matching': True,
  303. }
  304. class ORFOE1IE(ORFRadioIE):
  305. IE_NAME = 'orf:oe1'
  306. IE_DESC = 'Radio Österreich 1'
  307. _VALID_URL = r'https?://(?P<station>oe1)\.orf\.at/player/(?P<date>[0-9]+)/(?P<show>\w+)'
  308. _API_STATION = 'oe1'
  309. _LOOP_STATION = 'oe1'
  310. _TEST = {
  311. 'url': 'http://oe1.orf.at/player/20170108/456544',
  312. 'md5': '34d8a6e67ea888293741c86a099b745b',
  313. 'info_dict': {
  314. 'id': '2017-01-08_0759_tl_51_7DaysSun6_256141',
  315. 'ext': 'mp3',
  316. 'title': 'Morgenjournal',
  317. 'duration': 609,
  318. 'timestamp': 1483858796,
  319. 'upload_date': '20170108',
  320. },
  321. 'skip': 'Shows from ORF radios are only available for 7 days.'
  322. }
  323. class ORFIPTVIE(InfoExtractor):
  324. IE_NAME = 'orf:iptv'
  325. IE_DESC = 'iptv.ORF.at'
  326. _VALID_URL = r'https?://iptv\.orf\.at/(?:#/)?stories/(?P<id>\d+)'
  327. _TEST = {
  328. 'url': 'http://iptv.orf.at/stories/2275236/',
  329. 'md5': 'c8b22af4718a4b4af58342529453e3e5',
  330. 'info_dict': {
  331. 'id': '350612',
  332. 'ext': 'flv',
  333. 'title': 'Weitere Evakuierungen um Vulkan Calbuco',
  334. 'description': 'md5:d689c959bdbcf04efeddedbf2299d633',
  335. 'duration': 68.197,
  336. 'thumbnail': r're:^https?://.*\.jpg$',
  337. 'upload_date': '20150425',
  338. },
  339. }
  340. def _real_extract(self, url):
  341. story_id = self._match_id(url)
  342. webpage = self._download_webpage(
  343. 'http://iptv.orf.at/stories/%s' % story_id, story_id)
  344. video_id = self._search_regex(
  345. r'data-video(?:id)?="(\d+)"', webpage, 'video id')
  346. data = self._download_json(
  347. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  348. video_id)[0]
  349. duration = float_or_none(data['duration'], 1000)
  350. video = data['sources']['default']
  351. load_balancer_url = video['loadBalancerUrl']
  352. abr = int_or_none(video.get('audioBitrate'))
  353. vbr = int_or_none(video.get('bitrate'))
  354. fps = int_or_none(video.get('videoFps'))
  355. width = int_or_none(video.get('videoWidth'))
  356. height = int_or_none(video.get('videoHeight'))
  357. thumbnail = video.get('preview')
  358. rendition = self._download_json(
  359. load_balancer_url, video_id, transform_source=strip_jsonp)
  360. f = {
  361. 'abr': abr,
  362. 'vbr': vbr,
  363. 'fps': fps,
  364. 'width': width,
  365. 'height': height,
  366. }
  367. formats = []
  368. for format_id, format_url in rendition['redirect'].items():
  369. if format_id == 'rtmp':
  370. ff = f.copy()
  371. ff.update({
  372. 'url': format_url,
  373. 'format_id': format_id,
  374. })
  375. formats.append(ff)
  376. elif determine_ext(format_url) == 'f4m':
  377. formats.extend(self._extract_f4m_formats(
  378. format_url, video_id, f4m_id=format_id))
  379. elif determine_ext(format_url) == 'm3u8':
  380. formats.extend(self._extract_m3u8_formats(
  381. format_url, video_id, 'mp4', m3u8_id=format_id))
  382. else:
  383. continue
  384. self._sort_formats(formats)
  385. title = remove_end(self._og_search_title(webpage), ' - iptv.ORF.at')
  386. description = self._og_search_description(webpage)
  387. upload_date = unified_strdate(self._html_search_meta(
  388. 'dc.date', webpage, 'upload date'))
  389. return {
  390. 'id': video_id,
  391. 'title': title,
  392. 'description': description,
  393. 'duration': duration,
  394. 'thumbnail': thumbnail,
  395. 'upload_date': upload_date,
  396. 'formats': formats,
  397. }
  398. class ORFFM4StoryIE(InfoExtractor):
  399. IE_NAME = 'orf:fm4:story'
  400. IE_DESC = 'fm4.orf.at stories'
  401. _VALID_URL = r'https?://fm4\.orf\.at/stories/(?P<id>\d+)'
  402. _TEST = {
  403. 'url': 'http://fm4.orf.at/stories/2865738/',
  404. 'playlist': [{
  405. 'md5': 'e1c2c706c45c7b34cf478bbf409907ca',
  406. 'info_dict': {
  407. 'id': '547792',
  408. 'ext': 'flv',
  409. 'title': 'Manu Delago und Inner Tongue live',
  410. '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.',
  411. 'duration': 1748.52,
  412. 'thumbnail': r're:^https?://.*\.jpg$',
  413. 'upload_date': '20170913',
  414. },
  415. }, {
  416. 'md5': 'c6dd2179731f86f4f55a7b49899d515f',
  417. 'info_dict': {
  418. 'id': '547798',
  419. 'ext': 'flv',
  420. 'title': 'Manu Delago und Inner Tongue live (2)',
  421. 'duration': 1504.08,
  422. 'thumbnail': r're:^https?://.*\.jpg$',
  423. 'upload_date': '20170913',
  424. '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.',
  425. },
  426. }],
  427. }
  428. def _real_extract(self, url):
  429. story_id = self._match_id(url)
  430. webpage = self._download_webpage(url, story_id)
  431. entries = []
  432. all_ids = orderedSet(re.findall(r'data-video(?:id)?="(\d+)"', webpage))
  433. for idx, video_id in enumerate(all_ids):
  434. data = self._download_json(
  435. 'http://bits.orf.at/filehandler/static-api/json/current/data.json?file=%s' % video_id,
  436. video_id)[0]
  437. duration = float_or_none(data['duration'], 1000)
  438. video = data['sources']['q8c']
  439. load_balancer_url = video['loadBalancerUrl']
  440. abr = int_or_none(video.get('audioBitrate'))
  441. vbr = int_or_none(video.get('bitrate'))
  442. fps = int_or_none(video.get('videoFps'))
  443. width = int_or_none(video.get('videoWidth'))
  444. height = int_or_none(video.get('videoHeight'))
  445. thumbnail = video.get('preview')
  446. rendition = self._download_json(
  447. load_balancer_url, video_id, transform_source=strip_jsonp)
  448. f = {
  449. 'abr': abr,
  450. 'vbr': vbr,
  451. 'fps': fps,
  452. 'width': width,
  453. 'height': height,
  454. }
  455. formats = []
  456. for format_id, format_url in rendition['redirect'].items():
  457. if format_id == 'rtmp':
  458. ff = f.copy()
  459. ff.update({
  460. 'url': format_url,
  461. 'format_id': format_id,
  462. })
  463. formats.append(ff)
  464. elif determine_ext(format_url) == 'f4m':
  465. formats.extend(self._extract_f4m_formats(
  466. format_url, video_id, f4m_id=format_id))
  467. elif determine_ext(format_url) == 'm3u8':
  468. formats.extend(self._extract_m3u8_formats(
  469. format_url, video_id, 'mp4', m3u8_id=format_id))
  470. else:
  471. continue
  472. self._sort_formats(formats)
  473. title = remove_end(self._og_search_title(webpage), ' - fm4.ORF.at')
  474. if idx >= 1:
  475. # Titles are duplicates, make them unique
  476. title += ' (' + str(idx + 1) + ')'
  477. description = self._og_search_description(webpage)
  478. upload_date = unified_strdate(self._html_search_meta(
  479. 'dc.date', webpage, 'upload date'))
  480. entries.append({
  481. 'id': video_id,
  482. 'title': title,
  483. 'description': description,
  484. 'duration': duration,
  485. 'thumbnail': thumbnail,
  486. 'upload_date': upload_date,
  487. 'formats': formats,
  488. })
  489. return self.playlist_result(entries)