6 from .common
import InfoExtractor
16 from ..utils
.traversal
import traverse_obj
19 class Pr0grammIE(InfoExtractor
):
20 _VALID_URL
= r
'https?://pr0gramm\.com\/(?:[^/?#]+/)+(?P<id>[\d]+)(?:[/?#:]|$)'
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 'timestamp': 1671590240,
31 'upload_date': '20221221',
35 'thumbnail': r
're:^https://thumb\.pr0gramm\.com/.*\.jpg',
36 '_old_archive_ids': ['pr0grammstatic 5466437'],
39 'url': 'https://pr0gramm.com/new/3052805:comment28391322',
43 'title': 'pr0gramm-3052805 by Hansking1',
45 'uploader': 'Hansking1',
46 'uploader_id': '385563',
47 'timestamp': 1552930408,
48 'upload_date': '20190318',
52 'thumbnail': r
're:^https://thumb\.pr0gramm\.com/.*\.jpg',
53 '_old_archive_ids': ['pr0grammstatic 3052805'],
56 # Requires verified account
57 'url': 'https://pr0gramm.com/new/Gianna%20Michaels/5848332',
61 'title': 'pr0gramm-5848332 by erd0pfel',
63 'uploader': 'erd0pfel',
64 'uploader_id': '349094',
65 'timestamp': 1694489652,
66 'upload_date': '20230912',
70 'thumbnail': r
're:^https://thumb\.pr0gramm\.com/.*\.jpg',
71 '_old_archive_ids': ['pr0grammstatic 5848332'],
74 'url': 'https://pr0gramm.com/top/5895149',
78 'title': 'pr0gramm-5895149 by algoholigSeeManThrower',
80 'uploader': 'algoholigSeeManThrower',
81 'uploader_id': '457556',
82 'timestamp': 1697580902,
83 'upload_date': '20231018',
87 'thumbnail': 'https://thumb.pr0gramm.com/2023/10/18/db47bb3db5e1a1b3.jpg',
88 '_old_archive_ids': ['pr0grammstatic 5895149'],
91 'url': 'https://pr0gramm.com/static/5466437',
92 'only_matching': True,
94 'url': 'https://pr0gramm.com/new/rowan%20atkinson%20herr%20bohne/3052805',
95 'only_matching': True,
97 'url': 'https://pr0gramm.com/user/froschler/dafur-ist-man-hier/5091290',
98 'only_matching': True,
101 BASE_URL
= 'https://pr0gramm.com'
103 @functools.cached_property
104 def _is_logged_in(self
):
105 return 'pp' in self
._get
_cookies
(self
.BASE_URL
)
107 @functools.cached_property
108 def _maximum_flags(self
):
109 # We need to guess the flags for the content otherwise the api will raise an error
110 # We can guess the maximum allowed flags for the account from the cookies
111 # Bitflags are (msbf): pol, nsfp, nsfl, nsfw, sfw
113 if self
._is
_logged
_in
:
115 cookies
= self
._get
_cookies
(self
.BASE_URL
)
116 if 'me' not in cookies
:
117 self
._download
_webpage
(self
.BASE_URL
, None, 'Refreshing verification information')
118 if traverse_obj(cookies
, ('me', {lambda x
: x
.value
}, {urllib
.parse
.unquote
}, {json
.loads
}, 'verified')):
123 def _call_api(self
, endpoint
, video_id
, query
={}, note
='Downloading API json'):
124 data
= self
._download
_json
(
125 f
'https://pr0gramm.com/api/items/{endpoint}',
126 video_id
, note
, query
=query
, expected_status
=403)
128 error
= traverse_obj(data
, ('error', {str}
))
129 if error
in ('nsfwRequired', 'nsflRequired', 'nsfpRequired', 'verificationRequired'):
130 if not self
._is
_logged
_in
:
131 self
.raise_login_required()
132 raise ExtractorError(f
'Unverified account cannot access NSFW/NSFL ({error})', expected
=True)
134 message
= traverse_obj(data
, ('msg', {str}
)) or error
135 raise ExtractorError(f
'API returned error: {message}', expected
=True)
140 def _create_source_url(path
):
141 return urljoin('https://img.pr0gramm.com', path
)
143 def _real_extract(self
, url
):
144 video_id
= self
._match
_id
(url
)
145 video_info
= traverse_obj(
146 self
._call
_api
('get', video_id
, {'id': video_id
, 'flags': self
._maximum
_flags
}),
147 ('items', 0, {dict}
))
149 source
= video_info
.get('image')
150 if not source
or not source
.endswith('mp4'):
151 self
.raise_no_formats('Could not extract a video', expected
=bool(source
), video_id
=video_id
)
153 metadata
= self
._call
_api
('info', video_id
, {'itemId': video_id
}, note
='Downloading tags')
154 tags
= traverse_obj(metadata
, ('tags', ..., 'tag', {str}
))
155 # Sorted by "confidence", higher confidence = earlier in list
156 confidences
= traverse_obj(metadata
, ('tags', ..., 'confidence', ({int}
, {float}
)))
158 tags
= [tag
for _
, tag
in sorted(zip(confidences
, tags
), reverse
=True)]
160 formats
= traverse_obj(video_info
, ('variants', ..., {
161 'format_id': ('name', {str}
),
162 'url': ('path', {self
._create
_source
_url
}),
163 'ext': ('mimeType', {mimetype2ext}
),
164 'vcodec': ('codec', {str}
),
165 'width': ('width', {int_or_none}
),
166 'height': ('height', {int_or_none}
),
167 'bitrate': ('bitRate', {float_or_none}
),
168 'filesize': ('fileSize', {int_or_none}
),
169 })) if video_info
.get('variants') else [{
171 'format_id': 'source',
172 **traverse_obj(video_info
, {
173 'url': ('image', {self
._create
_source
_url
}),
174 'width': ('width', {int_or_none}
),
175 'height': ('height', {int_or_none}
),
180 for subtitle
in traverse_obj(video_info
, ('subtitles', lambda _
, v
: v
['language'])):
181 subtitles
.setdefault(subtitle
['language'], []).append(traverse_obj(subtitle
, {
182 'url': ('path', {self
._create
_source
_url
}),
183 'note': ('label', {str}
),
188 'title': f
'pr0gramm-{video_id} by {video_info.get("user")}',
191 'subtitles': subtitles
,
192 'age_limit': 18 if traverse_obj(video_info
, ('flags', {0b110.__and
__})) else 0,
193 '_old_archive_ids': [make_archive_id('Pr0grammStatic', video_id
)],
194 **traverse_obj(video_info
, {
195 'uploader': ('user', {str}
),
196 'uploader_id': ('userId', {str_or_none}
),
197 'like_count': ('up', {int}
),
198 'dislike_count': ('down', {int}
),
199 'timestamp': ('created', {int}
),
200 'upload_date': ('created', {int}
, {dt
.date
.fromtimestamp
}, {lambda x
: x
.strftime('%Y%m%d')}),
201 'thumbnail': ('thumb', {lambda x
: urljoin('https://thumb.pr0gramm.com', x
)}),