Advertisement
Guest User

Untitled

a guest
Mar 20th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.57 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. check_newgrounds() {
  3.     online_page=$(curl -s "$line") || return 1;
  4.     online_latest=$(grep -o '<meta property="og:description" content="Latest: '.* <<< "$online_page" | sed 's|<meta property="og:description" content="Latest: '\''||; s|'\''" />.*||;')
  5.     online_title=$(grep '<title>.*</title>' <<< "$online_page" | sed 's|.*<title>||; s|'\''s Movies</title>.*||')
  6. }
  7. check_youtube() {
  8.     online_page=$(curl -s "$line") || return 1;
  9.     online_latest=$(grep -o '"text":"'[^}]*'"}],"' <<< "$online_page" | sed 's|^"text":"||; s|"}],"$||' | head -n1)
  10.     online_title=$(grep -o "<title>.*</title>" <<< "$online_page" | sed 's|<title>||; s| - YouTube</title>||')
  11. }
  12. check_prawnhub() {
  13.     online_page=$(curl -s "$line") || return 1;
  14.     online_page_condensed=$(tr -d '\n' <<< "$online_page" | sed 's|\t| |g; s|  *| |g')
  15.     online_latest=$(sed 's|.*"profileContent"||; s|.*"channelsBody"||; s|data-related-url.*||; s|.*title="||; s|" class.*||' <<< "$online_page_condensed")
  16.     online_title=$(sed 's|.*<title>||; s|</title>.*|</title>|; s|Prawn Videos Uploaded by Prawnstar ||; s| &#124; Prawnhub</title>||; s|&#039;s Videos$||' <<< "$online_page_condensed")
  17. }
  18. remove_old_entry() {
  19.     lineno=$(grep -n "$line" "$cachefile"|sed 's|:.*$||')
  20.     sed -i "$lineno"'d' "$cachefile"
  21. }
  22. add_entry() {
  23.     echo "$line|$online_latest|$today" >> "$cachefile"
  24.     online_date="NEW!"
  25. }
  26.  
  27. cachefile="channels_cache.txt"
  28. [[ ! -f "$cachefile" ]] && touch "$cachefile"
  29. today=$(date +%d-%m-%Y)
  30. printf "%-15.15s %-15.15s %-75.75s\n" "[Author]" "[Updated]" "[Latest video]"
  31. while read line; do
  32.  
  33.     # Get online version
  34.     online_date="$today"
  35.     if [[ "$line" == *"newgrounds.com"* ]]; then check_newgrounds;
  36.     elif [[ "$line" == *"youtube.com"* ]]; then check_youtube;
  37.     elif [[ "$line" == *"prawnhub.com"* ]]; then check_prawnhub;
  38.     else
  39.         printf "%s\n" "$line";
  40.         continue;
  41.     fi
  42.  
  43.     if [ "$?" = "1" ]; then
  44.         printf "%-15.15s %-15.15s %-75.75s\n" "ERROR" "n/a" "Page could not be reached: $line"
  45.         continue
  46.     fi
  47.  
  48.     # Compare against local txt file
  49.     if cached_page=$(grep "$line" "$cachefile"); then
  50.         cache_date=$(cut -d\| -f3 <<< "$cached_page")
  51.         cache_latest=$(cut -d\| -f2 <<< "$cached_page")
  52.         if [[ "$cache_latest" = "$online_latest" ]]; then
  53.             online_date="$cache_date"
  54.         else
  55.             remove_old_entry
  56.             add_entry
  57.         fi
  58.     else
  59.         add_entry
  60.     fi
  61.  
  62.     printf "%-15.15s %-15.15s %-75.75s\n" "$online_title" "$online_date" "$online_latest"
  63. done < "channels.txt"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement