1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-12-23 08:02:53 +08:00
youtube-dl/youtube_dl/extractor/chirbit.py

85 lines
2.5 KiB
Python
Raw Normal View History

2015-02-20 17:49:45 +08:00
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import (
parse_duration,
int_or_none,
)
2015-02-20 17:49:45 +08:00
class ChirbitIE(InfoExtractor):
2015-02-23 23:28:14 +08:00
IE_NAME = 'chirbit'
_VALID_URL = r'https?://(?:www\.)?chirb\.it/(?:(?:wp|pl)/|fb_chirbit_player\.swf\?key=)?(?P<id>[\da-zA-Z]+)'
_TESTS = [{
2015-02-20 17:49:45 +08:00
'url': 'http://chirb.it/PrIPv5',
'md5': '9847b0dad6ac3e074568bf2cfb197de8',
'info_dict': {
'id': 'PrIPv5',
'ext': 'mp3',
'title': 'Фасадстрой',
'duration': 52,
'view_count': int,
'comment_count': int,
2015-02-20 17:49:45 +08:00
}
}, {
'url': 'https://chirb.it/fb_chirbit_player.swf?key=PrIPv5',
'only_matching': True,
}]
2015-02-20 17:49:45 +08:00
def _real_extract(self, url):
audio_id = self._match_id(url)
webpage = self._download_webpage(
'http://chirb.it/%s' % audio_id, audio_id)
audio_url = self._search_regex(
r'"setFile"\s*,\s*"([^"]+)"', webpage, 'audio url')
2015-02-20 17:49:45 +08:00
title = self._search_regex(
r'itemprop="name">([^<]+)', webpage, 'title')
duration = parse_duration(self._html_search_meta(
'duration', webpage, 'duration', fatal=False))
view_count = int_or_none(self._search_regex(
r'itemprop="playCount"\s*>(\d+)', webpage,
'listen count', fatal=False))
comment_count = int_or_none(self._search_regex(
r'>(\d+) Comments?:', webpage,
'comment count', fatal=False))
2015-02-20 17:49:45 +08:00
return {
'id': audio_id,
'url': audio_url,
'title': title,
'duration': duration,
'view_count': view_count,
'comment_count': comment_count,
2015-02-20 17:49:45 +08:00
}
2015-02-20 21:48:12 +08:00
2015-02-20 21:48:12 +08:00
class ChirbitProfileIE(InfoExtractor):
2015-02-23 23:28:14 +08:00
IE_NAME = 'chirbit:profile'
_VALID_URL = r'https?://(?:www\.)?chirbit.com/(?:rss/)?(?P<id>[^/]+)'
2015-02-20 21:48:12 +08:00
_TEST = {
'url': 'http://chirbit.com/ScarletBeauty',
'info_dict': {
'id': 'ScarletBeauty',
'title': 'Chirbits by ScarletBeauty',
},
'playlist_mincount': 3,
2015-02-20 21:48:12 +08:00
}
def _real_extract(self, url):
profile_id = self._match_id(url)
rss = self._download_xml(
'http://chirbit.com/rss/%s' % profile_id, profile_id)
2015-02-20 21:48:12 +08:00
entries = [
self.url_result(audio_url.text, 'Chirbit')
for audio_url in rss.findall('./channel/item/link')]
2015-02-20 21:48:12 +08:00
title = rss.find('./channel/title').text
2015-02-20 21:48:12 +08:00
return self.playlist_result(entries, profile_id, title)