Merge pull request #32 from akhilrex/episode_number

pull/34/head
Akhil Gupta 4 years ago committed by GitHub
commit 76a8ba90db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -139,6 +139,13 @@
<div class="columns one"></div> <div class="columns one"></div>
</div> </div>
<hr /> <hr />
{{else}}
<div class="welcome">
<p>
<a href="/add">Click here</a> to add
a new podcast to start downloading.
</p>
</div>
{{end}} {{end}}
<div class="row"> <div class="row">

@ -68,8 +68,7 @@
<div class="row"> <div class="row">
<div class="columns four"> <div class="columns four">
{{if .LastEpisode}} {{if .LastEpisode}} Last Ep : {{ formatDate .LastEpisode }}
Last Ep : {{ formatDate .LastEpisode }}
{{end}} {{end}}
</div> </div>
{{$downloading:= .DownloadingEpisodesCount}} {{$downloading:= .DownloadingEpisodesCount}}
@ -79,9 +78,9 @@
{{if gt $downloading 0}} {{$downloading}} episodes in queue {{end}} {{if gt $downloading 0}} {{$downloading}} episodes in queue {{end}}
" "
> >
{{if gt $downloading 0}}
{{if gt $downloading 0}} ({{$downloading}})/{{end}}{{.DownloadedEpisodesCount}}/{{.AllEpisodesCount}} episodes ({{$downloading}})/{{end}}{{.DownloadedEpisodesCount}}/{{.AllEpisodesCount}}
episodes
</div> </div>
<div class="columns three" style=""> <div class="columns three" style="">
<button <button
@ -113,10 +112,22 @@
<hr /> <hr />
{{else}} {{else}}
<h5> <div class="welcome">
You haven't added any podcasts yet. <a href="/add">Click here</a> to add <h5>Welcome</h5>
a new podcast to start monitoring. <p>It seems you have just setup Podgrab for the first time?</p>
</h5> <p>
Before you start adding and downloading podcasts I recommend that you
give a quick look to the <a href="/settings"><strong>Settings</strong> here</a> so that you can customize the
downloading behavior of the software as per your needs.
</p>
<p>
<a href="/add">Click here</a> to add
a new podcast to start downloading.
</p>
<p>
Please feel free to report any issues or request any features on our github page <a target="_blank" href="https://github.com/akhilrex/podgrab">here</a>
</p>
</div>
{{end}} {{end}}
<!-- <div class="row"> <!-- <div class="row">
<div class="columns twelve" style="text-align: center;"> <div class="columns twelve" style="text-align: center;">

