Giter Club home page Giter Club logo

discord-youtube-notifier's Introduction

Discord YouTube Notifier

A selfhosted YouTube feed bot for Discord. Basically, this bot keeps you and your friends up-to-date with everything that's happening on YouTube. Or, if you are a YouTuber or YouTube livestreamer yourself, and like to forget to promote yourself like I do, this bot takes care of that too.

Features

  • Multi YouTuber support (you can add as many as you want)
  • Multi Discord channel support, so you can push the update feed in more than one server or channel at a time!
  • Livestream support
  • Custom messages for user uploads and livestreams!
    • Support for custom messages per channel!
  • Easy yaml configuration file (config.yml)

Requirements

  • Python 3.5
  • Microsoft Windows, I do not have Linux and all the launchers are done in batch (The bot should in theory still run just fine on Linux in a terminal, you would have to install the requirements manualy, though. I do NOT know if you need anything else for it to work, though.)
  • Discord.py
  • PyYaml
  • Google API Key (with YouTube Data API v3 activated), Tutorial in "Preparation"
  • Registered Discord bot, Tutorial in "Preparation"

Preparation

  • 1.) Install Python 3.5, and make sure it is included to your PATH.
  • 2.) In order to obtain an Google API Key (with YouTube Data API v3 activated) follow the Steps 1-3 here and then generate a key for the API. This key will later on go to the config file of the bot.
  • 3.) Set up a discord bot, get the token and invite the bot to your server, by following this guide. The bot token will later on go to the config file of the bot.
  • 4.) You need to enable developer mode in your discord client to obtain the channel ID's you want the feed to appear on. Do so by going to your User settings -> Appearance -> Tick "Developer Mode" in the ADVANCED tab.
  • 5.) Obtain the channel ID(s) by right clicking the channel and then clicking "Copy ID".
  • 6.) Obtain a user ID by right clicking the username and then clicking "Copy ID" (optional).
  • 7.) Get the YouTube channel ID(s). This is done in 2 ways:
    • Visit the YouTube channel and then copy the channel from the URL, for example:
    • Some YouTubers hide their channel ID completely and only show their username. In order to obtain the channel ID for them, we have to use this external site: http://johnnythetank.github.io/youtube-channel-name-converter/
      • e.g. entering "PewDiePie" into the "Youtube username" field will return "UC-lHJZR3Gqxm24_Vd_AJ5Yw". this is the one you want to copy.

Configuration

Configuration is done by editing the config.yaml file. I would suggest using an editor like Notepad++ to edit the file.

  • In the first section in "connection" you will have to enter your YouTube v3 API Key that you have obtained earlier in Step #2 of Preparation. Just copy and paste it into the field, so that this:
        Google API key: # YouTube v3 API Key

Will look like something like this:

        Google API key: 4P9nlidzQdMCxCzDymrUDpNwapMQ5jqC # YouTube v3 API Key
  • Then you need to provide your discord bot token you have obtained in Step #3 in Preparation. Again, just copy and paste it, so that this:
        Discord bot token: # Discord bot token

Becomes something like this:

        Discord bot token: 7PGNyakySQu8ZH0T3Y7EDldSnHKlOGbL.SFTM7Zq38J-aDR2pflmUS # Discord bot token
  • You can specify the time period in minutes the bot will check the YouTube channels for new content. I do not recommend going lower than 5 minutes though, because your daily use of queries is limited and can be used up very quickly that way. Just change the "5" to whatever you desire.
        Ping Every x Minutes: 5 # at least 5 minutes should be ok, anything lower not recommended, because the API traffic will be used up very quickly otherwise.
  • I have included 2 Discord channelID placeholders as an example in the config:
        0:
            channelID: # Discord channel ID
        1:
            channelID: # Discord channel ID

You can expand those further by copying it and incrementing the number correspondingly. In this example 4:

        0:
            channelID: # Discord channel ID
        1:
            channelID: # Discord channel ID
        2:
            channelID: # Discord channel ID
        3:
            channelID: # Discord channel ID

Then you need to provide your discord channel ID(s) you have obtained in Step #5 in Preparation. Again, just copy and paste it:

        0:
            channelID: 3C2DCFC6DCA9761B # Discord channel ID
        1:
            channelID: 69387236D19A2C12 # Discord channel ID

IMPORTANT: if you only use 1 channel, you need to delete all other entries:

        0:
            channelID: 3C2DCFC6DCA9761B # Discord channel ID
  • Now you can specify the YouTubers that you want to push on your discord. Again, I have included placeholders for 2 channels as an example:
        0:
            name: # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: # YouTube Channel ID
        1:
            name: # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: # YouTube Channel ID

Again, you can expand them by copying and incrementing accordingly. In this example 4:

        0:
            name: # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: # YouTube Channel ID
        1:
            name: # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: # YouTube Channel ID
        2:
            name: # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: # YouTube Channel ID
        3:
            name: # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: # YouTube Channel ID

