GithubHelp home page GithubHelp logo

radujica / tospotify Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 3.0 101 KB

Utility to parse m3u local playlists and add to Spotify

License: GNU General Public License v3.0

Python 97.88% Makefile 2.12%
local m3u m3u8 playlist python spotify

tospotify's People

Contributors

radujica avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tospotify's Issues

Illegal redirect_uri

Hi, I have seen a closed ticket on that topic but would like to raise the same issue.
I am getting the same error: Illegal redirect_uri
This message appears in my browser after I run the command (python -m tospotify "my_spotify_email" "playlist_path.m3u").
image

I have tried different URIs (http://localhost:8080/; http://localhost:8080; http://localhost:8888/; ...).
Of course setting it up in both the spotify dev dashboard and with "set SPOTIPY_REDIRECT_URI" but still getting that error.

No output in the terminal

Even with --verbose active and everything setup there is no Output in the Terminal.
It just does nothing. Everything is set up as explained but the Terminal stays empty.

I think it is related to the redirect with locahost:8888.
Im running on a qnap nas directly in the admin terminal..

Illegal redirect_uri

Sorry if it is my fault, it is the first time I am using Python... But I always get the following error "Illegal redirect_uri". I am using
the default redirect uri: http://localhost:8888/. What can be wrong?
Thank you very much!

ERROR:root:Could not find any tracks!

Hi there, does this error mean it couldn't find any tracks on Spotify corresponding to those in the playlist? Seems weird and I get the same error for all my playlists (50-100 songs in each).

ValueError: could not convert string to float: ''

Ubuntu 22.04
Python 3.10.12

INFO:root:Created playlist with name=Test at id=4rkgtHurcTnsGjp7lHNFMr
Traceback (most recent call last):
File "/usr/local/bin/tospotify", line 8, in
sys.exit(main())
File "/home/serenity/.local/lib/python3.10/site-packages/tospotify/run.py", line 87, in main
update_spotify_playlist(spot, playlist_path, playlist_id, args.convert)
File "/home/serenity/.local/lib/python3.10/site-packages/tospotify/search.py", line 120, in update_spotify_playlist
songs = parse_songs(playlist_path)
File "/home/serenity/.local/lib/python3.10/site-packages/tospotify/parser.py", line 33, in parse_songs
playlist = m3u8.load(playlist_path)
File "/home/serenity/.local/lib/python3.10/site-packages/m3u8/init.py", line 49, in load
return _load_from_file(uri, custom_tags_parser)
File "/home/serenity/.local/lib/python3.10/site-packages/m3u8/init.py", line 56, in _load_from_file
return M3U8(raw_content, base_uri=base_uri, custom_tags_parser=custom_tags_parser)
File "/home/serenity/.local/lib/python3.10/site-packages/m3u8/model.py", line 153, in init
self.data = parse(content, strict, custom_tags_parser)
File "/home/serenity/.local/lib/python3.10/site-packages/m3u8/parser.py", line 143, in parse
_parse_extinf(line, data, state, lineno, strict)
File "/home/serenity/.local/lib/python3.10/site-packages/m3u8/parser.py", line 261, in _parse_extinf
state['segment']['duration'] = float(duration)
ValueError: could not convert string to float: ''

Could not determine file extension // Illegal redirect_uri

Hi, I tried to use the tool, did the required steps:

set SPOTIPY_CLIENT_ID="my client id"
set SPOTIPY_CLIENT_SECRET="my client secret"
set SPOTIPY_REDIRECT_URI="http://localhost:8888/callback/"

And also whitelisted the url:
image

But when I try this code:

python -m tospotify "11153396121" "C:/Users/Desktop/playlist.m3u8"

It opens this page:

https://accounts.spotify.com/authorize?client_id=%22c0006d10eb15490e9c0b37df306b3afc%22&response_type=code&redirect_uri=%22http%3A%2F%2Flocalhost%3A8888%2Fcallback%2F%22&scope=playlist-modify-private

And says:

Illegal redirect_uri

And after that it asks me to copy paste the url that I got and i get into a loop.

And if I try this one:

tospotify [-h] [--verbose] [--public] [--convert] [--playlist-id 4BcjgCsCGScaUO3RMNm7lA] "11153396121" "C:\Users\user\Desktop\playlist.m3u8"

I get the following message:

C:\Users\user>tospotify [-h] [--verbose] [--public] [--convert] [--playlist-id 4BcjgCsCGScaUO3RMNm7lA] "11153396121" "C:\Users\user\Desktop\playlist.m3u8"
usage: tospotify [-h] [--verbose] [--public] [--convert] [--playlist-id PLAYLIST_ID] spotify_username playlist_path
tospotify: error: argument playlist_path: Could not determine file extension

What can I do to import my 1600 piece playlist to spotify?

code must be supplied

set SPOTIPY_CLIENT_ID=""
set SPOTIPY_CLIENT_SECRET="
"
set SPOTIPY_REDIRECT_URI="http://127.0.0.1/callback"

python -m tospotify ="*********************************"mp3tag2.m3u

url shows "Illegal redirect_uri" but booth urls are equal (the app in spotify and the env variable).

raise SpotifyOauthError(
spotipy.oauth2.SpotifyOauthError: error: invalid_request, error_description: code must be supplied

What am i doing wrong?

tospotify with web uri

As triggered by #20, it seems that newer m3u8 versions handle paths differently in >3.4.0.

Latest m3u8 internally uses urllib.parse.urlsplit(uri).scheme. While related issue should work with this, what if tospotify also supported web uri? It should work out of the box with m3u8.

Try it out.

C:\ is replaced with current directory

# Given pwd is HOME
tospotify --public --playlist-id 76EnUBXM3JIGN9L9YbXleN 1274469315 "C:\MEGA\Music\Jafet Meza\Halo\SPV3\mp3tag.m3u8"
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Noah\AppData\Roaming\Python\Python312\Scripts\tospotify.exe\__main__.py", line 7, in <module>
  File "C:\Users\Noah\AppData\Roaming\Python\Python312\site-packages\tospotify\run.py", line 87, in main
    update_spotify_playlist(spot, playlist_path, playlist_id, args.convert)
  File "C:\Users\Noah\AppData\Roaming\Python\Python312\site-packages\tospotify\search.py", line 120, in update_spotify_playlist
    songs = parse_songs(playlist_path)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Noah\AppData\Roaming\Python\Python312\site-packages\tospotify\parser.py", line 33, in parse_songs
    playlist = m3u8.load(playlist_path)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Noah\AppData\Roaming\Python\Python312\site-packages\m3u8\__init__.py", line 49, in load
    return _load_from_file(uri, custom_tags_parser)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Noah\AppData\Roaming\Python\Python312\site-packages\m3u8\__init__.py", line 53, in _load_from_file
    with open(uri, encoding='utf8') as fileobj:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Noah\\MEGA\\Music\\Jafet Meza\\Halo\\SPV3\\mp3tag.m3u8'

'utf-8' codec can't decode byte 0xe3 in position 3815: invalid continuation byte

Hello I get this error on windows or debian.

user@DESKTOP-H87NGVR:/mnt/c/Users/user/Desktop/toSpotify$ tospotify 1167047623 mp3tag2.m3u
Traceback (most recent call last):
File "/home/user/.local/bin/tospotify", line 10, in
sys.exit(main())
File "/home/user/.local/lib/python3.7/site-packages/tospotify/run.py", line 87, in main
update_spotify_playlist(spot, playlist_path, playlist_id, args.convert)
File "/home/user/.local/lib/python3.7/site-packages/tospotify/search.py", line 120, in update_spotify_playlist
songs = parse_songs(playlist_path)
File "/home/user/.local/lib/python3.7/site-packages/tospotify/parser.py", line 33, in parse_songs
playlist = m3u8.load(playlist_path)
File "/home/user/.local/lib/python3.7/site-packages/m3u8/init.py", line 49, in load
return _load_from_file(uri, custom_tags_parser)
File "/home/user/.local/lib/python3.7/site-packages/m3u8/init.py", line 54, in _load_from_file
raw_content = fileobj.read().strip()
File "/usr/lib/python3.7/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 3815: invalid continuation byte

Errors while testing with valid_playlist.m3u

Is this still working? I am getting errors when trying the valid_playlist.m3u file. I tried using tospotify 0.3.1 on Windows 10 with Python 3.6.0, 3.10.4 and 3.12.0. Here is the output.

Python 3.10.4
tospotify 0.3.1

INFO:root:Created playlist with name=valid_playlist at id=REDACTED
Traceback (most recent call last):
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\Scripts\tospotify.exe\__main__.py", line 7, in <module>
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\lib\site-packages\tospotify\run.py", line 87, in main
    update_spotify_playlist(spot, playlist_path, playlist_id, args.convert)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\lib\site-packages\tospotify\search.py", line 120, in update_spotify_playlist
    songs = parse_songs(playlist_path)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\lib\site-packages\tospotify\parser.py", line 33, in parse_songs
    playlist = m3u8.load(playlist_path)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\lib\site-packages\m3u8\__init__.py", line 96, in load
    content, base_uri = http_client.download(uri, timeout, headers, verify_ssl)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\lib\site-packages\m3u8\httpclient.py", line 16, in download
    resource = opener.open(uri, timeout=timeout)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 519, in open
    response = self._open(req, data)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 541, in _open
    return self._call_chain(self.handle_open, 'unknown',
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain
    result = func(*args)
  File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 1419, in unknown_open
    raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: c>

Split Artist, Title By Space-Surrounded Dash

Artists Names and Song Titles often contain dashes.
However, It's less likely that the Artist Name would contain " - ".
As such, everything after " - " could be assumed to be a Title—including any remaining " - " in that Title.

My personal motivation for this issue? Dash-separated dates in the Title denoting the date the track was exported. This is often the case when an artist puts out early previews of tracks.

WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - Brother In Arms 2022-08-24
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - Brother In Arms 2022-08-28
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - Brother In Arms 2022-12-22 (End)
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - Brother In Arms 2022-12-22
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - In Amber Clad (2023-04-07)
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - In Amber Clad (2024-01-05)
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - In Amber Clad (2024-01-05, Gtr)
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - In Amber Clad (2024-01-05, Nogtr)
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - Leonidas (2024-01-08)
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - Leonidas (2024-01-09)
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - Leonidas (2024-01-12)
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - On A Pale Horrse 2022-08-22
WARNING:root:Encountered more than 2 chunks when splitting song into artist and title. song=Jafet Meza - On A Pale Horrse 2022-12-22

Use latest m3u8

As triggered by #20, it seems that newer m3u8 versions handle paths differently in >3.4.0.

tospotify should work with both >3.4.0 and <=3.4.0 versions of m3u8. Figure out the correct way of using m3u8.load here and at least update these tests.

Finally, remove the m3u8<3.5.0 dependency restriction.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.