<?php
require '../fly2/fly3.php';
require '../config.php';
require '../youtube.php';

class ChannelUploader extends YoutubeV3{
	function execute(){
		$list_of_channel_id = query('select channel_id from subscribe');
		foreach($list_of_channel_id as $val){
			$channel_id = $val[channel_id];
			$a = $this->getChannel($channel_id);
			if($a[result] == 'success'){
				$a[title]= json_encode($a[title], JSON_UNESCAPED_UNICODE);
				$a[thumbnails]= json_encode($a[thumbnails], JSON_UNESCAPED_UNICODE);
				$a[channel_id] = $channel_id;
				$result = query("
					update subscribe set
						title=:title,
						thumbnails=:thumbnails
					where channel_id=:channel_id", $a);	
				if($result[numAffected]==1){
					echo $$channel_id."\n";
					echo '-> update done'."\n";
				}else{
					echo $channel_id."\n";
					echo '-> The current data is the latest '."\n";
				}
			}else{
				print_r($a[result]);
			}
			}
		}
	}		

$app = new ChannelUploader(); 
$app -> execute();
?>