1 from .common
import InfoExtractor
12 class NineGagIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?9gag\.com/gag/(?P<id>[^/?&#]+)'
18 'url': 'https://9gag.com/gag/ae5Ag7B',
22 'title': 'Capybara Agility Training',
23 'upload_date': '20191108',
24 'timestamp': 1573237208,
25 'thumbnail': 'https://img-9gag-fun.9cache.com/photo/ae5Ag7B_460s.jpg',
26 'categories': ['Awesome'],
35 'url': 'https://9gag.com/gag/av5nvyb',
36 'only_matching': True,
38 # Non Anonymous Uploader
39 'url': 'https://9gag.com/gag/ajgp66G',
43 'title': 'Master Shifu! Or Splinter! You decide:',
44 'upload_date': '20220806',
45 'timestamp': 1659803411,
46 'thumbnail': 'https://img-9gag-fun.9cache.com/photo/ajgp66G_460s.jpg',
47 'categories': ['Funny'],
53 'uploader': 'Peter Klaus',
54 'uploader_id': 'peterklaus12',
55 'uploader_url': 'https://9gag.com/u/peterklaus12',
59 def _real_extract(self
, url
):
60 post_id
= self
._match
_id
(url
)
61 post
= self
._download
_json
(
62 'https://9gag.com/v1/post', post_id
, query
={
66 if post
.get('type') != 'Animated':
68 'The given url does not contain a video',
74 for key
, image
in (post
.get('images') or {}).items():
75 image_url
= url_or_none(image
.get('url'))
78 ext
= determine_ext(image_url
)
79 image_id
= key
.strip('image')
82 'width': int_or_none(image
.get('width')),
83 'height': int_or_none(image
.get('height')),
85 if ext
in ('jpg', 'png'):
86 webp_url
= image
.get('webpUrl')
90 'id': image_id
+ '-webp',
98 thumbnails
.append(common
)
99 elif ext
in ('webm', 'mp4'):
101 duration
= int_or_none(image
.get('duration'))
102 common
['acodec'] = 'none' if image
.get('hasAudio') == 0 else None
103 for vcodec
in ('vp8', 'vp9', 'h265'):
104 c_url
= image
.get(vcodec
+ 'Url')
109 'format_id': image_id
+ '-' + vcodec
,
116 'format_id': image_id
,
118 formats
.append(common
)
120 section
= traverse_obj(post
, ('postSection', 'name'))
123 post_tags
= post
.get('tags')
126 for tag
in post_tags
:
127 tag_key
= tag
.get('key')
134 'title': unescapeHTML(post
.get('title')),
135 'timestamp': int_or_none(post
.get('creationTs')),
136 'duration': duration
,
137 'uploader': traverse_obj(post
, ('creator', 'fullName')),
138 'uploader_id': traverse_obj(post
, ('creator', 'username')),
139 'uploader_url': url_or_none(traverse_obj(post
, ('creator', 'profileUrl'))),
141 'thumbnails': thumbnails
,
142 'like_count': int_or_none(post
.get('upVoteCount')),
143 'dislike_count': int_or_none(post
.get('downVoteCount')),
144 'comment_count': int_or_none(post
.get('commentsCount')),
145 'age_limit': 18 if post
.get('nsfw') == 1 else None,
146 'categories': [section
] if section
else None,