Then you need to provide your channel ID(s) you have obtained in Step #7 in Preparation. Again, just copy and paste it:

        0:
            name: # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: UCXuqSBlHAE6Xw-yeJA0Tunw # YouTube Channel ID
        1:
            name: # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: UC-lHJZR3Gqxm24_Vd_AJ5Yw # YouTube Channel ID

And then provide a name for them. Note, this name is displayed on discord:

        0:
            name: LinusTechTips # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: UCXuqSBlHAE6Xw-yeJA0Tunw # YouTube Channel ID
        1:
            name: PewDiePie # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: UC-lHJZR3Gqxm24_Vd_AJ5Yw # YouTube Channel ID

Useful if you are a YouTuber yourself and want to automaticaly promote yourself: You can @mention yourself instead of giving a static name by typing <@DiscordUserID> (Replace DiscordUserID with your actual discord user ID you obtained in Step #6 of Preparation):

        0:
            name: <@32C6E424B5212> # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: UCXuqSBlHAE6Xw-yeJA0Tunw # YouTube Channel ID
        1:
            name: <@7E169455DF2EC> # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: UC-lHJZR3Gqxm24_Vd_AJ5Yw # YouTube Channel ID

AGAIN, IMPORTANT: if you only use 1 channel, you need to delete all other entries:

        0:
            name: LinusTechTips # Name that will be displayed in discord, mentions can be used with <@DiscordUserID>
            channelID: UCXuqSBlHAE6Xw-yeJA0Tunw # YouTube Channel ID
  • You can have custom messages for when a user uploads something or is currently livestreaming:
        New video: ":film_frames: **{0} HAS UPLOADED A NEW VIDEO!** :film_frames:" # Message that appears when a YouTuber has uploaded a new video, user placeholder: {0}
        Livestream: ":red_circle: **{0} IS LIVESTREAMING NOW!** :red_circle:" # Message that appears when a YouTuber is livestreaming, user placeholder: {0}
  • Make sure that your message is quoted (""). The following parameters can be used:
    • {0}
      • Name you specified in the YouTubers configuration
    • @everyone
      • Mention @everyone on Discord
    • <@DiscordUserID>
      • Mention a specific user on discord, ID can be obtained like described in Step #6 in Preparation.
    • :EmojiName:
      • In my example configuration file, I am using emoji's like ๐ŸŽฌ and ๐Ÿ”ด. You can use all the emoji's with :EmojiName:. Emoji names can be obtained by clicking on the emoji symbol on the right in the Discord textchat, and a mouseover will reveal the plain text that you need to enter.

Installation

Make sure you have Python 3.5 installed. Then run the file update_deps.bat by double clicking. This should automaticaly install all the python requirements you will need for this bot to function. Aaaand.. that's all, you are ready to run the bot now.

Running

Run the bot by opening the runbot.bat file.

discord-youtube-notifier's People

Contributors

amethyst93 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

discord-youtube-notifier's Issues

Problem Spotted

Traceback (most recent call last):
File "main.py", line 6, in
from config import Config
File "/home/runner/YouTube-Notify/config.py", line 1, in
import yaml
ModuleNotFoundError: No module named 'yaml'

"HELP ME ON THIS PLS"

Bot is not 'PUSHING UPDATE ON DISCORD'

Trying to run this on Raspberry Pi
Followed instructions
launching with command 'python3 main.py'
Bot is not posting

pi@pi:~/pipy_bot $ python3 main.py
Logged in as:
SamBot
768508391777107979
#---------------------------------------
Bot running.
Checking for new videos from <@samuli.pl>
<@samuli.pl> IS LIVESTREAMING NOW! PUSHING UPDATE ON DISCORD.
Rechecking in 04:57

allways this error

data = json.load(self.reader(urllib.request.urlopen('https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id={}&key={}'.format(self.YouTubeName, self.GOOGLE_API))))
File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.8/urllib/request.py", line 531, in open
response = meth(req, response)
File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/usr/lib/python3.8/urllib/request.py", line 569, in error
return self._call_chain(*args)
File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

Replit?

Can anyone please make a version that works with replit. thx

Lifestream get's posted several times

Hey,
as soon as a Youtuber goes Live, the Bot does not check if it already announced that said Youtuber is already streaming. So it repeatly pushed an update in the inverval you specified.

Error preventing start

/root/DiscordYoutubeNotifier/config.py:14: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  cfg = yaml.load(ymlfile)
Traceback (most recent call last):
  File "./main.py", line 74, in <module>
    client.run(config.getConnectionData()[1])
  File "/usr/lib/python3.6/site-packages/discord/client.py", line 598, in run
    return future.result()
  File "/usr/lib/python3.6/site-packages/discord/client.py", line 579, in runner
    await self.start(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/discord/client.py", line 543, in start
    await self.connect(reconnect=reconnect)
  File "/usr/lib/python3.6/site-packages/discord/client.py", line 457, in connect
    await self._connect()
  File "/usr/lib/python3.6/site-packages/discord/client.py", line 421, in _connect
    await self.ws.poll_event()
  File "/usr/lib/python3.6/site-packages/discord/gateway.py", line 469, in poll_event
    await self.received_message(msg)
  File "/usr/lib/python3.6/site-packages/discord/gateway.py", line 423, in received_message
    func(data)
  File "/usr/lib/python3.6/site-packages/discord/state.py", line 661, in parse_guild_create
    guild = self._get_create_guild(data)
  File "/usr/lib/python3.6/site-packages/discord/state.py", line 636, in _get_create_guild
    guild._from_data(data)
  File "/usr/lib/python3.6/site-packages/discord/guild.py", line 391, in _from_data
    self._sync(guild)
  File "/usr/lib/python3.6/site-packages/discord/guild.py", line 418, in _sync
    self._add_channel(TextChannel(guild=self, data=c, state=self._state))
  File "/usr/lib/python3.6/site-packages/discord/channel.py", line 107, in __init__
    self._update(guild, data)
  File "/usr/lib/python3.6/site-packages/discord/channel.py", line 131, in _update
    self._fill_overwrites(data)
  File "/usr/lib/python3.6/site-packages/discord/abc.py", line 271, in _fill_overwrites
    self._overwrites.append(_Overwrites(id=overridden_id, **overridden))
TypeError: __new__() got an unexpected keyword argument 'deny_new'

Bot terminates for various reasons

Hi,

Am unsure if this bot is updated much any more, but have had some issues with keeping it online as it terminates early or ends up being terminated.

After about 72 hours or bot run time, on my terminal i end up seeing this...

Task was destroyed but it is pending!
task: <Task pending coro=<update() running at main.py:63> wait_for=<Future pending cb=[Task._wakeup()]>>
Task exception was never retrieved
future: <Task finished coro=<WebSocketCommonProtocol.run() done, defined at /usr/local/lib/python3.5/dist-packages/websockets/protocol.py:428> exception=ConnectionResetError(104, 'Connection reset by peer')>
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
    result = coro.throw(exc)
  File "/usr/local/lib/python3.5/dist-packages/websockets/protocol.py", line 434, in run
    msg = yield from self.read_message()
  File "/usr/local/lib/python3.5/dist-packages/websockets/protocol.py", line 456, in read_message
    frame = yield from self.read_data_frame(max_size=self.max_size)
  File "/usr/local/lib/python3.5/dist-packages/websockets/protocol.py", line 511, in read_data_frame
    frame = yield from self.read_frame(max_size)
  File "/usr/local/lib/python3.5/dist-packages/websockets/protocol.py", line 546, in read_frame
    self.reader.readexactly, is_masked, max_size=max_size)
  File "/usr/local/lib/python3.5/dist-packages/websockets/framing.py", line 86, in read_frame
    data = yield from reader(2)
  File "/usr/lib/python3.5/asyncio/streams.py", line 668, in readexactly
    yield from self._wait_for_data('readexactly')
  File "/usr/lib/python3.5/asyncio/streams.py", line 458, in _wait_for_data
    yield from self._waiter
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 723, in _read_ready
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer

It's not always error 104, but any sort of error/timeout will terminate the bot. This is being ran via ubuntu, and not via windows - for the most part, when it is working, there's absolutely zero issues.

Any idea on this?

Error 404

Here it is the error:
root@giacomo:/bot# python3.5 main.py
/bot/config.py:14: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
cfg = yaml.load(ymlfile)
Traceback (most recent call last):
File "main.py", line 31, in
processes.append(YouTuber(GOOGLE_API, threads[i][1], threads[i][2]))
File "/bot/Implementation.py", line 30, in init
self.data = self.getPlaylistData()
File "/bot/Implementation.py", line 63, in getPlaylistData
data = json.load(self.reader(urllib.request.urlopen('https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=5&playlistId={}&key={}'.format(self.PlaylistID, self.GOOGLE_API))))
File "/usr/local/lib/python3.5/urllib/request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.5/urllib/request.py", line 472, in open
response = meth(req, response)
File "/usr/local/lib/python3.5/urllib/request.py", line 582, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/local/lib/python3.5/urllib/request.py", line 510, in error
return self._call_chain(*args)
File "/usr/local/lib/python3.5/urllib/request.py", line 444, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.5/urllib/request.py", line 590, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
root@giacomo:/bot#

I didn't edit any file, only config.yml to put bot token, YT channels, YouTube API Key V3 and the other things u said in readme.md.

If u find the error it will help me very much ;D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.