publication

package
v0.0.0-...-3236646 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CatalogURL = "https://app.jw-cdn.org/catalogs/publications/v4/%s/catalog.db.gz"

CatalogURL is the URL to the publication catalog

View Source
var ManifestURL = "https://app.jw-cdn.org/catalogs/publications/v4/manifest.json"

ManifestURL is the URL to the publication manifest

View Source
var MediaLinksURL = "https://b.jw-cdn.org/apis/pub-media/GETPUBMEDIALINKS"

MediaLinksURL is the URL to the jw.org API that lists the download links of a publication

Functions

func CatalogExists

func CatalogExists(path string) bool

CatalogExists checks if catalog.db exists at path

func CatalogNeedsUpdate

func CatalogNeedsUpdate(path string) bool

CatalogNeedsUpdate checks if catalog.db located at path is still up-to-date. For now it just makes sure that it is younger than one month. If it can't find a file at path, it returns true

func CatalogSize

func CatalogSize(path string) int64

CatalogSize returns the size of the catalog.db at path

func DownloadCatalog

func DownloadCatalog(ctx context.Context, prgrs chan Progress, dst string) error

DownloadCatalog downloads the newest catalog.db and saves it at dst. The prgrs channel informs about the progress of the download.

func NeedsDownload

func NeedsDownload(cacheDir string, location *model.Location, blockRanges []*model.BlockRange) bool

NeedsDownload reports whether MarkingSnippets has to download the publication of a marking first, because its text is not in cacheDir yet.

Types

type Lookup

type Lookup struct {
	DocumentID     int64
	KeySymbol      string
	IssueTagNumber int
	MepsLanguage   int
}

Lookup represents a lookup for a publication. This query can contain various fields.

type Progress

type Progress struct {
	Size           int64
	BytesComplete  int64
	BytesPerSecond float64
	Progress       float64
	Duration       time.Duration
	ETA            time.Time
	Done           bool
}

Progress represents the progress of a running download

type Publication

type Publication struct {
	ID                    int
	PublicationRootKeyID  int
	MepsLanguageID        int
	PublicationTypeID     int
	IssueTagNumber        int
	Title                 string
	IssueTitle            sql.NullString
	ShortTitle            string
	CoverTitle            sql.NullString
	UndatedTitle          sql.NullString
	UndatedReferenceTitle sql.NullString
	Year                  int
	Symbol                string
	KeySymbol             sql.NullString
	Reserved              int
}

Publication represents a publication with all its information from the catalogDB

func LookupPublication

func LookupPublication(dbPath string, query Lookup) (Publication, error)

LookupPublication looks up a publication from catalogDB located at dbPath

func (Publication) MarshalJSON

func (m Publication) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the entry

type Snippet

type Snippet struct {
	Before string `json:"before"`
	Marked string `json:"marked"`
	After  string `json:"after"`
	// Number is the paragraph number shown in the publication, or 0 if it
	// has none
	Number int `json:"number,omitempty"`
	// Heading is the subheading the paragraph belongs to
	Heading string `json:"heading,omitempty"`
	// Verse is the number of a Bible verse, or 0 for a paragraph
	Verse int `json:"verse,omitempty"`
}

Snippet is the text of a paragraph, split around the tokens of a marking

func MarkingSnippets

func MarkingSnippets(ctx context.Context, cacheDir string, location *model.Location, blockRanges []*model.BlockRange, progress func(downloaded int64, total int64)) ([]Snippet, error)

MarkingSnippets returns the text of the paragraphs or Bible verses that a marking covers. Those that are not available are left out, and so are all of them if jw.org has no EPUB of the publication. The text comes from the EPUB of the publication on jw.org. Only the text is kept in cacheDir, so each publication is downloaded once. While it downloads, progress, if not nil, is told how many bytes are downloaded out of total, which is -1 if unknown.

func Shorten

func Shorten(s Snippet) Snippet

Shorten keeps only the sentences of a snippet that contain the marked text. Context that is still longer than maxContext is cut at a word and marked with "…".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址