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>
<hr />
{{else}}
<div class="welcome">
<p>
<a href="/add">Click here</a> to add
a new podcast to start downloading.
</p>
</div>
{{end}}
<div class="row">

@ -68,8 +68,7 @@
<div class="row">
<div class="columns four">
{{if .LastEpisode}}
Last Ep : {{ formatDate .LastEpisode }}
{{if .LastEpisode}} Last Ep : {{ formatDate .LastEpisode }}
{{end}}
</div>
{{$downloading:= .DownloadingEpisodesCount}}
@ -79,9 +78,9 @@
{{if gt $downloading 0}} {{$downloading}} episodes in queue {{end}}
"
>
{{if gt $downloading 0}} ({{$downloading}})/{{end}}{{.DownloadedEpisodesCount}}/{{.AllEpisodesCount}} episodes
{{if gt $downloading 0}}
({{$downloading}})/{{end}}{{.DownloadedEpisodesCount}}/{{.AllEpisodesCount}}
episodes
</div>
<div class="columns three" style="">
<button
@ -113,10 +112,22 @@
<hr />
{{else}}
<h5>
You haven't added any podcasts yet. <a href="/add">Click here</a> to add
a new podcast to start monitoring.
</h5>
<div class="welcome">
<h5>Welcome</h5>
<p>It seems you have just setup Podgrab for the first time?</p>
<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}}
<!-- <div class="row">
<div class="columns twelve" style="text-align: center;">

@ -50,29 +50,60 @@
</div>
<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>
</label>
&nbsp;
<input type="number" name="initialDownloadCount" v-model.number="initialDownloadCount" min="0">
</div>
<br>
<label for="autoDownload">
<input type="checkbox" name="autoDownload" v-model="autoDownload">
<span class="label-body">Automatically download new episodes to the disk</span>
</label>
<br>
<label for="appendDateToFileName">
<input type="checkbox" name="appendDateToFileName" v-model="appendDateToFileName">
<span class="label-body">Append episode date to episode file name</span>
</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">
</form>
</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"}}
<script>
@ -89,7 +120,8 @@ var app = new Vue({
downloadOnAdd: self.downloadOnAdd,
initialDownloadCount:self.initialDownloadCount,
autoDownload:self.autoDownload,
appendDateToFileName:self.appendDateToFileName
appendDateToFileName:self.appendDateToFileName,
appendEpisodeNumberToFileName:self.appendEpisodeNumberToFileName
})
.then(function(response){
@ -125,6 +157,7 @@ var app = new Vue({
initialDownloadCount: {{ .setting.InitialDownloadCount }},
autoDownload: {{ .setting.AutoDownload }},
appendDateToFileName: {{ .setting.AppendDateToFileName }},
appendEpisodeNumberToFileName:{{ .setting.AppendEpisodeNumberToFileName }}
},

@ -24,6 +24,7 @@ type SettingModel struct {
InitialDownloadCount int `form:"initialDownloadCount" json:"initialDownloadCount" query:"initialDownloadCount"`
AutoDownload bool `form:"autoDownload" json:"autoDownload" query:"autoDownload"`
AppendDateToFileName bool `form:"appendDateToFileName" json:"appendDateToFileName" query:"appendDateToFileName"`
AppendEpisodeNumberToFileName bool `form:"appendEpisodeNumberToFileName" json:"appendEpisodeNumberToFileName" query:"appendEpisodeNumberToFileName"`
}
func AddPage(c *gin.Context) {

@ -258,7 +258,7 @@ func UpdateSetting(c *gin.Context) {
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 {
c.JSON(200, gin.H{"message": "Success"})

@ -100,6 +100,26 @@ func GetPodcastEpisodeStats() (*[]PodcastItemStatsModel, 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) {
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))
}

@ -67,6 +67,7 @@ type Setting struct {
InitialDownloadCount int `gorm:"default:5"`
AutoDownload bool `gorm:"default:true"`
AppendDateToFileName bool `gorm:"default:false"`
AppendEpisodeNumberToFileName bool `gorm:"default:false"`
}
type Migration struct {
Base

@ -290,8 +290,19 @@ func SetAllEpisodesToDownload(podcastId string) error {
func GetPodcastPrefix(item *db.PodcastItem, setting *db.Setting) string {
prefix := ""
if setting.AppendEpisodeNumberToFileName {
seq, err := db.GetEpisodeNumber(item.ID, item.PodcastID)
if err == nil {
prefix = strconv.Itoa(seq)
}
}
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
}
@ -487,13 +498,14 @@ func GetSearchFromItunes(pod model.ItunesSingleResult) *model.CommonSearchResult
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.AutoDownload = autoDownload
setting.DownloadOnAdd = downloadOnAdd
setting.InitialDownloadCount = initialDownloadCount
setting.AppendDateToFileName = appendDateToFileName
setting.AppendEpisodeNumberToFileName = appendEpisodeNumberToFileName
return db.UpdateSettings(setting)
}

Loading…
Cancel
Save