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.

322 lines
11 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import calendar
  5. import datetime
  6. from .common import InfoExtractor
  7. from ..compat import compat_str
  8. from ..utils import (
  9. HEADRequest,
  10. unified_strdate,
  11. strip_jsonp,
  12. int_or_none,
  13. float_or_none,
  14. determine_ext,
  15. remove_end,
  16. unescapeHTML,
  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. 'skip_download': True,
  52. }, {
  53. 'url': 'http://tvthek.orf.at/profile/Universum/35429',
  54. 'skip_download': 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. def quality_to_int(s):
  65. m = re.search('([0-9]+)', s)
  66. if m is None:
  67. return -1
  68. return int(m.group(1))
  69. entries = []
  70. for sd in data_jsb:
  71. video_id, title = sd.get('id'), sd.get('title')
  72. if not video_id or not title:
  73. continue
  74. video_id = compat_str(video_id)
  75. formats = [{
  76. 'preference': -10 if fd['delivery'] == 'hls' else None,
  77. 'format_id': '%s-%s-%s' % (
  78. fd['delivery'], fd['quality'], fd['quality_string']),
  79. 'url': fd['src'],
  80. 'protocol': fd['protocol'],
  81. 'quality': quality_to_int(fd['quality']),
  82. } for fd in sd['sources']]
  83. # Check for geoblocking.
  84. # There is a property is_geoprotection, but that's always false
  85. geo_str = sd.get('geoprotection_string')
  86. if geo_str:
  87. try:
  88. http_url = next(
  89. f['url']
  90. for f in formats
  91. if re.match(r'^https?://.*\.mp4$', f['url']))
  92. except StopIteration:
  93. pass
  94. else:
  95. req = HEADRequest(http_url)
  96. self._request_webpage(
  97. req, video_id,
  98. note='Testing for geoblocking',
  99. errnote=((
  100. 'This video seems to be blocked outside of %s. '
  101. 'You may want to try the streaming-* formats.')
  102. % geo_str),
  103. fatal=False)
  104. self._check_formats(formats, video_id)
  105. self._sort_formats(formats)
  106. subtitles = {}
  107. for sub in sd.get('subtitles', []):
  108. sub_src = sub.get('src')
  109. if not sub_src:
  110. continue
  111. subtitles.setdefault(sub.get('lang', 'de-AT'), []).append({
  112. 'url': sub_src,
  113. })
  114. upload_date = unified_strdate(sd.get('created_date'))
  115. entries.append({
  116. '_type': 'video',
  117. 'id': video_id,
  118. 'title': title,
  119. 'formats': formats,
  120. 'subtitles': subtitles,
  121. 'description': sd.get('description'),
  122. 'duration': int_or_none(sd.get('duration_in_seconds')),
  123. 'upload_date': upload_date,
  124. 'thumbnail': sd.get('image_full_url'),
  125. })
  126. return {
  127. '_type': 'playlist',
  128. 'entries': entries,
  129. 'id': playlist_id,
  130. }
  131. class ORFOE1IE(InfoExtractor):
  132. IE_NAME = 'orf:oe1'
  133. IE_DESC = 'Radio Österreich 1'
  134. _VALID_URL = r'https?://oe1\.orf\.at/(?:programm/|konsole\?.*?\btrack_id=)(?P<id>[0-9]+)'
  135. # Audios on ORF radio are only available for 7 days, so we can't add tests.
  136. _TESTS = [{
  137. 'url': 'http://oe1.orf.at/konsole?show=on_demand#?track_id=394211',
  138. 'only_matching': True,
  139. }, {
  140. 'url': 'http://oe1.orf.at/konsole?show=ondemand&track_id=443608&load_day=/programm/konsole/tag/20160726',
  141. 'only_matching': True,
  142. }]
  143. def _real_extract(self, url):
  144. show_id = self._match_id(url)
  145. data = self._download_json(
  146. 'http://oe1.orf.at/programm/%s/konsole' % show_id,
  147. show_id
  148. )
  149. timestamp = datetime.datetime.strptime('%s %s' % (
  150. data['item']['day_label'],
  151. data['item']['time']
  152. ), '%d.%m.%Y %H:%M')
  153. unix_timestamp = calendar.timegm(timestamp.utctimetuple())
  154. return {
  155. 'id': show_id,
  156. 'title': data['item']['title'],
  157. 'url': data['item']['url_stream'],
  158. 'ext': 'mp3',
  159. 'description': data['item'].get('info'),
  160. 'timestamp': unix_timestamp
  161. }
  162. class ORFFM4IE(InfoExtractor):
  163. IE_NAME = 'orf:fm4'
  164. IE_DESC = 'radio FM4'
  165. _VALID_URL = r'https?://fm4\.orf\.at/(?:7tage/?#|player/)(?P<date>[0-9]+)/(?P<show>\w+)'
  166. _TEST = {
  167. 'url': 'http://fm4.orf.at/player/20160110/IS/',
  168. 'md5': '01e736e8f1cef7e13246e880a59ad298',
  169. 'info_dict': {
  170. 'id': '2016-01-10_2100_tl_54_7DaysSun13_11244',
  171. 'ext': 'mp3',
  172. 'title': 'Im Sumpf',
  173. 'description': 'md5:384c543f866c4e422a55f66a62d669cd',
  174. 'duration': 7173,
  175. 'timestamp': 1452456073,
  176. 'upload_date': '20160110',
  177. },
  178. 'skip': 'Live streams on FM4 got deleted soon',
  179. }
  180. def _real_extract(self, url):
  181. mobj = re.match(self._VALID_URL, url)
  182. show_date = mobj.group('date')
  183. show_id = mobj.group('show')
  184. data = self._download_json(
  185. 'http://audioapi.orf.at/fm4/json/2.0/broadcasts/%s/4%s' % (show_date, show_id),
  186. show_id
  187. )
  188. def extract_entry_dict(info, title, subtitle):
  189. return {
  190. 'id': info['loopStreamId'].replace('.mp3', ''),
  191. 'url': 'http://loopstream01.apa.at/?channel=fm4&id=%s' % info['loopStreamId'],
  192. 'title': title,
  193. 'description': subtitle,
  194. 'duration': (info['end'] - info['start']) / 1000,
  195. 'timestamp': info['start'] / 1000,
  196. 'ext': 'mp3'
  197. }
  198. entries = [extract_entry_dict(t, data['title'], data['subtitle']) for t in data['streams']]
  199. return {
  200. '_type': 'playlist',
  201. 'id': show_id,
  202. 'title': data['title'],
  203. 'description': data['subtitle'],
  204. 'entries': entries
  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. }