resolved merge conficts

This commit is contained in:
Raju komati 2021-10-25 10:07:06 +05:30
commit 2454d50913
No known key found for this signature in database
GPG Key ID: D0390D7534A9E462
14 changed files with 172 additions and 133 deletions

3
.gitignore vendored
View File

@ -151,3 +151,6 @@ ZSpotify\ Podcasts/
# Intellij
.idea
# Config file
zs_config.json

84
CHANGELOG.md Normal file
View File

@ -0,0 +1,84 @@
## **Changelog:**
**v2.2 (24 Oct 2021):**
- Added basic support for downloading an entire podcast series.
- Split code into multiple files for easier maintenance.
- Changed initial launch script to app.py
- Simplified audio formats.
- Added prebuild exe for Windows users.
- Added Docker file.
- Added CONTRIBUTING.md.
- Fixed artist names getting cutoff in metadata.
- Removed data sanitization of metadata tags.
**v2.1 (23 Oct 2021):**
- Moved configuration from hard-coded values to separate zs_config.json file.
- Add subfolders for each disc.
- Can now search and download all songs by artist.
- Show single progress bar for entire album.
- Added song number at start of track name in albums.
**v2.0 (22 Oct 2021):**
- Added progress bar for downloads.
- Added multi-select support for all results when searching.
- Added GPLv3 Licence.
- Changed welcome banner and removed unnecessary debug print statements.
**v1.9 (22 Oct 2021):**
- Added Gitea mirror for when the Spotify Glowies come to DMCA the shit out of this.
- Changed the discord server invite to a matrix server so that won't get swatted either.
- Added option to select multiple of our saved playlists to download at once.
- Added support for downloading an entire show at once.
**v1.8 (21 Oct 2021):**
- Improved podcast downloading a bit.
- Simplified the code that catches crashes while downloading.
- Cleaned up code using linter again.
- Added option to just paste a url in the search bar to download it.
- Added a small delay between downloading each track when downloading in bulk to help with downloading issues and potential bans.
**v1.7 (21 Oct 2021):**
- Rewrote README.md to look a lot more professional.
- Added patch to fix edge case crash when downloading liked songs.
- Made premium account check a lot more reliable.
- Added experimental podcast support for specific episodes!
**v1.6 (20 Oct 2021):**
- Added Pillow to requirements.txt.
- Removed websocket-client from requirements.txt because librespot-python added it to their dependency list.
- Made it hide your password when you type it in.
- Added manual override to force premium quality if zspotify cannot auto detect it.
- Added option to just download the raw audio with no re-encoding at all.
- Added Shebang line so it runs smoother on Linux.
- Made it download the entire track at once now so it is more efficient and fixed a bug users encountered.
**v1.5 (19 Oct 2021):**
- Made downloading a lot more efficient and probably faster.
- Made the sanitizer more efficient.
- Formatted and linted all the code.
**v1.4 (19 Oct 2021):**
- Added option to encode the downloaded tracks in the "ogg" format rather than "mp3".
- Added small improvement to sanitation function so it catches another edge case.
**v1.3 (19 Oct 2021):**
- Added auto detection about if the current account is premium or not. If it is a premium account it automatically sets the quality to VERY_HIGH and otherwise HIGH if we are using a free account.
- Fixed conversion function so it now exports to the correct bitrate.
- Added sanitation to playlist names to help catch an edge case crash.
- Added option to download all your liked songs into a sub-folder.
**v1.2 (18 Oct 2021):**
- Added .gitignore.
- Replaced dependency list in README.md with a proper requirements.txt file.
- Improved the readability of README.md.
**v1.1 (16 Oct 2021):**
- Added try/except to help catch crashes where a very few specific tracks would crash either the downloading or conversion part.
**v1.0 (14 Oct 2021):**
- Adjusted some functions so it runs again with the newer version of librespot-python.
- Improved my sanitization function so it catches more edge cases.
- Fixed an issue where sometimes spotify wouldn't provide a song id for a track we are trying to download. It will now detect and skip these invalid tracks.
- Added additional check for tracks that cannot be "played" due to licence(and similar) issues. These tracks will be skipped.
**v0.9 (13 Oct 2021):**
- Initial upload, needs adjustments to get working again after backend rewrite.

View File

