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

[FR] Search #1001

Closed
JuniorJPDJ opened this issue May 24, 2021 · 12 comments · Fixed by #1030
Closed

[FR] Search #1001

JuniorJPDJ opened this issue May 24, 2021 · 12 comments · Fixed by #1030

Comments

@JuniorJPDJ
Copy link

JuniorJPDJ commented May 24, 2021

It would be cool to have some sort of youtube search (videos/playlists) API in pytube.

@github-actions
Copy link

Thank you for contributing to PyTube. Please remember to reference Contributing.md

@JarbasAl
Copy link
Contributor

i will port the code from https://github.com/HelloChatterbox/youtube_searcher over to this repo

@tfdahlin
Copy link
Collaborator

I'm working on this feature now. Expect search functionality to be added soon.

@tfdahlin tfdahlin linked a pull request Jun 23, 2021 that will close this issue
@tfdahlin
Copy link
Collaborator

I think I have the functionality written, feel free to test out the branch I created. It currently only supports video search results, but at a future point in time it could also probably support playlist results fairly easily. I don't plan to merge this for at least a little while so that I can make sure it works how I want it too, to add documentation for the new feature, and to make sure there's nothing else I want to bundle with the update. However, you're welcome to try out the development branch for it in my fork

@JuniorJPDJ
Copy link
Author

@Mrkazik99

@Pacifist2503
Copy link

Please tell me how to stop the download? Is there a special method?

@tfdahlin
Copy link
Collaborator

tfdahlin commented Jul 3, 2021

What do you mean by stopping the download?

@Pacifist2503
Copy link

What do you mean by stopping the download?

Now YouTube limits the download speed if you download, for example, a playlist. If the speed drops a lot, then I want to programmatically stop rutube.YouTube(url).streams.first().download(). Is there a method for this?

@tfdahlin
Copy link
Collaborator

tfdahlin commented Jul 3, 2021

One way you could do this is by adjusting the default download chunk size to be smaller, and using an on_progress_callback. For example:

import pytube

pytube.request.default_range_size = 524288  # 0.5MB

def progress_func(data_chunk, bytes_remaining):
    # Check when last called and raise an exception here
    ...

p = Playlist(url)
for url in p.video_urls:
    video = YouTube(url, on_progress_callback=progress_func)
    video.streams.first().download()

@Pacifist2503
Copy link

One way you could do this is by adjusting the default download chunk size to be smaller, and using an on_progress_callback. For example:

import pytube

pytube.request.default_range_size = 524288  # 0.5MB

def progress_func(data_chunk, bytes_remaining):
    # Check when last called and raise an exception here
    ...

p = Playlist(url)
for url in p.video_urls:
    video = YouTube(url, on_progress_callback=progress_func)
    video.streams.first().download()

Will this help solve the problem with the YouTube speed limit?

@tfdahlin
Copy link
Collaborator

tfdahlin commented Jul 3, 2021

No; i'm working on trying to fix the problem with the speed limit. If you want to test it, you can try using this experimental branch that I just got working this morning, but haven't had the chance to test extensively.

@Pacifist2503
Copy link

pytube.request.default_range_size = 524288 # 0.5MB
This method helped solve the YouTube speed limit. Thanks!

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

Successfully merging a pull request may close this issue.

4 participants