mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-15 05:48:35 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0297527965 | |||
| f56935e48b | |||
| b9e0f73534 | |||
| 7f560decd3 | |||
| 88fdf35dc5 | |||
| b4fe6270a9 | |||
| c103b6b22e | |||
| 0e860fe6a9 | |||
| fdccde6137 | |||
| 043b1d3628 | |||
| afc5c42e30 | |||
| 74b7c22b6c |
@@ -1,9 +1,9 @@
|
|||||||
# This Python file uses the following encoding: utf-8
|
|
||||||
"""
|
"""
|
||||||
The provided Python script sets up a Flask web server to manage a list of music files, with
|
The provided Python script sets up a Flask web server to manage a list of music files, with
|
||||||
functions for rescanning the music folder, updating the music list, and serving the music list via
|
functions for rescanning the music folder, updating the music list, and serving the music list via
|
||||||
API endpoints.
|
API endpoints.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@@ -48,10 +48,10 @@ if platform in ("linux", "linux2"):
|
|||||||
else:
|
else:
|
||||||
LOGFILE = "/home/pi/Conjurer/discord_mus_service.log"
|
LOGFILE = "/home/pi/Conjurer/discord_mus_service.log"
|
||||||
NETRC_FILE = "/home/pi/.netrc"
|
NETRC_FILE = "/home/pi/.netrc"
|
||||||
LOGSTORE = "/home/pi/RetroPie/logs/"
|
LOGSTORE = "/home/pi/MediaShare/logs/"
|
||||||
ENCODING = "utf-8"
|
ENCODING = "utf-8"
|
||||||
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/"
|
MUSIC_FOLDER = "/home/pi/MediaShare/mp3/"
|
||||||
PRIORITY_FOLDER = "/home/pi/RetroPie/mp3/Magiczne i chuj/"
|
PRIORITY_FOLDER = "/home/pi/MediaShare/mp3/Magiczne i chuj/"
|
||||||
RADIOLOG_PATH = "/home/pi/Conjurer/radio_log.log"
|
RADIOLOG_PATH = "/home/pi/Conjurer/radio_log.log"
|
||||||
PERSISTENCE_PATH = "/home/pi/Conjurer/persistence.log"
|
PERSISTENCE_PATH = "/home/pi/Conjurer/persistence.log"
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
flask
|
flask
|
||||||
waitress
|
waitress
|
||||||
sshtunnel
|
sshtunnel
|
||||||
|
requests
|
||||||
|
|||||||
+7
-4
@@ -78,14 +78,14 @@ if platform in ("linux", "linux2"):
|
|||||||
MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json"
|
MEMORY_FIVE_SIARA = "/home/pi/Conjurer/pamiec.json"
|
||||||
SYSTEM_GPT_SETTINGS = "/home/pi/Conjurer/system_gpt_settings.json"
|
SYSTEM_GPT_SETTINGS = "/home/pi/Conjurer/system_gpt_settings.json"
|
||||||
MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json"
|
MEMORY_FIVE_MUZYKA = "/home/pi/Conjurer/pamiec_muzyki.json"
|
||||||
MUSIC_FOLDER = "/home/pi/RetroPie/mp3/"
|
MUSIC_FOLDER = "/home/pi/MediaShare/mp3/"
|
||||||
SETTINGS_FILE = "/home/pi/Conjurer/settings.json"
|
SETTINGS_FILE = "/home/pi/Conjurer/settings.json"
|
||||||
NETRC_FILE = "/home/pi/.netrc"
|
NETRC_FILE = "/home/pi/.netrc"
|
||||||
LOGSTORE = "/home/pi/RetroPie/logs/"
|
LOGSTORE = "/home/pi/MediaShara/logs/"
|
||||||
ACCIDENT_LOG = "/home/pi/Conjurer/accident_log.json"
|
ACCIDENT_LOG = "/home/pi/Conjurer/accident_log.json"
|
||||||
ENCODING = "utf-8"
|
ENCODING = "utf-8"
|
||||||
GRAPHICS_PATH = "/home/pi/RetroPie/Conjurer_graphics/"
|
GRAPHICS_PATH = "/home/pi/MediaShare/Conjurer_graphics/"
|
||||||
DIR_PATH_SADOX = "/home/pi/RetroPie/Fansadox/"
|
DIR_PATH_SADOX = "/home/pi/MediaShare/Fansadox/"
|
||||||
|
|
||||||
|
|
||||||
elif platform == "win32":
|
elif platform == "win32":
|
||||||
@@ -120,6 +120,9 @@ SPOTIFY_CTRL = spotipy.Spotify(
|
|||||||
client_secret=authTokens[2],
|
client_secret=authTokens[2],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
REMOTE_HOST_NAME = "youtube"
|
||||||
|
authTokens = netrc_mod.authenticators(REMOTE_HOST_NAME)
|
||||||
|
YOUTUBE_AUTH = [authTokens[0],authTokens[2]]
|
||||||
|
|
||||||
WORD_REACTIONS = DATA["word_reactions"]
|
WORD_REACTIONS = DATA["word_reactions"]
|
||||||
CYCLIC_WORDS = DATA["cyclic_words"]
|
CYCLIC_WORDS = DATA["cyclic_words"]
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Package: ffmpeg libavcodec-dev libavcodec59 libavdevice59 libavfilter8 libavformat-dev libavformat59 libavutil-dev libavutil57 libpostproc56 libswresample-dev libswresample4 libswscale-dev libswscale6 libavdevice-dev libavfilter-dev libpostproc-dev
|
||||||
|
Pin: origin deb.debian.org
|
||||||
|
Pin-Priority: 1001
|
||||||
+11
-9
@@ -1,20 +1,22 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
sudo apt-get install python3-dev
|
sudo apt-get install python3-dev
|
||||||
|
sudo apt-get install portaudio19-dev python3-pyaudio
|
||||||
|
sudo apt-get install
|
||||||
cd /home/pi || exit
|
cd /home/pi || exit
|
||||||
mdkir Conjurer
|
mdkir Conjurer
|
||||||
cd Conjurer ||exit
|
cd Conjurer ||exit
|
||||||
python3 -m venv /home/pi/Conjurer/.venv
|
python3 -m venv /home/pi/Conjurer/.env
|
||||||
cp /home/pi/conjurer/requirements_bot.txt /home/pi/Conjurer/
|
cp /home/pi/conjurer/requirements_bot.txt /home/pi/Conjurer/
|
||||||
# trunk-ignore(shellcheck/SC1091)
|
# trunk-ignore(shellcheck/SC1091)
|
||||||
source /home/pi/Conjurer/.venv/bin/activate
|
source /home/pi/Conjurer/.env/bin/activate
|
||||||
./env/bin/python3 -m pip install --upgrade pip
|
./.env/bin/python3 -m pip install --upgrade pip
|
||||||
./env/bin/python3 -m pip install -r requirements_bot.txt
|
./.env/bin/python3 -m pip install -r requirements_bot.txt
|
||||||
sed -i -e 's/os.rename/shutil.copy/g' ./env/lib/python3.11/site-packages/spotify_dl/youtube.py
|
sed -i -e 's/os.rename/shutil.copy/g' ./.env/lib/python3.11/site-packages/spotify_dl/youtube.py
|
||||||
sed -i '1i\import shutil' ./env/lib/python3.11/site-packages/spotify_dl/youtube.py
|
sed -i '1i\import shutil' ./.env/lib/python3.11/site-packages/spotify_dl/youtube.py
|
||||||
sed -i '1i\import logging' ./env/lib/python3.11/site-packages/spotify_dl/spotify.py
|
sed -i '1i\import logging' ./.env/lib/python3.11/site-packages/spotify_dl/spotify.py
|
||||||
|
|
||||||
sed -i '21i\ logger = logging.getLogger("discord")' ./env/lib/python3.11/site-packages/spotify_dl/spotify.py
|
sed -i '21i\ logger = logging.getLogger("discord")' ./.env/lib/python3.11/site-packages/spotify_dl/spotify.py
|
||||||
sed -i '22i\ logger.info("Playlist")' ./env/lib/python3.11/site-packages/spotify_dl/spotify.py
|
sed -i '22i\ logger.info("Playlist")' ./.env/lib/python3.11/site-packages/spotify_dl/spotify.py
|
||||||
#add sed changing signal registration to catch exception in spotify dl init
|
#add sed changing signal registration to catch exception in spotify dl init
|
||||||
deactivate
|
deactivate
|
||||||
sudo cp ./conjurer.service /etc/systemd/system/
|
sudo cp ./conjurer.service /etc/systemd/system/
|
||||||
|
|||||||
@@ -25,8 +25,12 @@ sudo usermod -aG pulse-access root
|
|||||||
sudo usermod -aG audio pi
|
sudo usermod -aG audio pi
|
||||||
sudo usermod -aG audio root
|
sudo usermod -aG audio root
|
||||||
|
|
||||||
|
echo "Add exception suppresion to signal handler in spotify __ini__.py"
|
||||||
|
echo "Add password to youtube opts in spotify_dl youtube.py"
|
||||||
|
echo "Downgrade ffmpeg by copying ffmpeg.pref from repository to /etc/apt/preferences.d"
|
||||||
|
echo "Install opam from installation link"
|
||||||
|
echo "Initialize opam"
|
||||||
|
echo "Install liquidsoap and its dependencies"
|
||||||
|
|
||||||
touch /home/pi/Conjurer/radio_log.log
|
touch /home/pi/Conjurer/radio_log.log
|
||||||
./env/bin/python3 -m pip install --upgrade pip
|
./env/bin/python3 -m pip install --upgrade pip
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
# === SYSTEM SETUP ===
|
||||||
|
sudo apt update && sudo apt install -y \
|
||||||
|
pulseaudio pulseaudio-utils pavucontrol \
|
||||||
|
libgtk-3-dev gtk-3-examples \
|
||||||
|
xauth dbus-x11 \
|
||||||
|
samba
|
||||||
|
|
||||||
|
# === SAMBA CONFIGURATION ===
|
||||||
|
sudo nano /etc/samba/smb.conf
|
||||||
|
# Add at the end of the file:
|
||||||
|
# [RaspberryPiNAS]
|
||||||
|
# path = /home/pi/Public
|
||||||
|
# comment = Pi Share
|
||||||
|
# browseable = yes
|
||||||
|
# writeable = yes
|
||||||
|
# guest ok = no
|
||||||
|
# valid users = pi
|
||||||
|
|
||||||
|
# Set permissions
|
||||||
|
chmod 755 /home/pi
|
||||||
|
mkdir -p /home/pi/Public
|
||||||
|
chmod 777 /home/pi/Public
|
||||||
|
chown -R pi:pi /home/pi/Public
|
||||||
|
|
||||||
|
# Set Samba password for pi
|
||||||
|
sudo smbpasswd -a pi
|
||||||
|
|
||||||
|
# Restart Samba
|
||||||
|
sudo systemctl restart smbd
|
||||||
|
|
||||||
|
# === PULSEAUDIO SYSTEM-WIDE SERVICE ===
|
||||||
|
sudo nano /etc/systemd/system/pulseaudio.service
|
||||||
|
# Paste this content:
|
||||||
|
# [Unit]
|
||||||
|
# Description=PulseAudio System-wide Daemon
|
||||||
|
# After=sound.target network.target
|
||||||
|
#
|
||||||
|
# [Service]
|
||||||
|
# Type=simple
|
||||||
|
# ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading=0 --daemonize=no
|
||||||
|
# Restart=always
|
||||||
|
#
|
||||||
|
# [Install]
|
||||||
|
# WantedBy=multi-user.target
|
||||||
|
|
||||||
|
# === PULSEAUDIO MODULES FOR LEXICON LAMBDA USB ===
|
||||||
|
sudo nano /etc/pulse/system.pa
|
||||||
|
# Comment out:
|
||||||
|
# load-module module-udev-detect
|
||||||
|
# load-module module-detect
|
||||||
|
# Add this at the bottom:
|
||||||
|
# load-module module-alsa-sink device=hw:1,0 sink_name=LambdaOutput sink_properties=device.description="Lexicon_Lambda_USB_Output"
|
||||||
|
# load-module module-alsa-source device=hw:1,0 source_name=LambdaInput source_properties=device.description="Lexicon_Lambda_USB_Input"
|
||||||
|
# load-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/pulseaudio.socket
|
||||||
|
|
||||||
|
# Set client default socket
|
||||||
|
sudo nano /etc/pulse/client.conf
|
||||||
|
# Add this line:
|
||||||
|
# default-server = unix:/tmp/pulseaudio.socket
|
||||||
|
|
||||||
|
# Enable and start PulseAudio system-wide
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable pulseaudio.service
|
||||||
|
sudo systemctl restart pulseaudio.service
|
||||||
|
|
||||||
|
# === X11 & GUI FIXES FOR SSH/MOBAXTERM ===
|
||||||
|
sudo nano /etc/ssh/sshd_config
|
||||||
|
# Ensure these lines are present:
|
||||||
|
# X11Forwarding yes
|
||||||
|
# X11UseLocalhost no
|
||||||
|
# XAuthLocation /usr/bin/xauth
|
||||||
|
|
||||||
|
# Restart SSH
|
||||||
|
sudo systemctl restart ssh
|
||||||
|
|
||||||
|
# Ensure xauth is installed
|
||||||
|
sudo apt install -y xauth
|
||||||
|
|
||||||
|
# === BASHRC: MAKE GUI EXPORTS PERSISTENT ===
|
||||||
|
nano ~/.bashrc
|
||||||
|
# Add this at the end:
|
||||||
|
# export GDK_BACKEND=x11
|
||||||
|
# export LIBGL_ALWAYS_INDIRECT=1
|
||||||
|
# export NO_AT_BRIDGE=1
|
||||||
|
# export $(dbus-launch)
|
||||||
|
|
||||||
|
# Reload bashrc immediately
|
||||||
|
source ~/.bashrc
|
||||||
|
|
||||||
|
# === TESTING GUI ===
|
||||||
|
# (Reconnect via MobaXterm SSH with X11 forwarding enabled before running below)
|
||||||
|
|
||||||
|
# Run pavucontrol GUI
|
||||||
|
pavucontrol &
|
||||||
|
|
||||||
|
# Optional: Test GTK GUI rendering
|
||||||
|
gtk3-demo &
|
||||||
|
|
||||||
|
# Check audio devices
|
||||||
|
pactl list sinks short
|
||||||
|
pactl list sources short
|
||||||
+5
-1
@@ -16,6 +16,7 @@ from constants import (
|
|||||||
MUSIC_FOLDER,
|
MUSIC_FOLDER,
|
||||||
SEND_MP3,
|
SEND_MP3,
|
||||||
SPOTIFY_CTRL,
|
SPOTIFY_CTRL,
|
||||||
|
YOUTUBE_AUTH,
|
||||||
)
|
)
|
||||||
from spotify_dl import spotify
|
from spotify_dl import spotify
|
||||||
from spotify_dl import youtube as youtube_download
|
from spotify_dl import youtube as youtube_download
|
||||||
@@ -161,6 +162,7 @@ async def get_file(ctx, source, link):
|
|||||||
file_name_f=file_name_f,
|
file_name_f=file_name_f,
|
||||||
multi_core=0,
|
multi_core=0,
|
||||||
proxy="",
|
proxy="",
|
||||||
|
YT_AUTH = YOUTUBE_AUTH
|
||||||
)
|
)
|
||||||
_ = await coro
|
_ = await coro
|
||||||
logger.info("YT-DL done")
|
logger.info("YT-DL done")
|
||||||
@@ -203,6 +205,8 @@ async def get_file(ctx, source, link):
|
|||||||
else:
|
else:
|
||||||
dir_path = "/home/pi/RetroPie/mp3/Youtube"
|
dir_path = "/home/pi/RetroPie/mp3/Youtube"
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
|
"username": YOUTUBE_AUTH[0],
|
||||||
|
"password": YOUTUBE_AUTH[1],
|
||||||
"proxy": "",
|
"proxy": "",
|
||||||
"default_search": "ytsearch",
|
"default_search": "ytsearch",
|
||||||
"format": "bestaudio/best",
|
"format": "bestaudio/best",
|
||||||
@@ -258,7 +262,7 @@ async def get_file(ctx, source, link):
|
|||||||
]
|
]
|
||||||
# TODO: Make sponsorblock work
|
# TODO: Make sponsorblock work
|
||||||
sponsorblock_postprocessor = []
|
sponsorblock_postprocessor = []
|
||||||
dir_path = "/home/pi/RetroPie/movies/porn"
|
dir_path = "/home/pi/MediaShare/movies/porn"
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
"postprocessors": sponsorblock_postprocessor,
|
"postprocessors": sponsorblock_postprocessor,
|
||||||
"paths": {"home": dir_path},
|
"paths": {"home": dir_path},
|
||||||
|
|||||||
@@ -66,6 +66,22 @@ class OtherModule(commands.Cog):
|
|||||||
"""
|
"""
|
||||||
await ctx.send(historia_fabryczki)
|
await ctx.send(historia_fabryczki)
|
||||||
|
|
||||||
|
@commands.hybrid_command(
|
||||||
|
name="set_logging_level",
|
||||||
|
description="Nie intererer bo kici kici",
|
||||||
|
guild=discord.Object(id=664789470779932693),
|
||||||
|
)
|
||||||
|
@commands.has_any_role('Legenda', 'Jarl', 'Bartender')
|
||||||
|
async def set_logging_level(self,ctx):
|
||||||
|
if "DEBUG" in ctx.message.content:
|
||||||
|
logger = logging.getLogger("discord")
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
elif "INFO" in ctx.message.content:
|
||||||
|
logger = logging.getLogger("discord")
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
else:
|
||||||
|
await ctx.send("Weź się kurwa zdecyduj co ?")
|
||||||
|
|
||||||
@commands.hybrid_command(
|
@commands.hybrid_command(
|
||||||
name="reset_the_clock",
|
name="reset_the_clock",
|
||||||
description="Resetowanie zegara - dostępne wyłącznie dla Hammera",
|
description="Resetowanie zegara - dostępne wyłącznie dla Hammera",
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=PulseAudio System-wide Daemon
|
||||||
|
After=sound.target network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading=0 --daemonize=no
|
||||||
|
Restart=always
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -17,4 +17,4 @@ waitress
|
|||||||
clickupython
|
clickupython
|
||||||
assemblyai[extras]
|
assemblyai[extras]
|
||||||
SpeechRecognition
|
SpeechRecognition
|
||||||
git+https://github.com/imayhaveborkedit/discord-ext-voice-recvO
|
git+https://github.com/imayhaveborkedit/discord-ext-voice-recv
|
||||||
|
|||||||
@@ -8,5 +8,7 @@ def signal_handler(sig, frame):
|
|||||||
print("\nCaught interrupt(did you press Ctrl+C?), stopping spotify_dl")
|
print("\nCaught interrupt(did you press Ctrl+C?), stopping spotify_dl")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
try:
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
except ValueError:
|
||||||
|
print("Exception in signal handler")
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
__all__ = ["VERSION"]
|
__all__ = ["VERSION"]
|
||||||
|
|
||||||
VERSION = "8.8.1"
|
VERSION = "8.9.0"
|
||||||
|
|
||||||
if os.getenv("XDG_CACHE_HOME") is not None:
|
if os.getenv("XDG_CACHE_HOME") is not None:
|
||||||
SAVE_PATH = os.getenv("XDG_CACHE_HOME") + "/spotifydl"
|
SAVE_PATH = os.getenv("XDG_CACHE_HOME") + "/spotifydl"
|
||||||
|
|||||||
+52
-16
@@ -1,15 +1,17 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import logging
|
||||||
from spotify_dl.scaffold import log
|
from spotify_dl.scaffold import log
|
||||||
from spotify_dl.utils import sanitize
|
from spotify_dl.utils import sanitize
|
||||||
from rich.progress import Progress
|
from rich.progress import Progress
|
||||||
|
|
||||||
|
|
||||||
def fetch_tracks(sp, item_type, url):
|
def fetch_tracks(sp, item_type, item_id):
|
||||||
"""
|
"""
|
||||||
Fetches tracks from the provided URL.
|
Fetches tracks from the provided item_id.
|
||||||
:param sp: Spotify client
|
:param sp: Spotify client
|
||||||
:param item_type: Type of item being requested for: album/playlist/track
|
:param item_type: Type of item being requested for: album/playlist/track
|
||||||
:param url: URL of the item
|
:param item_id: id of the item
|
||||||
:return Dictionary of song and artist
|
:return Dictionary of song and artist
|
||||||
"""
|
"""
|
||||||
songs_list = []
|
songs_list = []
|
||||||
@@ -17,11 +19,14 @@ def fetch_tracks(sp, item_type, url):
|
|||||||
songs_fetched = 0
|
songs_fetched = 0
|
||||||
|
|
||||||
if item_type == "playlist":
|
if item_type == "playlist":
|
||||||
|
logger = logging.getLogger("discord")
|
||||||
|
|
||||||
|
logger.info("Playlist")
|
||||||
with Progress() as progress:
|
with Progress() as progress:
|
||||||
songs_task = progress.add_task(description="Fetching songs from playlist..")
|
songs_task = progress.add_task(description="Fetching songs from playlist..")
|
||||||
while True:
|
while True:
|
||||||
items = sp.playlist_items(
|
items = sp.playlist_items(
|
||||||
playlist_id=url,
|
playlist_id=item_id,
|
||||||
fields="items.track.name,items.track.artists(name, uri),"
|
fields="items.track.name,items.track.artists(name, uri),"
|
||||||
"items.track.album(name, release_date, total_tracks, images),"
|
"items.track.album(name, release_date, total_tracks, images),"
|
||||||
"items.track.track_number,total, next,offset,"
|
"items.track.track_number,total, next,offset,"
|
||||||
@@ -30,6 +35,7 @@ def fetch_tracks(sp, item_type, url):
|
|||||||
offset=offset,
|
offset=offset,
|
||||||
)
|
)
|
||||||
total_songs = items.get("total")
|
total_songs = items.get("total")
|
||||||
|
logger.info(total_songs)
|
||||||
track_info_task = progress.add_task(
|
track_info_task = progress.add_task(
|
||||||
description="Fetching track info", total=len(items["items"])
|
description="Fetching track info", total=len(items["items"])
|
||||||
)
|
)
|
||||||
@@ -37,16 +43,32 @@ def fetch_tracks(sp, item_type, url):
|
|||||||
track_info = item.get("track")
|
track_info = item.get("track")
|
||||||
# If the user has a podcast in their playlist, there will be no track
|
# If the user has a podcast in their playlist, there will be no track
|
||||||
# Without this conditional, the program will fail later on when the metadata is fetched
|
# Without this conditional, the program will fail later on when the metadata is fetched
|
||||||
|
logger.info(item)
|
||||||
if track_info is None:
|
if track_info is None:
|
||||||
offset += 1
|
offset += 1
|
||||||
continue
|
continue
|
||||||
|
if not track_info.get("artists")[0]["name"]:
|
||||||
|
offset +=1
|
||||||
|
continue
|
||||||
track_album_info = track_info.get("album")
|
track_album_info = track_info.get("album")
|
||||||
track_num = track_info.get("track_number")
|
track_num = track_info.get("track_number")
|
||||||
spotify_id = track_info.get("id")
|
|
||||||
track_name = track_info.get("name")
|
track_name = track_info.get("name")
|
||||||
track_artist = ", ".join(
|
spotify_id = track_info.get("id")
|
||||||
[artist["name"] for artist in track_info.get("artists")]
|
track_audio_data = "No audio data"
|
||||||
)
|
try:
|
||||||
|
track_audio_data = sp.audio_analysis(spotify_id)
|
||||||
|
tempo = track_audio_data.get("track").get("tempo")
|
||||||
|
except:
|
||||||
|
log.error("Couldn't fetch audio analysis for %s", track_name)
|
||||||
|
tempo = None
|
||||||
|
print(track_info.get("artists"))
|
||||||
|
print(track_audio_data)
|
||||||
|
track_artist = ""
|
||||||
|
for artist in track_info.get("artists"):
|
||||||
|
if artist["name"]:
|
||||||
|
track_artist = ", ".join(
|
||||||
|
[artist["name"]]
|
||||||
|
)
|
||||||
if track_album_info:
|
if track_album_info:
|
||||||
track_album = track_album_info.get("name")
|
track_album = track_album_info.get("name")
|
||||||
track_year = (
|
track_year = (
|
||||||
@@ -86,6 +108,7 @@ def fetch_tracks(sp, item_type, url):
|
|||||||
"genre": genre,
|
"genre": genre,
|
||||||
"spotify_id": spotify_id,
|
"spotify_id": spotify_id,
|
||||||
"track_url": None,
|
"track_url": None,
|
||||||
|
"tempo": tempo,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
offset += 1
|
offset += 1
|
||||||
@@ -111,8 +134,8 @@ def fetch_tracks(sp, item_type, url):
|
|||||||
description="Fetching songs from the album.."
|
description="Fetching songs from the album.."
|
||||||
)
|
)
|
||||||
while True:
|
while True:
|
||||||
album_info = sp.album(album_id=url)
|
album_info = sp.album(album_id=item_id)
|
||||||
items = sp.album_tracks(album_id=url, offset=offset)
|
items = sp.album_tracks(album_id=item_id, offset=offset)
|
||||||
total_songs = items.get("total")
|
total_songs = items.get("total")
|
||||||
track_album = album_info.get("name")
|
track_album = album_info.get("name")
|
||||||
track_year = (
|
track_year = (
|
||||||
@@ -141,6 +164,12 @@ def fetch_tracks(sp, item_type, url):
|
|||||||
)
|
)
|
||||||
track_num = item["track_number"]
|
track_num = item["track_number"]
|
||||||
spotify_id = item.get("id")
|
spotify_id = item.get("id")
|
||||||
|
try:
|
||||||
|
track_audio_data = sp.audio_analysis(spotify_id)
|
||||||
|
tempo = track_audio_data.get("track").get("tempo")
|
||||||
|
except:
|
||||||
|
log.error("Couldn't fetch audio analysis for %s", track_name)
|
||||||
|
tempo = None
|
||||||
songs_list.append(
|
songs_list.append(
|
||||||
{
|
{
|
||||||
"name": track_name,
|
"name": track_name,
|
||||||
@@ -154,6 +183,7 @@ def fetch_tracks(sp, item_type, url):
|
|||||||
"cover": cover,
|
"cover": cover,
|
||||||
"genre": genre,
|
"genre": genre,
|
||||||
"spotify_id": spotify_id,
|
"spotify_id": spotify_id,
|
||||||
|
"tempo": tempo,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
offset += 1
|
offset += 1
|
||||||
@@ -168,7 +198,7 @@ def fetch_tracks(sp, item_type, url):
|
|||||||
break
|
break
|
||||||
|
|
||||||
elif item_type == "track":
|
elif item_type == "track":
|
||||||
items = sp.track(track_id=url)
|
items = sp.track(track_id=item_id)
|
||||||
track_name = items.get("name")
|
track_name = items.get("name")
|
||||||
album_info = items.get("album")
|
album_info = items.get("album")
|
||||||
track_artist = ", ".join([artist["name"] for artist in items["artists"]])
|
track_artist = ", ".join([artist["name"] for artist in items["artists"]])
|
||||||
@@ -182,6 +212,12 @@ def fetch_tracks(sp, item_type, url):
|
|||||||
album_total = album_info.get("total_tracks")
|
album_total = album_info.get("total_tracks")
|
||||||
track_num = items["track_number"]
|
track_num = items["track_number"]
|
||||||
spotify_id = items["id"]
|
spotify_id = items["id"]
|
||||||
|
try:
|
||||||
|
track_audio_data = sp.audio_analysis(spotify_id)
|
||||||
|
tempo = track_audio_data.get("track").get("tempo")
|
||||||
|
except:
|
||||||
|
log.error("Couldn't fetch audio analysis for %s", track_name)
|
||||||
|
tempo = None
|
||||||
if len(items["album"]["images"]) > 0:
|
if len(items["album"]["images"]) > 0:
|
||||||
cover = items["album"]["images"][0]["url"]
|
cover = items["album"]["images"][0]["url"]
|
||||||
else:
|
else:
|
||||||
@@ -203,6 +239,7 @@ def fetch_tracks(sp, item_type, url):
|
|||||||
"genre": genre,
|
"genre": genre,
|
||||||
"track_url": None,
|
"track_url": None,
|
||||||
"spotify_id": spotify_id,
|
"spotify_id": spotify_id,
|
||||||
|
"tempo": tempo,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -219,9 +256,10 @@ def parse_spotify_url(url):
|
|||||||
if url.startswith("spotify:"):
|
if url.startswith("spotify:"):
|
||||||
log.error("Spotify URI was provided instead of a playlist/album/track URL.")
|
log.error("Spotify URI was provided instead of a playlist/album/track URL.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
parsed_url = url.replace("https://open.spotify.com/", "").split("?")[0]
|
parsed_url = url.replace("https://open.spotify.com/", "").split("?")[0].split("/")
|
||||||
item_type = parsed_url.split("/")[0]
|
index_adjustment = 1 if parsed_url[0].startswith("intl") else 0
|
||||||
item_id = parsed_url.split("/")[1]
|
item_type = parsed_url[0+index_adjustment]
|
||||||
|
item_id = parsed_url[1+index_adjustment]
|
||||||
return item_type, item_id
|
return item_type, item_id
|
||||||
|
|
||||||
|
|
||||||
@@ -239,8 +277,6 @@ def get_item_name(sp, item_type, item_id):
|
|||||||
name = sp.album(album_id=item_id).get("name")
|
name = sp.album(album_id=item_id).get("name")
|
||||||
elif item_type == "track":
|
elif item_type == "track":
|
||||||
name = sp.track(track_id=item_id).get("name")
|
name = sp.track(track_id=item_id).get("name")
|
||||||
elif item_type == "artist_top_tracks":
|
|
||||||
name = sp.artist_top_tracks(artist_id=item_id).get("name")
|
|
||||||
return sanitize(name)
|
return sanitize(name)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ def spotify_dl():
|
|||||||
)
|
)
|
||||||
url_dict["save_path"].mkdir(parents=True, exist_ok=True)
|
url_dict["save_path"].mkdir(parents=True, exist_ok=True)
|
||||||
log.info("Saving songs to %s directory", directory_name)
|
log.info("Saving songs to %s directory", directory_name)
|
||||||
url_dict["songs"] = fetch_tracks(sp, item_type, url)
|
url_dict["songs"] = fetch_tracks(sp, item_type, item_id)
|
||||||
url_data["urls"].append(url_dict.copy())
|
url_data["urls"].append(url_dict.copy())
|
||||||
if args.dump_json is True:
|
if args.dump_json is True:
|
||||||
dump_json(url_dict["songs"])
|
dump_json(url_dict["songs"])
|
||||||
|
|||||||
+11
-11
@@ -1,9 +1,9 @@
|
|||||||
|
import shutil
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from os import path
|
from os import path
|
||||||
import os
|
import os
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
import shutil
|
|
||||||
import json
|
import json
|
||||||
import mutagen
|
import mutagen
|
||||||
import csv
|
import csv
|
||||||
@@ -65,13 +65,13 @@ def write_tracks(tracks_file, song_dict):
|
|||||||
i = 0
|
i = 0
|
||||||
writer = csv.writer(file_out, delimiter=";")
|
writer = csv.writer(file_out, delimiter=";")
|
||||||
for url_dict in song_dict["urls"]:
|
for url_dict in song_dict["urls"]:
|
||||||
# for track in url_dict['songs']:
|
|
||||||
for track in url_dict["songs"]:
|
for track in url_dict["songs"]:
|
||||||
track_url = track["track_url"] # here
|
track_url = track["track_url"] # here
|
||||||
track_name = track["name"]
|
track_name = track["name"]
|
||||||
track_artist = track["artist"]
|
track_artist = track["artist"]
|
||||||
track_num = track["num"]
|
track_num = track["num"]
|
||||||
track_album = track["album"]
|
track_album = track["album"]
|
||||||
|
track_tempo = track["tempo"]
|
||||||
track["save_path"] = url_dict["save_path"]
|
track["save_path"] = url_dict["save_path"]
|
||||||
track_db.append(track)
|
track_db.append(track)
|
||||||
track_index = i
|
track_index = i
|
||||||
@@ -82,6 +82,7 @@ def write_tracks(tracks_file, song_dict):
|
|||||||
track_url,
|
track_url,
|
||||||
str(track_num),
|
str(track_num),
|
||||||
track_album,
|
track_album,
|
||||||
|
str(track_tempo),
|
||||||
str(track_index),
|
str(track_index),
|
||||||
]
|
]
|
||||||
try:
|
try:
|
||||||
@@ -97,8 +98,8 @@ def write_tracks(tracks_file, song_dict):
|
|||||||
def set_tags(temp, filename, kwargs):
|
def set_tags(temp, filename, kwargs):
|
||||||
"""
|
"""
|
||||||
sets song tags after they are downloaded
|
sets song tags after they are downloaded
|
||||||
:param temp: contains index used to obtain more info about song being edited
|
:param temp: contains index used to obtain more info about song being editted
|
||||||
:param filename: location of song whose tags are to be edited
|
:param filename: location of song whose tags are to be editted
|
||||||
:param kwargs: a dictionary of extra arguments to be used in tag editing
|
:param kwargs: a dictionary of extra arguments to be used in tag editing
|
||||||
"""
|
"""
|
||||||
song = kwargs["track_db"][int(temp[-1])]
|
song = kwargs["track_db"][int(temp[-1])]
|
||||||
@@ -120,6 +121,8 @@ def set_tags(temp, filename, kwargs):
|
|||||||
)
|
)
|
||||||
|
|
||||||
song_file["genre"] = song.get("genre")
|
song_file["genre"] = song.get("genre")
|
||||||
|
if song.get("tempo") is not None:
|
||||||
|
song_file["bpm"] = str(song.get("tempo"))
|
||||||
song_file.save()
|
song_file.save()
|
||||||
song_file = MP3(filename, ID3=ID3)
|
song_file = MP3(filename, ID3=ID3)
|
||||||
cover = song.get("cover")
|
cover = song.get("cover")
|
||||||
@@ -162,7 +165,7 @@ def find_and_download_songs(kwargs):
|
|||||||
print(f"Initiating download for {query}.")
|
print(f"Initiating download for {query}.")
|
||||||
|
|
||||||
file_name = kwargs["file_name_f"](
|
file_name = kwargs["file_name_f"](
|
||||||
name=name, artist=artist, track_num=kwargs["track_db"][i].get("num")
|
name=name, artist=artist, track_num=kwargs["track_db"][i].get("playlist_num")
|
||||||
)
|
)
|
||||||
|
|
||||||
if kwargs["use_sponsorblock"][0].lower() == "y":
|
if kwargs["use_sponsorblock"][0].lower() == "y":
|
||||||
@@ -197,9 +200,10 @@ def find_and_download_songs(kwargs):
|
|||||||
):
|
):
|
||||||
print(f"File {mp3file_path} already exists, we do not overwrite it ")
|
print(f"File {mp3file_path} already exists, we do not overwrite it ")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
outtmpl = f"{file_path}.%(ext)s"
|
outtmpl = f"{file_path}.%(ext)s"
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
|
"username":kwargs["YT_AUTH"][0],
|
||||||
|
"password":kwargs["YT_AUTH"][1],
|
||||||
"proxy": kwargs.get("proxy"),
|
"proxy": kwargs.get("proxy"),
|
||||||
"default_search": "ytsearch",
|
"default_search": "ytsearch",
|
||||||
"format": "bestaudio/best",
|
"format": "bestaudio/best",
|
||||||
@@ -312,11 +316,7 @@ def download_songs(**kwargs):
|
|||||||
log.debug("Downloading to %s", url["save_path"])
|
log.debug("Downloading to %s", url["save_path"])
|
||||||
reference_file = DOWNLOAD_LIST
|
reference_file = DOWNLOAD_LIST
|
||||||
track_db = write_tracks(reference_file, kwargs["songs"])
|
track_db = write_tracks(reference_file, kwargs["songs"])
|
||||||
try:
|
shutil.copy(reference_file, kwargs["output_dir"] + "/" + reference_file)
|
||||||
shutil.copy(reference_file, kwargs["output_dir"] + "/" + reference_file)
|
|
||||||
os.remove(reference_file)
|
|
||||||
except:
|
|
||||||
os.rename(reference_file, kwargs["output_dir"] + "/" + reference_file)
|
|
||||||
reference_file = str(kwargs["output_dir"]) + "/" + reference_file
|
reference_file = str(kwargs["output_dir"]) + "/" + reference_file
|
||||||
kwargs["reference_file"] = reference_file
|
kwargs["reference_file"] = reference_file
|
||||||
kwargs["track_db"] = track_db
|
kwargs["track_db"] = track_db
|
||||||
|
|||||||
Regular → Executable
+2
-2
@@ -75,8 +75,8 @@ async def on_ready():
|
|||||||
for com in client.commands:
|
for com in client.commands:
|
||||||
logger.info("Command %s is awejleble", com.qualified_name)
|
logger.info("Command %s is awejleble", com.qualified_name)
|
||||||
|
|
||||||
logger.info("Logged in as ---->", client.user)
|
logger.info("Logged in as ----> %s", client.user)
|
||||||
logger.info("ID:", client.user.id)
|
logger.info("ID:%s ", client.user.id)
|
||||||
logger.info("All systems: operational")
|
logger.info("All systems: operational")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user