Guest User

Untitled

a guest
Aug 5th, 2025
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.60 KB | None | 0 0
  1. What I think is happening here is that you're mixing up the signal and the event.
  2.  
  3. Your code seems fine, it creates a broadcast, but nowhere in the code do you link it to the signal that the camera sends. So, you end up with a camera signal that goes to ingestion endpoint A, and then you've got the event (public-facing title, description, etc) which doesn't connect in any way to ingestion endpoint A (hope this makes sense).
  4.  
  5. I haven't used their API in ages, but there appears to be a bind you can use: https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/bind
  6.  
  7. This is their example python code:
  8.  
  9. # -*- coding: utf-8 -*-
  10.  
  11. # Sample Python code for youtube.liveBroadcasts.bind
  12. # See instructions for running these code samples locally:
  13. # https://developers.google.com/explorer-help/code-samples#python
  14.  
  15. import os
  16.  
  17. import google_auth_oauthlib.flow
  18. import googleapiclient.discovery
  19. import googleapiclient.errors
  20.  
  21. scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]
  22.  
  23. def main():
  24.     # Disable OAuthlib's HTTPS verification when running locally.
  25.     # *DO NOT* leave this option enabled in production.
  26.     os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
  27.  
  28.     api_service_name = "youtube"
  29.     api_version = "v3"
  30.     client_secrets_file = "YOUR_CLIENT_SECRET_FILE.json"
  31.  
  32.     # Get credentials and create an API client
  33.     flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
  34.         client_secrets_file, scopes)
  35.     credentials = flow.run_console()
  36.     youtube = googleapiclient.discovery.build(
  37.         api_service_name, api_version, credentials=credentials)
  38.  
  39.     request = youtube.liveBroadcasts().bind(
  40.         id="YOUR_BROADCAST_ID",
  41.         part="snippet",
  42.         streamId="YOUR_STREAM_ID"
  43.     )
  44.     response = request.execute()
  45.  
  46.     print(response)
  47.  
  48. if __name__ == "__main__":
  49.     main()
  50.  
  51. So, you'll have to add this as a new function, something like:
  52.  
  53. def bind_broadcast_to_stream(youtube, broadcast_id, stream_id):
  54.    request = youtube.liveBroadcasts().bind(
  55.        part="id,snippet,contentDetails,status",
  56.        id=broadcast_id,
  57.        streamId=stream_id
  58.    )
  59.    response = request.execute()
  60.    print(f"Broadcast {broadcast_id} has been bound to stream {stream_id}.")
  61.    return responsedef bind_broadcast_to_stream(youtube, broadcast_id, stream_id):
  62.    request = youtube.liveBroadcasts().bind(
  63.        part="id,snippet,contentDetails,status",
  64.        id=broadcast_id,
  65.        streamId=stream_id
  66.    )
  67.    response = request.execute()
  68.    print(f"Broadcast {broadcast_id} has been bound to stream {stream_id}.")
  69.    return response
Advertisement
Add Comment
Please, Sign In to add comment