Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spotify to Plex #30

Open
Captain-Wiggles opened this issue Sep 8, 2021 · 12 comments
Open

Spotify to Plex #30

Captain-Wiggles opened this issue Sep 8, 2021 · 12 comments

Comments

@Captain-Wiggles
Copy link

Hi again, apologies for the multiple issues but I've spent a few hours trying to figure all these out with no luck and your program seems to be a game changer so I'd really like to get it going :)

I'm trying to link my spotify playlists to plex and wanted a few clarifications:

Music Directory (from Plex): This is the directory where all my music is stored, correct?
Music Directory (from ultrasonics): I'm not sure I completely understand what this folder is for. My understanding is that plex will copy songs to create the playlists here? or am I misunderstanding?

For my testing, I've used the same directory for both and am receiving the following error:

2021-09-07 20:22:26,311 - 🎧 plex - DEBUG - Running settings test for plugin plex v0.1 (plugins.py:187)
2021-09-07 20:22:26,314 - 🎧 plex - DEBUG - Checking that Plex responds to API requests... (up_plex.py:310)
2021-09-07 20:22:26,335 - 🎧 plex - DEBUG - Test successful. (up_plex.py:317)
2021-09-07 20:22:26,336 - 🎧 plex - DEBUG - Testing music directories... (up_plex.py:322)
2021-09-07 20:22:26,338 - 🎧 plex - DEBUG - Plex and ultrasonics music paths detected successfully. (up_plex.py:324)
2021-09-07 20:22:26,339 - 🎧 plex - DEBUG - Checking permissions... (up_plex.py:329)
2021-09-07 20:22:26,358 - 🎧 plex - DEBUG - Successfully created and removed temporary ultrasonics sync directory. (up_plex.py:343)
2021-09-07 20:22:26,359 - 🎧 plex - INFO - Settings test successful. (up_plex.py:349)
[2021-09-07 20:22:26,360] ERROR in app: Exception on /configure_plugin [POST]
Traceback (most recent call last):
File "C:\Users\Russ-Laptop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\flask\app.py", line 2070, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Russ-Laptop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\flask\app.py", line 1516, in full_dispatch_request
return self.finalize_request(rv)
File "C:\Users\Russ-Laptop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\flask\app.py", line 1535, in finalize_request
response = self.make_response(rv)
File "C:\Users\Russ-Laptop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\flask\app.py", line 1698, in make_response
raise TypeError(
TypeError: The view function for 'html_configure_plugin' did not return a valid response. The function either returned None or ended without a return statement.

The last line looks to be the error, and I couldn't figure out where to start digging to debug. Any guidance appreciated!

@XDGFX
Copy link
Owner

XDGFX commented Sep 13, 2021

Music Directory (from Plex): This is the directory where all my music is stored, correct?

This is the directory where all your music is stored, as seen by Plex. For example, if Plex is running on the same server your music is stored, it might be a local directory, if it's running inside a container it might be a mount.

Music Directory (from ultrasonics): I'm not sure I completely understand what this folder is for. My understanding is that plex will copy songs to create the playlists here? or am I misunderstanding?

This is the same as above, where your music is stored, however relative to ultrasonics. If ultrasonics is running in a different container or on another computer with an NFS mount or something, the path might be different to how Plex would access.

If both ultrasonics and Plex are running on the same computer, on bare metal, the two fields are likely the same :)

Your error looks like it's failing somewhere in this function, when the non-persistent plugin settings screen is returned.

