diff --git a/ccfmstat/ccfmstat.sh b/ccfmstat/ccfmstat.sh index 812d0c8..76f3212 100755 --- a/ccfmstat/ccfmstat.sh +++ b/ccfmstat/ccfmstat.sh @@ -19,7 +19,7 @@ # Configuration. login="april-cc" -tmpPrefix="/tmp/ccfmstat-" +tmpPrefix="/tmp/ccfmstat" # ############################################ help() @@ -54,19 +54,18 @@ getInfoFromId() local title="$2" local cookieFile="$3" - #

Total listens: 109

Total listeners: 92

Listening sources:

See more detail »

- + # 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" | grep "Total listens: " > "$pageFile" + local pageFile="${tmpPrefix}-pageid$id" + curl -s -b "$cookieFile" "$pageUrl" > "$pageFile" - line=$(<"$pageFile") + # Extract file infos. + local pageInfoFile="${tmpPrefix}-pageinfoid$id" + grep "Total listens: " "$pageFile" > "$pageInfoFile" + line=$(<"$pageInfoFile") #echo "TRACE $line\n" - if [ -f "$pageFile" ]; then - rm -f "$pageFile" - fi - + #

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") @@ -79,7 +78,22 @@ getInfoFromId() 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" + + # 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$playerFM\t$other\t$recordedDate\t$title" } # ############################################ @@ -90,19 +104,19 @@ run() # 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" + 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" + 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" + echo -e "id\ttotalListens\ttotalListeners\tiTunes\tpocketcasts\tovercast\tdirectDownload\tplayedInNewWindow\taudioPlayer\tpodcastAddict\tplayerFM\tother\trecordedDate\ttitle" while read line; do #echo $line @@ -115,14 +129,6 @@ run() getInfoFromId "$id" "$title" "$cookieFile" done < "$idsFile" - - if [ -f "$cookieFile" ]; then - rm -f "$cookieFile" - fi - - if [ -f "$idsFile" ]; then - rm -f "$idsFile" - fi } # ########################################### @@ -138,4 +144,11 @@ else pass="${pass//&/%26}" run "$pass" + + # Clean temporary files. + # Clean. + if [ -n "${tmpPrefix}" ]; then + ls "${tmpPrefix}-"* + rm -f "${tmpPrefix}-"* + fi fi