[MOD] Spotify Music Integration

A curated forum for compatible and maintained mods. Users are unable to create new topics in this forum but can reply to existing topics. Please message a moderator to have your mod moved into this forum area.
User avatar
Macadaynu
Posts: 264
Joined: Sun Mar 07, 2021 1:18 pm

[MOD] Spotify Music Integration

Post by Macadaynu »

Spotify Soundtracks (Spotify Premium Required)

Recently I have been playing Daggerfall with the music off and a Jeremy Soule playlist playing on Spotify in the background (It's great). I do this partly because I prefer Jeremy Soule's music, and partly because my in game audio stutters quite a bit (I've maybe got too many mods installed).

I have an 'Exploration' playlist for outside of dungeons, which I then switch to a 'Dungeon' playlist upon entering dungeons. I wondered if it was possible to automate this process. Turns out you can using the Spotify API.

So the logic I went with was, upon loading a save, check where the player is (Dungeon, Tavern, or anywhere else) and play a random track from the appropriate playlist. When the player transitions between these locations, change to a random track from the appropriate playlist.

I recorded this in action below (I've not included the audio in the video due to licensing, but I've put the Spotify app side by side so you can see the playlists changing).



What's cool about this is you can use any playlist you like for these areas (existing or new playlists), so if you wanted Megadeth to start playing when you enter a dungeon, that can be done :lol: (Doing that is as simple as changing the playlist Id in the mod settings)
Last edited by Macadaynu on Wed Oct 06, 2021 9:01 pm, edited 9 times in total.

User avatar
Macadaynu
Posts: 264
Joined: Sun Mar 07, 2021 1:18 pm

Re: [MOD] Spotify Music Integration

Post by Macadaynu »

One-time Setup Guide (Spotify Premium Required)

This integration requires a small setup procedure, but only needs to be done once. We need to authorise your Spotify account to interact with DFU, this can only be done by clicking on an 'Agree' popup from Spotify.

We require 3 things to authenticate: Client ID, Client Secret and Refresh Token. It's an easy process and I'll guide you through it.

Firstly go to https://developer.spotify.com/dashboard/login and click Login, use your standard Spotify credentials.
Click on 'Create an App', and enter a name and description (call it whatever you like), agree to the terms and click Create.

Your Client ID and Client Secret are now available on the left:
ClientDetails.PNG
ClientDetails.PNG (21.71 KiB) Viewed 16544 times


Click on the 'Edit Settings' button, then copy this link address: https://getyourspotifyrefreshtoken.hero ... m/callback and paste into the Redirect URIs field, click 'Add' and then 'Save' at the bottom of the pop up.
settings.png
settings.png (26.98 KiB) Viewed 16544 times

Now browse to https://getyourspotifyrefreshtoken.herokuapp.com/, enter your Client ID and Client Secret into the relevant fields and then click 'Select All' to make sure all the scope checkboxes are ticked, then click 'Submit'.
RefreshToken.png
RefreshToken.png (17.04 KiB) Viewed 16544 times

Click 'Agree' on the Spotify prompt, and you should now be redirected back to a page with your Refresh Token.

Client Id, Client Secret, and Refresh Token all need to be pasted into the relevant fields in your DFU mod settings file, you can't just paste these in the mod settings screen unfortunately (Ctrl-V doesn't seem to work in DFU yet), so you will need to go directly to the json file. This can be found in: C:\Users\<Username>\AppData\LocalLow\Daggerfall Workshop\Daggerfall Unity\Mods\GameData\02e9fd2d-25cc-42d3-8d0b-b2e2937ef827

If this directory doesn't exist yet, you may need to open and close DFU with the dfmod installed.

That's it! Your Refresh Token should last forever, so you shouldn't need to go through any of this procedure again.

General Usage Guide

Make sure your Spotify application is running on your computer, and is ready to play before starting DFU. I recommend turning your shuffle on, but that's up to you. Spotify will start playing when you load / start a game.

Ensure your credentials have been entered into your mod settings as described in the Setup guide above. You can check those fields are populated by checking your mod settings as normal.

Please try out the default playlist Ids first before changing them, they are set to play some Elder Scrolls music.

The mod will set your music to 0 on startup, and then look for active Spotify computer apps running on your account, so make sure you don't have multiple computers running Spotify. (I plan to add a device id to the settings)
Last edited by Macadaynu on Sat Sep 11, 2021 8:54 pm, edited 2 times in total.

User avatar
Macadaynu
Posts: 264
Joined: Sun Mar 07, 2021 1:18 pm

Re: [MOD] Spotify Music Integration

Post by Macadaynu »

Setting Playlists

Open your Spotify application and find your desired playlist.

Click on the 3 dots > Share > Copy link to playlist.
PlaylistId.png
PlaylistId.png (29.27 KiB) Viewed 16446 times

Paste this link somewhere (notepad is fine), it will look something like this:

open.spotify.com/playlist/7qV3GK17XvJy5eNyB6K2Fm?si=111e41203eb04645

The playlist Id is the bit where I have highlighted in blue (all text between the last '/' and the '?'), copy that and paste it into your mod settings json file, in the appropriate area.

If you want to revert to defaults, just clear your playlist Id from each area in the mod settings json file.
Last edited by Macadaynu on Sat Sep 11, 2021 8:58 pm, edited 3 times in total.

User avatar
Cliffworms
Posts: 209
Joined: Sun Dec 30, 2018 6:24 pm
Location: Québec

Re: [MOD] Spotify Music Integration

Post by Cliffworms »

I gave it a try. This is really cool. Thank you, Macadaynu. :)

