protected function process(ViewBag $viewbag)
 {
     $this->SetView("MovieSelector");
     $viewbag->Query = $search = Param('search') == '' ? '' : Param('search');
     if (Param('series') === null) {
         $series = isset($_COOKIE['__mc_series']) ? trim($_COOKIE['__mc_series']) : '';
         $skip_cutted = isset($_COOKIE['__mc_skip_cutted']) ? $_COOKIE['__mc_skip_cutted'] == 'J' : '';
     } else {
         $series = trim(Param('series'));
         $skip_cutted = Param('skip_cutted') == 'J';
     }
     $viewbag->SkipCutted = $skip_cutted;
     if (Param('submit')) {
         list($chanid, $starttime) = explode(".", Param('Movie'));
         $_SESSION['SelectedMovie'] = new SelectedMovie();
         $_SESSION['SelectedMovie']->chanid = $chanid;
         $_SESSION['SelectedMovie']->starttime = $starttime;
         unset($_SESSION['list']);
         Thumbnailer::CleanCache();
         $this->Redirect('?rand=' . rand(0, 10000000));
     }
     setCookie("__mc_skip_cutted", $skip_cutted ? 'J' : 'N');
     setCookie("__mc_series", $series);
     $q = new Query("select title, count(1) as cnt, sum(filesize) as size\n\t\t        from recorded r\n\t\t       where transcoded = 0\n\t\t         and deletepending = 0");
     if ($skip_cutted) {
         $q->Append("and not exists (select 1 from recordedmarkup m where m.chanid=r.chanid and m.starttime=r.starttime and m.type in (0,1))");
     }
     $q->Append("group by title order by size desc");
     $available_series = array();
     $viewbag->Series = array();
     foreach ($q->Execute() as $v) {
         $size = sprintf("%.1f", DoubleVal($v->size) / 1024.0 / 1024.0 / 1024.0);
         $c = new StdClass();
         $c->Title = $v->title;
         $c->Size = $size;
         $c->Recordings = $v->cnt;
         $c->Selected = $series == $c->Title;
         $viewbag->Series[] = $c;
     }
     $q = new Query("select *,\n\t\t             unix_timestamp(starttime) as unix\n\t\t        from recorded  r\n\t\t       where transcoded = 0\n\t\t         and deletepending = 0");
     if ($series) {
         $q->Append("and title = :series");
         $q->series = $series;
     }
     $words = preg_split('!\\s+!', $viewbag->Query);
     $row = 0;
     foreach ($words as $v) {
         $v = trim(chop($v));
         if ($v > '') {
             $row++;
             $w1 = '%' . strtr($v, array('%' => '\\%')) . '%';
             $q->Append("and concat(coalesce(title, ''), ' ', coalesce(subtitle, ''), ' ', coalesce(description, '')) like :word" . $row);
             $q->Set('word' . $row, $w1);
         }
     }
     if ($skip_cutted) {
         $q->Append(" and not exists (select 1 from recordedmarkup m where m.chanid=r.chanid and m.starttime=r.starttime and m.type in (0,1))");
     }
     $sort_by_size = Param('sort_by_size');
     if ($sort_by_size) {
         $q->Append(" order by filesize desc");
     } else {
         $q->Append("order by starttime desc");
     }
     $viewbag->Movies = array();
     foreach ($q->Execute() as $item) {
         $c = new StdClass();
         $c->Value = $item->chanid . '.' . $item->unix;
         $c->Title = $item->title;
         $c->Subtitle = $item->subtitle;
         $c->Size = sprintf("%.1f", DoubleVal($item->filesize / 1024.0 / 1024.0 / 1024.0));
         $c->Starttime = $item->starttime;
         $viewbag->Movies[] = $c;
     }
 }
