chirbit.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_duration,
  6. int_or_none,
  7. )
  8. class ChirbitIE(InfoExtractor):
  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/PrIPv5',
  12. 'md5': '9847b0dad6ac3e074568bf2cfb197de8',
  13. 'info_dict': {
  14. 'id': 'PrIPv5',
  15. 'ext': 'mp3',
  16. 'title': 'Фасадстрой',
  17. 'duration': 52,
  18. 'view_count': int,
  19. 'comment_count': int,
  20. }
  21. }, {
  22. 'url': 'https://chirb.it/fb_chirbit_player.swf?key=PrIPv5',
  23. 'only_matching': True,
  24. }]
  25. def _real_extract(self, url):
  26. audio_id = self._match_id(url)
  27. webpage = self._download_webpage(
  28. 'http://chirb.it/%s' % audio_id, audio_id)
  29. audio_url = self._search_regex(
  30. r'"setFile"\s*,\s*"([^"]+)"', webpage, 'audio url')
  31. title = self._search_regex(
  32. r'itemprop="name">([^<]+)', webpage, 'title')
  33. duration = parse_duration(self._html_search_meta(
  34. 'duration', webpage, 'duration', fatal=False))
  35. view_count = int_or_none(self._search_regex(
  36. r'itemprop="playCount"\s*>(\d+)', webpage,
  37. 'listen count', fatal=False))
  38. comment_count = int_or_none(self._search_regex(
  39. r'>(\d+) Comments?:', webpage,
  40. 'comment count', fatal=False))
  41. return {
  42. 'id': audio_id,
  43. 'url': audio_url,
  44. 'title': title,
  45. 'duration': duration,
  46. 'view_count': view_count,
  47. 'comment_count': comment_count,
  48. }
  49. class ChirbitProfileIE(InfoExtractor):
  50. _VALID_URL = r'https?://(?:www\.)?chirbit.com/(?:rss/)?(?P<id>[^/]+)'
  51. _TEST = {
  52. 'url': 'http://chirbit.com/ScarletBeauty',
  53. 'info_dict': {
  54. 'id': 'ScarletBeauty',
  55. 'title': 'Chirbits by ScarletBeauty',
  56. },
  57. 'playlist_mincount': 3,
  58. }
  59. def _real_extract(self, url):
  60. profile_id = self._match_id(url)
  61. rss = self._download_xml(
  62. 'http://chirbit.com/rss/%s' % profile_id, profile_id)
  63. entries = [
  64. self.url_result(audio_url.text, 'Chirbit')
  65. for audio_url in rss.findall('./channel/item/link')]
  66. title = rss.find('./channel/title').text
  67. return self.playlist_result(entries, profile_id, title)