Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError for video_url, and better workflow #1321

Merged
merged 4 commits into from
Nov 12, 2021

Conversation

fireattack
Copy link
Collaborator

@fireattack fireattack commented Oct 26, 2021

Fixes #1320.

Also improves the workflow a little bit.

@pafke2
Copy link

pafke2 commented Oct 29, 2021

Sorry for a lame question, but where can I put those lines to make it work?

@SpyHoodle
Copy link

Attribute video_url in object StoryItem also needs to be fixed, creates the same errors

@fireattack
Copy link
Collaborator Author

StoryItem actually uses video_resources, and does not suffer from this problem (graphql will return URLs). But it doesn't hurt to copy the workflow there.

Copy link
Member

@aandergr aandergr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Sorry for my late response, I have been quite busy the last few weeks.

The change looks very good, I have only inline-commented a little suggestion.

I have noticed that one of the Actions failed, fixed that, and rebased your branch on the now-current master.

if self._context.iphone_support and self._context.is_logged_in:
try:
version_urls.extend(version['url'] for version in self._iphone_struct['video_versions'])
except (InstaloaderException, KeyError, IndexError) as err:
self._context.error(f"Unable to fetch high-quality video version of {self}: {err}")
return version_urls[0]
else:
version_urls = list(dict.fromkeys(version_urls))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to remove duplicates, right? It might be a little cleaner to use a set for version_urls rather than a list. It does not store the order of items, so we will loose the enumeration in the warning message "Video URL candidate 1/4 for ..."; but neither does list(dict.fromkeys(...)) ensure that the order is kept. But that's okay anyway, there is probably little value in printing the index of the URL that fails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is to remove duplicates. I prefer this way than set exactly because of the order preservation (even though not very important here), and IIRC since Py 3.5 dicts are ordered, so this operation will keep the order of items.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting, did not know that. Then it is fine. Thanks!

instaloader/structures.py Show resolved Hide resolved
@aandergr aandergr merged commit 470fc0d into instaloader:master Nov 12, 2021
@pafke2

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StoryVideo has no video_url field and thus causes KeyError when parsing
4 participants