jo1gi / audiobook-dl

Audiobook CLI downloader
GNU General Public License v3.0
242 stars 42 forks source link

bash script for linux #124

Open msebastian100 opened 3 months ago

msebastian100 commented 3 months ago

Hello, I have created a bash script for linux but although the commands are correct I can't get a login.

The command would be correct and works under windows. unfortunately not under linux

audiobook-dl --username "basti-xxxxxxx@malxxx.de" --password "xxxxxxxxxxxx" https://www.storytel.com/de/books/der-sturm-vernichtet-engelhardt-krieger-ermitteln-band-6-ungek%C3%BCrzte-lesung-8823385

linux script create with nano audiobookdl.sh then chmod +x audiobookdl.sh then ./audiobookdl.sh

Supported for now: storytel

Debug log linux:

Running audiobook-dl command... DEBUG audiobook-dl 0.7.3 DEBUG python 3.10.12 (main, Mar 22 2024, 16:50:05) [GCC 11.4.0] INFO Finding compatible source INFO Authenticating with storytel DEBUG Logging in ERROR: User not authorized

Make sure you have given the correct cookies with the --cookie argument or with --username and --password, and have all the right permissions to access the book you are trying to download.

Traceback Traceback (most recent call last): File "/root/venv/lib/python3.10/site-packages/audiobookdl/main.py", line 31, in main process_url(url, options, config) File "/root/venv/lib/python3.10/site-packages/audiobookdl/main.py", line 51, in process_url authenticate(url, source, options, config) File "/root/venv/lib/python3.10/site-packages/audiobookdl/main.py", line 134, in authenticate login(url, source, options, config) File "/root/venv/lib/python3.10/site-packages/audiobookdl/main.py", line 115, in login source.login(url, login_data) File "/root/venv/lib/python3.10/site-packages/audiobookdl/sources/source/init.py", line 86, in login self._login(url, kwargs) File "/root/venv/lib/python3.10/site-packages/audiobookdl/sources/storytel.py", line 53, in _login raise UserNotAuthorized audiobookdl.exceptions.UserNotAuthorized

bash Script;

#!/bin/bash

# Exit script on any error
set -e

# Logfile setup
LOGFILE="audiobook_dl_installation.log"
exec &> >(tee -a "$LOGFILE")

echo "Logfile: $LOGFILE"

# Update package lists
echo "Updating package lists..."
sudo apt update

# Function to check if a package is installed
is_installed() {
    dpkg -l | grep -qw "$1"
}

# Check and install system packages
packages_installed=true

echo "Checking and installing system packages..."

if ! is_installed python3; then
    echo "Installing Python3..."
    sudo apt install -y python3
    packages_installed=false
fi

if ! is_installed python3-pip; then
    echo "Installing python3-pip..."
    sudo apt install -y python3-pip
    packages_installed=false
fi

if ! is_installed python3-venv; then
    echo "Installing python3-venv..."
    sudo apt install -y python3-venv
    packages_installed=false
fi

if [ "$packages_installed" = true ]; then
    echo "System dependencies already installed."
else
    echo "System dependencies installed."
fi

# Create virtual environment if not already existing
if [ ! -d "venv" ]; then
    echo "Creating virtual environment..."
    python3 -m venv venv
else
    echo "Virtual environment already exists."
fi

# Activate virtual environment
echo "Activating virtual environment..."
source venv/bin/activate

# Upgrade pip in the virtual environment
echo "Upgrading pip..."
pip install --upgrade pip > /dev/null 2>&1

# Function to check if a Python package is installed in the virtual environment
pip_installed() {
    pip show "$1" &> /dev/null
}

# List of required Python packages
required_packages=(appdirs attrs cssselect importlib-resources lxml m3u8 mutagen pillow pycountry pycryptodome requests rich tomli urllib3)

# Check and install required Python packages
all_packages_installed=true

echo "Checking and installing Python packages..."

for package in "${required_packages[@]}"; do
    if ! pip_installed "$package"; then
        echo "Installing $package..."
        pip install "$package" > /dev/null 2>&1
        all_packages_installed=false
    fi
done

# Check and install audiobook-dl
if ! pip_installed audiobook-dl; then
    echo "Installing audiobook-dl..."
    pip install audiobook-dl > /dev/null 2>&1
    all_packages_installed=false
fi

if [ "$all_packages_installed" = true ]; then
    echo "Python dependencies and audiobook-dl already installed."
else
    echo "Python dependencies and audiobook-dl installed."
fi

# Prompt for username, password, and URL
read -p "Enter your username: " USERNAME
read -p "Enter your password (will be shown in cleartext): " PASSWORD
read -p "Enter the URL: " URL

# Log the username and URL
echo "Username: $USERNAME" >> "$LOGFILE"
echo "URL: $URL" >> "$LOGFILE"

# Run audiobook-dl command
echo "Running audiobook-dl command..."
audiobook-dl --username "$USERNAME" --password "$PASSWORD" "$URL"

echo "Script completed successfully."

greetings msebastian100

freddy36 commented 2 months ago

Is this still a problem with the latest version (v0.7.5?