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.

67 lines
2.3 KiB

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