gen_includes.sh 721 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. # This required jq and wget
  3. DAY=$((60 * 60 * 24))
  4. # Remove instances.json when it's older then 1 day
  5. if [ -f "instances.json" ]; then
  6. NOW=$(date "+%s")
  7. THEN=$(date -r "instances.json" "+%s")
  8. DELTA=$((NOW - THEN))
  9. if [ $DELTA -gt $DAY ]; then
  10. echo "YES"
  11. rm "instances.json"
  12. fi
  13. fi
  14. # Get new instances.json
  15. if [ ! -f "instances.json" ]; then
  16. wget "https://api.invidious.io/instances.json"
  17. fi
  18. # Process
  19. while IFS= read -r line
  20. do
  21. URL="${line:1:-1}"
  22. echo "// @include https://$URL/channel/*"
  23. echo "// @include https://$URL/watch*"
  24. echo "// @include https://$URL/search*"
  25. echo "// @include https://$URL/feed/*"
  26. done <<< $(jq ".[][0]" instances.json | grep -v ".onion\|.i2p")