diff --git a/install.sh b/install.sh index b25b11b..0b70861 100755 --- a/install.sh +++ b/install.sh @@ -1,3 +1,9 @@ #/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." diff --git a/ytpsort.mjs b/ytpsort.mjs index 0e3e9c9..94bb108 100755 --- a/ytpsort.mjs +++ b/ytpsort.mjs @@ -50,7 +50,13 @@ const body = await fetch("https://www.youtube.com/youtubei/v1/browse?prettyPrint }) }).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/;