yt-dlp/youtube_dlc/extractor/hitrecord.py

69 lines
2.2 KiB
Python
Raw Normal View History

2017-01-06 15:56:59 -05:00
from __future__ import unicode_literals
from .common import InfoExtractor
2017-01-08 08:15:39 -05:00
from ..compat import compat_str
2017-01-06 15:56:59 -05:00
from ..utils import (
clean_html,
2017-01-08 08:15:39 -05:00
float_or_none,
2017-01-06 15:56:59 -05:00
int_or_none,
2017-01-08 08:15:39 -05:00
try_get,
2017-01-06 15:56:59 -05:00
)
class HitRecordIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?hitrecord\.org/records/(?P<id>\d+)'
_TEST = {
'url': 'https://hitrecord.org/records/2954362',
'md5': 'fe1cdc2023bce0bbb95c39c57426aa71',
'info_dict': {
'id': '2954362',
'ext': 'mp4',
'title': 'A Very Different World (HITRECORD x ACLU)',
'description': 'md5:e62defaffab5075a5277736bead95a3d',
2017-01-08 08:15:39 -05:00
'duration': 139.327,
2017-01-06 15:56:59 -05:00
'timestamp': 1471557582,
2017-01-08 08:15:39 -05:00
'upload_date': '20160818',
2017-01-06 15:56:59 -05:00
'uploader': 'Zuzi.C12',
'uploader_id': '362811',
2017-01-08 08:15:39 -05:00
'view_count': int,
'like_count': int,
'comment_count': int,
'tags': list,
2017-01-06 15:56:59 -05:00
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
2017-01-08 08:15:39 -05:00
video = self._download_json(
'https://hitrecord.org/api/web/records/%s' % video_id, video_id)
title = video['title']
video_url = video['source_url']['mp4_url']
tags = None
tags_list = try_get(video, lambda x: x['tags'], list)
if tags_list:
tags = [
t['text']
for t in tags_list
if isinstance(t, dict) and t.get('text')
and isinstance(t['text'], compat_str)]
2017-01-06 15:56:59 -05:00
return {
'id': video_id,
2017-01-08 08:15:39 -05:00
'url': video_url,
'title': title,
'description': clean_html(video.get('body')),
'duration': float_or_none(video.get('duration'), 1000),
'timestamp': int_or_none(video.get('created_at_i')),
'uploader': try_get(
video, lambda x: x['user']['username'], compat_str),
'uploader_id': try_get(
video, lambda x: compat_str(x['user']['id'])),
'view_count': int_or_none(video.get('total_views_count')),
'like_count': int_or_none(video.get('hearts_count')),
'comment_count': int_or_none(video.get('comments_count')),
'tags': tags,
2017-01-06 15:56:59 -05:00
}