Compare commits

...

27 commits

Author SHA1 Message Date
Nico
4acf499c52
Merge a3db3faba6 into bcfef05a8a 2024-09-16 18:08:16 +09:00
Vendicated
bcfef05a8a
delete TimeBarAllActivites ~ now a stock feature 2024-09-14 17:22:29 +02:00
Cookie
f17b92c2fd
OpenInApp: support Spotify prerelease links (#2870) 2024-09-14 15:03:58 +00:00
Ryan Cao
292f7d71d3
AppleMusicRichPresence: fix metadata fetching (#2864) 2024-09-14 16:59:05 +02:00
Nico
a3db3faba6
fix(mediaPlaybackSpeed): update broken patch 2024-07-18 09:11:01 +02:00
D3SOX
96df1bbe1e
feat(mediaPlaybackSpeed): add settings to set default speeds 2024-07-01 18:44:46 +02:00
D3SOX
308b9a1fef
Merge branch 'refs/heads/dev' into plugin/audioPlaybackSpeed 2024-07-01 18:44:29 +02:00
Nico
777b5dde69
refactor(mediaPlaybackSpeed): improve find 2024-06-19 19:39:42 +02:00
Nico
bf71bbc979
fix(mediaPlaybackSpeed): update voice message patch 2024-06-19 07:09:54 +02:00
D3SOX
c9459e9cf7
fix(mediaPlaybackSpeed): mediaRef is possibly undefined when 1 patch breaks 2024-06-06 11:58:25 +02:00
D3SOX
a8eea4dc7a
fix(mediaPlaybackSpeed): improve patch 2024-06-06 11:53:49 +02:00
D3SOX
b24c50d213
fix(mediaPlaybackSpeed): add error boundary 2024-06-06 09:02:40 +02:00
Nico
d2efeff84f
refactor(mediaPlaybackSpeed: export icon directly
Co-authored-by: vee <vendicated@riseup.net>
2024-06-06 08:58:16 +02:00
Nico
aec59be3f5
refactor(mediaPlaybackSpeed): spread all tooltip props
Co-authored-by: vee <vendicated@riseup.net>
2024-06-06 08:57:35 +02:00
Nico
065575718d
refactor(mediaPlaybackSpeed): prefix nav id with vc
Co-authored-by: vee <vendicated@riseup.net>
2024-06-06 08:57:15 +02:00
vee
3fb8e433e9
Merge branch 'dev' into plugin/audioPlaybackSpeed 2024-06-06 01:03:24 +02:00
D3SOX
b4e71fe412
feat(mediaPlaybackSpeed): add tooltip 2024-06-03 02:55:18 +02:00
D3SOX
7708172b12
Merge branch 'refs/heads/dev' into plugin/audioPlaybackSpeed 2024-06-02 15:57:22 +02:00
D3SOX
19896ef59e
refactor(audioPlaybackSpeed): rename to MediaPlaybackSpeed
I was about to add support for videos but then I noticed it already works xD
2024-06-02 14:42:43 +02:00
Nuckyz
6e6ee4db68
NoPendingCount: Fix for message requests 2024-06-01 23:40:05 -03:00
Nuckyz
d8524b087c
Add shortcut for lazy loading chunks 2024-06-01 18:39:01 -03:00
Vendicated
78fd37a4c6
fix(css): brand-experiment is now brand-500 2024-06-01 19:13:27 +02:00
Nico
64d519b54d
chore(audioPlaybackSpeed): fix formatting 2024-06-01 18:19:56 +02:00
D3SOX
8846d70247
fix(audioPlaybackSpeed): copy hover color behavior 2024-06-01 18:18:16 +02:00
Nico
5347356634
fix(audioPlaybackSpeed): make compatible with VoiceDownload 2024-06-01 17:14:38 +02:00
D3SOX
28767d97f4
chore(audioPlaybackSpeed): remove obsolete style 2024-06-01 16:56:26 +02:00
D3SOX
c9b29127c9
feat(audioPlaybackSpeed): add new plugin 2024-06-01 16:53:39 +02:00
10 changed files with 233 additions and 127 deletions

View file

@ -120,7 +120,7 @@ const settings = definePluginSettings({
stateString: { stateString: {
type: OptionType.STRING, type: OptionType.STRING,
description: "Activity state format string", description: "Activity state format string",
default: "{artist}" default: "{artist} · {album}"
}, },
largeImageType: { largeImageType: {
type: OptionType.SELECT, type: OptionType.SELECT,

View file

@ -11,37 +11,11 @@ import type { TrackData } from ".";
const exec = promisify(execFile); const exec = promisify(execFile);
// function exec(file: string, args: string[] = []) {
// return new Promise<{ code: number | null, stdout: string | null, stderr: string | null; }>((resolve, reject) => {
// const process = spawn(file, args, { stdio: [null, "pipe", "pipe"] });
// let stdout: string | null = null;
// process.stdout.on("data", (chunk: string) => { stdout ??= ""; stdout += chunk; });
// let stderr: string | null = null;
// process.stderr.on("data", (chunk: string) => { stdout ??= ""; stderr += chunk; });
// process.on("exit", code => { resolve({ code, stdout, stderr }); });
// process.on("error", err => reject(err));
// });
// }
async function applescript(cmds: string[]) { async function applescript(cmds: string[]) {
const { stdout } = await exec("osascript", cmds.map(c => ["-e", c]).flat()); const { stdout } = await exec("osascript", cmds.map(c => ["-e", c]).flat());
return stdout; return stdout;
} }
function makeSearchUrl(type: string, query: string) {
const url = new URL("https://tools.applemediaservices.com/api/apple-media/music/US/search.json");
url.searchParams.set("types", type);
url.searchParams.set("limit", "1");
url.searchParams.set("term", query);
return url;
}
const requestOptions: RequestInit = {
headers: { "user-agent": "Mozilla/5.0 (Windows NT 10.0; rv:125.0) Gecko/20100101 Firefox/125.0" },
};
interface RemoteData { interface RemoteData {
appleMusicLink?: string, appleMusicLink?: string,
songLink?: string, songLink?: string,
@ -51,6 +25,24 @@ interface RemoteData {
let cachedRemoteData: { id: string, data: RemoteData; } | { id: string, failures: number; } | null = null; let cachedRemoteData: { id: string, data: RemoteData; } | { id: string, failures: number; } | null = null;
const APPLE_MUSIC_BUNDLE_REGEX = /<script type="module" crossorigin src="([a-zA-Z0-9.\-/]+)"><\/script>/;
const APPLE_MUSIC_TOKEN_REGEX = /\w+="([A-Za-z0-9-_]*\.[A-Za-z0-9-_]*\.[A-Za-z0-9-_]*)",\w+="x-apple-jingle-correlation-key"/;
let cachedToken: string | undefined = undefined;
const getToken = async () => {
if (cachedToken) return cachedToken;
const html = await fetch("https://music.apple.com/").then(r => r.text());
const bundleUrl = new URL(html.match(APPLE_MUSIC_BUNDLE_REGEX)![1], "https://music.apple.com/");
const bundle = await fetch(bundleUrl).then(r => r.text());
const token = bundle.match(APPLE_MUSIC_TOKEN_REGEX)![1];
cachedToken = token;
return token;
};
async function fetchRemoteData({ id, name, artist, album }: { id: string, name: string, artist: string, album: string; }) { async function fetchRemoteData({ id, name, artist, album }: { id: string, name: string, artist: string, album: string; }) {
if (id === cachedRemoteData?.id) { if (id === cachedRemoteData?.id) {
if ("data" in cachedRemoteData) return cachedRemoteData.data; if ("data" in cachedRemoteData) return cachedRemoteData.data;
@ -58,21 +50,39 @@ async function fetchRemoteData({ id, name, artist, album }: { id: string, name:
} }
try { try {
const [songData, artistData] = await Promise.all([ const dataUrl = new URL("https://amp-api-edge.music.apple.com/v1/catalog/us/search");
fetch(makeSearchUrl("songs", artist + " " + album + " " + name), requestOptions).then(r => r.json()), dataUrl.searchParams.set("platform", "web");
fetch(makeSearchUrl("artists", artist.split(/ *[,&] */)[0]), requestOptions).then(r => r.json()) dataUrl.searchParams.set("l", "en-US");
]); dataUrl.searchParams.set("limit", "1");
dataUrl.searchParams.set("with", "serverBubbles");
dataUrl.searchParams.set("types", "songs");
dataUrl.searchParams.set("term", `${name} ${artist} ${album}`);
dataUrl.searchParams.set("include[songs]", "artists");
const appleMusicLink = songData?.songs?.data[0]?.attributes.url; const token = await getToken();
const songLink = songData?.songs?.data[0]?.id ? `https://song.link/i/${songData?.songs?.data[0]?.id}` : undefined;
const albumArtwork = songData?.songs?.data[0]?.attributes.artwork.url.replace("{w}", "512").replace("{h}", "512"); const songData = await fetch(dataUrl, {
const artistArtwork = artistData?.artists?.data[0]?.attributes.artwork.url.replace("{w}", "512").replace("{h}", "512"); headers: {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9",
"authorization": `Bearer ${token}`,
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
"origin": "https://music.apple.com",
},
})
.then(r => r.json())
.then(data => data.results.song.data[0]);
cachedRemoteData = { cachedRemoteData = {
id, id,
data: { appleMusicLink, songLink, albumArtwork, artistArtwork } data: {
appleMusicLink: songData.attributes.url,
songLink: `https://song.link/i/${songData.id}`,
albumArtwork: songData.attributes.artwork.url.replace("{w}x{h}", "512x512"),
artistArtwork: songData.relationships.artists.data[0].attributes.artwork.url.replace("{w}x{h}", "512x512"),
}
}; };
return cachedRemoteData.data; return cachedRemoteData.data;
} catch (e) { } catch (e) {
console.error("[AppleMusicRichPresence] Failed to fetch remote data:", e); console.error("[AppleMusicRichPresence] Failed to fetch remote data:", e);

View file

@ -0,0 +1,5 @@
# MediaPlaybackSpeed
Allows changing the (default) playback speed of media embeds
![New icon with menu to change the playback speed](https://github.com/Vendicated/Vencord/assets/24937357/21792b09-8d6a-45be-a6e8-916cdd67a477)

View file

@ -0,0 +1,19 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
export default function SpeedIcon() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
fill="currentColor"
viewBox="0 -960 960 960"
>
<path d="M418-340q24 24 62 23.5t56-27.5l224-336-336 224q-27 18-28.5 55t22.5 61zm62-460q59 0 113.5 16.5T696-734l-76 48q-33-17-68.5-25.5T480-720q-133 0-226.5 93.5T160-400q0 42 11.5 83t32.5 77h552q23-38 33.5-79t10.5-85q0-36-8.5-70T766-540l48-76q30 47 47.5 100T880-406q1 57-13 109t-41 99q-11 18-30 28t-40 10H204q-21 0-40-10t-30-28q-26-45-40-95.5T80-400q0-83 31.5-155.5t86-127Q252-737 325-768.5T480-800zm7 313z"></path>
</svg>
);
}

View file

@ -0,0 +1,151 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import "./styles.css";
import { definePluginSettings } from "@api/Settings";
import { classNameFactory } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary";
import { makeRange } from "@components/PluginSettings/components";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { ContextMenuApi, FluxDispatcher, Heading, Menu, React, Tooltip, useEffect } from "@webpack/common";
import { RefObject } from "react";
import SpeedIcon from "./components/SpeedIcon";
const cl = classNameFactory("vc-media-playback-speed-");
const min = 0.25;
const max = 3.5;
const speeds = makeRange(min, max, 0.25);
const settings = definePluginSettings({
test: {
type: OptionType.COMPONENT,
description: "",
component() {
return <Heading variant="heading-lg/bold" selectable={false}>
Default playback speeds
</Heading>;
}
},
defaultVoiceMessageSpeed: {
type: OptionType.SLIDER,
default: 1,
description: "Voice messages",
markers: speeds,
},
defaultVideoSpeed: {
type: OptionType.SLIDER,
default: 1,
description: "Videos",
markers: speeds,
},
defaultAudioSpeed: {
type: OptionType.SLIDER,
default: 1,
description: "Audios",
markers: speeds,
},
});
type MediaRef = RefObject<HTMLMediaElement> | undefined;
export default definePlugin({
name: "MediaPlaybackSpeed",
description: "Allows changing the (default) playback speed of media embeds",
authors: [Devs.D3SOX],
settings,
PlaybackSpeedComponent({ mediaRef }: { mediaRef: MediaRef }) {
const changeSpeed = (speed: number) => {
const media = mediaRef?.current;
if (media) {
media.playbackRate = speed;
}
};
useEffect(() => {
if (!mediaRef?.current) return;
const media = mediaRef.current;
if (media.tagName === "AUDIO") {
const isVoiceMessage = media.className.includes("audioElement_");
changeSpeed(isVoiceMessage ? settings.store.defaultVoiceMessageSpeed : settings.store.defaultAudioSpeed);
} else if (media.tagName === "VIDEO") {
changeSpeed(settings.store.defaultVideoSpeed);
}
}, [mediaRef]);
return (
<Tooltip text="Playback speed">
{tooltipProps => (
<button
{...tooltipProps}
className={cl("icon")}
onClick={e => {
ContextMenuApi.openContextMenu(e, () =>
<Menu.Menu
navId="vc-playback-speed"
onClose={() => FluxDispatcher.dispatch({ type: "CONTEXT_MENU_CLOSE" })}
aria-label="Playback speed control"
>
<Menu.MenuGroup
label="Playback speed"
>
{speeds.map(speed => (
<Menu.MenuItem
key={speed}
id={"speed-" + speed}
label={`${speed}x`}
action={() => changeSpeed(speed)}
/>
))}
</Menu.MenuGroup>
</Menu.Menu>
);
}}>
<SpeedIcon/>
</button>
)}
</Tooltip>
);
},
renderComponent(mediaRef: MediaRef) {
return <ErrorBoundary noop>
<this.PlaybackSpeedComponent mediaRef={mediaRef} />
</ErrorBoundary>;
},
patches: [
// voice message embeds
{
find: "\"--:--\"",
replacement: {
match: /onVolumeShow:\i,onVolumeHide:\i\}\)(?<=useCallback\(\(\)=>\{let \i=(\i).current;.+?)/,
replace: "$&,$self.renderComponent($1)"
}
},
// audio & video embeds
{
// need to pass media ref via props to make it easily accessible from inside controls
find: "renderControls(){",
replacement: {
match: /onToggleMuted:this.toggleMuted,/,
replace: "$&mediaRef:this.mediaRef,"
}
},
{
find: "AUDIO:\"AUDIO\"",
replacement: {
match: /onVolumeHide:\i,iconClassName:\i.controlIcon,iconColor:"currentColor",sliderWrapperClassName:\i.volumeSliderWrapper\}\)\}\),/,
replace: "$&$self.renderComponent(this.props.mediaRef),"
}
}
]
});

View file

@ -0,0 +1,10 @@
.vc-media-playback-speed-icon {
background-color: transparent;
height: 100%;
z-index: 2;
color: var(--interactive-normal);
}
.vc-media-playback-speed-icon:hover {
color: var(--interactive-active);
}

View file

@ -33,7 +33,7 @@ interface URLReplacementRule {
// Do not forget to add protocols to the ALLOWED_PROTOCOLS constant // Do not forget to add protocols to the ALLOWED_PROTOCOLS constant
const UrlReplacementRules: Record<string, URLReplacementRule> = { const UrlReplacementRules: Record<string, URLReplacementRule> = {
spotify: { spotify: {
match: /^https:\/\/open\.spotify\.com\/(?:intl-[a-z]{2}\/)?(track|album|artist|playlist|user|episode)\/(.+)(?:\?.+?)?$/, match: /^https:\/\/open\.spotify\.com\/(?:intl-[a-z]{2}\/)?(track|album|artist|playlist|user|episode|prerelease)\/(.+)(?:\?.+?)?$/,
replace: (_, type, id) => `spotify://${type}/${id}`, replace: (_, type, id) => `spotify://${type}/${id}`,
description: "Open Spotify links in the Spotify app", description: "Open Spotify links in the Spotify app",
shortlinkMatch: /^https:\/\/spotify\.link\/.+$/, shortlinkMatch: /^https:\/\/spotify\.link\/.+$/,

View file

@ -1,5 +0,0 @@
# TimeBarAllActivities
Adds the Spotify time bar to all activities if they have start and end timestamps.
![](https://github.com/user-attachments/assets/9fbbe33c-8218-43c9-8b8d-f907a4e809fe)

View file

@ -1,84 +0,0 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findComponentByCodeLazy } from "@webpack";
import { RequiredDeep } from "type-fest";
interface Activity {
timestamps?: ActivityTimestamps;
}
interface ActivityTimestamps {
start?: string;
end?: string;
}
interface TimebarComponentProps {
activity: Activity;
}
const ActivityTimeBar = findComponentByCodeLazy<ActivityTimestamps>(".bar", ".progress", "(100*");
function isActivityTimestamped(activity: Activity): activity is RequiredDeep<Activity> {
return activity.timestamps != null && activity.timestamps.start != null && activity.timestamps.end != null;
}
export const settings = definePluginSettings({
hideActivityDetailText: {
type: OptionType.BOOLEAN,
description: "Hide the large title text next to the activity",
default: true,
},
hideActivityTimerBadges: {
type: OptionType.BOOLEAN,
description: "Hide the timer badges next to the activity",
default: true,
}
});
export default definePlugin({
name: "TimeBarAllActivities",
description: "Adds the Spotify time bar to all activities if they have start and end timestamps",
authors: [Devs.fawn, Devs.niko],
settings,
patches: [
{
find: ".gameState,children:",
replacement: [
// Insert Spotify time bar component
{
match: /\(0,.{0,30}activity:(\i),className:\i\.badges\}\)/g,
replace: "$&,$self.TimebarComponent({activity:$1})"
},
// Hide the large title on listening activities, to make them look more like Spotify (also visible from hovering over the large icon)
{
match: /(\i).type===(\i\.\i)\.WATCHING/,
replace: "($self.settings.store.hideActivityDetailText&&$self.isActivityTimestamped($1)&&$1.type===$2.LISTENING)||$&"
}
]
},
// Hide the "badge" timers that count the time since the activity starts
{
find: ".TvIcon).otherwise",
replacement: {
match: /null!==\(\i=null===\(\i=(\i)\.timestamps\).{0,50}created_at/,
replace: "($self.settings.store.hideActivityTimerBadges&&$self.isActivityTimestamped($1))?null:$&"
}
}
],
isActivityTimestamped,
TimebarComponent: ErrorBoundary.wrap(({ activity }: TimebarComponentProps) => {
if (!isActivityTimestamped(activity)) return null;
return <ActivityTimeBar start={activity.timestamps.start} end={activity.timestamps.end} />;
}, { noop: true })
});

View file

@ -268,7 +268,7 @@ export const Devs = /* #__PURE__*/ Object.freeze({
id: 841509053422632990n id: 841509053422632990n
}, },
F53: { F53: {
name: "F53", name: "Cassie (Code)",
id: 280411966126948353n id: 280411966126948353n
}, },
AutumnVN: { AutumnVN: {