Skip to content

Instantly share code, notes, and snippets.

@havudk1707
Last active November 15, 2016 11:12
Show Gist options
  • Save havudk1707/4d9dd3f2cee4a889f1ec8b1fe800f6d0 to your computer and use it in GitHub Desktop.
Save havudk1707/4d9dd3f2cee4a889f1ec8b1fe800f6d0 to your computer and use it in GitHub Desktop.
parserBitly
<?php
function file_get_contents_utf8($fn) {
$content = file_get_contents($fn);
return mb_convert_encoding($content, "UTF-8",
"Shift-JIS, EUC-JP, JIS, SJIS, JIS-ms, eucJP-win, SJIS-win, ISO-2022-JP,
ISO-2022-JP-MS, SJIS-mac, SJIS-Mobile#DOCOMO, SJIS-Mobile#KDDI,
SJIS-Mobile#SOFTBANK, UTF-8-Mobile#DOCOMO, UTF-8-Mobile#KDDI-A,
UTF-8-Mobile#KDDI-B, UTF-8-Mobile#SOFTBANK, ISO-2022-JP-MOBILE#KDDI");
}
/* returns a result form url */
function curl_get_result($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($ch, CURLOPT_ENCODING, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function get_bitly_lookup_url($url,$access_token,$format='json') {
$connectURL = 'https://api-ssl.bitly.com/v3/user/link_lookup?url='.urlencode($url).'&access_token='.$access_token.'&format='.$format;
return curl_get_result($connectURL);
}
function get_youtube_info($arrayIDs) {
$connectURL = 'https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,statistics&id='.$arrayIDs.'&key=AIzaSyDT5UFC_Tj4Palxf73R7Pv2f9iiTKGxSk0';
return file_get_contents_utf8($connectURL);
}
if (isset($_GET['name'])) {
$name = $_GET['name'];
} else {
$response = array('status'=>'error');
echo json_encode($response);
die();
}
if (isset($_GET['array'])) {
$arrayIDs = $_GET['array'];
$info = get_youtube_info($arrayIDs);
$json_output = json_decode($info, true);
} else {
$response = array('status'=>'error');
echo json_encode($response);
die();
}
$str = 'name='.$name.'&array='.$arrayIDs;
$link_url = 'http://ec2-52-192-87-58.ap-northeast-1.compute.amazonaws.com/app-dev/vuha/API/Bitly/parserURL.php?name='.$name.'&array='.$arrayIDs;
$lookup_url = get_bitly_lookup_url($link_url,access_token);
$data = json_decode($lookup_url, true);
if ($data['status_code'] == '200') {
$bitlyURL = array_values($data['data']['link_lookup'])[0]['link'];
$strReturn = 'name='.$name.'&array='.$arrayIDs.'&bitlyURL='.$bitlyURL;
} else {
$strReturn = 'name='.$name.'&array='.$arrayIDs;
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Include meta tag to ensure proper rendering and touch zooming -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-type" value="text/html; charset=UTF-8" />
<script src="nativeDroid2/vendor/jquerymobile/jquery.min.js"></script>
<script src="nativeDroid2/vendor/jquerymobile/jquery-ui.min.js"></script>
<script src="nativeDroid2/vendor/jquerymobile/jquery.mobile.min.js"></script>
<script src="nativeDroid2/vendor/waves/waves.min.js"></script>
<script src="nativeDroid2/vendor/wow/wow.min.js"></script>
<script src="nativeDroid2/js/nativedroid2.js"></script>
<script src="nativeDroid2/nd2settings.js"></script>
<link rel="stylesheet" href="nativeDroid2/vendor/jquerymobile/jquery.mobile.min.css">
<link rel="stylesheet" href="nativeDroid2/vendor/waves/waves.min.css" />
<link rel="stylesheet" href="nativeDroid2/vendor/wow/animate.css" />
<link rel="stylesheet" href="nativeDroid2/css/nativedroid2.css" />
<style>
body { opacity: 0; }
#customHeader {
background-image: url('nativeDroid2/mylist_title.png');
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
}
</style>
</head>
<body>
<script type='text/javascript'>
function iOSVersion() {
if(window.MSStream){
// There is some iOS in Windows Phone...
// https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx
return false;
}
var match = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/),
version;
if (match !== undefined && match !== null) {
version = [
parseInt(match[1], 10),
parseInt(match[2], 10),
parseInt(match[3] || 0, 10)
];
return parseFloat(version.join('.'));
}
return false;
}
function open_appstore() {
window.location='https://itunes.apple.com/app/id1136104983';
}
function try_to_open_app() {
setTimeout('open_appstore()', 80);
}
function myFunction(){
ver = iOSVersion();
if (ver >= 9) {
window.location = 'https://q28w3.app.goo.gl/?<?= $strReturn ?>';
} else {
try_to_open_app();
window.location = 'musicplus://?<?= $strReturn ?>';
}
}
</script>
<div data-role="page" id="pageone">
<div data-role="header" data-position="fixed" class="wow fadeIn" id="customHeader">
<img src="nativeDroid2/rogo.png" class="ui-thumbnail" style="max-width: 100%; max-height: 100%; display:block; margin-left:auto; margin-right:auto; margin-top: 10px ; margin-bottom: 10px "/>
</div>
<a onclick="myFunction(); return false" href="#" style="width: 200px; !important; display:block; margin-left:auto; margin-right:auto; margin-top: 10px ; margin-bottom: 10px;">
<img src="nativeDroid2/button_mylist_plus.png" style="width: 100%; height: 100%;"/>
</a>
<a class="ui-btn" data-role="button" onclick="open_appstore(); return false" href="#" data-shadow="false" data-theme="none" style="display:flex; width: 100%; height: 40px;margin-left: auto;margin-right: auto;">
<img src="nativeDroid2/icon_80.png" border="0" style="width: 40px; height: 40px;margin-left: auto;"/>
<img src="nativeDroid2/button_mylist_download.png" border="0" style="width: 130px; height: 40px;margin-left: 5px;"/>
<div style="margin-left:30px; margin-right: auto;"></div>
</a>
<hr/>
<?php
echo '<ul data-role="listview" data-icon="false">';
foreach ($json_output['items'] as $value) {
$title = $value['snippet']['title'];
$thumb = $value['snippet']['thumbnails']['default']['url'];
$channel = $value['snippet']['channelTitle'];
echo '<li>';
echo '<img src="'.$thumb.'" class="ui-thumbnail" />';
echo "<h2>".$title."</h2>";
echo "<p>".$channel."</p>";
echo '</li>';
}
echo '</ul>';
?>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment