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.

92 lines
2.9 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. 'uploader': 'Gerryaudio',
  19. },
  20. 'params': {
  21. 'skip_download': True,
  22. }
  23. }, {
  24. 'url': 'https://chirb.it/fb_chirbit_player.swf?key=PrIPv5',
  25. 'only_matching': True,
  26. }, {
  27. 'url': 'https://chirb.it/wp/MN58c2',
  28. 'only_matching': True,
  29. }]
  30. def _real_extract(self, url):
  31. audio_id = self._match_id(url)
  32. webpage = self._download_webpage(
  33. 'http://chirb.it/%s' % audio_id, audio_id)
  34. data_fd = self._search_regex(
  35. r'data-fd=(["\'])(?P<url>(?:(?!\1).)+)\1',
  36. webpage, 'data fd', group='url')
  37. # Reverse engineered from https://chirb.it/js/chirbit.player.js (look
  38. # for soundURL)
  39. audio_url = base64.b64decode(
  40. data_fd[::-1].encode('ascii')).decode('utf-8')
  41. title = self._search_regex(
  42. r'class=["\']chirbit-title["\'][^>]*>([^<]+)', webpage, 'title')
  43. description = self._search_regex(
  44. r'<h3>Description</h3>\s*<pre[^>]*>([^<]+)</pre>',
  45. webpage, 'description', default=None)
  46. duration = parse_duration(self._search_regex(
  47. r'class=["\']c-length["\'][^>]*>([^<]+)',
  48. webpage, 'duration', fatal=False))
  49. uploader = self._search_regex(
  50. r'id=["\']chirbit-username["\'][^>]*>([^<]+)',
  51. webpage, 'uploader', fatal=False)
  52. return {
  53. 'id': audio_id,
  54. 'url': audio_url,
  55. 'title': title,
  56. 'description': description,
  57. 'duration': duration,
  58. 'uploader': uploader,
  59. }
  60. class ChirbitProfileIE(InfoExtractor):
  61. IE_NAME = 'chirbit:profile'
  62. _VALID_URL = r'https?://(?:www\.)?chirbit\.com/(?:rss/)?(?P<id>[^/]+)'
  63. _TEST = {
  64. 'url': 'http://chirbit.com/ScarletBeauty',
  65. 'info_dict': {
  66. 'id': 'ScarletBeauty',
  67. },
  68. 'playlist_mincount': 3,
  69. }
  70. def _real_extract(self, url):
  71. profile_id = self._match_id(url)
  72. webpage = self._download_webpage(url, profile_id)
  73. entries = [
  74. self.url_result(self._proto_relative_url('//chirb.it/' + video_id))
  75. for _, video_id in re.findall(r'<input[^>]+id=([\'"])copy-btn-(?P<id>[0-9a-zA-Z]+)\1', webpage)]
  76. return self.playlist_result(entries, profile_id)