Skip to content

Commit

Permalink
- Extended fat32safe to convert Unicode characters to ASCII equival…
Browse files Browse the repository at this point in the history
…ent when `Text::Unidecode` is available.
  • Loading branch information
trizen committed May 6, 2023
1 parent 2e50448 commit 3324f40
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
27 changes: 12 additions & 15 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ my $builder = Module::Build->new(
'Test::More' => 0,
},

extra_manify_args => { utf8 => 1 },
extra_manify_args => {utf8 => 1},

configure_requires => {
'Module::Build' => 0,
},

get_options => {
'gtk3' => {
type => '!',
store => \$gtk3,
},
},
'gtk3' => {
type => '!',
store => \$gtk3,
},
},

requires => {
'perl' => 5.016,
Expand Down Expand Up @@ -64,21 +64,18 @@ my $builder = Module::Build->new(
},

recommends => {
'LWP::UserAgent::Cached' => 0, # cache support
'Term::ReadLine::Gnu' => 0, # for better STDIN support (+history)
'JSON::XS' => 0, # faster JSON to HASH conversion
'Unicode::GCString' => 0, # fixed-width format
'LWP::UserAgent::Cached' => 0, # cache support
'Term::ReadLine::Gnu' => 0, # for better STDIN support (+history)
'JSON::XS' => 0, # faster JSON to HASH conversion
'Unicode::GCString' => 0, # fixed-width format
'Text::Unidecode' => 0, # for the `fat32safe` option
},

add_to_cleanup => ['WWW-YoutubeViewer-*'],
create_makefile_pl => 'traditional',
);

$builder->script_files(
['bin/youtube-viewer',
($gtk3 ? ('bin/gtk-youtube-viewer') : ()),
]
);
$builder->script_files(['bin/youtube-viewer', ($gtk3 ? ('bin/gtk-youtube-viewer') : ())]);

$builder->share_dir('share') if $gtk3;
$builder->create_build_script();
4 changes: 3 additions & 1 deletion bin/youtube-viewer
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ usage: $execname [options] ([url] | [keywords])
--copy-caption! : copy and rename the caption for downloaded videos
--downloads-dir=s : downloads directory (set: '$opt{downloads_dir}')
--filename=s : set a custom format for the video filename (see: -T)
--fat32safe! : makes filenames FAT32 safe (includes Unicode)
--fat32safe! : makes filenames FAT32 safe
--mkv-merge! : merge audio and video into an MKV container
--merge-captions! : include closed-captions in the MKV container
Expand Down Expand Up @@ -5451,6 +5451,8 @@ Load proxy settings from C<*_proxy> environment variables (if any).
When downloading a video, make the filename compatible with the FAT32 filesystem.
Additionally, if L<Text::Unidecode> is available, then Unicode characters are converted to ASCII equivalents.
=head2 ffmpeg_cmd
Path to the C<ffmpeg> program.
Expand Down
7 changes: 7 additions & 0 deletions lib/WWW/YoutubeViewer/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ sub normalize_filename {
}

if ($fat32safe) {

state $has_unidecode = eval { require Text::Unidecode; 1 };

if ($has_unidecode) {
$title = Text::Unidecode::unidecode($title);
}

$title =~ s/: / - /g;
$title =~ tr{:"*/?\\|}{;'+%!%%}; # "
$title =~ tr/<>//d;
Expand Down

0 comments on commit 3324f40

Please sign in to comment.