Skip to content

Commit

Permalink
[imgbb] update username extraction (#4626)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Oct 14, 2023
1 parent 1671a90 commit c6a3892
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 26 deletions.
33 changes: 22 additions & 11 deletions gallery_dl/extractor/imgbb.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ def _login_impl(self, username, password):
raise exception.AuthenticationError()
return self.cookies

def _extract_resource(self, page):
return util.json_loads(text.extr(
page, "CHV.obj.resource=", "};") + "}")

def _extract_user(self, page):
return self._extract_resource(page).get("user") or {}

def _pagination(self, page, endpoint, params):
data = None
seek, pos = text.extract(page, 'data-seek="', '"')
Expand Down Expand Up @@ -124,14 +131,14 @@ def __init__(self, match):
self.page_url = "https://ibb.co/album/" + self.album_id

def metadata(self, page):
album , pos = text.extract(page, '"og:title" content="', '"')
displayname, pos = text.extract(page, '"user":{"name":"', '"', pos)
username , pos = text.extract(page, ',"username":"', '"', pos)
album = text.extr(page, '"og:title" content="', '"')
user = self._extract_user(page)
return {
"album_id" : self.album_id,
"album_name" : text.unescape(album),
"user" : username.lower() if username else "",
"displayname": displayname or "",
"user" : user.get("username") or "",
"user_id" : user.get("id") or "",
"displayname": user.get("name") or "",
}

def images(self, page):
Expand Down Expand Up @@ -160,11 +167,11 @@ def __init__(self, match):
self.page_url = "https://{}.imgbb.com/".format(self.user)

def metadata(self, page):
displayname, pos = text.extract(page, '"user":{"name":"', '"')
username , pos = text.extract(page, ',"username":"', '"', pos)
user = self._extract_user(page)
return {
"user" : username or self.user,
"displayname": displayname or "",
"user" : user.get("username") or self.user,
"user_id" : user.get("id") or "",
"displayname": user.get("name") or "",
}

def images(self, page):
Expand All @@ -188,7 +195,9 @@ def __init__(self, match):

def items(self):
url = "https://ibb.co/" + self.image_id
extr = text.extract_from(self.request(url).text)
page = self.request(url).text
extr = text.extract_from(page)
user = self._extract_user(page)

image = {
"id" : self.image_id,
Expand All @@ -197,7 +206,9 @@ def items(self):
"url" : extr('"og:image" content="', '"'),
"width" : text.parse_int(extr('"og:image:width" content="', '"')),
"height": text.parse_int(extr('"og:image:height" content="', '"')),
"user" : extr(',"username":"', '"').lower(),
"user" : user.get("username") or "",
"user_id" : user.get("id") or "",
"displayname": user.get("name") or "",
}
image["extension"] = text.ext_from_url(image["url"])

Expand Down
50 changes: 35 additions & 15 deletions test/results/imgbb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,34 @@
"#url" : "https://ibb.co/album/i5PggF",
"#category": ("", "imgbb", "album"),
"#class" : imgbb.ImgbbAlbumExtractor,
"#range" : "1-80",
"#sha1_url" : "70afec9fcc3a6de62a6b644b487d892d8d47cf1a",
"#sha1_metadata": "569e1d88ebdd27655387559cdf1cd526a3e1ab69",
"#patten" : r"https://i\.ibb\.co/\w{7}/[\w-]+\.jpg",
"#count" : 91,
"#sha1_url" : "efe7e5a76531436e3b82c87e4ebd34c4dfeb484c",
"#sha1_metadata": "f1ab5492adb6333409f3367566a6dd7110537e21",

"album_id" : "i5PggF",
"album_name" : "British Scrap Book",
"extension" : "jpg",
"id" : "re:^\w{7}$",
"title" : str,
"url" : r"re:https://i\.ibb\.co/\w{7}/[\w-]+\.jpg",
"user" : "folkie",
"user_id" : "GvFMGK",
"displayname": "Folkie",
"width" : range(501, 1034),
"height" : range(335, 768),
"size" : range(74758, 439037),
},

{
"#url" : "https://ibb.co/album/i5PggF?sort=title_asc",
"#comment" : "'sort' query argument",
"#category": ("", "imgbb", "album"),
"#class" : imgbb.ImgbbAlbumExtractor,
"#range" : "1-80",
"#sha1_url" : "afdf5fc95d8e09d77e8f44312f3e9b843987bb5a",
"#sha1_metadata": "f090e14d0e5f7868595082b2c95da1309c84872d",
"#patten" : r"https://i\.ibb\.co/\w{7}/[\w-]+\.jpg",
"#count" : 91,
"#sha1_url" : "cde36552cc132a27178f22a1b9aceaa4df7e1575",
"#sha1_metadata": "b98bbb7671e31ebf9c7585fb9fc691b71bcdb546",
},

{
Expand All @@ -34,7 +50,9 @@
"#class" : imgbb.ImgbbAlbumExtractor,
"#sha1_url": "ac0abcfcb89f4df6adc2f7e4ff872f3b03ef1bc7",

"user": "",
"displayname": "",
"user" : "",
"user_id" : "",
},

{
Expand All @@ -49,7 +67,7 @@
"#url" : "https://folkie.imgbb.com",
"#category": ("", "imgbb", "user"),
"#class" : imgbb.ImgbbUserExtractor,
"#pattern" : r"https?://i\.ibb\.co/\w+/[^/?#]+",
"#patten" : r"https://i\.ibb\.co/\w{7}/[\w-]+\.jpg",
"#range" : "1-80",
},

Expand All @@ -60,13 +78,15 @@
"#pattern" : r"https://i\.ibb\.co/g3kvx80/Arundel-Ireeman-5\.jpg",
"#sha1_content": "c5a0965178a8b357acd8aa39660092918c63795e",

"id" : "fUqh5b",
"title" : "Arundel Ireeman 5",
"url" : "https://i.ibb.co/g3kvx80/Arundel-Ireeman-5.jpg",
"width" : 960,
"height" : 719,
"user" : "folkie",
"extension": "jpg",
"id" : "fUqh5b",
"title" : "Arundel Ireeman 5",
"url" : "https://i.ibb.co/g3kvx80/Arundel-Ireeman-5.jpg",
"width" : 960,
"height" : 719,
"user" : "folkie",
"user_id" : "GvFMGK",
"displayname": "Folkie",
"extension" : "jpg",
},

)

0 comments on commit c6a3892

Please sign in to comment.