la7.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_duration,
  6. )
  7. class LA7IE(InfoExtractor):
  8. IE_NAME = 'la7.tv'
  9. _VALID_URL = r'''(?x)
  10. https?://(?:www\.)?la7\.tv/
  11. (?:
  12. richplayer/\?assetid=|
  13. \?contentId=
  14. )
  15. (?P<id>[0-9]+)'''
  16. _TEST = {
  17. 'url': 'http://www.la7.tv/richplayer/?assetid=50355319',
  18. 'md5': 'ec7d1f0224d20ba293ab56cf2259651f',
  19. 'info_dict': {
  20. 'id': '50355319',
  21. 'ext': 'mp4',
  22. 'title': 'IL DIVO',
  23. 'description': 'Un film di Paolo Sorrentino con Toni Servillo, Anna Bonaiuto, Giulio Bosetti e Flavio Bucci',
  24. 'duration': 6254,
  25. },
  26. 'skip': 'Blocked in the US',
  27. }
  28. def _real_extract(self, url):
  29. video_id = self._match_id(url)
  30. xml_url = 'http://www.la7.tv/repliche/content/index.php?contentId=%s' % video_id
  31. doc = self._download_xml(xml_url, video_id)
  32. video_title = doc.find('title').text
  33. description = doc.find('description').text
  34. duration = parse_duration(doc.find('duration').text)
  35. thumbnail = doc.find('img').text
  36. view_count = int(doc.find('views').text)
  37. prefix = doc.find('.//fqdn').text.strip().replace('auto:', 'http:')
  38. formats = [{
  39. 'format': vnode.find('quality').text,
  40. 'tbr': int(vnode.find('quality').text),
  41. 'url': vnode.find('fms').text.strip().replace('mp4:', prefix),
  42. } for vnode in doc.findall('.//videos/video')]
  43. self._sort_formats(formats)
  44. return {
  45. 'id': video_id,
  46. 'title': video_title,
  47. 'description': description,
  48. 'thumbnail': thumbnail,
  49. 'duration': duration,
  50. 'formats': formats,
  51. 'view_count': view_count,
  52. }