add stuff :3

This commit is contained in:
ashley 2024-10-22 13:54:47 +00:00
parent 4827e9c626
commit e3b68cb658

View file

@ -17,11 +17,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Function to generate a random Chrome version
generate_random_chrome_version() {
major=$((RANDOM % 100 + 1)) # Major version 1-99
minor=$((RANDOM % 100)) # Minor version 0-99
build=$((RANDOM % 10000)) # Build version 0-9999
patch=$((RANDOM % 100)) # Patch version 0-99
minor=$((RANDOM % 100)) # Minor version 0-99
build=$((RANDOM % 10000)) # Build version 0-9999
patch=$((RANDOM % 100)) # Patch version 0-99
echo "$major.$minor.$build.$patch"
}
@ -30,23 +31,23 @@ restart_services() {
# Navigate to the script directory
scriptDir=$(dirname "$(readlink -f "$0")")
cd "$scriptDir/../services/invidious" || { echo "Error: Failed to navigate to $scriptDir/../services/invidious"; exit 1; }
docker compose down
echo "Services stopped. Restarting..."
docker compose up -d
echo "Services restarted successfully."
/home/qt/globe/scripts/inv-update-token.sh
/home/qt/globe/scripts/inv-update-token.sh
}
fetch_playlist() {
local playlist_id="$1"
response=$(curl -s -w "%{http_code}" -o /tmp/playlist_data.json "https://invid-api.poketube.fun/api/v1/playlists/${playlist_id}")
if [ "$response" -eq 502 ] || [ "$response" -eq 500 ]; then
if [ "$response" -eq 502 ] || [ "$response" -eq 500 ] || [ "$response" -eq 403 ]; then
echo "Error: Failed to fetch playlist data. HTTP Status: $response"
restart_services
return 1
@ -66,14 +67,17 @@ extract_video_ids() {
echo "$video_ids"
}
# Playlist IDs to fetch
playlist_ids=("PLMws9SCqJ1JCeVMVPsdamuUM0HK0MbA6g")
# Base URL for the API
base_url="http://localhost:54301/latest_version?id="
random_playlist_id=("PLMC9KNkIncKvYin_USF1qoJQnIyMAfRxl")
# Pick a random playlist (without using invalid options in shuf)
random_playlist_id="PLMC9KNkIncKvYin_USF1qoJQnIyMAfRxl"
echo "Randomly selected playlist: $random_playlist_id"
# Fetch playlist JSON data
fetch_playlist "$random_playlist_id"
if [ $? -ne 0 ]; then
echo "Error: Playlist fetch failed. Restarting services..."
@ -81,23 +85,25 @@ if [ $? -ne 0 ]; then
exit 1
fi
# Extract video IDs from the playlist
video_ids=($(extract_video_ids "/tmp/playlist_data.json"))
if [ $? -ne 0 ]; then
echo "Error: Failed to extract video IDs. Exiting..."
exit 1
fi
# Shuffle video IDs and pick 4 random videos
shuffled_video_ids=($(shuf -e "${video_ids[@]}" | head -n 4))
error_count=0
all_errors=(500 502)
all_errors=(500 502 403)
# Loop through the selected random videos and check for errors
for video_id in "${shuffled_video_ids[@]}"; do
# Add a cache buster query (unique random number)
unique_param=$RANDOM
url="${base_url}${video_id}&itag=18&local=true&_=${unique_param}"
# Generate a random Chrome version
chrome_version=$(generate_random_chrome_version)
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/$chrome_version Safari/537.36"
@ -117,6 +123,7 @@ for video_id in "${shuffled_video_ids[@]}"; do
status_code=$(curl -s -o /dev/null -w "%{http_code}" -A "$user_agent" "$url")
fi
# Echo the status code for visibility
echo "Checking URL: $url"
echo "User Agent: $user_agent"
echo "HTTP Status Code for ID $video_id: $status_code"
@ -125,13 +132,17 @@ for video_id in "${shuffled_video_ids[@]}"; do
echo "Error: Received $status_code for ID $video_id."
error_count=$((error_count + 1))
# Run the token refresh script
echo "Running inv-update-token.sh for ID $video_id..."
/home/qt/globe/scripts/inv-update-token.sh
/home/qt/globe/scripts/inv-update-token.sh
echo "inv-update-token.sh script executed successfully."
# Fetch the video again after token refresh
status_code=$(curl -s -o /dev/null -w "%{http_code}" -A "$user_agent" "$url")
echo "Post-token-refresh Status Code for ID $video_id: $status_code"
# Check if it still results in 500/502/403 after refresh
if [[ " ${all_errors[@]} " =~ " ${status_code} " ]]; then
echo "Error: Received $status_code for ID $video_id after token refresh."
else
@ -140,12 +151,13 @@ for video_id in "${shuffled_video_ids[@]}"; do
elif [ "$status_code" -eq 304 ]; then
echo "Content is still fresh for ID $video_id. No action required."
else
echo "we are so barack (Status code for ID $video_id is neither 502 nor 500.)"
echo "we are so barack (Status code for ID $video_id is neither 502, 500, nor 403.)"
fi
echo "----------------------------------------" # Separator for readability
echo "----------------****************----------------" # Separator for readability
done
# If all videos still resulted in 500/502/403 errors even after running inv-update-token.sh, try restaring
if [ "$error_count" -eq "${#shuffled_video_ids[@]}" ]; then
echo "All videos failed to load after running inv-update-token.sh. Restarting services..."
restart_services