added size report

pull/65/head
Akhil Gupta 4 years ago
parent 087d8fbde1
commit ab91ca49c9

@ -520,12 +520,33 @@
} }
this.podcasts.sort(compareFunction) this.podcasts.sort(compareFunction)
}, },
getReadableSize(bytes){
if(bytes<1024){
return `${bytes} bytes`;
}
bytes=bytes/1024
if(bytes<1024){
return `${bytes.toFixed(2)} KB`;
}
bytes=bytes/1024
if(bytes<1024){
return `${bytes.toFixed(2)} MB`;
}
bytes=bytes/1024
if(bytes<1024){
return `${bytes.toFixed(2)} GB`;
}
bytes=bytes/1024
return `${bytes.toFixed(2)} TB`;
},
getEpisodeCountTooltip(podcast){ getEpisodeCountTooltip(podcast){
var title=`${podcast.DownloadedEpisodesCount} episodes downloaded out of total ${podcast.AllEpisodesCount} episodes` var title=`${podcast.DownloadedEpisodesCount} episodes (${this.getReadableSize(podcast.DownloadedEpisodesSize)}) downloaded out of total ${podcast.AllEpisodesCount} episodes (${this.getReadableSize(podcast.AllEpisodesSize)})`
if(podcast.DownloadingEpisodesCount){ if(podcast.DownloadingEpisodesCount){
title+= '\n'+podcast.DownloadingEpisodesCount+' episodes in the queue.' title+= '\n'+podcast.DownloadingEpisodesCount+' episodes ('+ this.getReadableSize(podcast.DownloadingEpisodesSize)+') in the queue.'
} }
return title return title
}, },
getFormattedLastEpisodeDate(podcast){ getFormattedLastEpisodeDate(podcast){

@ -42,7 +42,7 @@
</div> </div>
<hr> <hr>
<div class="row" id="app"> <div class="row" id="app">
<div class="columns twelve"> <div class="columns six">
<form action="/saveSettings" method="post" @submit="saveSettings" > <form action="/saveSettings" method="post" @submit="saveSettings" >
<div class="row"> <div class="row">
<h3>Settings</h3> <h3>Settings</h3>
@ -91,6 +91,21 @@
<input type="submit" value="Save" class="button"> <input type="submit" value="Save" class="button">
</form> </form>
</div> </div>
<div class="columns six">
<div class="row">
<h3>Disk Stats</h3>
<table>
<tr>
<td>Disk Used</td>
<td>{{formatFileSize .diskStats.Downloaded}}</td>
</tr>
<tr>
<td>Pending Download</td>
<td>{{ formatFileSize .diskStats.PendingDownload }}</td>
</tr>
</table>
</div>
</div>
</div> </div>
<hr> <hr>
<div class="row"> <div class="row">
@ -113,7 +128,7 @@
<td><a href="https://github.com/akhilrex/podgrab/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc" target="_blank" rel="noopener noreferrer">Request here</a></td> <td><a href="https://github.com/akhilrex/podgrab/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc" target="_blank" rel="noopener noreferrer">Request here</a></td>
</tr> </tr>
<tr> <tr>
<td>Support development</td> <td>Support the developer</td>
<td><a href="https://www.buymeacoffee.com/akhilrex" target="_blank" rel="noopener noreferrer">Support here</a></td> <td><a href="https://www.buymeacoffee.com/akhilrex" target="_blank" rel="noopener noreferrer">Support here</a></td>
</tr> </tr>
</table> </table>

@ -183,9 +183,11 @@ func PlayerPage(c *gin.Context) {
func SettingsPage(c *gin.Context) { func SettingsPage(c *gin.Context) {
setting := c.MustGet("setting").(*db.Setting) setting := c.MustGet("setting").(*db.Setting)
diskStats, _ := db.GetPodcastEpisodeDiskStats()
c.HTML(http.StatusOK, "settings.html", gin.H{ c.HTML(http.StatusOK, "settings.html", gin.H{
"setting": setting, "setting": setting,
"title": "Update your preferences", "title": "Update your preferences",
"diskStats": diskStats,
}) })
} }

@ -146,10 +146,29 @@ func GetAllPodcastItemsAlreadyDownloaded() (*[]PodcastItem, error) {
func GetPodcastEpisodeStats() (*[]PodcastItemStatsModel, error) { func GetPodcastEpisodeStats() (*[]PodcastItemStatsModel, error) {
var stats []PodcastItemStatsModel 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 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) { func GetEpisodeNumber(podcastItemId, podcastId string) (int, error) {
var id string var id string
var sequence int var sequence int

@ -26,6 +26,10 @@ type Podcast struct {
DownloadedEpisodesCount int `gorm:"-"` DownloadedEpisodesCount int `gorm:"-"`
DownloadingEpisodesCount int `gorm:"-"` DownloadingEpisodesCount int `gorm:"-"`
AllEpisodesCount int `gorm:"-"` AllEpisodesCount int `gorm:"-"`
DownloadedEpisodesSize int64 `gorm:"-"`
DownloadingEpisodesSize int64 `gorm:"-"`
AllEpisodesSize int64 `gorm:"-"`
} }
//PodcastItem is //PodcastItem is
@ -107,4 +111,19 @@ type PodcastItemStatsModel struct {
PodcastID string PodcastID string
DownloadStatus DownloadStatus DownloadStatus DownloadStatus
Count int 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
} }

@ -90,6 +90,27 @@ func main() {
} }
return count 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 { "formatDuration": func(total int) string {
if total <= 0 { if total <= 0 {
return "" return ""

@ -82,15 +82,23 @@ func GetAllPodcasts(sorting string) *[]db.Podcast {
PodcastID string PodcastID string
DownloadStatus db.DownloadStatus DownloadStatus db.DownloadStatus
} }
statsMap := make(map[Key]int) countMap := make(map[Key]int)
sizeMap := make(map[Key]int64)
for _, stat := range *stats { 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 var toReturn []db.Podcast
for _, podcast := range podcasts { for _, podcast := range podcasts {
podcast.DownloadedEpisodesCount = statsMap[Key{podcast.ID, db.Downloaded}] podcast.DownloadedEpisodesCount = countMap[Key{podcast.ID, db.Downloaded}]
podcast.DownloadingEpisodesCount = statsMap[Key{podcast.ID, db.NotDownloaded}] podcast.DownloadingEpisodesCount = countMap[Key{podcast.ID, db.NotDownloaded}]
podcast.AllEpisodesCount = podcast.DownloadedEpisodesCount + podcast.DownloadingEpisodesCount + statsMap[Key{podcast.ID, db.Deleted}] 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) toReturn = append(toReturn, podcast)
} }
return &toReturn return &toReturn

Loading…
Cancel
Save