unistra.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import qualities
  4. class UnistraIE(InfoExtractor):
  5. _VALID_URL = r'https?://utv\.unistra\.fr/(?:index|video)\.php\?id_video\=(?P<id>\d+)'
  6. _TESTS = [
  7. {
  8. 'url': 'http://utv.unistra.fr/video.php?id_video=154',
  9. 'md5': '736f605cfdc96724d55bb543ab3ced24',
  10. 'info_dict': {
  11. 'id': '154',
  12. 'ext': 'mp4',
  13. 'title': 'M!ss Yella',
  14. 'description': 'md5:104892c71bd48e55d70b902736b81bbf',
  15. },
  16. },
  17. {
  18. 'url': 'http://utv.unistra.fr/index.php?id_video=437',
  19. 'md5': '1ddddd6cccaae76f622ce29b8779636d',
  20. 'info_dict': {
  21. 'id': '437',
  22. 'ext': 'mp4',
  23. 'title': 'Prix Louise Weiss 2014',
  24. 'description': 'md5:cc3a8735f079f4fb6b0b570fc10c135a',
  25. },
  26. },
  27. ]
  28. def _real_extract(self, url):
  29. mobj = self._match_valid_url(url)
  30. video_id = mobj.group('id')
  31. webpage = self._download_webpage(url, video_id)
  32. files = set(re.findall(r'file\s*:\s*"(/[^"]+)"', webpage))
  33. quality = qualities(['SD', 'HD'])
  34. formats = []
  35. for file_path in files:
  36. format_id = 'HD' if file_path.endswith('-HD.mp4') else 'SD'
  37. formats.append({
  38. 'url': f'http://vod-flash.u-strasbg.fr:8080{file_path}',
  39. 'format_id': format_id,
  40. 'quality': quality(format_id),
  41. })
  42. title = self._html_search_regex(
  43. r'<title>UTV - (.*?)</', webpage, 'title')
  44. description = self._html_search_regex(
  45. r'<meta name="Description" content="(.*?)"', webpage, 'description', flags=re.DOTALL)
  46. thumbnail = self._search_regex(
  47. r'image: "(.*?)"', webpage, 'thumbnail')
  48. return {
  49. 'id': video_id,
  50. 'title': title,
  51. 'description': description,
  52. 'thumbnail': thumbnail,
  53. 'formats': formats,
  54. }