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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[extractor/TwitCasting] fix: Use UserNotLive #7975

Merged
merged 6 commits into from Sep 21, 2023

Conversation

at-wat
Copy link
Contributor

@at-wat at-wat commented Aug 28, 2023

IMPORTANT: PRs without the template will be CLOSED

Description of your pull request and other information

Running yt-dlp with --wait-for-video option for TwitCastingLive URL results an error:

$ yt-dlp --wait-for-video=30 https://twitcasting.tv/channel_name
[TwitCastingLive] Extracting URL: https://twitcasting.tv/channel_name
[TwitCastingLive] Downloading live video of user channel_name. Pass "https://twitcasting.tv/channel_name/show" to download the history
[TwitCastingLive] channel_name: Downloading webpage
[TwitCastingLive] channel_name: Downloading live history
ERROR: [TwitCastingLive] channel_name: The user is not currently live; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
$

This is caused since class TwitCastingLiveIE raises ExtractorError instead of UserNotLive when the channel is currently not live.

This PR fixes TwitCastingIE to raise UserNotLive when the channel isn't live.
--wait-for-video option for TwitCasting works with this branch as below:

$ yt-dlp --wait-for-video=30 https://twitcasting.tv/channel_name
[TwitCastingLive] Extracting URL: https://twitcasting.tv/channel_name
[TwitCastingLive] Downloading live video of user channel_name. Pass "https://twitcasting.tv/channel_name/show" to download the history
[TwitCastingLive] channel_name: Downloading webpage
[TwitCastingLive] channel_name: Downloading live history
WARNING: [TwitCastingLive] channel_name: The channel is not currently live
[wait] Waiting for 00:00:30 - Press Ctrl+C to try now
[wait] Remaining time until next attempt: 00:00:22

Added a test case to check the raised exception against a dummy TwitCasting account which won't be live.

$ python test/test_download.py TestDownload.test_TwitCastingLive_all
[debug] Loaded 1864 extractors
[TwitCastingLive] Extracting URL: https://twitcasting.tv/c:unusedlive
[TwitCastingLive] Downloading live video of user c:unusedlive. Pass "https://twitcasting.tv/c:unusedlive/show" to download the history
[TwitCastingLive] c:unusedlive: Downloading webpage
[TwitCastingLive] c:unusedlive: Downloading live history
ERROR: [TwitCastingLive] c:unusedlive: The channel is not currently live
  File "/home/at-wat/Downloads/yt-dlp/yt_dlp/extractor/common.py", line 715, in extract
    ie_result = self._real_extract(url)
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/at-wat/Downloads/yt-dlp/yt_dlp/extractor/twitcasting.py", line 267, in _real_extract
    raise UserNotLive(video_id=uploader_id)

.
----------------------------------------------------------------------
Ran 1 test in 0.487s

OK
$ 
Template

Before submitting a pull request make sure you have:

In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check all of the following options that apply:

  • 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?

Copilot Summary

馃 Generated by Copilot at 48e7bb8

Summary

馃И馃毃馃帴

This pull request enhances the testing and error handling of test_download and twitcasting modules. It adds support for testing expected exceptions in test_download and raises a specific exception for non-live streams in twitcasting.

YoutubeDLError is the sign of doom
We skip the tests that seal our fate
UserNotLive is the curse we loom
We raise the exception and test our hate

Walkthrough

  • Import YoutubeDLError and UserNotLive exceptions from yt_dlp.utils (link, link)
  • Add and modify test cases for TwitCastingLiveIE extractor to expect UserNotLive exception when user is not live (link, link)
  • Raise UserNotLive exception in TwitCastingLiveIE._real_extract method when current_live value is missing from webpage (link)
  • Add helper method to check if raised exception matches expected exception in test function (link)
  • Call helper method in except blocks and return or re-raise exception accordingly in test function (link, link)

To make --wait-for-video work.
@bashonly bashonly added enhancement New feature or request site-bug Issue with a specific website labels Aug 29, 2023
Copy link
Member

@pukkandan pukkandan left a comment

Choose a reason for hiding this comment

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

LGTM. But the core and extractor changes should be merged in separate commits

test/test_download.py Outdated Show resolved Hide resolved
test/test_download.py Outdated Show resolved Hide resolved
test/test_download.py Outdated Show resolved Hide resolved
test/test_download.py Outdated Show resolved Hide resolved
test/test_download.py Outdated Show resolved Hide resolved
@bashonly bashonly merged commit c1d71d0 into yt-dlp:master Sep 21, 2023
16 checks passed
aalsuwaidi pushed a commit to aalsuwaidi/yt-dlp that referenced this pull request Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request site-bug Issue with a specific website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants