*/ class LiveCoding { protected $app; public function __construct(Application $app) { $this->app = $app; } public function getLanguages() { return [ 'objc-swift-ios' => 'Obj-C/Swift (iOS)', 'java' => 'Java', 'android' => 'Android', 'c-cplusplus' => 'C/C++', 'csharp-dotnet' => 'C#/.NET', 'python' => 'Python', 'javascript' => 'JavaScript', 'php' => 'PHP', 'ruby"' => 'Ruby', 'sql"' => 'SQL', 'html-css' => 'HTML/CSS', 'others' => 'Others', ]; } public function getDifficulties() { return [ 1 => 'beginner', 2 => 'intermediate', 3 => 'expert', ]; } public function getStreams($language = null, $difficulty = null) { $content = file_get_contents($this->app->buildUrl(sprintf( 'livestreams/%s%s', $language !== null ? $language.'/' : 'all', $difficulty !== null ? '/'.$difficulty.'/' : null ))); preg_match_all( '`
(.+)\s+
`isU', $content, $matches, PREG_SET_ORDER ); if (empty($matches)) { return []; } $streams = []; foreach ($matches as $match) { preg_match('`href="([^"]+)"`', $match[1], $urlMatch); preg_match('`data-title="([^"]+)"`', $match[1], $countryMatch); preg_match('`/> ([^\s]+)`', $match[1], $authorMatch); preg_match('` (\d+)`', $match[1], $viewsMatch); preg_match( '`(.*)`', $match[1], $titleMatch ); preg_match_all('`(.+)`', $match[1], $languagesMatches, PREG_SET_ORDER); $languages = []; foreach ($languagesMatches as $languagesMatch) { $languages[] = $languagesMatch[1]; } if (!empty($languages)) { $difficulty = trim(array_pop($languages), '()'); } else { $difficulty = null; } $stream = new Stream(); $stream ->setTitle(html_entity_decode(trim($titleMatch[1]))) ->setViews($viewsMatch[1]) ->setCountry($countryMatch[1]) ->setAuthor($authorMatch[1]) ->setLanguages($languages) ->setDifficulty($difficulty) ->setUrl($this->app->buildUrl($urlMatch[1])); $streams[] = $stream; } return $streams; } }