Skip to content

Commit

Permalink
code refactoring, fixed playlist downloads sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopiovanello committed Oct 19, 2023
1 parent 2d75030 commit da4aaea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions frontend/src/components/DownloadDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
useState,
useTransition
} from 'react'
import { useRecoilValue } from 'recoil'
import { useRecoilState, useRecoilValue } from 'recoil'
import { settingsState } from '../atoms/settings'
import { availableDownloadPathsState, connectedState } from '../atoms/status'
import FormatsGrid from '../components/FormatsGrid'
Expand All @@ -40,6 +40,7 @@ import { useRPC } from '../hooks/useRPC'
import { CliArguments } from '../lib/argsParser'
import type { DLMetadata } from '../types'
import { isValidURL, toFormatArgs } from '../utils'
import { downloadTemplateState } from '../atoms/downloadTemplate'

const Transition = forwardRef(function Transition(
props: TransitionProps & {
Expand Down Expand Up @@ -72,7 +73,7 @@ export default function DownloadDialog({
const [pickedAudioFormat, setPickedAudioFormat] = useState('')
const [pickedBestFormat, setPickedBestFormat] = useState('')

const [customArgs, setCustomArgs] = useState(localStorage.getItem("last-input-args")||'')
const [customArgs, setCustomArgs] = useRecoilState(downloadTemplateState)
const [downloadPath, setDownloadPath] = useState(0)

const [fileNameOverride, setFilenameOverride] = useState('')
Expand Down
7 changes: 5 additions & 2 deletions server/handlers/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ func Login(w http.ResponseWriter, r *http.Request) {
return
}

cfg := config.Instance().GetConfig()
var (
username = config.Instance().GetConfig().Username
password = config.Instance().GetConfig().Password
)

if cfg.Username != req.Username || cfg.Password != req.Password {
if username != req.Username || password != req.Password {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
Expand Down
11 changes: 8 additions & 3 deletions server/internal/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ type metadata struct {
}

func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB) error {
cmd := exec.Command(config.Instance().GetConfig().DownloaderPath, req.URL, "-J")
var (
downloader = config.Instance().GetConfig().DownloaderPath
cmd = exec.Command(downloader, req.URL, "-J")
)

stdout, err := cmd.StdoutPipe()
if err != nil {
Expand Down Expand Up @@ -51,7 +54,9 @@ func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB) error {
cli.BgGreen, "Playlist detected", cli.Reset, m.Count, "entries",
)

for _, meta := range m.Entries {
for i, meta := range m.Entries {
delta := time.Second.Microseconds() * int64(i+1)

proc := &Process{
Url: meta.OriginalURL,
Progress: DownloadProgress{},
Expand All @@ -61,7 +66,7 @@ func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB) error {
}

proc.Info.URL = meta.OriginalURL
proc.Info.CreatedAt = time.Now().Add(time.Second)
proc.Info.CreatedAt = time.Now().Add(time.Duration(delta))

db.Set(proc)
proc.SetPending()
Expand Down

0 comments on commit da4aaea

Please sign in to comment.