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.

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