Closed NannoSilver closed 2 weeks ago
I'll upload a branch with a possible fix, if you can test it, I'd appreciate it.
in my tests:
>>> from pytubefix import Channel
>>>
>>>
>>> urls = {
... "url1": "https://www.youtube.com/joerogan",
... "url2": "https://www.youtube.com/c/joerogan",
... "url3": "https://www.youtube.com/@joerogan"
... }
>>>
>>>
>>> for key, url in urls.items():
... c = Channel(url)
... print(f'Channel name: {c.channel_name}')
...
Channel name: PowerfulJRE
Channel name: PowerfulJRE
Channel name: PowerfulJRE
>>>
is now available in the "channel" branch
Seems it is working properly.
I installed the branch at pycharm with the command:
pip install https://github.com/JuanBindez/pytubefix/archive/channel.zip
Pytubefix was updated to version 7.4.0.
Tested code:
from pytubefix import Channel
url = 'https://www.youtube.com/joerogan'
c = Channel(url)
print(c.channel_name)
Outcome:
PowerfulJRE
Process finished with exit code 0
I tested a few other Youtube channels as well, and all worked well.
It seems so, I'll do more tests later to see if everything is correct.
Although YouTube supports channel urls without the '@', some names can generate bugs
Example:
from pytubefix.contrib.channel import Channel
c = Channel('https://www.youtube.com/null')
print(c.channel_name)
print(c.videos)
null
[]
from pytubefix.contrib.channel import Channel
c = Channel('https://www.youtube.com/@null')
print(c.channel_name)
print(c.videos)
null
[<pytubefix.__main__.YouTube object: videoId=kqeOjDEchlo>, <pytubefix.__main__.YouTube object: videoId=M6ZjMWLqJvM>, <pytubefix.__main__.YouTube object: videoId=9SjHLau-DWE>, <pytubefix.__main__.YouTube object: videoId=KvkNPCCLyVk>, <pytubefix.__main__.YouTube object: videoId=BbHsxrYzdIg>]
Others, for example, cause:
from pytubefix.contrib.channel import Channel
c = Channel('https://www.youtube.com/None')
print(c.channel_name)
print(c.videos)
urllib.error.HTTPError: HTTP Error 404: Not Found
from pytubefix.contrib.channel import Channel
c = Channel('https://www.youtube.com/@None')
print(c.channel_name)
print(c.videos)
None
[<pytubefix.__main__.YouTube object: videoId=o1RZIxzEFPI>, <pytubefix.__main__.YouTube object: videoId=VU_0OQ51kuc>, <pytubefix.__main__.YouTube object: videoId=JG9cyL5FW90>, <pytubefix.__main__.YouTube object: videoId=jikRvNK0LKc>, <pytubefix.__main__.YouTube object: videoId=qc1ArRy3j8I>, <pytubefix.__main__.YouTube object: videoId=P0nfuhazyt0>, <pytubefix.__main__.YouTube object: videoId=_jBeDtT080s>, <pytubefix.__main__.YouTube object: videoId=RfYU_PX9DBs>, <pytubefix.__main__.YouTube object: videoId=7zRUmcFN-Xc>, <pytubefix.__main__.YouTube object: videoId=7-mgU3wzEsg>, <pytubefix.__main__.YouTube object: videoId=8HfzI6Dhpgw>, <pytubefix.__main__.YouTube object: videoId=qOmZY6YzEXM>, <pytubefix.__main__.YouTube object: videoId=gypDP4n1Ddo>, <pytubefix.__main__.YouTube object: videoId=dljOGm0x6Uo>, <pytubefix.__main__.YouTube object: videoId=I6h81Uy4mK4>, <pytubefix.__main__.YouTube object: videoId=ibwu3osov6I>, <pytubefix.__main__.YouTube object: videoId=xm9CD3wEm6w>, <pytubefix.__main__.YouTube object: videoId=ccQ2CANWAyw>, <pytubefix.__main__.YouTube object: videoId=SpHWz_cqvfk>, <pytubefix.__main__.YouTube object: videoId=wRLd3HU7aFg>, <pytubefix.__main__.YouTube object: videoId=_TA_lBYsZog>, <pytubefix.__main__.YouTube object: videoId=mhkGkkdGybU>, <pytubefix.__main__.YouTube object: videoId=8ZFTwgP94o0>, <pytubefix.__main__.YouTube object: videoId=v1fZ2mYn1E4>, <pytubefix.__main__.YouTube object: videoId=uKvQUuM4eCo>, <pytubefix.__main__.YouTube object: videoId=hmhvv73MTfU>, <pytubefix.__main__.YouTube object: videoId=27oBFGhFfUs>, <pytubefix.__main__.YouTube object: videoId=ID15D1Wz2bA>, <pytubefix.__main__.YouTube object: videoId=gaek_48LhtY>, <pytubefix.__main__.YouTube object: videoId=xNjeWaTGrl4>, <pytubefix.__main__.YouTube object: videoId=t1iGRIMljIY>, <pytubefix.__main__.YouTube object: videoId=3TbngrUGE6I>, <pytubefix.__main__.YouTube object: videoId=qTWkTSZHXik>, <pytubefix.__main__.YouTube object: videoId=cZAdWzpExgk>, <pytubefix.__main__.YouTube object: videoId=BTiH7yK2n3Y>, <pytubefix.__main__.YouTube object: videoId=rQwZ2RZrSb8>, <pytubefix.__main__.YouTube object: videoId=tw7k_CzBAmU>, <pytubefix.__main__.YouTube object: videoId=fgTGjXl4duo>]
These are just basic examples, some urls can even redirect to other channels with the same name. So although YouTube supports urls without '@', I believe that now would not be the right time to implement.
I took tests yesterday and thought the same
After adopt the "@" to designate channels URLs, seems Youtube is allowing an additional scheme.
The new scheme is similar to the one with @ but without the @.
Here is an example:
Former channel URL scheme: https://www.youtube.com/c/joerogan URL scheme with @: https://www.youtube.com/@joerogan
New scheme: https://www.youtube.com/joerogan