Example #2
0
 private function getMovieList()
 {
     $page = (int) Param("page");
     if ($page < 1 || $page > 10000) {
         $page = 1;
     }
     if (Param("restore") === 'true' && is_object($_SESSION['lastMovieSelection'])) {
         $params = $_SESSION['lastMovieSelection'];
     } else {
         $params = new StdClass();
         $params->search = Param('search');
         $params->series = Param('series');
         $params->skipTranscoded = Param('skipTranscoded') ? 1 : 0;
         $params->skipHasCutlist = Param('skipHasCutlist') ? 1 : 0;
         $params->hpp = (int) Param('hpp') > 0 && (int) Param('hpp') <= 1000 ? (int) Param('hpp') : HPP;
     }
     $_SESSION['lastMovieSelection'] = $params;
     $q = new Query("select title, chanid,\n\t\t\t\t             unix_timestamp(starttime) as unix,\n\t\t\t\t             filesize\n\t\t\t\t        from recorded  r\n\t\t\t\t       where deletepending = 0");
     if ($params->skipTranscoded) {
         $q->Append(" and transcoded=0");
     }
     if (strlen($params->series) > 0) {
         $q->Append("and title = :series");
         $q->series = $params->series;
     }
     $words = preg_split('!\\s+!', $params->search);
     $row = 0;
     foreach ($words as $v) {
         $v = trim(chop($v));
         if ($v > '') {
             $row++;
             $w1 = '%' . strtr($v, array('%' => '\\%')) . '%';
             $q->Append("and concat(coalesce(title, ''), ' ', coalesce(subtitle, ''), ' ', coalesce(description, '')) like :word" . $row);
             $q->Set('word' . $row, $w1);
         }
     }
     if ($params->skipHasCutlist) {
         $q->Append(" and not exists (select 1 from recordedmarkup m where m.chanid=r.chanid and m.starttime=r.starttime and m.type in (0,1))");
     }
     $sort_by_size = Param('sort_by_size');
     if ($sort_by_size) {
         $q->Append(" order by filesize desc");
     } else {
         $q->Append("order by starttime desc");
     }
     $data = array();
     $row = 0;
     $hits = 0;
     $series = array();
     $movies_to_load = array();
     $range_from = ($page - 1) * $params->hpp;
     $range_to = $page * $params->hpp;
     foreach ($q->Execute() as $v) {
         $c = new StdClass();
         $c->Chanid = $v->chanid;
         $c->Unixtime = $v->unix;
         $c->Title = $v->title;
         $c->Filesize = $v->filesize;
         $data[] = $c;
         if (!isset($series[$c->Title])) {
             $e = new StdClass();
             $e->Title = $c->Title;
             $e->NumRecordings = 0;
             $e->Filesize = 0.0;
             $e->LastRecording = 0;
             $e->Recordings = array();
             $series[$c->Title] = $e;
         }
         $series[$c->Title]->Filesize += DoubleVal($c->Filesize);
         $series[$c->Title]->LastRecording = max($series[$c->Title]->LastRecording, $c->Unixtime);
         $series[$c->Title]->NumRecordings++;
         $series[$c->Title]->Recordings[] = $c;
         if ($row >= $range_from && $row < $range_to) {
             $key = sprintf("%d.%d", $c->Chanid, $c->Unixtime);
             $movies_to_load[$key] = $c;
         }
         $row++;
         $hits++;
     }
     if (count($movies_to_load) > 0) {
         $q = new Query("select r.subtitle, r.description, r.chanid,\n\t\t\t\t\t\t\t  \t   unix_timestamp(r.starttime) as unix,\n\t\t\t\t\t\t\t  \t   c.name as channel,\n\t\t\t\t\t\t\t  \t   r.filesize\t\t\t\t\t\t\t  \t   \n\t\t\t\t\t\t\t  from recorded r\n\t\t\t\t\t\t\t  \t\t  left join channel c on (c.chanid = r.chanid)\n\t\t\t\t\t\t\t where (\n\t\t\t                         0 = 1");
         $row = 0;
         foreach ($movies_to_load as $v) {
             $row++;
             $q->Set("chanid" . $row, $v->Chanid);
             $q->Set("starttime" . $row, date("Y-m-d H:i:s", $v->Unixtime));
             $q->Append(sprintf(" or (r.chanid = :chanid%d and r.starttime=:starttime%s)", $row, $row));
         }
         unset($v);
         $q->Append(")");
         foreach ($q->Execute() as $v) {
             $key = sprintf("%d.%d", $v->chanid, $v->unix);
             $c = $movies_to_load[$key];
             $c->Subtitle = $v->subtitle;
             $c->Description = $v->description;
             $c->Channel = $v->channel;
             $c->Selector = $key;
             $c->Date = self::JsonDate($v->unix);
             $c->Filesize = (double) $v->filesize;
             $c->FilesizeGB = (double) sprintf("%.1f", $c->Filesize / 1024.0 / 1024.0 / 1024.0);
             $c->IsSeries = $series[$c->Title]->NumRecordings > 1;
             if ($c->IsSeries) {
                 $e = new StdClass();
                 $e->NumEpisodes = $series[$c->Title]->NumRecordings;
                 $e->Filesize = $series[$c->Title]->Filesize;
                 $e->FilesizeGB = (double) sprintf("%.1f", $series[$c->Title]->Filesize / 1024.0 / 1024.0 / 1024.0);
                 $c->Episodes = $e;
             }
             unset($c);
         }
     }
     $result = new StdClass();
     $result->TotalHits = $hits;
     $result->Pages = Floor(($hits + $params->hpp - 1) / $params->hpp);
     $result->CurrentPage = $page;
     $result->EntriesPerPage = $params->hpp;
     $result->Movies = array_values($movies_to_load);
     $result->PageList = array();
     $url = sprintf("?action=json&call=getMovieList&tpp=%d&search=%s&series=%s", $params->hpp, urlencode($params->search), urlencode($params->series));
     $pagelist = new Pagelist($url);
     $pagelist->HitsPerPage = $params->hpp;
     $result->BaseHREF = $url;
     $result->PageList = $pagelist->Get($result->Pages, $page);
     $result->Params = $params;
     return $this->successResult($result);
 }
