Compare commits
No commits in common. "d0ed29e685e7043154973025c8dff00240ba76e6" and "474c24e05affd6452435c471e60c9f1091c12b5a" have entirely different histories.
d0ed29e685
...
474c24e05a
3 changed files with 3 additions and 62 deletions
|
@ -36,9 +36,6 @@ create_ydl_fn = {
|
|||
|
||||
ydl_fn_keys = create_ydl_fn.keys()
|
||||
|
||||
# need process=True for track title in extract_info output
|
||||
NP_YDLS = {'yandex'}
|
||||
|
||||
|
||||
class Downloader:
|
||||
|
||||
|
@ -54,7 +51,6 @@ class Downloader:
|
|||
}
|
||||
|
||||
self.cur_ydl: YoutubeDL | None = None
|
||||
self.cur_site = ''
|
||||
|
||||
self.progress_cb = progress_cb
|
||||
self.lyrics_cb = lyrics_cb
|
||||
|
@ -75,7 +71,6 @@ class Downloader:
|
|||
ydl.params['cookiefile'] = str(cookies)
|
||||
|
||||
self.cur_ydl = ydl
|
||||
self.cur_site = site
|
||||
|
||||
def get_cur_ydl(self) -> YoutubeDL:
|
||||
|
||||
|
@ -91,13 +86,12 @@ class Downloader:
|
|||
Downloader._target_get_playlist_items,
|
||||
self.get_cur_ydl(),
|
||||
url,
|
||||
self.cur_site in NP_YDLS,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _target_get_playlist_items(ydl: YoutubeDL, url: str, process: bool) -> list[str]:
|
||||
def _target_get_playlist_items(ydl: YoutubeDL, url: str) -> list[str]:
|
||||
|
||||
info = ydl.extract_info(url, download=False, process=process)
|
||||
info = ydl.extract_info(url, download=False, process=True)
|
||||
if info is None:
|
||||
raise RuntimeError('ydl.extract_info returned None')
|
||||
return [
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</div>
|
||||
<div id="items-container"></div>
|
||||
<div>
|
||||
<button type="button" id="dl-btn">Download</button>
|
||||
<button type="button">Download</button>
|
||||
</div>
|
||||
<div>
|
||||
<label>Progress: <span id="progress">not implemented</span></label>
|
||||
|
|
|
@ -15,57 +15,4 @@ addEventListener('DOMContentLoaded', () => {
|
|||
site.value = 'yandex'
|
||||
}
|
||||
})
|
||||
|
||||
const socket = new WebSocket('ws://127.0.0.1:4009')
|
||||
|
||||
const itemsDiv = document.getElementById('items-container')
|
||||
let items = []
|
||||
|
||||
document.getElementById('items-btn').addEventListener('click', () => {
|
||||
socket.send(JSON.stringify({
|
||||
action: 'list',
|
||||
site: site.value,
|
||||
url: urlField.value,
|
||||
}))
|
||||
})
|
||||
|
||||
document.getElementById('dl-btn').addEventListener('click', () => {
|
||||
socket.send(JSON.stringify({
|
||||
action: 'download',
|
||||
site: site.value,
|
||||
url: urlField.value,
|
||||
items: items,
|
||||
}))
|
||||
items = []
|
||||
})
|
||||
|
||||
socket.addEventListener('message', ev => {
|
||||
const msg = JSON.parse(ev.data)
|
||||
switch (msg.type) {
|
||||
case 'items':
|
||||
itemsDiv.textContent = '' // clear
|
||||
const len = msg.data.length
|
||||
for (let i = 1; i <= len; i++) {
|
||||
const itemElem = document.createElement('label')
|
||||
const itemCheckbox = document.createElement('input')
|
||||
itemCheckbox.type = 'checkbox'
|
||||
itemCheckbox.addEventListener('change', () => {
|
||||
if (itemCheckbox.checked) {
|
||||
items.push(i)
|
||||
} else {
|
||||
items.splice(items.indexOf(i), 1)
|
||||
}
|
||||
})
|
||||
itemElem.append(itemCheckbox)
|
||||
itemText = document.createTextNode(msg.data[i - 1])
|
||||
itemElem.append(itemText)
|
||||
itemsDiv.append(itemElem)
|
||||
}
|
||||
break
|
||||
case 'dl_progress':
|
||||
break
|
||||
case 'dl_end':
|
||||
break
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue