Skip to content

Commit

Permalink
fix(codacy): Fix code quality issues listed by Codacy (#391)
Browse files Browse the repository at this point in the history
From the 43 errors listed in the "Error prone" category of [Codacy - Issues](https://app.codacy.com/gh/openwhyd/openwhyd/issues?bid=17325385&filters=W3siaWQiOiJMYW5ndWFnZSIsInZhbHVlcyI6W119LHsiaWQiOiJDYXRlZ29yeSIsInZhbHVlcyI6WyJFcnJvclByb25lIl19LHsiaWQiOiJMZXZlbCIsInZhbHVlcyI6WyJFcnJvciJdfSx7ImlkIjoiUGF0dGVybiIsInZhbHVlcyI6W119LHsiaWQiOiJBdXRob3IiLCJ2YWx1ZXMiOltdfV0=)

* fix(codacy): disallow empty block statements (no-empty)
https://app.codacy.com/gh/openwhyd/openwhyd/file/50126255144/issues/source?bid=17325385&fileBranchId=17325385#l49

* remove bookmarkletdev.js

* quick fixes in browse.css and ContentEmbed.js

* fix facebook.js

* ignore @typescript-eslint/no-empty-function where needed

* fixes in whyd.js

* fixes in other files

* fix and clean-up whydPlayer.js
  • Loading branch information
adrienjoly committed Nov 11, 2020
1 parent 6beefd6 commit df00b67
Show file tree
Hide file tree
Showing 20 changed files with 201 additions and 880 deletions.
8 changes: 1 addition & 7 deletions public/css/browse.css
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,6 @@ ul#footerLinks > li {
color: #000;
}

.dlgContactUs {
width: 300px;
line-height: 100px;
background: white;
}

.dlgWelcome {
width: 600px;
height: 550px;
Expand Down Expand Up @@ -687,7 +681,7 @@ font-family: Helvetica, Arial, Sans-serif;

.dlgEditPlaylist #imageForm input[type='file'] {
margin-top: 20px;
margin-bottom: 20x;
margin-bottom: 20px;
font-size: 14px;
}

Expand Down
68 changes: 37 additions & 31 deletions public/js/ContentEmbed.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/* global $, showMessage */

/**
* ContentEmbed
* a class for embedding content from openwhyd and other web sites: youtube, dailymotion, vimeo, soundcloud...
* @author adrienjoly, whyd
*/

// DEPRECATED: The track detection and metadata retrieval functionalities are to be replaced by PlayemJS
// TODO: Remove this file

function ContentEmbed() {
var generalUrl = /\/\/[-A-Z0-9+&@#$*'()\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/gi; // \b(?:https?|ftp|file):
var generalUrl = /\/\/[-A-Z0-9+&@#$*'()/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]/gi; // \b(?:https?|ftp|file):
var scClientId = 'eb257e698774349c22b0b727df0238ad';
var JAMENDO_CLIENT_ID = '2c9a11b9';

Expand Down Expand Up @@ -46,7 +49,9 @@ function ContentEmbed() {
try {
var errors = data.headers.error_message + data.headers.warnings;
if (errors) console.log(errors);
} catch (e) {}
} catch (e) {
console.error(e);
}
data = data.results[0];
embedRef.name = data.artist_name + ' - ' + data.name;
embedRef.img = data.album_image;
Expand All @@ -63,7 +68,7 @@ function ContentEmbed() {
var API_KEY = 'vatnajokull';
var API_PREFIX = '//api.bandcamp.com/api';
var API_SUFFIX = '&key=' + API_KEY + '&callback=?';
var REGEX = /([a-zA-Z0-9_\-]+).bandcamp\.com\/track\/([a-zA-Z0-9_\-]+)/;
var REGEX = /([a-zA-Z0-9_-]+).bandcamp\.com\/track\/([a-zA-Z0-9_-]+)/;
function detect(url, cb) {
url = url.split('#')[0].split('//').pop();
var matches = url.match(REGEX);
Expand Down Expand Up @@ -131,7 +136,7 @@ function ContentEmbed() {
}
);
}
var BandcampPlayer = BandcampPlayer || function () {};
var BandcampPlayer = BandcampPlayer || function () {}; // eslint-disable-line @typescript-eslint/no-empty-function
return {
whydPrefix: 'bc',
label: 'Bandcamp',
Expand All @@ -140,7 +145,7 @@ function ContentEmbed() {
getHref: function (embedRef) {
return embedRef.url;
},
renderImg: function (embedRef, callback) {
renderImg: function (embedRef) {
return '<img src="' + embedRef.img + '" />';
},
play: function (embedRef, options, cb) {
Expand Down Expand Up @@ -172,7 +177,7 @@ function ContentEmbed() {
getHref: function (embedRef) {
return embedRef.url;
},
renderImg: function (embedRef, callback) {
renderImg: function (embedRef) {
return '<img src="' + embedRef.img + '" />';
},
};
Expand Down Expand Up @@ -218,7 +223,7 @@ function ContentEmbed() {
if (regexs[i].test(url)) return cb({ url: url, videoId: RegExp.$1 });
cb();
},
getHref: function (embedRef) {
getHref: function () {
return this.url;
},
renderImg: function (embedRef) {
Expand Down Expand Up @@ -248,7 +253,7 @@ function ContentEmbed() {
'sp',
'Spotify',
'//embed.spotify.com/oembed/?url=',
[/spotify\.com\/track\/(\w+)/i, /spotify\:track\:(\w+)/i]
[/spotify\.com\/track\/(\w+)/i, /spotify:track:(\w+)/i]
);

// test: spotify:track:6NmXV4o6bmp704aPGyTVVG => https://open.spotify.com/track/4VGLw2x6oTDc9krhyP0MVP
Expand All @@ -258,7 +263,7 @@ function ContentEmbed() {
label: 'Youtube',
//regex: /https?\:\/\/(?:www\.)?youtu(?:\.)?be(?:\.com)?\/(?:(?:.*)?[\?\&]v=|v\/)?([a-zA-Z0-9_\-]+)/,
//regex: /https?\:\/\/(?:www\.)?youtu(?:\.)?be(?:\.com)?\/(?:(?:.*)?[\?\&]v=|v\/|embed\/|\/)?([a-zA-Z0-9_\-]+)/,
regex: /(youtube\.com\/(v\/|embed\/|(?:.*)?[\?\&]v=)|youtu\.be\/)([a-zA-Z0-9_\-]+)/,
regex: /(youtube\.com\/(v\/|embed\/|(?:.*)?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]+)/,
detect: function (url, cb) {
var m = url.match(this.regex);
cb(
Expand All @@ -272,7 +277,7 @@ function ContentEmbed() {
getHref: function (embedRef) {
return 'https://www.youtube.com/v/' + embedRef.videoId;
},
renderImg: function (embedRef, callback) {
renderImg: function (embedRef) {
return '<img src="' + embedRef.img + '" title="' + embedRef.name + '" />';
},
require: function (embedRef, callback) {
Expand All @@ -293,8 +298,7 @@ function ContentEmbed() {
}
);
},
render: function (embedRef, options, callback) {
var options = options || embedDefaults;
render: function (embedRef, options = embedDefaults, callback) {
var url =
'https://youtube.com/embed/' +
embedRef.videoId +
Expand All @@ -316,13 +320,15 @@ function ContentEmbed() {
var soundcloudEmbed = {
whydPrefix: 'sc',
label: 'Soundcloud',
regex: /soundcloud\.com\/([\w-_\/]+)/, // https?:\/\/(?:www\.)?
regexShort: /snd\.sc\/([\w-_\/]+)/, // https?:\/\/
regex: /soundcloud\.com\/([\w-_/]+)/, // https?:\/\/(?:www\.)?
regexShort: /snd\.sc\/([\w-_/]+)/, // https?:\/\/
detect: function (url, cb) {
if (url.split('?')[0].indexOf('/sets/') > -1) {
try {
showMessage('Soundcloud Sets are not supported yet', true);
} catch (e) {}
} catch (e) {
console.error(e);
}
cb();
return;
}
Expand All @@ -337,20 +343,20 @@ function ContentEmbed() {
});*/ else if (
url.indexOf('soundcloud.com/player') != -1
) {
var url = /url=([^&]*)/.exec(url);
var finalUrl = /url=([^&]*)/.exec(url);
cb(
!url || url.length != 2
!finalUrl || finalUrl.length != 2
? null
: {
url: decodeURIComponent(url[1]),
url: decodeURIComponent(finalUrl[1]),
}
);
} else cb();
},
getHref: function (embedRef) {
return embedRef.url;
},
renderImg: function (embedRef, callback) {
renderImg: function (embedRef) {
return '<img src="' + embedRef.img + '" />';
},
require: function (embedRef, callback) {
Expand All @@ -361,7 +367,7 @@ function ContentEmbed() {
'&client_id=' +
scClientId +
'&callback=?';
$.getJSON(url, function (data, status) {
$.getJSON(url, function (data) {
if (!data || !data.id) return callback();
embedRef.name = data.title;
embedRef.id =
Expand All @@ -377,8 +383,7 @@ function ContentEmbed() {
callback(embedRef);
});
},
render: function (embedRef, options, callback) {
var options = options || embedDefaults;
render: function (embedRef, options = embedDefaults, callback) {
var scId = embedRef.id.split('#').pop();
var url =
'https://w.soundcloud.com/player/?url=' +
Expand All @@ -399,7 +404,7 @@ function ContentEmbed() {
var vimeoEmbed = {
whydPrefix: 'vi',
label: 'Vimeo',
regex: /vimeo\.com\/(clip\:)?(\d+)/, // https?:\/\/(?:www\.)? // http://stackoverflow.com/questions/2662485/simple-php-regex-question
regex: /vimeo\.com\/(clip:)?(\d+)/, // https?:\/\/(?:www\.)? // http://stackoverflow.com/questions/2662485/simple-php-regex-question
detect: function (url, cb) {
var m = url.match(this.regex);
cb(
Expand All @@ -413,7 +418,7 @@ function ContentEmbed() {
getHref: function (embedRef) {
return 'https://vimeo.com/' + embedRef.videoId;
},
renderImg: function (embedRef, callback) {
renderImg: function (embedRef) {
return '<img src="' + embedRef.img + '" />';
},
require: function (embedRef, callback) {
Expand All @@ -431,8 +436,7 @@ function ContentEmbed() {
}
);
},
render: function (embedRef, options, callback) {
var options = options || embedDefaults;
render: function (embedRef, options = embedDefaults, callback) {
var url =
'https://player.vimeo.com/video/' +
embedRef.videoId +
Expand Down Expand Up @@ -468,10 +472,10 @@ function ContentEmbed() {
getHref: function (embedRef) {
return embedRef.url; //'http://www.dailymotion.com/swf/' + embedRef.videoId;
},
renderImg: function (embedRef, callback) {
renderImg: function (embedRef) {
return (
'<img src="https://www.dailymotion.com/thumbnail/video/' +
videoId +
embedRef.videoId +
'" />'
);
},
Expand All @@ -487,7 +491,7 @@ function ContentEmbed() {
//console.log(data)
embedRef.img = data.thumbnail_url; //.replace("_preview_medium", "_preview_large");
embedRef.name = data.title;
embedRef.url = /src=\"([^\"]*)\"/.exec(data.html).pop();
embedRef.url = /src="([^"]*)"/.exec(data.html).pop();
if (embedRef.url)
embedRef.videoId = decodeURIComponent(embedRef.url)
.split('/')
Expand Down Expand Up @@ -542,7 +546,7 @@ function ContentEmbed() {
}
function detectNext(i) {
if (i == embedDetectors.length) return fallback();
var detectorName = Object.keys(embedTypes)[i];
// var detectorName = Object.keys(embedTypes)[i];
//console.log(detectorName, "...");
embedDetectors[i].detect(url, function (embedRef) {
//console.log(detectorName, "->", embedRef);
Expand Down Expand Up @@ -613,4 +617,6 @@ function ContentEmbed() {

try {
module.exports = ContentEmbed;
} catch (e) {}
} catch (e) {
/* do nothing */
}
4 changes: 3 additions & 1 deletion public/js/TrackFinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ window.$ =
var res = undefined;
try {
res = JSON.parse(this.responseText);
} catch (e) {}
} catch (e) {
console.error(e);
}
cb(res, this);
};
r.open('get', src, true);
Expand Down
Loading

0 comments on commit df00b67

Please sign in to comment.