Skip to content

Commit

Permalink
feat(ui): fetch and display artist bio
Browse files Browse the repository at this point in the history
feat(core): artist enrichment now returns bios
  • Loading branch information
feugy committed Oct 4, 2020
1 parent c32d68a commit fc6e524
Show file tree
Hide file tree
Showing 33 changed files with 765 additions and 263 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ There are thunsands of them in the wild. This mine is an excuse for learning [El

- [ ] images from tags
- [ ] system integration (play folder/file)
- [ ] display album/artist descriptions
- [ ] configure replay gain from settings
- [ ] display tracks/albums/artists count in settings
- [ ] allow reseting database from settings
Expand Down
2 changes: 1 addition & 1 deletion main/models/artists.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { uniqRef, parseRawRef } = require('../utils')

class ArtistsModel extends TrackList {
constructor() {
super({ name: 'artists', searchCol: 'name' })
super({ name: 'artists', searchCol: 'name', jsonColumns: ['bio'] })
}

async computeRefs(trx, trackIds) {
Expand Down
6 changes: 4 additions & 2 deletions main/models/artists.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ describe('Artist model', () => {
media: faker.image.image(),
processedEpoch: null,
name: faker.commerce.productName(),
trackIds: [tracks[0].id, tracks[3].id]
trackIds: [tracks[0].id, tracks[3].id],
bio: null
}

await artistsModel.save(artist)
Expand All @@ -70,7 +71,8 @@ describe('Artist model', () => {
media: faker.image.image(),
processedEpoch: null,
name: faker.commerce.productName(),
trackIds: [tracks[0].id, tracks[3].id]
trackIds: [tracks[0].id, tracks[3].id],
bio: { en: faker.lorem.words() }
}

expect((await artistsModel.save(artist)).saved).toEqual([
Expand Down
32 changes: 12 additions & 20 deletions main/models/migrations/001-init.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
'use strict'

const {
settingsModel,
albumsModel,
artistsModel,
playlistsModel,
tracksModel
} = require('../')

exports.up = async function (db) {
await db.schema
.createTable(settingsModel.name, table => {
.createTable('settings', table => {
table.integer('id').primary()
table.json('folders')
table.json('providers')
table.string('locale')
table.integer('openCount').unsigned()
})
.createTable(albumsModel.name, table => {
.createTable('albums', table => {
table.integer('id').primary()
table.string('name')
table.string('media')
table.integer('processedEpoch')
table.json('trackIds')
table.json('refs')
})
.createTable(artistsModel.name, table => {
.createTable('artists', table => {
table.integer('id').primary()
table.string('name')
table.string('media')
table.integer('processedEpoch')
table.json('trackIds')
table.json('refs')
})
.createTable(playlistsModel.name, table => {
.createTable('playlists', table => {
table.integer('id').primary()
table.string('name')
table.text('desc')
Expand All @@ -42,7 +34,7 @@ exports.up = async function (db) {
table.json('trackIds')
table.json('refs')
})
.createTable(tracksModel.name, table => {
.createTable('tracks', table => {
table.integer('id').primary()
table.string('path')
table.string('media')
Expand All @@ -52,8 +44,8 @@ exports.up = async function (db) {
table.float('mtimeMs')
})
// do not use settingsModel.save(): it'll fail on further migration that may add new JSON columns
await db(settingsModel.name).insert({
id: settingsModel.ID,
await db('settings').insert({
id: 1000,
folders: JSON.stringify([]),
openCount: 1,
providers: JSON.stringify({ audiodb: {}, discogs: {} })
Expand All @@ -62,9 +54,9 @@ exports.up = async function (db) {

exports.down = async function ({ schema }) {
await schema
.dropTable(tracksModel.name)
.dropTable(playlistsModel.name)
.dropTable(artistsModel.name)
.dropTable(albumsModel.name)
.dropTable(settingsModel.name)
.dropTable('tracks')
.dropTable('playlists')
.dropTable('artists')
.dropTable('albums')
.dropTable('settings')
}
17 changes: 0 additions & 17 deletions main/models/migrations/002-enqueue-settings.js

This file was deleted.

23 changes: 23 additions & 0 deletions main/models/migrations/002-settings-and-bio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

exports.up = async function ({ schema }) {
await schema
.table('settings', table => {
table
.json('enqueueBehaviour')
.defaultTo(JSON.stringify({ clearBefore: true, onClick: true }))
})
.table('artists', table => {
table.json('bio')
})
}

exports.down = async function ({ schema }) {
await schema
.table('settings', table => {
table.dropColumn('enqueueBehaviour')
})
.table('artists', table => {
table.dropColumn('bio')
})
}
41 changes: 20 additions & 21 deletions main/providers/audiodb/__nocks__/returns_artwork.json

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions main/providers/audiodb/__nocks__/returns_cover.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,43 @@
{
"scope": "https://www.theaudiodb.com:443",
"method": "GET",
"path": "/api/v1/json/1/search.php?s=katie+lombardi",
"path": "/api/v1/json/1/search.php?s=a+common+ground",
"body": "",
"status": 200,
"response": {
"artists": null
},
"response": [
"31241000205bb655b54c6acc3b515b0382644f72e8ffc135f5995f0fed231a2472bab62e8ad2d9b070a2b335d7a5b8750e3d8818c866bf7f203c469f7d286e7e80bad45f421112997c229b82305cb2c7a82e852af6f1b0143aea30455ae2cb843d741ca3a1181a2dccd67fa1771acaba429a3b360375d5887df9cde895111e14210e385216a8d1a256151baddcaba2ef9a76530e26fcb91b10360c79e62656b0d5b37600e9b556948ac2567a307d21b3999bfef076adaf9dc6e7566bd273ebe307acf4c1d6146c0fc1f10cac4dfa0f75f79fd80cf6bbfd9b3382fd41ff9696ae61e11b0768dafc4c64b64e5f0ccf3573bc0fba51b1dab544fcdd4f2fc1434a139ce35d7bb695af9cdbd92d3cee672c501b5d7beb820611ac4192849e42cadd145015bdc047554e5f7ffcb6aa5084d329a54c4aeb483259d091b4cc652352254dc4e8848cc77322a3e285953fed0a9febbdcac5341f89316c5be0fb0913f5adba9520a0fbabf7bffb370003"
],
"rawHeaders": [
"Date",
"Tue, 22 Sep 2020 05:50:35 GMT",
"Sun, 04 Oct 2020 08:44:01 GMT",
"Content-Type",
"application/json",
"Content-Length",
"16",
"Transfer-Encoding",
"chunked",
"Connection",
"close",
"Set-Cookie",
"__cfduid=d0c1dfc39873f375c6ffa9b411c52b6991600753835; expires=Thu, 22-Oct-20 05:50:35 GMT; path=/; domain=.theaudiodb.com; HttpOnly; SameSite=Lax; Secure",
"__cfduid=daf738b7d7044c4ddeec4e0a706dd4f3a1601801041; expires=Tue, 03-Nov-20 08:44:01 GMT; path=/; domain=.theaudiodb.com; HttpOnly; SameSite=Lax; Secure",
"X-Powered-By",
"PHP/7.4.1",
"Access-Control-Allow-Origin",
"*",
"CF-Cache-Status",
"DYNAMIC",
"cf-request-id",
"0555f636430000bbfa4da44200000001",
"0594614f2500000493d8092200000001",
"Expect-CT",
"max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"",
"Report-To",
"{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report?lkg-colo=19&lkg-time=1601801042\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
"NEL",
"{\"report_to\":\"cf-nel\",\"max_age\":604800}",
"Server",
"cloudflare",
"CF-RAY",
"5d69bfd06eb3bbfa-LHR"
"5dcd9e5ead690493-CDG",
"Content-Encoding",
"br"
],
"responseIsBinary": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,33 @@
},
"rawHeaders": [
"Date",
"Tue, 22 Sep 2020 05:50:35 GMT",
"Sun, 04 Oct 2020 08:44:01 GMT",
"Content-Type",
"application/json",
"Content-Length",
"16",
"Connection",
"close",
"Set-Cookie",
"__cfduid=d924b3d7032021f1b1db0d8bb887dd3381600753835; expires=Thu, 22-Oct-20 05:50:35 GMT; path=/; domain=.theaudiodb.com; HttpOnly; SameSite=Lax; Secure",
"__cfduid=d5650ab76719fbad40193e709bcf1fa6c1601801041; expires=Tue, 03-Nov-20 08:44:01 GMT; path=/; domain=.theaudiodb.com; HttpOnly; SameSite=Lax; Secure",
"X-Powered-By",
"PHP/7.4.1",
"Access-Control-Allow-Origin",
"*",
"CF-Cache-Status",
"DYNAMIC",
"cf-request-id",
"0555f636d100000656ce83c200000001",
"0594614fbb0000ee7df49dd200000001",
"Expect-CT",
"max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"",
"Report-To",
"{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report?lkg-colo=19&lkg-time=1601801042\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
"NEL",
"{\"report_to\":\"cf-nel\",\"max_age\":604800}",
"Server",
"cloudflare",
"CF-RAY",
"5d69bfd148860656-LHR"
"5dcd9e5f986bee7d-CDG"
],
"responseIsBinary": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,33 @@
],
"rawHeaders": [
"Date",
"Tue, 22 Sep 2020 05:50:39 GMT",
"Sun, 04 Oct 2020 08:44:05 GMT",
"Content-Type",
"application/json",
"Transfer-Encoding",
"chunked",
"Connection",
"close",
"Set-Cookie",
"__cfduid=d4ec81453ce8fd6dbf170026ed7132f341600753839; expires=Thu, 22-Oct-20 05:50:39 GMT; path=/; domain=.theaudiodb.com; HttpOnly; SameSite=Lax; Secure",
"__cfduid=d9816c0d92885051c4552ec10def018291601801045; expires=Tue, 03-Nov-20 08:44:05 GMT; path=/; domain=.theaudiodb.com; HttpOnly; SameSite=Lax; Secure",
"X-Powered-By",
"PHP/7.4.1",
"Access-Control-Allow-Origin",
"*",
"CF-Cache-Status",
"DYNAMIC",
"cf-request-id",
"0555f643f70000e6080fb45200000001",
"0594615d040000048b6f2f2200000001",
"Expect-CT",
"max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"",
"Report-To",
"{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report?lkg-colo=19&lkg-time=1601801045\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
"NEL",
"{\"report_to\":\"cf-nel\",\"max_age\":604800}",
"Server",
"cloudflare",
"CF-RAY",
"5d69bfe65da6e608-LHR",
"5dcd9e74d88b048b-CDG",
"Content-Encoding",
"br"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,33 @@
},
"rawHeaders": [
"Date",
"Tue, 22 Sep 2020 05:50:39 GMT",
"Sun, 04 Oct 2020 08:44:05 GMT",
"Content-Type",
"application/json",
"Content-Length",
"14",
"Connection",
"close",
"Set-Cookie",
"__cfduid=d55735b0f003d8c329c36881366b9c1ed1600753839; expires=Thu, 22-Oct-20 05:50:39 GMT; path=/; domain=.theaudiodb.com; HttpOnly; SameSite=Lax; Secure",
"__cfduid=d35757f3e8aad95d6da4a78908ab67a4c1601801045; expires=Tue, 03-Nov-20 08:44:05 GMT; path=/; domain=.theaudiodb.com; HttpOnly; SameSite=Lax; Secure",
"X-Powered-By",
"PHP/7.4.1",
"Access-Control-Allow-Origin",
"*",
"CF-Cache-Status",
"DYNAMIC",
"cf-request-id",
"0555f6443e0000e61c8f045200000001",
"0594615d4b000068c4e191e200000001",
"Expect-CT",
"max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"",
"Report-To",
"{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report?lkg-colo=19&lkg-time=1601801045\"}],\"group\":\"cf-nel\",\"max_age\":604800}",
"NEL",
"{\"report_to\":\"cf-nel\",\"max_age\":604800}",
"Server",
"cloudflare",
"CF-RAY",
"5d69bfe6c9d7e61c-LHR"
"5dcd9e7548b568c4-CDG"
],
"responseIsBinary": false
}
Expand Down
47 changes: 27 additions & 20 deletions main/providers/audiodb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

const got = require('got')
const AbstractProvider = require('../abstract-provider')
const descByLocales = {
en: 'strBiographyEN',
fr: 'strBiographyFR'
}

class AudioDB extends AbstractProvider {
constructor() {
Expand Down Expand Up @@ -30,24 +34,27 @@ class AudioDB extends AbstractProvider {
`got results for ${searched}`
)

return (artists || []).reduce(
(results, { strArtistThumb, strArtistFanart }) => {
if (strArtistThumb) {
results.push({
full: strArtistThumb,
provider: this.name
})
}
if (strArtistFanart) {
results.push({
full: strArtistFanart,
provider: this.name
})
return (artists || []).reduce((results, data) => {
const result = { bio: {}, provider: this.name }
let hasBio = false
for (const locale in descByLocales) {
const description = data[descByLocales[locale]]
if (description) {
hasBio = true
result.bio[locale] = description
}
return results
},
[]
)
}
if (data.strArtistThumb) {
results.push({ ...result, artwork: data.strArtistThumb })
}
if (data.strArtistFanart) {
results.push({ ...result, artwork: data.strArtistFanart })
}
if (!data.strArtistThumb && !data.strArtistFanart && hasBio) {
results.push(result)
}
return results
}, [])
} catch (err) {
this.logger.error(
{ err, searched },
Expand All @@ -74,10 +81,10 @@ class AudioDB extends AbstractProvider {
`got results for ${searched}`
)

return (album || []).reduce((results, { strAlbumThumb: full }) => {
if (full) {
return (album || []).reduce((results, { strAlbumThumb: cover }) => {
if (cover) {
results.push({
full,
cover,
provider: this.name
})
}
Expand Down
Loading

0 comments on commit fc6e524

Please # to comment.