@ -14,7 +14,8 @@ ZSpotify is a community-driven project. There are many different ways to contrib
### What we aren't looking for
Please don't use the issues section to request help installing or setting up the project. It should be reserved for bugs when running the code, and feature requqests. Instead use the support channel in either our Discord or Matrix server.
Please don't use the issues section to request help installing or setting up the project. It should be reserved for bugs when running the code, and feature requests. Instead use the support channel in either our Discord or Matrix server.
Please do not make a new pull request just to fix a typo or any small issue like that. We'd rather you just make an issue reporting it and we will fix it in the next commit. This helps to prevent commit spamming.
# Ground rules

View File

@ -13,7 +13,7 @@ RUN apk add gcc libc-dev zlib zlib-dev jpeg-dev \
FROM base
COPY --from=builder /install /usr/local
COPY src /app
COPY zspotify /app
COPY zs_config.json /
WORKDIR /app
ENTRYPOINT ["/usr/local/bin/python", "app.py"]
ENTRYPOINT ["/usr/local/bin/python", "__main__.py"]

112
README.md
View File

@ -24,14 +24,16 @@ Python packages:
```
\*ffmpeg can be installed via apt for Debian-based distros or by downloading the binaries from [ffmpeg.org](https://ffmpeg.org) and placing them in your %PATH% in Windows.
\*ffmpeg can be installed via apt for Debian-based distros or by downloading the binaries from [ffmpeg.org](https://ffmpeg.org) and placing them in your %PATH% in Windows. Mac users can install it with [Homebrew](https://brew.sh) by running `brew install ffmpeg`.
\*\*Git can be installed via apt for Debian-based distros or by downloading the binaries from [git-scm.com](https://git-scm.com/download/win) for Windows.
### Command line usage:
```
Command line usage:
python app.py Loads search prompt to find then download a specific track, album or playlist
python app.py <track/album/playlist/episode url> Downloads the track, album, playlist or podcast episode specified as a command line argument
python app.py <artist url> Downloads all albums by specified artist
Basic usage:
python zspotify Loads search prompt to find then download a specific track, album or playlist
python zspotify <track/album/playlist/episode url> Downloads the track, album, playlist or podcast episode specified as a command line argument
python zspotify <artist url> Downloads all albums by specified artist
Extra command line options:
-p, --playlist Downloads a saved playlist from your account
@ -43,13 +45,23 @@ Options that can be configured in zs_config.json:
SKIP_EXISTING_FILES Set this to false if you want ZSpotify to overwrite files with the same name rather than skipping the song
MUSIC_FORMAT Can be "mp3" or "ogg", mp3 is required for track metadata however ogg is slightly higer quality as it is not trsnacoded.
MUSIC_FORMAT Can be "mp3" or "ogg", mp3 is required for track metadata however ogg is slightly higher quality as it is not transcoded.
FORCE_PREMIUM Set this to true if ZSpotify isn't automatically detecting that you are using a premium account
ANTI_BAN_WAIT_TIME Change this setting if the time waited between bulk downloads is too high or low
OVERRIDE_AUTO_WAIT Change this to true if you want to completely disable the wait between songs for faster downloads with the risk of instability
```
### Docker Usage
```
Build the docker image from the Dockerfile:
docker build -t zspotify .
Create and run a container from the image:
docker run --rm -v "$PWD/ZSpotify Music:/ZSpotify Music" -v "$PWD/ZSpotify Podcasts:/ZSpotify Podcasts" -it zspotify
```
### Will my account get banned if I use this tool?
Currently no user has reported their account getting banned after using ZSpotify.
This isn't to say _you_ won't get banned as it is technically against Spotify's TOS.
@ -59,89 +71,7 @@ This isn't to say _you_ won't get banned as it is technically against Spotify's
If you see this, don't worry! Just try logging back in. If you see the incorrect username or password error, reset your password and you should be able to log back in and continue using Spotify.
### Contributing
Please refer to CONTRIBUTING.md
Please refer to [CONTRIBUTING](CONTRIBUTING.md)
## **Changelog:**
**v2.2 (24 Oct 2021):**
- Added basic support for downloading an entire podcast series.
- Split code into multiple files for easier maintenance.
- Changed initial launch script to app.py
- Simplified audio formats.
- Added prebuild exe for Windows users.
- Added Docker file.
- Added CONTRIBUTING.md.
- Fixed artist names getting cutoff in metadata.
- Removed data sanitization of metadata tags.
**v2.1 (23 Oct 2021):**
- Moved configuration from hard-coded values to separate zs_config.json file.
- Add subfolders for each disc.
- Can now search and download all songs by artist.
- Show single progress bar for entire album.
- Added song number at start of track name in albums.
**v2.0 (22 Oct 2021):**
- Added progress bar for downloads.
- Added multi-select support for all results when searching.
- Added GPLv3 Licence.
- Changed welcome banner and removed unnecessary debug print statements.
**v1.9 (22 Oct 2021):**
- Added Gitea mirror for when the Spotify Glowies come to DMCA the shit out of this.
- Changed the discord server invite to a matrix server so that won't get swatted either.
- Added option to select multiple of our saved playlists to download at once.
- Added support for downloading an entire show at once.
**v1.8 (21 Oct 2021):**
- Improved podcast downloading a bit.
- Simplified the code that catches crashes while downloading.
- Cleaned up code using linter again.
- Added option to just paste a url in the search bar to download it.
- Added a small delay between downloading each track when downloading in bulk to help with downloading issues and potential bans.
**v1.7 (21 Oct 2021):**
- Rewrote README.md to look a lot more professional.
- Added patch to fix edge case crash when downloading liked songs.
- Made premium account check a lot more reliable.
- Added experimental podcast support for specific episodes!
**v1.6 (20 Oct 2021):**
- Added Pillow to requirements.txt.
- Removed websocket-client from requirements.txt because librespot-python added it to their dependency list.
- Made it hide your password when you type it in.
- Added manual override to force premium quality if zspotify cannot auto detect it.
- Added option to just download the raw audio with no re-encoding at all.
- Added Shebang line so it runs smoother on Linux.
- Made it download the entire track at once now so it is more efficient and fixed a bug users encountered.
**v1.5 (19 Oct 2021):**
- Made downloading a lot more efficient and probably faster.
- Made the sanitizer more efficient.
- Formatted and linted all the code.
**v1.4 (19 Oct 2021):**
- Added option to encode the downloaded tracks in the "ogg" format rather than "mp3".
- Added small improvement to sanitation function so it catches another edge case.
**v1.3 (19 Oct 2021):**
- Added auto detection about if the current account is premium or not. If it is a premium account it automatically sets the quality to VERY_HIGH and otherwise HIGH if we are using a free account.
- Fixed conversion function so it now exports to the correct bitrate.
- Added sanitation to playlist names to help catch an edge case crash.
- Added option to download all your liked songs into a sub-folder.
**v1.2 (18 Oct 2021):**
- Added .gitignore.
- Replaced dependency list in README.md with a proper requirements.txt file.
- Improved the readability of README.md.
**v1.1 (16 Oct 2021):**
- Added try/except to help catch crashes where a very few specific tracks would crash either the downloading or conversion part.
**v1.0 (14 Oct 2021):**
- Adjusted some functions so it runs again with the newer version of librespot-python.
- Improved my sanitization function so it catches more edge cases.
- Fixed an issue where sometimes spotify wouldn't provide a song id for a track we are trying to download. It will now detect and skip these invalid tracks.
- Added additional check for tracks that cannot be "played" due to licence(and similar) issues. These tracks will be skipped.
**v0.9 (13 Oct 2021):**
- Initial upload, needs adjustments to get working again after backend rewrite.
### Changelog
Please refer to [CHANGELOG](CHANGELOG.md)

View File

@ -1,11 +0,0 @@
{
"ROOT_PATH": "../ZSpotify Music/",
"ROOT_PODCAST_PATH": "../ZSpotify Podcasts/",
"SKIP_EXISTING_FILES": true,
"DOWNLOAD_FORMAT": "mp3",
"FORCE_PREMIUM": false,
"ANTI_BAN_WAIT_TIME": 1,
"OVERRIDE_AUTO_WAIT": false,
"CHUNK_SIZE": 50000,
"SPLIT_ALBUM_DISCS": false
}

4
zspotify/__main__.py Normal file
View File

@ -0,0 +1,4 @@
from app import client
if __name__ == '__main__':
client()

View File

@ -37,7 +37,13 @@ def get_artist_albums(artist_id):
""" Returns artist's albums """
resp = ZSpotify.invoke_url(f'{ARTIST_URL}/{artist_id}/albums')
# Return a list each album's id
return [resp[ITEMS][i][ID] for i in range(len(resp[ITEMS]))]
album_ids = [resp[ITEMS][i][ID] for i in range(len(resp[ITEMS]))]
# Recursive requests to get all albums including singles an EPs
while resp['next'] is not None:
resp = ZSpotify.invoke_url(resp['next'])
album_ids.extend([resp[ITEMS][i][ID] for i in range(len(resp[ITEMS]))])
return album_ids
def download_album(album):

View File

@ -162,6 +162,3 @@ def perform_action(tracks: list, albums: list, playlists: list, artists: list,
else:
download_playlist(playlists, position - total_tracks - total_albums - total_artists)
if __name__ == '__main__':
client()

View File

@ -55,6 +55,8 @@ ERROR = 'error'
EXPLICIT = 'explicit'
PLAYLIST = 'playlist'
PLAYLISTS = 'playlists'
OWNER = 'owner'
@ -109,4 +111,15 @@ ALBUM_ID = 'AlbumID'
TRACK_ID = 'TrackID'
S_NO = 'S.NO'
S_NO = 'S.NO'
CONFIG_DEFAULT_SETTINGS = {
'ROOT_PATH': '../ZSpotify Music/',
'ROOT_PODCAST_PATH': '../ZSpotify Podcasts/',
'SKIP_EXISTING_FILES': True,
'DOWNLOAD_FORMAT': 'mp3',
'FORCE_PREMIUM': False,
'ANTI_BAN_WAIT_TIME': 1,
'OVERRIDE_AUTO_WAIT': False,
'CHUNK_SIZE': 50000,
'SPLIT_ALBUM_DISCS': False
}

View File

@ -1,5 +1,5 @@
import os
from typing import Optional
from typing import Optional, Tuple
from librespot.metadata import EpisodeId
from tqdm import tqdm
@ -12,7 +12,7 @@ EPISODE_INFO_URL = 'https://api.spotify.com/v1/episodes'
SHOWS_URL = 'https://api.spotify.com/v1/shows'
def get_episode_info(episode_id) -> tuple[Optional[str], Optional[str]]:
def get_episode_info(episode_id) -> Tuple[Optional[str], Optional[str]]:
info = ZSpotify.invoke_url(f'{EPISODE_INFO_URL}/{episode_id}')
if ERROR in info:
return None, None

View File

@ -1,7 +1,7 @@
import math
import os
import time
from typing import Any
from typing import Any, Tuple, List
from librespot.audio.decoders import AudioQuality
from librespot.metadata import TrackId
@ -23,7 +23,8 @@ def get_saved_tracks() -> list:
limit = 50
while True:
resp = ZSpotify.invoke_url_with_params(SAVED_TRACKS_URL, limit=limit, offset=offset)
resp = ZSpotify.invoke_url_with_params(
SAVED_TRACKS_URL, limit=limit, offset=offset)
offset += limit
songs.extend(resp[ITEMS])
if len(resp[ITEMS]) < limit:
@ -32,15 +33,15 @@ def get_saved_tracks() -> list:
return songs
def get_song_info(song_id) -> tuple[list[str], str, str, Any, Any, Any, Any, Any, Any, Any]:
def get_song_info(song_id) -> Tuple[List[str], str, str, Any, Any, Any, Any, Any, Any, Any]:
""" Retrieves metadata for downloaded songs """
info = ZSpotify.invoke_url(f'{TRACKS_URL}?ids={song_id}&market=from_token')
artists = []
for data in info[TRACKS][0][ARTISTS]:
artists.append(data[NAME])
album_name = info[TRACKS][0][ALBUM][NAME]
name = info[TRACKS][0][NAME]
artists.append(sanitize_data(data[NAME]))
album_name = sanitize_data(info[TRACKS][0][ALBUM][NAME])
name = sanitize_data(info[TRACKS][0][NAME])
image_url = info[TRACKS][0][ALBUM][IMAGES][0][URL]
release_year = info[TRACKS][0][ALBUM][RELEASE_DATE].split('-')[0]
disc_number = info[TRACKS][0][DISC_NUMBER]
@ -84,18 +85,23 @@ def process_track_metadata(artists: list, name: str, disc_number: Any, extra_pat
create_m3u_file: bool):
m3u_filename = None
song_name = sanitize_data(artists[0]) + ' - ' + sanitize_data(name)
if create_m3u_file:
download_directory = os.path.join(os.path.dirname(
__file__), ZSpotify.get_config(ROOT_PATH), extra_paths, extra_paths[:-1])
m3u_filename = f'{download_directory}.m3u'
if ZSpotify.get_config(SPLIT_ALBUM_DISCS):
download_directory = os.path.join(os.path.dirname(
__file__), ZSpotify.get_config(ROOT_PATH), extra_paths, f'Disc {disc_number}')
else:
download_directory = os.path.join(os.path.dirname(
__file__), ZSpotify.get_config(ROOT_PATH), extra_paths)
song_name = artists[0] + ' - ' + name
if prefix:
song_name = f'{prefix_value.zfill(2)} - {song_name}' if prefix_value.isdigit(
) else f'{prefix_value} - {song_name}'
if create_m3u_file:
m3u_filename = f'{os.path.join(ZSpotify.get_config(ROOT_PATH), extra_paths, extra_paths)[:-1]}.m3u'
if ZSpotify.get_config(SPLIT_ALBUM_DISCS):
filename = os.path.join(ZSpotify.get_config(ROOT_PATH), extra_paths, 'Disc ' + str(
disc_number) + '/' + song_name + '.' + ZSpotify.get_config(DOWNLOAD_FORMAT))
else:
filename = os.path.join(ZSpotify.get_config(ROOT_PATH), extra_paths,
song_name + '.' + ZSpotify.get_config(DOWNLOAD_FORMAT))
filename = os.path.join(
download_directory, f'{song_name}.{ZSpotify.get_config(DOWNLOAD_FORMAT)}')
return song_name, filename, m3u_filename

View File

@ -3,7 +3,7 @@ import platform
import re
import time
from enum import Enum
from typing import Match
from typing import List, Tuple, Match
import music_tag
import requests
@ -28,7 +28,7 @@ def wait(seconds: int = 3) -> None:
time.sleep(1)
def split_input(selection) -> list[str]:
def split_input(selection) -> List[str]:
""" Returns a list of inputted strings """
inputs = []
if '-' in selection:
@ -92,7 +92,7 @@ def set_music_thumbnail(filename, image_url) -> None:
tags.save()
def regex_input_for_urls(search_input) -> tuple[str, str, str, str, str, str]:
def regex_input_for_urls(search_input) -> Tuple[str, str, str, str, str, str]:
""" Since many kinds of search may be passed at the command line, process them all here. """
track_uri_search = re.search(
r'^spotify:track:(?P<TrackID>[0-9a-zA-Z]{22})$', search_input)

View File

@ -18,7 +18,7 @@ from librespot.core import Session
from const import CREDENTIALS_JSON, TYPE, \
PREMIUM, USER_READ_EMAIL, AUTHORIZATION, OFFSET, LIMIT, CONFIG_FILE_PATH, FORCE_PREMIUM, \
PLAYLIST_READ_PRIVATE
PLAYLIST_READ_PRIVATE, CONFIG_DEFAULT_SETTINGS
from utils import MusicFormat
@ -55,8 +55,14 @@ class ZSpotify:
@classmethod
def load_config(cls) -> None:
app_dir = os.path.dirname(__file__)
with open(os.path.join(app_dir, CONFIG_FILE_PATH), encoding='utf-8') as config_file:
cls.CONFIG = json.load(config_file)
true_config_file_path = os.path.join(app_dir, CONFIG_FILE_PATH)
if not os.path.exists(true_config_file_path):
with open(true_config_file_path, 'w', encoding='utf-8') as config_file:
json.dump(CONFIG_DEFAULT_SETTINGS, config_file, indent=4)
cls.CONFIG = CONFIG_DEFAULT_SETTINGS
else:
with open(true_config_file_path, encoding='utf-8') as config_file:
cls.CONFIG = json.load(config_file)
@classmethod
def get_config(cls, key) -> Any: