From ac14bb7bc60a50637be6f18f9de38b7b7c85dac5 Mon Sep 17 00:00:00 2001 From: Sathya Date: Sun, 20 Oct 2019 11:58:24 +0300 Subject: [PATCH] v3.3 release (#59) * fix: user_id error & support for playlist url with or without userid * prepare for release --- README.md | 1 + README.rst | 157 --------------------------------------- build.sh | 1 + setup.py | 14 ++-- spotify_dl/spotify.py | 21 ++++-- spotify_dl/spotify_dl.py | 2 +- 6 files changed, 22 insertions(+), 174 deletions(-) delete mode 100644 README.rst diff --git a/README.md b/README.md index 29045109..ddc089dd 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ You can set defaults per user by creating a file at `~/.spotify_dl_settings`. Cr - [Gowtham](https://github.com/HackToHell) for [create playlist in download](https://github.com/SathyaBhat/spotify-dl/pull/23) directory - [alvierahman90](https://github.com/alvierahman90) for [config file support](https://github.com/SathyaBhat/spotify-dl/pull/42) and [Spotify playlist URL support](https://github.com/SathyaBhat/spotify-dl/pull/41) - [Bibhas](https://github.com/iambibhas) for fixing [can only concatenate list (not "str") to list error](https://github.com/SathyaBhat/spotify-dl/issues/44) + - [Nikhil Nagaraju](https://github.com/nikhilnagaraju) for fixing support for playlist url with or without userid #58 ## Issues, Feedback, Contact details Feel free to raise any bugs/issues under Github issues. Pull requests are also more than welcome. You can reach me on twitter at [@sathyabhat](https://twitter.com/sathyabhat) or drop an email [sathya@sathyasays.com](mailto:sathya@sathyasays.com) diff --git a/README.rst b/README.rst deleted file mode 100644 index c011a7e0..00000000 --- a/README.rst +++ /dev/null @@ -1,157 +0,0 @@ -spotify\_dl -=========== - -Downloads songs from any Spotify playlist or from your "My Music" -collection. - -Tell me more! -============= - -I wanted an easy way to grab the songs present in my library so I can -download it & use it offline(Spotify still hasn't launched here. Y U NO -COME?). `spotify\_to\_mp3 `__ -worked well but it relied on grooveshark, which unfortunately is no -more. - -So I wrote this script which mimics that library, but instead of -downloading from grooveshark, it provides you with a file of youtube -URLs which you can then plug into -`youtube-dl `__ - -How do I get this thing running? -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Pre-requisite: You need Python 3+ - -1. Install using pip ``sudo pip3 install spotify_dl`` (use ``pip`` if - your distro natively provides Python 3) - -2. Create your Spotify app & fetch the client id and client secret from - `Spotify Developer - Console `__. - These keys then need to be assigned as ``SPOTIPY_CLIENT_ID``, - ``SPOTIPY_CLIENT_SECRET`` and ``SPOTIPY_REDIRECT_URI`` environment - variables. - - You can set environment variables in Linux like so: - - :: - - export SPOTIPY_CLIENT_ID='your-spotify-client-id' - export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret' - export SPOTIPY_REDIRECT_URI='your-app-redirect-url' - - Windows users, check for `this - question `__ for details on how - you can set environment variables. - - Note the redirect URL can be a valid URL, just ensure it matches with - what you have entered in the developer console & in the environment - variable above. - -3. Create your YouTube API key & fetch the keys from `Google Developer - Console `__. - Set the key as ``YOUTUBE_DEV_KEY`` environment variable as mentioned - above. -4. Run the script using ``spotify_dl``. spotify\_dl accepts different - parameters, for more details run ``spotify_dl -h``. - -For most users -``spotify_dl -l spotify_playlist_link -o download_directory`` should do -where - -- ``spotify_playlist_link`` is a link to Spotify's playlist. You can - get it from the 3-dot menu. - -.. figure:: https://cloud.githubusercontent.com/assets/25424/25472453/f256c94a-2b48-11e7-8f91-7bfa1ce232c2.png - :alt: image - - image - -If the Spotify playlist link is skipped then it will download songs from -your "My Music" collection - ``download_directory`` is the location -where the songs must be downloaded to. If you give a ``.`` then it will -download to the current directory. - -Alternatively, -``spotify_dl -p playlist_id -u user_name -o download_directory`` will -also work - -- ``playlist_id`` is the id of the playlist where songs need to be - downloaded. If this is skipped then it will download songs ftom your - "My Music" collection -- ``user_name`` is the user name who created the playlist. -- ``download_directory`` is the location where the songs must be - downloaded to. - -5. A first time run will require authentication; you will need to click - on the URL prompted to authenticate. Once logged in, paste the URL - back in. -6. To retrieve download songs as MP3, you will need to install ffmpeg. - If you prefer to skip MP3 conversion, pass ``-m`` or ``--skip_mp3`` - as a parameter when running the script - -- Linux users can get them by installing libav-tools by using apt-get - (``sudo apt-get install -y libav-tools``) or a package manager which - comes with your distro -- Windows users can download FFMPEG pre-built binaries from - `here `__. Extract the file using - `7-zip `__ to a foldrer and `add the folder to - your PATH environment - variable `__ - -How do I set defaults? -~~~~~~~~~~~~~~~~~~~~~~ - -You can set defaults per user by creating a file at -``~/.spotify_dl_settings``. Create a key with value for every argument -you want a default for. Example: - -.. code:: json - - { - "output" : "/home/foo/spotify-dl-output" - , "verbose" : "true" - , "skip_mp3" : "t" - } - -Credits -~~~~~~~ - -- `rhnvrm `__ for `adding in - youtube-dl `__ -- `mr-karan `__ for `adding save to - directory `__ -- `shantanugoel `__ for adding in - `User playlist `__, - `skip MP3 - conversion `__ and - `Ability to use custom format string - support `__ -- `sildur `__ for adding any `user playlist - support and other - fixes `__ -- `avinassh `__ for being a - `Rockstar `__ and not - teleporting over to my house to kill me when I innundated him with - questions -- `doulwyi `__ for adding id3 tagging and - ability to parse Spotify URI -- `Gowtham `__ for `create playlist in - download `__ - directory -- `alvierahman90 `__ for `config file - support `__ and - `Spotify playlist URL - support `__ -- `Bibhas `__ for fixing `can only - concatenate list (not "str") to list - error `__ - -Issues, Feedback, Contact details ---------------------------------- - -Feel free to raise any bugs/issues under Github issues. Pull requests -are also more than welcome. You can reach me on twitter at -[@sathyabhat](https://twitter.com/sathyabhat) or drop an email -sathya@sathyasays.com diff --git a/build.sh b/build.sh index a897ea8a..8e73e502 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,5 @@ rm dist/* +pip3 install -r requirements.txt python3 setup.py sdist python3 setup.py bdist_wheel twine upload dist/* diff --git a/setup.py b/setup.py index 4be57feb..0d4b216b 100644 --- a/setup.py +++ b/setup.py @@ -2,16 +2,13 @@ from setuptools import setup, find_packages -try: - import pypandoc - long_description = pypandoc.convert('README.md', 'rst') -except (IOError, ImportError): - long_description = open('README.rst', encoding="utf8").read() +with open('README.md') as f: + long_description = f.read() with open('requirements.txt') as f: requirements = f.read().splitlines() -version = '3.0.1' +version = '3.3.0' setup( name='spotify_dl', @@ -24,9 +21,10 @@ include_package_data=True, url='https://github.com/SathyaBhat/spotify-dl/', license='MIT', - description='Downloads songs from Spotify My Music ' - 'or Spotify Playlist that you provide', + description='Downloads songs from a ' + 'Spotify Playlist that you provide', long_description=long_description, + long_description_content_type='text/markdown', entry_points={ 'console_scripts': [ 'spotify_dl=spotify_dl.spotify_dl:spotify_dl', diff --git a/spotify_dl/spotify.py b/spotify_dl/spotify.py index 19df3fa8..1a3308ca 100644 --- a/spotify_dl/spotify.py +++ b/spotify_dl/spotify.py @@ -104,19 +104,24 @@ def download_songs(info, download_directory, format_string, skip_mp3): continue -def extract_user_and_playlist_from_uri(uri): - playlist_re = re.compile("spotify:user:[\w,.]+:playlist:[\w]+") - for playlist_uri in playlist_re.findall(uri): +def extract_user_and_playlist_from_uri(uri, sp): + playlist_re = re.compile("(spotify)(:user:[\w,.]+)?(:playlist:[\w]+)") + user_id = sp.current_user()['id'] + for playlist_uri in ["".join(x) for x in playlist_re.findall(uri)]: segments = playlist_uri.split(":") - user_id = segments[2] - log.info('List owner: ' + str(user_id)) - playlist_id = segments[4] - log.info('List ID: ' + str(playlist_id)) + if len(segments) >= 4: + user_id = segments[2] + playlist_id = segments[4] + log.info('List ID: ' + str(playlist_id)) + else: + playlist_id = segments[2] + log.info('List ID: ' + str(playlist_id)) + log.info('List owner: ' + str(user_id)) return user_id, playlist_id def playlist_name(uri, sp): - user_id, playlist_id = extract_user_and_playlist_from_uri(uri) + user_id, playlist_id = extract_user_and_playlist_from_uri(uri, sp) return get_playlist_name_from_id(playlist_id, user_id, sp) diff --git a/spotify_dl/spotify_dl.py b/spotify_dl/spotify_dl.py index a56e9c76..5d8beeaf 100644 --- a/spotify_dl/spotify_dl.py +++ b/spotify_dl/spotify_dl.py @@ -82,7 +82,7 @@ def spotify_dl(): else: raise Exception('Invalid playlist URL ') if args.uri: - current_user_id, playlist_id = extract_user_and_playlist_from_uri(args.uri[0]) + current_user_id, playlist_id = extract_user_and_playlist_from_uri(args.uri[0], sp) else: if args.user_id is None: current_user_id = sp.current_user()['id']