Skip to content

Support for Live Broadcasts - #462

Merged
kangkyu merged 1 commit into
claudiob:masterfrom
gmarziou:LiveBroadcasts
Jul 30, 2026
Merged

Support for Live Broadcasts#462
kangkyu merged 1 commit into
claudiob:masterfrom
gmarziou:LiveBroadcasts

Conversation

@gmarziou

Copy link
Copy Markdown
Contributor

This PR implements LiveBroadcast resource and collection.

To create a alive broadcast:

    params = {
      title: title, description: description, privacy_status: privacy_status,
      scheduled_start_time: scheduled_start_time, scheduled_end_time: scheduled_end_time,
      default_language: "en"
    }
    account.create_live_broadcast(**params)

To list all live broadcasts of an account/channel:

account(email).live_broadcasts

Fix #461

@kangkyu

kangkyu commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

@gmarziou thank you for opening a pr! I will try and get back to you

@kangkyu kangkyu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params and body can be handled differently, I think we can use more existing methods. For example:

def insert_params
  super.tap {|p| p[:part] = "snippet,status"}
end

Comment thread lib/yt/models/account.rb Outdated
Comment thread lib/yt/models/account.rb Outdated
Comment on lines +60 to +64
def insert_parts
snippet = {keys: [:title, :description], sanitize_brackets: true}
status = {keys: [:privacy_status]}
{snippet: snippet, status: status}
end

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might have wanted to use insert_parts in insert method in this class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit that I did not understand how this worked in other classes.
I looked at other collections and they seemed to use slightly different patterns.

Could you point me to a class that is a good example that I could study?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. @gmarziou

I was wondering if this part could be used and simplify insert method above, how do you think? If you don't mind, could you please try something like following code, for me to learn more?

def insert_parts
  snippet = {keys: [:title, :description, :scheduled_start_time, :scheduled_end_time, :default_language], sanitize_brackets: true}
  status = {keys: [:privacy_status, :self_declared_made_for_kids]}
  {snippet: snippet, status: status}
end

Comment thread lib/yt/models/live_broadcast.rb Outdated
Comment on lines +35 to +37
def insert
do_insert
end

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this insert method may not be used.

@gmarziou
gmarziou force-pushed the LiveBroadcasts branch 2 times, most recently from 17ae0b1 to 57f5631 Compare July 24, 2026 15:51
@gmarziou

Copy link
Copy Markdown
Contributor Author

I think I applied your suggestions and tested, it works.
I will squash if it's better now.

@gmarziou

Copy link
Copy Markdown
Contributor Author

Oops, I found that maybe the issue could come from the fact that LiveBroadcasts inherits from Base while it should inherit from Resources

Could you explain why some classes use Base super class (e.g. LiveCuepoints) while some like Playlists use Resources?

@kangkyu

kangkyu commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

I think Resources have title and description for them. (Yes, that's why) If you prefer Base directly, then I think you may simply remove insert_parts from your code. Either way. I don't have a strong opinion that LiveBroadcast should be one of Resource here.

@gmarziou

gmarziou commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

When I use Resources as parent class for LiveBroadcasts, it simplifies the code but it fails to build a valid snippet part
for scheduled_start_time and scheduled_end_time which get nullified by Yt::Actions::Base#sanitize_brackets! because they are of type TimeWithZone.

      def sanitize_brackets!(source)
        case source
          when String then source.gsub('<', '‹').gsub('>', '›')
          when Array then source.map{|string| sanitize_brackets! string}
          when Hash then source.each{|k,v| source[k] = sanitize_brackets! v}
        end
      end

I think that sanitize_brackets! should left as-is the types it can't handle, I propose this change:

      def sanitize_brackets!(source)
        case source
          when String then source.gsub('<', '‹').gsub('>', '›')
          when Array then source.map{|string| sanitize_brackets! string}
          when Hash then source.each{|k,v| source[k] = sanitize_brackets! v}
          # Don't sanitize other types of objects
          else source
        end
      end

I tested it, it works fine for creating LiveBroadcasts.

@kangkyu kangkyu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

This PR implements LiveBroadcast resource and collection.

To create a alive broadcast:

```ruby
    params = {
      title: title, description: description, privacy_status: privacy_status,
      scheduled_start_time: scheduled_start_time, scheduled_end_time: scheduled_end_time,
      default_language: "en"
    }
    account.create_live_broadcast(**params)
 ```

To list all live broadcasts of an account/channel:

```ruby
account(email).live_broadcasts
```

Fix claudiob#461
@gmarziou

Copy link
Copy Markdown
Contributor Author

Great, I just squashed the 3 commits on my branch.

@kangkyu
kangkyu merged commit 86c2a11 into claudiob:master Jul 30, 2026
@gmarziou
gmarziou deleted the LiveBroadcasts branch July 30, 2026 22:05
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

Successfully merging this pull request may close these issues.

Support for LiveBroadcasts

2 participants