/**
  * Gets all shows and store them in json.
  */
 public function updateShows()
 {
     $url = $this->builder->getAddictedShowsUrl();
     printf("Trying to get shows from [%s].\n", $url);
     $crawler = $this->client->request('GET', $url);
     $showsLinkAndName = $crawler->filter('table.tabel90 > tr > td > h3 > a')->extract(['_text', 'href']);
     $showsSeasons = $crawler->filter('table.tabel90 > tr > td.newsDate')->extract(['_text']);
     if (count($showsLinkAndName) != count($showsSeasons)) {
         throw new \Exception("Inconsistencies detected while updating shows.");
     }
     printf("Found [%s] shows.\n", count($showsLinkAndName));
     $shows = [];
     foreach ($showsLinkAndName as $n => $show) {
         $id = $this->extractShowId($show[1]);
         if ($this->nonEmptyShow($showsSeasons[$n])) {
             $name = Episode::sanitizeShowName($show[0]);
             // if multiple shows name reference the same id
             if (isset($this->mappedShowsNames()[$name])) {
                 foreach ($this->mappedShowsNames()[$name] as $name) {
                     $shows[$name] = $id;
                 }
             } else {
                 $shows[$name] = $id;
             }
         }
     }
     $this->io->saveShows($shows);
 }
 public function __construct()
 {
     $this->config = new Config();
     $this->client = new Client();
     $this->builder = new RequestBuilder();
     $this->io = new IO();
     $this->shows = $this->io->getShows();
     $this->languages = $this->io->getLanguages();
 }