Skip to content

Commit

Permalink
update imports and fmt to match standard
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob committed Dec 11, 2019
1 parent 14aebe4 commit ebd1099
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 111 deletions.
12 changes: 5 additions & 7 deletions database_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
"io/ioutil"
"os"
"strconv"
"time"

log "github.com/sirupsen/logrus"
)

var db []DownloadTarget
Expand Down Expand Up @@ -60,7 +61,6 @@ func (target DownloadTarget) UpdateDownloadHistory(videoId string) error {
return appendToDownloadHistory(target, videoId, databaseName)
}


func (target DownloadTarget) Delete() error {
databaseName = setDatabaseName(target.Type)
return removeItem(target.URL, databaseName)
Expand Down Expand Up @@ -131,7 +131,6 @@ func getItemFromDatabase(databaseName, targetURL string) (DownloadTarget, error)
return DownloadTarget{}, fmt.Errorf("Couldn't find target")
}


func setDatabaseName(targetType string) string {
if targetType == "Channel" {
return "channels.json"
Expand All @@ -155,11 +154,10 @@ func removeItem(targetURL, databaseName string) error {
return writeDb(db, CONFIG_ROOT+databaseName)
}


func appendToDownloadHistory(target DownloadTarget, videoId, databaseName string) error {
db = openDatabaseAndUnmarshalJSON(databaseName)

for i:= range db {
for i := range db {
if db[i].URL == target.URL {
db[i].DownloadHistory = append(target.DownloadHistory, videoId)
log.Info(db)
Expand All @@ -181,7 +179,7 @@ func addTargetToDatabase(target DownloadTarget, databaseName string) error {
func updateLastCheckedDateAndTime(target DownloadTarget, databaseName string) error {
openDatabaseAndUnmarshalJSON(databaseName)

for i:= range db {
for i := range db {
if db[i].URL == target.URL {
dt := time.Now()
db[i].LastChecked = dt.Format("01-02-2006 15:04:05")
Expand Down Expand Up @@ -240,4 +238,4 @@ func openDatabaseAndUnmarshalJSON(databaseName string) []DownloadTarget {
byteValue, _ := openJSONDatabase(CONFIG_ROOT + databaseName)
json.Unmarshal(byteValue, &db)
return db
}
}
6 changes: 4 additions & 2 deletions database_handlers_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

var targets = []DownloadTarget{
Expand Down Expand Up @@ -56,6 +57,7 @@ func TestDownloadTarget_AddToDatabase(t *testing.T) {
assert.Nil(err)
}
}

//
//func TestDownloadTarget_UpdateLatestDownloaded(t *testing.T) {
// assert := assert.New(t)
Expand Down Expand Up @@ -119,4 +121,4 @@ func TestDownloadTarget_AddToDatabase(t *testing.T) {
// assert.Nil(err)
// }
// }
//}
//}
3 changes: 2 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package main

import (
"encoding/json"
log "github.com/sirupsen/logrus"
"net/http"
"strings"
"time"

log "github.com/sirupsen/logrus"
)

type version struct {
Expand Down
5 changes: 3 additions & 2 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
"io/ioutil"
"net/http"
"os"
"strings"

log "github.com/sirupsen/logrus"
)

func GetAll(target string) ([]DownloadTarget, error) {
Expand Down Expand Up @@ -191,4 +192,4 @@ func reverseVideos(s []DownloadVideoPayload) []DownloadVideoPayload {
s[i], s[j] = s[j], s[i]
}
return s
}
}
4 changes: 1 addition & 3 deletions helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package main



//func TestDownloadTarget_CheckNow(t *testing.T) {
// assert := assert.New(t)
// for _, target := range targets {
Expand All @@ -13,4 +11,4 @@ package main
// err = target.Delete()
// assert.Nil(err)
// }
//}
//}
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package main

import (
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
"io"
"net/http"
"os"
"time"

"github.com/gorilla/handlers"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
)

func initLogFile() {
Expand Down Expand Up @@ -76,7 +77,7 @@ func uploadCheckerPlaylists() {

func main() {
log.Info("server running on port 8080")

go uploadCheckerChannels()
go uploadCheckerPlaylists()

Expand Down
52 changes: 26 additions & 26 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type TargetMetadata struct {
}

type DownloadTarget struct {
URL string
URL string
LatestDownloaded string
DownloadMode string
Name string
Expand All @@ -139,7 +139,7 @@ type DownloadTarget struct {
DownloadHistory []string
LastChecked string
CheckingInterval string
Type string
Type string
DownloadPath string
}

Expand All @@ -148,32 +148,32 @@ type GetTargetPayload struct {
}

type DeleteTargetPayload struct {
URL string
URL string
Type string
}

type CheckingIntervalPayload struct {
CheckingInterval string
Type string
Type string
}

type AddTargetPayload struct {
URL string
DownloadMode string
FileExtension string
DownloadQuality string
DownloadEntire bool
CheckingInterval string
DownloadPath string
Type string
URL string
DownloadMode string
FileExtension string
DownloadQuality string
DownloadEntire bool
CheckingInterval string
DownloadPath string
Type string
}

type DownloadVideoPayload struct {
VideoURL string
DownloadMode string
FileExtension string
DownloadQuality string
DownloadPath string
VideoURL string
DownloadMode string
FileExtension string
DownloadQuality string
DownloadPath string
}

type Response struct {
Expand All @@ -183,18 +183,18 @@ type Response struct {
}

type Video struct {
VideoID string
DownloadMode string
VideoID string
DownloadMode string
DownloadQuality string
FileExtension string
FileExtension string
}

type YTDLCommand struct {
TargetType string
Binary string
FirstFlag string
TargetType string
Binary string
FirstFlag string
FirstFlagArg string
FileType string
Output string
Target string
FileType string
Output string
Target string
}
5 changes: 3 additions & 2 deletions videos_database_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package main
import (
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
"io/ioutil"
"os"

log "github.com/sirupsen/logrus"
)

func (v DownloadVideoPayload) AddToDatabase() error {
Expand Down Expand Up @@ -67,4 +68,4 @@ func writeToVideosDb(db []DownloadVideoPayload, dbName string) error {
}

return nil
}
}
43 changes: 22 additions & 21 deletions videos_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"encoding/json"
log "github.com/sirupsen/logrus"
"net/http"

log "github.com/sirupsen/logrus"
)

func HandleDownloadVideo(w http.ResponseWriter, r *http.Request) {
Expand All @@ -19,41 +20,41 @@ func HandleDownloadVideo(w http.ResponseWriter, r *http.Request) {
if videoData.DownloadPath == "" {
if videoData.DownloadMode == "Audio Only" {
ytdlCommand = YTDLCommand{
Binary: "youtube-dl",
FirstFlag: "",
Binary: "youtube-dl",
FirstFlag: "",
FirstFlagArg: "",
FileType: "bestaudio[ext=" + videoData.FileExtension + "]",
Output: videoData.DownloadPath,
Target: videoData.VideoURL,
FileType: "bestaudio[ext=" + videoData.FileExtension + "]",
Output: videoData.DownloadPath,
Target: videoData.VideoURL,
}
} else if videoData.DownloadMode == "Video And Audio" {
ytdlCommand = YTDLCommand{
Binary: "youtube-dl",
FirstFlag: "",
Binary: "youtube-dl",
FirstFlag: "",
FirstFlagArg: "",
FileType: "bestvideo[ext=" + videoData.FileExtension + "]",
Output: videoData.DownloadPath,
Target: videoData.VideoURL,
FileType: "bestvideo[ext=" + videoData.FileExtension + "]",
Output: videoData.DownloadPath,
Target: videoData.VideoURL,
}
}
} else {
if videoData.DownloadMode == "Audio Only" {
ytdlCommand = YTDLCommand{
Binary: "youtube-dl",
FirstFlag: "",
Binary: "youtube-dl",
FirstFlag: "",
FirstFlagArg: "",
FileType: "bestaudio[ext=" + videoData.FileExtension + "]",
Output: "downloads" + videoData.DownloadPath,
Target: videoData.VideoURL,
FileType: "bestaudio[ext=" + videoData.FileExtension + "]",
Output: "downloads" + videoData.DownloadPath,
Target: videoData.VideoURL,
}
} else if videoData.DownloadMode == "Video And Audio" {
ytdlCommand = YTDLCommand{
Binary: "youtube-dl",
FirstFlag: "",
Binary: "youtube-dl",
FirstFlag: "",
FirstFlagArg: "",
FileType: "bestvideo[ext=" + videoData.FileExtension + "]",
Output: "downloads" + videoData.DownloadPath,
Target: videoData.VideoURL,
FileType: "bestvideo[ext=" + videoData.FileExtension + "]",
Output: "downloads" + videoData.DownloadPath,
Target: videoData.VideoURL,
}
}
}
Expand Down
Loading

0 comments on commit ebd1099

Please sign in to comment.