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.

90 lines
2.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import base64
  4. from .common import InfoExtractor
  5. from ..utils import parse_duration
  6. class ChirbitIE(InfoExtractor):
  7. IE_NAME = 'chirbit'
  8. _VALID_URL = r'https?://(?:www\.)?chirb\.it/(?:(?:wp|pl)/|fb_chirbit_player\.swf\?key=)?(?P<id>[\da-zA-Z]+)'
  9. _TESTS = [{
  10. 'url': 'http://chirb.it/be2abG',
  11. 'info_dict': {
  12. 'id': 'be2abG',
  13. 'ext': 'mp3',
  14. 'title': 'md5:f542ea253f5255240be4da375c6a5d7e',
  15. 'description': 'md5:f24a4e22a71763e32da5fed59e47c770',
  16. 'duration': 306,
  17. },
  18. 'params': {
  19. 'skip_download': True,
  20. }
  21. }, {
  22. 'url': 'https://chirb.it/fb_chirbit_player.swf?key=PrIPv5',
  23. 'only_matching': True,
  24. }, {
  25. 'url': 'https://chirb.it/wp/MN58c2',
  26. 'only_matching': True,
  27. }]
  28. def _real_extract(self, url):
  29. audio_id = self._match_id(url)
  30. webpage = self._download_webpage(
  31. 'http://chirb.it/%s' % audio_id, audio_id)
  32. data_fd = self._search_regex(
  33. r'data-fd=(["\'])(?P<url>(?:(?!\1).)+)\1',
  34. webpage, 'data fd', group='url')
  35. # Reverse engineered from https://chirb.it/js/chirbit.player.js (look
  36. # for soundURL)
  37. audio_url = base64.b64decode(
  38. data_fd[::-1].encode('ascii')).decode('utf-8')
  39. title = self._search_regex(
  40. r'class=["\']chirbit-title["\'][^>]*>([^<]+)', webpage, 'title')
  41. description = self._search_regex(
  42. r'<h3>Description</h3>\s*<pre[^>]*>([^<]+)</pre>',
  43. webpage, 'description', default=None)
  44. duration = parse_duration(self._search_regex(
  45. r'class=["\']c-length["\'][^>]*>([^<]+)',
  46. webpage, 'duration', fatal=False))
  47. return {
  48. 'id': audio_id,
  49. 'url': audio_url,
  50. 'title': title,
  51. 'description': description,
  52. 'duration': duration,
  53. }
  54. class ChirbitProfileIE(InfoExtractor):
  55. IE_NAME = 'chirbit:profile'
  56. _VALID_URL = r'https?://(?:www\.)?chirbit\.com/(?:rss/)?(?P<id>[^/]+)'
  57. _TEST = {
  58. 'url': 'http://chirbit.com/ScarletBeauty',
  59. 'info_dict': {
  60. 'id': 'ScarletBeauty',
  61. 'title': 'Chirbits by ScarletBeauty',
  62. },
  63. 'playlist_mincount': 3,
  64. }
  65. def _real_extract(self, url):
  66. profile_id = self._match_id(url)
  67. rss = self._download_xml(
  68. 'http://chirbit.com/rss/%s' % profile_id, profile_id)
  69. entries = [
  70. self.url_result(audio_url.text, 'Chirbit')
  71. for audio_url in rss.findall('./channel/item/link')]
  72. title = rss.find('./channel/title').text
  73. return self.playlist_result(entries, profile_id, title)