[instagram] simplify code & complete tests (#743)

This commit is contained in:
Mike Fährmann
2020-05-28 22:31:01 +02:00
parent a4e3d40672
commit a63682a9c0

View File

@@ -145,20 +145,16 @@ class InstagramExtractor(Extractor):
)), )),
} }
if self._find_tags(common['description']): tags = self._find_tags(common['description'])
common['tags'] = sorted( if tags:
set(self._find_tags(common['description']))) common['tags'] = sorted(set(tags))
if media['location']: location = media['location']
common['location_id'] = media['location']['id'] if location:
common['location_slug'] = media['location']['slug'] common['location_id'] = location['id']
common['location_url'] = ( common['location_slug'] = location['slug']
'https://www.instagram.com/explore/locations/' + common['location_url'] = "{}/explore/locations/{}/{}/".format(
media['location']['id'] + self.root, location['id'], location['slug'])
'/' +
media['location']['slug'] +
'/'
)
medias = [] medias = []
if media['__typename'] == 'GraphSidecar': if media['__typename'] == 'GraphSidecar':
@@ -329,17 +325,16 @@ class InstagramExtractor(Extractor):
) )
def _extract_tagged_users(self, src_media, dest_dict): def _extract_tagged_users(self, src_media, dest_dict):
if src_media['edge_media_to_tagged_user']['edges']: edges = src_media['edge_media_to_tagged_user']['edges']
tagged_users = [] if edges:
for num, edge in enumerate( dest_dict['tagged_users'] = tagged_users = []
src_media['edge_media_to_tagged_user']['edges'], 1): for edge in edges:
tagged = edge['node'] user = edge['node']['user']
tagged_data = { tagged_users.append({
'username': tagged['user']['username'], 'id' : user['id'],
'full_name': tagged['user']['full_name'], 'username' : user['username'],
} 'full_name': user['full_name'],
tagged_users.append(tagged_data) })
dest_dict['tagged_users'] = tagged_users
class InstagramImageExtractor(InstagramExtractor): class InstagramImageExtractor(InstagramExtractor):
@@ -359,6 +354,7 @@ class InstagramImageExtractor(InstagramExtractor):
"likes": int, "likes": int,
"location_id": "214424288", "location_id": "214424288",
"location_slug": "hong-kong", "location_slug": "hong-kong",
"location_url": "re:/explore/locations/214424288/hong-kong/",
"media_id": "1922949326347663701", "media_id": "1922949326347663701",
"shortcode": "BqvsDleB3lV", "shortcode": "BqvsDleB3lV",
"post_id": "1922949326347663701", "post_id": "1922949326347663701",
@@ -436,8 +432,9 @@ class InstagramImageExtractor(InstagramExtractor):
("https://www.instagram.com/p/B_2lf3qAd3y/", { ("https://www.instagram.com/p/B_2lf3qAd3y/", {
"keyword": { "keyword": {
"tagged_users": [{ "tagged_users": [{
"id": "1246468638",
"username": "kaaymbl",
"full_name": "Call Me Kay", "full_name": "Call Me Kay",
"username": "kaaymbl"
}] }]
} }
}), }),