Skip to content

armgit / my-yt

Public Imported from GitHub
0

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

JavaScript

feat: filter by only downloaded

Christian Fei08483ed3dc97
diff --git a/client/components/search-videos.js b/client/components/search-videos.js
index 6b8c267..c800114 100644
--- a/client/components/search-videos.js
+++ b/client/components/search-videos.js
@@ -20,17 +20,25 @@ class SearchVideos extends HTMLElement {
registerEvents () {
this.querySelector('#search').addEventListener('input', this.searchHandler.bind(this))
this.querySelector('#with-excluded').addEventListener('change', this.searchHandler.bind(this))
+ this.querySelector('#only-downloaded').addEventListener('change', this.searchHandler.bind(this))
}
unregisterEvents () {
this.querySelector('#search').removeEventListener('input', this.searchHandler.bind(this))
this.querySelector('#with-excluded').removeEventListener('change', this.searchHandler.bind(this))
+ this.querySelector('#only-downloaded').removeEventListener('change', this.searchHandler.bind(this))
}
render () {
this.innerHTML = /*html*/`
<input type="search" incremental="incremental" id="search" placeholder="🔍 Search videos or paste video url" autofocus>
- <div>
- <label for="with-excluded">Search excluded videos</label>
- <input type="checkbox" id="with-excluded"/>
+ <div class="flex">
+ <div class="flex-1">
+ <label for="with-excluded">Show excluded</label>
+ <input type="checkbox" id="with-excluded"/>
+ </div>
+ <div class="flex-1">
+ <label for="only-downloaded">Only downloaded</label>
+ <input type="checkbox" id="only-downloaded"/>
+ </div>
</div>
`
}
@@ -59,8 +67,20 @@ class SearchVideos extends HTMLElement {
searchTerm = searchTerm.toLowerCase()
document.body.classList.add('searching')
let withExcluded = this.querySelector('#with-excluded').checked
+ let onlyDownloaded = this.querySelector('#only-downloaded').checked
- fetch(`/api/videos?filter=${encodeURIComponent(searchTerm)}${withExcluded ? '&excluded=true' : ''}`)
+ if (withExcluded) {
+ this.querySelector('#only-downloaded').disabled = true
+ } else {
+ this.querySelector('#only-downloaded').disabled = false
+ }
+ if (onlyDownloaded) {
+ this.querySelector('#with-excluded').disabled = true
+ } else {
+ this.querySelector('#with-excluded').disabled = false
+ }
+
+ fetch(`/api/videos?filter=${encodeURIComponent(searchTerm)}${withExcluded ? '&excluded=true' : ''}${onlyDownloaded ? '&downloaded=true' : ''}`)
.then(res => res.json())
.then((videos) => {
const $videosContainer = document.querySelector('.main-videos-container')
diff --git a/lib/repository.js b/lib/repository.js
index b6815d3..48358d6 100644
--- a/lib/repository.js
+++ b/lib/repository.js
@@ -77,6 +77,7 @@ export default class Repository {
const isFiltering = Object.keys(query).length > 0 && query.filter
let videos = this.videos
.filter(v => query.excluded === 'true' ? true : this.filterByExcludedTerms(v))
+ .filter(v => query.downloaded === 'true' ? v.downloaded : true)
.filter(v => isFiltering ? true : !v.ignored)
.sort((a, b) => +new Date(b.publishedAt) - +new Date(a.publishedAt))