|
15 | 15 | #------------------------------------------------------- |
16 | 16 | # youtube-viewer |
17 | 17 | # Created on: 02 June 2010 |
18 | | -# Latest edit on: 11 August 2024 |
| 18 | +# Latest edit on: 23 August 2024 |
19 | 19 | # https://github.com/trizen/youtube-viewer |
20 | 20 | #------------------------------------------------------- |
21 | 21 |
|
@@ -360,6 +360,7 @@ my %CONFIG = ( |
360 | 360 | merge_into_mkv => undef, # auto-defined later |
361 | 361 | merge_into_mkv_args => '-loglevel warning -c:s srt -c:v copy -c:a copy -disposition:s forced', |
362 | 362 | merge_with_captions => 1, |
| 363 | + set_mtime => $constant{win32} ^ 1, |
363 | 364 |
|
364 | 365 | video_filename_format => '*FTITLE* - *ID*.*FORMAT*', |
365 | 366 | ); |
@@ -914,6 +915,7 @@ usage: $execname [options] ([url] | [keywords]) |
914 | 915 | --fat32safe! : makes filenames FAT32 safe |
915 | 916 | --mkv-merge! : merge audio and video into an MKV container |
916 | 917 | --merge-captions! : include closed-captions in the MKV container |
| 918 | + --set-mtime! : set the original file modification time |
917 | 919 |
|
918 | 920 | * Convert |
919 | 921 | --convert-cmd=s : command for converting videos after download |
@@ -1866,6 +1868,7 @@ sub parse_arguments { |
1866 | 1868 |
|
1867 | 1869 | 'merge-into-mkv|mkv-merge!' => \$opt{merge_into_mkv}, |
1868 | 1870 | 'merge-with-captions|merge-captions!' => \$opt{merge_with_captions}, |
| 1871 | + 'set-mtime|mtime!' => \$opt{set_mtime}, |
1869 | 1872 |
|
1870 | 1873 | 'convert-command|convert-cmd=s' => \$opt{convert_cmd}, |
1871 | 1874 | 'dash-segmented!' => \$opt{dash_segmented}, |
@@ -4272,7 +4275,7 @@ sub download_video { |
4272 | 4275 |
|
4273 | 4276 | if (not $opt{keep_original_video}) { |
4274 | 4277 | 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"; |
4276 | 4279 | } |
4277 | 4280 |
|
4278 | 4281 | $video_filename = $convert_filename if -e $convert_filename; |
@@ -4311,6 +4314,20 @@ sub download_video { |
4311 | 4314 | File::Copy::cp($from, $to); |
4312 | 4315 | } |
4313 | 4316 |
|
| 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 | + |
4314 | 4331 | return 1; |
4315 | 4332 | } |
4316 | 4333 |
|
@@ -5640,6 +5657,10 @@ The C<safeSearch> option indicates whether the search results should include res |
5640 | 5657 |
|
5641 | 5658 | Valid values: "strict", "moderate", "none". |
5642 | 5659 |
|
| 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 | +
|
5643 | 5664 | =head2 show_video_info |
5644 | 5665 |
|
5645 | 5666 | Show extra info for videos when selected. |
|
0 commit comments