Documentation
¶
Index ¶
- func DownloadFile(ctx context.Context, urlStr, fileName string, overwrite bool) (string, error)
- func GetMessage(client *tg.Client, url string) (*tg.NewMessage, error)
- type ApiData
- type Download
- type DownloaderWrapper
- func (d *DownloaderWrapper) DownloadTrack(ctx context.Context, info cache.TrackInfo, video bool) (string, error)
- func (d *DownloaderWrapper) GetInfo(ctx context.Context) (cache.PlatformTracks, error)
- func (d *DownloaderWrapper) GetTrack(ctx context.Context) (cache.TrackInfo, error)
- func (d *DownloaderWrapper) IsValid() bool
- func (d *DownloaderWrapper) Search(ctx context.Context) (cache.PlatformTracks, error)
- type MusicService
- type YouTubeData
- func (y *YouTubeData) BuildYtdlpParams(videoID string, video bool) []string
- func (y *YouTubeData) GetInfo(ctx context.Context) (cache.PlatformTracks, error)
- func (y *YouTubeData) GetTrack(ctx context.Context) (cache.TrackInfo, error)
- func (y *YouTubeData) IsValid() bool
- func (y *YouTubeData) Search(ctx context.Context) (cache.PlatformTracks, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DownloadFile ¶
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 ¶
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 ¶
ApiData provides a unified interface for fetching track and playlist information from various music platforms via an API gateway.
func NewApiData ¶
NewApiData creates and initializes a new ApiData instance with the provided query.
func (*ApiData) GetInfo ¶
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 ¶
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 ¶
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.
type Download ¶
Download encapsulates the information and context required for a download operation.
func NewDownload ¶
NewDownload creates and validates a new Download instance. It returns an error if the track's CDN URL is missing.
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 ¶
func (d *DownloaderWrapper) GetInfo(ctx context.Context) (cache.PlatformTracks, error)
GetInfo retrieves metadata by delegating the call to the wrapped service.
func (*DownloaderWrapper) GetTrack ¶
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 ¶
func (d *DownloaderWrapper) Search(ctx context.Context) (cache.PlatformTracks, error)
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 ¶
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 ¶
func (y *YouTubeData) Search(ctx context.Context) (cache.PlatformTracks, error)
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.