Skip to content

Instantly share code, notes, and snippets.

@tuxity
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxity/cfc01edf4dc13a328b06 to your computer and use it in GitHub Desktop.
Save tuxity/cfc01edf4dc13a328b06 to your computer and use it in GitHub Desktop.
<?php
// Put your Betaserie account informations
define("API_KEY", "");
define("LOGIN", "");
define("PASSWORD", "");
// END OF CONFIGURATION
$authParams = [
"v" => "2.4",
"key" => API_KEY,
"login" => LOGIN,
"password" => md5(PASSWORD)
];
function query($url, $params = [], $method = "GET") {
global $authParams;
if (!isset($authParams["token"]) && $url != "/members/auth") {
$userInfos = query("/members/auth", $authParams, "POST");
if (!empty($userInfos->errors)) {
echo $userInfos->errors[0]->text;
exit();
}
$authParams = array_merge($authParams, ["token" => $userInfos->token]);
}
$params = array_merge($params, $authParams);
$query = '';
if ($method == "GET" || $method != "POST") {
$query = '?' . http_build_query($params);
}
$url = "https://api.betaseries.com{$url}{$query}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($method == "POST") {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
}
if ($method != "GET" && $method != "POST") {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$data = substr($response, $headerSize);
curl_close($ch);
return json_decode($data);
}
$memberObj = query("/members/infos", ["only" => "shows"], "GET");
$regex = "/(";
foreach($memberObj->member->shows as $show) {
// only active shows
if ($show->user->archived != 1 && $show->status == "Continuing") {
if (is_numeric(substr($regex, -1)))
$regex .= "|";
// Remove ' by nothing
$show->title = str_replace("'", "", $show->title);
// Remove . by a space
$show->title = str_replace(".", " ", $show->title);
$actualSeason = ($show->seasons < 10) ? "0".$show->seasons : $show->seasons;
$regex .= $show->title . " S" . $actualSeason;
}
}
$regex .= ").*720p/i";
echo $regex."\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment