@@ -20,7 +20,18 @@ function buildMp3(episodeNumber, inputFolder, outputFolder) {
2020 ] ) ;
2121}
2222
23- function buildChapters ( inputFile ) {
23+ function getMediaInfo ( inputFile ) {
24+ return runCommandSync ( 'ffprobe' , [
25+ '-i' , inputFile ,
26+ '-loglevel' , '0' ,
27+ '-hide_banner' ,
28+ '-print_format' , 'json' ,
29+ '-show_chapters' ,
30+ '-show_format' ,
31+ ] ) ;
32+ }
33+
34+ function getChapters ( inputFile ) {
2435 return runCommandSync ( 'ffprobe' , [
2536 '-i' , inputFile ,
2637 '-loglevel' , '0' ,
@@ -31,6 +42,16 @@ function buildChapters(inputFile) {
3142 ] ) ;
3243}
3344
45+ function formatDuration ( seconds ) {
46+ return new Date ( seconds * 1000 ) . toISOString ( ) . slice ( 11 , 19 ) ;
47+ }
48+
49+ function updateYmlDuration ( ymlPath , duration ) {
50+ const content = fs . readFileSync ( ymlPath , 'utf-8' ) ;
51+ const updated = content . replace ( / ^ d u r a t i o n : .* $ / m, `duration: ${ duration } ` ) ;
52+ fs . writeFileSync ( ymlPath , updated ) ;
53+ }
54+
3455function parseTime ( str ) {
3556 return `0${ str } ` . split ( '.' ) [ 0 ] ;
3657}
@@ -70,6 +91,7 @@ const mp3Dir = path.join('src', 'mp3');
7091const mp3Path = path . join ( mp3Dir , `${ episode } .mp3` ) ;
7192const episodeDir = path . join ( 'src' , 'episodes' , episode ) ;
7293const indexPath = path . join ( episodeDir , 'index.txt' ) ;
94+ const ymlPath = path . join ( episodeDir , 'index.yml' ) ;
7395
7496if ( ! fs . existsSync ( wavPath ) ) {
7597 console . error ( `Файл не найден: ${ wavPath } ` ) ;
@@ -86,15 +108,20 @@ fs.mkdirSync(mp3Dir, { recursive: true });
86108buildMp3 ( episode , path . join ( 'src' , 'wav' ) , mp3Dir ) ;
87109console . log ( `Создан: ${ mp3Path } ` ) ;
88110
89- const json = buildChapters ( mp3Path ) ;
90- const parsedJson = JSON . parse ( json ) ;
111+ const mediaInfo = JSON . parse ( getMediaInfo ( mp3Path ) ) ;
112+ const chaptersInfo = JSON . parse ( getChapters ( mp3Path ) ) ;
91113
92- if ( ! parsedJson . chapters ) {
114+ if ( ! chaptersInfo . chapters ) {
93115 console . error ( 'В файле нет глав' ) ;
94116 process . exit ( 1 ) ;
95117}
96118
97119fs . mkdirSync ( episodeDir , { recursive : true } ) ;
98120
99- writeIndexFile ( templatePath , episode , parsedJson . chapters , indexPath ) ;
121+ writeIndexFile ( templatePath , episode , chaptersInfo . chapters , indexPath ) ;
100122console . log ( `Создан: ${ indexPath } ` ) ;
123+
124+ const durationSeconds = parseFloat ( mediaInfo . format . duration ) ;
125+ const duration = formatDuration ( durationSeconds ) ;
126+ updateYmlDuration ( ymlPath , duration ) ;
127+ console . log ( `Обновлён: ${ ymlPath } ` ) ;
0 commit comments