core

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package core provides HLS (HTTP Live Streaming) download functionality.

Index

Constants

View Source
const (
	ActionPlay     Action = "play"
	ActionDownload Action = "download"

	Movie  MediaType = "movie"
	Series MediaType = "series"
)
View Source
const (
	FLIXHQ_BASE_URL   = "https://flixhq.to"
	FLIXHQ_SEARCH_URL = FLIXHQ_BASE_URL + "/search"
	FLIXHQ_AJAX_URL   = FLIXHQ_BASE_URL + "/ajax"
	TMDB_API_KEY      = "653bb8af90162bd98fc7ee32bcbbfb3d"
	TMDB_BASE_URL     = "https://api.themoviedb.org/3"
)
View Source
const TMDB_IMAGE_BASE_URL = "https://image.tmdb.org/t/p/w500"

TMDB_IMAGE_BASE_URL is the prefix for constructing poster image URLs.

Variables

View Source
var Version string = "v1.1.1"

Functions

func CleanCache

func CleanCache() error

func DecryptEmbedSu

func DecryptEmbedSu(urlStr string, client *http.Client) (string, []string, string, error)

func DecryptGeneric added in v1.0.18

func DecryptGeneric(urlStr string, client *http.Client) (string, []string, string, error)

func DecryptMegacloud added in v1.0.18

func DecryptMegacloud(urlStr string, client *http.Client) (string, []string, string, error)

func DecryptMegacloudFromPage added in v1.0.18

func DecryptMegacloudFromPage(urlStr string, client *http.Client) (string, []string, string, error)

func DecryptMultiembed added in v1.0.18

func DecryptMultiembed(urlStr string, client *http.Client) (string, []string, string, error)

func DecryptStream

func DecryptStream(embedLink string, client *http.Client) (string, []string, string, error)
func DecryptVidlink(urlStr string, client *http.Client) (string, []string, string, error)

func DecryptVidlinkStream added in v1.0.18

func DecryptVidlinkStream(urlStr, tmdbID string, client *http.Client) (string, []string, string, error)

func DecryptVidsrc

func DecryptVidsrc(urlStr string, client *http.Client) (string, []string, string, error)

func Download

func Download(basePath, dlPath, name, url, referer, userAgent string, subtitles []string, debug bool) error

Download downloads a stream to disk using a native Go implementation. HLS streams (*.m3u8) are downloaded by fetching and concatenating segments concurrently. Other URLs are downloaded directly, using parallel byte-range requests when the server supports them and the file is large enough.

Subtitle files (VTT/SRT) are downloaded alongside the video when provided.

func DownloadHLS added in v1.1.0

func DownloadHLS(ctx context.Context, streamURL, outputPath, referer string, progressCallback func(int, int)) error

DownloadHLS downloads an HLS stream to outputPath, reporting segment progress via progressCallback(downloadedSegments, totalSegments). Pass nil to skip progress reporting.

func DownloadPoster

func DownloadPoster(url string, title string) (string, error)

func DownloadYTDLP added in v1.1.0

func DownloadYTDLP(basePath, dlPath, name, url, referer, userAgent string, debug bool) error

DownloadYTDLP downloads a URL using yt-dlp. It is intended for providers (e.g. YouTube) whose URLs yt-dlp handles natively.

func FormatRecommendLabel added in v1.1.0

func FormatRecommendLabel(r Recommendation) string

FormatRecommendLabel returns the fzf label for a recommendation.

func FormatShowLabel added in v1.1.0

func FormatShowLabel(s ShowSummary) string

FormatShowLabel returns a human-readable fzf label for a show summary.

func GetCacheDir

func GetCacheDir() (string, error)

func NewClient

func NewClient() *http.Client

func NewRequest

func NewRequest(method, url string) (*http.Request, error)

func ParseEpisodeRange

func ParseEpisodeRange(s string) ([]int, error)

func Play

func Play(url, title, referer, userAgent string, subtitles []string, debug bool, startSecs float64) (float64, error)

Play starts the player and blocks until it exits. Returns the final playback position in seconds; 0 if not tracked.

func PreviewPoster

func PreviewPoster(path string) error

func PreviewWithBackend added in v1.1.0

func PreviewWithBackend(path, backend string) error

PreviewWithBackend renders the image at path using chafa with the given backend.

func Prompt

func Prompt(label string) string

func Select

func Select(label string, items []string) int

func SelectAction added in v1.1.0

func SelectAction(label string, actions []string) string

SelectAction shows an fzf menu with the given action labels and returns the label of the chosen action. Returns "" if the selection is cancelled.

func SelectActionCtx added in v1.1.1

func SelectActionCtx(label string, actions []string, done <-chan struct{}) string

SelectActionCtx is like SelectAction but takes an optional done channel. If done is closed before the user makes a selection, fzf is killed and "" is returned — this lets the caller detect that the player exited on its own.

func SelectQuality added in v1.0.19

func SelectQuality(qualities []Quality, selectBest bool) (string, error)

func SelectWithPreview

func SelectWithPreview(label string, items []string, previewCmd string) int

func StartPlayer added in v1.1.0

func StartPlayer(url, title, referer, userAgent string, subtitles []string, debug bool, wlDir string, startSecs float64) (*exec.Cmd, error)

StartPlayer launches the player in the background with its output suppressed so the terminal stays available for the fzf control menu. wlDir is passed to mpv's --watch-later-directory if non-empty. startSecs, if > 0, tells mpv to seek to that position before playing. Returns the running *exec.Cmd so the caller can wait on or kill it.

Types

type Action

type Action string

type Config

type Config struct {
	FzfPath      string `yaml:"fzf_path"`
	Player       string `yaml:"player"`
	ImageBackend string `yaml:"image_backend"`
	Provider     string `yaml:"provider"`
	DlPath       string `yaml:"dl_path"`
	Quality      string `yaml:"quality"`
}

func LoadConfig

func LoadConfig() *Config

type Context

type Context struct {
	Client *http.Client

	Query       string
	URL         string
	Title       string
	ContentType MediaType

	Season   int
	Episodes []int

	SelectedMedia []EpisodeData
	PlayType      Action
	Debug         bool
}

type DB added in v1.1.0

type DB struct {
	// contains filtered or unexported fields
}

DB wraps an open SQLite database for history operations.

func OpenHistory added in v1.1.0

func OpenHistory() (*DB, error)

OpenHistory opens (or creates) the history database.

func (*DB) AddEntry added in v1.1.0

func (db *DB) AddEntry(e HistoryEntry) error

AddEntry inserts a new history record.

func (*DB) Close added in v1.1.0

func (db *DB) Close() error

Close releases the database connection.

func (*DB) GetLastPosition added in v1.1.1

func (db *DB) GetLastPosition(title string, season, episode int) (float64, error)

GetLastPosition returns the most recently recorded playback position in seconds for the given title, season and episode. Returns 0 if no record is found.

func (*DB) ListShows added in v1.1.0

func (db *DB) ListShows() ([]ShowSummary, error)

ListShows returns one row per unique (title, url) pair, ordered by the most recent watch time descending. This is what --history displays.

type DecryptResponse

type DecryptResponse struct {
	Sources []DecryptedSource `json:"sources"`
	Tracks  []DecryptedTrack  `json:"tracks"`
}

type DecryptedSource

type DecryptedSource struct {
	File  string `json:"file"`
	Type  string `json:"type"`
	Label string `json:"label"`
}

type DecryptedTrack

type DecryptedTrack struct {
	File  string `json:"file"`
	Kind  string `json:"kind"`
	Label string `json:"label"`
}

type Episode

type Episode struct {
	ID   string
	Name string
}

type EpisodeData

type EpisodeData struct {
	File    string
	Label   string
	Type    string
	Season  int
	Episode int
}

type HistoryEntry added in v1.1.0

type HistoryEntry struct {
	ID       int64
	Title    string
	Season   int    // 0 for movies
	Episode  int    // 0 for movies
	EpName   string // episode display name, empty for movies
	URL      string // provider media URL (used to resume)
	Provider string // provider name (e.g. "flixhq", "sflix")

	// PositionSecs is the playback position in seconds as written by mpv's
	// watch-later file (e.g. 1234.56).  0 means start / not tracked.
	PositionSecs float64

	WatchedAt time.Time
}

HistoryEntry represents a single watch history record.

type MediaType

type MediaType string

type PlayResult added in v1.1.1

type PlayResult struct {
	Action       PlaybackAction
	PositionSecs float64 // seconds; 0 if not tracked
}

PlayResult bundles the chosen action and the final playback position.

