function process_chapter($e, $path, $chno)
{
    $chapter = $e->find('span.chTitle', 0)->plaintext;
    $sections = $e->find('tr.showToggleDeltails');
    $chapter = parse_chapter_name($chapter, $chno);
    $dir = $path . '/' . str_pure($chapter);
    $j = 1;
    foreach ($sections as $section) {
        $num = $j < 10 ? "0{$j}" : $j;
        $title = "{$num}. " . $section->find('a', 0)->plaintext;
        $rows = $section->find('td.tC');
        $rows_num = count($rows);
        $sub = '';
        for ($i = 0; $i < $rows_num;) {
            $start = $rows[$i]->plaintext;
            // $lms   = explode(':', $rows[$i+1]->plaintext);
            // $lsec  = $lms[1] - 1;
            // $lsec  = $lsec<10?"0$lsec":$lsec;
            // $end   = "$lms[0]:$lsec";
            // Lynda.com has changed its transcript page structure
            if ($i == $rows_num - 1) {
                $lms = explode(':', $start);
                $lmin = $lms[0] + 1;
                $lmin = $lmin < 10 ? "0{$lmin}" : $lmin;
                $end = "{$lmin}:{$lms['1']}";
            } else {
                $lms = explode(':', $rows[$i + 1]->plaintext);
                if ($lms[1] > 0) {
                    $lsec = $lms[1] - 1;
                } else {
                    $lsec = '59';
                    $lms[0]--;
                    $lms[0] = $lms[0] < 10 ? "0{$lms['0']}" : $lms[0];
                }
                $lsec = $lsec < 10 ? "0{$lsec}" : $lsec;
                $end = "{$lms['0']}:{$lsec}";
            }
            $text = preg_replace("/\\s+/", ' ', trim($rows[$i]->next_sibling()->plaintext));
            $i++;
            $sub .= "{$i}" . PHP_EOL;
            $sub .= "00:{$start},000 --> 00:{$end},990" . PHP_EOL;
            $sub .= "{$text}" . PHP_EOL . PHP_EOL;
        }
        to_srt($sub, $dir, str_pure($title));
        $j++;
    }
}
function process_chapter($e, $path, $chno)
{
    $chapter = $e->find('span.chTitle', 0)->plaintext;
    $sections = $e->find('tr.showToggleDeltails');
    $chapter = parse_chapter_name($chapter, $chno);
    $dir = $path . '/' . str_pure($chapter);
    $j = 1;
    foreach ($sections as $section) {
        $num = $j < 10 ? "0{$j}" : $j;
        $title = "{$num}. " . $section->find('a', 0)->plaintext;
        $rows = $section->find('td.tC');
        $sub = '';
        for ($i = 0; $i < count($rows) - 1;) {
            $start = $rows[$i]->plaintext;
            $lms = explode(':', $rows[$i + 1]->plaintext);
            $lsec = $lms[1] - 1;
            $lsec = $lsec < 10 ? "0{$lsec}" : $lsec;
            $end = "{$lms['0']}:{$lsec}";
            $text = trim($rows[$i]->next_sibling()->plaintext);
            $i++;
            $sub .= "{$i}" . PHP_EOL;
            $sub .= "00:{$start},000 --> 00:{$end},990" . PHP_EOL;
            $sub .= "{$text}" . PHP_EOL . PHP_EOL;
        }
        to_srt($sub, $dir, str_pure($title));
        $j++;
    }
}