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.

84 lines
2.5 KiB

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