2 from urllib
.parse
import unquote
4 from .common
import InfoExtractor
5 from ..compat
import functools
15 from ..utils
.traversal
import traverse_obj
18 class Pr0grammIE(InfoExtractor
):
19 _VALID_URL
= r
'https?://pr0gramm\.com\/(?:[^/?#]+/)+(?P<id>[\d]+)(?:[/?#:]|$)'
21 'url': 'https://pr0gramm.com/new/video/5466437',
25 'title': 'pr0gramm-5466437 by g11st',
26 'tags': ['Neon Genesis Evangelion', 'Touhou Project', 'Fly me to the Moon', 'Marisad', 'Marisa Kirisame', 'video', 'sound', 'Marisa', 'Anime'],
28 'uploader_id': '394718',
29 'timestamp': 1671590240,
30 'upload_date': '20221221',
34 'thumbnail': r
're:^https://thumb\.pr0gramm\.com/.*\.jpg',
35 '_old_archive_ids': ['pr0grammstatic 5466437'],
38 'url': 'https://pr0gramm.com/new/3052805:comment28391322',
42 'title': 'pr0gramm-3052805 by Hansking1',
44 'uploader': 'Hansking1',
45 'uploader_id': '385563',
46 'timestamp': 1552930408,
47 'upload_date': '20190318',
51 'thumbnail': r
're:^https://thumb\.pr0gramm\.com/.*\.jpg',
52 '_old_archive_ids': ['pr0grammstatic 3052805'],
55 # Requires verified account
56 'url': 'https://pr0gramm.com/new/Gianna%20Michaels/5848332',
60 'title': 'pr0gramm-5848332 by erd0pfel',
62 'uploader': 'erd0pfel',
63 'uploader_id': '349094',
64 'timestamp': 1694489652,
65 'upload_date': '20230912',
69 'thumbnail': r
're:^https://thumb\.pr0gramm\.com/.*\.jpg',
70 '_old_archive_ids': ['pr0grammstatic 5848332'],
73 'url': 'https://pr0gramm.com/top/5895149',
77 'title': 'pr0gramm-5895149 by algoholigSeeManThrower',
79 'uploader': 'algoholigSeeManThrower',
80 'uploader_id': '457556',
81 'timestamp': 1697580902,
82 'upload_date': '20231018',
86 'thumbnail': 'https://thumb.pr0gramm.com/2023/10/18/db47bb3db5e1a1b3.jpg',
87 '_old_archive_ids': ['pr0grammstatic 5895149'],
90 'url': 'https://pr0gramm.com/static/5466437',
91 'only_matching': True,
93 'url': 'https://pr0gramm.com/new/rowan%20atkinson%20herr%20bohne/3052805',
94 'only_matching': True,
96 'url': 'https://pr0gramm.com/user/froschler/dafur-ist-man-hier/5091290',
97 'only_matching': True,
100 BASE_URL
= 'https://pr0gramm.com'
102 @functools.cached_property
103 def _is_logged_in(self
):
104 return 'pp' in self
._get
_cookies
(self
.BASE_URL
)
106 @functools.cached_property
107 def _maximum_flags(self
):
108 # We need to guess the flags for the content otherwise the api will raise an error
109 # We can guess the maximum allowed flags for the account from the cookies
110 # Bitflags are (msbf): pol, nsfp, nsfl, nsfw, sfw
112 if self
._is
_logged
_in
:
114 cookies
= self
._get
_cookies
(self
.BASE_URL
)
115 if 'me' not in cookies
:
116 self
._download
_webpage
(self
.BASE_URL
, None, 'Refreshing verification information')
117 if traverse_obj(cookies
, ('me', {lambda x: x.value}
, {unquote}
, {json.loads}
, 'verified')):
122 def _call_api(self
, endpoint
, video_id
, query
={}, note
='Downloading API json'):
123 data
= self
._download
_json
(
124 f
'https://pr0gramm.com/api/items/{endpoint}',
125 video_id
, note
, query
=query
, expected_status
=403)
127 error
= traverse_obj(data
, ('error', {str}
))
128 if error
in ('nsfwRequired', 'nsflRequired', 'nsfpRequired', 'verificationRequired'):
129 if not self
._is
_logged
_in
:
130 self
.raise_login_required()
131 raise ExtractorError(f
'Unverified account cannot access NSFW/NSFL ({error})', expected
=True)
133 message
= traverse_obj(data
, ('msg', {str}
)) or error
134 raise ExtractorError(f
'API returned error: {message}', expected
=True)
139 def _create_source_url(path
):
140 return urljoin('https://img.pr0gramm.com', path
)
142 def _real_extract(self
, url
):
143 video_id
= self
._match
_id
(url
)
144 video_info
= traverse_obj(
145 self
._call
_api
('get', video_id
, {'id': video_id, 'flags': self._maximum_flags}
),
146 ('items', 0, {dict}
))
148 source
= video_info
.get('image')
149 if not source
or not source
.endswith('mp4'):
150 self
.raise_no_formats('Could not extract a video', expected
=bool(source
), video_id
=video_id
)
152 metadata
= self
._call
_api
('info', video_id
, {'itemId': video_id}
, note
='Downloading tags')
153 tags
= traverse_obj(metadata
, ('tags', ..., 'tag', {str}
))
154 # Sorted by "confidence", higher confidence = earlier in list
155 confidences
= traverse_obj(metadata
, ('tags', ..., 'confidence', ({int}
, {float}
)))
157 tags
= [tag
for _
, tag
in sorted(zip(confidences
, tags
), reverse
=True)]
159 formats
= traverse_obj(video_info
, ('variants', ..., {
160 'format_id': ('name', {str}
),
161 'url': ('path', {self._create_source_url}
),
162 'ext': ('mimeType', {mimetype2ext}
),
163 'vcodec': ('codec', {str}
),
164 'width': ('width', {int_or_none}
),
165 'height': ('height', {int_or_none}
),
166 'bitrate': ('bitRate', {float_or_none}
),
167 'filesize': ('fileSize', {int_or_none}
),
168 })) if video_info
.get('variants') else [{
170 'format_id': 'source',
171 **traverse_obj(video_info
, {
172 'url': ('image', {self._create_source_url}
),
173 'width': ('width', {int_or_none}
),
174 'height': ('height', {int_or_none}
),
179 for subtitle
in traverse_obj(video_info
, ('subtitles', lambda _
, v
: v
['language'])):
180 subtitles
.setdefault(subtitle
['language'], []).append(traverse_obj(subtitle
, {
181 'url': ('path', {self._create_source_url}
),
182 'note': ('label', {str}
),
187 'title': f
'pr0gramm-{video_id} by {video_info.get("user")}',
190 'subtitles': subtitles
,
191 'age_limit': 18 if traverse_obj(video_info
, ('flags', {0b110.__and__}
)) else 0,
192 '_old_archive_ids': [make_archive_id('Pr0grammStatic', video_id
)],
193 **traverse_obj(video_info
, {
194 'uploader': ('user', {str}
),
195 'uploader_id': ('userId', {str_or_none}
),
196 'like_count': ('up', {int}
),
197 'dislike_count': ('down', {int}
),
198 'timestamp': ('created', {int}
),
199 'thumbnail': ('thumb', {lambda x: urljoin('https://thumb.pr0gramm.com', x)}
)