Created
December 5, 2013 19:58
-
-
Save michaellujan/7812818 to your computer and use it in GitHub Desktop.
just for fun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function _radio_edit_cron() { | |
$this->_displayTemplate = false; | |
$cacheTtl = Ccomr_Util_Misc_CacheTtl::generate('TTL_NOCACHE'); | |
$this->_cacheTtl = $cacheTtl; | |
header("Cache-Control: max-age={$this->_cacheTtl}, must-revalidate"); | |
$reApi = new Ccomr_Api_RadioEdit(); | |
$streamApi = new Ccomr_Api_Stream(); | |
$old_version = $reApi->get_radio_edit_cron(); | |
if (!$old_version) { | |
$old_version = 30694; | |
} | |
$new_version = $reApi->get_t3_startup(); | |
$market_lookup = array(); | |
$markets = $reApi->stream_market_xref(); | |
foreach($markets as $m) { | |
$market = array(); | |
$market['market_id'] = intval($m['marketId']); | |
$market['sort_order'] = intval($m['sortOrder']); | |
$market['cume'] = intval($m['cume']); | |
$market_lookup[$m['streamId']][] = $market; | |
} | |
$genre_lookup = array(); | |
$genres = $reApi->stream_genre_xref(); | |
foreach($genres as $g) { | |
$genre = array(); | |
$genre['genre_id'] = intval($g['genreId']); | |
$genre['sort_order'] = intval($g['sortOrder']); | |
$genre_lookup[$g['streamId']][] = $genre; | |
} | |
$device_lookup = array(); | |
$devices = $reApi->stream_device_ids(); | |
foreach($devices as $d) { | |
$device_lookup[$d['streamId']][] = $d['deviceId']; | |
} | |
$streams = $reApi->get_stream_info($old_version, $new_version); | |
foreach($streams as $s) { | |
if (strlen($s['call_letters']) < 4) { | |
continue; | |
} | |
if (!$s['twitter']) { | |
if($s['twitter_2']) { | |
$s['twitter'] = $s['twitter_2']; | |
} | |
} | |
$s['twitter_2'] = null; | |
// Add Feed to Non Digital CC stations | |
if ($s['provider'] == 1 && $s['origin_market'] != 402) { | |
$feed = array(); | |
$feed['feed'] = strtolower($s['call_letters']) . '.app.clearchannel.com'; | |
$s['feeds'] = $feed; | |
} | |
// Add Markets | |
$s['markets'] = $market_lookup[$s['stream_id']]; | |
// Add Genres | |
$genres = $genre_lookup[$s['stream_id']]; | |
if ($s['isPersonality'] == '1') { | |
$genre['genre_id'] = 101; | |
$genres[] = $genre; | |
} | |
$s['genres'] = $genres; | |
$s['isPersonality'] = null; | |
/* Does Stream Already Exist? */ | |
// 10.5.1.28 | |
//$radioEdit = "http://10.5.1.28"; | |
//$token = base64_encode('pfxtnGFcRM'); | |
// 10.5.1.29 | |
//$radioEdit = "http://10.5.1.29"; | |
//$token = base64_encode('nkmkembv6d'); | |
// 10.5.40.195 | |
$radioEdit = "http://radioedit.iheart.com"; | |
$token = base64_encode('zcIvOwMX0B'); | |
/* update image */ | |
if ($s['logo']) { | |
$image = file_get_contents($s['logo']); | |
if ($image) { | |
/* is active? */ | |
$active = "true"; | |
if (count($device_lookup[$s['stream_id']]) < 1) { | |
$active = "false"; | |
} else { | |
/* upload image */ | |
$ch = curl_init($radioEdit .'/storage/assets/images/' . $s['stream_id'] . '.png'); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token, 'Content-Type: image/png', 'Content-Length: ' . strlen($image))); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $image); | |
$output = curl_exec($ch); | |
curl_close($ch); | |
/* Commit */ | |
$post = array(); | |
$post['jsonrpc'] = "2.0"; | |
$post['id'] = 1; | |
$post['method'] = "commit"; | |
$params = array(); | |
$params['bucket'] = "assets"; | |
$params['_id'] = "/images/".$s['stream_id'].".png"; | |
$refs[] = "LIVE"; | |
$params['refs'] = $refs; | |
$post['params'] = $params; | |
$commit = json_encode($post); | |
$ch = curl_init($radioEdit . '/api/rpc'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $commit); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token, 'Content-Type:application/json', 'Content-Length: ' . strlen($commit))); | |
$logo_commit = json_decode(curl_exec($ch)); | |
curl_close($ch); | |
/* Create Logo Array */ | |
$version = explode("#", $logo_commit->result); | |
$image_meta['base_id'] = "~" . $version[1] . "/assets/images/" . $s['stream_id'] . ".png"; | |
$image_meta['extension'] = "png"; | |
$image_meta['mime_type'] = "image/png"; | |
$logo->devices = $device_lookup[$s['stream_id']]; | |
$logo->enabled = true; | |
$logo->type = "img"; | |
$logo->img_meta = $image_meta; | |
$s['logos'][0] = $logo; | |
} | |
} | |
else { | |
$image = file_get_contents($s['alt_logo']); | |
if ($image) { | |
/* is active? */ | |
$active = "true"; | |
if (count($device_lookup[$s['stream_id']]) < 1) { | |
$active = "false"; | |
} else { | |
/* upload image */ | |
$ch = curl_init($radioEdit .'/storage/assets/images/' . $s['stream_id'] . '.png'); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token, 'Content-Type: image/png', 'Content-Length: ' . strlen($image))); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $image); | |
$output = curl_exec($ch); | |
curl_close($ch); | |
/* Commit */ | |
$post = array(); | |
$post['jsonrpc'] = "2.0"; | |
$post['id'] = 1; | |
$post['method'] = "commit"; | |
$params = array(); | |
$params['bucket'] = "assets"; | |
$params['_id'] = "/images/".$s['stream_id'].".png"; | |
$refs[] = "LIVE"; | |
$params['refs'] = $refs; | |
$post['params'] = $params; | |
$commit = json_encode($post); | |
$ch = curl_init($radioEdit . '/api/rpc'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $commit); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token, 'Content-Type:application/json', 'Content-Length: ' . strlen($commit))); | |
$logo_commit = json_decode(curl_exec($ch)); | |
curl_close($ch); | |
/* Create Logo Array */ | |
$version = explode("#", $logo_commit->result); | |
$image_meta['base_id'] = "~" . $version[1] . "/assets/images/" . $s['stream_id'] . ".png"; | |
$image_meta['extension'] = "png"; | |
$image_meta['mime_type'] = "image/png"; | |
$logo->devices = $device_lookup[$s['stream_id']]; | |
$logo->enabled = true; | |
$logo->type = "img"; | |
$logo->img_meta = $image_meta; | |
$s['logos'][0] = $logo; | |
} | |
} else { | |
$active = "true"; | |
} | |
} | |
} | |
$s['logo'] = null; | |
$s['alt_logo'] = null; | |
// Is Active? | |
if ($s['active'] == 0) { | |
$s['active'] = "false"; | |
} | |
else { | |
$s['active'] = $active; | |
} | |
// Now Create Post | |
$post = array(); | |
$params = array(); | |
$post['jsonrpc'] = "2.0"; | |
$post['id'] = 1; | |
$post['method'] = "save"; | |
$ch = curl_init($radioEdit . '/api/rpc'); | |
$params['schema'] = "generic"; | |
$params['bucket'] = "default"; | |
$params['_id'] = "/streams/" . $s['stream_id']; | |
$value = array(); | |
foreach($s as $k=>$v) { | |
if($v) { | |
$value[$k] = $v; | |
} | |
} | |
$params['value'] = $value; | |
$post['params'] = $params; | |
$insert = json_encode($post); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $insert); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token, 'Content-Type:application/json', 'Content-Length: ' . strlen($insert))); | |
$stream = curl_exec($ch); | |
curl_close($ch); | |
$info = curl_getinfo($ch); | |
$post = array(); | |
$post['jsonrpc'] = "2.0"; | |
$post['id'] = 1; | |
$post['method'] = "commit"; | |
$params = array(); | |
$params['bucket'] = "default"; | |
$params['_id'] = "/streams/".$s['stream_id']; | |
$refs[] = "LIVE"; | |
$params['refs'] = $refs; | |
$post['params'] = $params; | |
$commit = json_encode($post); | |
$ch = curl_init($radioEdit . '/api/rpc'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $commit); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token, 'Content-Type:application/json', 'Content-Length: ' . strlen($commit))); | |
$stream_commit = curl_exec($ch); | |
curl_close($ch); | |
} | |
$reApi->update_radio_edit_cron($new_version); | |
} | |
protected function _radio_edit_genres() { | |
$this->_displayTemplate = false; | |
$reApi = new Ccomr_Api_RadioEdit(); | |
// 10.5.1.28 | |
// $radioEdit = "http://10.5.1.28"; | |
// $token = base64_encode('pfxtnGFcRM'); | |
// 10.5.1.29 | |
// $radioEdit = "http://10.5.1.29"; | |
// $token = base64_encode('nkmkembv6d'); | |
// 10.5.40.195 | |
$radioEdit = "http://radioedit.iheart.com"; | |
$token = base64_encode('zcIvOwMX0B'); | |
$genres = $reApi->get_genres(); | |
foreach($genres as $g) { | |
if($g['genre_id'] == "9" || $g['genre_id'] == "96") { | |
$g['genre_group'] = "Talk Radio"; | |
} else { | |
$g['genre_group'] = "Music & Entertainment"; | |
} | |
$g['genre_id'] = intval($g['genre_id']); | |
// Now Create Post | |
$post = array(); | |
$params = array(); | |
$post['jsonrpc'] = "2.0"; | |
$post['id'] = 1; | |
$post['method'] = "save"; | |
$ch = curl_init($radioEdit . '/api/rpc'); | |
$params['schema'] = "generic"; | |
$params['bucket'] = "default"; | |
$params['_id'] = "/genres/" . $g['genre_id']; | |
$value = array(); | |
foreach($g as $k=>$v) { | |
if($v) { | |
$value[$k] = $v; | |
} | |
} | |
$params['value'] = $value; | |
$post['params'] = $params; | |
$insert = json_encode($post); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $insert); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token, 'Content-Type:application/json', 'Content-Length: ' . strlen($insert))); | |
$stream = curl_exec($ch); | |
curl_close($ch); | |
} | |
} | |
protected function _radio_edit_markets() { | |
$this->_displayTemplate = false; | |
$reApi = new Ccomr_Api_RadioEdit(); | |
// 10.5.1.28 | |
// $radioEdit = "http://10.5.1.28"; | |
// $token = base64_encode('pfxtnGFcRM'); | |
// 10.5.1.29 | |
// $radioEdit = "http://10.5.1.29"; | |
// $token = base64_encode('nkmkembv6d'); | |
// 10.5.40.195 | |
$radioEdit = "http://radioedit.iheart.com"; | |
$token = base64_encode('zcIvOwMX0B'); | |
$markets = $reApi->get_markets(); | |
foreach($genres as $g) { | |
$g['market_id'] = intval($g['market_id']); | |
// Now Create Post | |
$post = array(); | |
$params = array(); | |
$post['jsonrpc'] = "2.0"; | |
$post['id'] = 1; | |
$post['method'] = "save"; | |
$ch = curl_init($radioEdit . '/api/rpc'); | |
$params['schema'] = "generic"; | |
$params['bucket'] = "default"; | |
$params['_id'] = "/markets/" . $g['market_id']; | |
$value = array(); | |
foreach($g as $k=>$v) { | |
if($v) { | |
$value[$k] = $v; | |
} | |
} | |
$params['value'] = $value; | |
$post['params'] = $params; | |
$insert = json_encode($post); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $insert); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token, 'Content-Type:application/json', 'Content-Length: ' . strlen($insert))); | |
$stream = curl_exec($ch); | |
curl_close($ch); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment