Permalink
Browse files

Replace video id polling with channel at startup.

  • Loading branch information...
1 parent be821ae commit 85a150ffed62985de6155a3311c3ebb29dc70f97 @iopred committed Dec 10, 2016
Showing with 13 additions and 16 deletions.
  1. +1 −2 README.md
  2. +11 −3 cmd/bruxism/main.go
  3. +1 −11 youtube.go
View
@@ -69,8 +69,7 @@ To invite your bot to a server, visit: `https://discordapp.com/oauth2/authorize?
* `youtubeauth` - Exchanges the provided auth code for an oauth2 token.
* `youtubeconfig` - The filename for your YouTube OAuth client JSON. (Download JSON in Google Developers Console -> Credentials).
* `youtubetoken` - The filename to store the oauth2 token.
-* `youtubelivevideoids` - Comma separated list of video id's to poll.
-* `youtubelivechatids` - An additional comma separated list of YouTube Live Chat ID's to listen on. By default the bot listens to all the live broadcasts on the primary account.
+* `youtubelivechannelids` - Comma separated list of channel ids to poll.
* `discordtoken` - Sets the Discord token.
* `discordemail` - Sets the Discord account email.
* `discordpassword` - Sets the Discord account password.
View
@@ -37,7 +37,7 @@ var youtubeURL bool
var youtubeAuth string
var youtubeConfigFilename string
var youtubeTokenFilename string
-var youtubeLiveVideoIDs string
+var youtubeChannelIDs string
var youtubeInvitePort int
var discordToken string
var discordEmail string
@@ -61,7 +61,7 @@ func init() {
flag.StringVar(&youtubeAuth, "youtubeauth", "", "Exchanges the provided auth code for an oauth2 token.")
flag.StringVar(&youtubeConfigFilename, "youtubeconfig", "youtubeoauth2config.json", "The filename that contains the oauth2 config.")
flag.StringVar(&youtubeTokenFilename, "youtubetoken", "youtubeoauth2token.json", "The filename to store the oauth2 token.")
- flag.StringVar(&youtubeLiveVideoIDs, "youtubelivevideoids", "", "Comma separated list of video id's to poll.")
+ flag.StringVar(&youtubeChannelIDs, "youtubechannelids", "", "Comma separated list of channel ids to poll.")
flag.IntVar(&youtubeInvitePort, "youtubeinviteport", 7777, "The port to listen for invites.")
flag.StringVar(&discordToken, "discordtoken", "", "Discord token.")
flag.StringVar(&discordEmail, "discordemail", "", "Discord account email.")
@@ -109,7 +109,7 @@ func main() {
}
}, nil)
- youtube := bruxism.NewYouTube(youtubeURL, youtubeAuth, youtubeConfigFilename, youtubeTokenFilename, youtubeLiveVideoIDs)
+ youtube := bruxism.NewYouTube(youtubeURL, youtubeAuth, youtubeConfigFilename, youtubeTokenFilename)
err := youtube.Init()
if err != nil {
log.Fatal(err)
@@ -203,6 +203,14 @@ func main() {
// Start all our services.
bot.Open()
+ if youtubeChannelIDs != "" {
+ channelIDs := strings.Split(youtubeChannelIDs, ",")
+
+ for _, channelID := range channelIDs {
+ ytip.Monitor(channelID)
+ }
+ }
+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
channel := r.FormValue("channel")
if channel != "" {
View
@@ -98,7 +98,6 @@ type YouTube struct {
auth string
configFilename string
tokenFilename string
- liveVideoIDs string
config *oauth2.Config
token *oauth2.Token
Client *http.Client
@@ -113,13 +112,12 @@ type YouTube struct {
}
// NewYouTube creates a new YouTube service.
-func NewYouTube(url bool, auth, configFilename, tokenFilename, liveVideoIDs string) *YouTube {
+func NewYouTube(url bool, auth, configFilename, tokenFilename string) *YouTube {
return &YouTube{
url: url,
auth: auth,
configFilename: configFilename,
tokenFilename: tokenFilename,
- liveVideoIDs: liveVideoIDs,
messageChan: make(chan Message, 200),
InsertChan: make(chan interface{}, 200),
DeleteChan: make(chan interface{}, 200),
@@ -366,14 +364,6 @@ func (yt *YouTube) Open() (<-chan Message, error) {
yt.pollBroadcasts(yt.Service.LiveBroadcasts.List("id,snippet,status,contentDetails").Mine(true).BroadcastType("all").Do())
- if yt.liveVideoIDs != "" {
- liveVideoIDsArray := strings.Split(yt.liveVideoIDs, ",")
-
- for _, liveVideoID := range liveVideoIDsArray {
- yt.Join(liveVideoID)
- }
- }
-
// Start a goroutine to handle all requests.
go yt.handleRequests()

0 comments on commit 85a150f

Please sign in to comment.