mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-11-22 16:44:32 +01:00
[bannedvideo] Coding conventions
This commit is contained in:
parent
53f669364f
commit
b662e68bec
@ -1,10 +1,18 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
|
||||||
|
from ..utils import (
|
||||||
|
try_get,
|
||||||
|
int_or_none,
|
||||||
|
url_or_none,
|
||||||
|
float_or_none,
|
||||||
|
unified_timestamp,
|
||||||
|
unified_strdate,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BannedVideoIE(InfoExtractor):
|
class BannedVideoIE(InfoExtractor):
|
||||||
_GRAPHQL_API = 'https://api.infowarsmedia.com/graphql'
|
_GRAPHQL_API = 'https://api.infowarsmedia.com/graphql'
|
||||||
@ -122,48 +130,50 @@ fragment VideoComment on Comment {
|
|||||||
'thumbnail': r're:^https?://(?:www\.)?assets\.infowarsmedia.com/images/',
|
'thumbnail': r're:^https?://(?:www\.)?assets\.infowarsmedia.com/images/',
|
||||||
'description': 'The Chinese Communist Party Official Spokesperson At the Ministry of Truth Released Their Statement Exclusively To Alex Jones and Infowars.com',
|
'description': 'The Chinese Communist Party Official Spokesperson At the Ministry of Truth Released Their Statement Exclusively To Alex Jones and Infowars.com',
|
||||||
'upload_date': '20200324',
|
'upload_date': '20200324',
|
||||||
'timestamp': 1585084295.064,
|
'timestamp': 1585087895,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
video_info = self._download_json(
|
video_info = try_get(
|
||||||
self._GRAPHQL_API,
|
self._download_json(
|
||||||
video_id,
|
self._GRAPHQL_API,
|
||||||
headers=self._GRAPHQL_HEADERS,
|
video_id,
|
||||||
data=json.dumps({
|
headers=self._GRAPHQL_HEADERS,
|
||||||
'variables': {
|
data=json.dumps({
|
||||||
'id': video_id
|
'variables': {
|
||||||
},
|
'id': video_id
|
||||||
'operationName': 'GetVideo',
|
},
|
||||||
'query': self._GRAPHQL_GETVIDEO_QUERY
|
'operationName': 'GetVideo',
|
||||||
}).encode('utf8'),
|
'query': self._GRAPHQL_GETVIDEO_QUERY
|
||||||
).get('data').get('getVideo')
|
}).encode('utf8')),
|
||||||
video_comments = self._download_json(
|
lambda x: x['data']['getVideo'])
|
||||||
self._GRAPHQL_API,
|
video_comments = try_get(
|
||||||
video_id,
|
self._download_json(
|
||||||
headers=self._GRAPHQL_HEADERS,
|
self._GRAPHQL_API,
|
||||||
data=json.dumps({
|
video_id,
|
||||||
'variables': {
|
headers=self._GRAPHQL_HEADERS,
|
||||||
'id': video_id
|
data=json.dumps({
|
||||||
},
|
'variables': {
|
||||||
'operationName': 'GetVideoComments',
|
'id': video_id
|
||||||
'query': self._GRAPHQL_GETCOMMENTS_QUERY
|
},
|
||||||
}).encode('utf8'),
|
'operationName': 'GetVideoComments',
|
||||||
).get('data').get('getVideoComments')
|
'query': self._GRAPHQL_GETCOMMENTS_QUERY
|
||||||
upload_date = datetime.fromisoformat(video_info.get('createdAt')[:-1])
|
}).encode('utf8')),
|
||||||
|
lambda x: x['data']['getVideoComments'])
|
||||||
|
upload_date = video_info.get('createdAt')
|
||||||
metadata = {}
|
metadata = {}
|
||||||
metadata['id'] = video_id
|
metadata['id'] = video_id
|
||||||
metadata['title'] = video_info.get('title')[:-1]
|
metadata['title'] = video_info.get('title')[:-1]
|
||||||
metadata['description'] = video_info.get('summary')
|
metadata['description'] = video_info.get('summary')
|
||||||
metadata['channel'] = video_info.get('channel').get('title')
|
metadata['channel'] = video_info.get('channel').get('title')
|
||||||
metadata['channel_id'] = video_info.get('channel').get('_id')
|
metadata['channel_id'] = video_info.get('channel').get('_id')
|
||||||
metadata['view_count'] = video_info.get('playCount')
|
metadata['view_count'] = int_or_none(video_info.get('playCount'))
|
||||||
metadata['thumbnail'] = video_info.get('largeImage')
|
metadata['thumbnail'] = url_or_none(video_info.get('largeImage'))
|
||||||
metadata['duration'] = video_info.get('videoDuration')
|
metadata['duration'] = float_or_none(video_info.get('videoDuration'), scale=1000)
|
||||||
metadata['upload_date'] = upload_date.strftime('%Y%m%d')
|
metadata['upload_date'] = unified_strdate(upload_date)
|
||||||
metadata['timestamp'] = upload_date.timestamp()
|
metadata['timestamp'] = unified_timestamp(upload_date)
|
||||||
tags = []
|
tags = []
|
||||||
|
|
||||||
for tag in video_info.get('tags'):
|
for tag in video_info.get('tags'):
|
||||||
@ -175,7 +185,13 @@ fragment VideoComment on Comment {
|
|||||||
|
|
||||||
if is_live:
|
if is_live:
|
||||||
formats = []
|
formats = []
|
||||||
formats.extend(self._extract_m3u8_formats(video_info.get('streamUrl'), video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls', live=True))
|
formats.extend(self._extract_m3u8_formats(
|
||||||
|
video_info.get('streamUrl'),
|
||||||
|
video_id,
|
||||||
|
'mp4',
|
||||||
|
entry_protocol='m3u8_native',
|
||||||
|
m3u8_id='hls',
|
||||||
|
live=True))
|
||||||
metadata['formats'] = formats
|
metadata['formats'] = formats
|
||||||
else:
|
else:
|
||||||
metadata['url'] = video_info.get('directUrl')
|
metadata['url'] = video_info.get('directUrl')
|
||||||
@ -184,36 +200,35 @@ fragment VideoComment on Comment {
|
|||||||
comments = []
|
comments = []
|
||||||
|
|
||||||
for comment in video_comments:
|
for comment in video_comments:
|
||||||
comment_date = datetime.fromisoformat(comment.get('createdAt')[:-1])
|
|
||||||
comments.append({
|
comments.append({
|
||||||
'id': comment.get('_id'),
|
'id': comment.get('_id'),
|
||||||
'text': comment.get('content'),
|
'text': comment.get('content'),
|
||||||
'author': comment.get('user').get('username'),
|
'author': comment.get('user').get('username'),
|
||||||
'author_id': comment.get('user').get('_id'),
|
'author_id': comment.get('user').get('_id'),
|
||||||
'timestamp': comment_date.timestamp(),
|
'timestamp': unified_timestamp(comment.get('createdAt')),
|
||||||
'parent': 'root'
|
'parent': 'root'
|
||||||
})
|
})
|
||||||
if comment.get('replyCount') > 0:
|
if comment.get('replyCount') > 0:
|
||||||
replies = self._download_json(
|
replies = try_get(
|
||||||
self._GRAPHQL_API,
|
self._download_json(
|
||||||
video_id,
|
self._GRAPHQL_API,
|
||||||
headers=self._GRAPHQL_HEADERS,
|
video_id,
|
||||||
data=json.dumps({
|
headers=self._GRAPHQL_HEADERS,
|
||||||
'variables': {
|
data=json.dumps({
|
||||||
'id': comment.get('_id')
|
'variables': {
|
||||||
},
|
'id': comment.get('_id')
|
||||||
'operationName': 'GetCommentReplies',
|
},
|
||||||
'query': self._GRAPHQL_GETCOMMENTSREPLIES_QUERY
|
'operationName': 'GetCommentReplies',
|
||||||
}).encode('utf8'),
|
'query': self._GRAPHQL_GETCOMMENTSREPLIES_QUERY
|
||||||
).get('data').get('getCommentReplies')
|
}).encode('utf8')),
|
||||||
|
lambda x: x['data']['getCommentReplies'])
|
||||||
for reply in replies:
|
for reply in replies:
|
||||||
reply_date = datetime.fromisoformat(reply.get('createdAt')[:-1])
|
|
||||||
comments.append({
|
comments.append({
|
||||||
'id': reply.get('_id'),
|
'id': reply.get('_id'),
|
||||||
'text': reply.get('content'),
|
'text': reply.get('content'),
|
||||||
'author': reply.get('user').get('username'),
|
'author': reply.get('user').get('username'),
|
||||||
'author_id': reply.get('user').get('_id'),
|
'author_id': reply.get('user').get('_id'),
|
||||||
'timestamp': reply_date.timestamp(),
|
'timestamp': unified_timestamp(reply.get('createdAt')),
|
||||||
'parent': comment.get('_id')
|
'parent': comment.get('_id')
|
||||||
})
|
})
|
||||||
metadata["comments"] = comments
|
metadata["comments"] = comments
|
||||||
|
Loading…
Reference in New Issue
Block a user