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

Add more info from youtube. #62

Open
SurajBhari opened this issue May 5, 2024 · 1 comment
Open

Add more info from youtube. #62

SurajBhari opened this issue May 5, 2024 · 1 comment

Comments

@SurajBhari
Copy link
Contributor

currently get_video only returns "videoPrimaryInfoRenderer" part from "ytInitialData". although for some other applications having "ytInitialPlayerResponse" would be useful. like storyboards thumbnails.

def get_video(
    id: str,
) -> dict:

    """Get a single video.

    Parameters:
        id (``str``):
            The video id from the video you want to get.
    """

    session = get_session()
    url = f"https://www.youtube.com/watch?v={id}"
    html = get_initial_data(session, url)
    client = json.loads(
        get_json_from_html(html, "INNERTUBE_CONTEXT", 2, '"}},') + '"}}'
    )["client"]
    session.headers["X-YouTube-Client-Name"] = "1"
    session.headers["X-YouTube-Client-Version"] = client["clientVersion"]
    data = json.loads(
        get_json_from_html(html, "var ytInitialData = ", 0, "};") + "}"
    )
    ytInitialPlayerResponse = json.loads(
        get_json_from_html(html, "var ytInitialPlayerResponse = ", 0, "};") + "}"
    )
    returning = next(search_dict(data, "videoPrimaryInfoRenderer"))
    returning['ytInitialPlayerResponse'] = ytInitialPlayerResponse
    return returning

something like this would be appreciated.

@SurajBhari
Copy link
Contributor Author

forgot to mention. it should also do similar on get_videos too

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

No branches or pull requests

1 participant