mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-16 23:01:06 +02:00
feat(instagram): improve parsing of Instagram media IDs and mentions
- Enhanced the regular expression for mentions to prevent trailing punctuation from being included in handles. - Added support for extracting media IDs from deep-link meta tags in anonymous posts. - Updated unit tests to validate the new media ID extraction and ensure proper handling of mentions.
This commit is contained in:
parent
d41ccb7edd
commit
457be1871c
2 changed files with 21 additions and 7 deletions
|
|
@ -123,14 +123,16 @@ def test_parse_post_falls_back_to_og_meta():
|
|||
<html><head>
|
||||
<meta property="og:type" content="video.other" />
|
||||
<meta property="og:image" content="https://cdn/i.jpg" />
|
||||
<meta property="al:ios:url" content="instagram://media?id=3938367641542741384" />
|
||||
<meta property="og:title"
|
||||
content="Nat Geo on Instagram: "a caption #wow #wow @buzz"" />
|
||||
content="Nat Geo on Instagram: "a caption #wow #wow @buzz."" />
|
||||
<meta property="og:description"
|
||||
content="1,234 likes, 56 comments - natgeo on January 2, 2024: "a caption #wow #wow @buzz"" />
|
||||
content="1,234 likes, 56 comments - natgeo on January 2, 2024: "a caption #wow #wow @buzz."" />
|
||||
</head></html>
|
||||
"""
|
||||
item = parse_post(html, url=_POST_URL, shortcode="Cabc")
|
||||
assert item is not None
|
||||
assert item["id"] == "3938367641542741384" # numeric pk from al:ios:url meta
|
||||
assert item["likesCount"] == 1234
|
||||
assert item["commentsCount"] == 56
|
||||
assert item["displayUrl"] == "https://cdn/i.jpg"
|
||||
|
|
@ -138,9 +140,9 @@ def test_parse_post_falls_back_to_og_meta():
|
|||
assert item["ownerUsername"] == "natgeo"
|
||||
assert item["ownerFullName"] == "Nat Geo"
|
||||
assert item["timestamp"] == "2024-01-02" # og carries date only, no time
|
||||
assert item["caption"] == "a caption #wow #wow @buzz" # unescaped, unwrapped
|
||||
assert item["hashtags"] == ["wow"] # deduped, no counts-prefix pollution
|
||||
assert item["mentions"] == ["buzz"]
|
||||
assert item["caption"] == "a caption #wow #wow @buzz." # @ -> @, unescaped
|
||||
assert item["hashtags"] == ["wow"] # deduped, no @-as-#064 pollution
|
||||
assert item["mentions"] == ["buzz"] # trailing sentence dot stripped
|
||||
|
||||
|
||||
def test_parse_post_og_degrades_without_crashing():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue