Skip to content

Commit

Permalink
Added enclosures support for podcast items
Browse files Browse the repository at this point in the history
  • Loading branch information
R. S. Doiel committed Oct 11, 2024
1 parent e554e05 commit 5f3b2ab
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 24 deletions.
4 changes: 2 additions & 2 deletions about.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<!-- <h1>about</h1> -->

<h1 id="about-this-software">About this software</h1>
<h2 id="skimmer-0.0.14">skimmer 0.0.14</h2>
<h2 id="skimmer-0.0.15">skimmer 0.0.15</h2>
<h3 id="authors">Authors</h3>
<ul>
<li>R. S. Doiel</li>
Expand Down Expand Up @@ -61,7 +61,7 @@ <h3 id="software-requirements">Software Requirements</h3>
<li>GNU Make &gt;= 3.8</li>
<li>Pandoc &gt;= 3.1</li>
<li>SQLite3 &gt;= 3.43</li>
<li>Go &gt;= 1.22.6</li>
<li>Go &gt;= 1.23.2</li>
</ul>
</section>

Expand Down
2 changes: 1 addition & 1 deletion html2skim.1.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%html2skim(1) html2skim user manual | version 0.0.15 8b50960
%html2skim(1) html2skim user manual | version 0.0.15 e554e05
% R. S. Doiel
% 2024-10-10

Expand Down
Binary file added pagefind/fragment/en_dd2927d.pf_fragment
Binary file not shown.
Binary file added pagefind/index/en_592b2b9.pf_index
Binary file not shown.
2 changes: 1 addition & 1 deletion pagefind/pagefind-entry.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"1.1.0","languages":{"en":{"hash":"en_9d1896c532","wasm":"en","page_count":12}}}
{"version":"1.1.1","languages":{"en":{"hash":"en_173328a792","wasm":"en","page_count":12}}}
4 changes: 2 additions & 2 deletions pagefind/pagefind-modular-ui.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pagefind/pagefind-ui.js

Large diffs are not rendered by default.

Binary file added pagefind/pagefind.en_173328a792.pf_meta
Binary file not shown.
2 changes: 1 addition & 1 deletion pagefind/pagefind.js

Large diffs are not rendered by default.

Binary file modified pagefind/wasm.en.pagefind
Binary file not shown.
Binary file modified pagefind/wasm.unknown.pagefind
Binary file not shown.
2 changes: 1 addition & 1 deletion skim2md.1.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%skim2md(1) skim2md user manual | version 0.0.15 8b50960
%skim2md(1) skim2md user manual | version 0.0.15 e554e05
% R. S. Doiel
% 2024-10-10

Expand Down
50 changes: 45 additions & 5 deletions skim2md.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package skimmer

import (
"io"
"encoding/json"
"fmt"
"database/sql"
"strings"
"time"

// 3rd Party Packages
"github.com/mmcdole/gofeed"
)

// Skim2Md supports the skim2md cli.
Expand Down Expand Up @@ -37,7 +41,7 @@ func NewSkim2Md(appName string) (*Skim2Md, error) {
return app, nil
}

