first commit
This commit is contained in:
commit
9fd80a272d
|
@ -0,0 +1,43 @@
|
||||||
|
1. Create a working dir
|
||||||
|
`mkdir /absolute/path/to/`
|
||||||
|
3. Create a python virtual environment
|
||||||
|
`python3 -m venv /absolute/path/to/venv`
|
||||||
|
5. Install depends in venv
|
||||||
|
`/absolute/path/to/venv/bin/pip install spotdl`
|
||||||
|
`/absolute/path/to/venv/bin/pip install python-telegram-bot`
|
||||||
|
script was written with version 4.14.0
|
||||||
|
`/absolute/path/to/venv/bin/pip install python-telegram-bot==4.14.0`
|
||||||
|
6. Edit start.py with correct telegram API token and change directories
|
||||||
|
|
||||||
|
start the script
|
||||||
|
`/absolute/path/to/venv/bin/python start.py`
|
||||||
|
|
||||||
|
|
||||||
|
## Unit file
|
||||||
|
|
||||||
|
```
|
||||||
|
[Unit]
|
||||||
|
Description=tg_spotdl
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=clay
|
||||||
|
ExecStart=/absolute/path/to/venv/bin/python /absolute/path/to/start.py
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5s
|
||||||
|
RuntimeMaxSec=12h
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## start script
|
||||||
|
```
|
||||||
|
#!/bin/bash
|
||||||
|
/absolute/path/to/venv/bin/python /absolute/path/to/start.py
|
||||||
|
exit
|
||||||
|
```
|
||||||
|
|
||||||
|
## useful links
|
||||||
|
https://github.com/eternnoir/pyTelegramBotAPI
|
|
@ -0,0 +1,78 @@
|
||||||
|
import telebot
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
# Replace 'YOUR_API_TOKEN' with your actual Telegram Bot API token
|
||||||
|
bot = telebot.TeleBot("TOKEN GOES HERE")
|
||||||
|
dldir = "/WHERE/TO/PUT/THE/MUSIC"
|
||||||
|
workingdir = "WHERE/IS/THE/PYTHON/VENV"
|
||||||
|
|
||||||
|
|
||||||
|
# Get the current day of the month
|
||||||
|
current_day = datetime.date.today().day
|
||||||
|
|
||||||
|
# Check if the day is divisible by 3
|
||||||
|
if current_day % 3 == 0:
|
||||||
|
# Replace the following command with the command you want to execute
|
||||||
|
command_to_run = f"{workingdir}bin/pip install --upgrade spotdl"
|
||||||
|
|
||||||
|
# Execute the command
|
||||||
|
try:
|
||||||
|
subprocess.run(command_to_run, shell=True, check=True)
|
||||||
|
print(f"Updated SpotDL!.")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Error updating SpotDL: {e}")
|
||||||
|
else:
|
||||||
|
print("Not upgrading SpotDL today.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Define conversation states
|
||||||
|
ARTIST, URL = range(2)
|
||||||
|
user_data = {}
|
||||||
|
|
||||||
|
print("tg_spotdl bot is running.")
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['start'])
|
||||||
|
|
||||||
|
def start(message):
|
||||||
|
bot.send_message(message.chat.id, "Hi! I'm a bot that can download music for you.")
|
||||||
|
bot.send_message(message.chat.id, "Please enter the artist name:")
|
||||||
|
bot.register_next_step_handler(message, get_artist)
|
||||||
|
print("User pushed start.")
|
||||||
|
|
||||||
|
def get_artist(message):
|
||||||
|
user_data['artist'] = message.text
|
||||||
|
bot.send_message(message.chat.id, "Please enter the Spotify URL for the artist:")
|
||||||
|
bot.register_next_step_handler(message, get_url)
|
||||||
|
|
||||||
|
def get_url(message):
|
||||||
|
artist = user_data['artist']
|
||||||
|
url = message.text
|
||||||
|
|
||||||
|
bot.send_message(message.chat.id, "This is going to take a while. Please wait!")
|
||||||
|
|
||||||
|
# Create a directory for the artist
|
||||||
|
artist_directory = f"{dldir}{artist}"
|
||||||
|
os.makedirs(artist_directory, exist_ok=True)
|
||||||
|
os.chdir(artist_directory)
|
||||||
|
|
||||||
|
# Download the music using spotdl
|
||||||
|
subprocess.run([
|
||||||
|
f"{workingdir}bin/spotdl",
|
||||||
|
"--format", "opus",
|
||||||
|
"--bitrate", "80k",
|
||||||
|
url
|
||||||
|
])
|
||||||
|
|
||||||
|
bot.send_message(message.chat.id, f"Finished downloading {artist}")
|
||||||
|
print("Download completed.")
|
||||||
|
bot.send_message(message.chat.id, "Use the /start command to download another artist.")
|
||||||
|
|
||||||
|
@bot.message_handler(func=lambda message: True)
|
||||||
|
def echo_all(message):
|
||||||
|
bot.reply_to(message, "I don't understand. Please use the /start command to begin.")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
bot.polling()
|
Loading…
Reference in New Issue