Example #3
0
 public function getSeekTable($from_mark = -1, $to_mark = -1, $skip_frames = null)
 {
     if ($skip_frames === null) {
         $duration = $this->moviedata->duration;
         if ($duration < 900) {
             $skip_frames = 300;
         }
         if ($duration < 1800) {
             $skip_frames = 700;
         } else {
             if ($duration < 3600) {
                 $skip_frames = 1000;
             } else {
                 $skip_frames = 1439;
             }
         }
     }
     // Load existing cutpoints and commercial breaks
     $q = new Query("select *\n\t                     from recordedmarkup \n\t                    where chanid = :chanid \n\t                      and starttime = :starttime \n\t                      and type in (0, 1, 4, 5) \n\t                      order by mark");
     $q->chanid = $this->chanid;
     $q->starttime = date('Y-m-d H:i:s', $this->starttime);
     $cutlist_from_db = array();
     $commercials = array();
     foreach ($q->Execute() as $v) {
         $t = $v->type;
         if ($t == 0 || $t == 1) {
             $cutlist_from_db[$v->mark] = $t;
         } else {
             $commercials[$v->mark] = $t == 5 ? 0 : 1;
         }
     }
     if ($this->useCommercialBreaks) {
         $cutlist_from_db = $commercials;
     }
     // Find max mark
     $q = new Query("select max(mark) as maxmark\n\t\t\t\t\t\t  from recordedseek \n\t\t\t\t\t\t where chanid = :chanid\n\t\t\t\t\t\t   and starttime = :starttime\n\t\t\t\t\t\t   and type = 9");
     $q->chanid = $this->chanid;
     $q->starttime = date('Y-m-d H:i:s', $this->starttime);
     $max_mark = $q->Result();
     $q = new Query("select *\n\t\t\t\t\t\t  from recordedseek \n\t\t\t\t\t\t where chanid = :chanid\n\t\t\t\t\t\t   and starttime = :starttime \n\t\t\t\t\t\t   and type = 9");
     $q->chanid = $this->chanid;
     $q->starttime = date('Y-m-d H:i:s', $this->starttime);
     // Fixup cutlist to match keyframes
     foreach ($cutlist_from_db as $k => $v) {
         $fixed_mark = $this->findNearestKeyframeMark($k, $v == 0 ? -1 : 1);
         if ($fixed_mark != $k) {
             $cutlist_from_db[$fixed_mark] = $v;
             unset($cutlist_from_db[$k]);
         }
     }
     if ($from_mark != -1) {
         $q->Append("and mark > :from_mark");
         $q->from_mark = $from_mark;
     }
     if ($to_mark != -1) {
         $q->Append("and mark < :to_mark");
         $q->to_mark = $to_mark;
     }
     $q->Append("order by mark");
     $frame_idx = 0;
     $result = array();
     $next = -10000;
     $last_mark = null;
     $last = null;
     foreach ($q->Execute() as $v) {
         $last = null;
         // Compute approx. seconds for thumbnail generation
         $seconds = IntVal(DoubleVal($this->duration()) / DoubleVal($max_mark) * $v->mark);
         if ($v->mark > $next) {
             $c = new PreviewImage($v->mark, (double) $v->offset, $seconds);
             if (array_key_exists($v->mark, $cutlist_from_db)) {
                 $c->cutpoint = $cutlist_from_db[$v->mark] == 0 ? PreviewImage::CUT_LEFT : PreviewImage::CUT_RIGHT;
             }
             $result[] = $c;
             $next = $v->mark + $skip_frames;
         } else {
             if (array_key_exists($v->mark, $cutlist_from_db)) {
                 $c = new PreviewImage($v->mark, (double) $v->offset, $seconds);
                 if (array_key_exists($v->mark, $cutlist_from_db)) {
                     $c->cutpoint = $cutlist_from_db[$v->mark] == 0 ? PreviewImage::CUT_LEFT : PreviewImage::CUT_RIGHT;
                 }
                 $result[] = $c;
             } else {
                 $last = $v;
             }
         }
     }
     if ($last !== null) {
         $c = new PreviewImage($last->mark, (double) $last->offset, $seconds);
         if (array_key_exists($last->mark, $cutlist_from_db)) {
             $c->cutpoint = $cutlist_from_db[$last->mark] == 0 ? PreviewImage::CUT_LEFT : PreviewImage::CUT_RIGHT;
         }
     }
     if (count($result) > 0 && $result[0]->cutpoint == PreviewImage::CUT_RIGHT) {
         $result[0]->cutpoint = PreviewImage::CUT_NONE;
     }
     return $result;
 }