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

[Eporner] Check if video was deleted #33051

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Holek
Copy link

@Holek Holek commented Feb 7, 2025

Please follow the guide below

  • You will be asked some questions, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your pull request (like that [x])
  • Use Preview tab to see how your pull request will actually look like

Before submitting a pull request make sure you have:

In order to be accepted and merged into youtube-dl each piece of code must be in public domain or released under Unlicense. Check one of the following options:

  • I am the original author of this code and I am willing to release it under Unlicense
  • I am not the original author of this code but it is in public domain or released under Unlicense (provide reliable evidence)

What is the purpose of your pull request?

  • Bug fix
  • Improvement
  • New extractor
  • New feature

This change gives user a friendly error message, instead of a stacktrace. I couldn't find examples for tests of deleted videos. All of them I found had skip_video flag set, so that's not what I wanted.

If you point me to an example that has this test, I'll gladly add it to the test matrix for this site.

This gives user a friendly error message, instead of a stacktrace
Comment on lines +62 to +65
deleted = self._html_search_regex(r'<strong>Video has been deleted</strong>', webpage, 'deleted', default=False, fatal=False, group=0)
if deleted:
raise ExtractorError(
'Video %s has been deleted' % video_id, expected=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Partly a matter of taste, but this arrangement could be extended to other error cases by adding to the tuple of error message patterns. It's better then to use the default search for group 1 -- default=None is all that's needed to silence the "not found" case; and the pattern can be relaxed in case the HTML gets split up (I didn't make each space a \s+ which might be logical):

Suggested change
deleted = self._html_search_regex(r'<strong>Video has been deleted</strong>', webpage, 'deleted', default=False, fatal=False, group=0)
if deleted:
raise ExtractorError(
'Video %s has been deleted' % video_id, expected=True)
missing = self._html_search_regex((
r'<strong>\s*(Video has been deleted)\s*</strong>',
), webpage, 'missing', default=None)
if missing:
raise ExtractorError(
'Video %s is not available: "%s"' % (video_id, missing), expected=True)

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.

2 participants