# Configure Plugin page
@app.route('/configure_plugin', methods=['GET', 'POST'])
def html_configure_plugin():
"""
Settings page for each instance for a plugin.
"""
global_settings = database.Core().load(raw=True)
# Data received is to update persistent plugin settings
if request.form.get('action') in ['add', 'test']:
plugin = request.form.get('plugin')
version = request.form.get('version')
component = request.form.get('component')
new_data = {key: value for key, value in request.form.to_dict().items() if key not in [
'action', 'plugin', 'version', 'component'] and value != ""}
# Merge new settings with existing database settings
data = plugins.plugin_load(plugin, version)
if data is None:
data = new_data
else:
data.update(new_data)
persistent = False
if request.form.get('action') == 'test':
response = plugins.plugin_test(plugin, version, data, component)
sio.emit("plugin_test", response)
return
else:
plugins.plugin_update(plugin, version, data)
# # Redirect to remove url parameters, so that refreshing won't keep adding more plugin instances
# return redirect(request.path, code=302)
else:
plugin = request.args.get('plugin')
version = request.args.get('version')
component = request.args.get('component')
persistent = request.args.get('persistent') != '0'
# Get persistent settings for the plugin
for item in plugins.handshakes:
if item["name"] == plugin and item["version"] == version:
persistent_settings = item["settings"]
# If persistent settings are supplied
try:
if persistent_settings:
settings = plugins.plugin_build(plugin, version, component)
# Force redirect to persistent settings if manually requested through url parameters, or if plugin has not been configured
persistent = persistent or settings is None
if persistent:
settings = persistent_settings
else:
# No persistent settings exist
settings = plugins.plugin_build(
plugin, version, component, force=True)
persistent = -1
except Exception as e:
log.error(
"Could not build plugin! Check your database settings are correct.", e)
return render_template('index.html')
# Check if any settings are custom html strings
custom_html = any([isinstance(setting, str) for setting in settings])
test_exists = plugins.plugin_test(plugin, version, component=component)
return render_template('configure_plugin.html', settings=settings, plugin=plugin, version=version, component=component, persistent=persistent, custom_html=custom_html, test_exists=test_exists, global_settings=global_settings)

Maybe this bit is causing the issue, if for some reson Flask is taking this response as the html to view

        if request.form.get('action') == 'test':
            response = plugins.plugin_test(plugin, version, data, component)
            sio.emit("plugin_test", response)
            return

Could you try set up a different plugin with a 'test' option and see if it gives the same error? It seemed to be fine when I was writing it so not sure why it would be acting differently.

@Captain-Wiggles
Copy link
Author

So I tried to set up the ultrasonics plugin and tested it. similar error it seems:

2021-09-15 20:45:38,887 - 🎧 lastfm - INFO - Trying last.fm api at url: https://ultrasonics-api.herokuapp.com/api/lastfm (up_lastfm.py:264) 2021-09-15 20:45:38,889 - 🎧 lastfm - INFO - Using username: SirCaptainCo (up_lastfm.py:265) 2021-09-15 20:45:39,282 - 🎧 lastfm - INFO - {"user":{"playlists":"0","playcount":"23730","gender":"n","name":"SirCaptainCo","subscriber":"0","url":"https:\/\/www.last.fm\/user\/SirCaptainCo","country":"None","image":[{"size":"small","#text":""},{"size":"medium","#text":""},{"size":"large","#text":""},{"size":"extralarge","#text":""}],"registered":{"unixtime":"1588223638","#text":1588223638},"type":"user","age":"0","bootstrap":"0","realname":""}} (up_lastfm.py:274) [2021-09-15 20:45:39,287] ERROR in app: Exception on /configure_plugin [POST] Traceback (most recent call last): File "C:\Users\Russ-Laptop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\flask\app.py", line 2070, in wsgi_app response = self.full_dispatch_request() File "C:\Users\Russ-Laptop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\flask\app.py", line 1516, in full_dispatch_request return self.finalize_request(rv) File "C:\Users\Russ-Laptop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\flask\app.py", line 1535, in finalize_request response = self.make_response(rv) File "C:\Users\Russ-Laptop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\flask\app.py", line 1698, in make_response raise TypeError( TypeError: The view function for 'html_configure_plugin' did not return a valid response. The function either returned None or ended without a return statement.

@XDGFX
Copy link
Owner

XDGFX commented Sep 23, 2021

Have a go with the latest commits on the 1.1.0 branch. I've hopefully fixed the error you were having :)

https://github.com/XDGFX/ultrasonics/tree/1.1.0

@Captain-Wiggles
Copy link
Author

Captain-Wiggles commented Sep 29, 2021

