Skip to content

Commit

Permalink
Autoformat this code for prettier readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
kordianbruck committed Jan 6, 2021
1 parent 5130d81 commit 88a3377
Show file tree
Hide file tree
Showing 8 changed files with 2,534 additions and 2,517 deletions.
20 changes: 10 additions & 10 deletions api/get_rbg_hls_link.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
include_once 'CacheAccess.php';

function get_rbg_hls_link(string $url): ?string {
$html = CacheAccess::getHtml($url, 60*60*24); // this site should be static, therefore we cache it longer.
$html = CacheAccess::getHtml($url, 60 * 60 * 24); // this site should be static, therefore we cache it longer.

if($html) {
$matches = array();
if ($html) {
$matches = [];

preg_match('/MMstartStream.*\'(.+)\'/', $html, $matches);

if(sizeof($matches) >= 1) {
return $matches[1];
preg_match('/MMstartStream.*\'(.+)\'/', $html, $matches);

if (sizeof($matches) >= 1) {
return $matches[1];
}
}
}

return null;
return null;
}
?>

13 changes: 6 additions & 7 deletions api/get_rbg_stream_site.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
include 'simple_html_dom.php';
include_once 'CacheAccess.php';

function ParseInformation($link)
{
function ParseInformation($link) {
// First get html of remote page
$html = CacheAccess::getHtml($link);

$veranstaltung = $html->find("main", 1)->find("font", 0)->find("b", 0)->innertext;
$date = $html->find("main", 1)->find("font", 0)->find("b", 1)->innertext;
$time = $html->find("main", 1)->find("font", 0)->find("b", 2)->innertext;
$veranstaltung = $html->find("main", 1)->find("font", 0)->find("b", 0)->innertext;
$date = $html->find("main", 1)->find("font", 0)->find("b", 1)->innertext;
$time = $html->find("main", 1)->find("font", 0)->find("b", 2)->innertext;

$link;
if ($html) {
$matches = array();
$matches = [];

preg_match('/MMstartStream.*\'(.+)\'/', $html, $matches);

Expand All @@ -23,5 +22,5 @@ function ParseInformation($link)
}


return array("name" => $veranstaltung, "date" => $date, "time" => $time, "hls_url" => $link);
return ["name" => $veranstaltung, "date" => $date, "time" => $time, "hls_url" => $link];
}
55 changes: 30 additions & 25 deletions api/get_rbg_streams.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
$html = CacheAccess::getHtml($URL);

// Initialize basic data structure
$data = array();
$data["livestreams"] = array();
$data["vod"] = array();
$data["vod_archive"] = array();
$data = [];
$data["livestreams"] = [];
$data["vod"] = [];
$data["vod_archive"] = [];
// First index is normally current live events (first ul)
// Second index is normally VOD - current semester (second ul)
// Last index is normally VOD - archive (last ul)
$index = 0;
$indexToType = array(0 => "live", 1 => "vod");
$indexToType = [0 => "live", 1 => "vod"];
// If there are currently no active livestreams, the types shift (as 0 is now vod, because there is no ul with livestream-events existing)
if (strpos($html->find("main", 0), "Derzeit gibt es keine aktiven Livestreams")) {
// If first is empty -> leave index of ul, if does not exist at all skip index
Expand All @@ -29,67 +29,74 @@
// Find the amount of all uls on the whole html page (to identify last one)
$totalLists = sizeof($html->find("ul"));
// If the archive (last ul) was found already
$archiveFound = False;
$archiveFound = false;
for ($index; !$archiveFound; $index++) {

// Check if we are in a sub ul of an VOD-Entry (then skip as this was already read in) or if we are at the last list entry
if (!array_key_exists($index, $indexToType) && $index != $totalLists - 1)
if (!array_key_exists($index, $indexToType) && $index != $totalLists - 1) {
continue;
}

// Find all lists to go through them
$lists = $html->find("ul", $index);

// Check if we are in the archive ul
if ($index == $totalLists - 1) {
$archiveFound = True;
$archiveFound = true;
$indexToType[$index] = "vod_archive";
}

// Got through each list entry and parse data
foreach ($lists->find('li') as $entry) {
$element = array();
$element = [];
// If this is a live entry, get name and links
if ($indexToType[$index] == "live") {
$link = $entry->find('a');
if (sizeof($link) > 1) {
// Got a Livestream-Entry
$element["info"] = array();
$element["links"] = array();
$element["info"] = [];
$element["links"] = [];
$element["info"]["name"] = FormatText($link[0]->innertext);
$element["links"]["overall"] = FormatLink($link[0]->attr["href"]);
if (sizeof($link) > 1)
if (sizeof($link) > 1) {
$element["links"]["comb"] = FormatLink($link[1]->attr["href"]);
if (sizeof($link) > 2)
}
if (sizeof($link) > 2) {
$element["links"]["pres"] = FormatLink($link[2]->attr["href"]);
if (sizeof($link) > 3)
}
if (sizeof($link) > 3) {
$element["links"]["cam"] = FormatLink($link[3]->attr["href"]);
}
}
$data["livestreams"][] = $element;
} else if ($indexToType[$index] == "vod") {
// If this is a VOD Entry it contains a header (in bold)
if ($entry->find("b") != null) {
// Got a VOD Entry
$element["info"] = array();
$element["videos"] = array();
$element["info"] = [];
$element["videos"] = [];
$element["info"]["name"] = FormatText($entry->find(".vodlistth", 0)->innertext);
foreach ($entry->find("li") as $videoEntry) {
$retEntry = array();
$retEntry = [];
$link = $videoEntry->find('a');
$retEntry["info"]["name"] = FormatText($link[0]->innertext);
$retEntry["links"]["overall"] = FormatLink($link[0]->attr["href"]);
if (sizeof($link) > 1)
if (sizeof($link) > 1) {
$retEntry["links"]["comb"] = FormatLink($link[1]->attr["href"]);
if (sizeof($link) > 2)
}
if (sizeof($link) > 2) {
$retEntry["links"]["pres"] = FormatLink($link[2]->attr["href"]);
if (sizeof($link) > 3)
}
if (sizeof($link) > 3) {
$retEntry["links"]["cam"] = FormatLink($link[3]->attr["href"]);
}
$element["videos"][] = $retEntry;
}
$data["vod"][] = $element;
}
} else if ($indexToType[$index] == "vod_archive") {
// Got a VOD - Archive Entry
$element["info"] = array();
$element["info"] = [];
$element["info"]["name"] = FormatText($entry->find("a", 0)->innertext);
$element["info"]["link"] = FormatLink($entry->find("a", 0)->attr["href"]);
$data["vod_archive"][] = $element;
Expand All @@ -99,16 +106,14 @@
}
}

function FormatLink($string)
{
function FormatLink($string) {
if (substr($string, 0, 4) === "http") {
return FormatText($string);
}
return FormatText("https://live.rbg.tum.de$string");
}

function FormatText($string)
{
function FormatText($string) {
$string = trim(strip_tags($string));
return $string;
}
Expand Down
Loading

0 comments on commit 88a3377

Please sign in to comment.