Merge pull request #154563 from schnusch/mpv_sponsorblock

This commit is contained in:
legendofmiracles 2022-01-12 20:54:49 -06:00 committed by GitHub
commit 38ec35cef2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 5 deletions

View file

@ -3,13 +3,13 @@
# Usage: `pkgs.mpv.override { scripts = [ pkgs.mpvScripts.sponsorblock ]; }`
stdenvNoCC.mkDerivation {
pname = "mpv_sponsorblock";
version = "unstable-2020-07-05";
version = "unstable-2021-12-23";
src = fetchFromGitHub {
owner = "po5";
repo = "mpv_sponsorblock";
rev = "f71e49e0531350339134502e095721fdc66eac20";
sha256 = "1fr4cagzs26ygxyk8dxqvjw4n85fzv6is6cb1jhr2qnsjg6pa0p8";
rev = "6743bd47d4cfce3ae3d5dd4f587f3193bd4fb9b2";
sha256 = "06c37f33cdpz1w1jacjf1wnbh4f9b1xpipxzkg5ixf46cbwssmsj";
};
dontBuild = true;
@ -39,10 +39,13 @@ stdenvNoCC.mkDerivation {
cp -r sponsorblock.lua sponsorblock_shared $out/share/mpv/scripts/
'';
passthru.scriptName = "sponsorblock.lua";
passthru = {
scriptName = "sponsorblock.lua";
updateScript = ./update-sponsorblock.sh;
};
meta = with lib; {
description = "mpv script to skip sponsored segments of YouTube videos";
description = "Script for mpv to skip sponsored segments of YouTube videos";
homepage = "https://github.com/po5/mpv_sponsorblock";
license = licenses.gpl3;
platforms = platforms.all;

View file

@ -0,0 +1,49 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p common-updater-scripts git jq nix nix-prefetch-git
git_url='https://github.com/po5/mpv_sponsorblock.git'
git_branch='master'
git_dir='/var/tmp/mpv_sponsorblock.git'
nix_file="$(dirname "${BASH_SOURCE[0]}")/sponsorblock.nix"
pkg='mpvScripts.sponsorblock'
set -euo pipefail
info() {
if [ -t 2 ]; then
set -- '\033[32m%s\033[39m\n' "$@"
else
set -- '%s\n' "$@"
fi
printf "$@" >&2
}
old_rev=$(nix-instantiate --eval --strict --json -A "$pkg.src.rev" | jq -r)
old_version=$(nix-instantiate --eval --strict --json -A "$pkg.version" | jq -r)
today=$(LANG=C date -u +'%Y-%m-%d')
info "fetching $git_url..."
if [ ! -d "$git_dir" ]; then
git init --initial-branch="$git_branch" "$git_dir"
git -C "$git_dir" remote add origin "$git_url"
fi
git -C "$git_dir" fetch --depth=1 origin "$git_branch"
# use latest commit before today, we should not call the version *today*
# because there might still be commits coming
# use the day of the latest commit we picked as version
new_rev=$(git -C "$git_dir" log -n 1 --format='format:%H' --before="${today}T00:00:00Z" "origin/$git_branch")
new_version="unstable-$(git -C "$git_dir" log -n 1 --format='format:%cs' "$new_rev")"
info "latest commit before $today: $new_rev"
if [ "$new_rev" = "$old_rev" ]; then
info "$pkg is up-to-date."
exit
fi
new_sha256=$(nix-prefetch-git --rev "$new_rev" "$git_dir" | jq -r .sha256)
update-source-version "$pkg" \
"$new_version" \
"$new_sha256" \
--rev="$new_rev"
git add "$nix_file"
git commit --verbose --message "$pkg: $old_version -> $new_version"