0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-30 03:33:02 +00:00
yt-dlp/youtube_dlc/extractor/radiojavan.py

84 lines
2.7 KiB
Python
Raw Normal View History

2015-04-03 16:25:39 +00:00
from __future__ import unicode_literals
import re
2015-04-03 16:25:39 +00:00
from .common import InfoExtractor
from ..utils import (
parse_resolution,
str_to_int,
unified_strdate,
2018-08-04 13:47:58 +00:00
urlencode_postdata,
urljoin,
2015-04-03 16:25:39 +00:00
)
2015-04-03 16:25:39 +00:00
class RadioJavanIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?radiojavan\.com/videos/video/(?P<id>[^/]+)/?'
_TEST = {
'url': 'http://www.radiojavan.com/videos/video/chaartaar-ashoobam',
'md5': 'e85208ffa3ca8b83534fca9fe19af95b',
'info_dict': {
'id': 'chaartaar-ashoobam',
'ext': 'mp4',
'title': 'Chaartaar - Ashoobam',
'thumbnail': r're:^https?://.*\.jpe?g$',
'upload_date': '20150215',
'view_count': int,
'like_count': int,
'dislike_count': int,
2015-04-03 16:25:39 +00:00
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
2015-04-03 16:25:39 +00:00
2018-08-04 13:47:58 +00:00
download_host = self._download_json(
'https://www.radiojavan.com/videos/video_host', video_id,
2018-08-04 13:47:58 +00:00
data=urlencode_postdata({'id': video_id}),
headers={
'Content-Type': 'application/x-www-form-urlencoded',
'Referer': url,
}).get('host', 'https://host1.rjmusicmedia.com')
webpage = self._download_webpage(url, video_id)
formats = []
for format_id, _, video_path in re.findall(
r'RJ\.video(?P<format_id>\d+[pPkK])\s*=\s*(["\'])(?P<url>(?:(?!\2).)+)\2',
webpage):
f = parse_resolution(format_id)
f.update({
'url': urljoin(download_host, video_path),
'format_id': format_id,
})
formats.append(f)
2015-04-04 13:25:08 +00:00
self._sort_formats(formats)
2015-04-03 16:25:39 +00:00
title = self._og_search_title(webpage)
thumbnail = self._og_search_thumbnail(webpage)
upload_date = unified_strdate(self._search_regex(
r'class="date_added">Date added: ([^<]+)<',
webpage, 'upload date', fatal=False))
2015-04-03 16:25:39 +00:00
view_count = str_to_int(self._search_regex(
r'class="views">Plays: ([\d,]+)',
webpage, 'view count', fatal=False))
like_count = str_to_int(self._search_regex(
r'class="rating">([\d,]+) likes',
webpage, 'like count', fatal=False))
dislike_count = str_to_int(self._search_regex(
r'class="rating">([\d,]+) dislikes',
webpage, 'dislike count', fatal=False))
2015-04-03 16:25:39 +00:00
return {
'id': video_id,
2015-04-03 16:25:39 +00:00
'title': title,
'thumbnail': thumbnail,
'upload_date': upload_date,
'view_count': view_count,
'like_count': like_count,
'dislike_count': dislike_count,
'formats': formats,
}