jbilcke-hf HF staff commited on
Commit
f1ee3c6
·
1 Parent(s): bc6f13d

attempt emergency hotfix

Browse files
package.json CHANGED
@@ -5,7 +5,6 @@
5
  "main": "src/index.mts",
6
  "scripts": {
7
  "start": "node --loader ts-node/esm src/index.mts",
8
- "batch:updatePlaylists": "node --loader ts-node/esm src/batch/updatePlaylists.mts",
9
  "batch:interpolate": "node --loader ts-node/esm src/batch/interpolate_legacy.mts",
10
  "docker": "npm run docker:build && npm run docker:run",
11
  "docker:build": "docker build -t media-server .",
 
5
  "main": "src/index.mts",
6
  "scripts": {
7
  "start": "node --loader ts-node/esm src/index.mts",
 
8
  "batch:interpolate": "node --loader ts-node/esm src/batch/interpolate_legacy.mts",
9
  "docker": "npm run docker:build && npm run docker:run",
10
  "docker:build": "docker build -t media-server .",
scripts/channel_random.sh CHANGED
@@ -2,10 +2,11 @@
2
 
3
  echo "Starting FFMPEG live stream for channel random"
4
  while true; do
5
- if [ -f channel_random.txt ] && [ -f channel_1_audio.txt ]; then
 
6
  echo "Files exist, starting stream"
7
  # Note: for now we also use channel 1 for audio!
8
- ffmpeg -y -nostdin -re -f concat -safe 0 -i channel_random.txt -stream_loop -1 -safe 0 -i channel_1_audio.txt -loglevel error -c:v libx264 -preset veryfast -tune zerolatency -c:a aac -ar 44100 -shortest -f flv rtmp://localhost/live/random
9
  else
10
  echo "Files do not exist, waiting for files"
11
  sleep 1 # check every second
 
2
 
3
  echo "Starting FFMPEG live stream for channel random"
4
  while true; do
5
+ # TODO use channel_random.txt
6
+ if [ -f channel_3_video.txt ] && [ -f channel_1_audio.txt ]; then
7
  echo "Files exist, starting stream"
8
  # Note: for now we also use channel 1 for audio!
9
+ ffmpeg -y -nostdin -re -f concat -safe 0 -i channel_3_video.txt -stream_loop -1 -safe 0 -i channel_1_audio.txt -loglevel error -c:v libx264 -preset veryfast -tune zerolatency -c:a aac -ar 44100 -shortest -f flv rtmp://localhost/live/random
10
  else
11
  echo "Files do not exist, waiting for files"
12
  sleep 1 # check every second
scripts/legacy_video3.sh ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ echo "Starting the video collection stream for channel 3.."
4
+ echo "listing files in $WEBTV_VIDEO_STORAGE_PATH_CHANNEL_3*.mp4"
5
+ current_count=0
6
+
7
+ while true; do
8
+ new_count=$(ls $WEBTV_VIDEO_STORAGE_PATH_CHANNEL_3*.mp4 2> /dev/null | wc -l)
9
+
10
+ if [ $new_count -ne $current_count ]; then
11
+ echo "there are $new_count videos files for channel 3"
12
+
13
+ echo "Updating playlist for channel 3.."
14
+ current_count=$new_count
15
+ files=($WEBTV_VIDEO_STORAGE_PATH_CHANNEL_3*.mp4)
16
+
17
+ echo "ffconcat version 1.0" > channel_3_video_tmp.txt
18
+ for (( i=0; i<${#files[@]}; i++ )); do
19
+ echo "file '${files[$i]}'" >> channel_3_video_tmp.txt
20
+ done
21
+ rm channel_3_video.txt
22
+ mv channel_3_video_tmp.txt channel_3_video.txt
23
+ fi
24
+
25
+ # the new playlist will only be updated after the current playlist ended
26
+ # so there is no emergency here
27
+ sleep 60
28
+ done
src/index.mts CHANGED
@@ -9,7 +9,7 @@ import { downloadVideo } from './downloadVideo.mts'
9
  import { getDatabase } from './getDatabase.mts'
10
  import { callMusicgen } from './callMusicgen.mts'
11
  import { interpolateVideo } from './interpolateVideo.mts'
12
- import { updatePlaylists } from './batch/updatePlaylists.mts'
13
 
14
  let hasReachedStartingPoint = false
15
 
 
9
  import { getDatabase } from './getDatabase.mts'
10
  import { callMusicgen } from './callMusicgen.mts'
11
  import { interpolateVideo } from './interpolateVideo.mts'
12
+ import { updatePlaylists } from './updatePlaylists.mts'
13
 
14
  let hasReachedStartingPoint = false
15
 
src/{batch/updatePlaylists.mts → updatePlaylists.mts} RENAMED
@@ -1,13 +1,49 @@
1
  import fs from "fs"
2
  import path from "path"
3
 
4
- import { Database } from "../types.mts"
5
 
6
  export const updatePlaylists = async (db: Database) => {
7
  // TODO we should DROP THE CHANNEL 3 name,
8
  // and only keep WEBTV_VIDEO_STORAGE_PATH
9
  const directoryPath = process.env.WEBTV_VIDEO_STORAGE_PATH_CHANNEL_3
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  // Record of file paths categorized by tags
12
  const categoryToFilePaths: Record<string, string[]> = {}
13
 
@@ -60,36 +96,4 @@ export const updatePlaylists = async (db: Database) => {
60
  console.log(`Created playlist channel_${category}.txt`)
61
  }
62
  }
63
-
64
- // Get all the file paths in the directory
65
- const allFiles = await fs.promises.readdir(directoryPath)
66
- const allFilePaths = allFiles
67
- .map(file => path.join(directoryPath, file))
68
- .filter(filePath => filePath.endsWith('.mp4'))
69
-
70
- // Create channel_random.txt with all files
71
- let randomData = 'ffconcat version 1.0\n'
72
- allFilePaths.forEach(filePath => {
73
- randomData += `file '${filePath}'\n`
74
- })
75
- await fs.promises.writeFile("channel_random.txt", randomData)
76
- console.log("Created playlist channel_random.txt")
77
-
78
- // Filter the list for the last 400 updated files
79
- const lastUpdatedFilePaths = allFilePaths
80
- .map(filePath => ({
81
- filePath,
82
- mtime: fs.statSync(filePath).mtime
83
- }))
84
- .sort((a, b) => b.mtime.getTime() - a.mtime.getTime())
85
- .slice(0, 400)
86
- .map(file => file.filePath)
87
-
88
- // Create channel_fresh.txt
89
- let freshData = 'ffconcat version 1.0\n'
90
- lastUpdatedFilePaths.forEach(filePath => {
91
- freshData += `file '${filePath}'\n`
92
- })
93
- await fs.promises.writeFile("channel_fresh.txt", freshData)
94
- console.log("Created playlist channel_fresh.txt")
95
  }
 
1
  import fs from "fs"
2
  import path from "path"
3
 
4
+ import { Database } from "./types.mts"
5
 
6
  export const updatePlaylists = async (db: Database) => {
7
  // TODO we should DROP THE CHANNEL 3 name,
8
  // and only keep WEBTV_VIDEO_STORAGE_PATH
9
  const directoryPath = process.env.WEBTV_VIDEO_STORAGE_PATH_CHANNEL_3
10
 
11
+ console.log("Generating playlist for all the videos..")
12
+
13
+ // Get all the file paths in the directory
14
+ const allFiles = await fs.promises.readdir(directoryPath)
15
+ const allFilePaths = allFiles
16
+ .map(file => path.join(directoryPath, file))
17
+ .filter(filePath => filePath.endsWith('.mp4'))
18
+
19
+ // Create channel_random.txt with all files
20
+ let randomData = 'ffconcat version 1.0\n'
21
+ allFilePaths.forEach(filePath => {
22
+ randomData += `file '${filePath}'\n`
23
+ })
24
+ await fs.promises.writeFile("channel_random.txt", randomData)
25
+ console.log("Created playlist channel_random.txt")
26
+
27
+ console.log("Generating playlist for the last files..")
28
+ // Filter the list for the last 400 updated files
29
+ const lastUpdatedFilePaths = allFilePaths
30
+ .map(filePath => ({
31
+ filePath,
32
+ mtime: fs.statSync(filePath).mtime
33
+ }))
34
+ .sort((a, b) => b.mtime.getTime() - a.mtime.getTime())
35
+ .slice(0, 400)
36
+ .map(file => file.filePath)
37
+
38
+ // Create channel_fresh.txt
39
+ let freshData = 'ffconcat version 1.0\n'
40
+ lastUpdatedFilePaths.forEach(filePath => {
41
+ freshData += `file '${filePath}'\n`
42
+ })
43
+ await fs.promises.writeFile("channel_fresh.txt", freshData)
44
+ console.log("Created playlist channel_fresh.txt")
45
+
46
+
47
  // Record of file paths categorized by tags
48
  const categoryToFilePaths: Record<string, string[]> = {}
49
 
 
96
  console.log(`Created playlist channel_${category}.txt`)
97
  }
98
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  }
start.sh CHANGED
@@ -28,16 +28,12 @@ sleep 1
28
  bash scripts/audio1.sh &
29
  # bash scripts/audio2.sh &
30
 
31
- # background process that creates a video stream from video files
32
- # bash scripts/video1.sh &
33
- # bash scripts/video2.sh &
34
- # bash scripts/video3.sh &
35
 
36
  sleep 1
37
 
38
  # background process that sends data to the media server
39
- # bash scripts/stream1.sh &
40
- # bash scripts/stream2.sh &
41
  bash scripts/channel_random.sh &
42
  bash scripts/channel_random_twitch.sh &
43
  bash scripts/channel_comedy.sh &
 
28
  bash scripts/audio1.sh &
29
  # bash scripts/audio2.sh &
30
 
31
+ # [LEGACY] background process that creates a video stream from video files
32
+ bash scripts/legacy_video3.sh &
 
 
33
 
34
  sleep 1
35
 
36
  # background process that sends data to the media server
 
 
37
  bash scripts/channel_random.sh &
38
  bash scripts/channel_random_twitch.sh &
39
  bash scripts/channel_comedy.sh &