fix: apply fix from eslint

This commit is contained in:
JellyBrick
2024-10-13 22:45:11 +09:00
parent f42f20f770
commit cb1381bbb3
85 changed files with 1858 additions and 1042 deletions

View File

@ -5,9 +5,20 @@ import type { SongInfo } from '@/providers/song-info';
export abstract class ScrobblerBase {
public abstract isSessionCreated(config: ScrobblerPluginConfig): boolean;
public abstract createSession(config: ScrobblerPluginConfig, setConfig: SetConfType): Promise<ScrobblerPluginConfig>;
public abstract createSession(
config: ScrobblerPluginConfig,
setConfig: SetConfType,
): Promise<ScrobblerPluginConfig>;
public abstract setNowPlaying(songInfo: SongInfo, config: ScrobblerPluginConfig, setConfig: SetConfType): void;
public abstract setNowPlaying(
songInfo: SongInfo,
config: ScrobblerPluginConfig,
setConfig: SetConfType,
): void;
public abstract addScrobble(songInfo: SongInfo, config: ScrobblerPluginConfig, setConfig: SetConfType): void;
public abstract addScrobble(
songInfo: SongInfo,
config: ScrobblerPluginConfig,
setConfig: SetConfType,
): void;
}

View File

@ -81,7 +81,11 @@ export class LastFmScrobbler extends ScrobblerBase {
return config;
}
override setNowPlaying(songInfo: SongInfo, config: ScrobblerPluginConfig, setConfig: SetConfType): void {
override setNowPlaying(
songInfo: SongInfo,
config: ScrobblerPluginConfig,
setConfig: SetConfType,
): void {
if (!config.scrobblers.lastfm.sessionKey) {
return;
}
@ -93,7 +97,11 @@ export class LastFmScrobbler extends ScrobblerBase {
this.postSongDataToAPI(songInfo, config, data, setConfig);
}
override addScrobble(songInfo: SongInfo, config: ScrobblerPluginConfig, setConfig: SetConfType): void {
override addScrobble(
songInfo: SongInfo,
config: ScrobblerPluginConfig,
setConfig: SetConfType,
): void {
if (!config.scrobblers.lastfm.sessionKey) {
return;
}
@ -101,7 +109,9 @@ export class LastFmScrobbler extends ScrobblerBase {
// This adds one scrobbled song to last.fm
const data = {
method: 'track.scrobble',
timestamp: Math.trunc((Date.now() - (songInfo.elapsedSeconds ?? 0)) / 1000),
timestamp: Math.trunc(
(Date.now() - (songInfo.elapsedSeconds ?? 0)) / 1000,
),
};
this.postSongDataToAPI(songInfo, config, data, setConfig);
}
@ -195,8 +205,7 @@ const createApiSig = (parameters: LastFmSongData, secret: string) => {
// This function creates the api signature, see: https://www.last.fm/api/authspec
let sig = '';
Object
.entries(parameters)
Object.entries(parameters)
.sort(([a], [b]) => a.localeCompare(b))
.forEach(([key, value]) => {
if (key === 'format') {
@ -212,12 +221,8 @@ const createApiSig = (parameters: LastFmSongData, secret: string) => {
const createToken = async ({
scrobblers: {
lastfm: {
apiKey,
apiRoot,
secret,
}
}
lastfm: { apiKey, apiRoot, secret },
},
}: ScrobblerPluginConfig) => {
// Creates and stores the auth token
const data: {
@ -240,7 +245,10 @@ const createToken = async ({
let authWindowOpened = false;
let latestAuthResult = false;
const authenticate = async (config: ScrobblerPluginConfig, mainWindow: BrowserWindow) => {
const authenticate = async (
config: ScrobblerPluginConfig,
mainWindow: BrowserWindow,
) => {
return new Promise<boolean>((resolve) => {
if (!authWindowOpened) {
authWindowOpened = true;
@ -266,9 +274,10 @@ const authenticate = async (config: ScrobblerPluginConfig, mainWindow: BrowserWi
const url = new URL(newUrl);
if (url.hostname.endsWith('last.fm')) {
if (url.pathname === '/api/auth') {
const isApproveScreen = await browserWindow.webContents.executeJavaScript(
'!!document.getElementsByName(\'confirm\').length'
) as boolean;
const isApproveScreen =
(await browserWindow.webContents.executeJavaScript(
"!!document.getElementsByName('confirm').length",
)) as boolean;
// successful authentication
if (!isApproveScreen) {
resolve(true);
@ -287,7 +296,7 @@ const authenticate = async (config: ScrobblerPluginConfig, mainWindow: BrowserWi
dialog.showMessageBox({
title: t('plugins.scrobbler.dialog.lastfm.auth-failed.title'),
message: t('plugins.scrobbler.dialog.lastfm.auth-failed.message'),
type: 'error'
type: 'error',
});
}
authWindowOpened = false;

View File

@ -29,12 +29,22 @@ export class ListenbrainzScrobbler extends ScrobblerBase {
return true;
}
override createSession(config: ScrobblerPluginConfig, _setConfig: SetConfType): Promise<ScrobblerPluginConfig> {
override createSession(
config: ScrobblerPluginConfig,
_setConfig: SetConfType,
): Promise<ScrobblerPluginConfig> {
return Promise.resolve(config);
}
override setNowPlaying(songInfo: SongInfo, config: ScrobblerPluginConfig, _setConfig: SetConfType): void {
if (!config.scrobblers.listenbrainz.apiRoot || !config.scrobblers.listenbrainz.token) {
override setNowPlaying(
songInfo: SongInfo,
config: ScrobblerPluginConfig,
_setConfig: SetConfType,
): void {
if (
!config.scrobblers.listenbrainz.apiRoot ||
!config.scrobblers.listenbrainz.token
) {
return;
}
@ -42,8 +52,15 @@ export class ListenbrainzScrobbler extends ScrobblerBase {
submitListen(body, config);
}
override addScrobble(songInfo: SongInfo, config: ScrobblerPluginConfig, _setConfig: SetConfType): void {
if (!config.scrobblers.listenbrainz.apiRoot || !config.scrobblers.listenbrainz.token) {
override addScrobble(
songInfo: SongInfo,
config: ScrobblerPluginConfig,
_setConfig: SetConfType,
): void {
if (
!config.scrobblers.listenbrainz.apiRoot ||
!config.scrobblers.listenbrainz.token
) {
return;
}
@ -54,7 +71,10 @@ export class ListenbrainzScrobbler extends ScrobblerBase {
}
}
function createRequestBody(listenType: string, songInfo: SongInfo): ListenbrainzRequestBody {
function createRequestBody(
listenType: string,
songInfo: SongInfo,
): ListenbrainzRequestBody {
const trackMetadata = {
artist_name: songInfo.artist,
track_name: songInfo.title,
@ -64,7 +84,7 @@ function createRequestBody(listenType: string, songInfo: SongInfo): Listenbrainz
submission_client: 'YouTube Music Desktop App - Scrobbler Plugin',
origin_url: songInfo.url,
duration: songInfo.songDuration,
}
},
};
return {
@ -72,19 +92,23 @@ function createRequestBody(listenType: string, songInfo: SongInfo): Listenbrainz
payload: [
{
track_metadata: trackMetadata,
}
]
},
],
};
}
function submitListen(body: ListenbrainzRequestBody, config: ScrobblerPluginConfig) {
net.fetch(config.scrobblers.listenbrainz.apiRoot + 'submit-listens',
{
function submitListen(
body: ListenbrainzRequestBody,
config: ScrobblerPluginConfig,
) {
net
.fetch(config.scrobblers.listenbrainz.apiRoot + 'submit-listens', {
method: 'POST',
body: JSON.stringify(body),
headers: {
'Authorization': 'Token ' + config.scrobblers.listenbrainz.token,
'Content-Type': 'application/json',
}
}).catch(console.error);
},
})
.catch(console.error);
}