youtube icon indicating copy to clipboard operation
youtube copied to clipboard

Banner image is not taken into account

Open Popolechien opened this issue 1 year ago • 6 comments

Looking at several of our latest Youtube channels I see that the banner image is never included in the corresponding zim file.

See, e.g.:

Youtube Zim
S2 Underground YT S2 zim
Voice of America YT VoA zim
Canadian prepper YT Canadian prepper ZIM
Astrolabe YT Astrolabe zim

Edit: this happens both when an entire channel or playlists within a channel are selected.

Popolechien avatar Sep 23 '24 08:09 Popolechien

Thank you for reporting, this is indeed a problem.

benoit74 avatar Sep 23 '24 09:09 benoit74

This is in fact "normal" behavior, see https://github.com/openzim/youtube/blob/0b9bed587f5a2cb890d272aee848b89cb2fb5fe8/CHANGELOG#L137-L139

We can have a look again whether google changed again the API and we can retrieve the banner again.

benoit74 avatar Sep 23 '24 11:09 benoit74

Unfortunately Google's API hasn't still changed to support retrieving banners again. As an alternative we could use something like BeautifulSoup to scrape the banner link off a channel and use it. I tested it with the code below:

import requests
from bs4 import BeautifulSoup
import json

channel_url = "https://www.youtube.com/@danasherniles"
response = requests.get(channel_url)
soup = BeautifulSoup(response.content, 'html.parser')

for script in soup.find_all("script"):
    if 'ytInitialData' in script.text:
        json_data = json.loads(script.text.split(' = ')[1].rstrip(';'))
        banner_url = json_data["header"]["pageHeaderRenderer"]["content"]["pageHeaderViewModel"]["banner"]["imageBannerViewModel"]["image"]["sources"][-1]["url"]
        print(banner_url)
        break

dan-niles avatar Sep 24 '24 14:09 dan-niles

Is this really worth it? I'm not against this, but it does look a bit fragile. And setting the banner image manually is not "that hard", so probably not the most priority issue to solve. That being said, I'm not against someone proposing a PR on this issue, just wondering which focus we should put on this issue.

benoit74 avatar Sep 26 '24 11:09 benoit74

Is this really worth it? I'm not against this, but it does look a bit fragile. And setting the banner image manually is not "that hard", so probably not the most priority issue to solve. That being said, I'm not against someone proposing a PR on this issue, just wondering which focus we should put on this issue.

Yes, fragile... but seems to be the best we can do... and the banner is pretty important!

kelson42 avatar Oct 01 '24 12:10 kelson42

This will come back with move to full yt-dlp in fact (see #177), yt-dlp nicely provides the banner.

benoit74 avatar Nov 04 '24 21:11 benoit74