// Create new rows in visited table for ($i = 0; $i < $numClips; $i++) { // echo "success"; $sth = $dbh->prepare("INSERT INTO visited (workerId, arrivalTime, submitTime, session, clipIndex, page, firstSaw) values (:workerId, 9999, 9999, :session, :clipIndex, 'coding', 9999)"); $sth->execute(array(':workerId' => "mitchell", ":session" => $newSession, ":clipIndex" => $i)); } } $clipTimes = makeClipBuckets($videoStart, $videoEnd, $clipLength); // print_r($clipTimes); // Create new rows in segments table $handle = fopen($fileName, "r"); if ($handle) { while (($line = fgets($handle)) !== false) { $times = explode("-", $line); $start = timeToSeconds($times[0]) / $playbackSpeed; $end = timeToSeconds($times[1]) / $playbackSpeed; $clipIndexStart = findClipIndex($start, $clipTimes); $clipIndexEnd = findClipIndex($end, $clipTimes); // If both start and end are in the same clip // if(($end % $clipLength + $start % $clipLength) < $clipLength){ if ($clipIndexStart == $clipIndexEnd) { $sth = $dbh->prepare("INSERT INTO segments (session, author, startSegment, endSegment, confidence, clipIndex) values (:session, :author, :startSegment, :endSegment, :confidence, :clipIndex)"); $sth->execute(array(":session" => $newSession, ":author" => "mitchell", ":startSegment" => $start, ":endSegment" => $end, ":confidence" => "N/A", ":clipIndex" => $clipIndexStart)); } else { //Insert segment from earlier clip $sth = $dbh->prepare("INSERT INTO segments (session, author, startSegment, endSegment, confidence, clipIndex) values (:session, :author, :startSegment, :endSegment, :confidence, :clipIndex)"); $sth->execute(array(":session" => $newSession, ":author" => "mitchell", ":startSegment" => $start, ":endSegment" => ($clipIndexStart + 1) * $clipLength, ":confidence" => "N/A", ":clipIndex" => $clipIndexStart)); // Insert segment from later clip $sth = $dbh->prepare("INSERT INTO segments (session, author, startSegment, endSegment, confidence, clipIndex) values (:session, :author, :startSegment, :endSegment, :confidence, :clipIndex)"); $sth->execute(array(":session" => $newSession, ":author" => "mitchell", ":startSegment" => ($clipIndexStart + 1) * $clipLength, ":endSegment" => $end, ":confidence" => "N/A", ":clipIndex" => $clipIndexEnd)); }
public function getVideo($options = null) { if (!isset($options["youtubeId"])) { die("You must specify a youtubeId param"); } $this->db->where('youtubeId', $options["youtubeId"]); $video = $this->db->getOne('videos'); if (strpos($video["slides"], "http") === false) { $video["slides"] = "https://docs.google.com/presentation/d/{$video['slides']}/embed?start=false&loop=false&delayms=3000"; } $ids = explode(",", $video["related"]); $video["related"] = array(); foreach ($ids as $id) { $this->db->where('id', $id); $v = $this->db->getOne('videos'); array_push($video["related"], $v); } $video["tags"] = explode(",", $video["tags"]); $entries = explode("\n", $video["videoIndex"]); $video["videoIndex"] = array(); foreach ($entries as $e) { $index = strpos($e, " "); $entry = array("time" => substr($e, 0, $index), "text" => substr($e, $index + 1)); // Parse time to seconds $entry["seconds"] = timeToSeconds($entry["time"]); array_push($video["videoIndex"], $entry); } // Parse PT40M2S to 40:02 $time = convtime($video["duration"]); $video["length"] = timeToSeconds($time); //TODO: get current progress for the user meetup_id $this->db->where("youtubeId", $options["youtubeId"]); $v = $this->db->getOne("videos"); $this->db->where("video_id", $v["id"]); if (isset($options['meetupId'])) { $this->db->where("meetup_id", $options['meetupId']); $elem = $this->db->getOne("progress"); $video["progress"] = array(); if (!$elem) { foreach ($video["videoIndex"] as $entry) { array_push($video["progress"], array($entry["seconds"], 0)); } } else { $indexes = explode("|", $elem["indexes"]); for ($i = 0; $i < sizeof($indexes); $i++) { $t = explode(",", $indexes[$i]); array_push($video["progress"], array($video["videoIndex"][$i]["seconds"], $t[1])); } } //Skip this step when video length==0 -> webinar if ($video["length"]) { $videoNumEl = sizeof($video["progress"]); for ($i = 0; $i < $videoNumEl; $i++) { $t0 = $video["progress"][$i][0]; if ($i + 1 < $videoNumEl) { $t1 = $video["progress"][$i + 1][0]; } else { $t1 = $video["length"]; } $num = ($t1 - $t0) / $video["length"]; array_push($video["progress"][$i], $num); } } } return $video; }