func (app *Skim2Md) DisplayItem(link string, title string, description string, updated string, published string, label string, tags string) error {
func (app *Skim2Md) DisplayItem(link string, title string, description string, enclosures string, updated string, published string, label string, tags string) error {
// Then see about formatting things.
pressTime := published
if len(pressTime) > 10 {
Expand All @@ -57,28 +61,45 @@ func (app *Skim2Md) DisplayItem(link string, title string, description string, u
} else {
title = fmt.Sprintf("## %s\n\ndate: %s, from: %s", title, pressTime, label)
}
var (
audioElement string
err error
)
if enclosures != "" {
audioElement, err = enclosuresToAudioElement(enclosures)
if err != nil {
fmt.Fprintf(app.eout, "could not make audio element for %s, %s", link, err)
audioElement = ""
}
} else {
audioElement = ""
}
if app.PocketButton {
fmt.Fprintf(app.out, `---
%s
%s
%s
<span class="feed-item-link">
<a href="%s">%s</a> <a href="https://getpocket.com/save" class="pocket-btn" data-lang="en" data-save-url="%s">Save to Pocket</a>
</span>
`, title, description, link, link, link)
`, title, description, audioElement, link, link, link)
} else {
fmt.Fprintf(app.out, `---
%s
%s
%s
<%s>
`, title, description, link)
`, title, description, audioElement, link)
}
return nil
}
Expand Down Expand Up @@ -118,16 +139,17 @@ func (app *Skim2Md) Write(db *sql.DB) error {
link string
title string
description string
enclosures string
updated string
published string
label string
tags string
)
if err := rows.Scan(&link, &title, &description, &updated, &published, &label, &tags); err != nil {
if err := rows.Scan(&link, &title, &description, &enclosures, &updated, &published, &label, &tags); err != nil {
fmt.Fprintf(app.eout, "%s\n", err)
continue
}
if err := app.DisplayItem(link, title, description, updated, published, label, tags); err != nil {
if err := app.DisplayItem(link, title, description, enclosures, updated, published, label, tags); err != nil {
return err
}
}
Expand Down Expand Up @@ -167,3 +189,21 @@ func (app *Skim2Md) Run(out io.Writer, eout io.Writer, args []string, frontMatte
}
return nil
}

func enclosuresToAudioElement(enclosures string) (string, error) {
elements := []*gofeed.Enclosure{}
if err := json.Unmarshal([]byte(enclosures), &elements); err != nil {
return "", err
}
parts := []string{}
for _, elem := range elements {
parts = append(parts, fmt.Sprintf(`<source type="%s" src="%s"></source>`, elem.Type, elem.URL))
}
if len(elements) > 0 {
parts = append(parts, `<p>Your browser does not support the audio element.</p>`)
}

return fmt.Sprintf(`<audio controls="controls">
%s
</audio>`, strings.Join(parts, "\n\t")), nil
}
2 changes: 1 addition & 1 deletion skimmer.1.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%skimmer(1) skimmer user manual | version 0.0.15 8b50960
%skimmer(1) skimmer user manual | version 0.0.15 e554e05
% R. S. Doiel
% 2024-10-10

Expand Down
30 changes: 24 additions & 6 deletions skimmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func (app *Skimmer) PruneItems(db *sql.DB, pruneDT time.Time) error {
return err
}

func (app *Skimmer) DisplayItem(link string, title string, description string, updated string, published string, label string, tags string) error {
func (app *Skimmer) DisplayItem(link string, title string, description string, enclosures string, updated string, published string, label string, tags string) error {
// Then see about formatting things.
pressTime := published
if updated != "" {
Expand All @@ -504,16 +504,32 @@ func (app *Skimmer) DisplayItem(link string, title string, description string, u
} else {
title = fmt.Sprintf("## %s\n\ndate: %s", title, pressTime)
}
var (
audioElement string
err error
)
if enclosures != "" {
audioElement, err = enclosuresToAudioElement(enclosures)
if err != nil {
fmt.Fprintf(app.eout, "could not make audio element for %s, %s", link, err)
audioElement = ""
}
} else {
audioElement = ""
}

fmt.Fprintf(app.out, `---
%s
%s
%s
<%s>
%s
`, title, description, link, tags)
`, title, description, audioElement, link, tags)
} else if title != "" {
fmt.Fprintf(app.out, `---
Expand Down Expand Up @@ -542,16 +558,17 @@ func (app *Skimmer) Write(db *sql.DB) error {
link string
title string
description string
enclosures string
updated string
published string
label string
tags string
)
if err := rows.Scan(&link, &title, &description, &updated, &published, &label, &tags); err != nil {
if err := rows.Scan(&link, &title, &description, &enclosures, &updated, &published, &label, &tags); err != nil {
fmt.Fprintf(app.eout, "%s\n", err)
continue
}
if err := app.DisplayItem(link, title, description, updated, published, label, tags); err != nil {
if err := app.DisplayItem(link, title, description, enclosures, updated, published, label, tags); err != nil {
return err
}
}
Expand Down Expand Up @@ -656,20 +673,21 @@ func (app *Skimmer) RunInteractive(db *sql.DB) error {
link string
title string
description string
enclosures string
updated string
published string
label string
tags string
)
i++
if err := rows.Scan(&link, &title, &description, &updated, &published, &label, &tags); err != nil {
if err := rows.Scan(&link, &title, &description, &enclosures, &updated, &published, &label, &tags); err != nil {
fmt.Fprintf(app.eout, "%s\n", err)
continue
}
// Now sanitize each element
title = html.UnescapeString(p.Sanitize(title))
description = html.UnescapeString(p.Sanitize(description))
if err := app.DisplayItem(link, title, description, updated, published, label, tags); err != nil {
if err := app.DisplayItem(link, title, description, enclosures, updated, published, label, tags); err != nil {
return err
}
// Wait for some input
Expand Down
2 changes: 1 addition & 1 deletion sql_stmts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS items (
link PRIMARY KEY,
title TEXT,
description TEXT,
enclosures JSON,
enclosures JSON DEFAULT '',
authors JSON,
updated DATETIME,
published DATETIME,
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
ReleaseDate = "2024-10-10"

// ReleaseHash, the Git hash when version.go was generated
ReleaseHash = "8b50960"
ReleaseHash = "e554e05"

LicenseText = `
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Expand Down

0 comments on commit 5f3b2ab

Please sign in to comment.