[facebook] support selecting albums by title (#7848)
This commit is contained in:
@@ -443,17 +443,20 @@ class FacebookVideoExtractor(FacebookExtractor):
|
||||
class FacebookAlbumsExtractor(FacebookExtractor):
|
||||
"""Extractor for Facebook Profile albums"""
|
||||
subcategory = "albums"
|
||||
pattern = USER_PATTERN + r"/photos_albums"
|
||||
pattern = USER_PATTERN + r"/photos_albums(?:/([^/?#]+))?"
|
||||
example = "https://www.facebook.com/USERNAME/photos_albums"
|
||||
|
||||
def items(self):
|
||||
url = f"{self.root}/{self.groups[0]}/photos_albums"
|
||||
profile, name = self.groups
|
||||
url = f"{self.root}/{profile}/photos_albums"
|
||||
page = self.request(url).text
|
||||
|
||||
pos = page.find(
|
||||
'"TimelineAppCollectionAlbumsRenderer","collection":{"id":"')
|
||||
if pos < 0:
|
||||
return
|
||||
if name is not None:
|
||||
name = name.lower()
|
||||
|
||||
items = text.extract(page, '},"pageItems":', '}}},', pos)[0]
|
||||
edges = util.json_loads(items + "}}")["edges"]
|
||||
@@ -462,8 +465,10 @@ class FacebookAlbumsExtractor(FacebookExtractor):
|
||||
for edge in edges:
|
||||
node = edge["node"]
|
||||
album = node["node"]
|
||||
album["title"] = title = node["title"]["text"]
|
||||
if name is not None and name != title.lower():
|
||||
continue
|
||||
album["_extractor"] = FacebookSetExtractor
|
||||
album["title"] = node["title"]["text"]
|
||||
album["thumbnail"] = (img := node["image"]) and img["uri"]
|
||||
yield Message.Queue, album["url"], album
|
||||
|
||||
|
||||
@@ -265,4 +265,17 @@ __tests__ = (
|
||||
"url" : str,
|
||||
},
|
||||
|
||||
{
|
||||
"#url" : "https://www.facebook.com/facebook/photos_albums/Mobile uploads",
|
||||
"#class" : facebook.FacebookAlbumsExtractor,
|
||||
"#results" : (
|
||||
"https://www.facebook.com/media/set/?set=a.736550611850295&type=3",
|
||||
),
|
||||
|
||||
"id" : "736550611850295",
|
||||
"thumbnail": str,
|
||||
"title" : "Mobile uploads",
|
||||
"url" : "https://www.facebook.com/media/set/?set=a.736550611850295&type=3",
|
||||
},
|
||||
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user