Skip to content

Commit

Permalink
👽️ Workaround for 404 avatars
Browse files Browse the repository at this point in the history
- sometimes the rss feed channel_id is missing 'UC'
  • Loading branch information
essembeh committed Nov 7, 2023
1 parent 23edc61 commit 537e1f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions tests/test_youtube.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from yourss.model import RssFeed
from yourss.youtube import (
YoutubeScrapper,
youtube_get_metadata,
youtube_get_rss_feed,
yt_home_url,
yt_html_get,
Expand Down Expand Up @@ -62,3 +63,9 @@ def test_slug_metadata():
== "https://www.youtube.com/channel/UCa_Dlwrwv3ktrhCy91HpVRw"
)
assert metadata.avatar_url is not None

def test_avatar():
metadata = youtube_get_metadata("@jonnygiger")
assert metadata is not None
print(">>>>>>>>>>>>>>", metadata.avatar_url)
assert metadata.avatar_url is not None
6 changes: 4 additions & 2 deletions yourss/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ def title(self) -> str:
@property
def channel_id(self) -> str:
node = checknode(self.root.find("./yt:channelId", namespaces=NAMESPACES))
if node.text is not None:
return node.text
if (out := node.text) is not None:
# workaround, sometime channel id does not start with UC
if out.startswith("UC"):
return out
# no channel id, parse the url to retrieve it
params = parse_qs(urlparse(self.url).query)
channel_id = params.get("channel_id")
Expand Down

0 comments on commit 537e1f0

Please sign in to comment.