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

Fetch image from Wikimedia via MusicBrainz #49

Merged
merged 8 commits into from
Dec 26, 2020
Merged

Conversation

dmcneary
Copy link
Contributor

@dmcneary dmcneary commented Dec 2, 2020

resolves #44
(mostly)

I set up a fetch call to MusicBrainz, which I have working most of the time to grab an image and change the background. It scrapes an image from Wikimedia, as long as there is one available. Some bands, however, don't have any images on Wikimedia.

lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
@sunny sunny mentioned this pull request Dec 4, 2020
Copy link
Owner

@sunny sunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this Pull-Request, this is awesome! I've marked most of HoundCI's suggestions as resolved since they should be outdated now that #50 is merged.

Can you apply the suggestions and rebase on top of main? 🙏

lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
@sunny
Copy link
Owner

sunny commented Dec 19, 2020

Hey @dmcneary, any chance you will have some time to look over the requested changes?

const filename =
imageUrl.substring(imageUrl.lastIndexOf('/') + 1);
imageUrl =
'https://commons.wikimedia.org/wiki/Special:Redirect/file/' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

let commonsStub =
'https://commons.wikimedia.org/wiki/File:';
if (imageUrl.startsWith(commonsStub)) {
const filename =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

const imagesArr = [];
for (let i = 0; i < relations.length; i++) {
if (relations[i].type === 'image') {
let imageUrl = relations[i].url.resource;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
if (!artist) return callback();
cache = artistImage.cache;
artist = encodeURI(artist);
const getImageFromCache =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that merging the main branch should make these hints disappear.

lib/sonice/public/script.js Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
var changeBackground = function(){
artistImage(currentSong.artist, function(url) {
$('body').background(url)
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

// Change background on the body regularly
var changeBackground = function(){
artistImage(currentSong.artist, function(url) {
$('body').background(url)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

}

// Change background on the body regularly
var changeBackground = function(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'changeBackground' was used before it was defined.

@@ -52,6 +122,16 @@ $(function() {

if (artistChange || songChange)
$('#vote').removeAttr('disabled').show()

if (artistChange)
changeBackground()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected '{' and instead saw 'changeBackground'.
Missing semicolon.

const filename =
imageUrl.substring(imageUrl.lastIndexOf('/') + 1);
imageUrl =
'https://commons.wikimedia.org/wiki/Special:Redirect/file/' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this can be in a variable nearer the top of the file, such as wikimediaUrlPrefix?

for (let i = 0; i < relations.length; i++) {
if (relations[i].type === 'image') {
let imageUrl = relations[i].url.resource;
let commonsStub =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

@dmcneary
Copy link
Contributor Author

Hey @sunny,

Been busy with finals. I refactored your suggestions, still some little complaints from CI but let me know what you think.

lib/sonice/public/script.js Outdated Show resolved Hide resolved
if (!artist) return callback();
cache = artistImage.cache;
artist = encodeURI(artist);
const getImageFromCache =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that merging the main branch should make these hints disappear.

lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Show resolved Hide resolved
const filename =
imageUrl.substring(imageUrl.lastIndexOf('/') + 1);
imageUrl =
'https://commons.wikimedia.org/wiki/Special:Redirect/file/' +
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this can be in a variable nearer the top of the file, such as wikimediaUrlPrefix?

lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
lib/sonice/public/script.js Outdated Show resolved Hide resolved
}

// Change background on the body regularly
var changeBackground = function () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'changeBackground' was used before it was defined.

$('#vote').removeAttr('disabled').show()
$('#vote').removeAttr('disabled').show();

if (artistChange) changeBackground();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected '{' and instead saw 'changeBackground'.


if (artistChange || songChange)
$('#vote').removeAttr('disabled').show()
$('#vote').removeAttr('disabled').show();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected '{' and instead saw '$'.

else
$('title').text(artist + (artist && title ? ' — ' : '') + title)
$('title').text(artist + (artist && title ? ' — ' : '') + title);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected '{' and instead saw '$'.


if (!title)
$('title').text('So nice')
$('title').text('So nice');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected '{' and instead saw '$'.

.then(res => res.json())
.then(data => {
const relations = data.relations;
const commonsStub =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

fetch(url)
.then(res => res.json())
.then(data => {
const relations = data.relations;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

'?inc=url-rels&fmt=json';
fetch(url)
.then(res => res.json())
.then(data => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

mbid +
'?inc=url-rels&fmt=json';
fetch(url)
.then(res => res.json())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

// (https://github.com/hugovk/now-playing-radiator)
const mbid = response.artist.mbid;
if (!mbid) return;
const url =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

@sunny
Copy link
Owner

sunny commented Dec 26, 2020

Don't know why houndci-bot is still complaining. Looks good to me! Great work, @dmcneary 🎉

image

@sunny sunny merged commit 371ffc7 into sunny:main Dec 26, 2020
@sunny sunny mentioned this pull request Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Images on LastFM's API not working
3 participants