@ -50,29 +50,60 @@
</div> </div>
<div v-if="downloadOnAdd"> <div v-if="downloadOnAdd">
<br>
<label for="initialDownloadCount" > <label for="initialDownloadCount" style="display: inline-block;" >
<span class="label-body">How many episodes to be downloaded when a new podcast is added</span> <span class="label-body">How many episodes to be downloaded when a new podcast is added</span>
</label> </label>
&nbsp;
<input type="number" name="initialDownloadCount" v-model.number="initialDownloadCount" min="0"> <input type="number" name="initialDownloadCount" v-model.number="initialDownloadCount" min="0">
</div> </div>
<br>
<label for="autoDownload"> <label for="autoDownload">
<input type="checkbox" name="autoDownload" v-model="autoDownload"> <input type="checkbox" name="autoDownload" v-model="autoDownload">
<span class="label-body">Automatically download new episodes to the disk</span> <span class="label-body">Automatically download new episodes to the disk</span>
</label> </label>
<br>
<label for="appendDateToFileName"> <label for="appendDateToFileName">
<input type="checkbox" name="appendDateToFileName" v-model="appendDateToFileName"> <input type="checkbox" name="appendDateToFileName" v-model="appendDateToFileName">
<span class="label-body">Append episode date to episode file name</span> <span class="label-body">Append episode date to episode file name</span>
</label> </label>
<br>
<label for="appendEpisodeNumberToFileName">
<input type="checkbox" name="appendEpisodeNumberToFileName" v-model="appendEpisodeNumberToFileName">
<span class="label-body">Append episode number to episode file name</span>
</label>
<input type="submit" value="Save" class="button button-primary"> <input type="submit" value="Save" class="button button-primary">
</form> </form>
</div> </div>
</div> </div>
<hr>
<div class="row">
<div class="columns twelve">
<h3>More Info</h3>
<table>
<tr>
<td>Website</td>
<td><a href="https://github.com/akhilrex/podgrab" target="_blank">https://github.com/akhilrex/podgrab</a></td>
</tr>
<tr>
<td>Found a bug</td>
<td><a href="https://github.com/akhilrex/podgrab/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc" target="_blank" rel="noopener noreferrer">Report here</a></td>
</tr>
<tr>
<td>Feature Request</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>
<td>Support development</td>
<td><a href="https://www.buymeacoffee.com/akhilrex" target="_blank" rel="noopener noreferrer">Support here</a></td>
</tr>
</table>
</div>
</div>
{{template "scripts"}} {{template "scripts"}}
<script> <script>
@ -89,7 +120,8 @@ var app = new Vue({
downloadOnAdd: self.downloadOnAdd, downloadOnAdd: self.downloadOnAdd,
initialDownloadCount:self.initialDownloadCount, initialDownloadCount:self.initialDownloadCount,
autoDownload:self.autoDownload, autoDownload:self.autoDownload,
appendDateToFileName:self.appendDateToFileName appendDateToFileName:self.appendDateToFileName,
appendEpisodeNumberToFileName:self.appendEpisodeNumberToFileName
}) })
.then(function(response){ .then(function(response){
@ -125,6 +157,7 @@ var app = new Vue({
initialDownloadCount: {{ .setting.InitialDownloadCount }}, initialDownloadCount: {{ .setting.InitialDownloadCount }},
autoDownload: {{ .setting.AutoDownload }}, autoDownload: {{ .setting.AutoDownload }},
appendDateToFileName: {{ .setting.AppendDateToFileName }}, appendDateToFileName: {{ .setting.AppendDateToFileName }},
appendEpisodeNumberToFileName:{{ .setting.AppendEpisodeNumberToFileName }}
}, },

@ -20,10 +20,11 @@ type SearchGPodderData struct {
Q string `binding:"required" form:"q" json:"q" query:"q"` Q string `binding:"required" form:"q" json:"q" query:"q"`
} }
type SettingModel struct { type SettingModel struct {
DownloadOnAdd bool `form:"downloadOnAdd" json:"downloadOnAdd" query:"downloadOnAdd"` DownloadOnAdd bool `form:"downloadOnAdd" json:"downloadOnAdd" query:"downloadOnAdd"`
InitialDownloadCount int `form:"initialDownloadCount" json:"initialDownloadCount" query:"initialDownloadCount"` InitialDownloadCount int `form:"initialDownloadCount" json:"initialDownloadCount" query:"initialDownloadCount"`
AutoDownload bool `form:"autoDownload" json:"autoDownload" query:"autoDownload"` AutoDownload bool `form:"autoDownload" json:"autoDownload" query:"autoDownload"`
AppendDateToFileName bool `form:"appendDateToFileName" json:"appendDateToFileName" query:"appendDateToFileName"` AppendDateToFileName bool `form:"appendDateToFileName" json:"appendDateToFileName" query:"appendDateToFileName"`
AppendEpisodeNumberToFileName bool `form:"appendEpisodeNumberToFileName" json:"appendEpisodeNumberToFileName" query:"appendEpisodeNumberToFileName"`
} }
func AddPage(c *gin.Context) { func AddPage(c *gin.Context) {

@ -258,7 +258,7 @@ func UpdateSetting(c *gin.Context) {
if err == nil { if err == nil {
err = service.UpdateSettings(model.DownloadOnAdd, model.InitialDownloadCount, model.AutoDownload, model.AppendDateToFileName) err = service.UpdateSettings(model.DownloadOnAdd, model.InitialDownloadCount, model.AutoDownload, model.AppendDateToFileName, model.AppendEpisodeNumberToFileName)
if err == nil { if err == nil {
c.JSON(200, gin.H{"message": "Success"}) c.JSON(200, gin.H{"message": "Success"})

@ -100,6 +100,26 @@ func GetPodcastEpisodeStats() (*[]PodcastItemStatsModel, error) {
return &stats, result.Error return &stats, result.Error
} }
func GetEpisodeNumber(podcastItemId, podcastId string) (int, error) {
var id string
var sequence int
row := DB.Raw(`;With cte as(
SELECT
id,
RANK() OVER (ORDER BY pub_date) as sequence
FROM
podcast_items
WHERE
podcast_id=?
)
select *
from cte
where id = ?
`, podcastId, podcastItemId).Row()
error := row.Scan(&id, &sequence)
return sequence, error
}
func ForceSetLastEpisodeDate(podcastId string) { func ForceSetLastEpisodeDate(podcastId string) {
DB.Exec("update podcasts set last_episode = (select max(pi.pub_date) from podcast_items pi where pi.podcast_id = @id) where id = @id", sql.Named("id", podcastId)) DB.Exec("update podcasts set last_episode = (select max(pi.pub_date) from podcast_items pi where pi.podcast_id = @id) where id = @id", sql.Named("id", podcastId))
} }

@ -63,10 +63,11 @@ const (
type Setting struct { type Setting struct {
Base Base
DownloadOnAdd bool `gorm:"default:true"` DownloadOnAdd bool `gorm:"default:true"`
InitialDownloadCount int `gorm:"default:5"` InitialDownloadCount int `gorm:"default:5"`
AutoDownload bool `gorm:"default:true"` AutoDownload bool `gorm:"default:true"`
AppendDateToFileName bool `gorm:"default:false"` AppendDateToFileName bool `gorm:"default:false"`
AppendEpisodeNumberToFileName bool `gorm:"default:false"`
} }
type Migration struct { type Migration struct {
Base Base

@ -290,8 +290,19 @@ func SetAllEpisodesToDownload(podcastId string) error {
func GetPodcastPrefix(item *db.PodcastItem, setting *db.Setting) string { func GetPodcastPrefix(item *db.PodcastItem, setting *db.Setting) string {
prefix := "" prefix := ""
if setting.AppendEpisodeNumberToFileName {
seq, err := db.GetEpisodeNumber(item.ID, item.PodcastID)
if err == nil {
prefix = strconv.Itoa(seq)
}
}
if setting.AppendDateToFileName { if setting.AppendDateToFileName {
prefix = item.PubDate.Format("2006-01-02") toAppend := item.PubDate.Format("2006-01-02")
if prefix == "" {
prefix = toAppend
} else {
prefix = prefix + "-" + toAppend
}
} }
return prefix return prefix
} }
@ -487,13 +498,14 @@ func GetSearchFromItunes(pod model.ItunesSingleResult) *model.CommonSearchResult
return p return p
} }
func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload bool, appendDateToFileName bool) error { func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload bool, appendDateToFileName bool, appendEpisodeNumberToFileName bool) error {
setting := db.GetOrCreateSetting() setting := db.GetOrCreateSetting()
setting.AutoDownload = autoDownload setting.AutoDownload = autoDownload
setting.DownloadOnAdd = downloadOnAdd setting.DownloadOnAdd = downloadOnAdd
setting.InitialDownloadCount = initialDownloadCount setting.InitialDownloadCount = initialDownloadCount
setting.AppendDateToFileName = appendDateToFileName setting.AppendDateToFileName = appendDateToFileName
setting.AppendEpisodeNumberToFileName = appendEpisodeNumberToFileName
return db.UpdateSettings(setting) return db.UpdateSettings(setting)
} }

Loading…
Cancel
Save