Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for raw podcast description #352

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,27 @@ password can then be changed from the web interface

## configuration options

| env var | command line arg | description |
| ------------------------------ | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GONIC_MUSIC_PATH` | `-music-path` | path to your music collection (see also multi-folder support below) |
| `GONIC_PODCAST_PATH` | `-podcast-path` | path to a podcasts directory |
| `GONIC_PLAYLISTS_PATH` | `-playlists-path` | path to new or existing directory with m3u files for subsonic playlists. items in the directory should be in the format `<userid>/<name>.m3u`. for example the admin user could have `1/my-playlist.m3u`. gonic create and make changes to these playlists over the subsonic api. |
| `GONIC_CACHE_PATH` | `-cache-path` | path to store audio transcodes, covers, etc |
| `GONIC_DB_PATH` | `-db-path` | **optional** path to database file |
| `GONIC_HTTP_LOG` | `-http-log` | **optional** http request logging, enabled by default |
| `GONIC_LISTEN_ADDR` | `-listen-addr` | **optional** host and port to listen on (eg. `0.0.0.0:4747`, `127.0.0.1:4747`) (_default_ `0.0.0.0:4747`) |
| `GONIC_TLS_CERT` | `-tls-cert` | **optional** path to a TLS cert (enables HTTPS listening) |
| `GONIC_TLS_KEY` | `-tls-key` | **optional** path to a TLS key (enables HTTPS listening) |
| `GONIC_PROXY_PREFIX` | `-proxy-prefix` | **optional** url path prefix to use if behind reverse proxy. eg `/gonic` (see example configs below) |
| `GONIC_SCAN_INTERVAL` | `-scan-interval` | **optional** interval (in minutes) to check for new music (automatic scanning disabled if omitted) |
| `GONIC_SCAN_AT_START_ENABLED` | `-scan-at-start-enabled` | **optional** whether to perform an initial scan at startup |
| `GONIC_SCAN_WATCHER_ENABLED` | `-scan-watcher-enabled` | **optional** whether to watch file system for new music and rescan |
| `GONIC_JUKEBOX_ENABLED` | `-jukebox-enabled` | **optional** whether the subsonic [jukebox api](https://airsonic.github.io/docs/jukebox/) should be enabled |
| `GONIC_JUKEBOX_MPV_EXTRA_ARGS` | `-jukebox-mpv-extra-args` | **optional** extra command line arguments to pass to the jukebox mpv daemon |
| `GONIC_PODCAST_PURGE_AGE` | `-podcast-purge-age` | **optional** age (in days) to purge podcast episodes if not accessed |
| `GONIC_GENRE_SPLIT` | `-genre-split` | **optional** a string or character to split genre tags on for multi-genre support (eg. `;`) |
| `GONIC_EXCLUDE_PATTERN` | `-exclude-pattern` | **optional** files matching this regex pattern will not be imported |
| env var | command line arg | description |
| ------------------------------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `GONIC_MUSIC_PATH` | `-music-path` | path to your music collection (see also multi-folder support below) |
| `GONIC_PODCAST_PATH` | `-podcast-path` | path to a podcasts directory |
| `GONIC_PLAYLISTS_PATH` | `-playlists-path` | path to new or existing directory with m3u files for subsonic playlists. items in the directory should be in the format `<userid>/<name>.m3u`. for example the admin user could have `1/my-playlist.m3u`. gonic create and make changes to these playlists over the subsonic api. |
| `GONIC_CACHE_PATH` | `-cache-path` | path to store audio transcodes, covers, etc |
| `GONIC_DB_PATH` | `-db-path` | **optional** path to database file |
| `GONIC_HTTP_LOG` | `-http-log` | **optional** http request logging, enabled by default |
| `GONIC_LISTEN_ADDR` | `-listen-addr` | **optional** host and port to listen on (eg. `0.0.0.0:4747`, `127.0.0.1:4747`) (_default_ `0.0.0.0:4747`) |
| `GONIC_TLS_CERT` | `-tls-cert` | **optional** path to a TLS cert (enables HTTPS listening) |
| `GONIC_TLS_KEY` | `-tls-key` | **optional** path to a TLS key (enables HTTPS listening) |
| `GONIC_PROXY_PREFIX` | `-proxy-prefix` | **optional** url path prefix to use if behind reverse proxy. eg `/gonic` (see example configs below) |
| `GONIC_SCAN_INTERVAL` | `-scan-interval` | **optional** interval (in minutes) to check for new music (automatic scanning disabled if omitted) |
| `GONIC_SCAN_AT_START_ENABLED` | `-scan-at-start-enabled` | **optional** whether to perform an initial scan at startup |
| `GONIC_SCAN_WATCHER_ENABLED` | `-scan-watcher-enabled` | **optional** whether to watch file system for new music and rescan |
| `GONIC_JUKEBOX_ENABLED` | `-jukebox-enabled` | **optional** whether the subsonic [jukebox api](https://airsonic.github.io/docs/jukebox/) should be enabled |
| `GONIC_JUKEBOX_MPV_EXTRA_ARGS` | `-jukebox-mpv-extra-args` | **optional** extra command line arguments to pass to the jukebox mpv daemon |
| `GONIC_PODCAST_PURGE_AGE` | `-podcast-purge-age` | **optional** age (in days) to purge podcast episodes if not accessed |
| `GONIC_GENRE_SPLIT` | `-genre-split` | **optional** a string or character to split genre tags on for multi-genre support (eg. `;`) |
| `GONIC_EXCLUDE_PATTERN` | `-exclude-pattern` | **optional** files matching this regex pattern will not be imported |
| `GONIC_PODCAST_DESCRIPTION_RAW` | `-podcast-description-raw` | **optional** if true will return raw (not filtred) podcast and episode description |

## screenshots

Expand Down
24 changes: 13 additions & 11 deletions cmd/gonic/gonic.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func main() {

confPodcastPurgeAgeDays := set.Int("podcast-purge-age", 0, "age (in days) to purge podcast episodes if not accessed (optional)")
confPodcastPath := set.String("podcast-path", "", "path to podcasts")
confPodcastDescriptionRAW := set.Bool("podcast-description-raw", false, "will return raw podcast and episode description (with HTML tags)")

confCachePath := set.String("cache-path", "", "path to cache")

Expand Down Expand Up @@ -136,17 +137,18 @@ func main() {
proxyPrefixExpr := regexp.MustCompile(`^\/*(.*?)\/*$`)
*confProxyPrefix = proxyPrefixExpr.ReplaceAllString(*confProxyPrefix, `/$1`)
server, err := server.New(server.Options{
DB: dbc,
MusicPaths: musicPaths,
ExcludePattern: *confExcludePatterns,
CacheAudioPath: cacheDirAudio,
CoverCachePath: cacheDirCovers,
PodcastPath: *confPodcastPath,
PlaylistsPath: *confPlaylistsPath,
ProxyPrefix: *confProxyPrefix,
GenreSplit: *confGenreSplit,
HTTPLog: *confHTTPLog,
JukeboxEnabled: *confJukeboxEnabled,
DB: dbc,
MusicPaths: musicPaths,
ExcludePattern: *confExcludePatterns,
CacheAudioPath: cacheDirAudio,
CoverCachePath: cacheDirCovers,
PodcastPath: *confPodcastPath,
PlaylistsPath: *confPlaylistsPath,
ProxyPrefix: *confProxyPrefix,
GenreSplit: *confGenreSplit,
HTTPLog: *confHTTPLog,
JukeboxEnabled: *confJukeboxEnabled,
PodcastDescriptionRAW: *confPodcastDescriptionRAW,
})
if err != nil {
log.Panicf("error creating server: %v\n", err)
Expand Down
16 changes: 9 additions & 7 deletions podcasts/podcasts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ const downloadAllWaitInterval = 3 * time.Second
const fetchUserAgent = `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11`

type Podcasts struct {
db *db.DB
baseDir string
tagger tags.Reader
db *db.DB
baseDir string
tagger tags.Reader
DescriptionRaw bool
}

func New(db *db.DB, base string, tagger tags.Reader) *Podcasts {
func New(db *db.DB, base string, tagger tags.Reader, descriptionRaw bool) *Podcasts {
// Walk podcast path making filenames safe. Phase 1: Files
err := filepath.WalkDir(base, func(path string, d os.DirEntry, err error) error {
if (path == base) || d.IsDir() {
Expand Down Expand Up @@ -76,9 +77,10 @@ func New(db *db.DB, base string, tagger tags.Reader) *Podcasts {
log.Fatalf("error making podcast directory names safe: %v\n", err)
}
return &Podcasts{
db: db,
baseDir: base,
tagger: tagger,
db: db,
baseDir: base,
tagger: tagger,
DescriptionRaw: descriptionRaw,
}
}

Expand Down
4 changes: 2 additions & 2 deletions server/ctrlsubsonic/handlers_podcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (c *Controller) ServeGetPodcasts(r *http.Request) *spec.Response {
sub := spec.NewResponse()
sub.Podcasts = &spec.Podcasts{}
for _, podcast := range podcasts {
channel := spec.NewPodcastChannel(podcast)
channel := spec.NewPodcastChannel(podcast, c.Podcasts.DescriptionRaw)
sub.Podcasts.List = append(sub.Podcasts.List, channel)
}
return sub
Expand All @@ -38,7 +38,7 @@ func (c *Controller) ServeGetNewestPodcasts(r *http.Request) *spec.Response {
sub := spec.NewResponse()
sub.NewestPodcasts = &spec.NewestPodcasts{}
for _, episode := range episodes {
sub.NewestPodcasts.List = append(sub.NewestPodcasts.List, spec.NewPodcastEpisode(episode))
sub.NewestPodcasts.List = append(sub.NewestPodcasts.List, spec.NewPodcastEpisode(episode, c.Podcasts.DescriptionRaw))
}
return sub
}
Expand Down
28 changes: 20 additions & 8 deletions server/ctrlsubsonic/spec/construct_podcast.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
package spec

import (
"jaytaylor.com/html2text"
"go.senan.xyz/gonic/db"
"jaytaylor.com/html2text"
)

func NewPodcastChannel(p *db.Podcast) *PodcastChannel {
func NewPodcastChannel(p *db.Podcast, descRaw bool) *PodcastChannel {
desc := p.Description
if !descRaw {
var err error
desc, err = html2text.FromString(p.Description, html2text.Options{TextOnly: true})
if err != nil {
desc = ""
}
}
ret := &PodcastChannel{
ID: p.SID(),
OriginalImageURL: p.ImageURL,
Title: p.Title,
Description: p.Description,
Description: desc,
URL: p.URL,
CoverArt: p.SID(),
Status: "skipped",
}
for _, episode := range p.Episodes {
specEpisode := NewPodcastEpisode(episode)
specEpisode := NewPodcastEpisode(episode, descRaw)
ret.Episode = append(ret.Episode, specEpisode)
}
return ret
}

func NewPodcastEpisode(e *db.PodcastEpisode) *PodcastEpisode {
func NewPodcastEpisode(e *db.PodcastEpisode, descRaw bool) *PodcastEpisode {
if e == nil {
return nil
}
desc, err := html2text.FromString(e.Description, html2text.Options{TextOnly: true})
if (err != nil) {
desc = ""
desc := e.Description
if !descRaw {
var err error
desc, err = html2text.FromString(e.Description, html2text.Options{TextOnly: true})
if err != nil {
desc = ""
}
}
return &PodcastEpisode{
ID: e.SID(),
Expand Down
25 changes: 13 additions & 12 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ import (
)

type Options struct {
DB *db.DB
MusicPaths []ctrlsubsonic.MusicPath
ExcludePattern string
PodcastPath string
CacheAudioPath string
CoverCachePath string
PlaylistsPath string
ProxyPrefix string
GenreSplit string
HTTPLog bool
JukeboxEnabled bool
DB *db.DB
MusicPaths []ctrlsubsonic.MusicPath
ExcludePattern string
PodcastPath string
CacheAudioPath string
CoverCachePath string
PlaylistsPath string
ProxyPrefix string
GenreSplit string
HTTPLog bool
JukeboxEnabled bool
PodcastDescriptionRAW bool
}

type Server struct {
Expand Down Expand Up @@ -90,7 +91,7 @@ func New(opts Options) (*Server, error) {
sessDB.SessionOpts.HttpOnly = true
sessDB.SessionOpts.SameSite = http.SameSiteLaxMode

podcast := podcasts.New(opts.DB, opts.PodcastPath, tagger)
podcast := podcasts.New(opts.DB, opts.PodcastPath, tagger, opts.PodcastDescriptionRAW)

cacheTranscoder := transcode.NewCachingTranscoder(
transcode.NewFFmpegTranscoder(),
Expand Down
Loading