mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-07-28 00:22:26 +02:00
added songwhip
This commit is contained in:
@@ -10,5 +10,6 @@ export const globalEvents = {
|
||||
showSettings: "showSettings",
|
||||
storeChanged: "storeChanged",
|
||||
error: "error",
|
||||
whip: "whip",
|
||||
log: "log",
|
||||
};
|
||||
|
21
src/features/songwhip/models/Artist.ts
Normal file
21
src/features/songwhip/models/Artist.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { ServiceLinks } from "./ServiceLinks";
|
||||
|
||||
export interface Artist {
|
||||
type: string;
|
||||
id: number;
|
||||
path: string;
|
||||
name: string;
|
||||
sourceUrl: string;
|
||||
sourceCountry: string;
|
||||
url: string;
|
||||
image: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
refreshedAt: string;
|
||||
serviceIds: { [key: string]: string };
|
||||
orchardId: string;
|
||||
spotifyId: string;
|
||||
links: { [key: string]: ServiceLinks[] };
|
||||
linksCountries: string[];
|
||||
description: string;
|
||||
}
|
4
src/features/songwhip/models/ServiceLinks.ts
Normal file
4
src/features/songwhip/models/ServiceLinks.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface ServiceLinks {
|
||||
link: string;
|
||||
countries: string[];
|
||||
}
|
27
src/features/songwhip/models/whip.ts
Normal file
27
src/features/songwhip/models/whip.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Artist } from "./Artist";
|
||||
import { ServiceLinks } from "./ServiceLinks";
|
||||
|
||||
export interface WhippedResult {
|
||||
status: string;
|
||||
data: {
|
||||
item: {
|
||||
type: string;
|
||||
id: number;
|
||||
path: string;
|
||||
name: string;
|
||||
url: string;
|
||||
sourceUrl: string;
|
||||
sourceCountry: string;
|
||||
releaseDate: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
refreshedAt: string;
|
||||
image: string;
|
||||
isrc: string;
|
||||
isExplicit: boolean;
|
||||
links: { [key: string]: ServiceLinks[] };
|
||||
linksCountries: string[];
|
||||
artists: Artist[];
|
||||
};
|
||||
};
|
||||
}
|
32
src/features/songwhip/songwhip.ts
Normal file
32
src/features/songwhip/songwhip.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { WhippedResult } from "./models/whip";
|
||||
import axios from "axios";
|
||||
|
||||
export class Songwhip {
|
||||
/**
|
||||
* Call the songwhip API and create a shareable songwhip page
|
||||
* @param currentUrl
|
||||
* @returns
|
||||
*/
|
||||
public static async whip(currentUrl: string): Promise<WhippedResult> {
|
||||
try {
|
||||
const response = await axios.post("https://songwhip.com/api/songwhip/create", {
|
||||
url: currentUrl,
|
||||
// doesn't actually matter.. returns everything the same way anyway
|
||||
country: "NL",
|
||||
});
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.log(JSON.stringify(error));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a songwhip response into a shareable url
|
||||
* @param response
|
||||
* @returns
|
||||
*/
|
||||
public static getWhipUrl(response: WhippedResult) {
|
||||
return `https://songwhip.com${response.data.item.url}`;
|
||||
}
|
||||
}
|
@@ -26,6 +26,7 @@ import {
|
||||
import { settings } from "./constants/settings";
|
||||
import { addTray, refreshTray } from "./scripts/tray";
|
||||
import { MediaInfo } from "./models/mediaInfo";
|
||||
import { Songwhip } from "./features/songwhip/songwhip";
|
||||
import { Logger } from "./features/logger";
|
||||
const tidalUrl = "https://listen.tidal.com";
|
||||
|
||||
@@ -222,4 +223,8 @@ ipcMain.on(globalEvents.error, (event) => {
|
||||
console.log(event);
|
||||
});
|
||||
|
||||
ipcMain.handle(globalEvents.whip, async (event, url) => {
|
||||
return await Songwhip.whip(url);
|
||||
});
|
||||
|
||||
Logger.watch(ipcMain);
|
||||
|
@@ -1,16 +1,17 @@
|
||||
import { Notification, app, dialog } from "@electron/remote";
|
||||
import { ipcRenderer } from "electron";
|
||||
import { app, dialog, Notification } from "@electron/remote";
|
||||
import { clipboard, ipcRenderer } from "electron";
|
||||
import fs from "fs";
|
||||
import Player from "mpris-service";
|
||||
import { globalEvents } from "./constants/globalEvents";
|
||||
import { settings } from "./constants/settings";
|
||||
import { statuses } from "./constants/statuses";
|
||||
import { Songwhip } from "./features/songwhip/songwhip";
|
||||
import { Options } from "./models/options";
|
||||
import { downloadFile } from "./scripts/download";
|
||||
import { addHotkey } from "./scripts/hotkeys";
|
||||
|
||||
import { settingsStore } from "./scripts/settings";
|
||||
import { setTitle } from "./scripts/window-functions";
|
||||
|
||||
const notificationPath = `${app.getPath("userData")}/notification.jpg`;
|
||||
const appName = "Tidal Hifi";
|
||||
let currentSong = "";
|
||||
@@ -232,6 +233,15 @@ function addHotKeys() {
|
||||
addHotkey("control+r", function () {
|
||||
elements.click("repeat");
|
||||
});
|
||||
addHotkey("control+w", async function () {
|
||||
const result = await ipcRenderer.invoke(globalEvents.whip, getTrackURL());
|
||||
const url = Songwhip.getWhipUrl(result);
|
||||
clipboard.writeText(url);
|
||||
new Notification({
|
||||
title: `Successfully whipped: `,
|
||||
body: `URL copied to clipboard: ${url}`,
|
||||
}).show();
|
||||
});
|
||||
}
|
||||
|
||||
// always add the hotkey for the settings window
|
||||
|
Reference in New Issue
Block a user