diff --git a/src/backend/common/errors/ErrorUtils.ts b/src/backend/common/errors/ErrorUtils.ts index 9b7055d4..e8f0f72d 100644 --- a/src/backend/common/errors/ErrorUtils.ts +++ b/src/backend/common/errors/ErrorUtils.ts @@ -1,4 +1,4 @@ -import {ResponseError} from "superagent"; +import { ResponseError } from "superagent"; export const isSuperAgentResponseError = (e: any): e is ResponseError => { return typeof e === 'object' diff --git a/src/backend/common/errors/NodeErrors.ts b/src/backend/common/errors/NodeErrors.ts index d487f2fc..adfe0e61 100644 --- a/src/backend/common/errors/NodeErrors.ts +++ b/src/backend/common/errors/NodeErrors.ts @@ -1,6 +1,6 @@ +import { findCauseByFunc } from "../../utils.js"; import { isArbitraryObject } from "../infrastructure/Atomic.js"; import ErrnoException = NodeJS.ErrnoException; -import { findCauseByFunc } from "../../utils.js"; export type NodeNetworkErrorCode = 'ENOTFOUND' | 'ETIMEDOUT' | 'EAI_AGAIN' | 'ECONNRESET' | 'ECONNREFUSED' | 'ERRADDRINUSE' | 'EADDRNOTAVAIL' | 'ECONNABORTED' | 'EHOSTUNREACH'; export const NETWORK_ERROR_CODES: NodeNetworkErrorCode[] = ['ENOTFOUND', 'ETIMEDOUT', 'EAI_AGAIN', 'ECONNRESET', 'ECONNREFUSED', 'ERRADDRINUSE', 'EADDRNOTAVAIL', 'ECONNABORTED', 'EHOSTUNREACH']; diff --git a/src/backend/common/errors/UpstreamError.ts b/src/backend/common/errors/UpstreamError.ts index 452385a3..fc0ab357 100644 --- a/src/backend/common/errors/UpstreamError.ts +++ b/src/backend/common/errors/UpstreamError.ts @@ -1,5 +1,5 @@ +import { Response } from 'superagent'; import { findCauseByFunc } from "../../utils.js"; -import {Response} from 'superagent'; export class UpstreamError extends Error { diff --git a/src/backend/common/infrastructure/Atomic.ts b/src/backend/common/infrastructure/Atomic.ts index 1b36c804..e27dfffe 100644 --- a/src/backend/common/infrastructure/Atomic.ts +++ b/src/backend/common/infrastructure/Atomic.ts @@ -1,10 +1,10 @@ -import {Dayjs} from "dayjs"; -import {FixedSizeList} from 'fixed-size-list'; -import {Logger} from '@foxxmd/logging'; +import { Logger } from '@foxxmd/logging'; +import { Dayjs } from "dayjs"; +import { Request, Response } from "express"; +import { NextFunction, ParamsDictionary, Query } from "express-serve-static-core"; +import { FixedSizeList } from 'fixed-size-list'; +import { PlayMeta, PlayObject } from "../../../core/Atomic.js"; import TupleMap from "../TupleMap.js"; -import {Request, Response} from "express"; -import {NextFunction, ParamsDictionary, Query} from "express-serve-static-core"; -import {PlayMeta, PlayObject} from "../../../core/Atomic.js"; export type SourceType = 'spotify' | 'plex' | 'tautulli' | 'subsonic' | 'jellyfin' | 'lastfm' | 'deezer' | 'ytmusic' | 'mpris' | 'mopidy' | 'listenbrainz' | 'jriver' | 'kodi' | 'webscrobbler' | 'chromecast'; export const sourceTypes: SourceType[] = ['spotify', 'plex', 'tautulli', 'subsonic', 'jellyfin', 'lastfm', 'deezer', 'ytmusic', 'mpris', 'mopidy', 'listenbrainz', 'jriver', 'kodi', 'webscrobbler', 'chromecast']; diff --git a/src/backend/common/infrastructure/config/aioConfig.ts b/src/backend/common/infrastructure/config/aioConfig.ts index 1eb73bd2..7546983a 100644 --- a/src/backend/common/infrastructure/config/aioConfig.ts +++ b/src/backend/common/infrastructure/config/aioConfig.ts @@ -1,9 +1,9 @@ -import { CommonSourceOptions, ScrobbleThresholds, SourceRetryOptions } from "./source/index.js"; -import { RequestRetryOptions } from "./common.js"; -import { SourceAIOConfig } from "./source/sources.js"; +import { LogOptions } from "@foxxmd/logging"; import { ClientAIOConfig } from "./client/clients.js"; +import { RequestRetryOptions } from "./common.js"; import { WebhookConfig } from "./health/webhooks.js"; -import {LogOptions} from "@foxxmd/logging"; +import { CommonSourceOptions, ScrobbleThresholds, SourceRetryOptions } from "./source/index.js"; +import { SourceAIOConfig } from "./source/sources.js"; export interface SourceDefaults extends SourceRetryOptions { diff --git a/src/backend/common/infrastructure/config/client/clients.ts b/src/backend/common/infrastructure/config/client/clients.ts index ed5cd584..535d1607 100644 --- a/src/backend/common/infrastructure/config/client/clients.ts +++ b/src/backend/common/infrastructure/config/client/clients.ts @@ -1,6 +1,6 @@ -import { MalojaClientAIOConfig, MalojaClientConfig } from "./maloja.js"; import { LastfmClientAIOConfig, LastfmClientConfig } from "./lastfm.js"; import { ListenBrainzClientAIOConfig, ListenBrainzClientConfig } from "./listenbrainz.js"; +import { MalojaClientAIOConfig, MalojaClientConfig } from "./maloja.js"; export type ClientConfig = MalojaClientConfig | LastfmClientConfig | ListenBrainzClientConfig; diff --git a/src/backend/common/infrastructure/config/client/lastfm.ts b/src/backend/common/infrastructure/config/client/lastfm.ts index 4558230a..2507d721 100644 --- a/src/backend/common/infrastructure/config/client/lastfm.ts +++ b/src/backend/common/infrastructure/config/client/lastfm.ts @@ -1,5 +1,5 @@ -import { CommonClientConfig, CommonClientData } from "./index.js"; import { RequestRetryOptions } from "../common.js"; +import { CommonClientConfig, CommonClientData } from "./index.js"; export interface LastfmData extends RequestRetryOptions { /** diff --git a/src/backend/common/infrastructure/config/client/listenbrainz.ts b/src/backend/common/infrastructure/config/client/listenbrainz.ts index ee8e0835..a852db39 100644 --- a/src/backend/common/infrastructure/config/client/listenbrainz.ts +++ b/src/backend/common/infrastructure/config/client/listenbrainz.ts @@ -1,5 +1,5 @@ -import { CommonClientConfig, CommonClientData } from "./index.js"; import { RequestRetryOptions } from "../common.js"; +import { CommonClientConfig, CommonClientData } from "./index.js"; export interface ListenBrainzData extends RequestRetryOptions{ /** diff --git a/src/backend/common/infrastructure/config/client/maloja.ts b/src/backend/common/infrastructure/config/client/maloja.ts index 633f4daf..59d9170e 100644 --- a/src/backend/common/infrastructure/config/client/maloja.ts +++ b/src/backend/common/infrastructure/config/client/maloja.ts @@ -1,5 +1,5 @@ -import { CommonClientConfig, CommonClientData } from "./index.js"; import { RequestRetryOptions } from "../common.js"; +import { CommonClientConfig, CommonClientData } from "./index.js"; export interface MalojaClientData extends RequestRetryOptions, CommonClientData { /** diff --git a/src/backend/common/infrastructure/config/source/jriver.ts b/src/backend/common/infrastructure/config/source/jriver.ts index 6459610e..e53c2a40 100644 --- a/src/backend/common/infrastructure/config/source/jriver.ts +++ b/src/backend/common/infrastructure/config/source/jriver.ts @@ -1,5 +1,5 @@ -import { CommonSourceConfig, CommonSourceData } from "./index.js"; import { PollingOptions } from "../common.js"; +import { CommonSourceConfig, CommonSourceData } from "./index.js"; export interface JRiverData extends CommonSourceData, PollingOptions { /** diff --git a/src/backend/common/infrastructure/config/source/kodi.ts b/src/backend/common/infrastructure/config/source/kodi.ts index b38dbcfd..f7680940 100644 --- a/src/backend/common/infrastructure/config/source/kodi.ts +++ b/src/backend/common/infrastructure/config/source/kodi.ts @@ -1,5 +1,5 @@ -import { CommonSourceConfig, CommonSourceData } from "./index.js"; import { PollingOptions } from "../common.js"; +import { CommonSourceConfig, CommonSourceData } from "./index.js"; export interface KodiData extends CommonSourceData, PollingOptions { diff --git a/src/backend/common/infrastructure/config/source/lastfm.ts b/src/backend/common/infrastructure/config/source/lastfm.ts index a3faafe1..4360c4aa 100644 --- a/src/backend/common/infrastructure/config/source/lastfm.ts +++ b/src/backend/common/infrastructure/config/source/lastfm.ts @@ -1,6 +1,6 @@ import { LastfmData } from "../client/lastfm.js"; -import { CommonSourceConfig, CommonSourceData } from "./index.js"; import { PollingOptions } from "../common.js"; +import { CommonSourceConfig, CommonSourceData } from "./index.js"; export interface LastFmSourceData extends CommonSourceData, PollingOptions, LastfmData{} diff --git a/src/backend/common/infrastructure/config/source/listenbrainz.ts b/src/backend/common/infrastructure/config/source/listenbrainz.ts index 06ed18e4..b6316fa3 100644 --- a/src/backend/common/infrastructure/config/source/listenbrainz.ts +++ b/src/backend/common/infrastructure/config/source/listenbrainz.ts @@ -1,6 +1,6 @@ -import { CommonSourceConfig, CommonSourceData } from "./index.js"; import { ListenBrainzData } from "../client/listenbrainz.js"; import { PollingOptions } from "../common.js"; +import { CommonSourceConfig, CommonSourceData } from "./index.js"; export interface ListenBrainzSourceData extends ListenBrainzData, CommonSourceData, PollingOptions { } diff --git a/src/backend/common/infrastructure/config/source/mopidy.ts b/src/backend/common/infrastructure/config/source/mopidy.ts index bd0ab082..bf4b1d12 100644 --- a/src/backend/common/infrastructure/config/source/mopidy.ts +++ b/src/backend/common/infrastructure/config/source/mopidy.ts @@ -1,5 +1,5 @@ -import { CommonSourceConfig, CommonSourceData } from "./index.js"; import { PollingOptions } from "../common.js"; +import { CommonSourceConfig, CommonSourceData } from "./index.js"; export interface MopidyData extends CommonSourceData, PollingOptions { /** diff --git a/src/backend/common/infrastructure/config/source/sources.ts b/src/backend/common/infrastructure/config/source/sources.ts index 9798e2a2..dc76a456 100644 --- a/src/backend/common/infrastructure/config/source/sources.ts +++ b/src/backend/common/infrastructure/config/source/sources.ts @@ -1,18 +1,18 @@ -import { SpotifySourceAIOConfig, SpotifySourceConfig } from "./spotify.js"; -import { PlexSourceAIOConfig, PlexSourceConfig } from "./plex.js"; -import { TautulliSourceAIOConfig, TautulliSourceConfig } from "./tautulli.js"; +import { ChromecastSourceAIOConfig, ChromecastSourceConfig } from "./chromecast.js"; import { DeezerSourceAIOConfig, DeezerSourceConfig } from "./deezer.js"; -import { SubsonicSourceAIOConfig, SubSonicSourceConfig } from "./subsonic.js"; import { JellySourceAIOConfig, JellySourceConfig } from "./jellyfin.js"; -import { LastFmSouceAIOConfig, LastfmSourceConfig } from "./lastfm.js"; -import { YTMusicSourceAIOConfig, YTMusicSourceConfig } from "./ytmusic.js"; -import { MPRISSourceAIOConfig, MPRISSourceConfig } from "./mpris.js"; -import { MopidySourceAIOConfig, MopidySourceConfig } from "./mopidy.js"; -import { ListenBrainzSourceAIOConfig, ListenBrainzSourceConfig } from "./listenbrainz.js"; import { JRiverSourceAIOConfig, JRiverSourceConfig } from "./jriver.js"; import { KodiSourceAIOConfig, KodiSourceConfig } from "./kodi.js"; +import { LastFmSouceAIOConfig, LastfmSourceConfig } from "./lastfm.js"; +import { ListenBrainzSourceAIOConfig, ListenBrainzSourceConfig } from "./listenbrainz.js"; +import { MopidySourceAIOConfig, MopidySourceConfig } from "./mopidy.js"; +import { MPRISSourceAIOConfig, MPRISSourceConfig } from "./mpris.js"; +import { PlexSourceAIOConfig, PlexSourceConfig } from "./plex.js"; +import { SpotifySourceAIOConfig, SpotifySourceConfig } from "./spotify.js"; +import { SubsonicSourceAIOConfig, SubSonicSourceConfig } from "./subsonic.js"; +import { TautulliSourceAIOConfig, TautulliSourceConfig } from "./tautulli.js"; import { WebScrobblerSourceAIOConfig, WebScrobblerSourceConfig } from "./webscrobbler.js"; -import { ChromecastSourceConfig, ChromecastSourceAIOConfig } from "./chromecast.js"; +import { YTMusicSourceAIOConfig, YTMusicSourceConfig } from "./ytmusic.js"; export type SourceConfig = SpotifySourceConfig | PlexSourceConfig | TautulliSourceConfig | DeezerSourceConfig | SubSonicSourceConfig | JellySourceConfig | LastfmSourceConfig | YTMusicSourceConfig | MPRISSourceConfig | MopidySourceConfig | ListenBrainzSourceConfig | JRiverSourceConfig | KodiSourceConfig | WebScrobblerSourceConfig | ChromecastSourceConfig; diff --git a/src/backend/common/infrastructure/config/source/spotify.ts b/src/backend/common/infrastructure/config/source/spotify.ts index ed624638..742e0daf 100644 --- a/src/backend/common/infrastructure/config/source/spotify.ts +++ b/src/backend/common/infrastructure/config/source/spotify.ts @@ -1,5 +1,5 @@ -import { CommonSourceConfig, CommonSourceData } from "./index.js"; import { PollingOptions } from "../common.js"; +import { CommonSourceConfig, CommonSourceData } from "./index.js"; export interface SpotifySourceData extends CommonSourceData, PollingOptions { /** diff --git a/src/backend/common/infrastructure/config/source/subsonic.ts b/src/backend/common/infrastructure/config/source/subsonic.ts index 6a34c959..63a5999d 100644 --- a/src/backend/common/infrastructure/config/source/subsonic.ts +++ b/src/backend/common/infrastructure/config/source/subsonic.ts @@ -1,5 +1,5 @@ -import { CommonSourceConfig, CommonSourceData } from "./index.js"; import { PollingOptions } from "../common.js"; +import { CommonSourceConfig, CommonSourceData } from "./index.js"; export interface SubsonicData extends CommonSourceData, PollingOptions { /** diff --git a/src/backend/common/infrastructure/config/source/ytmusic.ts b/src/backend/common/infrastructure/config/source/ytmusic.ts index 4e858c4b..a5b71e00 100644 --- a/src/backend/common/infrastructure/config/source/ytmusic.ts +++ b/src/backend/common/infrastructure/config/source/ytmusic.ts @@ -1,5 +1,5 @@ -import { CommonSourceConfig, CommonSourceData } from "./index.js"; import { PollingOptions } from "../common.js"; +import { CommonSourceConfig, CommonSourceData } from "./index.js"; export interface YTMusicData extends CommonSourceData, PollingOptions { /** diff --git a/src/backend/common/infrastructure/typings/passport-deezer.d.ts b/src/backend/common/infrastructure/typings/passport-deezer.d.ts index 21c498cd..22015895 100644 --- a/src/backend/common/infrastructure/typings/passport-deezer.d.ts +++ b/src/backend/common/infrastructure/typings/passport-deezer.d.ts @@ -1,7 +1,8 @@ declare module 'passport-deezer' { //import {Strategy as Oauth2Strategy} from 'passport-oauth2'; - import {Strategy as PassportStrategy} from "passport"; + import { Strategy as PassportStrategy } from "passport"; + export class Strategy extends PassportStrategy { constructor(options: any, verify: any); } diff --git a/src/backend/common/logging.ts b/src/backend/common/logging.ts index 6b58639d..45ac8379 100644 --- a/src/backend/common/logging.ts +++ b/src/backend/common/logging.ts @@ -1,16 +1,16 @@ -import path from "path"; -import { projectDir } from "./index.js"; -import process from "process"; import { - parseLogOptions, + childLogger, + Logger as FoxLogger, loggerAppRolling, + LogLevel, LogOptions as FoxLogOptions, - Logger as FoxLogger, - childLogger, LogLevel, PrettyOptionsExtra, + parseLogOptions, } from '@foxxmd/logging'; -import {PassThrough, Transform} from "node:stream"; -import {buildLogger, buildDestinationStdout, buildDestinationJsonPrettyStream} from "@foxxmd/logging/factory"; -import {parseBool} from "../utils.js"; +import { buildDestinationJsonPrettyStream, buildDestinationStdout, buildLogger } from "@foxxmd/logging/factory"; +import { PassThrough, Transform } from "node:stream"; +import path from "path"; +import process from "process"; +import { projectDir } from "./index.js"; export let logPath = path.resolve(projectDir, `./logs`); if (typeof process.env.CONFIG_DIR === 'string') { diff --git a/src/backend/common/vendor/AbstractApiClient.ts b/src/backend/common/vendor/AbstractApiClient.ts index 8357e7d1..99cf8391 100644 --- a/src/backend/common/vendor/AbstractApiClient.ts +++ b/src/backend/common/vendor/AbstractApiClient.ts @@ -1,7 +1,7 @@ -import {childLogger, Logger} from "@foxxmd/logging"; -import {AbstractApiOptions, FormatPlayObjectOptions} from "../infrastructure/Atomic.js"; +import { childLogger, Logger } from "@foxxmd/logging"; import { PlayObject } from "../../../core/Atomic.js"; import { capitalize } from "../../../core/StringUtils.js"; +import { AbstractApiOptions, FormatPlayObjectOptions } from "../infrastructure/Atomic.js"; export default abstract class AbstractApiClient { name: string; diff --git a/src/backend/common/vendor/JRiverApiClient.ts b/src/backend/common/vendor/JRiverApiClient.ts index a9d40f9a..c2b2c6c7 100644 --- a/src/backend/common/vendor/JRiverApiClient.ts +++ b/src/backend/common/vendor/JRiverApiClient.ts @@ -1,8 +1,8 @@ -import AbstractApiClient from "./AbstractApiClient.js"; -import {JRiverData} from "../infrastructure/config/source/jriver.js"; -import request, {Request, Response} from 'superagent'; +import request, { Request, Response } from 'superagent'; import xml2js from 'xml2js'; -import {AbstractApiOptions, DEFAULT_RETRY_MULTIPLIER} from "../infrastructure/Atomic.js"; +import { AbstractApiOptions, DEFAULT_RETRY_MULTIPLIER } from "../infrastructure/Atomic.js"; +import { JRiverData } from "../infrastructure/config/source/jriver.js"; +import AbstractApiClient from "./AbstractApiClient.js"; const parser = new xml2js.Parser({'async': true}); diff --git a/src/backend/common/vendor/KodiApiClient.ts b/src/backend/common/vendor/KodiApiClient.ts index 61b63eb8..b6e2390a 100644 --- a/src/backend/common/vendor/KodiApiClient.ts +++ b/src/backend/common/vendor/KodiApiClient.ts @@ -1,12 +1,12 @@ -import AbstractApiClient from "./AbstractApiClient.js"; -import { KodiData } from "../infrastructure/config/source/kodi.js"; +import dayjs from "dayjs"; import { KodiClient } from 'kodi-api' import normalizeUrl from "normalize-url"; -import {URL} from "url"; -import { RecentlyPlayedOptions } from "../../sources/AbstractSource.js"; -import {AbstractApiOptions, FormatPlayObjectOptions} from "../infrastructure/Atomic.js"; -import dayjs from "dayjs"; +import { URL } from "url"; import { PlayObject } from "../../../core/Atomic.js"; +import { RecentlyPlayedOptions } from "../../sources/AbstractSource.js"; +import { AbstractApiOptions, FormatPlayObjectOptions } from "../infrastructure/Atomic.js"; +import { KodiData } from "../infrastructure/config/source/kodi.js"; +import AbstractApiClient from "./AbstractApiClient.js"; interface KodiDuration { hours: number diff --git a/src/backend/common/vendor/LastfmApiClient.ts b/src/backend/common/vendor/LastfmApiClient.ts index 4f0d6595..bc2c4136 100644 --- a/src/backend/common/vendor/LastfmApiClient.ts +++ b/src/backend/common/vendor/LastfmApiClient.ts @@ -1,3 +1,4 @@ +import dayjs from "dayjs"; import LastFm, { AuthGetSessionResponse, NowPlayingResponse, @@ -5,16 +6,15 @@ import LastFm, { TrackScrobblePayload, UserGetInfoResponse } from "lastfm-node-client"; -import AbstractApiClient from "./AbstractApiClient.js"; -import dayjs from "dayjs"; -import {readJson, removeUndefinedKeys, sleep, writeFile} from "../../utils.js"; -import {AbstractApiOptions, DEFAULT_RETRY_MULTIPLIER, FormatPlayObjectOptions} from "../infrastructure/Atomic.js"; -import { LastfmData } from "../infrastructure/config/client/lastfm.js"; import { PlayObject } from "../../../core/Atomic.js"; -import {getNodeNetworkException, isNodeNetworkException} from "../errors/NodeErrors.js"; -import {nonEmptyStringOrDefault, splitByFirstFound} from "../../../core/StringUtils.js"; -import {getScrobbleTsSOCDate} from "../../utils/TimeUtils.js"; -import {UpstreamError} from "../errors/UpstreamError.js"; +import { nonEmptyStringOrDefault, splitByFirstFound } from "../../../core/StringUtils.js"; +import { readJson, removeUndefinedKeys, sleep, writeFile } from "../../utils.js"; +import { getScrobbleTsSOCDate } from "../../utils/TimeUtils.js"; +import { getNodeNetworkException, isNodeNetworkException } from "../errors/NodeErrors.js"; +import { UpstreamError } from "../errors/UpstreamError.js"; +import { AbstractApiOptions, DEFAULT_RETRY_MULTIPLIER, FormatPlayObjectOptions } from "../infrastructure/Atomic.js"; +import { LastfmData } from "../infrastructure/config/client/lastfm.js"; +import AbstractApiClient from "./AbstractApiClient.js"; const badErrors = [ 'api key suspended', diff --git a/src/backend/common/vendor/ListenbrainzApiClient.ts b/src/backend/common/vendor/ListenbrainzApiClient.ts index 417836d2..a4bc2226 100644 --- a/src/backend/common/vendor/ListenbrainzApiClient.ts +++ b/src/backend/common/vendor/ListenbrainzApiClient.ts @@ -1,12 +1,9 @@ -import AbstractApiClient from "./AbstractApiClient.js"; -import request, {Request} from 'superagent'; -import { ListenBrainzClientData } from "../infrastructure/config/client/listenbrainz.js"; -import {AbstractApiOptions, DEFAULT_RETRY_MULTIPLIER, FormatPlayObjectOptions} from "../infrastructure/Atomic.js"; -import dayjs from "dayjs"; import { stringSameness } from '@foxxmd/string-sameness'; -import { combinePartsToString } from "../../utils.js"; +import dayjs from "dayjs"; +import request, { Request } from 'superagent'; import { PlayObject } from "../../../core/Atomic.js"; import { slice } from "../../../core/StringUtils.js"; +import { combinePartsToString } from "../../utils.js"; import { findDelimiters, normalizeStr, @@ -15,8 +12,11 @@ import { parseTrackCredits, uniqueNormalizedStrArr, } from "../../utils/StringUtils.js"; -import { UpstreamError } from "../errors/UpstreamError.js"; import { getScrobbleTsSOCDate } from "../../utils/TimeUtils.js"; +import { UpstreamError } from "../errors/UpstreamError.js"; +import { AbstractApiOptions, DEFAULT_RETRY_MULTIPLIER, FormatPlayObjectOptions } from "../infrastructure/Atomic.js"; +import { ListenBrainzClientData } from "../infrastructure/config/client/listenbrainz.js"; +import AbstractApiClient from "./AbstractApiClient.js"; export interface ArtistMBIDMapping { diff --git a/src/backend/common/vendor/chromecast/ChromecastClientUtils.ts b/src/backend/common/vendor/chromecast/ChromecastClientUtils.ts index cfcd11a3..ad59291d 100644 --- a/src/backend/common/vendor/chromecast/ChromecastClientUtils.ts +++ b/src/backend/common/vendor/chromecast/ChromecastClientUtils.ts @@ -1,8 +1,8 @@ -import { REPORTED_PLAYER_STATUSES, ReportedPlayerStatus } from "../../infrastructure/Atomic.js"; -import { PlatformApplication, PlatformType } from "./interfaces.js"; -import {Media, MediaController, Result} from "@foxxmd/chromecast-client"; +import { Media, MediaController, Result } from "@foxxmd/chromecast-client"; import objectHash from "object-hash"; import { PlayObject } from "../../../../core/Atomic.js"; +import { REPORTED_PLAYER_STATUSES, ReportedPlayerStatus } from "../../infrastructure/Atomic.js"; +import { PlatformApplication, PlatformType } from "./interfaces.js"; export const chromePlayerStateToReported = (state: string): ReportedPlayerStatus => { switch (state) { diff --git a/src/backend/common/vendor/chromecast/interfaces.ts b/src/backend/common/vendor/chromecast/interfaces.ts index 41494d1c..f2929989 100644 --- a/src/backend/common/vendor/chromecast/interfaces.ts +++ b/src/backend/common/vendor/chromecast/interfaces.ts @@ -1,7 +1,7 @@ -import {createPlatform, MediaController, PersistentClient} from "@foxxmd/chromecast-client"; +import { createPlatform, MediaController } from "@foxxmd/chromecast-client"; +import { Logger } from "@foxxmd/logging"; +import { Dayjs } from "dayjs"; import { FormatPlayObjectOptions } from "../../infrastructure/Atomic.js"; -import {Dayjs} from "dayjs"; -import {Logger} from "@foxxmd/logging"; export type PlatformType = ReturnType; export interface PlatformApplication { diff --git a/src/backend/common/vendor/maloja/interfaces.ts b/src/backend/common/vendor/maloja/interfaces.ts index f53e4e1f..a3ac3724 100644 --- a/src/backend/common/vendor/maloja/interfaces.ts +++ b/src/backend/common/vendor/maloja/interfaces.ts @@ -1,4 +1,4 @@ -import {ResponseError} from "superagent"; +import { ResponseError } from "superagent"; import { findCauseByFunc } from "../../../utils.js"; import { isSuperAgentResponseError } from "../../errors/ErrorUtils.js"; diff --git a/src/backend/common/vendor/subsonic/interfaces.ts b/src/backend/common/vendor/subsonic/interfaces.ts index 54f1b5ef..a3e384a3 100644 --- a/src/backend/common/vendor/subsonic/interfaces.ts +++ b/src/backend/common/vendor/subsonic/interfaces.ts @@ -1,4 +1,4 @@ -import {Response} from 'superagent'; +import { Response } from 'superagent'; export interface SubsonicResponseCommon { status: 'failed' | 'ok' diff --git a/src/backend/index.ts b/src/backend/index.ts index 340bc2e4..524efa23 100644 --- a/src/backend/index.ts +++ b/src/backend/index.ts @@ -1,23 +1,21 @@ import 'dotenv/config'; -import {LogDataPretty, Logger} from "@foxxmd/logging"; +import { childLogger, LogDataPretty, Logger as FoxLogger } from "@foxxmd/logging"; import dayjs from 'dayjs'; -import utc from 'dayjs/plugin/utc.js'; +import duration from 'dayjs/plugin/duration.js'; import isBetween from 'dayjs/plugin/isBetween.js'; import relativeTime from 'dayjs/plugin/relativeTime.js'; -import duration from 'dayjs/plugin/duration.js'; import timezone from 'dayjs/plugin/timezone.js'; -import { parseBool, readJson, sleep } from "./utils.js"; +import utc from 'dayjs/plugin/utc.js'; import * as path from "path"; +import { SimpleIntervalJob, ToadScheduler } from "toad-scheduler"; import { projectDir } from "./common/index.js"; -import SpotifySource from "./sources/SpotifySource.js"; import { AIOConfig } from "./common/infrastructure/config/aioConfig.js"; +import { appLogger, initLogger as getInitLogger } from "./common/logging.js"; import { getRoot } from "./ioc.js"; -import {appLogger, initLogger as getInitLogger} from "./common/logging.js"; import { initServer } from "./server/index.js"; -import {SimpleIntervalJob, ToadScheduler} from "toad-scheduler"; -import { createHeartbeatSourcesTask } from "./tasks/heartbeatSources.js"; import { createHeartbeatClientsTask } from "./tasks/heartbeatClients.js"; -import {loggerDebug, childLogger, LogData, Logger as FoxLogger} from '@foxxmd/logging'; +import { createHeartbeatSourcesTask } from "./tasks/heartbeatSources.js"; +import { parseBool, readJson, sleep } from "./utils.js"; dayjs.extend(utc) dayjs.extend(isBetween); diff --git a/src/backend/ioc.ts b/src/backend/ioc.ts index 31312f98..cfa7899d 100644 --- a/src/backend/ioc.ts +++ b/src/backend/ioc.ts @@ -1,15 +1,15 @@ -import {createContainer} from "iti"; +import { Logger } from "@foxxmd/logging"; +import { EventEmitter } from "events"; +import fs from 'fs'; +import { createContainer } from "iti"; +import normalizeUrl from 'normalize-url'; import path from "path"; -import { configDir, projectDir } from "./common/index.js"; -import ScrobbleClients from "./scrobblers/ScrobbleClients.js"; -import ScrobbleSources from "./sources/ScrobbleSources.js"; -import { Notifiers } from "./notifier/Notifiers.js"; -import {EventEmitter} from "events"; +import { projectDir } from "./common/index.js"; import { logPath } from "./common/logging.js"; import { WildcardEmitter } from "./common/WildcardEmitter.js"; -import normalizeUrl from 'normalize-url'; -import fs from 'fs'; -import {Logger} from "@foxxmd/logging"; +import { Notifiers } from "./notifier/Notifiers.js"; +import ScrobbleClients from "./scrobblers/ScrobbleClients.js"; +import ScrobbleSources from "./sources/ScrobbleSources.js"; let version = 'Unknown'; diff --git a/src/backend/notifier/AbstractWebhookNotifier.ts b/src/backend/notifier/AbstractWebhookNotifier.ts index bba6be35..4181a09b 100644 --- a/src/backend/notifier/AbstractWebhookNotifier.ts +++ b/src/backend/notifier/AbstractWebhookNotifier.ts @@ -1,6 +1,5 @@ +import { childLogger, Logger } from "@foxxmd/logging"; import { GotifyConfig, NtfyConfig, WebhookPayload } from "../common/infrastructure/config/health/webhooks.js"; -import {childLogger, Logger} from "@foxxmd/logging"; -import { mergeArr } from "../utils.js"; export abstract class AbstractWebhookNotifier { diff --git a/src/backend/notifier/GotifyWebhookNotifier.ts b/src/backend/notifier/GotifyWebhookNotifier.ts index f6a4af28..fa6f93b6 100644 --- a/src/backend/notifier/GotifyWebhookNotifier.ts +++ b/src/backend/notifier/GotifyWebhookNotifier.ts @@ -1,9 +1,9 @@ -import { AbstractWebhookNotifier } from "./AbstractWebhookNotifier.js"; -import { GotifyConfig, PrioritiesConfig, WebhookPayload } from "../common/infrastructure/config/health/webhooks.js"; -import {gotify} from 'gotify'; +import { Logger } from "@foxxmd/logging"; +import { HTTPError } from "got"; +import { gotify } from 'gotify'; import request from 'superagent'; -import {HTTPError} from "got"; -import {Logger} from "@foxxmd/logging"; +import { GotifyConfig, PrioritiesConfig, WebhookPayload } from "../common/infrastructure/config/health/webhooks.js"; +import { AbstractWebhookNotifier } from "./AbstractWebhookNotifier.js"; export class GotifyWebhookNotifier extends AbstractWebhookNotifier { diff --git a/src/backend/notifier/Notifiers.ts b/src/backend/notifier/Notifiers.ts index 5ddb6cca..8fae13b2 100644 --- a/src/backend/notifier/Notifiers.ts +++ b/src/backend/notifier/Notifiers.ts @@ -1,9 +1,14 @@ -import {childLogger, Logger} from '@foxxmd/logging'; -import { GotifyConfig, NtfyConfig, WebhookConfig, WebhookPayload } from "../common/infrastructure/config/health/webhooks.js"; +import { childLogger, Logger } from '@foxxmd/logging'; +import { EventEmitter } from "events"; +import { + GotifyConfig, + NtfyConfig, + WebhookConfig, + WebhookPayload +} from "../common/infrastructure/config/health/webhooks.js"; import { AbstractWebhookNotifier } from "./AbstractWebhookNotifier.js"; import { GotifyWebhookNotifier } from "./GotifyWebhookNotifier.js"; import { NtfyWebhookNotifier } from "./NtfyWebhookNotifier.js"; -import {EventEmitter} from "events"; export class Notifiers { diff --git a/src/backend/notifier/NtfyWebhookNotifier.ts b/src/backend/notifier/NtfyWebhookNotifier.ts index 000cf741..a5aeeae7 100644 --- a/src/backend/notifier/NtfyWebhookNotifier.ts +++ b/src/backend/notifier/NtfyWebhookNotifier.ts @@ -1,9 +1,9 @@ -import { AbstractWebhookNotifier } from "./AbstractWebhookNotifier.js"; -import { NtfyConfig, PrioritiesConfig, WebhookPayload } from "../common/infrastructure/config/health/webhooks.js"; -import {publish} from 'ntfy'; +import { Logger } from "@foxxmd/logging"; +import { publish } from 'ntfy'; +import { Config } from "ntfy/interfaces.js"; import request from "superagent"; -import {Logger} from "@foxxmd/logging"; -import {Config} from "ntfy/interfaces.js"; +import { NtfyConfig, PrioritiesConfig, WebhookPayload } from "../common/infrastructure/config/health/webhooks.js"; +import { AbstractWebhookNotifier } from "./AbstractWebhookNotifier.js"; export class NtfyWebhookNotifier extends AbstractWebhookNotifier { diff --git a/src/backend/scrobblers/AbstractScrobbleClient.ts b/src/backend/scrobblers/AbstractScrobbleClient.ts index fc78a737..d9d7f4df 100644 --- a/src/backend/scrobblers/AbstractScrobbleClient.ts +++ b/src/backend/scrobblers/AbstractScrobbleClient.ts @@ -1,13 +1,20 @@ -import dayjs, {Dayjs} from "dayjs"; +import { childLogger, Logger } from "@foxxmd/logging"; +import dayjs, { Dayjs } from "dayjs"; +import EventEmitter from "events"; +import { FixedSizeList } from 'fixed-size-list'; +import { nanoid } from "nanoid"; +import { messageWithCauses } from "pony-cause"; import { - comparingMultipleArtists, - mergeArr, - playObjDataMatch, - pollingBackoff, - setIntersection, - sleep, - sortByOldestPlayDate, -} from "../utils.js"; + DeadLetterScrobble, + PlayObject, + QueuedScrobble, + TA_CLOSE, + TA_FUZZY, + TrackStringOptions, +} from "../../core/Atomic.js"; +import { buildTrackString, capitalize, truncateStringToLength } from "../../core/StringUtils.js"; +import { hasNodeNetworkException } from "../common/errors/NodeErrors.js"; +import { hasUpstreamError, UpstreamError } from "../common/errors/UpstreamError.js"; import { ARTIST_WEIGHT, Authenticatable, @@ -19,30 +26,21 @@ import { INITIALIZING, InitState, NOT_INITIALIZED, - REFERENCE_WEIGHT, ScrobbledPlayObject, TIME_WEIGHT, TITLE_WEIGHT, } from "../common/infrastructure/Atomic.js"; -import {childLogger, Logger} from "@foxxmd/logging"; import { CommonClientConfig } from "../common/infrastructure/config/client/index.js"; import { Notifiers } from "../notifier/Notifiers.js"; -import {FixedSizeList} from 'fixed-size-list'; import { - DeadLetterScrobble, - PlayObject, - QueuedScrobble, - TA_CLOSE, - TA_FUZZY, - TrackStringOptions, -} from "../../core/Atomic.js"; -import { buildTrackString, capitalize, truncateStringToLength } from "../../core/StringUtils.js"; -import EventEmitter from "events"; + comparingMultipleArtists, + playObjDataMatch, + pollingBackoff, + setIntersection, + sleep, + sortByOldestPlayDate, +} from "../utils.js"; import { compareScrobbleArtists, compareScrobbleTracks, normalizeStr } from "../utils/StringUtils.js"; -import { hasUpstreamError, UpstreamError } from "../common/errors/UpstreamError.js"; -import {nanoid} from "nanoid"; -import {messageWithCauses} from "pony-cause"; -import { hasNodeNetworkException } from "../common/errors/NodeErrors.js"; import { comparePlayTemporally, temporalAccuracyIsAtLeast, diff --git a/src/backend/scrobblers/LastfmScrobbler.ts b/src/backend/scrobblers/LastfmScrobbler.ts index 7f776f0c..c42c1b6d 100644 --- a/src/backend/scrobblers/LastfmScrobbler.ts +++ b/src/backend/scrobblers/LastfmScrobbler.ts @@ -1,25 +1,16 @@ -import AbstractScrobbleClient from "./AbstractScrobbleClient.js"; +import { Logger } from "@foxxmd/logging"; import dayjs from 'dayjs'; - -import { - playObjDataMatch, - removeUndefinedKeys, - setIntersection, - sleep, - sortByOldestPlayDate, -} from "../utils.js"; -import LastfmApiClient from "../common/vendor/LastfmApiClient.js"; -import { FormatPlayObjectOptions, INITIALIZING, ScrobbledPlayObject } from "../common/infrastructure/Atomic.js"; -import { LastfmClientConfig } from "../common/infrastructure/config/client/lastfm.js"; -import {TrackScrobblePayload, TrackScrobbleResponse, UserGetRecentTracksResponse} from "lastfm-node-client"; -import { Notifiers } from "../notifier/Notifiers.js"; -import {Logger} from "@foxxmd/logging"; -import { PlayObject, TrackStringOptions } from "../../core/Atomic.js"; -import { buildTrackString, capitalize } from "../../core/StringUtils.js"; import EventEmitter from "events"; -import { UpstreamError } from "../common/errors/UpstreamError.js"; +import { TrackScrobbleResponse, UserGetRecentTracksResponse } from "lastfm-node-client"; +import { PlayObject } from "../../core/Atomic.js"; +import { buildTrackString, capitalize } from "../../core/StringUtils.js"; import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; -import { getScrobbleTsSOCDate } from "../utils/TimeUtils.js"; +import { UpstreamError } from "../common/errors/UpstreamError.js"; +import { FormatPlayObjectOptions, INITIALIZING } from "../common/infrastructure/Atomic.js"; +import { LastfmClientConfig } from "../common/infrastructure/config/client/lastfm.js"; +import LastfmApiClient from "../common/vendor/LastfmApiClient.js"; +import { Notifiers } from "../notifier/Notifiers.js"; +import AbstractScrobbleClient from "./AbstractScrobbleClient.js"; export default class LastfmScrobbler extends AbstractScrobbleClient { diff --git a/src/backend/scrobblers/ListenbrainzScrobbler.ts b/src/backend/scrobblers/ListenbrainzScrobbler.ts index 81c7c0a7..473d8eae 100644 --- a/src/backend/scrobblers/ListenbrainzScrobbler.ts +++ b/src/backend/scrobblers/ListenbrainzScrobbler.ts @@ -1,16 +1,16 @@ +import { Logger } from "@foxxmd/logging"; import dayjs from 'dayjs'; - -import AbstractScrobbleClient from "./AbstractScrobbleClient.js"; +import EventEmitter from "events"; +import { PlayObject } from "../../core/Atomic.js"; +import { buildTrackString, capitalize } from "../../core/StringUtils.js"; +import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; +import { UpstreamError } from "../common/errors/UpstreamError.js"; import { FormatPlayObjectOptions, INITIALIZING } from "../common/infrastructure/Atomic.js"; -import { Notifiers } from "../notifier/Notifiers.js"; -import {Logger} from "@foxxmd/logging"; import { ListenBrainzClientConfig } from "../common/infrastructure/config/client/listenbrainz.js"; import { ListenbrainzApiClient, ListenPayload } from "../common/vendor/ListenbrainzApiClient.js"; -import { PlayObject, TrackStringOptions } from "../../core/Atomic.js"; -import { buildTrackString, capitalize } from "../../core/StringUtils.js"; -import EventEmitter from "events"; -import { UpstreamError } from "../common/errors/UpstreamError.js"; -import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; +import { Notifiers } from "../notifier/Notifiers.js"; + +import AbstractScrobbleClient from "./AbstractScrobbleClient.js"; export default class ListenbrainzScrobbler extends AbstractScrobbleClient { diff --git a/src/backend/scrobblers/MalojaScrobbler.ts b/src/backend/scrobblers/MalojaScrobbler.ts index 9d498a96..e1d1c6ea 100644 --- a/src/backend/scrobblers/MalojaScrobbler.ts +++ b/src/backend/scrobblers/MalojaScrobbler.ts @@ -1,12 +1,16 @@ -import AbstractScrobbleClient from "./AbstractScrobbleClient.js"; -import request, {ResponseError, SuperAgentRequest} from 'superagent'; -import dayjs from 'dayjs'; +import { Logger } from "@foxxmd/logging"; import compareVersions from 'compare-versions'; -import { sleep, parseRetryAfterSecsFromObj } from "../utils.js"; +import dayjs from 'dayjs'; +import EventEmitter from "events"; +import normalizeUrl from "normalize-url"; +import request, { SuperAgentRequest } from 'superagent'; +import { PlayObject } from "../../core/Atomic.js"; +import { buildTrackString, capitalize } from "../../core/StringUtils.js"; +import { isSuperAgentResponseError } from "../common/errors/ErrorUtils.js"; +import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; +import { UpstreamError } from "../common/errors/UpstreamError.js"; import { DEFAULT_RETRY_MULTIPLIER, FormatPlayObjectOptions, INITIALIZING } from "../common/infrastructure/Atomic.js"; import { MalojaClientConfig } from "../common/infrastructure/config/client/maloja.js"; -import { Notifiers } from "../notifier/Notifiers.js"; -import {Logger} from "@foxxmd/logging"; import { getMalojaResponseError, isMalojaAPIErrorBody, @@ -19,14 +23,10 @@ import { MalojaV2ScrobbleData, MalojaV3ScrobbleData, } from "../common/vendor/maloja/interfaces.js"; -import { PlayObject, TrackStringOptions } from "../../core/Atomic.js"; -import { buildTrackString, capitalize } from "../../core/StringUtils.js"; -import EventEmitter from "events"; -import normalizeUrl from "normalize-url"; -import { UpstreamError } from "../common/errors/UpstreamError.js"; +import { Notifiers } from "../notifier/Notifiers.js"; +import { parseRetryAfterSecsFromObj, sleep } from "../utils.js"; import { getScrobbleTsSOCDate, getScrobbleTsSOCDateWithContext } from "../utils/TimeUtils.js"; -import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; -import { isSuperAgentResponseError } from "../common/errors/ErrorUtils.js"; +import AbstractScrobbleClient from "./AbstractScrobbleClient.js"; const feat = ["ft.", "ft", "feat.", "feat", "featuring", "Ft.", "Ft", "Feat.", "Feat", "Featuring"]; diff --git a/src/backend/scrobblers/ScrobbleClients.ts b/src/backend/scrobblers/ScrobbleClients.ts index 42280b2c..60c014d1 100644 --- a/src/backend/scrobblers/ScrobbleClients.ts +++ b/src/backend/scrobblers/ScrobbleClients.ts @@ -1,25 +1,22 @@ /* eslint-disable no-case-declarations */ -import dayjs, {Dayjs} from "dayjs"; -import { - readJson, - validateJson, -} from "../utils.js"; -import MalojaScrobbler from "./MalojaScrobbler.js"; -import LastfmScrobbler from "./LastfmScrobbler.js"; +import { childLogger, Logger } from '@foxxmd/logging'; +import dayjs, { Dayjs } from "dayjs"; +import { PlayObject } from "../../core/Atomic.js"; import { clientTypes, ConfigMeta } from "../common/infrastructure/Atomic.js"; import { AIOConfig } from "../common/infrastructure/config/aioConfig.js"; -import * as aioSchema from '../common/schema/aio-client.json'; -import * as clientSchema from '../common/schema/client.json'; import { ClientAIOConfig, ClientConfig } from "../common/infrastructure/config/client/clients.js"; -import { MalojaClientConfig } from "../common/infrastructure/config/client/maloja.js"; import { LastfmClientConfig } from "../common/infrastructure/config/client/lastfm.js"; +import { ListenBrainzClientConfig } from "../common/infrastructure/config/client/listenbrainz.js"; +import { MalojaClientConfig } from "../common/infrastructure/config/client/maloja.js"; +import * as aioSchema from '../common/schema/aio-client.json'; +import * as clientSchema from '../common/schema/client.json'; +import { WildcardEmitter } from "../common/WildcardEmitter.js"; import { Notifiers } from "../notifier/Notifiers.js"; +import { readJson, validateJson, } from "../utils.js"; import AbstractScrobbleClient from "./AbstractScrobbleClient.js"; -import {childLogger, Logger} from '@foxxmd/logging'; +import LastfmScrobbler from "./LastfmScrobbler.js"; import ListenbrainzScrobbler from "./ListenbrainzScrobbler.js"; -import { ListenBrainzClientConfig } from "../common/infrastructure/config/client/listenbrainz.js"; -import { PlayObject } from "../../core/Atomic.js"; -import { WildcardEmitter } from "../common/WildcardEmitter.js"; +import MalojaScrobbler from "./MalojaScrobbler.js"; type groupedNamedConfigs = {[key: string]: ParsedConfig[]}; diff --git a/src/backend/server/api.ts b/src/backend/server/api.ts index 97fda5c2..d7ca2e38 100644 --- a/src/backend/server/api.ts +++ b/src/backend/server/api.ts @@ -1,32 +1,33 @@ -import {ExpressWithAsync} from "@awaitjs/express"; -import { getRoot } from "../ioc.js"; -import { makeClientCheckMiddle, makeSourceCheckMiddle } from "./middleware.js"; -import AbstractSource from "../sources/AbstractSource.js"; +import { ExpressWithAsync } from "@awaitjs/express"; +import { LogDataPretty, Logger, LogLevel } from "@foxxmd/logging"; +import bsseDef from 'better-sse'; +import bodyParser from "body-parser"; +import { FixedSizeList } from 'fixed-size-list'; +import { PassThrough } from "node:stream"; +import { Transform } from "stream"; import { ClientStatusData, - DeadLetterScrobble, LeveledLogData, + DeadLetterScrobble, + LeveledLogData, LogOutputConfig, - PlayObject, SOURCE_SOT, + PlayObject, + SOURCE_SOT, SourceStatusData, } from "../../core/Atomic.js"; -import {LogDataPretty, Logger, LogLevel} from "@foxxmd/logging"; -import {Transform} from "stream"; -import * as bsse from 'better-sse'; -import bsseDef from 'better-sse'; -import { setupTautulliRoutes } from "./tautulliRoutes.js"; -import { setupPlexRoutes } from "./plexRoutes.js"; -import { setupJellyfinRoutes } from "./jellyfinRoutes.js"; -import { setupDeezerRoutes } from "./deezerRoutes.js"; -import { setupAuthRoutes } from "./auth.js"; -import {ExpressHandler} from "../common/infrastructure/Atomic.js"; -import MemorySource from "../sources/MemorySource.js"; import { capitalize } from "../../core/StringUtils.js"; +import { ExpressHandler } from "../common/infrastructure/Atomic.js"; +import { getRoot } from "../ioc.js"; import AbstractScrobbleClient from "../scrobblers/AbstractScrobbleClient.js"; +import AbstractSource from "../sources/AbstractSource.js"; +import MemorySource from "../sources/MemorySource.js"; import { sortByNewestPlayDate } from "../utils.js"; -import bodyParser from "body-parser"; +import { setupAuthRoutes } from "./auth.js"; +import { setupDeezerRoutes } from "./deezerRoutes.js"; +import { setupJellyfinRoutes } from "./jellyfinRoutes.js"; +import { makeClientCheckMiddle, makeSourceCheckMiddle } from "./middleware.js"; +import { setupPlexRoutes } from "./plexRoutes.js"; +import { setupTautulliRoutes } from "./tautulliRoutes.js"; import { setupWebscrobblerRoutes } from "./webscrobblerRoutes.js"; -import {FixedSizeList} from 'fixed-size-list'; -import {PassThrough} from "node:stream"; const maxBufferSize = 300; const output: Record> = {}; diff --git a/src/backend/server/auth.ts b/src/backend/server/auth.ts index ecca9f87..10898a1d 100644 --- a/src/backend/server/auth.ts +++ b/src/backend/server/auth.ts @@ -1,11 +1,11 @@ -import {ExpressWithAsync} from "@awaitjs/express"; -import {Logger} from "@foxxmd/logging"; -import ScrobbleSources from "../sources/ScrobbleSources.js"; +import { ExpressWithAsync } from "@awaitjs/express"; +import { Logger } from "@foxxmd/logging"; import passport from "passport"; import { ExpressHandler } from "../common/infrastructure/Atomic.js"; -import ScrobbleClients from "../scrobblers/ScrobbleClients.js"; import LastfmScrobbler from "../scrobblers/LastfmScrobbler.js"; +import ScrobbleClients from "../scrobblers/ScrobbleClients.js"; import LastfmSource from "../sources/LastfmSource.js"; +import ScrobbleSources from "../sources/ScrobbleSources.js"; import SpotifySource from "../sources/SpotifySource.js"; export const setupAuthRoutes = (app: ExpressWithAsync, logger: Logger, sourceMiddle: ExpressHandler, clientMiddle: ExpressHandler, scrobbleSources: ScrobbleSources, scrobbleClients: ScrobbleClients) => { diff --git a/src/backend/server/deezerRoutes.ts b/src/backend/server/deezerRoutes.ts index 5c960363..bbe3b633 100644 --- a/src/backend/server/deezerRoutes.ts +++ b/src/backend/server/deezerRoutes.ts @@ -1,12 +1,9 @@ -import { ExpressHandler } from "../common/infrastructure/Atomic.js"; -import { mergeArr, parseBool, sleep } from "../utils.js"; -import {ExpressWithAsync} from "@awaitjs/express"; -import {Logger} from "@foxxmd/logging"; -import ScrobbleSources from "../sources/ScrobbleSources.js"; -import PlexSource, { plexRequestMiddle } from "../sources/PlexSource.js"; -import { PlexNotifier } from "../sources/ingressNotifiers/PlexNotifier.js"; -import DeezerSource from "../sources/DeezerSource.js"; +import { ExpressWithAsync } from "@awaitjs/express"; +import { Logger } from "@foxxmd/logging"; import passport from "passport"; +import DeezerSource from "../sources/DeezerSource.js"; +import ScrobbleSources from "../sources/ScrobbleSources.js"; +import { sleep } from "../utils.js"; export const setupDeezerRoutes = (app: ExpressWithAsync, logger: Logger, scrobbleSources: ScrobbleSources) => { diff --git a/src/backend/server/index.ts b/src/backend/server/index.ts index 4c60232d..56dcdb93 100644 --- a/src/backend/server/index.ts +++ b/src/backend/server/index.ts @@ -1,16 +1,15 @@ -import {addAsync, Router} from '@awaitjs/express'; -import express from 'express'; -import ViteExpress from "vite-express"; +import { addAsync, Router } from '@awaitjs/express'; +import { childLogger, LogDataPretty, Logger } from "@foxxmd/logging"; import bodyParser from 'body-parser'; -import passport from 'passport'; +import { stripIndents } from "common-tags"; +import express from 'express'; import session from 'express-session'; +import { PassThrough } from "node:stream"; +import passport from 'passport'; +import ViteExpress from "vite-express"; import { getRoot } from "../ioc.js"; +import { getAddress, parseBool } from "../utils.js"; import { setupApi } from "./api.js"; -import { getAddress, mergeArr, parseBool } from "../utils.js"; -import {stripIndents} from "common-tags"; -import {childLogger, LogData, LogDataPretty} from "@foxxmd/logging"; -import {PassThrough} from "node:stream"; -import {Logger} from '@foxxmd/logging'; const app = addAsync(express()); const router = Router(); diff --git a/src/backend/server/jellyfinRoutes.ts b/src/backend/server/jellyfinRoutes.ts index b356f950..08ce2f92 100644 --- a/src/backend/server/jellyfinRoutes.ts +++ b/src/backend/server/jellyfinRoutes.ts @@ -1,10 +1,10 @@ -import { parseBool, remoteHostIdentifiers } from "../utils.js"; -import {ExpressWithAsync} from "@awaitjs/express"; -import {Logger} from "@foxxmd/logging"; -import ScrobbleSources from "../sources/ScrobbleSources.js"; +import { ExpressWithAsync } from "@awaitjs/express"; +import { Logger } from "@foxxmd/logging"; import bodyParser from "body-parser"; import { JellyfinNotifier } from "../sources/ingressNotifiers/JellyfinNotifier.js"; import JellyfinSource from "../sources/JellyfinSource.js"; +import ScrobbleSources from "../sources/ScrobbleSources.js"; +import { parseBool, remoteHostIdentifiers } from "../utils.js"; export const setupJellyfinRoutes = (app: ExpressWithAsync, logger: Logger, scrobbleSources: ScrobbleSources) => { diff --git a/src/backend/server/middleware.ts b/src/backend/server/middleware.ts index 8e0b58df..06dc5a99 100644 --- a/src/backend/server/middleware.ts +++ b/src/backend/server/middleware.ts @@ -1,5 +1,5 @@ +import { Logger } from "@foxxmd/logging"; import { ExpressHandler } from "../common/infrastructure/Atomic.js"; -import {Logger} from "@foxxmd/logging"; export const makeSourceCheckMiddle = (sources: any) => (required: boolean ): ExpressHandler => (req: any, res: any, next: any) => { const { diff --git a/src/backend/server/plexRoutes.ts b/src/backend/server/plexRoutes.ts index c1341c84..de398a79 100644 --- a/src/backend/server/plexRoutes.ts +++ b/src/backend/server/plexRoutes.ts @@ -1,10 +1,9 @@ +import { ExpressWithAsync } from "@awaitjs/express"; +import { childLogger, Logger } from "@foxxmd/logging"; import { ExpressHandler } from "../common/infrastructure/Atomic.js"; -import { mergeArr, parseBool } from "../utils.js"; -import {ExpressWithAsync} from "@awaitjs/express"; -import {childLogger, Logger} from "@foxxmd/logging"; -import ScrobbleSources from "../sources/ScrobbleSources.js"; -import PlexSource, { plexRequestMiddle } from "../sources/PlexSource.js"; import { PlexNotifier } from "../sources/ingressNotifiers/PlexNotifier.js"; +import PlexSource, { plexRequestMiddle } from "../sources/PlexSource.js"; +import ScrobbleSources from "../sources/ScrobbleSources.js"; export const setupPlexRoutes = (app: ExpressWithAsync, logger: Logger, scrobbleSources: ScrobbleSources) => { diff --git a/src/backend/server/tautulliRoutes.ts b/src/backend/server/tautulliRoutes.ts index cac0ba10..ae4f523d 100644 --- a/src/backend/server/tautulliRoutes.ts +++ b/src/backend/server/tautulliRoutes.ts @@ -1,10 +1,10 @@ -import { TautulliNotifier } from "../sources/ingressNotifiers/TautulliNotifier.js"; +import { ExpressWithAsync } from "@awaitjs/express"; +import { Logger } from "@foxxmd/logging"; import { ExpressHandler } from "../common/infrastructure/Atomic.js"; +import { TautulliNotifier } from "../sources/ingressNotifiers/TautulliNotifier.js"; +import ScrobbleSources from "../sources/ScrobbleSources.js"; import TautulliSource from "../sources/TautulliSource.js"; import { parseBool } from "../utils.js"; -import {ExpressWithAsync} from "@awaitjs/express"; -import {Logger} from "@foxxmd/logging"; -import ScrobbleSources from "../sources/ScrobbleSources.js"; export const setupTautulliRoutes = (app: ExpressWithAsync, logger: Logger, scrobbleSources: ScrobbleSources) => { diff --git a/src/backend/server/webscrobblerRoutes.ts b/src/backend/server/webscrobblerRoutes.ts index 18b4956c..cbc343ee 100644 --- a/src/backend/server/webscrobblerRoutes.ts +++ b/src/backend/server/webscrobblerRoutes.ts @@ -1,13 +1,11 @@ -import { mergeArr, parseBool, remoteHostIdentifiers } from "../utils.js"; -import {ExpressWithAsync} from "@awaitjs/express"; -import {childLogger, Logger} from "@foxxmd/logging"; -import ScrobbleSources from "../sources/ScrobbleSources.js"; +import { ExpressWithAsync } from "@awaitjs/express"; +import { childLogger, Logger } from "@foxxmd/logging"; import bodyParser from "body-parser"; -import { WebScrobblerPayload } from "../common/vendor/webscrobbler/interfaces.js"; +import path from "path"; import { WebhookNotifier } from "../sources/ingressNotifiers/WebhookNotifier.js"; -import { nonEmptyBody } from "./middleware.js"; +import ScrobbleSources from "../sources/ScrobbleSources.js"; import { WebScrobblerSource } from "../sources/WebScrobblerSource.js"; -import path from "path"; +import { nonEmptyBody } from "./middleware.js"; export const setupWebscrobblerRoutes = (app: ExpressWithAsync, parentLogger: Logger, scrobbleSources: ScrobbleSources) => { diff --git a/src/backend/sources/AbstractSource.ts b/src/backend/sources/AbstractSource.ts index 915f16e6..ed03b8f2 100644 --- a/src/backend/sources/AbstractSource.ts +++ b/src/backend/sources/AbstractSource.ts @@ -1,16 +1,10 @@ -import dayjs, {Dayjs} from "dayjs"; -import { - genGroupId, - genGroupIdStrFromPlay, - mergeArr, - playObjDataMatch, - pollingBackoff, - sleep, - sortByNewestPlayDate, - sortByOldestPlayDate, - findCauseByFunc, - formatNumber, -} from "../utils.js"; +import { childLogger, Logger } from '@foxxmd/logging'; +import dayjs, { Dayjs } from "dayjs"; +import { EventEmitter } from "events"; +import { FixedSizeList } from "fixed-size-list"; +import { PlayObject, TA_CLOSE } from "../../core/Atomic.js"; +import { buildTrackString, capitalize } from "../../core/StringUtils.js"; +import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; import { Authenticatable, DEFAULT_POLLING_INTERVAL, @@ -18,9 +12,7 @@ import { DEFAULT_RETRY_MULTIPLIER, DeviceId, GroupedFixedPlays, - GroupedPlays, InternalConfig, - NO_DEVICE, NO_USER, PlayPlatformId, PlayUserId, @@ -28,14 +20,18 @@ import { SINGLE_USER_PLATFORM_ID, SourceType, } from "../common/infrastructure/Atomic.js"; -import {childLogger, Logger} from '@foxxmd/logging'; import { SourceConfig } from "../common/infrastructure/config/source/sources.js"; -import {EventEmitter} from "events"; -import {FixedSizeList} from "fixed-size-list"; import TupleMap from "../common/TupleMap.js"; -import { PlayObject, TA_CLOSE } from "../../core/Atomic.js"; -import { buildTrackString, capitalize } from "../../core/StringUtils.js"; -import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; +import { + findCauseByFunc, + formatNumber, + genGroupId, + playObjDataMatch, + pollingBackoff, + sleep, + sortByNewestPlayDate, + sortByOldestPlayDate, +} from "../utils.js"; import { comparePlayTemporally, temporalAccuracyIsAtLeast } from "../utils/TimeUtils.js"; export interface RecentlyPlayedOptions { diff --git a/src/backend/sources/ChromecastSource.ts b/src/backend/sources/ChromecastSource.ts index c0f08dd2..1745ba3b 100644 --- a/src/backend/sources/ChromecastSource.ts +++ b/src/backend/sources/ChromecastSource.ts @@ -1,5 +1,14 @@ -import MemorySource from "./MemorySource.js"; -import { ChromecastSourceConfig } from "../common/infrastructure/config/source/chromecast.js"; +import { createPlatform, Media, MediaController, PersistentClient } from "@foxxmd/chromecast-client"; +import { ContextualValidationError } from "@foxxmd/chromecast-client/dist/cjs/src/utils.js"; +import { childLogger, Logger } from "@foxxmd/logging"; +import { Client as CastClient } from 'castv2'; +import dayjs from "dayjs"; +import { EventEmitter } from "events"; +import e from "express"; +import { findCauseByReference } from "pony-cause"; +import { PlayObject } from "../../core/Atomic.js"; +import { buildTrackString } from "../../core/StringUtils.js"; +import { NETWORK_ERROR_FAILURE_CODES } from "../common/errors/NodeErrors.js"; import { FormatPlayObjectOptions, InternalConfig, @@ -8,30 +17,24 @@ import { PlayerStateData, SourceData, } from "../common/infrastructure/Atomic.js"; -import {EventEmitter} from "events"; -import {MediaController, PersistentClient, Media, createPlatform} from "@foxxmd/chromecast-client"; -import {Client as CastClient} from 'castv2'; -import {findCauseByReference} from "pony-cause"; -import { PlayObject } from "../../core/Atomic.js"; -import dayjs from "dayjs"; -import { RecentlyPlayedOptions } from "./AbstractSource.js"; -import { difference, genGroupIdStr, isIPv4, mergeArr, parseBool, sleep } from "../utils.js"; -import { PlatformApplication, PlatformApplicationWithContext, PlatformType } from "../common/vendor/chromecast/interfaces.js"; +import { ChromecastSourceConfig } from "../common/infrastructure/config/source/chromecast.js"; +import { MaybeLogger } from "../common/logging.js"; import { chromePlayerStateToReported, genDeviceId, + genPlayHash, getCurrentPlatformApplications, getMediaStatus, - genPlayHash, } from "../common/vendor/chromecast/ChromecastClientUtils.js"; -import {Logger} from "@foxxmd/logging"; -import {ContextualValidationError} from "@foxxmd/chromecast-client/dist/cjs/src/utils.js"; -import { buildTrackString } from "../../core/StringUtils.js"; +import { + PlatformApplication, + PlatformApplicationWithContext, + PlatformType +} from "../common/vendor/chromecast/interfaces.js"; +import { difference, genGroupIdStr, parseBool } from "../utils.js"; import { discoveryAvahi, discoveryNative } from "../utils/MDNSUtils.js"; -import {MaybeLogger} from "../common/logging.js"; -import e, {application} from "express"; -import {NETWORK_ERROR_FAILURE_CODES} from "../common/errors/NodeErrors.js"; -import {childLogger} from "@foxxmd/logging"; +import { RecentlyPlayedOptions } from "./AbstractSource.js"; +import MemorySource from "./MemorySource.js"; interface ChromecastDeviceInfo { mdns: MdnsDeviceInfo diff --git a/src/backend/sources/DeezerSource.ts b/src/backend/sources/DeezerSource.ts index 22c3d8db..7c95cd63 100644 --- a/src/backend/sources/DeezerSource.ts +++ b/src/backend/sources/DeezerSource.ts @@ -1,19 +1,13 @@ -import request from 'superagent'; -import passport from "passport"; -import { - parseRetryAfterSecsFromObj, - readJson, - sleep, - sortByOldestPlayDate, - writeFile, -} from "../utils.js"; -import {Strategy as DeezerStrategy} from 'passport-deezer'; -import AbstractSource, { RecentlyPlayedOptions } from "./AbstractSource.js"; import dayjs from "dayjs"; -import { DeezerSourceConfig } from "../common/infrastructure/config/source/deezer.js"; -import { DEFAULT_RETRY_MULTIPLIER, FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; import EventEmitter from "events"; +import passport from "passport"; +import { Strategy as DeezerStrategy } from 'passport-deezer'; +import request from 'superagent'; import { PlayObject } from "../../core/Atomic.js"; +import { DEFAULT_RETRY_MULTIPLIER, FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; +import { DeezerSourceConfig } from "../common/infrastructure/config/source/deezer.js"; +import { parseRetryAfterSecsFromObj, readJson, sleep, sortByOldestPlayDate, writeFile, } from "../utils.js"; +import AbstractSource, { RecentlyPlayedOptions } from "./AbstractSource.js"; export default class DeezerSource extends AbstractSource { workingCredsPath; diff --git a/src/backend/sources/JRiverSource.ts b/src/backend/sources/JRiverSource.ts index a0d720dd..526eff2f 100644 --- a/src/backend/sources/JRiverSource.ts +++ b/src/backend/sources/JRiverSource.ts @@ -1,13 +1,13 @@ -import MemorySource from "./MemorySource.js"; -import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; import dayjs from "dayjs"; -import {URL} from "url"; +import { EventEmitter } from "events"; import normalizeUrl from 'normalize-url'; -import {EventEmitter} from "events"; -import { RecentlyPlayedOptions } from "./AbstractSource.js"; +import { URL } from "url"; +import { PlayObject } from "../../core/Atomic.js"; +import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; import { JRiverSourceConfig } from "../common/infrastructure/config/source/jriver.js"; import { Info, JRiverApiClient, PLAYER_STATE } from "../common/vendor/JRiverApiClient.js"; -import { PlayObject } from "../../core/Atomic.js"; +import { RecentlyPlayedOptions } from "./AbstractSource.js"; +import MemorySource from "./MemorySource.js"; export class JRiverSource extends MemorySource { declare config: JRiverSourceConfig; diff --git a/src/backend/sources/JellyfinSource.ts b/src/backend/sources/JellyfinSource.ts index 840dead8..a7cb7e3d 100644 --- a/src/backend/sources/JellyfinSource.ts +++ b/src/backend/sources/JellyfinSource.ts @@ -1,26 +1,25 @@ -import MemorySource from "./MemorySource.js"; -import dayjs, {Dayjs} from "dayjs"; +import { Logger } from "@foxxmd/logging"; +import dayjs from "dayjs"; +import EventEmitter from "events"; +import { PlayObject, TA_CLOSE } from "../../core/Atomic.js"; +import { buildTrackString, splitByFirstFound, truncateStringToLength } from "../../core/StringUtils.js"; +import { FormatPlayObjectOptions, InternalConfig, PlayPlatformId } from "../common/infrastructure/Atomic.js"; +import { JellySourceConfig } from "../common/infrastructure/config/source/jellyfin.js"; import { combinePartsToString, + doubleReturnNewline, parseBool, parseDurationFromTimestamp, playObjDataMatch, - doubleReturnNewline, } from "../utils.js"; -import { JellySourceConfig } from "../common/infrastructure/config/source/jellyfin.js"; -import { FormatPlayObjectOptions, InternalConfig, PlayPlatformId } from "../common/infrastructure/Atomic.js"; -import EventEmitter from "events"; -import { PlayerStateOptions } from "./PlayerState/AbstractPlayerState.js"; -import {Logger} from "@foxxmd/logging"; -import { JellyfinPlayerState } from "./PlayerState/JellyfinPlayerState.js"; -import { PlayObject, TA_CLOSE } from "../../core/Atomic.js"; -import { buildTrackString, splitByFirstFound, truncateStringToLength } from "../../core/StringUtils.js"; -import {source} from "common-tags"; import { comparePlayTemporally, temporalAccuracyIsAtLeast, temporalPlayComparisonSummary, } from "../utils/TimeUtils.js"; +import MemorySource from "./MemorySource.js"; +import { PlayerStateOptions } from "./PlayerState/AbstractPlayerState.js"; +import { JellyfinPlayerState } from "./PlayerState/JellyfinPlayerState.js"; const shortDeviceId = truncateStringToLength(10, ''); diff --git a/src/backend/sources/KodiSource.ts b/src/backend/sources/KodiSource.ts index b6329f95..ca58cb19 100644 --- a/src/backend/sources/KodiSource.ts +++ b/src/backend/sources/KodiSource.ts @@ -1,10 +1,10 @@ -import MemorySource from "./MemorySource.js"; +import { EventEmitter } from "events"; +import { PlayObject } from "../../core/Atomic.js"; import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; -import {EventEmitter} from "events"; -import { RecentlyPlayedOptions } from "./AbstractSource.js"; import { KodiSourceConfig } from "../common/infrastructure/config/source/kodi.js"; import { KodiApiClient } from "../common/vendor/KodiApiClient.js"; -import { PlayObject } from "../../core/Atomic.js"; +import { RecentlyPlayedOptions } from "./AbstractSource.js"; +import MemorySource from "./MemorySource.js"; export class KodiSource extends MemorySource { declare config: KodiSourceConfig; diff --git a/src/backend/sources/LastfmSource.ts b/src/backend/sources/LastfmSource.ts index 9dc631a1..0c16b903 100644 --- a/src/backend/sources/LastfmSource.ts +++ b/src/backend/sources/LastfmSource.ts @@ -1,15 +1,15 @@ -import { RecentlyPlayedOptions } from "./AbstractSource.js"; +import dayjs from "dayjs"; +import EventEmitter from "events"; +import { TrackObject, UserGetRecentTracksResponse } from "lastfm-node-client"; +import request from "superagent"; +import { PlayObject, SOURCE_SOT } from "../../core/Atomic.js"; +import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; +import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; +import { LastfmSourceConfig } from "../common/infrastructure/config/source/lastfm.js"; import LastfmApiClient from "../common/vendor/LastfmApiClient.js"; import { sortByOldestPlayDate } from "../utils.js"; -import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; -import {TrackObject, UserGetRecentTracksResponse} from "lastfm-node-client"; -import EventEmitter from "events"; -import {PlayObject, SOURCE_SOT} from "../../core/Atomic.js"; +import { RecentlyPlayedOptions } from "./AbstractSource.js"; import MemorySource from "./MemorySource.js"; -import { LastfmSourceConfig } from "../common/infrastructure/config/source/lastfm.js"; -import dayjs from "dayjs"; -import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; -import request from "superagent"; export default class LastfmSource extends MemorySource { diff --git a/src/backend/sources/ListenbrainzSource.ts b/src/backend/sources/ListenbrainzSource.ts index 0ef9b53e..3995437c 100644 --- a/src/backend/sources/ListenbrainzSource.ts +++ b/src/backend/sources/ListenbrainzSource.ts @@ -1,12 +1,12 @@ -import AbstractSource, { RecentlyPlayedOptions } from "./AbstractSource.js"; -import { FormatPlayObjectOptions, INITIALIZING, InternalConfig } from "../common/infrastructure/Atomic.js"; import EventEmitter from "events"; +import request from "superagent"; +import { PlayObject, SOURCE_SOT } from "../../core/Atomic.js"; +import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; +import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; import { ListenBrainzSourceConfig } from "../common/infrastructure/config/source/listenbrainz.js"; import { ListenbrainzApiClient } from "../common/vendor/ListenbrainzApiClient.js"; +import { RecentlyPlayedOptions } from "./AbstractSource.js"; import MemorySource from "./MemorySource.js"; -import request from "superagent"; -import {isNodeNetworkException} from "../common/errors/NodeErrors.js"; -import {PlayObject, SOURCE_SOT} from "../../core/Atomic.js"; export default class ListenbrainzSource extends MemorySource { diff --git a/src/backend/sources/MPRISSource.ts b/src/backend/sources/MPRISSource.ts index 0ace261c..37647900 100644 --- a/src/backend/sources/MPRISSource.ts +++ b/src/backend/sources/MPRISSource.ts @@ -1,4 +1,9 @@ +import { Interfaces as Notifications } from '@dbus-types/notifications' import dayjs from "dayjs"; +import { DBusInterface, sessionBus } from 'dbus-ts'; +import EventEmitter from "events"; +import { PlayObject } from "../../core/Atomic.js"; +import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; import { MPRIS_IFACE, MPRIS_PATH, @@ -8,14 +13,9 @@ import { PlaybackStatus, PlayerInfo, } from "../common/infrastructure/config/source/mpris.js"; -import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; -import MemorySource from "./MemorySource.js"; -import { RecentlyPlayedOptions } from "./AbstractSource.js"; import { removeDuplicates } from "../utils.js"; -import EventEmitter from "events"; -import { PlayObject } from "../../core/Atomic.js"; -import {DBusInterface, sessionBus} from 'dbus-ts'; -import { Interfaces as Notifications } from '@dbus-types/notifications' +import { RecentlyPlayedOptions } from "./AbstractSource.js"; +import MemorySource from "./MemorySource.js"; export class MPRISSource extends MemorySource { diff --git a/src/backend/sources/MemorySource.ts b/src/backend/sources/MemorySource.ts index 9c75dfbd..196db4c6 100644 --- a/src/backend/sources/MemorySource.ts +++ b/src/backend/sources/MemorySource.ts @@ -1,41 +1,33 @@ -import AbstractSource from "./AbstractSource.js"; -import { - playObjDataMatch, - sortByOldestPlayDate, - toProgressAwarePlayObject, - getProgress, - thresholdResultSummary, - genGroupId, - genGroupIdStr, - getPlatformIdFromData, - formatNumber, -} from "../utils.js"; +import { Logger } from "@foxxmd/logging"; import dayjs from "dayjs"; +import { EventEmitter } from "events"; +import objectHash from 'object-hash'; +import { SimpleIntervalJob, Task, ToadScheduler } from "toad-scheduler"; +import { PlayObject, SOURCE_SOT, SOURCE_SOT_TYPES, SourcePlayerObj } from "../../core/Atomic.js"; +import { buildTrackString } from "../../core/StringUtils.js"; import { asPlayerStateData, CALCULATED_PLAYER_STATUSES, - DeviceId, - GroupedPlays, InternalConfig, PlayerStateData, PlayPlatformId, - PlayUserId, ProgressAwarePlayObject, - ScrobbleThresholdResult, SourceType, } from "../common/infrastructure/Atomic.js"; -import TupleMap from "../common/TupleMap.js"; -import {AbstractPlayerState, createPlayerOptions, PlayerStateOptions} from "./PlayerState/AbstractPlayerState.js"; -import { GenericPlayerState } from "./PlayerState/GenericPlayerState.js"; -import {Logger} from "@foxxmd/logging"; -import {PlayObject, SOURCE_SOT, SOURCE_SOT_TYPES, SourcePlayerObj} from "../../core/Atomic.js"; -import { buildTrackString } from "../../core/StringUtils.js"; -import {SimpleIntervalJob, Task, ToadScheduler} from "toad-scheduler"; +import { PollingOptions } from "../common/infrastructure/config/common.js"; import { SourceConfig } from "../common/infrastructure/config/source/sources.js"; -import {EventEmitter} from "events"; -import objectHash from 'object-hash'; +import { + formatNumber, + genGroupId, + genGroupIdStr, + getPlatformIdFromData, + playObjDataMatch, + thresholdResultSummary, +} from "../utils.js"; import { timePassesScrobbleThreshold } from "../utils/TimeUtils.js"; -import {PollingOptions} from "../common/infrastructure/config/common.js"; +import AbstractSource from "./AbstractSource.js"; +import { AbstractPlayerState, createPlayerOptions, PlayerStateOptions } from "./PlayerState/AbstractPlayerState.js"; +import { GenericPlayerState } from "./PlayerState/GenericPlayerState.js"; export default class MemorySource extends AbstractSource { diff --git a/src/backend/sources/MopidySource.ts b/src/backend/sources/MopidySource.ts index 0215e8ee..369671f3 100644 --- a/src/backend/sources/MopidySource.ts +++ b/src/backend/sources/MopidySource.ts @@ -1,21 +1,21 @@ -import MemorySource from "./MemorySource.js"; -import { MopidySourceConfig } from "../common/infrastructure/config/source/mopidy.js"; +import { loggerTest } from "@foxxmd/logging"; +import dayjs from "dayjs"; +import { EventEmitter } from "events"; +import Mopidy, { models } from "mopidy"; +import normalizeUrl from 'normalize-url'; +import pEvent from 'p-event'; +import { URL } from "url"; +import { PlayObject } from "../../core/Atomic.js"; +import { buildTrackString } from "../../core/StringUtils.js"; import { FormatPlayObjectOptions, InternalConfig, PlayerStateData, SINGLE_USER_PLATFORM_ID, } from "../common/infrastructure/Atomic.js"; -import dayjs from "dayjs"; -import Mopidy, {models} from "mopidy"; -import {URL} from "url"; -import normalizeUrl from 'normalize-url'; -import {EventEmitter} from "events"; -import pEvent from 'p-event'; +import { MopidySourceConfig } from "../common/infrastructure/config/source/mopidy.js"; import { RecentlyPlayedOptions } from "./AbstractSource.js"; -import { PlayObject } from "../../core/Atomic.js"; -import { buildTrackString } from "../../core/StringUtils.js"; -import {loggerTest} from "@foxxmd/logging"; +import MemorySource from "./MemorySource.js"; export class MopidySource extends MemorySource { declare config: MopidySourceConfig; diff --git a/src/backend/sources/PlayerState/AbstractPlayerState.ts b/src/backend/sources/PlayerState/AbstractPlayerState.ts index 5db90442..787654d8 100644 --- a/src/backend/sources/PlayerState/AbstractPlayerState.ts +++ b/src/backend/sources/PlayerState/AbstractPlayerState.ts @@ -1,3 +1,7 @@ +import { childLogger, Logger } from "@foxxmd/logging"; +import dayjs, { Dayjs } from "dayjs"; +import { PlayObject, Second, SOURCE_SOT, SOURCE_SOT_TYPES, SourcePlayerObj } from "../../../core/Atomic.js"; +import { buildTrackString } from "../../../core/StringUtils.js"; import { CALCULATED_PLAYER_STATUSES, CalculatedPlayerStatus, @@ -5,15 +9,10 @@ import { REPORTED_PLAYER_STATUSES, ReportedPlayerStatus, } from "../../common/infrastructure/Atomic.js"; -import dayjs, {Dayjs} from "dayjs"; +import { PollingOptions } from "../../common/infrastructure/config/common.js"; import { formatNumber, genGroupIdStr, playObjDataMatch, progressBar } from "../../utils.js"; -import {childLogger, Logger} from "@foxxmd/logging"; import { ListenProgress } from "./ListenProgress.js"; -import {PlayObject, Second, SOURCE_SOT, SOURCE_SOT_TYPES, SourcePlayerObj} from "../../../core/Atomic.js"; -import { buildTrackString } from "../../../core/StringUtils.js"; import { ListenRange } from "./ListenRange.js"; -import {id} from "common-tags"; -import {PollingOptions} from "../../common/infrastructure/config/common.js"; export interface PlayerStateIntervals { staleInterval?: number diff --git a/src/backend/sources/PlayerState/GenericPlayerState.ts b/src/backend/sources/PlayerState/GenericPlayerState.ts index 3977de6a..bafb6b5f 100644 --- a/src/backend/sources/PlayerState/GenericPlayerState.ts +++ b/src/backend/sources/PlayerState/GenericPlayerState.ts @@ -1,6 +1,6 @@ -import { AbstractPlayerState, PlayerStateOptions } from "./AbstractPlayerState.js"; -import {Logger} from "@foxxmd/logging"; +import { Logger } from "@foxxmd/logging"; import { PlayPlatformId } from "../../common/infrastructure/Atomic.js"; +import { AbstractPlayerState, PlayerStateOptions } from "./AbstractPlayerState.js"; export class GenericPlayerState extends AbstractPlayerState { constructor(logger: Logger, platformId: PlayPlatformId, opts?: PlayerStateOptions) { diff --git a/src/backend/sources/PlayerState/JellyfinPlayerState.ts b/src/backend/sources/PlayerState/JellyfinPlayerState.ts index b7019cde..764608b2 100644 --- a/src/backend/sources/PlayerState/JellyfinPlayerState.ts +++ b/src/backend/sources/PlayerState/JellyfinPlayerState.ts @@ -1,8 +1,8 @@ -import { GenericPlayerState } from "./GenericPlayerState.js"; -import {Logger} from "@foxxmd/logging"; +import { Logger } from "@foxxmd/logging"; +import { PlayObject } from "../../../core/Atomic.js"; import { PlayPlatformId, ReportedPlayerStatus } from "../../common/infrastructure/Atomic.js"; import { PlayerStateOptions } from "./AbstractPlayerState.js"; -import { PlayObject } from "../../../core/Atomic.js"; +import { GenericPlayerState } from "./GenericPlayerState.js"; export class JellyfinPlayerState extends GenericPlayerState { constructor(logger: Logger, platformId: PlayPlatformId, opts?: PlayerStateOptions) { diff --git a/src/backend/sources/PlayerState/ListenProgress.ts b/src/backend/sources/PlayerState/ListenProgress.ts index a36667ba..2d66e58e 100644 --- a/src/backend/sources/PlayerState/ListenProgress.ts +++ b/src/backend/sources/PlayerState/ListenProgress.ts @@ -1,4 +1,4 @@ -import dayjs, {Dayjs} from "dayjs"; +import dayjs, { Dayjs } from "dayjs"; import { PlayProgress, Second } from "../../../core/Atomic.js"; diff --git a/src/backend/sources/PlayerState/ListenRange.ts b/src/backend/sources/PlayerState/ListenRange.ts index 6b10d40f..6a2dc050 100644 --- a/src/backend/sources/PlayerState/ListenRange.ts +++ b/src/backend/sources/PlayerState/ListenRange.ts @@ -1,6 +1,6 @@ -import { ListenProgress } from "./ListenProgress.js"; -import dayjs, {Dayjs} from "dayjs"; +import dayjs, { Dayjs } from "dayjs"; import { ListenRangeData, Second } from "../../../core/Atomic.js"; +import { ListenProgress } from "./ListenProgress.js"; export class ListenRange implements ListenRangeData { diff --git a/src/backend/sources/PlexSource.ts b/src/backend/sources/PlexSource.ts index a5697305..703caddc 100644 --- a/src/backend/sources/PlexSource.ts +++ b/src/backend/sources/PlexSource.ts @@ -1,14 +1,14 @@ -import dayjs from "dayjs"; -import { combinePartsToString } from "../utils.js"; -import AbstractSource from "./AbstractSource.js"; -import formidable from 'formidable'; +import { childLogger, Logger } from "@foxxmd/logging"; import concatStream from 'concat-stream'; -import { PlexSourceConfig } from "../common/infrastructure/config/source/plex.js"; -import { FormatPlayObjectOptions, InternalConfig, SourceType } from "../common/infrastructure/Atomic.js"; +import dayjs from "dayjs"; import EventEmitter from "events"; +import formidable from 'formidable'; import { PlayObject } from "../../core/Atomic.js"; import { truncateStringToLength } from "../../core/StringUtils.js"; -import {childLogger, Logger} from "@foxxmd/logging"; +import { FormatPlayObjectOptions, InternalConfig, SourceType } from "../common/infrastructure/Atomic.js"; +import { PlexSourceConfig } from "../common/infrastructure/config/source/plex.js"; +import { combinePartsToString } from "../utils.js"; +import AbstractSource from "./AbstractSource.js"; const shortDeviceId = truncateStringToLength(10, ''); diff --git a/src/backend/sources/ScrobbleSources.ts b/src/backend/sources/ScrobbleSources.ts index 13ed28ae..70d72f5b 100644 --- a/src/backend/sources/ScrobbleSources.ts +++ b/src/backend/sources/ScrobbleSources.ts @@ -1,46 +1,45 @@ /* eslint-disable no-case-declarations */ -import { mergeArr, parseBool, readJson, validateJson } from "../utils.js"; -import SpotifySource from "./SpotifySource.js"; -import PlexSource from "./PlexSource.js"; -import TautulliSource from "./TautulliSource.js"; -import { SubsonicSource } from "./SubsonicSource.js"; -import JellyfinSource from "./JellyfinSource.js"; -import LastfmSource from "./LastfmSource.js"; -import DeezerSource from "./DeezerSource.js"; -import { ConfigMeta, InternalConfig, SourceType, sourceTypes } from "../common/infrastructure/Atomic.js"; +import { childLogger, Logger } from '@foxxmd/logging'; +import EventEmitter from "events"; import { configDir as defaultConfigDir } from "../common/index.js"; -import {childLogger, Logger} from '@foxxmd/logging'; -import { SourceAIOConfig, SourceConfig } from "../common/infrastructure/config/source/sources.js"; +import { ConfigMeta, InternalConfig, SourceType, sourceTypes } from "../common/infrastructure/Atomic.js"; +import { AIOConfig, SourceDefaults } from "../common/infrastructure/config/aioConfig.js"; +import { ChromecastSourceConfig } from "../common/infrastructure/config/source/chromecast.js"; import { DeezerData, DeezerSourceConfig } from "../common/infrastructure/config/source/deezer.js"; -import { LastfmClientConfig } from "../common/infrastructure/config/client/lastfm.js"; import { JellyData, JellySourceConfig } from "../common/infrastructure/config/source/jellyfin.js"; -import { SubsonicData, SubSonicSourceConfig } from "../common/infrastructure/config/source/subsonic.js"; -import { TautulliSourceConfig } from "../common/infrastructure/config/source/tautulli.js"; +import { JRiverData, JRiverSourceConfig } from "../common/infrastructure/config/source/jriver.js"; +import { KodiData, KodiSourceConfig } from "../common/infrastructure/config/source/kodi.js"; +import { LastfmSourceConfig } from "../common/infrastructure/config/source/lastfm.js"; +import { ListenBrainzSourceConfig } from "../common/infrastructure/config/source/listenbrainz.js"; +import { MopidySourceConfig } from "../common/infrastructure/config/source/mopidy.js"; +import { MPRISData, MPRISSourceConfig } from "../common/infrastructure/config/source/mpris.js"; import { PlexSourceConfig } from "../common/infrastructure/config/source/plex.js"; +import { SourceAIOConfig, SourceConfig } from "../common/infrastructure/config/source/sources.js"; import { SpotifySourceConfig, SpotifySourceData } from "../common/infrastructure/config/source/spotify.js"; -import AbstractSource from "./AbstractSource.js"; -import { AIOConfig, SourceDefaults } from "../common/infrastructure/config/aioConfig.js"; +import { SubsonicData, SubSonicSourceConfig } from "../common/infrastructure/config/source/subsonic.js"; +import { TautulliSourceConfig } from "../common/infrastructure/config/source/tautulli.js"; +import { WebScrobblerSourceConfig } from "../common/infrastructure/config/source/webscrobbler.js"; +import { YTMusicSourceConfig } from "../common/infrastructure/config/source/ytmusic.js"; import * as aioSchema from "../common/schema/aio-source.json"; import * as sourceSchema from "../common/schema/source.json"; -import { LastfmSourceConfig } from "../common/infrastructure/config/source/lastfm.js"; -import YTMusicSource from "./YTMusicSource.js"; -import { YTMusicSourceConfig } from "../common/infrastructure/config/source/ytmusic.js"; -import { MPRISData, MPRISSourceConfig } from "../common/infrastructure/config/source/mpris.js"; -import { MPRISSource } from "./MPRISSource.js"; -import EventEmitter from "events"; -import { MopidySource } from "./MopidySource.js"; -import { MopidySourceConfig } from "../common/infrastructure/config/source/mopidy.js"; -import ListenbrainzSource from "./ListenbrainzSource.js"; -import { ListenBrainzSourceConfig } from "../common/infrastructure/config/source/listenbrainz.js"; +import { WildcardEmitter } from "../common/WildcardEmitter.js"; +import { parseBool, readJson, validateJson } from "../utils.js"; +import AbstractSource from "./AbstractSource.js"; +import { ChromecastSource } from "./ChromecastSource.js"; +import DeezerSource from "./DeezerSource.js"; +import JellyfinSource from "./JellyfinSource.js"; import { JRiverSource } from "./JRiverSource.js"; -import { JRiverData, JRiverSourceConfig } from "../common/infrastructure/config/source/jriver.js"; import { KodiSource } from "./KodiSource.js"; -import { KodiData, KodiSourceConfig } from "../common/infrastructure/config/source/kodi.js"; -import { WildcardEmitter } from "../common/WildcardEmitter.js"; +import LastfmSource from "./LastfmSource.js"; +import ListenbrainzSource from "./ListenbrainzSource.js"; +import { MopidySource } from "./MopidySource.js"; +import { MPRISSource } from "./MPRISSource.js"; +import PlexSource from "./PlexSource.js"; +import SpotifySource from "./SpotifySource.js"; +import { SubsonicSource } from "./SubsonicSource.js"; +import TautulliSource from "./TautulliSource.js"; import { WebScrobblerSource } from "./WebScrobblerSource.js"; -import { WebScrobblerSourceConfig } from "../common/infrastructure/config/source/webscrobbler.js"; -import { ChromecastSource } from "./ChromecastSource.js"; -import { ChromecastSourceConfig } from "../common/infrastructure/config/source/chromecast.js"; +import YTMusicSource from "./YTMusicSource.js"; type groupedNamedConfigs = {[key: string]: ParsedConfig[]}; diff --git a/src/backend/sources/SpotifySource.ts b/src/backend/sources/SpotifySource.ts index acac7c9e..aff68d14 100644 --- a/src/backend/sources/SpotifySource.ts +++ b/src/backend/sources/SpotifySource.ts @@ -1,17 +1,11 @@ -import dayjs, {Dayjs} from "dayjs"; -import { - readJson, - writeFile, - sortByOldestPlayDate, - sleep, - parseRetryAfterSecsFromObj, - combinePartsToString, - findCauseByFunc, -} from "../utils.js"; +import dayjs, { Dayjs } from "dayjs"; +import EventEmitter from "events"; import SpotifyWebApi from "spotify-web-api-node"; import request from 'superagent'; -import AbstractSource, { RecentlyPlayedOptions } from "./AbstractSource.js"; -import { SpotifySourceConfig } from "../common/infrastructure/config/source/spotify.js"; +import { PlayObject, SCROBBLE_TS_SOC_END, SCROBBLE_TS_SOC_START, ScrobbleTsSOC } from "../../core/Atomic.js"; +import { truncateStringToLength } from "../../core/StringUtils.js"; +import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; +import { hasUpstreamError, UpstreamError } from "../common/errors/UpstreamError.js"; import { DEFAULT_POLLING_INTERVAL, FormatPlayObjectOptions, @@ -22,18 +16,24 @@ import { ReportedPlayerStatus, SourceData, } from "../common/infrastructure/Atomic.js"; -import PlayHistoryObject = SpotifyApi.PlayHistoryObject; -import EventEmitter from "events"; +import { SpotifySourceConfig } from "../common/infrastructure/config/source/spotify.js"; +import { + combinePartsToString, + findCauseByFunc, + parseRetryAfterSecsFromObj, + readJson, + sleep, + sortByOldestPlayDate, + writeFile, +} from "../utils.js"; +import { RecentlyPlayedOptions } from "./AbstractSource.js"; +import MemorySource from "./MemorySource.js"; +import AlbumObjectSimplified = SpotifyApi.AlbumObjectSimplified; +import ArtistObjectSimplified = SpotifyApi.ArtistObjectSimplified; import CurrentlyPlayingObject = SpotifyApi.CurrentlyPlayingObject; +import PlayHistoryObject = SpotifyApi.PlayHistoryObject; import TrackObjectFull = SpotifyApi.TrackObjectFull; -import ArtistObjectSimplified = SpotifyApi.ArtistObjectSimplified; -import AlbumObjectSimplified = SpotifyApi.AlbumObjectSimplified; import UserDevice = SpotifyApi.UserDevice; -import MemorySource from "./MemorySource.js"; -import { PlayObject, SCROBBLE_TS_SOC_END, SCROBBLE_TS_SOC_START, ScrobbleTsSOC } from "../../core/Atomic.js"; -import { buildTrackString, truncateStringToLength } from "../../core/StringUtils.js"; -import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; -import { hasUpstreamError, UpstreamError } from "../common/errors/UpstreamError.js"; const scopes = ['user-read-recently-played', 'user-read-currently-playing', 'user-read-playback-state', 'user-read-playback-position']; const state = 'random'; diff --git a/src/backend/sources/SubsonicSource.ts b/src/backend/sources/SubsonicSource.ts index bee2dc42..73c6ff58 100644 --- a/src/backend/sources/SubsonicSource.ts +++ b/src/backend/sources/SubsonicSource.ts @@ -1,17 +1,17 @@ -import request, {Request, Response} from 'superagent'; import * as crypto from 'crypto'; import dayjs from "dayjs"; import isSameOrAfter from "dayjs/plugin/isSameOrAfter.js"; -import {findCauseByFunc, parseRetryAfterSecsFromObj, removeDuplicates, sleep} from "../utils.js"; -import MemorySource from "./MemorySource.js"; -import { SubSonicSourceConfig } from "../common/infrastructure/config/source/subsonic.js"; -import { DEFAULT_RETRY_MULTIPLIER, FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; -import { RecentlyPlayedOptions } from "./AbstractSource.js"; import EventEmitter from "events"; +import request, { Request } from 'superagent'; import { PlayObject } from "../../core/Atomic.js"; -import {isNodeNetworkException} from "../common/errors/NodeErrors.js"; -import {UpstreamError} from "../common/errors/UpstreamError.js"; -import {getSubsonicResponse, SubsonicResponse, SubsonicResponseCommon} from "../common/vendor/subsonic/interfaces.js"; +import { isNodeNetworkException } from "../common/errors/NodeErrors.js"; +import { UpstreamError } from "../common/errors/UpstreamError.js"; +import { DEFAULT_RETRY_MULTIPLIER, FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; +import { SubSonicSourceConfig } from "../common/infrastructure/config/source/subsonic.js"; +import { getSubsonicResponse, SubsonicResponse, SubsonicResponseCommon } from "../common/vendor/subsonic/interfaces.js"; +import { findCauseByFunc, parseRetryAfterSecsFromObj, removeDuplicates, sleep } from "../utils.js"; +import { RecentlyPlayedOptions } from "./AbstractSource.js"; +import MemorySource from "./MemorySource.js"; dayjs.extend(isSameOrAfter); diff --git a/src/backend/sources/TautulliSource.ts b/src/backend/sources/TautulliSource.ts index ec2ffedb..86115480 100644 --- a/src/backend/sources/TautulliSource.ts +++ b/src/backend/sources/TautulliSource.ts @@ -1,12 +1,12 @@ import dayjs from "dayjs"; -import PlexSource from "./PlexSource.js"; -import { TautulliSourceConfig } from "../common/infrastructure/config/source/tautulli.js"; -import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; -import { combinePartsToString } from "../utils.js"; import EventEmitter from "events"; -import {Request} from "express"; +import { Request } from "express"; import { PlayObject } from "../../core/Atomic.js"; import { truncateStringToLength } from "../../core/StringUtils.js"; +import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; +import { TautulliSourceConfig } from "../common/infrastructure/config/source/tautulli.js"; +import { combinePartsToString } from "../utils.js"; +import PlexSource from "./PlexSource.js"; const shortDeviceId = truncateStringToLength(10, ''); diff --git a/src/backend/sources/WebScrobblerSource.ts b/src/backend/sources/WebScrobblerSource.ts index c22d39ea..023100dc 100644 --- a/src/backend/sources/WebScrobblerSource.ts +++ b/src/backend/sources/WebScrobblerSource.ts @@ -1,4 +1,6 @@ -import MemorySource from "./MemorySource.js"; +import dayjs from "dayjs"; +import EventEmitter from "events"; +import { PlayObject, SOURCE_SOT } from "../../core/Atomic.js"; import { FormatPlayObjectOptions, InternalConfig, @@ -7,11 +9,13 @@ import { REPORTED_PLAYER_STATUSES, ReportedPlayerStatus, } from "../common/infrastructure/Atomic.js"; -import EventEmitter from "events"; -import {PlayObject, SOURCE_SOT} from "../../core/Atomic.js"; -import { WebScrobblerHookEvent, WebScrobblerPayload, WebScrobblerSong } from "../common/vendor/webscrobbler/interfaces.js"; -import dayjs from "dayjs"; import { WebScrobblerSourceConfig } from "../common/infrastructure/config/source/webscrobbler.js"; +import { + WebScrobblerHookEvent, + WebScrobblerPayload, + WebScrobblerSong +} from "../common/vendor/webscrobbler/interfaces.js"; +import MemorySource from "./MemorySource.js"; export class WebScrobblerSource extends MemorySource { diff --git a/src/backend/sources/YTMusicSource.ts b/src/backend/sources/YTMusicSource.ts index 0a44f16b..ca1cba8e 100644 --- a/src/backend/sources/YTMusicSource.ts +++ b/src/backend/sources/YTMusicSource.ts @@ -1,13 +1,13 @@ -import YouTubeMusic from "youtube-music-ts-api"; -import AbstractSource, { RecentlyPlayedOptions } from "./AbstractSource.js"; -import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; -import {IYouTubeMusicAuthenticated} from "youtube-music-ts-api/interfaces-primary"; import dayjs from "dayjs"; -import { parseDurationFromTimestamp, playObjDataMatch } from "../utils.js"; -import {IPlaylistDetail, ITrackDetail} from "youtube-music-ts-api/interfaces-supplementary"; -import { YTMusicSourceConfig } from "../common/infrastructure/config/source/ytmusic.js"; import EventEmitter from "events"; +import YouTubeMusic from "youtube-music-ts-api"; +import { IYouTubeMusicAuthenticated } from "youtube-music-ts-api/interfaces-primary"; +import { IPlaylistDetail, ITrackDetail } from "youtube-music-ts-api/interfaces-supplementary"; import { PlayObject } from "../../core/Atomic.js"; +import { FormatPlayObjectOptions, InternalConfig } from "../common/infrastructure/Atomic.js"; +import { YTMusicSourceConfig } from "../common/infrastructure/config/source/ytmusic.js"; +import { parseDurationFromTimestamp, playObjDataMatch } from "../utils.js"; +import AbstractSource, { RecentlyPlayedOptions } from "./AbstractSource.js"; export default class YTMusicSource extends AbstractSource { apiInstance?: IYouTubeMusicAuthenticated diff --git a/src/backend/sources/ingressNotifiers/IngressNotifier.ts b/src/backend/sources/ingressNotifiers/IngressNotifier.ts index e5b6df72..c82d3f1f 100644 --- a/src/backend/sources/ingressNotifiers/IngressNotifier.ts +++ b/src/backend/sources/ingressNotifiers/IngressNotifier.ts @@ -1,7 +1,7 @@ -import {childLogger, Logger} from '@foxxmd/logging'; -import { remoteHostIdentifiers, remoteHostStr } from "../../utils.js"; -import {Request} from "express"; +import { childLogger, Logger } from '@foxxmd/logging'; +import { Request } from "express"; import { RemoteIdentityParts } from "../../common/infrastructure/Atomic.js"; +import { remoteHostIdentifiers, remoteHostStr } from "../../utils.js"; export abstract class IngressNotifier { diff --git a/src/backend/sources/ingressNotifiers/JellyfinNotifier.ts b/src/backend/sources/ingressNotifiers/JellyfinNotifier.ts index bc91ad69..e7d0cfa6 100644 --- a/src/backend/sources/ingressNotifiers/JellyfinNotifier.ts +++ b/src/backend/sources/ingressNotifiers/JellyfinNotifier.ts @@ -1,8 +1,8 @@ -import { IngressNotifier } from "./IngressNotifier.js"; -import {Request} from "express"; -import JellyfinSource from "../JellyfinSource.js"; +import { Logger } from "@foxxmd/logging"; +import { Request } from "express"; import { remoteHostIdentifiers, remoteHostStr } from "../../utils.js"; -import {Logger} from "@foxxmd/logging"; +import JellyfinSource from "../JellyfinSource.js"; +import { IngressNotifier } from "./IngressNotifier.js"; export class JellyfinNotifier extends IngressNotifier { diff --git a/src/backend/sources/ingressNotifiers/PlexNotifier.ts b/src/backend/sources/ingressNotifiers/PlexNotifier.ts index 079e9c10..c12e1814 100644 --- a/src/backend/sources/ingressNotifiers/PlexNotifier.ts +++ b/src/backend/sources/ingressNotifiers/PlexNotifier.ts @@ -1,7 +1,7 @@ -import { IngressNotifier } from "./IngressNotifier.js"; -import {Request} from "express"; +import { Logger } from "@foxxmd/logging"; +import { Request } from "express"; import PlexSource from "../PlexSource.js"; -import {Logger} from "@foxxmd/logging"; +import { IngressNotifier } from "./IngressNotifier.js"; export class PlexNotifier extends IngressNotifier { diff --git a/src/backend/sources/ingressNotifiers/TautulliNotifier.ts b/src/backend/sources/ingressNotifiers/TautulliNotifier.ts index 5db110a2..ccc5dac9 100644 --- a/src/backend/sources/ingressNotifiers/TautulliNotifier.ts +++ b/src/backend/sources/ingressNotifiers/TautulliNotifier.ts @@ -1,8 +1,7 @@ -import { IngressNotifier } from "./IngressNotifier.js"; -import {Request} from "express"; -import PlexSource from "../PlexSource.js"; +import { Logger } from "@foxxmd/logging"; +import { Request } from "express"; import TautulliSource from "../TautulliSource.js"; -import {Logger} from "@foxxmd/logging"; +import { IngressNotifier } from "./IngressNotifier.js"; export class TautulliNotifier extends IngressNotifier { diff --git a/src/backend/sources/ingressNotifiers/WebhookNotifier.ts b/src/backend/sources/ingressNotifiers/WebhookNotifier.ts index d5b22625..38e68388 100644 --- a/src/backend/sources/ingressNotifiers/WebhookNotifier.ts +++ b/src/backend/sources/ingressNotifiers/WebhookNotifier.ts @@ -1,7 +1,7 @@ -import { IngressNotifier } from "./IngressNotifier.js"; -import {Request} from "express"; +import { Logger } from "@foxxmd/logging"; +import { Request } from "express"; import path from "path"; -import {Logger} from "@foxxmd/logging"; +import { IngressNotifier } from "./IngressNotifier.js"; export class WebhookNotifier extends IngressNotifier { diff --git a/src/backend/tasks/heartbeatClients.ts b/src/backend/tasks/heartbeatClients.ts index 472fcd21..678210b3 100644 --- a/src/backend/tasks/heartbeatClients.ts +++ b/src/backend/tasks/heartbeatClients.ts @@ -1,7 +1,6 @@ -import {childLogger, Logger} from '@foxxmd/logging'; -import { mergeArr } from "../utils.js"; -import {AsyncTask} from "toad-scheduler"; -import {PromisePool} from "@supercharge/promise-pool"; +import { childLogger, Logger } from '@foxxmd/logging'; +import { PromisePool } from "@supercharge/promise-pool"; +import { AsyncTask } from "toad-scheduler"; import ScrobbleClients from "../scrobblers/ScrobbleClients.js"; export const createHeartbeatClientsTask = (clients: ScrobbleClients, parentLogger: Logger) => { diff --git a/src/backend/tasks/heartbeatSources.ts b/src/backend/tasks/heartbeatSources.ts index 6d6efb9d..50ac72f0 100644 --- a/src/backend/tasks/heartbeatSources.ts +++ b/src/backend/tasks/heartbeatSources.ts @@ -1,9 +1,8 @@ -import {childLogger, Logger} from '@foxxmd/logging'; -import { mergeArr } from "../utils.js"; -import {AsyncTask} from "toad-scheduler"; -import {PromisePool} from "@supercharge/promise-pool"; -import ScrobbleSources from "../sources/ScrobbleSources.js"; +import { childLogger, Logger } from '@foxxmd/logging'; +import { PromisePool } from "@supercharge/promise-pool"; +import { AsyncTask } from "toad-scheduler"; import { ChromecastSource } from "../sources/ChromecastSource.js"; +import ScrobbleSources from "../sources/ScrobbleSources.js"; export const createHeartbeatSourcesTask = (sources: ScrobbleSources, parentLogger: Logger) => { const logger = childLogger(parentLogger, ['Heartbeat', 'Sources']); diff --git a/src/backend/tests/jellyfin/jellyfin.test.ts b/src/backend/tests/jellyfin/jellyfin.test.ts index 07770787..c1e7fdfd 100644 --- a/src/backend/tests/jellyfin/jellyfin.test.ts +++ b/src/backend/tests/jellyfin/jellyfin.test.ts @@ -1,11 +1,11 @@ -import {describe, it} from 'mocha'; -import {assert} from 'chai'; -import samplePayload from './playbackProgressSample.json'; +import { loggerTest } from "@foxxmd/logging"; +import { assert } from 'chai'; +import EventEmitter from "events"; +import { describe, it } from 'mocha'; +import { JsonPlayObject } from "../../../core/Atomic.js"; import JellyfinSource from "../../sources/JellyfinSource.js"; -import EventEmitter from "events"; -import { JsonPlayObject, PlayObject } from "../../../core/Atomic.js"; -import {loggerTest} from "@foxxmd/logging"; +import samplePayload from './playbackProgressSample.json'; const dataAsFixture = (data: any): TestFixture => { return data as TestFixture; diff --git a/src/backend/tests/listenbrainz/listenbrainz.test.ts b/src/backend/tests/listenbrainz/listenbrainz.test.ts index 8e35fe28..7f702421 100644 --- a/src/backend/tests/listenbrainz/listenbrainz.test.ts +++ b/src/backend/tests/listenbrainz/listenbrainz.test.ts @@ -1,11 +1,20 @@ -import {describe, it} from 'mocha'; -import {assert} from 'chai'; +import { loggerTest } from "@foxxmd/logging"; +import { assert } from 'chai'; +import dayjs from "dayjs"; +import { describe, it } from 'mocha'; +import { http, HttpResponse } from "msw"; +import { PlayObject } from "../../../core/Atomic.js"; +import { UpstreamError } from "../../common/errors/UpstreamError.js"; + +import { ListenbrainzApiClient, ListenResponse } from "../../common/vendor/ListenbrainzApiClient.js"; +import { ExpectedResults } from "../utils/interfaces.js"; +import { withRequestInterception } from "../utils/networking.js"; +import artistWithProperJoiner from './correctlyMapped/artistProperHasJoinerInName.json'; // correct mappings import multiArtistInArtistName from './correctlyMapped/multiArtistInArtistName.json'; import multiArtistsInTrackName from './correctlyMapped/multiArtistInTrackName.json'; -import noArtistMapping from './correctlyMapped/noArtistMapping.json'; import multiMappedArtistsWithSingleUserArtist from './correctlyMapped/multiArtistMappingWithSingleRecordedArtist.json'; -import artistWithProperJoiner from './correctlyMapped/artistProperHasJoinerInName.json'; +import noArtistMapping from './correctlyMapped/noArtistMapping.json'; import normalizedValues from './correctlyMapped/normalizedName.json'; import slightlyDifferentNames from './correctlyMapped/trackNameSlightlyDifferent.json'; @@ -13,15 +22,6 @@ import slightlyDifferentNames from './correctlyMapped/trackNameSlightlyDifferent import incorrectMultiArtistsTrackName from './incorrectlyMapped/multiArtistsInTrackName.json'; import veryWrong from './incorrectlyMapped/veryWrong.json'; -import { ListenbrainzApiClient, ListenResponse } from "../../common/vendor/ListenbrainzApiClient.js"; -import { PlayObject } from "../../../core/Atomic.js"; -import dayjs from "dayjs"; -import { withRequestInterception } from "../utils/networking.js"; -import {http, HttpResponse} from "msw"; -import { UpstreamError } from "../../common/errors/UpstreamError.js"; -import { ExpectedResults } from "../utils/interfaces.js"; -import {loggerTest} from "@foxxmd/logging"; - interface LZTestFixture { data: ListenResponse expected: ExpectedResults diff --git a/src/backend/tests/player/player.test.ts b/src/backend/tests/player/player.test.ts index 178e3203..6584256d 100644 --- a/src/backend/tests/player/player.test.ts +++ b/src/backend/tests/player/player.test.ts @@ -1,12 +1,17 @@ -import {describe, it} from 'mocha'; -import {assert} from 'chai'; -import { generatePlay } from "../utils/PlayTestUtils.js"; +import { loggerTest } from "@foxxmd/logging"; +import { assert } from 'chai'; +import clone from "clone"; +import dayjs from "dayjs"; +import { describe, it } from 'mocha'; +import { + CALCULATED_PLAYER_STATUSES, + NO_DEVICE, + NO_USER, + REPORTED_PLAYER_STATUSES +} from "../../common/infrastructure/Atomic.js"; import { GenericPlayerState } from "../../sources/PlayerState/GenericPlayerState.js"; -import { CALCULATED_PLAYER_STATUSES, NO_DEVICE, NO_USER, REPORTED_PLAYER_STATUSES } from "../../common/infrastructure/Atomic.js"; import { playObjDataMatch } from "../../utils.js"; -import dayjs from "dayjs"; -import clone from "clone"; -import {loggerTest} from "@foxxmd/logging"; +import { generatePlay } from "../utils/PlayTestUtils.js"; const logger = loggerTest; diff --git a/src/backend/tests/scrobbler/TestScrobbler.ts b/src/backend/tests/scrobbler/TestScrobbler.ts index 15787e98..c6f3998d 100644 --- a/src/backend/tests/scrobbler/TestScrobbler.ts +++ b/src/backend/tests/scrobbler/TestScrobbler.ts @@ -1,9 +1,9 @@ -import AbstractScrobbleClient from "../../scrobblers/AbstractScrobbleClient.js"; -import { PlayObject } from "../../../core/Atomic.js"; -import { Notifiers } from "../../notifier/Notifiers.js"; +import { loggerTest } from "@foxxmd/logging"; import EventEmitter from "events"; import request from "superagent"; -import {loggerTest} from "@foxxmd/logging"; +import { PlayObject } from "../../../core/Atomic.js"; +import { Notifiers } from "../../notifier/Notifiers.js"; +import AbstractScrobbleClient from "../../scrobblers/AbstractScrobbleClient.js"; export class TestScrobbler extends AbstractScrobbleClient { diff --git a/src/backend/tests/scrobbler/scrobblers.test.ts b/src/backend/tests/scrobbler/scrobblers.test.ts index 29bab612..9cff7d8e 100644 --- a/src/backend/tests/scrobbler/scrobblers.test.ts +++ b/src/backend/tests/scrobbler/scrobblers.test.ts @@ -1,21 +1,20 @@ -import {describe, it, after, before} from 'mocha'; -import chai, {assert} from 'chai'; +import chai, { assert } from 'chai'; import asPromised from 'chai-as-promised'; import clone from 'clone'; -import pEvent from 'p-event'; +import dayjs from "dayjs"; +import { after, before, describe, it } from 'mocha'; import { http, HttpResponse } from 'msw'; - -chai.use(asPromised); - -import withDuration from '../plays/withDuration.json'; +import pEvent from 'p-event'; +import { PlayObject } from "../../../core/Atomic.js"; +import { sleep } from "../../utils.js"; import mixedDuration from '../plays/mixedDuration.json'; +import withDuration from '../plays/withDuration.json'; +import { MockNetworkError, withRequestInterception } from "../utils/networking.js"; +import { asPlays, generatePlay, normalizePlays } from "../utils/PlayTestUtils.js"; import { TestScrobbler } from "./TestScrobbler.js"; -import { asPlays, generatePlay, normalizePlays } from "../utils/PlayTestUtils.js"; -import dayjs from "dayjs"; -import { sleep } from "../../utils.js"; -import { MockNetworkError, withRequestInterception } from "../utils/networking.js"; -import { PlayObject } from "../../../core/Atomic.js"; + +chai.use(asPromised); const firstPlayDate = dayjs().subtract(1, 'hour'); const olderFirstPlayDate = dayjs().subtract(4, 'hour'); diff --git a/src/backend/tests/utils/PlayTestUtils.ts b/src/backend/tests/utils/PlayTestUtils.ts index f46ae56c..16f7bc87 100644 --- a/src/backend/tests/utils/PlayTestUtils.ts +++ b/src/backend/tests/utils/PlayTestUtils.ts @@ -1,11 +1,11 @@ -import { JsonPlayObject, ObjectPlayData, PlayData, PlayMeta, PlayObject } from "../../../core/Atomic.js"; -import dayjs, {Dayjs} from "dayjs"; -import utc from "dayjs/plugin/utc.js"; +import { faker } from '@faker-js/faker'; +import dayjs, { Dayjs } from "dayjs"; +import duration from "dayjs/plugin/duration.js"; import isBetween from "dayjs/plugin/isBetween.js"; import relativeTime from "dayjs/plugin/relativeTime.js"; -import duration from "dayjs/plugin/duration.js"; import timezone from "dayjs/plugin/timezone.js"; -import {faker} from '@faker-js/faker'; +import utc from "dayjs/plugin/utc.js"; +import { JsonPlayObject, ObjectPlayData, PlayMeta, PlayObject } from "../../../core/Atomic.js"; dayjs.extend(utc) dayjs.extend(isBetween); diff --git a/src/backend/tests/utils/networking.ts b/src/backend/tests/utils/networking.ts index 7818c8b4..8fe3ab21 100644 --- a/src/backend/tests/utils/networking.ts +++ b/src/backend/tests/utils/networking.ts @@ -1,5 +1,5 @@ +import { setupServer, SetupServer } from 'msw/node'; import { NodeNetworkErrorCode, NodeNetworkException } from "../../common/errors/NodeErrors.js"; -import { setupServer, SetupServer } from 'msw/node'; export class MockNetworkError extends Error implements NodeNetworkException { diff --git a/src/backend/tests/utils/strings.test.ts b/src/backend/tests/utils/strings.test.ts index a0693691..e30f4c80 100644 --- a/src/backend/tests/utils/strings.test.ts +++ b/src/backend/tests/utils/strings.test.ts @@ -1,14 +1,14 @@ -import {describe, it} from 'mocha'; -import {assert} from 'chai'; +import { assert } from 'chai'; +import { describe, it } from 'mocha'; +import { intersect } from "../../utils.js"; import { compareNormalizedStrings, normalizeStr, parseTrackCredits, uniqueNormalizedStrArr } from "../../utils/StringUtils.js"; -import testData from './playTestData.json'; import { ExpectedResults } from "./interfaces.js"; -import { intersect } from "../../utils.js"; +import testData from './playTestData.json'; interface PlayTestFixture { caseHints: string[] diff --git a/src/backend/utils.ts b/src/backend/utils.ts index c15be4bf..f3a280fc 100644 --- a/src/backend/utils.ts +++ b/src/backend/utils.ts @@ -1,12 +1,19 @@ -import {accessSync, constants, promises} from "fs"; -import dayjs, {Dayjs} from 'dayjs'; +import { Logger } from '@foxxmd/logging'; +import backoffStrategies from '@kenyip/backoff-strategies'; +import address from "address"; +import * as AjvNS from 'ajv'; +import Ajv, { Schema } from 'ajv'; +import { replaceResultTransformer, stripIndentTransformer, TemplateTag, trimResultTransformer } from 'common-tags'; +import dayjs, { Dayjs } from 'dayjs'; +import { Duration } from "dayjs/plugin/duration.js"; import utc from 'dayjs/plugin/utc.js'; -import {Logger} from '@foxxmd/logging'; +import { Request } from "express"; +import { accessSync, constants, promises } from "fs"; import JSON5 from 'json5'; -import {TimeoutError, WebapiError} from "spotify-web-api-node/src/response-error.js"; -import {Schema} from 'ajv'; -import * as AjvNS from 'ajv'; -import Ajv from 'ajv'; +import pathUtil from "path"; +import { getErrorCause } from "pony-cause"; +import { TimeoutError, WebapiError } from "spotify-web-api-node/src/response-error.js"; +import { PlayObject } from "../core/Atomic.js"; import { asPlayerStateData, NO_DEVICE, @@ -19,14 +26,6 @@ import { RemoteIdentityParts, ScrobbleThresholdResult, } from "./common/infrastructure/Atomic.js"; -import {Request} from "express"; -import pathUtil from "path"; -import {getErrorCause} from "pony-cause"; -import backoffStrategies from '@kenyip/backoff-strategies'; -import {replaceResultTransformer, stripIndentTransformer, TemplateTag, trimResultTransformer} from 'common-tags'; -import {Duration} from "dayjs/plugin/duration.js"; -import { PlayObject } from "../core/Atomic.js"; -import address from "address"; //const { default: Ajv } = AjvNS; dayjs.extend(utc); diff --git a/src/backend/utils/MDNSUtils.ts b/src/backend/utils/MDNSUtils.ts index baa31314..a7d76e0e 100644 --- a/src/backend/utils/MDNSUtils.ts +++ b/src/backend/utils/MDNSUtils.ts @@ -1,10 +1,10 @@ -import {Logger} from "@foxxmd/logging"; +import { Browser, Service, ServiceType } from "@astronautlabs/mdns"; +import { Logger } from "@foxxmd/logging"; import AvahiBrowser from 'avahi-browse'; +import { MdnsDeviceInfo } from "../common/infrastructure/Atomic.js"; import { MaybeLogger } from "../common/logging.js"; import { sleep } from "../utils.js"; -import { MdnsDeviceInfo } from "../common/infrastructure/Atomic.js"; -import {Browser, Service, ServiceType} from "@astronautlabs/mdns"; -import {debounce, DebouncedFunction} from "./debounce.js"; +import { debounce, DebouncedFunction } from "./debounce.js"; export interface AvahiService { service_name: string diff --git a/src/backend/utils/StringUtils.ts b/src/backend/utils/StringUtils.ts index e10eed15..278f79dc 100644 --- a/src/backend/utils/StringUtils.ts +++ b/src/backend/utils/StringUtils.ts @@ -1,7 +1,7 @@ +import { strategies, stringSameness, StringSamenessResult } from "@foxxmd/string-sameness"; +import { PlayObject } from "../../core/Atomic.js"; import { DELIMITERS } from "../common/infrastructure/Atomic.js"; import { parseRegexSingleOrFail } from "../utils.js"; -import { PlayObject } from "../../core/Atomic.js"; -import {stringSameness, StringSamenessResult, strategies} from "@foxxmd/string-sameness"; const {levenStrategy, diceStrategy} = strategies; diff --git a/src/backend/utils/TimeUtils.ts b/src/backend/utils/TimeUtils.ts index 5857e4b3..6bfeae86 100644 --- a/src/backend/utils/TimeUtils.ts +++ b/src/backend/utils/TimeUtils.ts @@ -1,3 +1,4 @@ +import dayjs, { Dayjs } from "dayjs"; import { PlayObject, SCROBBLE_TS_SOC_END, @@ -10,16 +11,15 @@ import { TemporalAccuracy, TemporalPlayComparison, } from "../../core/Atomic.js"; +import { capitalize } from "../../core/StringUtils.js"; import { DEFAULT_SCROBBLE_DURATION_THRESHOLD, DEFAULT_SCROBBLE_PERCENT_THRESHOLD, lowGranularitySources, ScrobbleThresholdResult, } from "../common/infrastructure/Atomic.js"; -import { formatNumber } from "../utils.js"; import { ScrobbleThresholds } from "../common/infrastructure/config/source/index.js"; -import { capitalize } from "../../core/StringUtils.js"; -import dayjs, {Dayjs} from "dayjs"; +import { formatNumber } from "../utils.js"; export const temporalPlayComparisonSummary = (data: TemporalPlayComparison, existingPlay?: PlayObject, candidatePlay?: PlayObject) => { const parts: string[] = []; diff --git a/src/core/Atomic.ts b/src/core/Atomic.ts index 45d3c649..fbf48bd5 100644 --- a/src/core/Atomic.ts +++ b/src/core/Atomic.ts @@ -1,6 +1,6 @@ -import {Dayjs} from "dayjs"; -import {ListenProgress} from "../backend/sources/PlayerState/ListenProgress.js"; -import {LogDataPretty, LogLevel} from "@foxxmd/logging"; +import { LogDataPretty, LogLevel } from "@foxxmd/logging"; +import { Dayjs } from "dayjs"; +import { ListenProgress } from "../backend/sources/PlayerState/ListenProgress.js"; export interface SourceStatusData { status: string;