File tree Expand file tree Collapse file tree 1 file changed +65
-0
lines changed
Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "explo/src/debug"
5+ "log"
6+
7+ "explo/src/client"
8+ "explo/src/config"
9+ "explo/src/discovery"
10+ "explo/src/downloader"
11+ "explo/src/util"
12+ )
13+
14+ type Song struct {
15+ Title string
16+ Artist string
17+ Album string
18+ }
19+
20+ func initHttpClient () * util.HttpClient {
21+ return util .NewHttp (util.HttpClientConfig {
22+ Timeout : 10 ,
23+ })
24+ }
25+
26+ func setup (cfg * config.Config ) { // Inits debug, gets playlist name, if needed, handles deprecation
27+ debug .Init (cfg .Debug )
28+ cfg .GetPlaylistName ()
29+ }
30+
31+ func main () {
32+
33+ cfg := config .ReadEnv ()
34+ setup (& cfg )
35+ httpClient := initHttpClient ()
36+ client , err := client .NewClient (& cfg , httpClient )
37+ if err != nil {
38+ log .Fatal (err )
39+ }
40+ discovery := discovery .NewDiscoverer (cfg .DiscoveryCfg , httpClient )
41+ downloader := downloader .NewDownloader (& cfg .DownloadCfg , httpClient )
42+
43+ tracks , err := discovery .Discover ()
44+ if err != nil {
45+ log .Fatal (err )
46+ }
47+ if ! cfg .Persist {
48+ err := client .DeletePlaylist ()
49+ if err != nil {
50+ log .Println (err )
51+ }
52+ downloader .DeleteSongs ()
53+ }
54+ client .CheckTracks (tracks ) // Check if tracks exist on system before downloading
55+ downloader .StartDownload (& tracks )
56+ if len (tracks ) == 0 {
57+ log .Fatal ("couldn't download any tracks" )
58+ }
59+
60+ if err := client .CreatePlaylist (tracks ); err != nil {
61+ log .Println (err )
62+ } else {
63+ log .Printf ("[%s] %s playlist created successfully" , cfg .System , cfg .ClientCfg .PlaylistName )
64+ }
65+ }
You can’t perform that action at this time.
0 commit comments