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.

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