chirbit.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import clean_html
  6. class ChirbitIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?chirb\.it/(?P<id>[^/]+)'
  8. _TEST = {
  9. 'url': 'http://chirb.it/PrIPv5',
  10. 'md5': '9847b0dad6ac3e074568bf2cfb197de8',
  11. 'info_dict': {
  12. 'id': 'PrIPv5',
  13. 'display_id': 'kukushtv_1423231243',
  14. 'ext': 'mp3',
  15. 'title': 'Фасадстрой',
  16. 'url': 'http://audio.chirbit.com/kukushtv_1423231243.mp3'
  17. }
  18. }
  19. def _real_extract(self, url):
  20. audio_linkid = self._match_id(url)
  21. webpage = self._download_webpage(url, audio_linkid)
  22. audio_title = self._html_search_regex(r'<h2\s+itemprop="name">(.*?)</h2>', webpage, 'title')
  23. audio_id = self._html_search_regex(r'\("setFile",\s+"http://audio.chirbit.com/(.*?).mp3"\)', webpage, 'audio ID')
  24. audio_url = 'http://audio.chirbit.com/' + audio_id + '.mp3';
  25. return {
  26. 'id': audio_linkid,
  27. 'display_id': audio_id,
  28. 'title': audio_title,
  29. 'url': audio_url
  30. }
  31. class ChirbitProfileIE(InfoExtractor):
  32. _VALID_URL = r'https?://(?:www\.)?chirbit.com/(?P<id>[^/]+)/?$'
  33. _TEST = {
  34. 'url': 'http://chirbit.com/ScarletBeauty',
  35. 'playlist_count': 3,
  36. 'info_dict': {
  37. '_type': 'playlist',
  38. 'title': 'ScarletBeauty',
  39. 'id': 'ScarletBeauty'
  40. }
  41. }
  42. def _real_extract(self, url):
  43. profile_id = self._match_id(url)
  44. # Chirbit has a pretty weird "Last Page" navigation behavior.
  45. # We grab the profile's oldest entry to determine when to
  46. # stop fetching entries.
  47. oldestpage = self._download_webpage(url + '/24599', profile_id)
  48. oldest_page_entries = re.findall(
  49. r'''soundFile:\s*"http://audio.chirbit.com/(.*?).mp3"''',
  50. oldestpage);
  51. oldestentry = clean_html(oldest_page_entries[-1]);
  52. ids = []
  53. titles = []
  54. n = 0
  55. while True:
  56. page = self._download_webpage(url + '/' + str(n), profile_id)
  57. page_ids = re.findall(
  58. r'''soundFile:\s*"http://audio.chirbit.com/(.*?).mp3"''',
  59. page);
  60. page_titles = re.findall(
  61. r'''<div\s+class="chirbit_title"\s*>(.*?)</div>''',
  62. page);
  63. ids += page_ids
  64. titles += page_titles
  65. if oldestentry in page_ids:
  66. break
  67. n += 1
  68. entries = []
  69. i = 0
  70. for id in ids:
  71. entries.append({
  72. 'id': id,
  73. 'title': titles[i],
  74. 'url': 'http://audio.chirbit.com/' + id + '.mp3'
  75. });
  76. i += 1
  77. info_dict = {
  78. '_type': 'playlist',
  79. 'id': profile_id,
  80. 'title': profile_id,
  81. 'entries': entries
  82. }
  83. return info_dict;