function refreshYouTubeStats() { global $database; include_once 'functions_cast.php'; include_once 'functions_youtube.php'; $youtubeids = array(); foreach (getCasts() as $cast) { $meta = getCastHeader($cast); if ($meta == false) { continue; } if ($meta['YOUTUBE'] == '') { continue; } array_push($youtubeids, $meta['YOUTUBE']); } $viewStats = getVideoViews($youtubeids); $storestats = $database->prepare("INSERT INTO youtubestats (videoid, count) VALUES (:videoid, :count)\n\t\tON DUPLICATE KEY UPDATE videoid=VALUES(videoid), count=VALUES(count);"); // DRUNK ON SQL - this fails if the key is missing q.q {trying to avoid updating if count !> stored count} // $storestats = $database->prepare( "INSERT INTO youtubestats (videoid, count) // SELECT :videoid, :count FROM youtubestats WHERE videoid=:videoid AND count < :count // ON DUPLICATE KEY UPDATE videoid=VALUES(videoid), count=VALUES(count);" ); try { $database->beginTransaction(); foreach ($viewStats as $video => $count) { $storestats->execute(array('videoid' => $video, 'count' => $count)); } $database->commit(); } catch (Exception $e) { return false; } return true; }
\t\t<div class="panel-body panel-body-table"> \t\t\t<table id="casts" class="table table-striped table-hover tablesorter"> \t\t\t\t<thead> \t\t\t\t\t<tr> \t\t\t\t\t\t<th class="col-sm-1">No. \t\t\t\t\t\t<th class="hidden-xxs">Recorded \t\t\t\t\t\t<th class="col-sm-4">Title \t\t\t\t\t\t<th class="col-xs-1">Rating \t\t\t\t\t\t<th class="col-sm-2">Hosts \t\t\t\t\t\t<th>Guests \t\t\t\t\t</tr> \t\t\t\t</thead> \t\t\t\t<tbody> CASTTABLE; foreach (getCasts() as $castdir) { $meta = getCastHeader($castdir); /* if published unset, skip this entry */ $wip = ""; if ($meta['PUBLISHED'] === '') { $meta['TITLE'] = 'Edit In Progress'; $wip = "class=\"in-progress\" "; } $meta['TITLE'] = slenc($meta['TITLE']); // we add a zero width space to allow this to wrap better on mobile $meta['RECORDED'] = preg_replace('/-/', '-', $meta['RECORDED'], 1); $rating = $meta['RATING'] == 'Explicit' ? '<i class="text-danger"> <abbr title="Explicit">E</abbr></i>' : ($meta['RATING'] == 'Clean' ? '<i class="text-success"> <abbr title="Clean">C</abbr></i>' : ($meta['RATING'] != '' ? '<i><abbr title="Tolerable">T</abbr></i>' : '')); $listHosts = ""; $listGuests = ""; foreach ($meta['HOSTS'] as $Host) { $listHosts .= nameplate($Host, 22); }
/** * Returns data similar to getCastHeader(), metadata about an episode, rather than the episode slug * if you need that reference, it is returned in the array as [ 'SLUG' ] * @return array a dictionary of metadata for this file, with all keys in uppercase */ function getLatestCast() { $latest = getCasts(true); if (!$latest) { return false; } return getCastHeader($latest); }
<?php header('Content-Type: text/html; charset=UTF-8'); include_once 'includes/functions_cast.php'; function slenc($u) { return htmlentities($u, ENT_QUOTES, "UTF-8"); } /* User wanting to see a specific cast, and shownotes file exists */ if ($season !== "00" && $episode !== "00" && ($meta = getCastHeader($slug))) { $shownotes = getCastBody($slug); $meta['RECORDED'] = $meta['RECORDED'] === '' ? "N/A" : $meta['RECORDED']; echo "{$meta['DESCRIPTION']}<br>\n<br>\n"; echo "Shownotes featuring full descriptions and links can be found at https://steamlug.org/cast/{$meta['SLUG']}<br>\n"; echo "This cast was recorded on {$meta['RECORDED']}<br>\n<br>\n"; foreach ($shownotes as $note) { preg_replace_callback('/(\\d+:\\d+:\\d+)\\s+\\*(.*)\\*/', function ($matches) { print slenc($matches[1]) . " " . slenc($matches[2]) . "<br>"; }, $note); } echo "<br>\nSteamLUG Cast is a casual, fortnightly audiocast which aims to provide interesting news and discussion for the SteamLUG and broader Linux gaming communities.<br>\n"; echo "Visit our site http://steamlug.org/ and the cast homepage http://steamlug.org/cast<br>\n"; echo "Email us feedback, questions, tips and suggestions to cast@steamlug.org<br>\n"; echo "We can be followed on Twitter http://twitter.com/steamlug\n"; }
/** * Generates a video that we can upload to YouTube. This calls generateImage( ) directly. * Note this is long-running, and as such needs to call set_time_limit( ) * @param integer $season the season * @param integer $episode and episode for this specific cast episode * @return string location of the rendered file on the server */ function generateVideo($season, $episode) { global $avatarKeyPath; /* TODO find a better location to write to! */ set_time_limit(360); $slug = 's' . $season . 'e' . $episode; $meta = getCastHeader($slug); $audiofile = $meta['ABSFILENAME'] . '.ogg'; if (!file_exists($audiofile)) { return false; } $svgcontents = generateImage($season, $episode); $svgcontents = str_replace('/avatars', './avatars', $svgcontents); $svgcontents = str_replace('/images/', './images/', $svgcontents); $svgcontents = str_replace('/fonts/', './fonts/', $svgcontents); /* TODO: reg match on http references, check local cache for file and either dl & use, or use */ $svgfile = $avatarKeyPath . '/' . $meta['FILENAME'] . '.svg'; $pngfile = $avatarKeyPath . '/' . $meta['FILENAME'] . '.png'; $mp4filetmp = $avatarKeyPath . '/' . $meta['FILENAME'] . '-temp.mp4'; $mp4file = $avatarKeyPath . '/' . $meta['FILENAME'] . '.mp4'; $svgfileref = fopen($svgfile, 'w'); fwrite($svgfileref, $svgcontents); fclose($svgfileref); if (!file_exists($svgfile)) { return false; } $commandthumbnail = "rsvg-convert {$svgfile} > {$pngfile}"; print "Running: " . $commandthumbnail . "\n"; echo shell_exec($commandthumbnail . ' 2>&1'); if (!file_exists($pngfile)) { return false; } $commandvideo = "ffmpeg -y -loglevel warning -loop 1 -framerate 1 -i {$pngfile} -i {$audiofile} -c:v libx264 -tune stillimage -pix_fmt yuv420p -c:a aac -strict experimental -b:a 192k -shortest {$mp4filetmp}"; print "Running: " . $commandvideo . "\n"; echo shell_exec($commandvideo . ' 2>&1'); if (!file_exists($mp4filetmp)) { return false; } $commandfaststart = "qt-faststart {$mp4filetmp} {$mp4file}"; print "Running: " . $commandfaststart . "\n"; echo shell_exec($commandfaststart . ' 2>&1'); if (!file_exists($mp4file)) { return false; } return $mp4file; }