Skip to content

Commit 4baa91e

Browse files
committed
CLI: added the --set-mtime option and the set_mtime config-option.
Enabled by default on non-Win32. When enabled, it will set the original modification date of a downloaded video, using the published date of the video.
1 parent 75c8b58 commit 4baa91e

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

Build.PL

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ my $builder = Module::Build->new(
5252
'Text::ParseWords' => 0,
5353
'Text::Wrap' => 0,
5454
'URI::Escape' => 0,
55+
'Time::Piece' => 0,
5556

5657
$gtk3
5758
? (

Makefile.PL

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ WriteMakefile
2424
'Test::More' => 0,
2525
'Text::ParseWords' => 0,
2626
'Text::Wrap' => 0,
27+
'Time::Piece' => 0,
2728
'URI::Escape' => 0
2829
},
2930
'INSTALLDIRS' => 'site',

bin/youtube-viewer

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#-------------------------------------------------------
1616
# youtube-viewer
1717
# Created on: 02 June 2010
18-
# Latest edit on: 11 August 2024
18+
# Latest edit on: 23 August 2024
1919
# https://github.com/trizen/youtube-viewer
2020
#-------------------------------------------------------
2121

@@ -360,6 +360,7 @@ my %CONFIG = (
360360
merge_into_mkv => undef, # auto-defined later
361361
merge_into_mkv_args => '-loglevel warning -c:s srt -c:v copy -c:a copy -disposition:s forced',
362362
merge_with_captions => 1,
363+
set_mtime => $constant{win32} ^ 1,
363364

364365
video_filename_format => '*FTITLE* - *ID*.*FORMAT*',
365366
);
@@ -914,6 +915,7 @@ usage: $execname [options] ([url] | [keywords])
914915
--fat32safe! : makes filenames FAT32 safe
915916
--mkv-merge! : merge audio and video into an MKV container
916917
--merge-captions! : include closed-captions in the MKV container
918+
--set-mtime! : set the original file modification time
917919
918920
* Convert
919921
--convert-cmd=s : command for converting videos after download
@@ -1866,6 +1868,7 @@ sub parse_arguments {
18661868

18671869
'merge-into-mkv|mkv-merge!' => \$opt{merge_into_mkv},
18681870
'merge-with-captions|merge-captions!' => \$opt{merge_with_captions},
1871+
'set-mtime|mtime!' => \$opt{set_mtime},
18691872

18701873
'convert-command|convert-cmd=s' => \$opt{convert_cmd},
18711874
'dash-segmented!' => \$opt{dash_segmented},
@@ -4272,7 +4275,7 @@ sub download_video {
42724275

42734276
if (not $opt{keep_original_video}) {
42744277
unlink $video_filename
4275-
or warn colored("\n[!] Can't unlink file '$video_filename': $!", 'bold red') . "\n\n";
4278+
or warn colored("\n[!] Can't unlink file <<$video_filename>>: $!", 'bold red') . "\n\n";
42764279
}
42774280

42784281
$video_filename = $convert_filename if -e $convert_filename;
@@ -4311,6 +4314,20 @@ sub download_video {
43114314
File::Copy::cp($from, $to);
43124315
}
43134316

4317+
# Set original modification timestamp
4318+
if ($opt{set_mtime} and defined($info->{snippet}) and defined($info->{snippet}{publishedAt}) and -f $video_filename) {
4319+
4320+
require Time::Piece;
4321+
4322+
# Format example: 2011-11-15T12:59:30Z
4323+
my $published_time = eval { Time::Piece->strptime($info->{snippet}{publishedAt}, "%Y-%m-%dT%TZ") };
4324+
4325+
if (defined($published_time)) {
4326+
eval { utime(time, $published_time->epoch, $video_filename) }
4327+
|| warn colored("\n[!] Failed to set modification time of <<$video_filename>>: $!", 'bold red') . "\n\n";
4328+
}
4329+
}
4330+
43144331
return 1;
43154332
}
43164333

@@ -5640,6 +5657,10 @@ The C<safeSearch> option indicates whether the search results should include res
56405657
56415658
Valid values: "strict", "moderate", "none".
56425659
5660+
=head2 set_mtime
5661+
5662+
When enabled, it will set the original modification date of a downloaded video, using the published date of the video.
5663+
56435664
=head2 show_video_info
56445665
56455666
Show extra info for videos when selected.

0 commit comments

Comments
 (0)