|
<?php |
|
@apache_setenv('no-gzip', 1); |
|
@ini_set('zlib.output_compression', 0); |
|
ob_implicit_flush(true); |
|
ini_set("output_buffering", "Off"); |
|
ob_end_flush(); |
|
|
|
function rm_blank($in){ |
|
foreach($in as $k => $v){ |
|
if($v == ""){ |
|
unset($in[$k]); |
|
} |
|
} |
|
return $in; |
|
} |
|
|
|
function update_feed($user){ |
|
$f = json_decode(file_get_contents("http://gdata.youtube.com/feeds/base/users/$user/uploads?alt=json"), true); |
|
$f = $f['feed']['entry']; |
|
if(!$f){ |
|
die("Could not fetch feed for $user"); |
|
} |
|
file_put_contents("yt-cache/$user.txt", json_encode($f)); |
|
} |
|
|
|
$youtubers = @file_get_contents("yt.txt"); |
|
$youtubers = explode("\n", $youtubers); |
|
if(!$youtubers){ |
|
$youtubers = array(); |
|
} |
|
|
|
if($_GET['ad-yt']){ |
|
update_feed($_GET['ad-yt']); |
|
|
|
$youtubers[] = $_GET['ad-yt']; |
|
$youtubers = rm_blank($youtubers); |
|
file_put_contents("yt.txt", implode("\n", $youtubers)); |
|
|
|
echo '<script type="text/javascript">document.location.href= "yt.php?updated=true"</script>'; |
|
exit(0); |
|
} if($_GET['update']){ |
|
update_feed($_GET['update']); |
|
$_GET['updated'] = "true"; |
|
$youtubers = array($_GET['update']); |
|
if($_GET['json']){ exit("{'status':'ok'}"); } |
|
//header("Location: yt.php?updated=true"); |
|
} |
|
|
|
?> |
|
<!doctype html> |
|
<head><title>YouTube Manual Subscriptions</title> |
|
|
|
<link rel="stylesheet" href="bootstrap.min.css" /> |
|
</head> |
|
<body> |
|
<div class="container" style="margin-top: 10px;"> |
|
<?php |
|
if($_GET['updated']){ |
|
echo '<div class="alert alert-success">Updated</div>'; |
|
} |
|
if($_GET['update']){ |
|
echo '<a class="btn" href="?">All</a>'; |
|
} |
|
if(!$_GET['updateall']){ |
|
?> |
|
<form method="get" class="form-inline"> |
|
Add YouTuber: <input type="text" value="" class="input-text" name="ad-yt" /> |
|
<button class="btn">Submit</button> |
|
</form> |
|
<?php |
|
} if($_GET['updateall']){ |
|
?> |
|
<div class="progress"> |
|
<div class="bar" |
|
style="width: 0%;"></div> |
|
</div> |
|
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script> |
|
<script type="text/javascript"> |
|
var youtubers = <?php echo json_encode($youtubers); ?>; |
|
function doit(id){ |
|
$("#" + youtubers[id]).show(); |
|
$.get("yt.php?update=" + youtubers[id] + "&json=true", function(data){ |
|
$("#" + youtubers[id] + " .done").show(); |
|
id = id+1; |
|
$(".progress .bar").css("width", ((id+1)/youtubers.length * 100) + "%"); |
|
if(youtubers.length > id){ |
|
doit(id); |
|
} else{ |
|
$("#alldone").show(); |
|
$(".updating").hide(); |
|
document.location.href = "yt.php?updated=true"; |
|
} |
|
}); |
|
} |
|
|
|
$(document).ready(function(){ |
|
doit(0); |
|
}); |
|
</script> |
|
<?php foreach($youtubers as $youtuber){ ?> |
|
<div class="alert alert-info hide updating" id="<?php echo $youtuber; ?>"> |
|
Updating <?php echo $youtuber; ?>...<strong class="hide done"> done</strong> |
|
</div> |
|
<?php } ?> |
|
<div id="alldone" class="alert alert-success hide"> |
|
All done! :) |
|
</div> |
|
<?php |
|
exit(0); |
|
} |
|
?> |
|
Manual Subscriptions for |
|
<?php |
|
$videos = array(); |
|
foreach($youtubers as $youtuber){ |
|
echo "<a href='?update=$youtuber' title='Manual Update'>$youtuber</a>, "; |
|
$nv = @json_decode(@file_get_contents("yt-cache/$youtuber.txt"), true); |
|
if($nv) |
|
foreach($nv as $video){ |
|
$videos[strtotime($video['published']['$t'])] = $video; |
|
} |
|
} |
|
krsort($videos); |
|
$videos = array_slice($videos, 0, 20); |
|
|
|
?> |
|
<hr/> |
|
Videos: <a href="?updateall=true" class="btn">Update all feeds</a><br/> |
|
<table> |
|
<?php |
|
foreach($videos as $video){ |
|
$vidid = explode("/", $video['id']['$t']); |
|
$vidid = $vidid[count($vidid) - 1]; |
|
foreach($video['link'] as $link){ |
|
if($link['type'] == "text/html"){ |
|
$online = $link['href']; |
|
} |
|
} |
|
?> |
|
<a href="<?php echo $online; ?>"> |
|
<tr> |
|
<td> |
|
<a href="<?php echo $online; ?>"><img src="http://i.ytimg.com/vi/<?php echo $vidid; ?>/default.jpg" /></a> |
|
</td> |
|
<td> |
|
<strong><?php echo $video['title']['$t']; ?></strong><br/> |
|
<?php echo $video['author'][0]['name']['$t']; ?> - <?php echo date("D d F y, g:i a", strtotime($video['published']['$t'])); ?> |
|
</tr> |
|
</a> |
|
<?php |
|
} |
|
?> |
|
</table> |
|
</div></body> |