added size report

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

@ -520,12 +520,33 @@
}
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){
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){
title+= '\n'+podcast.DownloadingEpisodesCount+' episodes in the queue.'
title+= '\n'+podcast.DownloadingEpisodesCount+' episodes ('+ this.getReadableSize(podcast.DownloadingEpisodesSize)+') in the queue.'
}
}
return title
},
getFormattedLastEpisodeDate(podcast){

@ -42,7 +42,7 @@
</div>
<hr>
<div class="row" id="app">
<div class="columns twelve">
<div class="columns six">
<form action="/saveSettings" method="post" @submit="saveSettings" >
<div class="row">
<h3>Settings</h3>
@ -91,6 +91,21 @@
<input type="submit" value="Save" class="button">
</form>
</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>
<hr>
<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>
</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>
</tr>
</table>

@ -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,
})
}

@ -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

@ -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
}

@ -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 ""

@ -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

Loading…
Cancel
Save