2 from datetime
import date
3 from urllib
.parse
import unquote
5 from .common
import InfoExtractor
6 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 # Tags require account
22 'url': 'https://pr0gramm.com/new/video/5466437',
26 'title': 'pr0gramm-5466437 by g11st',
27 'tags': ['Neon Genesis Evangelion', 'Touhou Project', 'Fly me to the Moon', 'Marisad', 'Marisa Kirisame', 'video', 'sound', 'Marisa', 'Anime'],
29 'uploader_id': 394718,
30 'upload_timestamp': 1671590240,
31 'upload_date': '20221221',
35 'thumbnail': r
're:^https://thumb\.pr0gramm\.com/.*\.jpg',
36 '_old_archive_ids': ['pr0grammstatic 5466437'],
39 # Tags require account
40 'url': 'https://pr0gramm.com/new/3052805:comment28391322',
44 'title': 'pr0gramm-3052805 by Hansking1',
46 'uploader': 'Hansking1',
47 'uploader_id': 385563,
48 'upload_timestamp': 1552930408,
49 'upload_date': '20190318',
53 'thumbnail': r
're:^https://thumb\.pr0gramm\.com/.*\.jpg',
54 '_old_archive_ids': ['pr0grammstatic 3052805'],
57 # Requires verified account
58 'url': 'https://pr0gramm.com/new/Gianna%20Michaels/5848332',
62 'title': 'pr0gramm-5848332 by erd0pfel',
64 'uploader': 'erd0pfel',
65 'uploader_id': 349094,
66 'upload_timestamp': 1694489652,
67 'upload_date': '20230912',
71 'thumbnail': r
're:^https://thumb\.pr0gramm\.com/.*\.jpg',
72 '_old_archive_ids': ['pr0grammstatic 5848332'],
75 'url': 'https://pr0gramm.com/static/5466437',
76 'only_matching': True,
78 'url': 'https://pr0gramm.com/new/rowan%20atkinson%20herr%20bohne/3052805',
79 'only_matching': True,
81 'url': 'https://pr0gramm.com/user/froschler/dafur-ist-man-hier/5091290',
82 'only_matching': True,
85 BASE_URL
= 'https://pr0gramm.com'
87 @functools.cached_property
88 def _is_logged_in(self
):
89 return 'pp' in self
._get
_cookies
(self
.BASE_URL
)
91 @functools.cached_property
92 def _maximum_flags(self
):
93 # We need to guess the flags for the content otherwise the api will raise an error
94 # We can guess the maximum allowed flags for the account from the cookies
95 # Bitflags are (msbf): nsfp, nsfl, nsfw, sfw
97 if self
._is
_logged
_in
:
99 cookies
= self
._get
_cookies
(self
.BASE_URL
)
100 if 'me' not in cookies
:
101 self
._download
_webpage
(self
.BASE_URL
, None, 'Refreshing verification information')
102 if traverse_obj(cookies
, ('me', {lambda x: x.value}
, {unquote}
, {json.loads}
, 'verified')):
107 def _call_api(self
, endpoint
, video_id
, query
={}, note
='Downloading API json'):
108 data
= self
._download
_json
(
109 f
'https://pr0gramm.com/api/items/{endpoint}',
110 video_id
, note
, query
=query
, expected_status
=403)
112 error
= traverse_obj(data
, ('error', {str}
))
113 if error
in ('nsfwRequired', 'nsflRequired', 'nsfpRequired', 'verificationRequired'):
114 if not self
._is
_logged
_in
:
115 self
.raise_login_required()
116 raise ExtractorError(f
'Unverified account cannot access NSFW/NSFL ({error})', expected
=True)
118 message
= traverse_obj(data
, ('msg', {str}
)) or error
119 raise ExtractorError(f
'API returned error: {message}', expected
=True)
124 def _create_source_url(path
):
125 return urljoin('https://img.pr0gramm.com', path
)
127 def _real_extract(self
, url
):
128 video_id
= self
._match
_id
(url
)
129 video_info
= traverse_obj(
130 self
._call
_api
('get', video_id
, {'id': video_id, 'flags': self._maximum_flags}
),
131 ('items', 0, {dict}
))
133 source
= video_info
.get('image')
134 if not source
or not source
.endswith('mp4'):
135 self
.raise_no_formats('Could not extract a video', expected
=bool(source
), video_id
=video_id
)
138 if self
._is
_logged
_in
:
139 metadata
= self
._call
_api
('info', video_id
, {'itemId': video_id}
, note
='Downloading tags')
140 tags
= traverse_obj(metadata
, ('tags', ..., 'tag', {str}
))
141 # Sorted by "confidence", higher confidence = earlier in list
142 confidences
= traverse_obj(metadata
, ('tags', ..., 'confidence', ({int}
, {float}
)))
144 tags
= [tag
for _
, tag
in sorted(zip(confidences
, tags
), reverse
=True)]
146 formats
= traverse_obj(video_info
, ('variants', ..., {
147 'format_id': ('name', {str}
),
148 'url': ('path', {self._create_source_url}
),
149 'ext': ('mimeType', {mimetype2ext}
),
150 'vcodec': ('codec', {str}
),
151 'width': ('width', {int_or_none}
),
152 'height': ('height', {int_or_none}
),
153 'bitrate': ('bitRate', {float_or_none}
),
154 'filesize': ('fileSize', {int_or_none}
),
155 })) if video_info
.get('variants') else [{
157 'format_id': 'source',
158 **traverse_obj(video_info
, {
159 'url': ('image', {self._create_source_url}
),
160 'width': ('width', {int_or_none}
),
161 'height': ('height', {int_or_none}
),
166 for subtitle
in traverse_obj(video_info
, ('subtitles', lambda _
, v
: v
['language'])):
167 subtitles
.setdefault(subtitle
['language'], []).append(traverse_obj(subtitle
, {
168 'url': ('path', {self._create_source_url}
),
169 'note': ('label', {str}
),
174 'title': f
'pr0gramm-{video_id} by {video_info.get("user")}',
177 'subtitles': subtitles
,
178 'age_limit': 18 if traverse_obj(video_info
, ('flags', {0b110.__and__}
)) else 0,
179 '_old_archive_ids': [make_archive_id('Pr0grammStatic', video_id
)],
180 **traverse_obj(video_info
, {
181 'uploader': ('user', {str}
),
182 'uploader_id': ('userId', {int}
),
183 'like_count': ('up', {int}
),
184 'dislike_count': ('down', {int}
),
185 'upload_timestamp': ('created', {int}
),
186 'upload_date': ('created', {int}
, {date.fromtimestamp}
, {lambda x: x.strftime('%Y%m%d')}
),
187 'thumbnail': ('thumb', {lambda x: urljoin('https://thumb.pr0gramm.com', x)}
)