streamango.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/foqebrpftarclpob/asdf_asd_2_mp4',
  22. 'info_dict': {
  23. 'id': 'foqebrpftarclpob',
  24. 'ext': 'mp4',
  25. 'title': 'foqebrpftarclpob',
  26. }
  27. }, {
  28. 'url': 'https://streamango.com/embed/clapasobsptpkdfe/20170315_150006_mp4',
  29. 'only_matching': True,
  30. }]
  31. def _real_extract(self, url):
  32. video_id = self._match_id(url)
  33. webpage = self._download_webpage(url, video_id)
  34. title = self._og_search_title(webpage, default=video_id)
  35. formats = []
  36. for format_ in re.findall(r'({[^}]*\bsrc\s*:\s*[^}]*})', webpage):
  37. video = self._parse_json(
  38. format_, video_id, transform_source=js_to_json, fatal=False)
  39. if not video:
  40. continue
  41. src = video.get('src')
  42. if not src:
  43. continue
  44. ext = determine_ext(src, default_ext=None)
  45. if video.get('type') == 'application/dash+xml' or ext == 'mpd':
  46. formats.extend(self._extract_mpd_formats(
  47. src, video_id, mpd_id='dash', fatal=False))
  48. else:
  49. formats.append({
  50. 'url': src,
  51. 'ext': ext or 'mp4',
  52. 'width': int_or_none(video.get('width')),
  53. 'height': int_or_none(video.get('height')),
  54. 'tbr': int_or_none(video.get('bitrate')),
  55. })
  56. self._sort_formats(formats)
  57. return {
  58. 'id': video_id,
  59. 'url': url,
  60. 'title': title,
  61. 'formats': formats,
  62. }