mirror of
				https://github.com/Mastermindzh/tidal-hifi.git
				synced 2025-11-04 10:49:26 +01:00 
			
		
		
		
	Removed Songwhip (they shut down) and replaced it with TIDAL's universal link system
This commit is contained in:
		@@ -10,7 +10,7 @@ export const globalEvents = {
 | 
			
		||||
  showSettings: "showSettings",
 | 
			
		||||
  storeChanged: "storeChanged",
 | 
			
		||||
  error: "error",
 | 
			
		||||
  whip: "whip",
 | 
			
		||||
  getUniversalLink: "getUniversalLink",
 | 
			
		||||
  log: "log",
 | 
			
		||||
  toggleFavorite: "toggleFavorite",
 | 
			
		||||
  toggleShuffle: "toggleShuffle",
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
  "openapi": "3.1.0",
 | 
			
		||||
  "info": {
 | 
			
		||||
    "title": "TIDAL Hi-Fi API",
 | 
			
		||||
    "version": "5.16.0",
 | 
			
		||||
    "version": "5.17.0",
 | 
			
		||||
    "description": "",
 | 
			
		||||
    "license": {
 | 
			
		||||
      "name": "MIT",
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								src/features/sharingService/sharingService.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/features/sharingService/sharingService.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
export class SharingService {
 | 
			
		||||
  /**
 | 
			
		||||
   * Retrieve the universal link given a regular track link
 | 
			
		||||
   * @param currentUrl
 | 
			
		||||
   * @returns
 | 
			
		||||
   */
 | 
			
		||||
  public static getUniversalLink(currentUrl: string): string {
 | 
			
		||||
    return `${currentUrl}?u`;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,21 +0,0 @@
 | 
			
		||||
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;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +0,0 @@
 | 
			
		||||
export interface ServiceLinks {
 | 
			
		||||
  link: string;
 | 
			
		||||
  countries: string[];
 | 
			
		||||
}
 | 
			
		||||
@@ -1,27 +0,0 @@
 | 
			
		||||
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[];
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@@ -1,32 +0,0 @@
 | 
			
		||||
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}`;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -10,7 +10,7 @@ import {
 | 
			
		||||
  releaseInhibitorIfActive,
 | 
			
		||||
} from "./features/idleInhibitor/idleInhibitor";
 | 
			
		||||
import { Logger } from "./features/logger";
 | 
			
		||||
import { Songwhip } from "./features/songwhip/songwhip";
 | 
			
		||||
import { SharingService } from "./features/sharingService/sharingService";
 | 
			
		||||
import { MediaInfo } from "./models/mediaInfo";
 | 
			
		||||
import { MediaStatus } from "./models/mediaStatus";
 | 
			
		||||
import { initRPC, rpc, unRPC } from "./scripts/discord";
 | 
			
		||||
@@ -250,8 +250,8 @@ ipcMain.on(globalEvents.error, (event) => {
 | 
			
		||||
  console.log(event);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
ipcMain.handle(globalEvents.whip, async (event, url) => {
 | 
			
		||||
  return Songwhip.whip(url);
 | 
			
		||||
ipcMain.handle(globalEvents.getUniversalLink, async (event, url) => {
 | 
			
		||||
  return SharingService.getUniversalLink(url);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
Logger.watch(ipcMain);
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ import {
 | 
			
		||||
} from "./features/listenbrainz/listenbrainz";
 | 
			
		||||
import { StoreData } from "./features/listenbrainz/models/storeData";
 | 
			
		||||
import { Logger } from "./features/logger";
 | 
			
		||||
import { Songwhip } from "./features/songwhip/songwhip";
 | 
			
		||||
import { SharingService } from "./features/sharingService/sharingService";
 | 
			
		||||
import { addCustomCss } from "./features/theming/theming";
 | 
			
		||||
import { convertDurationToSeconds } from "./features/time/parse";
 | 
			
		||||
import { MediaInfo } from "./models/mediaInfo";
 | 
			
		||||
@@ -50,6 +50,7 @@ const elements = {
 | 
			
		||||
  repeat: '*[data-test="repeat"]',
 | 
			
		||||
  account: '*[data-test^="profile-image-button"]',
 | 
			
		||||
  settings: '*[data-test^="sidebar-menu-button"]',
 | 
			
		||||
  openSettings: '*[data-test^="open-settings"]',
 | 
			
		||||
  media: '*[data-test="current-media-imagery"]',
 | 
			
		||||
  image: "img",
 | 
			
		||||
  current: '*[data-test="current-time"]',
 | 
			
		||||
@@ -220,9 +221,9 @@ ListenBrainzStore.clear();
 | 
			
		||||
function addHotKeys() {
 | 
			
		||||
  if (settingsStore.get(settings.enableCustomHotkeys)) {
 | 
			
		||||
    addHotkey("Control+p", function () {
 | 
			
		||||
      elements.click("account");
 | 
			
		||||
      elements.click("settings");
 | 
			
		||||
      setTimeout(() => {
 | 
			
		||||
        elements.click("settings");
 | 
			
		||||
        elements.click("openSettings");
 | 
			
		||||
      }, 100);
 | 
			
		||||
    });
 | 
			
		||||
    addHotkey("Control+l", function () {
 | 
			
		||||
@@ -254,11 +255,10 @@ function addHotKeys() {
 | 
			
		||||
      elements.click("repeat");
 | 
			
		||||
    });
 | 
			
		||||
    addHotkey("control+w", async function () {
 | 
			
		||||
      const result = await ipcRenderer.invoke(globalEvents.whip, getTrackURL());
 | 
			
		||||
      const url = Songwhip.getWhipUrl(result);
 | 
			
		||||
      const url = SharingService.getUniversalLink(getTrackURL());
 | 
			
		||||
      clipboard.writeText(url);
 | 
			
		||||
      new Notification({
 | 
			
		||||
        title: `Successfully whipped: `,
 | 
			
		||||
        title: `Universal link generated: `,
 | 
			
		||||
        body: `URL copied to clipboard: ${url}`,
 | 
			
		||||
      }).show();
 | 
			
		||||
    });
 | 
			
		||||
@@ -550,7 +550,7 @@ setInterval(function () {
 | 
			
		||||
  const artistsArray = elements.getArtistsArray();
 | 
			
		||||
  const artistsString = elements.getArtistsString(artistsArray);
 | 
			
		||||
  const songDashArtistTitle = `${title} - ${artistsString}`;
 | 
			
		||||
  const staticTitle = "TIDAL Hi-Fi"
 | 
			
		||||
  const staticTitle = "TIDAL Hi-Fi";
 | 
			
		||||
  const titleOrArtistsChanged = currentSong !== songDashArtistTitle;
 | 
			
		||||
  const current = elements.getText("current");
 | 
			
		||||
  const currentStatus = getCurrentlyPlayingStatus();
 | 
			
		||||
@@ -595,7 +595,9 @@ setInterval(function () {
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // update title, url and play info with new info
 | 
			
		||||
    settingsStore.get(settings.staticWindowTitle) ? setTitle(staticTitle) : setTitle(songDashArtistTitle);
 | 
			
		||||
    settingsStore.get(settings.staticWindowTitle)
 | 
			
		||||
      ? setTitle(staticTitle)
 | 
			
		||||
      : setTitle(songDashArtistTitle);
 | 
			
		||||
    getTrackURL();
 | 
			
		||||
    currentSong = songDashArtistTitle;
 | 
			
		||||
    currentPlayStatus = currentStatus;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user