dl

package
v1.2.5-0...-67eddf4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadFile

func DownloadFile(ctx context.Context, urlStr, fileName string, overwrite bool) (string, error)

DownloadFile downloads a file from a URL and saves it to a local path. It supports overwriting existing files and determines the filename automatically if not provided. It returns the final file path or an error if the download fails.

func GetMessage

func GetMessage(client *tg.Client, url string) (*tg.NewMessage, error)

GetMessage retrieves a Telegram message by its URL. It supports both public (e.g., https://t.me/ChannelName/1234) and private (e.g., https://t.me/c/12345678/90) URLs. It returns the message object or an error if the URL is invalid or the message cannot be fetched.

Types

type ApiData

type ApiData struct {
	Query    string
	ApiUrl   string
	APIKey   string
	Patterns map[string]*regexp.Regexp
}

ApiData provides a unified interface for fetching track and playlist information from various music platforms via an API gateway.

func NewApiData

func NewApiData(query string) *ApiData

NewApiData creates and initializes a new ApiData instance with the provided query.

func (*ApiData) GetInfo

func (a *ApiData) GetInfo(ctx context.Context) (cache.PlatformTracks, error)

GetInfo retrieves metadata for a track or playlist from the API. It returns a PlatformTracks object or an error if the request fails.

func (*ApiData) GetTrack

func (a *ApiData) GetTrack(ctx context.Context) (cache.TrackInfo, error)

GetTrack retrieves detailed information for a single track from the API. It returns a TrackInfo object or an error if the request fails.

func (*ApiData) IsValid

func (a *ApiData) IsValid() bool

IsValid checks if the query is a valid URL for any of the supported platforms. It returns true if the URL matches a known pattern, and false otherwise.

func (*ApiData) Search

func (a *ApiData) Search(ctx context.Context) (cache.PlatformTracks, error)

Search queries the API for a track. The context can be used for timeouts or cancellations. If the query is a valid URL, it fetches the information directly. It returns a PlatformTracks object or an error if the search fails.

type Download

type Download struct {
	Track cache.TrackInfo
	// contains filtered or unexported fields
}

Download encapsulates the information and context required for a download operation.

func NewDownload

func NewDownload(ctx context.Context, track cache.TrackInfo) (*Download, error)

NewDownload creates and validates a new Download instance. It returns an error if the track's CDN URL is missing.

func (*Download) Process

func (d *Download) Process() (string, error)

Process initiates the download process based on the track's platform. It returns the file path of the downloaded track or an error if the download fails.

type DownloaderWrapper

type DownloaderWrapper struct {
	Query   string
	Service MusicService
}

DownloaderWrapper provides a unified interface for music service interactions, wrapping a specific MusicService implementation and delegating calls to it.

func NewDownloaderWrapper

func NewDownloaderWrapper(query string) *DownloaderWrapper

NewDownloaderWrapper selects the appropriate MusicService based on the query format or configuration defaults. It returns a new DownloaderWrapper configured with the chosen service.

func (*DownloaderWrapper) DownloadTrack

func (d *DownloaderWrapper) DownloadTrack(ctx context.Context, info cache.TrackInfo, video bool) (string, error)

DownloadTrack downloads a track by delegating the call to the wrapped service. It returns the file path of the downloaded track or an error if the download fails.

func (*DownloaderWrapper) GetInfo

GetInfo retrieves metadata by delegating the call to the wrapped service.

func (*DownloaderWrapper) GetTrack

func (d *DownloaderWrapper) GetTrack(ctx context.Context) (cache.TrackInfo, error)

GetTrack retrieves detailed track information by delegating the call to the wrapped service.

func (*DownloaderWrapper) IsValid

func (d *DownloaderWrapper) IsValid() bool

IsValid checks if the underlying service can handle the query.

func (*DownloaderWrapper) Search

Search performs a search by delegating the call to the wrapped service.

type MusicService

type MusicService interface {
	// IsValid determines if the service can handle the given query.
	IsValid() bool
	// GetInfo retrieves metadata for a track or playlist.
	GetInfo(ctx context.Context) (cache.PlatformTracks, error)
	// Search queries the service for a track.
	Search(ctx context.Context) (cache.PlatformTracks, error)
	// GetTrack fetches detailed information for a single track.
	GetTrack(ctx context.Context) (cache.TrackInfo, error)
	// contains filtered or unexported methods
}

MusicService defines a standard interface for interacting with various music services. This allows for a unified approach to handling different platforms like YouTube, Spotify, etc.

type YouTubeData

type YouTubeData struct {
	Query    string
	ApiUrl   string
	APIKey   string
	Patterns map[string]*regexp.Regexp
}

YouTubeData provides an interface for fetching track and playlist information from YouTube.

func NewYouTubeData

func NewYouTubeData(query string) *YouTubeData

NewYouTubeData initializes a YouTubeData instance with pre-compiled regex patterns and a cleaned query.

func (*YouTubeData) BuildYtdlpParams

func (y *YouTubeData) BuildYtdlpParams(videoID string, video bool) []string

BuildYtdlpParams constructs the command-line parameters for yt-dlp to download media. It takes a video ID and a boolean indicating whether to download video or audio, and returns the corresponding parameters.

func (*YouTubeData) GetInfo

func (y *YouTubeData) GetInfo(ctx context.Context) (cache.PlatformTracks, error)

GetInfo retrieves metadata for a track from YouTube. It returns a PlatformTracks object or an error if the information cannot be fetched.

func (*YouTubeData) GetTrack

func (y *YouTubeData) GetTrack(ctx context.Context) (cache.TrackInfo, error)

GetTrack retrieves detailed information for a single track. It returns a TrackInfo object or an error if the track cannot be found.

func (*YouTubeData) IsValid

func (y *YouTubeData) IsValid() bool

IsValid checks if the query string matches any of the known YouTube URL patterns.

func (*YouTubeData) Search

Search performs a search for a track on YouTube. It accepts a context for handling timeouts and cancellations, and returns a PlatformTracks object or an error.

Jump to

Keyboard shortcuts

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