mirror of
https://github.com/maciejpedzich/playlist-entry-validator.git
synced 2024-11-28 00:15:48 +01:00
Extract playlist's author from dedicated user page
This commit is contained in:
parent
576eaa6fc6
commit
b39372fede
46
appFn.ts
46
appFn.ts
@ -74,7 +74,7 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
|
|||||||
if (filesToVerify.length === 0) return;
|
if (filesToVerify.length === 0) return;
|
||||||
|
|
||||||
const playlistSearchResults = await throttleAll(
|
const playlistSearchResults = await throttleAll(
|
||||||
3,
|
1,
|
||||||
filesToVerify.map(({ filename }) => async () => {
|
filesToVerify.map(({ filename }) => async () => {
|
||||||
const filenameWithoutRegistryPath = removeRegistryPathFromFilename(
|
const filenameWithoutRegistryPath = removeRegistryPathFromFilename(
|
||||||
filename
|
filename
|
||||||
@ -89,7 +89,7 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
|
|||||||
|
|
||||||
if (!expectedStatusCodes.includes(spotifyResponse.status))
|
if (!expectedStatusCodes.includes(spotifyResponse.status))
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Spotify responded with a ${spotifyResponse.status} status code`
|
`Received ${spotifyResponse.status} status code from playlist page response`
|
||||||
);
|
);
|
||||||
|
|
||||||
const found = spotifyResponse.status === 200;
|
const found = spotifyResponse.status === 200;
|
||||||
@ -97,18 +97,48 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
|
|||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
const html = await spotifyResponse.text();
|
const html = await spotifyResponse.text();
|
||||||
const { title, description } = await getMetaData({ html });
|
const {
|
||||||
|
title,
|
||||||
|
author: authorUrl,
|
||||||
|
description
|
||||||
|
} = await getMetaData({
|
||||||
|
html,
|
||||||
|
customRules: {
|
||||||
|
author: {
|
||||||
|
rules: [
|
||||||
|
[
|
||||||
|
'meta[name="music:creator"]',
|
||||||
|
(e) => e.getAttribute('content')
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const author = title?.endsWith('Spotify Playlist')
|
let authorName = (authorUrl as string).endsWith('/user/spotify')
|
||||||
? 'Spotify'
|
? 'Spotify'
|
||||||
: title?.match(/(?<=\- playlist by )(.*?)(?= \|)/gm) ?? [
|
: '';
|
||||||
'FAILED TO EXTRACT AUTHOR'
|
|
||||||
];
|
if (authorName === '') {
|
||||||
|
const playlistAuthorResponse = await fetch(authorUrl as string);
|
||||||
|
|
||||||
|
if (!playlistAuthorResponse.ok)
|
||||||
|
throw new Error(
|
||||||
|
`Received ${playlistAuthorResponse.status} status code from author page response`
|
||||||
|
);
|
||||||
|
|
||||||
|
const authorPageHtml = await playlistAuthorResponse.text();
|
||||||
|
const { title: authorPageTitle } = await getMetaData({
|
||||||
|
html: authorPageHtml
|
||||||
|
});
|
||||||
|
|
||||||
|
authorName = authorPageTitle as string;
|
||||||
|
}
|
||||||
|
|
||||||
const playlistMeta = (description || '')
|
const playlistMeta = (description || '')
|
||||||
.split(' · ')
|
.split(' · ')
|
||||||
.filter((text) => text !== 'Playlist')
|
.filter((text) => text !== 'Playlist')
|
||||||
.concat(author);
|
.concat(authorName as string);
|
||||||
|
|
||||||
details = playlistMeta.join(' · ');
|
details = playlistMeta.join(' · ');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user