Something I always loved doing in Morrowind and Oblivion is setting up my custom mp3s from various games and movies.

User avatar
Macadaynu
Posts: 264
Joined: Sun Mar 07, 2021 1:18 pm

Re: [MOD] Spotify Music Integration

Post by Macadaynu »

Version 0.1.0:
  • Added Day / Night Exploration option - Enable this to have separate day / night exploration playlists
  • Added Town playlist option - Enable this to have town music play whenever you enter a town

User avatar
haloterm
Posts: 391
Joined: Sat Feb 16, 2019 5:21 am

Re: [MOD] Spotify Music Integration

Post by haloterm »

Could this be modified to use a local music player instead? Like just executing a command that starts a local player with a local playlist as parameter?

Like (pseudo code):

Code: Select all

If inDungeon == true then
  if handle>0 then stop (handle)
  handle = startprogram "myplayer.exe dungeon.playlist"
endif

User avatar
Macadaynu
Posts: 264
Joined: Sun Mar 07, 2021 1:18 pm

Re: [MOD] Spotify Music Integration

Post by Macadaynu »

I don't see why not, right now it just exists as a Spotify controller, so theoretically could just call a program instead of making the Spotify API calls

User avatar
haloterm
Posts: 391
Joined: Sat Feb 16, 2019 5:21 am

Re: [MOD] Spotify Music Integration

Post by haloterm »

Macadaynu wrote: Fri Sep 24, 2021 11:12 pm I don't see why not, right now it just exists as a Spotify controller, so theoretically could just call a program instead of making the Spotify API calls
Cool...

Right now I am actually thinking to create a Spotify account JUST for your mod. Because the flexibility it offers is really tempting...

User avatar
Macadaynu
Posts: 264
Joined: Sun Mar 07, 2021 1:18 pm

Re: [MOD] Spotify Music Integration

Post by Macadaynu »

haloterm wrote: Fri Sep 24, 2021 11:59 pm
Macadaynu wrote: Fri Sep 24, 2021 11:12 pm I don't see why not, right now it just exists as a Spotify controller, so theoretically could just call a program instead of making the Spotify API calls
Cool...

Right now I am actually thinking to create a Spotify account JUST for your mod. Because the flexibility it offers is really tempting...
Spotify sometimes do free trial offers for Premium, maybe worth keeping an eye out so you can test the mod to see if it's right for you

Glad to hear some more interest for this, it is cool (If I don't say so my self :lol:)

User avatar
Macadaynu
Posts: 264
Joined: Sun Mar 07, 2021 1:18 pm

Re: [MOD] Spotify Music Integration

Post by Macadaynu »

Nexus Release:

https://www.nexusmods.com/daggerfallunity/mods/238

Can this be moved into the released mods section please?

Post Reply