Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- check_newgrounds() {
- online_page=$(curl -s "$line") || return 1;
- online_latest=$(grep -o '<meta property="og:description" content="Latest: '.* <<< "$online_page" | sed 's|<meta property="og:description" content="Latest: '\''||; s|'\''" />.*||;')
- online_title=$(grep '<title>.*</title>' <<< "$online_page" | sed 's|.*<title>||; s|'\''s Movies</title>.*||')
- }
- check_youtube() {
- online_page=$(curl -s "$line") || return 1;
- online_latest=$(grep -o '"text":"'[^}]*'"}],"' <<< "$online_page" | sed 's|^"text":"||; s|"}],"$||' | head -n1)
- online_title=$(grep -o "<title>.*</title>" <<< "$online_page" | sed 's|<title>||; s| - YouTube</title>||')
- }
- check_prawnhub() {
- online_page=$(curl -s "$line") || return 1;
- online_page_condensed=$(tr -d '\n' <<< "$online_page" | sed 's|\t| |g; s| *| |g')
- online_latest=$(sed 's|.*"profileContent"||; s|.*"channelsBody"||; s|data-related-url.*||; s|.*title="||; s|" class.*||' <<< "$online_page_condensed")
- online_title=$(sed 's|.*<title>||; s|</title>.*|</title>|; s|Prawn Videos Uploaded by Prawnstar ||; s| | Prawnhub</title>||; s|'s Videos$||' <<< "$online_page_condensed")
- }
- remove_old_entry() {
- lineno=$(grep -n "$line" "$cachefile"|sed 's|:.*$||')
- sed -i "$lineno"'d' "$cachefile"
- }
- add_entry() {
- echo "$line|$online_latest|$today" >> "$cachefile"
- online_date="NEW!"
- }
- cachefile="channels_cache.txt"
- [[ ! -f "$cachefile" ]] && touch "$cachefile"
- today=$(date +%d-%m-%Y)
- printf "%-15.15s %-15.15s %-75.75s\n" "[Author]" "[Updated]" "[Latest video]"
- while read line; do
- # Get online version
- online_date="$today"
- if [[ "$line" == *"newgrounds.com"* ]]; then check_newgrounds;
- elif [[ "$line" == *"youtube.com"* ]]; then check_youtube;
- elif [[ "$line" == *"prawnhub.com"* ]]; then check_prawnhub;
- else
- printf "%s\n" "$line";
- continue;
- fi
- if [ "$?" = "1" ]; then
- printf "%-15.15s %-15.15s %-75.75s\n" "ERROR" "n/a" "Page could not be reached: $line"
- continue
- fi
- # Compare against local txt file
- if cached_page=$(grep "$line" "$cachefile"); then
- cache_date=$(cut -d\| -f3 <<< "$cached_page")
- cache_latest=$(cut -d\| -f2 <<< "$cached_page")
- if [[ "$cache_latest" = "$online_latest" ]]; then
- online_date="$cache_date"
- else
- remove_old_entry
- add_entry
- fi
- else
- add_entry
- fi
- printf "%-15.15s %-15.15s %-75.75s\n" "$online_title" "$online_date" "$online_latest"
- done < "channels.txt"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement