Bravo List
Register
Go Back   > Bravo List > P2P > Forum > Community Cafe
Reply
  #1  
Old 11th November 2021, 16:14
firefly007's Avatar
firefly007 firefly007 is offline
SUPPORT GURU
 
Join Date: Jun 2010
P2P
Posts: 721
Default Youtube live chat listening bot written in python (firefly)
Hi so here is a quick script which will listen to live Youtube chat stream.

You can do a number of things with this script. At the moment the script will have all the username and their message to a database.

Remember if you wana run this script in headless mode you need to comment out driver = webdriver.Firefox() so it will look like this #driver = webdriver.Firefox() and remove the hash from #driver = webdriver.Firefox(options=options) so it will look like this driver = webdriver.Firefox(options=options).

This script runs on Python3 both on Ubuntu 18.04 64bit LTS and Windows 10 64bit

Code:
# Module Imports
import mariadb
import sys
import os
from datetime import datetime
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from time import sleep
from itertools import count


# Connect to MariaDB Platform
try:
    conn = mariadb.connect(
        user="root",
        password="",
        host="localhost",
        port=3306,
        database="ytchat"

    )
except mariadb.Error as e:
    print(f"Error connecting to MariaDB Platform: {e}")
    sys.exit(1)

# Get Cursor
cur = conn.cursor()

def ytc(user,mess):
    cur.execute(
        "INSERT INTO mess (user,mess,added) VALUES (?, ?, ?)", 
        (user, mess, datetime.now()))
    conn.commit()


string = 'KZWVvBbjOuU'
options = FirefoxOptions()
options.add_argument("--headless")
driver = webdriver.Firefox()
#driver = webdriver.Firefox(options=options)
driver.get('https://www.youtube.com/live_chat?is_popout=1&v='+ str(string))
driver.maximize_window()
sleep(4)

messages = driver.find_elements_by_xpath('//*[@id="message"]')

last_message_text = messages[0].text



while (True):


    messages = driver.find_elements_by_xpath('//*[@id="message"]')
    driver.get('https://www.youtube.com/live_chat?is_popout=1&v='+ str(string))
    try:
        number =1
        for number in count(1):
            user = driver.find_elements_by_xpath('//*[@id="author-name"]')[number].text
            mess = driver.find_elements_by_xpath('//*[@id="message"]')[number].text
            print(user)
            print(mess)
            ytc(user,mess)
            sleep(5)
    except NoSuchElementException:
        sleep(10)
        number =1
        for number in count(1):
            user = driver.find_elements_by_xpath('//*[@id="author-name"]')[number].text
            mess = driver.find_elements_by_xpath('//*[@id="message"]')[number].text
            print(user)
            print(mess)
            ytc(user,mess)
            sleep(5)
__________________




Please Support Majority Report


You can contact me on Skype live:phesadent.elect but please let me know first.


If you are ever need me desperately then please email me at dan.oak44@gmail.com and I will contact u within a week.


Due to free time I'm able to help interested member's with their tracker.

Please Note!
Depending on your requests I will charge you for my assistance for Tracker installs and mods.
All my mods are custom and prices will very depending on the request.
I'm able to install any tracker and mods including themes.

Please PM me


Last edited by firefly007; 11th November 2021 at 16:35.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT +2. The time now is 19:10. vBulletin skin by ForumMonkeys. Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.