alexmercerind/youtube-search-python

Youtube hashtag search

Closed this issue · 10 comments

Youtube has this hashtag search this year: https://support.google.com/youtube/answer/6390658?hl=en
Could this feature be added in the near future?
Thanks!

I'm working on it. I will make a Pull Request as soon as I'm done with the asynchronous version & docs.

The problem is that we can't just get a list of videos with any hashtag. We need a special parameter called params, which we can get when searching. HashtagVideos makes a quick search query before making a request for actual videos parsing.

@meigaoms this should work now. Wait for the next release or, if you want to try it now, install the latest commit using:

pip install https://github.com/alexmercerind/youtube-search-python/archive/refs/heads/main.zip

Usage example:

from youtubesearchpython import Hashtag
hashtag = Hashtag('ncs', limit = 1)
print(hashtag.result())
mytja commented

Closing this issue... Huge thanks to @raitonoberu

@mytja I'm lazy to document the release. Just bumped the version & hopefully it will be published with your CI.

Thank you very much for the prompt response.
When I call hashtag.next() in a while loop, it prompt an error "Exception: ERROR: Could not parse YouTube response."
A simple loop to reproduce is:
while True:
hashtag.next()

I did a little research. The fact is that usually, if the response contains a continuationKey, then there are videos on the next page. But here, for some reason, there may simply be no results on the last page (sometimes). The most interesting thing is that YouTube itself does not know how to process this and shows an endless loading indicator.

I think I will make a hotfix soon.

Done. If you want to get all the pages, make your loop like this:

s = Hashtag("ncs")
while s.next():
    print(s.result()["result"][0]["title"])

Let us know if you find any issues.

@raitonoberu Using the code you suggested with a slight change with the limit.

hashtag = Hashtag('ncs', limit = 100) 
while hashtag.next(): 
    print(hashtag.result()["result"][0]["title"])

The first time I run this snippet. Everything looks good. But when I run it again and again, I got an exception, as you can see the last line below.

Top 10 NCS - Trance / Deep & Progressive Mix (No Copyright Songs)
Ranking February 2021 NCS Songs
Krakn - Aurora [NCS 1 HOUR]
RARE NGC and NCS Grading Results and Unboxing!
Panda Eyes - Colorblind [NCS Fanmade]
Jensation - Delicious [NCS Release]
TOP 10 BEST NCS SONGS FOR GAMING AND MONTAGES || PUBG/FREEFIRE/CODM || NON COPYRIGHT MUSIC.
Coopex,  EBEN, Shiah Maisel - Ruined My Life [NCS Release]
Exception: ERROR: Could not parse YouTube response.

@meigaoms Please make sure that you have installed the latest commit with

pip install https://github.com/alexmercerind/youtube-search-python/archive/refs/heads/main.zip

The PyPI release does not contain the fixes yet.

It works well now. It turned out my upgrade was unsuccessfully previously.
Thank you @raitonoberu .