Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple script to fetch Libsyn podcast download totals and display them in Panic's Status Board app.
<?php
$graph_title = 'Downloads By Episode';
$libsyn_show_id = 12345; // Find this in the various URLs in your control panel
$libsyn_credentials = array(
'email' => 'your@email.com',
'password' => 'your libsyn password'
);
$most_recent_episodes_to_include = 5;
function csv_with_headers_to_array($csv_str)
{
$lines = explode("\n", $csv_str);
$headers = array_shift($lines);
$headers = str_getcsv($headers);
$rows = array();
foreach ($lines as $line) {
$row = array();
foreach (str_getcsv($line) as $n => $field) {
$row[$headers[$n]] = $field;
}
$rows[] = $row;
}
return $rows;
}
shell_exec("curl -s -c /tmp/libsyn-stats-cookie -d " . escapeshellarg(http_build_query($libsyn_credentials)) . " 'https://three.libsyn.com/auth/login'");
$csv = shell_exec("curl -s -b /tmp/libsyn-stats-cookie 'https://three.libsyn.com/lite/statistics/export/show_id/" . $libsyn_show_id . "/type/three-month/target/show/id/" . $libsyn_show_id . "'");
$rows = csv_with_headers_to_array($csv);
$downloads = array();
foreach ($rows as $row) {
// Label each series point with the episode number (first number found in title/filename)
if (preg_match('/[0-9]+/', $row['item_title'], $m)) $episode_number = intval($m[0]);
else $episode_number = $row['item_title'];
$downloads[$episode_number] = intval($row['downloads__total']);
}
ksort($downloads);
$downloads = array_slice($downloads, 0 - $most_recent_episodes_to_include, NULL, true);
$datapoints = array();
foreach ($downloads as $episode_label => $download_count) {
$datapoints[] = array('title' => (string) $episode_label, 'value' => $download_count);
}
header('Content-Type: application/json');
echo json_encode(array(
'graph' => array(
'title' => '',
'type' => 'bar',
'datasequences' => array(
array(
'title' => $graph_title,
'datapoints' => $datapoints
)
)
)
));
@stevepvc

This comment has been minimized.

Copy link

commented Dec 9, 2015

Hey, is there any version of this that works with libsyn 4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.