From f833695c76cab9f53c67f9abaa862dbc4b6fdb0a Mon Sep 17 00:00:00 2001 From: Davo36 Date: Fri, 25 Oct 2019 10:20:42 +1300 Subject: [PATCH] Created the audiofilelibrary package --- audiofilelibrary.go => audiofilelibrary/audiofilelibrary.go | 4 ++-- downloader.go | 3 ++- main.go | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) rename audiofilelibrary.go => audiofilelibrary/audiofilelibrary.go (95%) diff --git a/audiofilelibrary.go b/audiofilelibrary/audiofilelibrary.go similarity index 95% rename from audiofilelibrary.go rename to audiofilelibrary/audiofilelibrary.go index e5aef81..2620915 100644 --- a/audiofilelibrary.go +++ b/audiofilelibrary/audiofilelibrary.go @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -package main +package audiofilelibrary import ( "errors" @@ -54,7 +54,7 @@ func extractIDFromFileName(fileName string) (int, error) { } // OpenLibrary reads the audio directory. And constructs a map of file IDs to file names. -func OpenLibrary(soundsDirectory string) (*AudioFileLibrary, error) { +func OpenLibrary(soundsDirectory string, scheduleFilename string) (*AudioFileLibrary, error) { library := &AudioFileLibrary{ soundsDirectory: soundsDirectory, diff --git a/downloader.go b/downloader.go index 5c45cd6..292d1c0 100644 --- a/downloader.go +++ b/downloader.go @@ -31,6 +31,7 @@ import ( "path/filepath" "time" + "github.com/TheCacophonyProject/audiobait/audiofilelibrary" "github.com/TheCacophonyProject/audiobait/playlist" "github.com/TheCacophonyProject/go-api" "github.com/TheCacophonyProject/modemd/connrequester" @@ -268,7 +269,7 @@ func (dl *Downloader) getFileDetails(apiObj *api.CacophonyAPI, fileID int) (*api // Try and download a single audio file from the API server. func (dl *Downloader) downloadAudioFile(api *api.CacophonyAPI, fileID int, fileResp *api.FileResponse) error { - filename := MakeFileName(fileResp.File.Details.OriginalName, fileResp.File.Details.Name, fileID) + filename := audiofilelibrary.MakeFileName(fileResp.File.Details.OriginalName, fileResp.File.Details.Name, fileID) return retry( fmt.Sprintf("download and validate file %d", fileID), diff --git a/main.go b/main.go index a8ee040..951eff3 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,7 @@ import ( arg "github.com/alexflint/go-arg" + "github.com/TheCacophonyProject/audiobait/audiofilelibrary" "github.com/TheCacophonyProject/audiobait/playlist" goconfig "github.com/TheCacophonyProject/go-config" ) @@ -140,7 +141,7 @@ func createPlayer(soundCard SoundCardPlayer, audioDirectory string) (*playlist.S func getScheduleFiles(audioDirectory string, schedule *playlist.Schedule) (map[int]string, error) { referencedFiles := schedule.GetReferencedSounds() - audioLibrary, err := OpenLibrary(audioDirectory) + audioLibrary, err := audiofilelibrary.OpenLibrary(audioDirectory, scheduleFilename) if err != nil { return nil, fmt.Errorf("error creating audio library: %v", err) }