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.

73 lines
2.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. clean_html,
  6. float_or_none,
  7. )
  8. class AudioBoomIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?audioboom\.com/(?:boos|posts)/(?P<id>[0-9]+)'
  10. _TESTS = [{
  11. 'url': 'https://audioboom.com/posts/7398103-asim-chaudhry',
  12. 'md5': '7b00192e593ff227e6a315486979a42d',
  13. 'info_dict': {
  14. 'id': '7398103',
  15. 'ext': 'mp3',
  16. 'title': 'Asim Chaudhry',
  17. 'description': 'md5:2f3fef17dacc2595b5362e1d7d3602fc',
  18. 'duration': 4000.99,
  19. 'uploader': 'Sue Perkins: An hour or so with...',
  20. 'uploader_url': r're:https?://(?:www\.)?audioboom\.com/channel/perkins',
  21. }
  22. }, {
  23. 'url': 'https://audioboom.com/posts/4279833-3-09-2016-czaban-hour-3?t=0',
  24. 'only_matching': True,
  25. }]
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(url, video_id)
  29. clip = None
  30. clip_store = self._parse_json(
  31. self._html_search_regex(
  32. r'data-new-clip-store=(["\'])(?P<json>{.+?})\1',
  33. webpage, 'clip store', default='{}', group='json'),
  34. video_id, fatal=False)
  35. if clip_store:
  36. clips = clip_store.get('clips')
  37. if clips and isinstance(clips, list) and isinstance(clips[0], dict):
  38. clip = clips[0]
  39. def from_clip(field):
  40. if clip:
  41. return clip.get(field)
  42. audio_url = from_clip('clipURLPriorToLoading') or self._og_search_property(
  43. 'audio', webpage, 'audio url')
  44. title = from_clip('title') or self._html_search_meta(
  45. ['og:title', 'og:audio:title', 'audio_title'], webpage)
  46. description = from_clip('description') or clean_html(from_clip('formattedDescription')) or self._og_search_description(webpage)
  47. duration = float_or_none(from_clip('duration') or self._html_search_meta(
  48. 'weibo:audio:duration', webpage))
  49. uploader = from_clip('author') or self._html_search_meta(
  50. ['og:audio:artist', 'twitter:audio:artist_name', 'audio_artist'], webpage, 'uploader')
  51. uploader_url = from_clip('author_url') or self._html_search_meta(
  52. 'audioboo:channel', webpage, 'uploader url')
  53. return {
  54. 'id': video_id,
  55. 'url': audio_url,
  56. 'title': title,
  57. 'description': description,
  58. 'duration': duration,
  59. 'uploader': uploader,
  60. 'uploader_url': uploader_url,
  61. }