#!/bin/bash # # Copyright (C) 2019 Christian Pierre MOMON # # This file is part of ccfmstat from "April/Libre à vous !" # # This script is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # Configuration. login="april-cc" tmpPrefix="/tmp/ccfmstat" # ############################################ help() { echo "Usage:" echo " ccfmstat [ -h | -help | --help ]" echo "If no parameter set then password is requested." echo "Number of result per page has to be fixed un web GUI page." } # ############################################ extractValue() { local line="$1" local token="$2" local result= local regexp="$token: ([0-9]+)" if [[ $line =~ $regexp ]]; then result=${BASH_REMATCH[1]} else result= fi echo "$result" } # ############################################ getInfoFromId() { local id="$1" local title="$2" local cookieFile="$3" # Get web page with info about one audio record. local pageUrl="https://cause-commune.fm/wp-admin/post.php?post=$id&action=edit" local pageFile="${tmpPrefix}-pageid$id" curl -s -b "$cookieFile" "$pageUrl" > "$pageFile" # Extract file infos. local pageInfoFile="${tmpPrefix}-pageinfoid$id" grep "Total listens: " "$pageFile" > "$pageInfoFile" line=$(<"$pageInfoFile") #echo "TRACE $line\n" #

Total listens: 109

Total listeners: 92

Listening sources:

See more detail »

local totalListens=$(extractValue "$line" "Total listens") local totalListeners=$(extractValue "$line" "Total listeners") local iTunes=$(extractValue "$line" "iTunes") local pocketCasts=$(extractValue "$line" "Pocket Casts") local overcast=$(extractValue "$line" "Overcast") local directDownload=$(extractValue "$line" "Direct download") local playedInNewWindow=$(extractValue "$line" "Played in new window") local audioPlayer=$(extractValue "$line" "Audio player") local podcastAddict=$(extractValue "$line" "Podcast Addict") local androidApp=$(extractValue "$line" "Android App") local playerFM=$(extractValue "$line" "Player FM") local other=$(extractValue "$line" "Other") # Extract record date. local pageDateFile="${tmpPrefix}-pagedateid$id" grep " "$pageDateFile" line=$(<"$pageDateFile") #echo "TRACE $line\n" # local recordedDate if [[ $line =~ value=\"(.+)\" ]]; then recordedDate=${BASH_REMATCH[1]} else recordedDate= fi echo -e "$id\t$totalListens\t$totalListeners\t$iTunes\t$pocketCasts\t$overcast\t$directDownload\t$playedInNewWindow\t$audioPlayer\t$podcastAddict\t$androidApp\t$playerFM\t$other\t$recordedDate\t$title" } # ############################################ run() { local pass="$1" # Connect. local loginUrl="https://cause-commune.fm/wp-login.php" local redirect="https%3A%2F%2Fcause-commune.fm%2Fwp-admin%2F" local cookieFile="${tmpPrefix}-cookies.txt" curl -s -c "$cookieFile" -d "log=$login&pwd=$pass&rememberme=forever&wp-submit=Se%20connecter&redirect_to=$redirect&testcookie=1" "$loginUrl" > /dev/null # Get page "Les miens" data. pageUrl="https://cause-commune.fm/wp-admin/edit.php?post_type=podcast&series=libre-a-vous" idsFile="${tmpPrefix}-listmiens" curl -s -b "$cookieFile" "$pageUrl" | grep row-title > "$idsFile" if [ $? -eq 0 ]; then # Wikipédia – chronique « Partager est bon » sur écoles et logiciels libres echo -e "id\ttotalListens\ttotalListeners\tiTunes\tpocketcasts\tovercast\tdirectDownload\tplayedInNewWindow\taudioPlayer\tpodcastAddict\tAndroidApp\tplayerFM\tother\trecordedDate\ttitle" while read line; do #echo $line [[ $line =~ post=([0-9]+)\& ]] && id=${BASH_REMATCH[1]} #echo "TRACE id=$id" [[ $line =~ aria-label=\".+\"\>(.+)\ ]] && title=${BASH_REMATCH[1]} #echo "TRACE title=$title" getInfoFromId "$id" "$title" "$cookieFile" done < "$idsFile" else echo "Connexion error. Bad password?" fi } # ########################################### # MAIN # ########################################### if [ "$#" = 1 ] && ([ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]); then help else (>&2 echo "Password for $login account on https://cause-commune.fm/ website:") read -s pass # Encode as URL characters. pass="${pass//&/%26}" run "$pass" # Clean temporary files. # Clean. if [ -n "${tmpPrefix}" ]; then rm -f "${tmpPrefix}-"* fi fi