@@ -154,17 +154,37 @@ static void updateDiscordPresence(int playback_status, float song_len) {
154154 // tracknum
155155 int nowplaying_num = 0 ;
156156 int nowplaying_all = 0 ;
157- if (deadbeef -> conf_get_int ("discord_presence.show_tracknum" , 1 )) {
158- DB_playItem_t * nowplaying = deadbeef -> streamer_get_playing_track ();
157+ if ((nowplaying_num = deadbeef -> conf_get_int ("discord_presence.show_tracknum" , 1 ))) {
158+ // using nowplaying num as type selection
159+ DB_playItem_t * nowplaying = deadbeef -> streamer_get_playing_track ();
159160 if (nowplaying ) {
160- nowplaying_num = deadbeef -> pl_get_idx_of (nowplaying ) + 1 ;
161- deadbeef -> pl_item_unref (nowplaying );
162- }
163-
164- ddb_playlist_t * nowplaying_plt = deadbeef -> plt_get_for_idx (deadbeef -> streamer_get_current_playlist ());
165- if (nowplaying_plt ) {
166- nowplaying_all = deadbeef -> plt_get_item_count (nowplaying_plt , PL_MAIN );
167- deadbeef -> plt_unref (nowplaying_plt );
161+ while (1 ) {
162+ if (nowplaying_num == 3 || nowplaying_num == 2 ) {
163+ // Set index in album
164+ DB_metaInfo_t * track = deadbeef -> pl_meta_for_key (nowplaying , "track" );
165+ DB_metaInfo_t * totaltracks = deadbeef -> pl_meta_for_key (nowplaying , "numtracks" );
166+
167+ if (track && totaltracks ) {
168+ // assuming value is not NULL
169+ nowplaying_num = atoi (track -> value );
170+ nowplaying_all = atoi (totaltracks -> value );
171+ break ;
172+ }
173+ if (nowplaying_num == 2 ) {
174+ break ;
175+ }
176+ /* fall through on type=3 */
177+ }
178+ // Set index in playlist
179+ nowplaying_num = deadbeef -> pl_get_idx_of (nowplaying ) + 1 ;
180+ ddb_playlist_t * nowplaying_plt = deadbeef -> plt_get_for_idx (deadbeef -> streamer_get_current_playlist ());
181+ if (nowplaying_plt ) {
182+ nowplaying_all = deadbeef -> plt_get_item_count (nowplaying_plt , PL_MAIN );
183+ deadbeef -> plt_unref (nowplaying_plt );
184+ }
185+ break ;
186+ }
187+ deadbeef -> pl_item_unref (nowplaying );
168188 }
169189 }
170190 discordPresence .partySize = nowplaying_num ;
@@ -323,7 +343,7 @@ static const char settings_dlg[] =
323343 "property \"Title format\" entry discord_presence.title_script \"%title%$if(%ispaused%,' ('paused')')\";\n"
324344 "property \"State format\" entry discord_presence.state_script \"%artist%\";\n"
325345 "property \"Overwrite state format with playlist name\" checkbox discord_presence.playlist_on_state 0;\n"
326- "property \"Display track number/total track count \" checkbox discord_presence.show_tracknum 1;\n"
346+ "property \"Range display '(n of m)' \" select[4] discord_presence.show_tracknum 1 \"Hidden\" \"Track index in playlist\" \"Track index in album\" \"Track index in album/playlist (fallback)\" ;\n"
327347 "property \"Display time\" select[3] discord_presence.end_timestamp 0 \"Elapsed time\" \"Remaining time\" \"Don't display time\";\n"
328348 "property \"Icon text format\" entry discord_presence.icon_script \"%artist% \'/\' %album%\";\n"
329349 "property \"Show paused icon\" checkbox discord_presence.paused_icon 1;\n"
@@ -335,7 +355,7 @@ DB_misc_t plugin = {
335355 .plugin .api_vminor = 10 ,
336356 .plugin .type = DB_PLUGIN_MISC ,
337357 .plugin .version_major = 1 ,
338- .plugin .version_minor = 3 ,
358+ .plugin .version_minor = 4 ,
339359 .plugin .id = "discord_presence" ,
340360 .plugin .name = "Discord Rich Presence Plugin" ,
341361 .plugin .descr = "Discord Rich Presence Plugin shows your current playing track on your Discord status.\n"
0 commit comments