diff --git a/models/upload_test.go b/models/upload_test.go index f91628a..27297ee 100644 --- a/models/upload_test.go +++ b/models/upload_test.go @@ -1,10 +1,11 @@ package models import ( - testUtil "../unitTestUtil" - utils "../utils" "os" "testing" + + testUtil "../unitTestUtil" + fileio "../utils/fileio" ) func TestParseUploads(t *testing.T) { @@ -62,7 +63,7 @@ func TestWriteToFile(t *testing.T) { upload.WriteToFile(filePath) - actual := utils.ReadFileToString(filePath) + actual := fileio.ReadFileToString(filePath) tu.AssertString(actual, expected, "File content") os.Remove(filePath) diff --git a/utils/archive.go b/utils/archive.go index 363ff26..606ba58 100644 --- a/utils/archive.go +++ b/utils/archive.go @@ -3,6 +3,7 @@ package utils import ( models "../models" config "../models/config" + fileio "./fileio" log "./log" ) @@ -18,7 +19,7 @@ func IsItemInArchive(upload models.Upload) bool { func RemoveArchivedItems(uploads []models.Upload) []models.Upload { archiveFilePath := config.Config.ArchiveFilePath - if archiveFilePath == "" || !CheckIfExists(archiveFilePath) { + if archiveFilePath == "" || !fileio.CheckIfExists(archiveFilePath) { return uploads } @@ -31,7 +32,7 @@ func RemoveArchivedItems(uploads []models.Upload) []models.Upload { } lenBeforeRemoval := len(uploads) - ReadFileLineByLine(archiveFilePath, removeArchivedItemsDelegate) + fileio.ReadFileLineByLine(archiveFilePath, removeArchivedItemsDelegate) removedCount := lenBeforeRemoval - len(uploads) if removedCount > 0 { @@ -49,5 +50,5 @@ func AddItemToArchive(uploadID string) { return } - AppendToFile(uploadID, archiveFilePath) + fileio.AppendToFile(uploadID, archiveFilePath) } diff --git a/utils/fileio.go b/utils/fileio/fileio.go similarity index 98% rename from utils/fileio.go rename to utils/fileio/fileio.go index 85b72cc..eaaeafc 100644 --- a/utils/fileio.go +++ b/utils/fileio/fileio.go @@ -5,7 +5,7 @@ import ( "io/ioutil" "os" - checkErr "./checkErr" + checkErr "../checkErr" ) type delegateString func(string) diff --git a/workflows/downloadBatchFile.go b/workflows/downloadBatchFile.go index e0fdfe5..7b4ae9d 100644 --- a/workflows/downloadBatchFile.go +++ b/workflows/downloadBatchFile.go @@ -2,7 +2,7 @@ package workflows import ( res "../resources" - utils "../utils" + fileio "../utils/fileio" log "../utils/log" ) @@ -13,11 +13,11 @@ func CanUseDownloadBatchFile(batchFilePath string) bool { // DownloadBatchFile - Download items from batch file func DownloadBatchFile(batchFilePath string) { - if !utils.CheckIfExists(batchFilePath) { + if !fileio.CheckIfExists(batchFilePath) { log.LogFatal(res.ErrorPathNotFound, batchFilePath) } - utils.ReadFileLineByLine(batchFilePath, downloadItem) + fileio.ReadFileLineByLine(batchFilePath, downloadItem) } func downloadItem(batchItem string) { diff --git a/workflows/downloadHashtag.go b/workflows/downloadHashtag.go index d07e76a..26e4a38 100644 --- a/workflows/downloadHashtag.go +++ b/workflows/downloadHashtag.go @@ -8,6 +8,7 @@ import ( config "../models/config" res "../resources" utils "../utils" + fileio "../utils/fileio" log "../utils/log" ) @@ -31,7 +32,7 @@ func DownloadHashtag(url string) { hashtag := utils.GetHashtagFromURL(url) downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, hashtag) - utils.InitOutputDirectory(downloadDir) + fileio.InitOutputDirectory(downloadDir) for index, upload := range uploads { downloadVideo(upload, downloadDir) diff --git a/workflows/downloadMusic.go b/workflows/downloadMusic.go index 8ce7ad5..c8cfb23 100644 --- a/workflows/downloadMusic.go +++ b/workflows/downloadMusic.go @@ -8,6 +8,7 @@ import ( config "../models/config" res "../resources" utils "../utils" + fileio "../utils/fileio" log "../utils/log" ) @@ -32,7 +33,7 @@ func DownloadMusic(url string) { username := utils.GetUsernameFromString(upload.Uploader) downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username) - utils.InitOutputDirectory(downloadDir) + fileio.InitOutputDirectory(downloadDir) downloadVideo(upload, downloadDir) log.Logf("\r[%d/%d] Downloaded", index+1, uploadCount) } diff --git a/workflows/downloadUser.go b/workflows/downloadUser.go index 3b767ca..2ad0afc 100644 --- a/workflows/downloadUser.go +++ b/workflows/downloadUser.go @@ -9,6 +9,7 @@ import ( config "../models/config" res "../resources" utils "../utils" + fileio "../utils/fileio" log "../utils/log" ) @@ -32,7 +33,7 @@ func DownloadUser(username string) { downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username) - utils.InitOutputDirectory(downloadDir) + fileio.InitOutputDirectory(downloadDir) for index, upload := range uploads { downloadVideo(upload, downloadDir) diff --git a/workflows/downloadVideo.go b/workflows/downloadVideo.go index 7f4adfb..d433182 100644 --- a/workflows/downloadVideo.go +++ b/workflows/downloadVideo.go @@ -9,6 +9,7 @@ import ( config "../models/config" res "../resources" utils "../utils" + fileio "../utils/fileio" log "../utils/log" ) @@ -32,7 +33,7 @@ func DownloadSingleVideo(url string) { } downloadDir := fmt.Sprintf("%s/%s", config.Config.OutputPath, username) - utils.InitOutputDirectory(downloadDir) + fileio.InitOutputDirectory(downloadDir) downloadVideo(upload, downloadDir) log.Log("[1/1] Downloaded\n") } @@ -42,7 +43,7 @@ func downloadVideo(upload models.Upload, downloadDir string) { uploadID := upload.GetUploadID() downloadPath := fmt.Sprintf("%s/%s.mp4", downloadDir, uploadID) - if utils.CheckIfExists(downloadPath) { + if fileio.CheckIfExists(downloadPath) { return }