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.

52 lines
2.0 KiB

  1. # coding: utf-8
  2. import json
  3. import re
  4. import xml.etree.ElementTree
  5. from .common import InfoExtractor
  6. class JeuxVideoIE(InfoExtractor):
  7. _VALID_URL = r'http://.*?\.jeuxvideo\.com/.*/(.*?)-\d+\.htm'
  8. _TEST = {
  9. u'url': u'http://www.jeuxvideo.com/reportages-videos-jeux/0004/00046170/tearaway-playstation-vita-gc-2013-tearaway-nous-presente-ses-papiers-d-identite-00115182.htm',
  10. u'file': u'5182.mp4',
  11. u'md5': u'046e491afb32a8aaac1f44dd4ddd54ee',
  12. u'info_dict': {
  13. u'title': u'GC 2013 : Tearaway nous présente ses papiers d\'identité',
  14. u'description': u'Lorsque les développeurs de LittleBigPlanet proposent un nouveau titre, on ne peut que s\'attendre à un résultat original et fort attrayant.\n',
  15. },
  16. }
  17. def _real_extract(self, url):
  18. mobj = re.match(self._VALID_URL, url)
  19. title = re.match(self._VALID_URL, url).group(1)
  20. webpage = self._download_webpage(url, title)
  21. xml_link = self._html_search_regex(
  22. r'<param name="flashvars" value="config=(.*?)" />',
  23. webpage, u'config URL')
  24. video_id = self._search_regex(
  25. r'http://www\.jeuxvideo\.com/config/\w+/\d+/(.*?)/\d+_player\.xml',
  26. xml_link, u'video ID')
  27. xml_config = self._download_webpage(
  28. xml_link, title, u'Downloading XML config')
  29. config = xml.etree.ElementTree.fromstring(xml_config.encode('utf-8'))
  30. info_json = self._search_regex(
  31. r'(?sm)<format\.json>(.*?)</format\.json>',
  32. xml_config, u'JSON information')
  33. info = json.loads(info_json)['versions'][0]
  34. video_url = 'http://video720.jeuxvideo.com/' + info['file']
  35. return {
  36. 'id': video_id,
  37. 'title': config.find('titre_video').text,
  38. 'ext': 'mp4',
  39. 'url': video_url,
  40. 'description': self._og_search_description(webpage),
  41. 'thumbnail': config.find('image').text,
  42. }