]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/chirbit.py
debian/watch: Add back pgpsigurlmangle.
[youtubedl] / youtube_dl / extractor / chirbit.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 parse_duration,
7 int_or_none,
8 )
9
10
11 class ChirbitIE(InfoExtractor):
12 IE_NAME = 'chirbit'
13 _VALID_URL = r'https?://(?:www\.)?chirb\.it/(?:(?:wp|pl)/|fb_chirbit_player\.swf\?key=)?(?P<id>[\da-zA-Z]+)'
14 _TESTS = [{
15 'url': 'http://chirb.it/PrIPv5',
16 'md5': '9847b0dad6ac3e074568bf2cfb197de8',
17 'info_dict': {
18 'id': 'PrIPv5',
19 'ext': 'mp3',
20 'title': 'Фасадстрой',
21 'duration': 52,
22 'view_count': int,
23 'comment_count': int,
24 }
25 }, {
26 'url': 'https://chirb.it/fb_chirbit_player.swf?key=PrIPv5',
27 'only_matching': True,
28 }]
29
30 def _real_extract(self, url):
31 audio_id = self._match_id(url)
32
33 webpage = self._download_webpage(
34 'http://chirb.it/%s' % audio_id, audio_id)
35
36 audio_url = self._search_regex(
37 r'"setFile"\s*,\s*"([^"]+)"', webpage, 'audio url')
38
39 title = self._search_regex(
40 r'itemprop="name">([^<]+)', webpage, 'title')
41 duration = parse_duration(self._html_search_meta(
42 'duration', webpage, 'duration', fatal=False))
43 view_count = int_or_none(self._search_regex(
44 r'itemprop="playCount"\s*>(\d+)', webpage,
45 'listen count', fatal=False))
46 comment_count = int_or_none(self._search_regex(
47 r'>(\d+) Comments?:', webpage,
48 'comment count', fatal=False))
49
50 return {
51 'id': audio_id,
52 'url': audio_url,
53 'title': title,
54 'duration': duration,
55 'view_count': view_count,
56 'comment_count': comment_count,
57 }
58
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 'title': 'Chirbits by ScarletBeauty',
68 },
69 'playlist_mincount': 3,
70 }
71
72 def _real_extract(self, url):
73 profile_id = self._match_id(url)
74
75 rss = self._download_xml(
76 'http://chirbit.com/rss/%s' % profile_id, profile_id)
77
78 entries = [
79 self.url_result(audio_url.text, 'Chirbit')
80 for audio_url in rss.findall('./channel/item/link')]
81
82 title = rss.find('./channel/title').text
83
84 return self.playlist_result(entries, profile_id, title)