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.

253 lines
8.9 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. compat_urlparse,
  8. )
  9. class FranceTVBaseInfoExtractor(InfoExtractor):
  10. def _extract_video(self, video_id):
  11. info = self._download_xml(
  12. 'http://www.francetvinfo.fr/appftv/webservices/video/'
  13. 'getInfosOeuvre.php?id-diffusion='
  14. + video_id, video_id, 'Downloading XML config')
  15. manifest_url = info.find('videos/video/url').text
  16. manifest_url = manifest_url.replace('/z/', '/i/')
  17. if manifest_url.startswith('rtmp'):
  18. formats = [{'url': manifest_url, 'ext': 'flv'}]
  19. else:
  20. formats = []
  21. available_formats = self._search_regex(r'/[^,]*,(.*?),k\.mp4', manifest_url, 'available formats')
  22. for index, format_descr in enumerate(available_formats.split(',')):
  23. format_info = {
  24. 'url': manifest_url.replace('manifest.f4m', 'index_%d_av.m3u8' % index),
  25. 'ext': 'mp4',
  26. }
  27. m_resolution = re.search(r'(?P<width>\d+)x(?P<height>\d+)', format_descr)
  28. if m_resolution is not None:
  29. format_info.update({
  30. 'width': int(m_resolution.group('width')),
  31. 'height': int(m_resolution.group('height')),
  32. })
  33. formats.append(format_info)
  34. thumbnail_path = info.find('image').text
  35. return {
  36. 'id': video_id,
  37. 'title': info.find('titre').text,
  38. 'formats': formats,
  39. 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', thumbnail_path),
  40. 'description': info.find('synopsis').text,
  41. }
  42. class PluzzIE(FranceTVBaseInfoExtractor):
  43. IE_NAME = 'pluzz.francetv.fr'
  44. _VALID_URL = r'https?://pluzz\.francetv\.fr/videos/(.*?)\.html'
  45. # Can't use tests, videos expire in 7 days
  46. def _real_extract(self, url):
  47. title = re.match(self._VALID_URL, url).group(1)
  48. webpage = self._download_webpage(url, title)
  49. video_id = self._search_regex(
  50. r'data-diffusion="(\d+)"', webpage, 'ID')
  51. return self._extract_video(video_id)
  52. class FranceTvInfoIE(FranceTVBaseInfoExtractor):
  53. IE_NAME = 'francetvinfo.fr'
  54. _VALID_URL = r'https?://(?:www|mobile)\.francetvinfo\.fr/.*/(?P<title>.+)\.html'
  55. _TESTS = [{
  56. 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
  57. 'info_dict': {
  58. 'id': '84981923',
  59. 'ext': 'mp4',
  60. 'title': 'Soir 3',
  61. },
  62. 'params': {
  63. 'skip_download': True,
  64. },
  65. }, {
  66. 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
  67. 'info_dict': {
  68. 'id': 'EV_20019',
  69. 'ext': 'mp4',
  70. 'title': 'Débat des candidats à la Commission européenne',
  71. 'description': 'Débat des candidats à la Commission européenne',
  72. },
  73. 'params': {
  74. 'skip_download': 'HLS (reqires ffmpeg)'
  75. }
  76. }]
  77. def _real_extract(self, url):
  78. mobj = re.match(self._VALID_URL, url)
  79. page_title = mobj.group('title')
  80. webpage = self._download_webpage(url, page_title)
  81. video_id = self._search_regex(r'id-video=((?:[^0-9]*?_)?[0-9]+)[@"]', webpage, 'video id')
  82. return self._extract_video(video_id)
  83. class FranceTVIE(FranceTVBaseInfoExtractor):
  84. IE_NAME = 'francetv'
  85. IE_DESC = 'France 2, 3, 4, 5 and Ô'
  86. _VALID_URL = r'''(?x)https?://www\.france[2345o]\.fr/
  87. (?:
  88. emissions/.*?/(videos|emissions)/(?P<id>[^/?]+)
  89. | (emissions?|jt)/(?P<key>[^/?]+)
  90. )'''
  91. _TESTS = [
  92. # france2
  93. {
  94. 'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
  95. 'file': '75540104.mp4',
  96. 'info_dict': {
  97. 'title': '13h15, le samedi...',
  98. 'description': 'md5:2e5b58ba7a2d3692b35c792be081a03d',
  99. },
  100. 'params': {
  101. # m3u8 download
  102. 'skip_download': True,
  103. },
  104. },
  105. # france3
  106. {
  107. 'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575',
  108. 'info_dict': {
  109. 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au',
  110. 'ext': 'flv',
  111. 'title': 'Le scandale du prix des médicaments',
  112. 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce',
  113. },
  114. 'params': {
  115. # rtmp download
  116. 'skip_download': True,
  117. },
  118. },
  119. # france4
  120. {
  121. 'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  122. 'info_dict': {
  123. 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  124. 'ext': 'flv',
  125. 'title': 'Hero Corp Making of - Extrait 1',
  126. 'description': 'md5:c87d54871b1790679aec1197e73d650a',
  127. },
  128. 'params': {
  129. # rtmp download
  130. 'skip_download': True,
  131. },
  132. },
  133. # france5
  134. {
  135. 'url': 'http://www.france5.fr/emissions/c-a-dire/videos/92837968',
  136. 'info_dict': {
  137. 'id': '92837968',
  138. 'ext': 'mp4',
  139. 'title': 'C à dire ?!',
  140. 'description': 'md5:fb1db1cbad784dcce7c7a7bd177c8e2f',
  141. },
  142. 'params': {
  143. # m3u8 download
  144. 'skip_download': True,
  145. },
  146. },
  147. # franceo
  148. {
  149. 'url': 'http://www.franceo.fr/jt/info-afrique/04-12-2013',
  150. 'info_dict': {
  151. 'id': '92327925',
  152. 'ext': 'mp4',
  153. 'title': 'Infô-Afrique',
  154. 'description': 'md5:ebf346da789428841bee0fd2a935ea55',
  155. },
  156. 'params': {
  157. # m3u8 download
  158. 'skip_download': True,
  159. },
  160. 'skip': 'The id changes frequently',
  161. },
  162. ]
  163. def _real_extract(self, url):
  164. mobj = re.match(self._VALID_URL, url)
  165. if mobj.group('key'):
  166. webpage = self._download_webpage(url, mobj.group('key'))
  167. id_res = [
  168. (r'''(?x)<div\s+class="video-player">\s*
  169. <a\s+href="http://videos.francetv.fr/video/([0-9]+)"\s+
  170. class="francetv-video-player">'''),
  171. (r'<a id="player_direct" href="http://info\.francetelevisions'
  172. '\.fr/\?id-video=([^"/&]+)'),
  173. (r'<a class="video" id="ftv_player_(.+?)"'),
  174. ]
  175. video_id = self._html_search_regex(id_res, webpage, 'video ID')
  176. else:
  177. video_id = mobj.group('id')
  178. return self._extract_video(video_id)
  179. class GenerationQuoiIE(InfoExtractor):
  180. IE_NAME = 'france2.fr:generation-quoi'
  181. _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<name>.*)(\?|$)'
  182. _TEST = {
  183. 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
  184. 'file': 'k7FJX8VBcvvLmX4wA5Q.mp4',
  185. 'info_dict': {
  186. 'title': 'Génération Quoi - Garde à Vous',
  187. 'uploader': 'Génération Quoi',
  188. },
  189. 'params': {
  190. # It uses Dailymotion
  191. 'skip_download': True,
  192. },
  193. 'skip': 'Only available from France',
  194. }
  195. def _real_extract(self, url):
  196. mobj = re.match(self._VALID_URL, url)
  197. name = mobj.group('name')
  198. info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % name)
  199. info_json = self._download_webpage(info_url, name)
  200. info = json.loads(info_json)
  201. return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
  202. ie='Dailymotion')
  203. class CultureboxIE(FranceTVBaseInfoExtractor):
  204. IE_NAME = 'culturebox.francetvinfo.fr'
  205. _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
  206. _TEST = {
  207. 'url': 'http://culturebox.francetvinfo.fr/einstein-on-the-beach-au-theatre-du-chatelet-146813',
  208. 'info_dict': {
  209. 'id': 'EV_6785',
  210. 'ext': 'mp4',
  211. 'title': 'Einstein on the beach au Théâtre du Châtelet',
  212. 'description': 'md5:9ce2888b1efefc617b5e58b3f6200eeb',
  213. },
  214. 'params': {
  215. # m3u8 download
  216. 'skip_download': True,
  217. },
  218. }
  219. def _real_extract(self, url):
  220. mobj = re.match(self._VALID_URL, url)
  221. name = mobj.group('name')
  222. webpage = self._download_webpage(url, name)
  223. video_id = self._search_regex(r'"http://videos\.francetv\.fr/video/(.*?)"', webpage, 'video id')
  224. return self._extract_video(video_id)