From 0feb10ba0fcece22105bfe80bb3c412b7db3a05a Mon Sep 17 00:00:00 2001 From: Christian Pierre MOMON Date: Wed, 10 Apr 2019 22:49:25 +0200 Subject: [PATCH] Added script to get statistics from https://cause-commune.fm/ website. --- ccfmstat/ccfmstat.sh | 141 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100755 ccfmstat/ccfmstat.sh diff --git a/ccfmstat/ccfmstat.sh b/ccfmstat/ccfmstat.sh new file mode 100755 index 0000000..812d0c8 --- /dev/null +++ b/ccfmstat/ccfmstat.sh @@ -0,0 +1,141 @@ +#!/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." +} + +# ############################################ +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" + + #

Total listens: 109

Total listeners: 92

Listening sources:

  • iTunes: 7
  • Overcast: 1
  • Direct download: 9
  • Played in new window: 6
  • Audio player: 23
  • Podcast Addict: 44
  • Player FM: 44
  • Other: 63

See more detail »

+ + local pageUrl="https://cause-commune.fm/wp-admin/post.php?post=$id&action=edit" + local pageFile="$tmpPrefix-pageid$id" + curl -s -b "$cookieFile" "$pageUrl" | grep "Total listens: " > "$pageFile" + + line=$(<"$pageFile") + #echo "TRACE $line\n" + + if [ -f "$pageFile" ]; then + rm -f "$pageFile" + fi + + 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 playerFM=$(extractValue "$line" "Player FM") + local other=$(extractValue "$line" "Other") + + echo -e "$id\t$totalListens\t$totalListeners\t$iTunes\t$pocketCasts\t$overcast\t$directDownload\t$playedInNewWindow\t$audioPlayer\t$podcastAddict\t$playerFM\t$other\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&author=5" + idsFile="$tmpPrefix-listmiens" + + curl -s -b "$cookieFile" "$pageUrl" | grep row-title > "$idsFile" + + # Wikipédia – chronique « Partager est bon » sur écoles et logiciels libres + + + echo -e "id\ttotalListens\ttotalListeners\tiTunes\tpocketcasts\tovercast\tdirectDownload\tplayedInNewWindow\taudioPlayer\tpodcastAddict\tplayerFM\tother\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" + + if [ -f "$cookieFile" ]; then + rm -f "$cookieFile" + fi + + if [ -f "$idsFile" ]; then + rm -f "$idsFile" + 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" +fi