@@ -10,7 +10,7 @@ import { genTaskOutputFiles, getFFmpegParaArray } from '@common/getFFmpegParaArr
1010import { defaultParams } from '@common/defaultParams' ;
1111import localConfig from '@common/localConfig' ;
1212import { parseFFmpegCodecsToCodecsList , parseFFmpegMuDeMuxersToList } from '@common/params/parser' ;
13- import { getInitialServiceTask , convertAnyTaskToTask , TypedEventEmitter , replaceOutputParams , randomString , getOutputDuration , parseTimeString } from '@common/utils' ;
13+ import { getInitialServiceTask , convertAnyTaskToTask , TypedEventEmitter , replaceOutputParams , randomString , getOutputDuration , parseTimeString , getOutputFileTime } from '@common/utils' ;
1414import { getMachineId , log } from './utils' ;
1515import { FFmpeg } from './FFmpegInvoke' ;
1616import UIBridge from './uiBridge' ;
@@ -33,7 +33,7 @@ export class FFBoxService extends (EventEmitter as new () => TypedEventEmitter<F
3333 private globalTask : ServiceTask ;
3434 public notifications : Notification [ ] = [ ] ;
3535 private latestNotificationId = 0 ;
36- private functionLevel = 20 ;
36+ public functionLevel = 20 ;
3737 public machineId : string ;
3838 // 设置部分
3939 private maxThreads = 1 ;
@@ -690,59 +690,22 @@ export class FFBoxService extends (EventEmitter as new () => TypedEventEmitter<F
690690 if ( mux . keepFileTime ) {
691691 try {
692692 // 如果输入文件不可读取,或者 utimes 失败,或者 FFBox 无法正确计算文件时间,都会产生 hasTimeError
693- const originalFilePath = task . after . input . files [ 0 ] ?. filePath ;
694- // await fsPromise.access(originalFilePath, fs.constants.R_OK);
695- const { accessTime, createTime, modifyTime } = task . before ;
696- // const { atime, birthtime, mtime } = fs.statSync(originalFilePath);
697- log . info ( `[任务 ${ id } ] 将按照首个输入文件的时间修改任务时间。原创建时间 ${ new Date ( createTime ) . toISOString ( ) } ;原修改时间 ${ new Date ( modifyTime ) . toISOString ( ) } ;原访问时间 ${ new Date ( accessTime ) . toISOString ( ) } 。` ) ;
698- if ( mux . keepFileTime === 'original' ) {
699- // 原样复制文件时间。输出文件的创建时间、修改时间、访问时间将从输入文件的时间原样复制
693+ const { accessTime, createTime, modifyTime, ok } = getOutputFileTime ( task , i ) ;
694+ if ( ok ) {
695+ log . info ( `[任务 ${ id } ] 将按照首个输入文件的时间修改任务时间。新创建时间 ${ new Date ( createTime ) . toISOString ( ) } ;新修改时间 ${ new Date ( modifyTime ) . toISOString ( ) } ;新访问时间 ${ new Date ( accessTime ) . toISOString ( ) } 。` ) ;
700696 await utimes ( outputFilePath , { btime : createTime , mtime : modifyTime , atime : accessTime } ) ;
701697 } else {
702- const startTime1 = parseTimeString ( task . after . input . files [ 0 ] . begin ) ;
703- const startTime2 = parseTimeString ( mux . begin ) ;
704- const startTime = ( ( startTime1 === - 1 ? 0 : startTime1 ) + ( startTime2 === - 1 ? 0 : startTime2 ) ) * 1000 ;
705- const duration = ( getOutputDuration ( task ) || 0 ) * 1000 ; // 假设 getOutputDuration 可接收 index
706- if ( mux . keepFileTime === 'autoShift' ) {
707- // 复制修正后的文件时间(依创建时间)。输出文件的创建时间、修改时间将以创建时间为基准,按照剪裁位置自动调整后进行修改
708- const newCreateTime = createTime + startTime ;
709- const newModifyTime = createTime + startTime + duration ;
710- await utimes ( outputFilePath , { btime : newCreateTime , mtime : newModifyTime , atime : accessTime } ) ;
711- } else if ( mux . keepFileTime === 'fixCTbyMTandShift' && task . before . duration > 0 ) {
712- // 复制修正后的文件时间(依修改时间)。输出文件的创建时间、修改时间将以修改时间为基准,按照剪裁位置自动调整后进行修改,用于修复拷贝后创建时间丢失的问题
713- const newCreateTime = modifyTime - task . before . duration * 1000 + startTime ;
714- const newModifyTime = modifyTime - task . before . duration * 1000 + startTime + duration ;
715- await utimes ( outputFilePath , { btime : newCreateTime , mtime : newModifyTime , atime : accessTime } ) ;
716- } else if ( mux . keepFileTime === 'fixByFilenameAndShift' ) {
717- // 根据文件名修正新文件时间。用于修复文件时间丢失的问题,将通过文件名作为创建时间,根据剪裁位置自动调整后进行修改
718- const regExp1 = / ( \d \d \d \d ) .? ( [ 0 1 ] \d ) .? ( [ 0 1 2 3 ] \d ) .? ( [ 0 1 2 ] \d ) .? ( [ 0 - 5 ] \d ) .? ( [ 0 - 5 ] \d ) ? / ;
719- const regExp2 = / ( \d \d \d \d ) ? 年 ? ? ( [ 0 1 ] ? \d ) ? 月 ? ? ( [ 0 1 2 3 ] ? \d ) ? 日 ? ? ( [ 0 1 2 ] ? \d ) ? 时 ? ? ( [ 0 - 5 ] ? \d ) ? 分 ? ? ( [ 0 - 5 ] ? \d ) ? ? 秒 ? ? / ;
720- const r = originalFilePath . match ( regExp1 ) || originalFilePath . match ( regExp2 ) ;
721- if ( r ) {
722- const oldCreateTime = new Date ( `${ r [ 1 ] } -${ r [ 2 ] } -${ r [ 3 ] } ${ r [ 4 ] } :${ r [ 5 ] } :${ r [ 6 ] || 0 } ` ) ;
723- if ( ! isNaN ( oldCreateTime . getTime ( ) ) ) {
724- const newCreateTime = oldCreateTime . getTime ( ) + startTime ;
725- const newModifyTime = oldCreateTime . getTime ( ) + startTime + duration ;
726- await utimes ( outputFilePath , { btime : newCreateTime , mtime : newModifyTime , atime : accessTime } ) ;
727- } else {
728- hasTimeError . push ( outputFilePath ) ;
729- }
730- } else {
731- hasTimeError . push ( outputFilePath ) ;
732- }
733- } else {
734- hasTimeError . push ( outputFilePath ) ;
735- }
698+ hasTimeError . push ( i + 1 + '' ) ;
736699 }
737700 } catch ( error ) {
738- hasTimeError . push ( task . outputFiles [ i ] ) ;
701+ hasTimeError . push ( i + 1 + '' ) ;
739702 }
740703 }
741704 }
742705 task . status = TaskStatus . finished ;
743706 task . progressLog . elapsed = new Date ( ) . getTime ( ) / 1000 - task . progressLog . lastStarted ;
744707 if ( hasTimeError . length ) {
745- this . setNotification ( id , ' 任务「' + task . taskName + ' 」已转码完成,但修改文件时间失败。请检查文件权限。' , NotificationLevel . warning ) ;
708+ this . setNotification ( id , ` 任务「${ task . taskName } 」已转码完成,但修改第 ${ hasTimeError . join ( ' ' ) } 个文件时间失败。` , NotificationLevel . warning ) ;
746709 } else {
747710 this . setNotification ( id , `任务「${ task . taskName } 」已转码完成` , NotificationLevel . ok ) ;
748711 }
@@ -1120,7 +1083,7 @@ export class FFBoxService extends (EventEmitter as new () => TypedEventEmitter<F
11201083 this . notifications [ notificationId ] = notification ;
11211084 }
11221085
1123- public activate ( activationCode : string ) : boolean {
1086+ private activate ( activationCode : string ) : boolean {
11241087 const fixedCode = 'd324c697ebfc42b7' ;
11251088 const key = this . machineId + fixedCode ;
11261089 const decrypted = CryptoJS . AES . decrypt ( activationCode , key ) ;
0 commit comments