ytpsort error handling and install script update

This commit is contained in:
Sangeeth Sudheer 2024-07-08 17:26:13 +05:30
parent 26133bf873
commit ca7369822d
Signed by: x
GPG Key ID: F6D06ECE734C57D1
2 changed files with 14 additions and 2 deletions

View File

@ -1,3 +1,9 @@
#/bin/sh #/bin/sh
ln -s "$PWD/ytpsort.mjs" ~/.local/bin/ytpsort scripts_dir="$HOME/.local/bin"
mkdir -p "$scripts_dir"
ln -s "$PWD/ytpsort.mjs" "$scripts_dir/ytpsort"
echo "Linked all scripts. Ensure $scripts_dir is in your \$PATH."

View File

@ -50,7 +50,13 @@ const body = await fetch("https://www.youtube.com/youtubei/v1/browse?prettyPrint
}) })
}).then(res => res.json()) }).then(res => res.json())
const rawPlaylistItems = body.contents.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].playlistVideoListRenderer.contents; let rawPlaylistItems = null;
try {
rawPlaylistItems = body.contents.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].playlistVideoListRenderer.contents;
} catch {
console.error("Error accessing JSON response fields: YT response possibly changed?");
process.exit(1);
}
const viewsRegex = /by .* ((?:\d+,?)+) views .*ago/; const viewsRegex = /by .* ((?:\d+,?)+) views .*ago/;