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.

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