Skip to content

Commit

Permalink
splitted download path to have separate torrents path.
Browse files Browse the repository at this point in the history
for memory storage download path is not mandatory now.
default paths go to kodi temporary directory.
  • Loading branch information
elgatito committed Aug 6, 2018
1 parent 719ac41 commit 8284ea7
Showing 5 changed files with 50 additions and 25 deletions.
7 changes: 7 additions & 0 deletions api/cmd.go
Original file line number Diff line number Diff line change
@@ -55,6 +55,13 @@ func ResetClearances(ctx *gin.Context) {
xbmc.Notify("Elementum", "LOCALIZE[30264]", config.AddonIcon())
}

// ResetPath ...
func ResetPath(ctx *gin.Context) {
xbmc.SetSetting("download_path", "")
xbmc.SetSetting("library_path", "special://temp/elementum_library/")
xbmc.SetSetting("torrents_path", "special://temp/elementum_torrents/")
}

// SetViewMode ...
func SetViewMode(ctx *gin.Context) {
contentType := ctx.Params.ByName("content_type")
1 change: 1 addition & 0 deletions api/routes.go
Original file line number Diff line number Diff line change
@@ -280,6 +280,7 @@ func Routes(btService *bittorrent.BTService) *gin.Engine {
cmd.GET("/clear_trakt_cache", ClearTraktCache)
cmd.GET("/clear_tmdb_cache", ClearTmdbCache)
cmd.GET("/reset_clearances", ResetClearances)
cmd.GET("/reset_path", ResetPath)
}

return r
6 changes: 0 additions & 6 deletions api/torrents.go
Original file line number Diff line number Diff line change
@@ -329,12 +329,6 @@ func AddTorrent(btService *bittorrent.BTService) gin.HandlerFunc {
}
torrentsLog.Infof("Adding torrent from %s", uri)

if config.Get().DownloadPath == "." {
xbmc.Notify("Elementum", "LOCALIZE[30113]", config.AddonIcon())
ctx.String(404, "Download path empty")
return
}

_, err := btService.AddTorrent(uri)
if err != nil {
ctx.String(404, err.Error())
2 changes: 1 addition & 1 deletion bittorrent/service.go
Original file line number Diff line number Diff line change
@@ -355,7 +355,7 @@ func (s *BTService) CheckAvailableSpace(torrent *Torrent) bool {
func (s *BTService) AddTorrent(uri string) (*Torrent, error) {
log.Infof("Adding torrent from %s", uri)

if s.config.DownloadPath == "." {
if s.config.DownloadStorage != estorage.StorageMemory && s.config.DownloadPath == "." {
xbmc.Notify("Elementum", "LOCALIZE[30113]", config.AddonIcon())
return nil, fmt.Errorf("Download path empty")
}
59 changes: 41 additions & 18 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -296,32 +296,55 @@ func Reload() *Configuration {
}

downloadPath := TranslatePath(xbmc.GetSettingString("download_path"))
if downloadPath == "." {
// xbmc.AddonSettings("plugin.video.elementum")
// xbmc.Dialog("Elementum", "LOCALIZE[30113]")
settingsWarning = "LOCALIZE[30113]"
panic(settingsWarning)
} else if err := IsWritablePath(downloadPath); err != nil {
log.Errorf("Cannot write to location '%s': %#v", downloadPath, err)
// xbmc.AddonSettings("plugin.video.elementum")
// xbmc.Dialog("Elementum", err.Error())
settingsWarning = err.Error()
panic(settingsWarning)
libraryPath := TranslatePath(xbmc.GetSettingString("library_path"))
torrentsPath := TranslatePath(xbmc.GetSettingString("torrents_path"))
downloadStorage := xbmc.GetSettingInt("download_storage")

if downloadStorage != 1 {
if downloadPath == "." {
settingsWarning = "LOCALIZE[30113]"
panic(settingsWarning)
} else if err := IsWritablePath(downloadPath); err != nil {
log.Errorf("Cannot write to download location '%s': %#v", downloadPath, err)
settingsWarning = err.Error()
panic(settingsWarning)
}
}
log.Infof("Using download path: %s", downloadPath)

libraryPath := TranslatePath(xbmc.GetSettingString("library_path"))
if libraryPath == "." {
libraryPath = downloadPath
} else if err := IsWritablePath(libraryPath); err != nil {
log.Error(err)
// xbmc.Dialog("Elementum", err.Error())
// xbmc.AddonSettings("plugin.video.elementum")
settingsWarning = "LOCALIZE[30220]"
panic(settingsWarning)
} else if strings.Contains(libraryPath, "elementum_library") {
if err := os.MkdirAll(libraryPath, 0777); err != nil {
log.Errorf("Could not create temporary library directory: %#v", err)
settingsWarning = err.Error()
panic(settingsWarning)
}
}
if err := IsWritablePath(libraryPath); err != nil {
log.Errorf("Cannot write to library location '%s': %#v", libraryPath, err)
settingsWarning = err.Error()
panic(settingsWarning)
}
log.Infof("Using library path: %s", libraryPath)

if torrentsPath == "." {
torrentsPath = filepath.Join(downloadPath, "Torrents")
} else if strings.Contains(torrentsPath, "elementum_torrents") {
if err := os.MkdirAll(torrentsPath, 0777); err != nil {
log.Errorf("Could not create temporary torrents directory: %#v", err)
settingsWarning = err.Error()
panic(settingsWarning)
}
}
if err := IsWritablePath(torrentsPath); err != nil {
log.Errorf("Cannot write to location '%s': %#v", torrentsPath, err)
settingsWarning = err.Error()
panic(settingsWarning)
}
log.Infof("Using torrents path: %s", torrentsPath)

xbmcSettings := xbmc.GetAllSettings()
settings := make(map[string]interface{})
for _, setting := range xbmcSettings {
@@ -359,7 +382,7 @@ func Reload() *Configuration {
newConfig := Configuration{
DownloadPath: downloadPath,
LibraryPath: libraryPath,
TorrentsPath: filepath.Join(downloadPath, "Torrents"),
TorrentsPath: torrentsPath,
Info: info,
Platform: platform,
Language: xbmc.GetLanguageISO639_1(),

0 comments on commit 8284ea7

Please sign in to comment.