mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-27 04:58:13 +01:00
add stuff :3
This commit is contained in:
parent
4827e9c626
commit
e3b68cb658
1 changed files with 25 additions and 13 deletions
|
@ -17,11 +17,12 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# Function to generate a random Chrome version
|
||||||
generate_random_chrome_version() {
|
generate_random_chrome_version() {
|
||||||
major=$((RANDOM % 100 + 1)) # Major version 1-99
|
major=$((RANDOM % 100 + 1)) # Major version 1-99
|
||||||
minor=$((RANDOM % 100)) # Minor version 0-99
|
minor=$((RANDOM % 100)) # Minor version 0-99
|
||||||
build=$((RANDOM % 10000)) # Build version 0-9999
|
build=$((RANDOM % 10000)) # Build version 0-9999
|
||||||
patch=$((RANDOM % 100)) # Patch version 0-99
|
patch=$((RANDOM % 100)) # Patch version 0-99
|
||||||
echo "$major.$minor.$build.$patch"
|
echo "$major.$minor.$build.$patch"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,23 +31,23 @@ restart_services() {
|
||||||
|
|
||||||
# Navigate to the script directory
|
# Navigate to the script directory
|
||||||
scriptDir=$(dirname "$(readlink -f "$0")")
|
scriptDir=$(dirname "$(readlink -f "$0")")
|
||||||
|
|
||||||
|
|
||||||
cd "$scriptDir/../services/invidious" || { echo "Error: Failed to navigate to $scriptDir/../services/invidious"; exit 1; }
|
cd "$scriptDir/../services/invidious" || { echo "Error: Failed to navigate to $scriptDir/../services/invidious"; exit 1; }
|
||||||
|
|
||||||
docker compose down
|
docker compose down
|
||||||
echo "Services stopped. Restarting..."
|
echo "Services stopped. Restarting..."
|
||||||
|
|
||||||
|
docker compose up -d
|
||||||
echo "Services restarted successfully."
|
echo "Services restarted successfully."
|
||||||
|
|
||||||
/home/qt/globe/scripts/inv-update-token.sh
|
/home/qt/globe/scripts/inv-update-token.sh
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_playlist() {
|
fetch_playlist() {
|
||||||
local playlist_id="$1"
|
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}")
|
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"
|
echo "Error: Failed to fetch playlist data. HTTP Status: $response"
|
||||||
restart_services
|
restart_services
|
||||||
return 1
|
return 1
|
||||||
|
@ -66,14 +67,17 @@ extract_video_ids() {
|
||||||
echo "$video_ids"
|
echo "$video_ids"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Playlist IDs to fetch
|
||||||
playlist_ids=("PLMws9SCqJ1JCeVMVPsdamuUM0HK0MbA6g")
|
playlist_ids=("PLMws9SCqJ1JCeVMVPsdamuUM0HK0MbA6g")
|
||||||
|
|
||||||
# Base URL for the API
|
# Base URL for the API
|
||||||
base_url="http://localhost:54301/latest_version?id="
|
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"
|
echo "Randomly selected playlist: $random_playlist_id"
|
||||||
|
|
||||||
|
# Fetch playlist JSON data
|
||||||
fetch_playlist "$random_playlist_id"
|
fetch_playlist "$random_playlist_id"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Playlist fetch failed. Restarting services..."
|
echo "Error: Playlist fetch failed. Restarting services..."
|
||||||
|
@ -81,23 +85,25 @@ if [ $? -ne 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Extract video IDs from the playlist
|
||||||
video_ids=($(extract_video_ids "/tmp/playlist_data.json"))
|
video_ids=($(extract_video_ids "/tmp/playlist_data.json"))
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: Failed to extract video IDs. Exiting..."
|
echo "Error: Failed to extract video IDs. Exiting..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Shuffle video IDs and pick 4 random videos
|
||||||
shuffled_video_ids=($(shuf -e "${video_ids[@]}" | head -n 4))
|
shuffled_video_ids=($(shuf -e "${video_ids[@]}" | head -n 4))
|
||||||
|
|
||||||
error_count=0
|
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
|
for video_id in "${shuffled_video_ids[@]}"; do
|
||||||
# Add a cache buster query (unique random number)
|
# Add a cache buster query (unique random number)
|
||||||
unique_param=$RANDOM
|
unique_param=$RANDOM
|
||||||
url="${base_url}${video_id}&itag=18&local=true&_=${unique_param}"
|
url="${base_url}${video_id}&itag=18&local=true&_=${unique_param}"
|
||||||
|
|
||||||
|
# Generate a random Chrome version
|
||||||
chrome_version=$(generate_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"
|
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")
|
status_code=$(curl -s -o /dev/null -w "%{http_code}" -A "$user_agent" "$url")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Echo the status code for visibility
|
||||||
echo "Checking URL: $url"
|
echo "Checking URL: $url"
|
||||||
echo "User Agent: $user_agent"
|
echo "User Agent: $user_agent"
|
||||||
echo "HTTP Status Code for ID $video_id: $status_code"
|
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."
|
echo "Error: Received $status_code for ID $video_id."
|
||||||
error_count=$((error_count + 1))
|
error_count=$((error_count + 1))
|
||||||
|
|
||||||
|
# Run the token refresh script
|
||||||
echo "Running inv-update-token.sh for ID $video_id..."
|
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
|
||||||
|
/home/qt/globe/scripts/inv-update-token.sh
|
||||||
echo "inv-update-token.sh script executed successfully."
|
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")
|
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"
|
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
|
if [[ " ${all_errors[@]} " =~ " ${status_code} " ]]; then
|
||||||
echo "Error: Received $status_code for ID $video_id after token refresh."
|
echo "Error: Received $status_code for ID $video_id after token refresh."
|
||||||
else
|
else
|
||||||
|
@ -140,12 +151,13 @@ for video_id in "${shuffled_video_ids[@]}"; do
|
||||||
elif [ "$status_code" -eq 304 ]; then
|
elif [ "$status_code" -eq 304 ]; then
|
||||||
echo "Content is still fresh for ID $video_id. No action required."
|
echo "Content is still fresh for ID $video_id. No action required."
|
||||||
else
|
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
|
fi
|
||||||
|
|
||||||
echo "----------------------------------------" # Separator for readability
|
echo "----------------****************----------------" # Separator for readability
|
||||||
done
|
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
|
if [ "$error_count" -eq "${#shuffled_video_ids[@]}" ]; then
|
||||||
echo "All videos failed to load after running inv-update-token.sh. Restarting services..."
|
echo "All videos failed to load after running inv-update-token.sh. Restarting services..."
|
||||||
restart_services
|
restart_services
|
||||||
|
|
Loading…
Reference in a new issue