Skip to content

armgit / my-yt

Public Imported from GitHub
0

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

JavaScript

chore: more logs in repo

Christian Fei2ccab2ac2db2
diff --git a/lib/repository.js b/lib/repository.js
index 68c0d98..916f533 100644
--- a/lib/repository.js
+++ b/lib/repository.js
@@ -30,10 +30,11 @@ export default class Repository {
}
fs.readdirSync(`${this.basePath}/videos`).forEach(file => {
- if (!file.endsWith('.mp4')) return
+ if (!file.endsWith('.mp4') || file.endsWith('.uncut.mp4')) return
const videoId = file.replace('.mp4', '')
this.setVideoDownloaded(videoId)
})
+ this.saveVideos()
}
getChannels () { return this.channels }
@@ -42,21 +43,28 @@ export default class Repository {
}
addChannel (name) {
this.channels.push({name})
+ console.log('adding channel', name)
this.saveChannels()
}
saveChannels() {
fs.writeFileSync(this.paths.channels, JSON.stringify(this.channels, null, 2))
+ console.log('saving channels', this.channels.length)
}
getVideos () {
- return this.videos
+ const videos = this.videos
.sort((a, b) => +new Date(b.publishedAt) - +new Date(a.publishedAt))
.sort((a, b) => (b.ignored ? -1 : 0) + (a.ignored ? 1 : 0))
.filter((_, i) => i < 500)
+
+ console.log('get videos', videos.length)
+
+ return videos
}
getVideo(id) {
return this.videos.find(v => v.id === id)
}
getChannelVideos (name) {
+ console.log('get channel videos', name)
return this.videos.filter(v => v.channelName === name)
}
upsertVideos(videos) {
@@ -64,9 +72,10 @@ export default class Repository {
.forEach(v => {
const index = this.videos.findIndex(video => video.id === v.id)
if (index !== -1) {
- this.videos[index] = v
+ this.videos[index] = Object.assign(this.videos[index], v)
} else {
this.videos.push(v)
+ console.log('upsert video, insert', v.id)
}
})
this.saveVideos()
@@ -77,20 +86,27 @@ export default class Repository {
Object.assign(this.videos[index], update)
this.saveVideos()
return this.videos[index]
+ } else {
+ console.log('cannot update video, video does not exist', id)
}
}
deleteVideo(id) {
+ this.videos = this.videos.map(v => {
+ if (v.id === id) {
+ console.log('deleting video', id)
+ return Object.assign(v, {downloaded: false})
+ }
+ return v
+ })
+ this.saveVideos()
+
const files = fs.readdirSync(`${this.basePath}/videos`)
files.forEach(file => {
if (file.startsWith(id)) {
+ console.log('deleting video file', file)
fs.unlinkSync(`${this.basePath}/videos/${file}`)
}
})
- this.videos = this.videos.map(v => {
- if (v.id === id) return Object.assign(v, {downloaded: false})
- return v
- })
- this.saveVideos()
}
saveVideos() {
fs.writeFileSync(this.paths.videos, JSON.stringify(this.videos, null, 2))
@@ -100,17 +116,23 @@ export default class Repository {
let ignored = false
if (index !== -1) {
ignored = this.videos[index].ignored = !this.videos[index].ignored
+ console.log('set video ignored', id, ignored)
+ } else {
+ console.log('cannot set video ignored, video does not exist', id)
}
this.saveVideos()
return ignored
}
setVideoTranscript(id, transcript = '') {
+ console.log('set video transcript', id)
return this.updateVideo(id, {transcript})
}
setVideoSummary(id, summary = '') {
+ console.log('set video summary', id)
return this.updateVideo(id, {summary})
}
setVideoDownloaded(id, downloaded = true) {
+ console.log('set video downloaded', id)
return this.updateVideo(id, {downloaded})
}
patchVideo(video) {