Destinations are now DownloadOptions
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -27,7 +26,7 @@ type Download struct {
|
||||
ExitCode int `json:"exit_code"`
|
||||
State State `json:"state"`
|
||||
DownloadProfile config.DownloadProfile `json:"download_profile"`
|
||||
Destination *config.Destination `json:"destination"`
|
||||
DownloadOption *config.DownloadOption `json:"download_option"`
|
||||
Finished bool `json:"finished"`
|
||||
FinishedTS time.Time `json:"finished_ts"`
|
||||
Files []string `json:"files"`
|
||||
@@ -82,7 +81,6 @@ func (m *Manager) ManageQueue() {
|
||||
m.Lock.Lock()
|
||||
|
||||
m.startQueued(m.MaxPerDomain)
|
||||
m.moveToDest()
|
||||
m.cleanup()
|
||||
m.Lock.Unlock()
|
||||
|
||||
@@ -102,32 +100,6 @@ func (m *Manager) DownloadsAsJSON() ([]byte, error) {
|
||||
return b, err
|
||||
}
|
||||
|
||||
func (m *Manager) moveToDest() {
|
||||
|
||||
// move any downloads that are complete and have a dest
|
||||
for _, dl := range m.Downloads {
|
||||
|
||||
dl.Lock.Lock()
|
||||
if dl.Destination != nil && dl.State == STATE_COMPLETE {
|
||||
dl.State = STATE_MOVED
|
||||
for _, fn := range dl.Files {
|
||||
src := filepath.Join(dl.Config.Server.DownloadPath, fn)
|
||||
dst := filepath.Join(dl.Destination.Path, fn)
|
||||
err := os.Rename(src, dst)
|
||||
if err != nil {
|
||||
log.Printf("%s", err)
|
||||
dl.Log = append(dl.Log, fmt.Sprintf("Could not move %s to %s - %s", fn, dl.Destination.Path, err))
|
||||
break
|
||||
} else {
|
||||
dl.Log = append(dl.Log, fmt.Sprintf("Moved %s to %s", fn, dl.Destination.Path))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
dl.Lock.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// startQueued starts any downloads that have been queued, we would not exceed
|
||||
// maxRunning. If maxRunning is 0, there is no limit.
|
||||
func (m *Manager) startQueued(maxRunning int) {
|
||||
@@ -202,17 +174,6 @@ func (m *Manager) Queue(dl *Download) {
|
||||
dl.State = STATE_QUEUED
|
||||
}
|
||||
|
||||
func (m *Manager) ChangeDestination(dl *Download, dest *config.Destination) {
|
||||
dl.Lock.Lock()
|
||||
// we can only change destination is certain cases...
|
||||
if dl.State != STATE_FAILED && dl.State != STATE_MOVED {
|
||||
dl.Destination = dest
|
||||
}
|
||||
|
||||
dl.Lock.Unlock()
|
||||
|
||||
}
|
||||
|
||||
func NewDownload(url string, conf *config.Config) *Download {
|
||||
atomic.AddInt32(&downloadId, 1)
|
||||
dl := Download{
|
||||
|
||||
@@ -237,15 +237,15 @@ func TestUpdateMetadataPlaylist(t *testing.T) {
|
||||
|
||||
output := `
|
||||
start of log...
|
||||
[download] Downloading playlist: niceuser
|
||||
[RedGifsUser] niceuser: Downloading JSON metadata page 1
|
||||
[RedGifsUser] niceuser: Downloading JSON metadata page 2
|
||||
[RedGifsUser] niceuser: Downloading JSON metadata page 3
|
||||
[RedGifsUser] niceuser: Downloading JSON metadata page 4
|
||||
[RedGifsUser] niceuser: Downloading JSON metadata page 5
|
||||
[RedGifsUser] niceuser: Downloading JSON metadata page 6
|
||||
[info] Writing playlist metadata as JSON to: niceuser [niceuser].info.json
|
||||
[RedGifsUser] playlist niceuser: Downloading 3 videos
|
||||
[download] Downloading playlist: nice_user
|
||||
[RedGifsUser] nice_user: Downloading JSON metadata page 1
|
||||
[RedGifsUser] nice_user: Downloading JSON metadata page 2
|
||||
[RedGifsUser] nice_user: Downloading JSON metadata page 3
|
||||
[RedGifsUser] nice_user: Downloading JSON metadata page 4
|
||||
[RedGifsUser] nice_user: Downloading JSON metadata page 5
|
||||
[RedGifsUser] nice_user: Downloading JSON metadata page 6
|
||||
[info] Writing playlist metadata as JSON to: nice_user [nice_user].info.json
|
||||
[RedGifsUser] playlist nice_user: Downloading 3 videos
|
||||
[download] Downloading video 1 of 3
|
||||
[info] wrongpreciouschrysomelid: Downloading 1 format(s): hd
|
||||
[info] Writing video metadata as JSON to: Splendid Wonderful Speaker Power Chocolate Drop [wrongpreciouschrysomelid].info.json
|
||||
@@ -279,8 +279,8 @@ start of log...
|
||||
[download] 69.1% of 2.89MiB at 11.63MiB/s ETA 00:00
|
||||
[download] 100% of 2.89MiB at 14.25MiB/s ETA 00:00
|
||||
[download] 100% of 2.89MiB in 00:00
|
||||
[info] Writing updated playlist metadata as JSON to: niceuser [niceuser].info.json
|
||||
[download] Finished downloading playlist: niceuser
|
||||
[info] Writing updated playlist metadata as JSON to: nice_user [nice_user].info.json
|
||||
[download] Finished downloading playlist: nice_user
|
||||
`
|
||||
newD := Download{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user