So the applet is running successfully (and has a check mark beside the plugin after running) but I'm not seeing the playlists on my plex update. There are a few invalid songs listed but otherwise, everything is a success. any suggestions for debugging?

2021-09-28 20:25:27,236 - 🎧 spotify - DEBUG - Invalid spotify id for song: All Day [RMX] (ft. Kendrick Lamar of Black Hippy, Paul McCartney of The Beatles, Allan Kingdom & Theophilus London) (up_spotify.py:447)
2021-09-28 20:25:27,236 - 🎧 spotify - DEBUG - Invalid spotify id for song: Sin City [RMX] (up_spotify.py:447)
2021-09-28 20:25:27,236 - 🎧 spotify - DEBUG - Invalid spotify id for song: Only One (feat. Caroline Shaw, Paul Mccartney & Ty Dolla $ign) (Edit) (up_spotify.py:447)
2021-09-28 20:25:27,251 - 🎧 spotify - DEBUG - Invalid spotify id for song: I Don't Like (up_spotify.py:447)
Converting tracks in 7e9D9hVyhg0LjRmAPYvYZK: 100%|██████████████████████████████████████████████████████████████████████████| 121/121 [00:00<00:00, 1925.75it/s]
6it [00:00, 4.87it/s]2021-09-28 20:25:27,376 - 🎧 spotify - INFO - Converting tracks to ultrasonics format. (up_spotify.py:387)
Converting tracks in 1pwGONyKPZenqmTDmlRmgb: 100%|██████████████████████████████████████████████████████████████████████████████████████| 86/86 [00:00<?, ?it/s]
7it [00:01, 5.57it/s]2021-09-28 20:25:27,626 - 🎧 spotify - INFO - Converting tracks to ultrasonics format. (up_spotify.py:387) | 0/86 [00:00<?, ?it/s]
2021-09-28 20:25:27,642 - 🎧 spotify - DEBUG - Invalid spotify id for song: eight (acoustic) (up_spotify.py:447) | 0/109 [00:00<?, ?it/s]
Converting tracks in 5vFNYfSPULGtpvqV4ZGWNL: 100%|████████████████████████████████████████████████████████████████████████████████████| 109/109 [00:00<?, ?it/s]
8it [00:01, 4.84it/s]2021-09-28 20:25:27,767 - 🎧 spotify - INFO - Converting tracks to ultrasonics format. (up_spotify.py:387)
Converting tracks in 1yMtT4Xq9JxuERX8RsoasK: 100%|██████████████████████████████████████████████████████████████████████████████████████| 31/31 [00:00<?, ?it/s]
9it [00:01, 5.52it/s]2021-09-28 20:25:27,923 - 🎧 spotify - INFO - Converting tracks to ultrasonics format. (up_spotify.py:387) | 0/31 [00:00<?, ?it/s]
Converting tracks in 1B24omY7a6ZaE04RnCs8Uh: 100%|██████████████████████████████████████████████████████████████████████████████████████| 80/80 [00:00<?, ?it/s]
10it [00:01, 5.76it/s]2021-09-28 20:25:28,157 - 🎧 spotify - INFO - Converting tracks to ultrasonics format. (up_spotify.py:387) | 0/80 [00:00<?, ?it/s]
Converting tracks in 39eCskYCCRYNaYqZOoQMxI: 100%|██████████████████████████████████████████████████████████████████████████████████████| 44/44 [00:00<?, ?it/s]
11it [00:01, 5.21it/s]2021-09-28 20:25:28,298 - 🎧 spotify - INFO - Converting tracks to ultrasonics format. (up_spotify.py:387) | 0/44 [00:00<?, ?it/s]
Converting tracks in 7pHxDlq6aV72oZW2KuzJEA: 100%|██████████████████████████████████████████████████████████████████████████████████████| 68/68 [00:00<?, ?it/s]
12it [00:02, 5.52it/s]2021-09-28 20:25:28,423 - 🎧 spotify - INFO - Converting tracks to ultrasonics format. (up_spotify.py:387) | 0/68 [00:00<?, ?it/s]
Converting tracks in 6h8vruJFN8vFVboWiwNHrX: 100%|██████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:00<?, ?it/s]
13it [00:02, 6.27it/s]2021-09-28 20:25:28,548 - 🎧 spotify - INFO - Converting tracks to ultrasonics format. (up_spotify.py:387) | 0/20 [00:00<?, ?it/s]
Converting tracks in 08HOCcFD8sfl1lssxSh6wl: 100%|██████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:00<?, ?it/s]
14it [00:02, 6.70it/s]2021-09-28 20:25:28,658 - 🎧 spotify - INFO - Converting tracks to ultrasonics format. (up_spotify.py:387) | 0/20 [00:00<?, ?it/s]
Converting tracks in 5nKJLU6HY74S84haWauqfG: 100%|██████████████████████████████████████████████████████████████████████████████████████| 27/27 [00:00<?, ?it/s]
15it [00:02, 6.23it/s]KJLU6HY74S84haWauqfG: 0%| | 0/27 [00:00<?, ?it/s]
←[38m2021-09-28 20:25:28,673 - plugins - DEBUG - Running plugin plex v0.1 (plugins.py:158)←[0m
2021-09-28 20:25:28,673 - 🎧 plex - INFO - Requesting playlists from endpoint: http://10.0.1.211:32400/playlists/?X-Plex-Token=*********** (up_plex.py:179)
2021-09-28 20:25:28,689 - 🎧 plex - INFO - Found 4 playlists. (up_plex.py:195)
2021-09-28 20:25:28,689 - 🎧 plex - INFO - Creating temporary playlists to send to Plex. (up_plex.py:239)
2021-09-28 20:25:28,705 - 🎧 plex - INFO - Updating playlist: Comp. Adele (up_plex.py:243)
2021-09-28 20:25:28,736 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:28,736 - 🎧 plex - INFO - Updating playlist: Comp. Coldplay (up_plex.py:243)
2021-09-28 20:25:28,751 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:28,751 - 🎧 plex - INFO - Updating playlist: Comp. Ed Sheeran (up_plex.py:243)
2021-09-28 20:25:28,782 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:28,782 - 🎧 plex - INFO - Updating playlist: Comp. Fleetwood Mac (up_plex.py:243)
2021-09-28 20:25:28,798 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:28,814 - 🎧 plex - INFO - Updating playlist: Comp. Gambino (up_plex.py:243)
2021-09-28 20:25:28,829 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:28,829 - 🎧 plex - INFO - Updating playlist: Comp. GOOD MUSIC (up_plex.py:243)
2021-09-28 20:25:28,861 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:28,861 - 🎧 plex - INFO - Updating playlist: Comp. Gorillaz (up_plex.py:243)
2021-09-28 20:25:28,892 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:28,892 - 🎧 plex - INFO - Updating playlist: Comp. HIT (up_plex.py:243)
2021-09-28 20:25:28,908 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:28,908 - 🎧 plex - INFO - Updating playlist: Comp. Kendrick (up_plex.py:243)
2021-09-28 20:25:28,939 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:28,939 - 🎧 plex - INFO - Updating playlist: Comp. The Killers (up_plex.py:243)
2021-09-28 20:25:28,954 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:28,954 - 🎧 plex - INFO - Updating playlist: Comp. Lumineers (up_plex.py:243)
2021-09-28 20:25:28,985 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:28,985 - 🎧 plex - INFO - Updating playlist: Comp. Musicals (up_plex.py:243)
2021-09-28 20:25:29,032 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:29,032 - 🎧 plex - INFO - Updating playlist: Comp. OMAM (up_plex.py:243)
2021-09-28 20:25:29,048 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:29,048 - 🎧 plex - INFO - Updating playlist: Comp. RADWIMPS (up_plex.py:243)
2021-09-28 20:25:29,064 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
2021-09-28 20:25:29,079 - 🎧 plex - INFO - Updating playlist: Comp. Sigur Ros (up_plex.py:243)
2021-09-28 20:25:29,095 - 🎧 plex - DEBUG - <title>Internal Server Error</title>

500 Internal Server Error

(up_plex.py:298)
←[96m2021-09-28 20:25:29,111 - plugins - INFO - Applet ddfe9881-2002-11ec-a172-54424958cd16 completed successfully in 0:00:03.750089 (plugins.py:296)←[0m
←[96m2021-09-28 20:25:29,142 - database - INFO - Applet lastrun updated (database.py:377)←[0m

@XDGFX
Copy link
Owner

XDGFX commented Oct 5, 2021

Hmm, have you already got existing playlists in Plex which match the ones you're trying to sync? IIRC the Plex API will create a new playlist, even if an existing one with the same title already exists.

I don't like the look of all those 500 errors. Is that the case for all the playlists you're trying to sync?

Are you able to run Python in debug mode with break points? If you know how to do that it could be useful to break after ultrasonics creates temporary playlists to have a look at them. Another thought is if Plex is unable to access the temporary playlists being created (maybe a path or permissions issue in config?). It's a shame Plex doesn't return more detailed error information ;)

p.s. Thanks for the tip! :D

@XDGFX
Copy link
Owner

XDGFX commented Oct 23, 2021

Hi again! I've had a few people with issues synching with Plex, so I've started writing a new version of the up_plex plugin. It's currently available on the new https://github.com/XDGFX/ultrasonics/tree/1.2.0 branch, could you please download that and try syncing with the new 'plex beta' plugin instead, and let me know how you get on?

Thanks!

@rodrigorodrigo
Copy link

Is it possible to update the dockerhub repo? I'd rather deploy it that way to use and it seems the last version is not there yet

@Captain-Wiggles
Copy link
Author

Captain-Wiggles commented Oct 24, 2021

So I tried running 1.2.0, but it crashes immediately. The python window closes immediately and unfortunately I can't see the error causing it to crash.

I had tried to roll back to 1.1.0 but my files seem to be messed up still. I made a few plug-ins before and want to try and bring it back to a new install, which folders would I need to copy over?

Edit: I figured it out and it was the config folder.

@XDGFX
Copy link
Owner

XDGFX commented Nov 3, 2021

Is it possible to update the dockerhub repo? I'd rather deploy it that way to use and it seems the last version is not there yet

@rodrigorodrigo
Thanks for the heads up! I had originally set up automated Docker actions to update the containers automatically but I checked and it seemed that hadn't worked for any of the recent updates.

I've just updated all the Docker tags, the latest tag is whatever is on the main branch, and I've added 1.1.0 for more stability, and 1.2.0 for testing these changes :)

Try pulling the 1.2.0 tag and see if it works!

@XDGFX
Copy link
Owner

XDGFX commented Nov 3, 2021

@Captain-Wiggles
Not too sure why it would crash immediately, any logs which indicate why? Yep the config folder should be the only non-ephemeral folder so just copy that as needed (maybe keep a backup during testing).

@rodrigorodrigo
Copy link

rodrigorodrigo commented Nov 3, 2021

Is it possible to update the dockerhub repo? I'd rather deploy it that way to use and it seems the last version is not there yet

@rodrigorodrigo Thanks for the heads up! I had originally set up automated Docker actions to update the containers automatically but I checked and it seemed that hadn't worked for any of the recent updates.

I've just updated all the Docker tags, the latest tag is whatever is on the main branch, and I've added 1.1.0 for more stability, and 1.2.0 for testing these changes :)

Try pulling the 1.2.0 tag and see if it works!

I'm trying the latest tag and apparently it is working as intended. Even though I still yet to check how many tracks I actually have that ultrasonics did not find, I am impressed with how this turned out to be.

The only thing I found out up until now are the big blanks on log while executing the script that makes it a bit harder to read.

EDIT: Any chance on releasing it on unraid? I can set the template there if you need to as I am running it.

@XDGFX
Copy link
Owner

XDGFX commented Nov 25, 2021

Good to hear! Those blanks are due to tqdm when looking at the logs directly, I feel like I should redo the logging system a bit and fix that at the same time.

I did look into an Unraid release but I haven't managed to get anything yet. I also don't have Unraid running anywhere currently. If you have a template already that you wouldn't mind posting that would be really helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants