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

add when it was played for spotify in recent mode #104

Merged
merged 5 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@octokit/rest": "^18.0.15",
"axios": "^0.21.1",
"compression": "^1.7.4",
"dayjs": "^1.10.4",
"ejs": "^3.1.5",
"express": "^4.17.1",
"express-rate-limit": "^5.2.3",
Expand All @@ -46,8 +47,8 @@
"libxmljs": "^0.19.7"
},
"jest": {
"testEnvironment":"node",
"testTimeout":60000,
"transform":{}
"testEnvironment": "node",
"testTimeout": 60000,
"transform": {}
}
}
5 changes: 4 additions & 1 deletion source/app/metrics/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import axios from "axios"
import puppeteer from "puppeteer"
import imgb64 from "image-to-base64"
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc.js';
dayjs.extend(utc);

export {fs, os, paths, url, util, processes, axios, puppeteer, imgb64}
export {fs, os, paths, url, util, processes, axios, puppeteer, imgb64, dayjs};

/** Returns module __dirname */
export function __module(module) {
Expand Down
1 change: 1 addition & 0 deletions source/plugins/music/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Register your API key to finish setup.
plugin_music_mode: recent # Set plugin mode
plugin_music_limit: 4 # Limit to 4 entries
plugin_music_token: "${{ secrets.SPOTIFY_CLIENT_ID }}, ${{ secrets.SPOTIFY_CLIENT_SECRET }}, ${{ secrets.SPOTIFY_REFRESH_TOKEN }}"
plugin_music_played_at: yes # Only works with spotify.
```

```yaml
Expand Down
6 changes: 3 additions & 3 deletions source/plugins/music/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
embed:/^\b$/,
},
}

//Supported modes
const modes = {
playlist:"Suggested tracks",
Expand All @@ -36,7 +35,7 @@
let tracks = null

//Load inputs
let {provider, mode, playlist, limit, user} = imports.metadata.plugins.music.inputs({data, account, q})
let {provider, mode, playlist, limit, user, played_at} = imports.metadata.plugins.music.inputs({data, account, q})
//Auto-guess parameters
if ((playlist)&&(!mode))
mode = "playlist"
Expand Down Expand Up @@ -144,10 +143,11 @@
"Accept":"application/json",
"Content-Type":"application/json",
"Authorization":`Bearer ${access}`}
})).data.items.map(({track}) => ({
})).data.items.map(({track, played_at}) => ({
name:track.name,
artist:track.artists[0].name,
artwork:track.album.images[0].url,
played_at: played_at ? imports.dayjs(played_at).format('[played at] HH:MM on DD/MM/YYYY') : ''
}))
}
//Handle errors
Expand Down
4 changes: 4 additions & 0 deletions source/plugins/music/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ inputs:
default: 4
min: 1
max: 100
plugin_music_played_at:
description: Display when the track was played
type: boolean
default: no

# Username on music provider service
plugin_music_user:
Expand Down
11 changes: 7 additions & 4 deletions source/templates/classic/partials/music.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
<% } else { %>
<% if (plugins.music.tracks.length) { %>
<div class="tracklist">
<% for (const {name = "", artist = "", artwork = ""} of plugins.music.tracks) { %>
<% for (const {name = "", artist = "", artwork = "", played_at = ""} of plugins.music.tracks) { %>
<div class="track">
<img src="data:image/png;base64,<%= artwork %>" width="32" height="32" alt=""/>
<img src="data:image/png;base64,<%= artwork %>" width="<%= !!played_at.length ? 48 : 32 %>" height="<%= !!played_at.length ? 48 : 32 %>" alt=""/>
<div class="infos">
<div class="name"><%= name %></div>
<div class="name"><b><%= name %><b></div>
<div class="artist"><%= artist %></div>
<% if (played_at.length) { %>
<div class="played_at"><%= played_at %></div>
<% } %>
Milo123459 marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
<% } %>
Expand All @@ -40,4 +43,4 @@
</section>
</div>
</section>
<% } %>
<% } %>