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

How to get a broadcastId for someone else's stream? #14

Open
dmikushin opened this issue Mar 3, 2021 · 3 comments
Open

How to get a broadcastId for someone else's stream? #14

dmikushin opened this issue Mar 3, 2021 · 3 comments

Comments

@dmikushin
Copy link

Thank you for this great library! I'm wondering how do I determine what should I set for the first argument of get_live_chat_id_for_broadcast_id() call for someone's stream? The stream URL is known.

@dmikushin dmikushin changed the title How to get a boradcastId for someone else's stream? How to get a broadcastId for someone else's stream? Mar 3, 2021
@DamirLut
Copy link

Were you able to get it? I now faced the same problem, I cannot find the broadcastId for one stream.

@wvthoog
Copy link

wvthoog commented Jul 7, 2021

How do you mean someone else's stream. The way this works is oath_creds grants the permission for one specific Youtube account. I have two accounts. The first one is my own account en the second account i've created is for my chatbot. Created two oauth_creds files (oath_cred-main en oauth_creds-bot) and granted the bot moderator rights for live chat messages. Broadcast ID is pulled from oauth_creds-main and the chat_obj uses oauth_creds-bot. Like so

livechat_id = get_live_chat_id_for_broadcast_id(broadcast_id,'oauth_creds-main')
chat_obj = YoutubeLiveChat('oauth_creds-bot', [livechat_id])

@bigsby-exe
Copy link

I modified some of the existing functions in ytchat.py to get the Live Chat ID from a channel ID. They are a bit heavy on the API calls as it uses the /search/ endpoint but as long as you don't call it too much it should be ok.

I am pretty new to Python so please excuse some of the mess but I am open to suggestions on how to make it better.

def get_liveid(cid):
    url = "https://www.googleapis.com/youtube/v3/search?"
    params = {'part': 'snippet', 'channelId': cid, 'maxResults': 1,
              'order': 'date', 'eventType': 'live', 'type': 'video'}
    params = urlencode(params)
    uri = (url + params)
    method = 'GET'

    resp, content = http.request(uri, method, headers=None, body=None)
    content_type, content_type_params = cgi.parse_header(resp.get('content-type', 'application/json; charset=UTF-8'))
    charset = content_type_params.get('charset', 'UTF-8')
    data = loads(content.decode(charset))

    if data['pageInfo']['totalResults'] == 0:
        print("No streams found")
    else:
        video_id = data['items'][0]['id']['videoId']
        return video_id


def get_livechatid(video_id):
    url = "https://youtube.googleapis.com/youtube/v3/videos?"
    params = {'part': 'liveStreamingDetails', 'id': video_id}
    params = urlencode(params)
    uri = (url + params)
    method = 'GET'

    resp, content = http.request(uri, method, headers=None, body=None)
    content_type, content_type_params = cgi.parse_header(resp.get('content-type', 'application/json; charset=UTF-8'))
    charset = content_type_params.get('charset', 'UTF-8')
    data = loads(content.decode(charset))

    live_chat_id = data['items'][0]['liveStreamingDetails']['activeLiveChatId']

    return live_chat_id

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

4 participants