-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from sdasda7777/sdasda7777_staticOverrides
Implemented static overrides
- Loading branch information
Showing
6 changed files
with
140 additions
and
22 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
// Include your static overrides here | ||
// Override's key may use album artist name or album name, most specific combination being used first | ||
// Override's value must contain artworkFrom and artworkUrl or joinFrom and joinUrl or all four | ||
// For example: | ||
/* | ||
module.exports = [ | ||
{key: {albumArtist: "Artist1", albumName: "Album1"}, | ||
value: {artworkFrom: "Example1", artworkUrl: "example1.jpg", joinFrom: "Example1", joinUrl: "example1"}}, | ||
{key: {albumName: "Album2"}, | ||
value: {joinUrl: "example2a"}}, | ||
{key: {albumArtist: "Artist1", albumName: "Album2"}, | ||
value: {artworkFrom: "Example2b", artworkUrl: "example2b.jpg", joinFrom: "Example2b", joinUrl: "example2b"}}, | ||
{key: {albumArtist: "Artist1"}, | ||
value: {artworkFrom: "Example3", artworkUrl: "example3.jpg"}}, | ||
{key: {albumName: "Album4"}, | ||
value: {joinFrom: "Example4", joinUrl: "example4.jpg"}}, | ||
] | ||
*/ | ||
// will return: | ||
|
||
// for "Album1" by "Artist1": | ||
// {artworkFrom: "Example1", artworkUrl: "example1.jpg", joinFrom: "Example1", joinUrl: "example1"} | ||
// (no tricks here, the key is an exact match) | ||
|
||
// for "Album2" by "Artist1": | ||
// {artworkFrom: "Example2b", artworkUrl: "example2b.jpg", joinFrom: "Example2b", joinUrl: "example2b"} | ||
// (because the most specific key is used first) | ||
|
||
// for "Album3" by "Artist1": | ||
// {fetchedFrom: "Example3", artworkUrl: "example3.jpg"} | ||
// (because it is the best match for given album) | ||
|
||
// for "Album4" by "Artist1": | ||
// {artworkFrom: "Example3", artworkUrl: "example3.jpg", joinFrom: "Example4", joinUrl: "example4.jpg"} | ||
// (partial matches for "Album4" and "Artist1" get combined) | ||
|
||
|
||
module.exports = [ | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
/** | ||
* Fetcher of static overrides | ||
*/ | ||
class StaticOverridesFetcher | ||
{ | ||
/** @type {!Object} #data structure for storing the lookup data */ | ||
#data = {}; | ||
|
||
constructor(rawData) | ||
{ | ||
for (let v of rawData) | ||
{ | ||
// Use key stringified with sorted keys | ||
this.#data[JSON.stringify(v.key, Object.keys(v.key).sort())] = v.value; | ||
} | ||
} | ||
|
||
/** | ||
* @param {!Object} VLC metadata | ||
* @returns {!{artworkFrom: ?string, artworkUrl: ?string, joinFrom: ?string, joinUrl: ?string}} | ||
*/ | ||
fetch(metadata) | ||
{ | ||
let result = {}; | ||
|
||
for (let v of StaticOverridesFetcher.createPowerset(metadata.ALBUMARTIST || metadata.artist, | ||
metadata.album)) | ||
{ | ||
let lookup_result = this.#data[JSON.stringify(v)]; | ||
|
||
if (lookup_result) | ||
{ | ||
if (!result.artworkUrl && lookup_result.artworkUrl) | ||
{ | ||
result.artworkFrom = lookup_result.artworkFrom; | ||
result.artworkUrl = lookup_result.artworkUrl; | ||
} | ||
if (!result.joinUrl && lookup_result.joinUrl) | ||
{ | ||
result.joinFrom = lookup_result.joinFrom; | ||
result.joinUrl = lookup_result.joinUrl; | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
static createPowerset(albumArtist, albumName) | ||
{ | ||
let result = []; | ||
|
||
if (albumArtist && albumName) | ||
result.push({albumArtist, albumName}); | ||
if (albumArtist) | ||
result.push({albumArtist}); | ||
if (albumName) | ||
result.push({albumName}); | ||
|
||
return result; | ||
} | ||
} | ||
|
||
module.exports = StaticOverridesFetcher; |