Skip to content

Commit

Permalink
[naver] simplify code + add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Mar 5, 2024
1 parent 009322a commit 8a527f6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
18 changes: 7 additions & 11 deletions gallery_dl/extractor/naver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from .common import GalleryExtractor, Extractor, Message
from .. import text
from urllib.parse import unquote


class NaverBase():
Expand Down Expand Up @@ -63,16 +62,13 @@ def metadata(self, page):
return data

def images(self, page):
return [
(unquote(url, encoding="EUC-KR")
.replace("://post", "://blog", 1)
.partition("?")[0], None)
if "\ufffd" in unquote(url)
else
(url.replace("://post", "://blog", 1)
.partition("?")[0], None)
for url in text.extract_iter(page, 'data-lazy-src="', '"')
]
results = []
for url in text.extract_iter(page, 'data-lazy-src="', '"'):
url = url.replace("://post", "://blog", 1).partition("?")[0]
if "\ufffd" in text.unquote(url):
url = text.unquote(url, encoding="EUC-KR")
results.append((url, None))
return results


class NaverBlogExtractor(NaverBase, Extractor):
Expand Down
27 changes: 27 additions & 0 deletions test/results/naver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,33 @@
"#sha1_metadata": "a6e23d19afbee86b37d6e7ad934650c379d2cb1e",
},

{
"#url" : "https://blog.naver.com/PostView.nhn?blogId=rlfqjxm0&logNo=70161391809",
"#comment" : "filenames in EUC-KR encoding (#5126)",
"#category": ("", "naver", "post"),
"#class" : naver.NaverPostExtractor,
"#urls": (
"https://blogfiles.pstatic.net/20130305_23/ping9303_1362411028002Dpz9z_PNG/1_사본.png",
"https://blogfiles.pstatic.net/20130305_46/rlfqjxm0_1362473322580x33zi_PNG/오마갓합작.png",
),

"blog": {
"id" : "rlfqjxm0",
"num" : 43030507,
"user": "에나",
},
"post": {
"date" : "dt:2013-03-05 17:48:00",
"description": " ◈     PROMOTER :핑수 ˚ 아담 EDITOR:핑수   넵:이크:핑수...",
"num" : 70161391809,
"title" : "[공유] { 합작}  OH, MY GOD! ~ 아 또 무슨 종말을 한다 그래~"
},
"count" : 2,
"num" : range(1, 2),
"filename" : r"re:1_사본|오마갓합작",
"extension": "png",
},

{
"#url" : "https://blog.naver.com/gukjung",
"#category": ("", "naver", "blog"),
Expand Down

0 comments on commit 8a527f6

Please sign in to comment.