Documentation
¶
Index ¶
- Variables
- func CatalogExists(path string) bool
- func CatalogNeedsUpdate(path string) bool
- func CatalogSize(path string) int64
- func DownloadCatalog(ctx context.Context, prgrs chan Progress, dst string) error
- func NeedsDownload(cacheDir string, location *model.Location, blockRanges []*model.BlockRange) bool
- type Lookup
- type Progress
- type Publication
- type Snippet
Constants ¶
This section is empty.
Variables ¶
var CatalogURL = "https://app.jw-cdn.org/catalogs/publications/v4/%s/catalog.db.gz"
CatalogURL is the URL to the publication catalog
var ManifestURL = "https://app.jw-cdn.org/catalogs/publications/v4/manifest.json"
ManifestURL is the URL to the publication manifest
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 ¶
CatalogExists checks if catalog.db exists at path
func CatalogNeedsUpdate ¶
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 ¶
CatalogSize returns the size of the catalog.db at path
func DownloadCatalog ¶
DownloadCatalog downloads the newest catalog.db and saves it at dst. The prgrs channel informs about the progress of the download.
func NeedsDownload ¶
NeedsDownload reports whether MarkingSnippets has to download the publication of a marking first, because its text is not in cacheDir yet.
Types ¶
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.