1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-02 06:57:44 +00:00
youtube-dl/youtube_dl/extractor/parler.py

88 lines
3.1 KiB
Python
Raw Normal View History

2022-08-07 18:14:24 +00:00
# coding: utf-8
from __future__ import unicode_literals
from urllib import parse
from .common import InfoExtractor
from ..utils import (
clean_html,
strip_or_none,
unified_timestamp,
urlencode_postdata,
)
2022-08-07 18:14:24 +00:00
class ParlerIE(InfoExtractor):
"""Extract videos from posts on Parler."""
_UUID_RE = r'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
_VALID_URL = r'https://parler\.com/feed/(?P<id>%s)' % (_UUID_RE, )
2022-08-07 18:14:24 +00:00
_TESTS = [
{
2022-08-08 18:01:58 +00:00
'url': 'https://parler.com/feed/df79fdba-07cc-48fe-b085-3293897520d7',
'md5': '16e0f447bf186bb3cf64de5bbbf4d22d',
'info_dict': {
'id': 'df79fdba-07cc-48fe-b085-3293897520d7',
'ext': 'mp4',
2022-08-09 10:42:26 +00:00
'title': '@TulsiGabbard-720',
'description': 'Puberty-blocking procedures promoted by the Biden/Harris Admin are child abuse. The FDA has recently confirmed these hormones/drugs have extremely dangerous side effects, like brain swelling and vision loss.',
2022-08-08 18:01:58 +00:00
'timestamp': 1659744000,
'upload_date': '20220806',
'uploader': 'Tulsi Gabbard',
'uploader_id': 'TulsiGabbard',
2022-08-07 18:14:24 +00:00
},
},
{
2022-08-08 18:01:58 +00:00
'url': 'https://parler.com/feed/a7406eb4-91e5-4793-b5e3-ade57a24e287',
'md5': '11687e2f5bb353682cee338d181422ed',
'info_dict': {
'id': 'a7406eb4-91e5-4793-b5e3-ade57a24e287',
'ext': 'mp4',
2022-08-09 10:42:26 +00:00
'title': '@BennyJohnson-360',
'description': 'This man should run for office',
2022-08-08 18:01:58 +00:00
'timestamp': 1659657600,
'upload_date': '20220805',
'uploader': 'Benny Johnson',
'uploader_id': 'BennyJohnson',
2022-08-07 18:14:24 +00:00
},
},
]
def _real_extract(self, url):
video_id = self._match_id(url)
# Get data from API
api_url = 'https://parler.com/open-api/ParleyDetailEndpoint.php'
payload = urlencode_postdata({'uuid': video_id})
2022-08-07 18:14:24 +00:00
status = self._download_json(api_url, video_id, data=payload)
# Pull out video
url = status['data'][0]['primary']['video_data']['videoSrc']
# now we know this exists and is a dict
data = status['data'][0]['primary']
2022-08-07 18:14:24 +00:00
# Pull out metadata
2022-08-09 10:42:26 +00:00
description = strip_or_none(clean_html(data.get('full_body')))
timestamp = unified_timestamp(data.get('date_created'))
uploader = strip_or_none(data.get('name'))
uploader_id = strip_or_none(data.get('username'))
uploader_url = ('https://parler.com/' + uploader_id) if uploader_id else None
2022-08-07 18:14:24 +00:00
2022-08-09 10:42:26 +00:00
# Keep the file name short so it doesn't exceed filesystem limits
title = self._generic_title(url)
if uploader_id:
title = '@%s-%s' % (uploader_id, title)
2022-08-07 18:14:24 +00:00
# Return the result
return {
2022-08-08 18:04:11 +00:00
'id': video_id,
'url': url,
'title': title,
2022-08-09 10:42:26 +00:00
'description': description,
2022-08-08 18:04:11 +00:00
'timestamp': timestamp,
'uploader': uploader,
'uploader_id': uploader_id,
'uploader_url': uploader_url,
2022-08-07 18:14:24 +00:00
}