raywo / MMM-NowPlayingOnSpotify

A module for MagicMirror displaying the song currently playing on Spotify.
MIT License
205 stars 43 forks source link

Error when playing a podcast in Spotify #30

Open charraeus opened 5 years ago

charraeus commented 5 years ago

When playing a podcast the following error messages occur and the display is not updated:

Can’t retrieve current song. Reason: 
TypeError: Cannot read property 'album' of null
    at Class.sendRetrievedNotification (/home/pi/MagicMirror/modules/MMM-NowPlayingOnSpotify/node_helper.js:49:46)
    at connector.retrieveCurrentlyPlaying.then (/home/pi/MagicMirror/modules/MMM-NowPlayingOnSpotify/node_helper.js:32:16)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
Can’t retrieve current song. Reason: 
TypeError: Cannot read property 'album' of null
    at Class.sendRetrievedNotification (/home/pi/MagicMirror/modules/MMM-NowPlayingOnSpotify/node_helper.js:49:46)
    at connector.retrieveCurrentlyPlaying.then (/home/pi/MagicMirror/modules/MMM-NowPlayingOnSpotify/node_helper.js:32:16)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Tested with the following Podcast: "Lage der Nation" - LdN116 Kohleausstieg, Diesel-Nachrüstung, INF-Kündigung, US-Wahlkampf, Bischofssynode in Rom

When playing a "normal" album everything works.

Best regards, Christian

Guillaume-Bru commented 5 years ago

Hi,

I confirm this bug with an other podcast:

Can’t retrieve current song. Reason: TypeError: Cannot read property 'album' of null at Class.sendRetrievedNotification (/home/pi/MagicMirror/modules/MMM-NowPlayingOnSpotify/node_helper.js:49:46) at connector.retrieveCurrentlyPlaying.then (/home/pi/MagicMirror/modules/MMM-NowPlayingOnSpotify/node_helper.js:32:16) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7)

Does this bug is on the roadmap? :)

Thanks for your job guys!

Cheers, Guillaume

joehand commented 3 years ago

You can make a few changes to fix this.

  1. Open core/SpotifyConnector.js in a text editor and edit the apiEndpoint to include additional types:
const apiEndpoint = 'https://api.spotify.com/v1/me/player?additional_types=track,episode';
  1. Then in node-helper.js you need to deal with the fact that podcasts are organized by show and songs by album. Here are the new lines:
if (!songInfo.noSong) {
      // Add the line below
      if (!songInfo.item.album) songInfo.item.album = songInfo.item.show

      payload = {
        imgURL: this.getImgURL(songInfo.item.album.images),
        songTitle: songInfo.item.name,
        artist: this.getArtistName(songInfo.item.artists || []), // AND ADD THIS
        album: songInfo.item.album.name,
        titleLength: songInfo.item.duration_ms,
        progress: songInfo.progress_ms,
        isPlaying: songInfo.isPlaying,
        deviceName: songInfo.device.name
      };
    }
clancyjr commented 3 years ago

Love the code and the documentation. Y'all are the best. However, this change was implemented as documented, but no change. still stuck at "loading" in the gui.

JirR02 commented 2 years ago

Love the code and the documentation. Y'all are the best. However, this change was implemented as documented, but no change. still stuck at "loading" in the gui.

For me it worked :-) Thank you @joehand for the code. Perhaps it should be implemented into the master branch.