Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Commit

Permalink
Add tests for cleaned title
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Nov 30, 2018
1 parent 97cec53 commit a43c352
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Provider/Youtube/VideoInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,17 @@ public function getTitle()
*/
public function getCleanedTitle()
{
$filename = $this->getTitle();

// Removes non-alphanumeric and useless character
$special_chars = ['.', '?', '[', ']', '/', '\\', '=', '<', '>', ':', ';', ',', "'", '"', '&', '$', '#', '*', '(', ')', '|', '~', '`', '!', '{', '}', '%', '+', chr(0)];
$filename = str_replace($special_chars, ' ', $this->getTitle());
$filename = str_replace($special_chars, ' ', $filename);

// Emoji is being removed
// FIXME: not working atm
$filename = preg_replace("#\x{00a0}#siu", ' ', $filename);

// Litlle Housekeeping
// Little Housekeeping
$filename = str_replace(['%20', '+', ' '], '-', $filename);
$filename = preg_replace('/[\r\n\t -]+/', '-', $filename);
$filename = trim($filename, '.-_');
Expand Down
15 changes: 14 additions & 1 deletion tests/Unit/Provider/Youtube/VideoInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,20 @@ public function CleanedTitleProvider()
{
return [
['Replaces all spaces with hyphens.', 'Replaces-all-spaces-with-hyphens'],
['Как делать бэкапы. Cobian Backup.', 'Как-делать-бэкапы-Cobian-Backup'], // Removes useless chars.
['Как делать бэкапы. Cobian Backup.', 'Как-делать-бэкапы-Cobian-Backup'], // Keep kyril chars
['测试', '测试'], // Keep chinese chars
['kiểm tra', 'kiểm-tra'],
['ทดสอบ', 'ทดสอบ'], // Keep korean chars
['טעסטינג', 'טעסטינג'], // Keep jiddish chars
['اختبارات', 'اختبارات'], // Keep arab chars
['test.?[]/\\=<>:;,\'"%26$#*()|~`!{}%+chars', 'test-chars'], // %26 => &
['replace%20space', 'replace-space'], // %20 => " " (space)
["remove\ttabs", 'remove-tabs'],
["remove\rlinebreaks", 'remove-linebreaks'],
["remove\nline-breaks", 'remove-line-breaks'],
["remove-\r\n-linebreaks", 'remove-linebreaks'],
// ['remove\xf0\x9f\x98\x80emojis', 'remove-emojis'], // not working
// ['remove😍emojis', 'remove-emojis'], // not working
];
}

Expand Down

0 comments on commit a43c352

Please sign in to comment.