func PlayWithControls added in v1.1.0

func PlayWithControls(url, title, referer, userAgent string, subtitles []string, debug bool, startSecs float64) (PlayResult, error)

PlayWithControls starts the player in the background and shows an fzf menu with Replay / Next / Previous / Quit. It kills the running player process before returning so the caller can act on the chosen action immediately. Returns a PlayResult containing the chosen action and the last tracked position.

type PlaybackAction added in v1.1.0

type PlaybackAction string

PlaybackAction represents what the user chose from the playback control menu.

const (
	PlaybackReplay   PlaybackAction = "Replay"
	PlaybackNext     PlaybackAction = "Next"
	PlaybackPrevious PlaybackAction = "Previous"
	PlaybackQuit     PlaybackAction = "Quit"
)

type Provider

type Provider interface {
	Search(query string) ([]SearchResult, error)
	GetMediaID(url string) (string, error)
	GetSeasons(mediaID string) ([]Season, error)
	GetEpisodes(id string, isSeason bool) ([]Episode, error)
	GetServers(episodeID string) ([]Server, error)
	GetLink(serverID string) (string, error)
}

type Quality added in v1.0.19

type Quality struct {
	URL        string
	Resolution string
	Bandwidth  int
	Height     int
	Label      string
}

func GetBestQuality added in v1.0.19

func GetBestQuality(qualities []Quality) Quality

func GetQualities added in v1.0.19

func GetQualities(m3u8URL string, client *http.Client, referer string) ([]Quality, string, error)

type Recommendation added in v1.1.0

type Recommendation struct {
	Title      string
	MediaType  MediaType // Movie or Series
	Year       string
	Overview   string
	TmdbID     int
	Score      float64 // internal relevance score, higher is better
	PosterPath string  // TMDB poster_path (e.g. "/abc123.jpg"); build full URL with TMDB_IMAGE_BASE_URL
}

Recommendation is a title suggested based on watch history.

func GetRecommendations added in v1.1.0

func GetRecommendations(client *http.Client) ([]Recommendation, error)

GetRecommendations builds a taste profile from the user's watch history and returns a ranked list of titles the user has not yet watched.

Algorithm:

  1. Load history; assign each show a recency weight (exponential decay).
  2. For each show, fetch its TMDB genre and keyword IDs; accumulate into the taste profile weighted by recency.
  3. Derive the top genres from the profile and use /discover to pull a pool of candidate movies and TV shows.
  4. Score every candidate: sum of matched genre weight + keyword weight from the profile, multiplied by a quality factor (vote_average * log(vote_count+1)).
  5. Exclude already-watched titles, sort by score descending, return top 50.

type SearchResult

type SearchResult struct {
	Title  string
	URL    string
	Type   MediaType
	Poster string
	Year   string
}

type Season

type Season struct {
	ID   string
	Name string
}

type Server

type Server struct {
	ID   string
	Name string
}

type ShowSummary added in v1.1.0

type ShowSummary struct {
	Title    string
	URL      string
	Provider string
	Season   int
	Episode  int
	EpName   string

	WatchedAt time.Time
}

ShowSummary is one entry per unique show (title+url), carrying the most recent watch details so the user can resume from where they left off.

type TmdbEpisode added in v1.0.8

type TmdbEpisode struct {
	ID            int    `json:"id"`
	EpisodeNumber int    `json:"episode_number"`
	Name          string `json:"name"`
}

type TmdbSearchResult added in v1.0.8

type TmdbSearchResult struct {
	Results []struct {
		ID           int    `json:"id"`
		MediaType    string `json:"media_type"`
		Title        string `json:"title"`
		Name         string `json:"name"`
		PosterPath   string `json:"poster_path"`
		ReleaseDate  string `json:"release_date"`
		FirstAirDate string `json:"first_air_date"`
	} `json:"results"`
}

type TmdbSeason added in v1.0.8

type TmdbSeason struct {
	ID           int    `json:"id"`
	Name         string `json:"name"`
	SeasonNumber int    `json:"season_number"`
}

type TmdbSeasonDetails added in v1.0.8

type TmdbSeasonDetails struct {
	Episodes []TmdbEpisode `json:"episodes"`
}

type TmdbShowDetails added in v1.0.8

type TmdbShowDetails struct {
	Seasons []TmdbSeason `json:"seasons"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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