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.

265 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))
  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': 2,
  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. 'md5': '9cecf35f99c4079c199e9817882a9a1c',
  82. 'info_dict': {
  83. 'id': '84981923',
  84. 'ext': 'flv',
  85. 'title': 'Soir 3',
  86. 'upload_date': '20130826',
  87. 'timestamp': 1377548400,
  88. },
  89. }, {
  90. 'url': 'http://www.francetvinfo.fr/elections/europeennes/direct-europeennes-regardez-le-debat-entre-les-candidats-a-la-presidence-de-la-commission_600639.html',
  91. 'info_dict': {
  92. 'id': 'EV_20019',
  93. 'ext': 'mp4',
  94. 'title': 'Débat des candidats à la Commission européenne',
  95. 'description': 'Débat des candidats à la Commission européenne',
  96. },
  97. 'params': {
  98. 'skip_download': 'HLS (reqires ffmpeg)'
  99. },
  100. 'skip': 'Ce direct est terminé et sera disponible en rattrapage dans quelques minutes.',
  101. }]
  102. def _real_extract(self, url):
  103. mobj = re.match(self._VALID_URL, url)
  104. page_title = mobj.group('title')
  105. webpage = self._download_webpage(url, page_title)
  106. video_id, catalogue = self._search_regex(
  107. r'id-video=([^@]+@[^"]+)', webpage, 'video id').split('@')
  108. return self._extract_video(video_id, catalogue)
  109. class FranceTVIE(FranceTVBaseInfoExtractor):
  110. IE_NAME = 'francetv'
  111. IE_DESC = 'France 2, 3, 4, 5 and Ô'
  112. _VALID_URL = r'''(?x)https?://www\.france[2345o]\.fr/
  113. (?:
  114. emissions/.*?/(videos|emissions)/(?P<id>[^/?]+)
  115. | (emissions?|jt)/(?P<key>[^/?]+)
  116. )'''
  117. _TESTS = [
  118. # france2
  119. {
  120. 'url': 'http://www.france2.fr/emissions/13h15-le-samedi-le-dimanche/videos/75540104',
  121. 'md5': 'c03fc87cb85429ffd55df32b9fc05523',
  122. 'info_dict': {
  123. 'id': '109169362',
  124. 'ext': 'flv',
  125. 'title': '13h15, le dimanche...',
  126. 'description': 'md5:9a0932bb465f22d377a449be9d1a0ff7',
  127. 'upload_date': '20140914',
  128. 'timestamp': 1410693600,
  129. },
  130. },
  131. # france3
  132. {
  133. 'url': 'http://www.france3.fr/emissions/pieces-a-conviction/diffusions/13-11-2013_145575',
  134. 'md5': '679bb8f8921f8623bd658fa2f8364da0',
  135. 'info_dict': {
  136. 'id': '000702326_CAPP_PicesconvictionExtrait313022013_120220131722_Au',
  137. 'ext': 'mp4',
  138. 'title': 'Le scandale du prix des médicaments',
  139. 'description': 'md5:1384089fbee2f04fc6c9de025ee2e9ce',
  140. 'upload_date': '20131113',
  141. 'timestamp': 1384380000,
  142. },
  143. },
  144. # france4
  145. {
  146. 'url': 'http://www.france4.fr/emissions/hero-corp/videos/rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  147. 'md5': 'a182bf8d2c43d88d46ec48fbdd260c1c',
  148. 'info_dict': {
  149. 'id': 'rhozet_herocorp_bonus_1_20131106_1923_06112013172108_F4',
  150. 'ext': 'mp4',
  151. 'title': 'Hero Corp Making of - Extrait 1',
  152. 'description': 'md5:c87d54871b1790679aec1197e73d650a',
  153. 'upload_date': '20131106',
  154. 'timestamp': 1383766500,
  155. },
  156. },
  157. # france5
  158. {
  159. 'url': 'http://www.france5.fr/emissions/c-a-dire/videos/92837968',
  160. 'md5': '78f0f4064f9074438e660785bbf2c5d9',
  161. 'info_dict': {
  162. 'id': '108961659',
  163. 'ext': 'flv',
  164. 'title': 'C à dire ?!',
  165. 'description': 'md5:1a4aeab476eb657bf57c4ff122129f81',
  166. 'upload_date': '20140915',
  167. 'timestamp': 1410795000,
  168. },
  169. },
  170. # franceo
  171. {
  172. 'url': 'http://www.franceo.fr/jt/info-afrique/04-12-2013',
  173. 'md5': '52f0bfe202848b15915a2f39aaa8981b',
  174. 'info_dict': {
  175. 'id': '108634970',
  176. 'ext': 'flv',
  177. 'title': 'Infô Afrique',
  178. 'description': 'md5:ebf346da789428841bee0fd2a935ea55',
  179. 'upload_date': '20140915',
  180. 'timestamp': 1410822000,
  181. },
  182. },
  183. ]
  184. def _real_extract(self, url):
  185. mobj = re.match(self._VALID_URL, url)
  186. webpage = self._download_webpage(url, mobj.group('key') or mobj.group('id'))
  187. video_id, catalogue = self._html_search_regex(
  188. r'href="http://videos\.francetv\.fr/video/([^@]+@[^"]+)"',
  189. webpage, 'video ID').split('@')
  190. return self._extract_video(video_id, catalogue)
  191. class GenerationQuoiIE(InfoExtractor):
  192. IE_NAME = 'france2.fr:generation-quoi'
  193. _VALID_URL = r'https?://generation-quoi\.france2\.fr/portrait/(?P<name>.*)(\?|$)'
  194. _TEST = {
  195. 'url': 'http://generation-quoi.france2.fr/portrait/garde-a-vous',
  196. 'file': 'k7FJX8VBcvvLmX4wA5Q.mp4',
  197. 'info_dict': {
  198. 'title': 'Génération Quoi - Garde à Vous',
  199. 'uploader': 'Génération Quoi',
  200. },
  201. 'params': {
  202. # It uses Dailymotion
  203. 'skip_download': True,
  204. },
  205. 'skip': 'Only available from France',
  206. }
  207. def _real_extract(self, url):
  208. mobj = re.match(self._VALID_URL, url)
  209. name = mobj.group('name')
  210. info_url = compat_urlparse.urljoin(url, '/medias/video/%s.json' % name)
  211. info_json = self._download_webpage(info_url, name)
  212. info = json.loads(info_json)
  213. return self.url_result('http://www.dailymotion.com/video/%s' % info['id'],
  214. ie='Dailymotion')
  215. class CultureboxIE(FranceTVBaseInfoExtractor):
  216. IE_NAME = 'culturebox.francetvinfo.fr'
  217. _VALID_URL = r'https?://(?:m\.)?culturebox\.francetvinfo\.fr/(?P<name>.*?)(\?|$)'
  218. _TEST = {
  219. 'url': 'http://culturebox.francetvinfo.fr/festivals/dans-les-jardins-de-william-christie/dans-les-jardins-de-william-christie-le-camus-162553',
  220. 'md5': '5ad6dec1ffb2a3fbcb20cc4b744be8d6',
  221. 'info_dict': {
  222. 'id': 'EV_22853',
  223. 'ext': 'flv',
  224. 'title': 'Dans les jardins de William Christie - Le Camus',
  225. 'description': 'md5:4710c82315c40f0c865ca8b9a68b5299',
  226. 'upload_date': '20140829',
  227. 'timestamp': 1409317200,
  228. },
  229. }
  230. def _real_extract(self, url):
  231. mobj = re.match(self._VALID_URL, url)
  232. name = mobj.group('name')
  233. webpage = self._download_webpage(url, name)
  234. video_id, catalogue = self._search_regex(
  235. r'"http://videos\.francetv\.fr/video/([^@]+@[^"]+)"', webpage, 'video id').split('@')
  236. return self._extract_video(video_id, catalogue)