mirror of
https://github.com/jarulsamy/Plex-Bot.git
synced 2024-08-19 15:01:55 +02:00
Compare commits
No commits in common. "master" and "v0.0.1" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,7 +1,6 @@
|
||||
# Project specific
|
||||
config.yaml
|
||||
config/
|
||||
deploy.sh
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
19
Dockerfile
19
Dockerfile
@ -1,13 +1,11 @@
|
||||
FROM python:3.7-slim
|
||||
|
||||
LABEL maintainer="Joshua Arulsamy <joshua.gf.arul@gmail.com>"
|
||||
# Python 3.7
|
||||
FROM python:3.7
|
||||
|
||||
# Update system
|
||||
RUN apt-get -y update
|
||||
RUN apt-get -y upgrade
|
||||
# Install ffmpeg
|
||||
RUN apt-get -y update && \
|
||||
apt-get install -y --no-install-recommends ffmpeg=7:4.1.6-1~deb10u1 && \
|
||||
apt-get autoremove -y && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
RUN apt-get install -y ffmpeg
|
||||
|
||||
# All source code
|
||||
WORKDIR /src
|
||||
@ -16,10 +14,11 @@ WORKDIR /src
|
||||
COPY requirements.txt .
|
||||
|
||||
# Install all dependencies.
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
# Copy PlexBot over to src.
|
||||
COPY PlexBot/ PlexBot
|
||||
|
||||
# Run the bot
|
||||
CMD ["python", "-OO", "-m", "PlexBot"]
|
||||
# CMD ["python", "-OO", "-m", "PlexBot"]
|
||||
CMD ["python", "-m", "PlexBot"]
|
||||
|
30
Jenkinsfile
vendored
30
Jenkinsfile
vendored
@ -25,7 +25,6 @@ pipeline {
|
||||
sh ''' conda create --yes -n ${BUILD_TAG} python
|
||||
source /var/lib/jenkins/miniconda3/etc/profile.d/conda.sh
|
||||
conda activate ${BUILD_TAG}
|
||||
pip install -r requirements.txt
|
||||
pip install pylint
|
||||
'''
|
||||
}
|
||||
@ -36,7 +35,7 @@ pipeline {
|
||||
echo "Style check"
|
||||
sh ''' source /var/lib/jenkins/miniconda3/etc/profile.d/conda.sh
|
||||
conda activate ${BUILD_TAG}
|
||||
pylint PlexBot || true
|
||||
pylint CHANGE_ME || true
|
||||
'''
|
||||
}
|
||||
}
|
||||
@ -48,12 +47,20 @@ pipeline {
|
||||
}
|
||||
}
|
||||
steps {
|
||||
sh './deploy/build.sh'
|
||||
sh ''' source /var/lib/jenkins/miniconda3/etc/profile.d/conda.sh
|
||||
conda activate ${BUILD_TAG}
|
||||
pwd
|
||||
ls
|
||||
python setup.py bdist_wheel
|
||||
'''
|
||||
}
|
||||
}
|
||||
stage('Push Image') {
|
||||
steps {
|
||||
sh './deploy/push.sh'
|
||||
post {
|
||||
always {
|
||||
// Archive unit tests for the future
|
||||
archiveArtifacts (allowEmptyArchive: true,
|
||||
artifacts: 'dist/*whl',
|
||||
fingerprint: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,7 +68,14 @@ pipeline {
|
||||
post {
|
||||
always {
|
||||
sh 'conda remove --yes -n ${BUILD_TAG} --all'
|
||||
sh 'docker system prune -a -f'
|
||||
}
|
||||
failure {
|
||||
emailext (
|
||||
subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
|
||||
body: """<p>FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
|
||||
<p>Check console output at "<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
|
||||
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
17
Makefile
17
Makefile
@ -1,17 +0,0 @@
|
||||
.PHONY: help pull build clean
|
||||
.DEFAULT_GOAL: build
|
||||
|
||||
help:
|
||||
@echo "make pull"
|
||||
@echo " Start docker container with pull"
|
||||
@echo "make build"
|
||||
@echo " Start docker container rebuilding container"
|
||||
|
||||
pull:
|
||||
docker-compose up
|
||||
|
||||
build:
|
||||
docker-compose -f docker-compose_dev.yml up --build
|
||||
|
||||
clean:
|
||||
docker system prune -a
|
@ -1,7 +1,3 @@
|
||||
"""
|
||||
Plex music bot for discord.
|
||||
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
@ -12,33 +8,19 @@ import yaml
|
||||
FORMAT = "%(asctime)s %(levelname)s: [%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s"
|
||||
|
||||
logging.basicConfig(format=FORMAT)
|
||||
root_log = logging.getLogger()
|
||||
plex_log = logging.getLogger("Plex")
|
||||
bot_log = logging.getLogger("Bot")
|
||||
logger = logging.getLogger("PlexBot")
|
||||
|
||||
|
||||
def load_config(basedir: str,filename: str) -> Dict[str, str]:
|
||||
"""Loads config from yaml file
|
||||
def load_config(filename: str) -> Dict[str, str]:
|
||||
|
||||
Grabs key/value config pairs from a file.
|
||||
|
||||
Args:
|
||||
filename: str path to yaml file.
|
||||
|
||||
Returns:
|
||||
Dict[str, str] Values from config file.
|
||||
|
||||
Raises:
|
||||
FileNotFound Configuration file not found.
|
||||
"""
|
||||
# All config files should be in /config
|
||||
# for docker deployment.
|
||||
filename = Path(basedir, filename)
|
||||
filename = Path("/config", filename)
|
||||
try:
|
||||
with open(filename, "r") as config_file:
|
||||
config = yaml.safe_load(config_file)
|
||||
with open(filename, "r") as f:
|
||||
config = yaml.safe_load(f)
|
||||
except FileNotFoundError:
|
||||
root_log.fatal("Configuration file not found at '"+str(filename)+"'.")
|
||||
logging.fatal("Configuration file not found.")
|
||||
sys.exit(-1)
|
||||
|
||||
# Convert str level type to logging constant
|
||||
@ -49,12 +31,7 @@ def load_config(basedir: str,filename: str) -> Dict[str, str]:
|
||||
"ERROR": logging.ERROR,
|
||||
"CRITICAL": logging.CRITICAL,
|
||||
}
|
||||
|
||||
config["root"]["log_level"] = levels[config["root"]["log_level"].upper()]
|
||||
config["plex"]["log_level"] = levels[config["plex"]["log_level"].upper()]
|
||||
config["discord"]["log_level"] = levels[config["discord"]["log_level"].upper()]
|
||||
|
||||
if config["lyrics"] and config["lyrics"]["token"].lower() == "none":
|
||||
config["lyrics"] = None
|
||||
level = config["general"]["log_level"]
|
||||
config["general"]["log_level"] = levels[level.upper()]
|
||||
|
||||
return config
|
||||
|
@ -1,21 +1,14 @@
|
||||
"""
|
||||
Main entrypoint script.
|
||||
Sets up loggers and initiates bot.
|
||||
"""
|
||||
import logging
|
||||
|
||||
from discord.ext.commands import Bot
|
||||
|
||||
from . import load_config
|
||||
from . import FORMAT
|
||||
from .bot import General
|
||||
from .bot import Plex
|
||||
from PlexBot import load_config
|
||||
|
||||
# Load config from file
|
||||
configdir = "config"
|
||||
from os import geteuid
|
||||
if geteuid() == 0:
|
||||
configdir = "/config"
|
||||
config = load_config(configdir,"config.yaml")
|
||||
config = load_config("config.yaml")
|
||||
|
||||
BOT_PREFIX = config["discord"]["prefix"]
|
||||
TOKEN = config["discord"]["token"]
|
||||
@ -23,30 +16,14 @@ TOKEN = config["discord"]["token"]
|
||||
BASE_URL = config["plex"]["base_url"]
|
||||
PLEX_TOKEN = config["plex"]["token"]
|
||||
LIBRARY_NAME = config["plex"]["library_name"]
|
||||
LOG_LEVEL = config["general"]["log_level"]
|
||||
|
||||
if config["lyrics"]:
|
||||
LYRICS_TOKEN = config["lyrics"]["token"]
|
||||
else:
|
||||
LYRICS_TOKEN = None
|
||||
|
||||
# Set appropiate log level
|
||||
root_log = logging.getLogger()
|
||||
plex_log = logging.getLogger("Plex")
|
||||
bot_log = logging.getLogger("Bot")
|
||||
|
||||
plex_log.setLevel(config["plex"]["log_level"])
|
||||
bot_log.setLevel(config["discord"]["log_level"])
|
||||
|
||||
plex_args = {
|
||||
"base_url": BASE_URL,
|
||||
"plex_token": PLEX_TOKEN,
|
||||
"lib_name": LIBRARY_NAME,
|
||||
"lyrics_token": LYRICS_TOKEN,
|
||||
}
|
||||
logger = logging.getLogger("PlexBot")
|
||||
logging.basicConfig(format=FORMAT)
|
||||
logger.setLevel(LOG_LEVEL)
|
||||
|
||||
bot = Bot(command_prefix=BOT_PREFIX)
|
||||
# Remove help command, we have our own custom one.
|
||||
bot.remove_command("help")
|
||||
bot.add_cog(General(bot))
|
||||
bot.add_cog(Plex(bot, **plex_args))
|
||||
bot.add_cog(Plex(bot, BASE_URL, PLEX_TOKEN, LIBRARY_NAME, BOT_PREFIX))
|
||||
bot.run(TOKEN)
|
||||
|
@ -1,5 +0,0 @@
|
||||
"""Track version number of package."""
|
||||
VERSION = "1.0.3"
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(VERSION)
|
1032
PlexBot/bot.py
1032
PlexBot/bot.py
File diff suppressed because it is too large
Load Diff
@ -1,10 +0,0 @@
|
||||
class MediaNotFoundError(Exception):
|
||||
"""Raised when a PlexAPI media resource cannot be found."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class VoiceChannelError(Exception):
|
||||
"""Raised when user is not connected to a voice channel."""
|
||||
|
||||
pass
|
147
README.md
147
README.md
@ -1,74 +1,28 @@
|
||||
# Plex-Bot
|
||||
|
||||
[](https://app.codacy.com/manual/jarulsamy/Plex-Bot?utm_source=github.com&utm_medium=referral&utm_content=jarulsamy/Plex-Bot&utm_campaign=Badge_Grade_Dashboard)
|
||||
[](http://perso.crans.org/besson/LICENSE.html)
|
||||

|
||||

|
||||

|
||||
|
||||
A Python-based Plex music bot for discord.
|
||||
|
||||

|
||||
|
||||
## Setup
|
||||
|
||||
Plex-Bot runs entirely in a Docker container. Ensure you have Docker and docker-compose installed according to the official Docker [documentation](https://docs.docker.com/get-docker/).
|
||||
|
||||
1. Create a new folder and `cd` into it:
|
||||
1. Clone the repository and `cd` into it:
|
||||
|
||||
```bash
|
||||
mkdir Plex-Bot
|
||||
cd Plex-Bot
|
||||
```
|
||||
```
|
||||
$ git clone https://github.com/jarulsamy/Plex-Bot
|
||||
$ cd Plex-Bot
|
||||
```
|
||||
|
||||
2. Make a `docker-compose.yml` file or use this sample:
|
||||
2. Create a configuration folder:
|
||||
|
||||
```yml
|
||||
version: "3"
|
||||
services:
|
||||
plex-bot:
|
||||
container_name: "PlexBot"
|
||||
image: jarulsamy/plex-bot:latest
|
||||
environment:
|
||||
- PUID=1000
|
||||
- PGID=1000
|
||||
- TZ=America/Denver
|
||||
# Required dir for configuration files
|
||||
volumes:
|
||||
- "./config:/config:ro"
|
||||
restart: "unless-stopped"
|
||||
```
|
||||
Create a new `config` folder and copy the sample config file into it:
|
||||
|
||||
3. Create a new `config` folder and create a config file like this::
|
||||
```
|
||||
$ mkdir config
|
||||
$ cp sample-config.yaml config/config.yaml
|
||||
```
|
||||
|
||||
```bash
|
||||
mkdir config
|
||||
cd config
|
||||
touch config.yaml
|
||||
```
|
||||
|
||||
```yml
|
||||
# Create a file called config.yaml with the following contents
|
||||
|
||||
root:
|
||||
log_level: "info"
|
||||
|
||||
discord:
|
||||
prefix: "?"
|
||||
token: "<BOT_TOKEN>"
|
||||
log_level: "debug"
|
||||
|
||||
plex:
|
||||
base_url: "<BASE_URL>"
|
||||
token: "<PLEX_TOKEN>"
|
||||
library_name: "<LIBRARY_NAME>"
|
||||
log_level: "debug"
|
||||
|
||||
lyrics:
|
||||
token: "none" # Add your token here if you enable lyrics
|
||||
```
|
||||
|
||||
4. Create a Discord bot application:
|
||||
3. Create a Discord bot application:
|
||||
|
||||
1. Go to the Discord developer portal, [here](https://discord.com/developers/applications).
|
||||
|
||||
@ -84,69 +38,44 @@ Plex-Bot runs entirely in a Docker container. Ensure you have Docker and docker-
|
||||
6. Click Create Bot User
|
||||
This will provide you with your bot Username and Token
|
||||
|
||||
7. Fill in the bot token in `config/config.yaml`
|
||||
7. Fill in all the necessary numbers in `config/config.yaml`
|
||||
|
||||
5. Get your plex token:
|
||||
4. Get your plex token:
|
||||
|
||||
* Refer to the official [plex documentation](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/).
|
||||
Refer to the official [plex documentation](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/).
|
||||
|
||||
* Add it to `config/config.yaml` in the appropiate spot.
|
||||
Add it to `config/config.yaml` in the appropiate spot.
|
||||
|
||||
6. Get your Lyrics Genius token (Optional):
|
||||
5. Start the service:
|
||||
|
||||
If you would like to enable the lyrics feature of the bot, you need to signup for a free GeniusLyrics account, [here](https://genius.com/api-clients).
|
||||
|
||||
After you make an account:
|
||||
|
||||
1. Click New API Client
|
||||
|
||||
2. Set the app website url to: `https://github.com/jarulsamy/Plex-Bot`
|
||||
|
||||
3. Set the redirect url to: `http://localhost`
|
||||
|
||||
4. Copy the **Client Access Token** and replace `None` with your token in `config/config.yaml`
|
||||
|
||||
7. Customize remaining settings
|
||||
|
||||
Set any remaining settings in the config file that you would like. Such as music library, and base url of the Plex server.
|
||||
|
||||
8. Start the service:
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
## Logs
|
||||
|
||||
You can view the logs with the following command
|
||||
|
||||
```bash
|
||||
docker-compose logs -f CONTAINER_NAME_OR_ID
|
||||
|
||||
# For example
|
||||
docker-compose logs -f PlexBot
|
||||
```
|
||||
$ docker-compose up --build
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```text
|
||||
```
|
||||
General:
|
||||
kill [silent] - Halt the bot [silently].
|
||||
help - Print this help message.
|
||||
cleanup - Delete old messages from the bot.
|
||||
|
||||
kill - Stop the bot.
|
||||
Plex:
|
||||
play <SONG_NAME> - Play a song from the plex server.
|
||||
album <ALBUM_NAME> - Queue an entire album to play.
|
||||
playlist <PLAYLIST_NAME> - Queue an entire playlist to play.
|
||||
lyrics - Print the lyrics of the song (Requires Genius API)
|
||||
np - Print the current playing song.
|
||||
stop - Halt playback and leave vc.
|
||||
pause - Pause playback.
|
||||
resume - Resume playback.
|
||||
clear - Clear play queue.
|
||||
np - View currently playing song.
|
||||
pause - Pause currently playing song.
|
||||
play - Play a song from the Plex library.
|
||||
resume - Resume a paused song.
|
||||
skip - Skip a song.
|
||||
stop - Stop playing.
|
||||
No Category:
|
||||
help Shows this message
|
||||
|
||||
[] - Optional args.
|
||||
Type ?help command for more info on a command.
|
||||
You can also type ?help category for more info on a category.
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Reach out to me at one of the following places!
|
||||
|
||||
- Email (Best) at joshua.gf.arul@gmail.com
|
||||
- Twitter at <a href="http://twitter.com/jarulsamy_" target="_blank">`@jarulsamy_`</a>
|
||||
|
||||
* * *
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 17 KiB |
@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
VERSION=$(python PlexBot/__version__.py)
|
||||
|
||||
docker build -t "jarulsamy/plex-bot:$VERSION" .
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "Successfully build docker image."
|
||||
exit 0
|
||||
else
|
||||
echo "Failed to build docker image." >&2
|
||||
exit 1
|
||||
fi
|
@ -1,14 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
VERSION=$(python PlexBot/__version__.py)
|
||||
|
||||
docker push "jarulsamy/plex-bot:$VERSION"
|
||||
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "Successfully pushed docker image."
|
||||
exit 0
|
||||
else
|
||||
echo "Failed to push docker image." >&2
|
||||
exit 1
|
||||
fi
|
@ -2,7 +2,7 @@ version: "3"
|
||||
services:
|
||||
plex-bot:
|
||||
container_name: "PlexBot"
|
||||
image: jarulsamy/plex-bot:latest
|
||||
build: .
|
||||
environment:
|
||||
- PUID=1000
|
||||
- PGID=1000
|
||||
@ -10,4 +10,4 @@ services:
|
||||
# Required dir for configuration files
|
||||
volumes:
|
||||
- "./config:/config:ro"
|
||||
restart: "unless-stopped"
|
||||
restart: "no"
|
||||
|
@ -1,13 +0,0 @@
|
||||
version: "3"
|
||||
services:
|
||||
plex-bot:
|
||||
container_name: "PlexBot"
|
||||
build: .
|
||||
environment:
|
||||
- PUID=1000
|
||||
- PGID=1000
|
||||
- TZ=America/Denver
|
||||
# Required dir for configuration files
|
||||
volumes:
|
||||
- "./config:/config:ro"
|
||||
restart: "no"
|
@ -1,7 +1,7 @@
|
||||
discord.py==1.4.1
|
||||
discord.py==1.3.4
|
||||
PlexAPI==4.0.0
|
||||
fuzzywuzzy==0.18.0
|
||||
python-Levenshtein==0.12.0
|
||||
pynacl==1.4.0
|
||||
ffmpeg==1.4
|
||||
PyYAML==5.3.1
|
||||
lyricsgenius==2.0.0
|
||||
|
@ -1,16 +1,12 @@
|
||||
root:
|
||||
general:
|
||||
# Options: debug, info, warning, error, critical
|
||||
log_level: "info"
|
||||
|
||||
discord:
|
||||
prefix: "?"
|
||||
token: "<BOT_TOKEN>"
|
||||
log_level: "debug"
|
||||
|
||||
plex:
|
||||
base_url: "<BASE_URL>"
|
||||
token: "<PLEX_TOKEN>"
|
||||
library_name: "<LIBRARY_NAME>"
|
||||
log_level: "debug"
|
||||
|
||||
lyrics:
|
||||
token: <CLIENT_ACCESS_TOKEN>
|
||||
|
Loading…
x
Reference in New Issue
Block a user