| | 72 | |
| | 73 | // Converts the filename to the title and cleans it up a little |
| | 74 | // This is a direct port of the C++ code from mythvideo |
| | 75 | function filenametotitle($filename) { |
| | 76 | |
| | 77 | $title = substr($filename, 0, strripos($filename, '.')); |
| | 78 | |
| | 79 | $title = str_replace('_', ' ', $title); |
| | 80 | $title = str_replace('%20', ' ', $title); |
| | 81 | $title = str_replace('.', ' ', $title); |
| | 82 | |
| | 83 | $title = eatbraces($title, '[', ']'); |
| | 84 | $title = eatbraces($title, '(', ')'); |
| | 85 | $title = eatbraces($title, '{', '}'); |
| | 86 | |
| | 87 | return trim($title); |
| | 88 | } |
| | 89 | |
| | 90 | // Strips out braces and the text inside the braces. |
| | 91 | // This is a direct port of the C++ code from mythvideo |
| | 92 | function eatbraces($str, $left_brace, $right_brace) { |
| | 93 | $keep_checking = TRUE; |
| | 94 | |
| | 95 | while ($keep_checking) { |
| | 96 | $left_position = stripos($str, $left_brace); |
| | 97 | $right_position = stripos($str, $right_brace); |
| | 98 | |
| | 99 | // No matching pairs left |
| | 100 | if ($left_position === FALSE || $right_position === FALSE) |
| | 101 | $keep_checking = FALSE; |
| | 102 | |
| | 103 | // Matching set: () |
| | 104 | elseif ($left_position < $right_position) |
| | 105 | $str = substr($str, 0, $left_postion) + substr($str, $right_position); |
| | 106 | |
| | 107 | // Matching set: )( |
| | 108 | elseif ($left_position > $right_position) |
| | 109 | $str = substr($str, 0, $right_postion) + substr($str, $left_position); |
| | 110 | } |
| | 111 | return $str; |
| | 112 | } |
| | 113 | |