Пример #1
0
 def __init__(self, config):
     self.config = config
     self.tirc = twitch_chat(config['twitch_username'],
                             config['twitch_oauth'],
                             [config['twitch_channel']],
                             config['client_id'])
     self.tirc.subscribeChatMessage(self.new_twitchmessage)
     self.chatId = get_live_chat_id_for_stream_now('oauth_creds')
     self.ytchat = YoutubeLiveChat('oauth_creds', [self.chatId])
     self.ytchat.subscribe_chat_message(self.new_ytmessage)
Пример #2
0
class Chatmirror(object):
    def __init__(self, config):
        self.config = config
        self.tirc = twitch_chat(config['twitch_username'],
                                config['twitch_oauth'],
                                [config['twitch_channel']],
                                config['client_id'])
        self.tirc.subscribeChatMessage(self.new_twitchmessage)
        self.chatId = get_live_chat_id_for_stream_now('oauth_creds')
        self.ytchat = YoutubeLiveChat('oauth_creds', [self.chatId])
        self.ytchat.subscribe_chat_message(self.new_ytmessage)

    def start(self):
        self.ytchat.start()
        self.tirc.start()

    def join(self):
        self.tirc.join()

    def stop(self):
        self.tirc.stop()
        self.ytchat.stop()

    def new_ytmessage(self, msgs, chat_id):
        for msg in msgs:
            to_send = u"{0} : {1}".format(msg.author.display_name,
                                          msg.message_text)
            logger.debug(to_send)
            self.tirc.send_message(config['twitch_channel'], to_send)

    def new_twitchmessage(self, msg):
        uname = msg['display-name'] or msg['username']
        to_send = "{0} : {1}".format(uname, msg['message'])
        logger.debug(to_send)
        self.ytchat.send_message(to_send, self.chatId)
Пример #3
0
#!/usr/bin/env python

from time import sleep

from youtubechat import YoutubeLiveChat, get_live_chat_id_for_stream_now

livechat_id = get_live_chat_id_for_stream_now("oauth_creds")
chat_obj = YoutubeLiveChat("oauth_creds", [livechat_id])


# msg in this case is a LiveChatMessage object defined in ytchat.py
def respond(msgs, chatid):
    for msg in msgs:
        print(f"NEW MESSAGE: {msg.published_at} | {msg}")
        #print(msg)
        #msg.delete()
        #chat_obj.send_message("RESPONSE!", chatid)


try:
    chat_obj.start()
    chat_obj.subscribe_chat_message(respond)
    chat_obj.join()

finally:
    chat_obj.stop()
Пример #4
0
#!/usr/bin/env python

from time import sleep
import sys
import json
import re

from youtubechat import YoutubeLiveChat, get_live_chat_id_for_broadcast_id, get_live_chat_id_for_stream_now

getStringWithDecodedUnicode = lambda str: re.sub('\\\\u([\da-f]{4})', (
    lambda x: chr(int(x.group(1), 16))), str)

#Input FilePath of "oauth_creds", "broadcastid"
FILE_PATH = 'D:/@University/team-12-final/'

f = open(FILE_PATH + "broadcastid", "r")

broadcast_id = f.read()
print(broadcast_id)

livechat_id = get_live_chat_id_for_broadcast_id(broadcast_id,
                                                FILE_PATH + "oauth_creds")
print(livechat_id)

chat_obj = YoutubeLiveChat(FILE_PATH + "oauth_creds", [livechat_id])
f = open(FILE_PATH + "chatdata.json", "w")

dataaa = chat_obj.livechat_api.get_all_messages(livechat_id)
dataaa = json.dumps(dataaa)
f.write(dataaa)
f.close()
Пример #5
0
 tirc = twitch_chat(config['twitch_username'], config['twitch_oauth'], config['twitch_channels'],
                    config['client_id'])
 tirc.subscribeChatMessage(console.new_twitchmessage)
 tirc.subscribeNewSubscriber(console.new_subscriber)
 ytchat = None
 if 'youtube_enabled' in config:
     if config['youtube_enabled']:
         console.display_message("Grabbing youtube chat id")
         chatId = None
         if args.testyoutube:
             from youtubechat import get_top_stream_chat_ids
             chatId = get_top_stream_chat_ids("oauth_creds")[0]
         else:
             chatId = get_live_chat_id_for_stream_now('oauth_creds')
         console.display_message("Loading youtube chat handler")
         ytchat = YoutubeLiveChat('oauth_creds', [chatId])
         ytchat.subscribe_chat_message(console.new_ytmessage)
 if 'ignored_users' in config:
     for user in config['ignored_users']:
         console.ignore_user(user)
 try:
     console.display_message("Loading complete, awaiting messages")
     console.start()
     thandler.start()
     tirc.start()
     if ytchat:
         ytchat.start()
     while True:
         time.sleep(0.1)
         if pygame.display.get_init():
             pygame.event.pump()
Пример #6
0
#!/usr/bin/env python

from time import sleep

from youtubechat import YoutubeLiveChat, get_live_chat_id_for_stream_now

livechat_id = get_live_chat_id_for_stream_now("oauth_creds")
chat_obj = YoutubeLiveChat("oauth_creds", [livechat_id])


def respond(msgs, chatid):
    for msg in msgs:
        print(msg)
        msg.delete()
        chat_obj.send_message("RESPONSE!", chatid)


try:
    chat_obj.start()
    chat_obj.subscribe_chat_message(respond)
    chat_obj.join()

finally:
    chat_obj.stop()