turbo.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import re
  2. from .common import InfoExtractor
  3. from ..compat import compat_str
  4. from ..utils import (
  5. ExtractorError,
  6. int_or_none,
  7. qualities,
  8. xpath_text,
  9. )
  10. class TurboIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?turbo\.fr/videos-voiture/(?P<id>[0-9]+)-'
  12. _API_URL = 'http://www.turbo.fr/api/tv/xml.php?player_generique=player_generique&id={0:}'
  13. _TEST = {
  14. 'url': 'http://www.turbo.fr/videos-voiture/454443-turbo-du-07-09-2014-renault-twingo-3-bentley-continental-gt-speed-ces-guide-achat-dacia.html',
  15. 'md5': '33f4b91099b36b5d5a91f84b5bcba600',
  16. 'info_dict': {
  17. 'id': '454443',
  18. 'ext': 'mp4',
  19. 'duration': 3715,
  20. 'title': 'Turbo du 07/09/2014 : Renault Twingo 3, Bentley Continental GT Speed, CES, Guide Achat Dacia... ',
  21. 'description': 'Turbo du 07/09/2014 : Renault Twingo 3, Bentley Continental GT Speed, CES, Guide Achat Dacia...',
  22. 'thumbnail': r're:^https?://.*\.jpg$',
  23. }
  24. }
  25. def _real_extract(self, url):
  26. mobj = self._match_valid_url(url)
  27. video_id = mobj.group('id')
  28. webpage = self._download_webpage(url, video_id)
  29. playlist = self._download_xml(self._API_URL.format(video_id), video_id)
  30. item = playlist.find('./channel/item')
  31. if item is None:
  32. raise ExtractorError('Playlist item was not found', expected=True)
  33. title = xpath_text(item, './title', 'title')
  34. duration = int_or_none(xpath_text(item, './durate', 'duration'))
  35. thumbnail = xpath_text(item, './visuel_clip', 'thumbnail')
  36. description = self._html_search_meta('description', webpage)
  37. formats = []
  38. get_quality = qualities(['3g', 'sd', 'hq'])
  39. for child in item:
  40. m = re.search(r'url_video_(?P<quality>.+)', child.tag)
  41. if m:
  42. quality = compat_str(m.group('quality'))
  43. formats.append({
  44. 'format_id': quality,
  45. 'url': child.text,
  46. 'quality': get_quality(quality),
  47. })
  48. return {
  49. 'id': video_id,
  50. 'title': title,
  51. 'duration': duration,
  52. 'thumbnail': thumbnail,
  53. 'description': description,
  54. 'formats': formats,
  55. }