@@ -113,7 +128,7 @@
Request here |
- Support development |
+ Support the developer |
Support here |
diff --git a/controllers/pages.go b/controllers/pages.go
index f22bb4a..a1750e6 100644
--- a/controllers/pages.go
+++ b/controllers/pages.go
@@ -183,9 +183,11 @@ func PlayerPage(c *gin.Context) {
func SettingsPage(c *gin.Context) {
setting := c.MustGet("setting").(*db.Setting)
+ diskStats, _ := db.GetPodcastEpisodeDiskStats()
c.HTML(http.StatusOK, "settings.html", gin.H{
- "setting": setting,
- "title": "Update your preferences",
+ "setting": setting,
+ "title": "Update your preferences",
+ "diskStats": diskStats,
})
}
diff --git a/db/dbfunctions.go b/db/dbfunctions.go
index dfd9b91..b47c5cb 100644
--- a/db/dbfunctions.go
+++ b/db/dbfunctions.go
@@ -146,10 +146,29 @@ func GetAllPodcastItemsAlreadyDownloaded() (*[]PodcastItem, error) {
func GetPodcastEpisodeStats() (*[]PodcastItemStatsModel, error) {
var stats []PodcastItemStatsModel
- result := DB.Model(&PodcastItem{}).Select("download_status,podcast_id, count(1) as count").Group("podcast_id,download_status").Find(&stats)
+ result := DB.Model(&PodcastItem{}).Select("download_status,podcast_id, count(1) as count,sum(file_size) as size").Group("podcast_id,download_status").Find(&stats)
return &stats, result.Error
}
+func GetPodcastEpisodeDiskStats() (PodcastItemConsolidateDiskStatsModel, error) {
+ var stats []PodcastItemDiskStatsModel
+ result := DB.Model(&PodcastItem{}).Select("download_status,count(1) as count,sum(file_size) as size").Group("download_status").Find(&stats)
+ dict := make(map[DownloadStatus]int64)
+ for _, stat := range stats {
+ dict[stat.DownloadStatus] = stat.Size
+ }
+
+ toReturn := PodcastItemConsolidateDiskStatsModel{
+ Downloaded: dict[Downloaded],
+ Downloading: dict[Downloading],
+ Deleted: dict[Deleted],
+ NotDownloaded: dict[NotDownloaded],
+ PendingDownload: dict[NotDownloaded] + dict[Downloading],
+ }
+
+ return toReturn, result.Error
+}
+
func GetEpisodeNumber(podcastItemId, podcastId string) (int, error) {
var id string
var sequence int
diff --git a/db/podcast.go b/db/podcast.go
index 98fc5ec..ef84f15 100644
--- a/db/podcast.go
+++ b/db/podcast.go
@@ -26,6 +26,10 @@ type Podcast struct {
DownloadedEpisodesCount int `gorm:"-"`
DownloadingEpisodesCount int `gorm:"-"`
AllEpisodesCount int `gorm:"-"`
+
+ DownloadedEpisodesSize int64 `gorm:"-"`
+ DownloadingEpisodesSize int64 `gorm:"-"`
+ AllEpisodesSize int64 `gorm:"-"`
}
//PodcastItem is
@@ -107,4 +111,19 @@ type PodcastItemStatsModel struct {
PodcastID string
DownloadStatus DownloadStatus
Count int
+ Size int64
+}
+
+type PodcastItemDiskStatsModel struct {
+ DownloadStatus DownloadStatus
+ Count int
+ Size int64
+}
+
+type PodcastItemConsolidateDiskStatsModel struct {
+ Downloaded int64
+ Downloading int64
+ NotDownloaded int64
+ Deleted int64
+ PendingDownload int64
}
diff --git a/main.go b/main.go
index 2a7bb0f..ee28239 100644
--- a/main.go
+++ b/main.go
@@ -90,6 +90,27 @@ func main() {
}
return count
},
+ "formatFileSize": func(inputSize int64) string {
+ size := float64(inputSize)
+ const divisor float64 = 1024
+ if size < divisor {
+ return fmt.Sprintf("%.0f bytes", size)
+ }
+ size = size / divisor
+ if size < divisor {
+ return fmt.Sprintf("%.2f KB", size)
+ }
+ size = size / divisor
+ if size < divisor {
+ return fmt.Sprintf("%.2f MB", size)
+ }
+ size = size / divisor
+ if size < divisor {
+ return fmt.Sprintf("%.2f GB", size)
+ }
+ size = size / divisor
+ return fmt.Sprintf("%.2f TB", size)
+ },
"formatDuration": func(total int) string {
if total <= 0 {
return ""
diff --git a/service/podcastService.go b/service/podcastService.go
index b878f2a..8c83c25 100644
--- a/service/podcastService.go
+++ b/service/podcastService.go
@@ -82,15 +82,23 @@ func GetAllPodcasts(sorting string) *[]db.Podcast {
PodcastID string
DownloadStatus db.DownloadStatus
}
- statsMap := make(map[Key]int)
+ countMap := make(map[Key]int)
+ sizeMap := make(map[Key]int64)
for _, stat := range *stats {
- statsMap[Key{stat.PodcastID, stat.DownloadStatus}] = stat.Count
+ countMap[Key{stat.PodcastID, stat.DownloadStatus}] = stat.Count
+ sizeMap[Key{stat.PodcastID, stat.DownloadStatus}] = stat.Size
+
}
var toReturn []db.Podcast
for _, podcast := range podcasts {
- podcast.DownloadedEpisodesCount = statsMap[Key{podcast.ID, db.Downloaded}]
- podcast.DownloadingEpisodesCount = statsMap[Key{podcast.ID, db.NotDownloaded}]
- podcast.AllEpisodesCount = podcast.DownloadedEpisodesCount + podcast.DownloadingEpisodesCount + statsMap[Key{podcast.ID, db.Deleted}]
+ podcast.DownloadedEpisodesCount = countMap[Key{podcast.ID, db.Downloaded}]
+ podcast.DownloadingEpisodesCount = countMap[Key{podcast.ID, db.NotDownloaded}]
+ podcast.AllEpisodesCount = podcast.DownloadedEpisodesCount + podcast.DownloadingEpisodesCount + countMap[Key{podcast.ID, db.Deleted}]
+
+ podcast.DownloadedEpisodesSize = sizeMap[Key{podcast.ID, db.Downloaded}]
+ podcast.DownloadingEpisodesSize = sizeMap[Key{podcast.ID, db.NotDownloaded}]
+ podcast.AllEpisodesSize = podcast.DownloadedEpisodesSize + podcast.DownloadingEpisodesSize + sizeMap[Key{podcast.ID, db.Deleted}]
+
toReturn = append(toReturn, podcast)
}
return &toReturn