Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mousai embed size #363

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("EmbedUrlParserService", () => {
album: `album/1000/artist-name/album-name`,
playlist: `playlist/1000/playlist-name`,
track: `track/1000/track-name`,
trackContainingNumberSign: `track/1000/track-#6`,
};
const createValidMousaiURLFromPath = (path: string) => [
`https://mousai.stream/${path}`,
Expand All @@ -46,11 +47,13 @@ describe("EmbedUrlParserService", () => {
...createValidMousaiURLFromPath(mousaiPaths.album),
...createValidMousaiURLFromPath(mousaiPaths.playlist),
...createValidMousaiURLFromPath(mousaiPaths.track),
...createValidMousaiURLFromPath(mousaiPaths.trackContainingNumberSign),
];
const validMousaiEmbedURLs = [
`https://mousai.stream/${mousaiPaths.album}/embed`,
`https://mousai.stream/${mousaiPaths.playlist}/embed`,
`https://mousai.stream/${mousaiPaths.track}/embed`,
`https://mousai.stream/${mousaiPaths.trackContainingNumberSign}/embed`,
];

const vimeoVideoID = "310195153";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ export class EmbedUrlParserService {
}

static mousaiParser(url): string | boolean {
const regExp = /^.*mousai\.stream\/((album|playlist|track)\/[0-9]+(\/[a-z0-9-_,]+){1,2}?)(?=(\/embed|$))/;
const regExp = /^.*mousai\.stream\/((album|playlist|track)\/[0-9]+(\/[a-z0-9-_,#%]+){1,2}?)(?=(\/embed|$))/;
const match = url.match(regExp);
return match ? match[1] : false;
}

static constructMousaiEmbedURL(url: URL): string {
const mousaiPath = this.mousaiParser(url.toString());
return mousaiPath ? `https://mousai.stream/${mousaiPath}/embed` : "";
return typeof mousaiPath === "string"
? `https://mousai.stream/${mousaiPath
.split("/")
.map((s) => encodeURIComponent(s))
.join("/")}/embed`
: "";
}

// Vimeo video URLs are simple -- anything after the last "/" in the url indicates the videoID.
Expand Down Expand Up @@ -347,7 +352,7 @@ export class EmbedUrlParserService {
}

static isValidMousaiEmbedURL(link: string): boolean {
const regExp = /https:\/\/mousai\.stream\/((album|playlist|track)\/[0-9]+(\/[a-z0-9-_,]+){1,2}?)\/embed$/;
const regExp = /https:\/\/mousai\.stream\/((album|playlist|track)\/[0-9]+(\/[a-z0-9-_,%]+){1,2}?)\/embed$/;
return !!link.match(regExp);
}

Expand Down Expand Up @@ -411,7 +416,7 @@ export class EmbedUrlParserService {
return link.indexOf("/sets/") > -1 ? 350 : 180;
}
if (this.isValidMousaiEmbedURL(link)) {
return 165;
return 380;
}
return 315;
}
Expand Down