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.

87 lines
2.7 KiB

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