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.

64 lines
2.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. int_or_none,
  8. js_to_json,
  9. )
  10. class StreamangoIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?streamango\.com/(?:f|embed)/(?P<id>[^/?#&]+)'
  12. _TESTS = [{
  13. 'url': 'https://streamango.com/f/clapasobsptpkdfe/20170315_150006_mp4',
  14. 'md5': 'e992787515a182f55e38fc97588d802a',
  15. 'info_dict': {
  16. 'id': 'clapasobsptpkdfe',
  17. 'ext': 'mp4',
  18. 'title': '20170315_150006.mp4',
  19. }
  20. }, {
  21. 'url': 'https://streamango.com/embed/clapasobsptpkdfe/20170315_150006_mp4',
  22. 'only_matching': True,
  23. }]
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(url, video_id)
  27. title = self._og_search_title(webpage)
  28. formats = []
  29. for format_ in re.findall(r'({[^}]*\bsrc\s*:\s*[^}]*})', webpage):
  30. video = self._parse_json(
  31. format_, video_id, transform_source=js_to_json, fatal=False)
  32. if not video:
  33. continue
  34. src = video.get('src')
  35. if not src:
  36. continue
  37. ext = determine_ext(src, default_ext=None)
  38. if video.get('type') == 'application/dash+xml' or ext == 'mpd':
  39. formats.extend(self._extract_mpd_formats(
  40. src, video_id, mpd_id='dash', fatal=False))
  41. else:
  42. formats.append({
  43. 'url': src,
  44. 'ext': ext or 'mp4',
  45. 'width': int_or_none(video.get('width')),
  46. 'height': int_or_none(video.get('height')),
  47. 'tbr': int_or_none(video.get('bitrate')),
  48. })
  49. self._sort_formats(formats)
  50. return {
  51. 'id': video_id,
  52. 'url': url,
  53. 'title': title,
  54. 'formats': formats,
  55. }