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.

264 lines
9.8 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. ExtractorError,
  9. clean_html,
  10. parse_duration,
  11. compat_urllib_parse_urlparse,
  12. int_or_none,
  13. )
  14. class FranceTVBaseInfoExtractor(InfoExtractor):
  15. def _extract_video(self, video_id, catalogue):
  16. info = self._download_json(
  17. 'http://webservices.francetelevisions.fr/tools/getInfosOeuvre/v2/?idDiffusion=%s&catalogue=%s'
  18. % (video_id, catalogue),
  19. video_id, 'Downloading video JSON')
  20. if info.get('status') == 'NOK':
  21. raise ExtractorError(
  22. '%s returned error: %s' % (self.IE_NAME, info['message']), expected=True)
  23. formats = []
  24. for video in info['videos']:
  25. if video['statut'] != 'ONLINE':
  26. continue
  27. video_url = video['url']
  28. if not video_url:
  29. continue
  30. format_id = video['format']
  31. if video_url.endswith('.f4m'):
  32. video_url_parsed = compat_urllib_parse_urlparse(video_url)
  33. f4m_url = self._download_webpage(
  34. 'http://hdfauth.francetv.fr/esi/urltokengen2.html?url=%s' % video_url_parsed.path,
  35. video_id, 'Downloading f4m manifest token', fatal=False)
  36. if f4m_url:
  37. f4m_formats = self._extract_f4m_formats(f4m_url, video_id)
  38. for f4m_format in f4m_formats:
  39. f4m_format['preference'] = 1
  40. formats.extend(f4m_formats)
  41. elif video_url.endswith('.m3u8'):
  42. formats.extend(self._extract_m3u8_formats(video_url, video_id, 'mp4'))
  43. elif video_url.startswith('rtmp'):
  44. formats.append({
  45. 'url': video_url,
  46. 'format_id': 'rtmp-%s' % format_id,
  47. 'ext': 'flv',
  48. 'preference': 1,
  49. })
  50. else:
  51. formats.append({
  52. 'url': video_url,
  53. 'format_id': format_id,
  54. 'preference': -1,
  55. })
  56. self._sort_formats(formats)
  57. return {
  58. 'id': video_id,
  59. 'title': info['titre'],
  60. 'description': clean_html(info['synopsis']),
  61. 'thumbnail': compat_urlparse.urljoin('http://pluzz.francetv.fr', info['image']),
  62. 'duration': parse_duration(info['duree']),
  63. 'timestamp': int_or_none(info['diffusion']['timestamp']),
  64. 'formats': formats,
  65. }
  66. class PluzzIE(FranceTVBaseInfoExtractor):
  67. IE_NAME = 'pluzz.francetv.fr'
  68. _VALID_URL = r'https?://pluzz\.francetv\.fr/videos/(.*?)\.html'
  69. # Can't use tests, videos expire in 7 days
  70. def _real_extract(self, url):
  71. title = re.match(self._VALID_URL, url).group(1)
  72. webpage = self._download_webpage(url, title)
  73. video_id = self._search_regex(
  74. r'data-diffusion="(\d+)"', webpage, 'ID')
  75. return self._extract_video(video_id, 'Pluzz')
  76. class FranceTvInfoIE(FranceTVBaseInfoExtractor):
  77. IE_NAME = 'francetvinfo.fr'
  78. _VALID_URL = r'https?://(?:www|mobile)\.francetvinfo\.fr/.*/(?P<title>.+)\.html'
  79. _TESTS = [{
  80. 'url': 'http://www.francetvinfo.fr/replay-jt/france-3/soir-3/jt-grand-soir-3-lundi-26-aout-2013_393427.html',
  81. 'info_dict': {
  82. 'id': '84981923',
  83. 'ext': 'flv',
  84. 'title': 'Soir 3',
  85. 'upload_date': '20130826',
  86. 'timestamp': 1377548400,
  87. },
  88. }, {
  89. 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
  90. 'info_dict': {
  91. 'id': 'EV_20019',
  92. 'ext': 'mp4',
  93. 'title': 'Débat des candidats à la Commission européenne',
  94. 'description': 'Débat des candidats à la Commission européenne',
  95. },
  96. 'params': {
  97. 'skip_download': 'HLS (reqires ffmpeg)'
  98. },
  99. 'skip': 'Ce direct est terminé et sera disponible en rattrapage dans quelques minutes.',
  100. }]
  101. def _real_extract(self, url):
  102. mobj = re.match(self._VALID_URL, url)
  103. page_title = mobj.group('title')
  104. webpage = self._download_webpage(url, page_title)
  105. video_id, catalogue = self._search_regex(
  106. r'id-video=([^@]+@[^"]+)', webpage, 'video id').split('@')
  107. return self._extract_video(video_id, catalogue)
  108. class FranceTVIE(FranceTVBaseInfoExtractor):
  109. IE_NAME = 'francetv'
  110. IE_DESC = 'France 2, 3, 4, 5 and Ô'
  111. _VALID_URL = r'''(?x)https?://www\.france[2345o]\.fr/
  112. (?:
  113. emissions/.*?/(videos|emissions)/(?P<id>[^/?]+)
  114. | (emissions?|jt)/(?P<key>[^/?]+)
  115. )'''
  116. _TESTS = [
  117. # france2
  118. {
  119. 'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
  120. 'md5': 'c03fc87cb85429ffd55df32b9fc05523',
  121. 'info_dict': {
  122. 'id': '109169362',
  123. 'ext': 'flv',
  124. 'title': '13h15, le dimanche...',
  125. 'description': 'md5:9a0932bb465f22d377a449be9d1a0ff7',
  126. 'upload_date': '20140914',
  127. 'timestamp': 1410693600,
  128. },
  129. },
  130. # france3
  131. {
  132. 'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575',
  133. 'md5': '679bb8f8921f8623bd658fa2f8364da0',
  134. 'info_dict': {
  135. 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au',
  136. 'ext': 'mp4',
  137. 'title': 'Le scandale du prix des médicaments',
  138. 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce',
  139. 'upload_date': '20131113',
  140. 'timestamp': 1384380000,
  141. },
  142. },
  143. # france4
  144. {
  145. 'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  146. 'md5': 'a182bf8d2c43d88d46ec48fbdd260c1c',
  147. 'info_dict': {
  148. 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  149. 'ext': 'mp4',
  150. 'title': 'Hero Corp Making of - Extrait 1',
  151. 'description': 'md5:c87d54871b1790679aec1197e73d650a',
  152. 'upload_date': '20131106',
  153. 'timestamp': 1383766500,
  154. },
  155. },
  156. # france5
  157. {
  158. 'url': 'http://www.france5.fr/emissions/c-a-dire/videos/92837968',
  159. 'md5': '78f0f4064f9074438e660785bbf2c5d9',
  160. 'info_dict': {
  161. 'id': '108961659',
  162. 'ext': 'flv',
  163. 'title': 'C à dire ?!',
  164. 'description': 'md5:1a4aeab476eb657bf57c4ff122129f81',
  165. 'upload_date': '20140915',
  166. 'timestamp': 1410795000,
  167. },
  168. },
  169. # franceo
  170. {
  171. 'url': 'http://www.franceo.fr/jt/info-afrique/04-12-2013',
  172. 'md5': '52f0bfe202848b15915a2f39aaa8981b',
  173. 'info_dict': {
  174. 'id': '108634970',
  175. 'ext': 'flv',
  176. 'title': 'Infô Afrique',
  177. 'description': 'md5:ebf346da789428841bee0fd2a935ea55',
  178. 'upload_date': '20140915',
  179. 'timestamp': 1410822000,
  180. },
  181. },
  182. ]
  183. def _real_extract(self, url):
  184. mobj = re.match(self._VALID_URL, url)
  185. webpage = self._download_webpage(url, mobj.group('key') or mobj.group('id'))
  186. video_id, catalogue = self._html_search_regex(
  187. r'href="http://videos\.francetv\.fr/video/([^@]+@[^"]+)"',
  188. webpage, 'video ID').split('@')
  189. return self._extract_video(video_id, catalogue)
  190. class GenerationQuoiIE(InfoExtractor):
  191. IE_NAME = 'france2.fr:generation-quoi'
  192. _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<name>.*)(\?|$)'
  193. _TEST = {
  194. 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
  195. 'file': 'k7FJX8VBcvvLmX4wA5Q.mp4',
  196. 'info_dict': {
  197. 'title': 'Génération Quoi - Garde à Vous',
  198. 'uploader': 'Génération Quoi',
  199. },
  200. 'params': {
  201. # It uses Dailymotion
  202. 'skip_download': True,
  203. },
  204. 'skip': 'Only available from France',
  205. }
  206. def _real_extract(self, url):
  207. mobj = re.match(self._VALID_URL, url)
  208. name = mobj.group('name')
  209. info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % name)
  210. info_json = self._download_webpage(info_url, name)
  211. info = json.loads(info_json)
  212. return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
  213. ie='Dailymotion')
  214. class CultureboxIE(FranceTVBaseInfoExtractor):
  215. IE_NAME = 'culturebox.francetvinfo.fr'
  216. _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
  217. _TEST = {
  218. 'url': 'http://culturebox.francetvinfo.fr/festivals/dans-les-jardins-de-william-christie/dans-les-jardins-de-william-christie-le-camus-162553',
  219. 'md5': '5ad6dec1ffb2a3fbcb20cc4b744be8d6',
  220. 'info_dict': {
  221. 'id': 'EV_22853',
  222. 'ext': 'flv',
  223. 'title': 'Dans les jardins de William Christie - Le Camus',
  224. 'description': 'md5:4710c82315c40f0c865ca8b9a68b5299',
  225. 'upload_date': '20140829',
  226. 'timestamp': 1409317200,
  227. },
  228. }
  229. def _real_extract(self, url):
  230. mobj = re.match(self._VALID_URL, url)
  231. name = mobj.group('name')
  232. webpage = self._download_webpage(url, name)
  233. video_id, catalogue = self._search_regex(
  234. r'"http://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@')
  235. return self._extract_video(video_id, catalogue)