player improvement

player_improvements
Akhil Gupta 4 years ago
parent ab91ca49c9
commit 33811c85d3

@ -7,6 +7,7 @@ import (
"math"
"net/http"
"os"
"sort"
"strings"
"time"
@ -124,7 +125,7 @@ func getItemsToPlay(itemId, podcastId string, tagIds []string) []db.PodcastItem
podIds = append(podIds, pod.ID)
}
}
items = *service.GetAllPodcastItemsByPodcastIds(podIds)
items = *service.GetAllPodcastItemsByPodcastIds(podIds, "")
}
return items
}
@ -134,6 +135,15 @@ func PlayerPage(c *gin.Context) {
itemId, hasItemId := c.GetQuery("itemId")
podcastId, hasPodcastId := c.GetQuery("podcastId")
tagIds, hasTagIds := c.GetQueryArray("tagIds")
sortOrder, hasSortOrder := c.GetQuery("sort")
if !hasSortOrder {
sortOrder = "desc"
}
sorting := "pub_date desc"
if sortOrder == "asc" {
sorting = "pub_date asc"
}
title := "Podgrab"
var items []db.PodcastItem
var totalCount int64
@ -156,7 +166,7 @@ func PlayerPage(c *gin.Context) {
podIds = append(podIds, pod.ID)
}
}
items = *service.GetAllPodcastItemsByPodcastIds(podIds)
items = *service.GetAllPodcastItemsByPodcastIds(podIds, sorting)
if len(tagNames) == 1 {
title = fmt.Sprintf("Playing episodes with tag : %s", (tagNames[0]))
} else {
@ -164,12 +174,17 @@ func PlayerPage(c *gin.Context) {
}
} else {
title = "Playing Latest Episodes"
if err := db.GetPaginatedPodcastItems(1, 20, nil, nil, time.Time{}, &items, &totalCount); err != nil {
if err := db.GetPaginatedPodcastItems(1, 20, nil, nil, time.Time{}, sorting, &items, &totalCount); err != nil {
fmt.Println(err.Error())
}
}
setting := c.MustGet("setting").(*db.Setting)
if sortOrder == "asc" {
sort.Slice(items, func(i, j int) bool {
return items[i].PubDate.Before(items[j].PubDate)
})
}
c.HTML(http.StatusOK, "player.html", gin.H{
"title": title,
"podcastItems": items,
@ -252,7 +267,7 @@ func AllEpisodesPage(c *gin.Context) {
}
if err := db.GetPaginatedPodcastItems(page, count,
nil, filter.PlayedOnly, fromDate,
nil, filter.PlayedOnly, fromDate, "",
&podcastItems, &totalCount); err == nil {
setting := c.MustGet("setting").(*db.Setting)

@ -35,7 +35,7 @@ func GetAllPodcastItemsWithoutSize() (*[]PodcastItem, error) {
result := DB.Where("file_size<=?", 0).Order("pub_date desc").Find(&podcasts)
return &podcasts, result.Error
}
func GetPaginatedPodcastItems(page int, count int, downloadedOnly *bool, playedOnly *bool, fromDate time.Time, podcasts *[]PodcastItem, total *int64) error {
func GetPaginatedPodcastItems(page int, count int, downloadedOnly *bool, playedOnly *bool, fromDate time.Time, sortOrder string, podcasts *[]PodcastItem, total *int64) error {
query := DB.Preload("Podcast")
if downloadedOnly != nil {
if *downloadedOnly {
@ -54,8 +54,11 @@ func GetPaginatedPodcastItems(page int, count int, downloadedOnly *bool, playedO
if (fromDate != time.Time{}) {
query = query.Where("pub_date>=?", fromDate)
}
if sortOrder == "" {
sortOrder = "pub_date desc"
}
totalsQuery := query.Order("pub_date desc").Find(&podcasts)
totalsQuery := query.Order(sortOrder).Find(&podcasts)
totalsQuery.Count(total)
result := query.Limit(count).Offset((page - 1) * count).Order("pub_date desc").Find(&podcasts)
@ -105,9 +108,11 @@ func GetAllPodcastItemsByPodcastId(podcastId string, podcastItems *[]PodcastItem
result := DB.Preload(clause.Associations).Where(&PodcastItem{PodcastID: podcastId}).Find(&podcastItems)
return result.Error
}
func GetAllPodcastItemsByPodcastIds(podcastIds []string, podcastItems *[]PodcastItem) error {
result := DB.Preload(clause.Associations).Where("podcast_id in ?", podcastIds).Order("pub_date desc").Find(&podcastItems)
func GetAllPodcastItemsByPodcastIds(podcastIds []string, sortOrder string, podcastItems *[]PodcastItem) error {
if sortOrder == "" {
sortOrder = "pub_date desc"
}
result := DB.Preload(clause.Associations).Where("podcast_id in ?", podcastIds).Order(sortOrder).Find(&podcastItems)
return result.Error
}

@ -59,10 +59,10 @@ func GetPodcastItemById(id string) *db.PodcastItem {
return &podcastItem
}
func GetAllPodcastItemsByPodcastIds(podcastIds []string) *[]db.PodcastItem {
func GetAllPodcastItemsByPodcastIds(podcastIds []string, sortOrder string) *[]db.PodcastItem {
var podcastItems []db.PodcastItem
db.GetAllPodcastItemsByPodcastIds(podcastIds, &podcastItems)
db.GetAllPodcastItemsByPodcastIds(podcastIds, sortOrder, &podcastItems)
return &podcastItems
}

Loading…
Cancel
Save