Skip to content

Instantly share code, notes, and snippets.

@yukixz
Last active August 29, 2015 14:17
Show Gist options
  • Save yukixz/6d759dd5f1a5bda91d1c to your computer and use it in GitHub Desktop.
Save yukixz/6d759dd5f1a5bda91d1c to your computer and use it in GitHub Desktop.
Fix bilibili on linux
<?php
error_reporting(E_ALL);
if (!($_SERVER['HTTP_HOST'] === "interface.bilibili.com")) {
return;
}
# curl init
$request_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$ch = curl_init($request_uri);
# Copy request headers
$headers = array();
foreach($_SERVER as $key => $value) {
if (strcasecmp(substr($key, 0, 4), 'HTTP') == 0) {
$key = str_replace("_", "-", substr($key, 5));
$headers[] = $key . ': ' . $value;
}
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
# Copy response headers
function headerfunction($ch, $str) {
if (strpos($str, 'Content-Length') === FALSE &&
strpos($str, 'Transfer-Encoding') === FALSE) {
header($str);
}
return strlen($str);
}
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'headerfunction');
# curl execute
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$ret = curl_exec($ch);
# Modify response
$ret = str_replace('<from><![CDATA[youku]]></from>', '<from><![CDATA[-youku]]></from>', $ret);
$ret = str_replace('<stream><![CDATA[letv]]></stream>', '<stream><![CDATA[-letv]]></stream>', $ret);
echo $ret;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment