Пример #1
0
class LiveChatStream:
    def __init__(self, video_id: str) -> None:
        self._livechat = LiveChat(video_id)

    def __enter__(self) -> LiveChatStream:
        return self

    def __exit__(self, *args) -> None:
        self.terminate()

    def terminate(self) -> None:
        self._livechat.terminate()

    def __call__(self) -> Iterator[Message]:
        while self._livechat.is_alive():
            for item in self.get():
                yield item

    def get(self) -> List[Message]:
        chatdata = self._livechat.get()
        chatlist = chatdata.items  # type: List[BaseRenderer]
        if chatlist:
            chatdata.tick()

        messages = [Message.from_renderer(x) for x in chatlist]
        return messages
Пример #2
0
def main():
    yt_url = get_stream_url()
    livechat = LiveChat(yt_url)
    hour_start = 19
    min_start = 30
    time_start = None
    time_chat = None
    count = 0
    limit = 100
    while livechat.is_alive():
        chatdata = livechat.get()
        for c in chatdata.items:
            if not bool(time_start):
                len_time = len(" 19:30:00")
                time_start = dt.datetime.strptime(c.datetime[:-len_time],
                                                  "%Y-%m-%d")
                time_start = time_start.replace(hour=hour_start,
                                                minute=min_start)
            time_chat = dt.datetime.strptime(c.datetime, "%Y-%m-%d %H:%M:%S")
            if time_chat >= time_start:
                print("{} [{}]- {}".format(c.datetime, c.author.name,
                                           c.message))
                count += 1
                print("count = {}".format(count))
            chatdata.tick()
            if count > limit:
                break
        if count > limit:
            break
Пример #3
0
class Pychat:
    def __init__(self, video, parser=YoutubeParser()):
        self.live_chat = LiveChat(video_id=video.id, processor=CompatibleProcessor())
        self._parser = parser

    def terminate(self):
        self.live_chat.terminate()

    def get_messages(self):
        return self._parser(self.live_chat.get())
def pipeYoutubeChat(activeYoutubeLink):
    livechat = LiveChat(activeYoutubeLink)
    while livechat.is_alive():
        try:
            chatdata = livechat.get()
            for c in chatdata.items:
                print(f"{c.datetime} [{c.author.name}]- {c.message}")
                requests.post(DISCORD_CHAT_WEBHOOK,
                              json={
                                  "content": c.message,
                                  "username": f"YT: {c.author.name}"
                              })
                chatdata.tick()
        except KeyboardInterrupt:
            livechat.terminate()
            break
    print("Terminated chat bridge.")
Пример #5
0
class collector(threading.Thread):
    def __init__(self, text, textor):
        super(collector, self).__init__()
        self.livechat = False
        self.program_running = True
        self.running = False
        self.text = textor

    def setlink(self, link):
        self.running = False
        if self.livechat: self.livechat.terminate()
        try:
            self.livechat = LiveChat(link)
            self.running = True
            self.text.settext('collecting\n > ' + link + '\n')
            return True
        except:
            print("link error")
            self.running = False
            return False

    def exit(self):
        if self.livechat: self.livechat.terminate()
        self.running = False
        self.program_running = False

    def run(self):
        while self.program_running:
            while self.running and self.livechat.is_alive():
                try:
                    self.chatdata = self.livechat.get()
                    for c in self.chatdata.items:
                        if not self.running: break
                        d = condition(c.message, c.author)
                        if d:
                            maintranslatoradd(c.author.name)
                            self.text.settext(d + '\n')
                        self.chatdata.tick()
                except KeyboardInterrupt:
                    self.livechat.terminate()
                    break
            time.sleep(0.1)
Пример #6
0
class collector(thr):
    def __init__(self):
        super(collector,self).__init__()
        self.livechat=False
        self.program_running=True
        self.running=False
        
        
    def setlink(self,link):
        if self.livechat:
            self.livechat.terminate()
        self.livechat = LiveChat(link)
        self.running=True

    def exit(self):
        self.livechat.terminate()
        self.running=False
        self.program_running=False

    def run(self):
        while self.program_running:
            while self.running and self.livechat.is_alive():
                try:
                    self.chatdata = self.livechat.get()
                    for c in self.chatdata.items:
                        if not self.running:break
                        d=condition(c.message,c.author)
                        if d:
                            maintranslatoradd(c.author.name)
                            print(f"[ >{c.author.name} ({maintranslator[c.author.name]})]")
                            print(d,end="\n\n")
                        self.chatdata.tick()
                except KeyboardInterrupt:
                    self.livechat.terminate()
                    break
                except Exception as e:
                    print(e)
                    break
            time.sleep(0.1)
Пример #7
0
class collector(threading.Thread):
    def __init__(self):
        super(collector,self).__init__()
        self.livechat=False
        self.program_running=True
        self.running=False
        # self.t=time.time()
        
    def setlink(self,link):
        if self.livechat:
            self.livechat.terminate()
        self.livechat = LiveChat(link)
        self.running=True

    def exit(self):
        self.livechat.terminate()
        self.running=False
        self.program_running=False

    def run(self):
        while self.program_running:
            while self.running:
                while self.livechat.is_alive():
                    if not self.program_running:
                        break
                    try:
                        try:self.chatdata = self.livechat.get()
                        except:break
                        for c in self.chatdata.items:
                            d=condition(c.message,c.author)
                            if d:
                                maintranslatoradd(c.author.name)
                                print(d)
                                text.insert(1.0,d)
                            self.chatdata.tick()
                    except KeyboardInterrupt:
                        self.livechat.terminate()
            time.sleep(0.1)
Пример #8
0
scope = [
    'https://spreadsheets.google.com/feeds',
    'https://www.googleapis.com/auth/drive'
]
creds = ServiceAccountCredentials.from_json_keyfile_name(
    'Spreadsheetapi-03009ddbdc6b.json', scope)
client = gspread.authorize(creds)

sheet = client.open("Rekap Soal Webinar").sheet1

data = sheet.get_all_records()

print(data)
print(livechat.is_alive())

count = len(data)
while livechat.is_alive():
    chatdata = livechat.get()
    # print("live")
    for c in chatdata.items:
        print(f"{c.datetime} [{c.author.name}]- {c.message}")

        value = c.message
        if value.count("#") >= 3:
            values = value.split("#")
            sheet.insert_row(values, count + 2)
            print("berhasil ditambah")
            print("count " + str(count))
            count += 1
            [sg.Text('_'*100)],
            [sg.Checkbox('Donation Message (100+ bits on twitch)', key='donmsg'), sg.Checkbox('Chat Message',key='chatmsg')],
            [sg.Submit()]  ]

window = sg.Window('Livestream Chat Narrator', layout, resizable=True,)

while True:
    event, values = window.read()
    chat = LiveChat(video_id=values['streamid'][values['streamid'].find('=')+1:])
    if 'youtube.com' in values['streamid'].lower(): #youtube textbox
        if values['donmsg']==True:
            print("youtube stream selected - donation messages selected - program activated")
            window.Refresh()
            while chat.is_alive():
                try:
                    data = chat.get()
                    items = data.items
                    for c in items:
                        if c.amountValue > float(0.0):
                            print(f"{c.datetime} [{c.author.name}] - {c.message} - {c.amountString}")
                            engine = pyttsx3.init()
                            engine.setProperty('rate', 135)
                            engine.say(c.author.name+' donated '+c.amountValue+' and says '+c.message)
                            engine.runAndWait()
                            print('finished playing audio message')
                except KeyboardInterrupt:
                    chat.terminate()
                    break
        if values['chatmsg']==True:
            print("youtube stream selected - all chat messages selected - program activated")
            while chat.is_alive():
Пример #10
0
        live_chat.terminate()
        break

if not live_chat.is_alive():
    print("URL is not currently a live stream")
    print("Would you like to start on the recorded stream? (y/n)")
    while True:
        playback = input("> ")
        if playback.lower() == 'y' or playback.lower() == 'n':
            break
        else:
            print('Please enter (y) or (n)!')
    if playback == 'y':
        live_chat = LiveChat(mo.group(5), seektime=1)
        while live_chat:
            try:
                chat_data = live_chat.get()
                for c in chat_data.items:
                    if c.author.name in myList:
                        if alarm.exists():
                            playsound(alarm_filename)
                        print("{} [{}] - {}".format(c.datetime, c.author.name,
                                                    c.message))
                        chat_data.tick()
            except KeyboardInterrupt:
                live_chat.terminate()
                sys.exit()
    else:
        print("Program will now exit...")
        sys.exit()