Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript

fix: normalize subtitles path

Christian Feibf110bcfe66a
diff --git a/lib/update-videos.js b/lib/update-videos.js
index 1d36818..2f2bd0f 100644
--- a/lib/update-videos.js
+++ b/lib/update-videos.js
@@ -9,7 +9,7 @@ export async function updateAndPersistVideos (repo, callback = () => {}) {
export async function updateAndPersistVideosForChannel(name, repo, callback = () => {}) {
let videos = await getVideosFor(name)
- console.log('received videos for ', name, videos?.length)
+ // console.log('received videos for ', name, videos?.length)
if (videos) {
videos = videos.map(v => repo.patchVideo(v))
repo.upsertVideos(videos)
diff --git a/lib/youtube.js b/lib/youtube.js
index 280d517..b1eda7b 100644
--- a/lib/youtube.js
+++ b/lib/youtube.js
@@ -31,7 +31,9 @@ export async function downloadVideo(id, repo, callback = () => {}) {
repo.upsertVideos([video])
callback(`downloaded external video ${id}`)
}
-
+
+ normalizeSubtitleFiles(id)
+
repo.setVideoDownloaded(id)
console.log('Download completed')
resolve(id)
@@ -57,6 +59,7 @@ export async function getVideoSubtitles (id, callback = () => {}) {
callback(line)
}
}
+ normalizeSubtitleFiles(id)
const transcript = fs.readFileSync(transcriptPath, 'utf-8')
resolve(transcript)
} catch (error) {
@@ -66,9 +69,24 @@ export async function getVideoSubtitles (id, callback = () => {}) {
})
}
+function normalizeSubtitleFiles (id) {
+ const files = fs.readdirSync('./data/videos')
+ files.forEach(file => {
+ if (file.startsWith(id) && file.endsWith('.srt')) {
+ if (!file.endsWith('.en.srt')) {
+ fs.renameSync(`./data/videos/${file}`, `./data/videos/${id}.en.srt`)
+ }
+ }
+ if (file.startsWith(id) && file.endsWith('.vtt')) {
+ if (!file.endsWith('.en.vtt')) {
+ fs.renameSync(`./data/videos/${file}`, `./data/videos/${id}.en.vtt`)
+ }
+ }
+ })
+}
export async function getVideosFor(channelName) {
try {
- console.log('fetching videos for', channelName)
+ // console.log('fetching videos for', channelName)
const response = await fetch(`https://www.youtube.com/${channelWithAt(channelName)}/videos`, {
headers: fetchYoutubeHeaders
})