telegram

package
v0.13.5 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package telegram provides Telegram media extraction and download functionality.

Index

Constants

View Source
const (
	// Telegram Desktop's public API credentials
	// Safe to use - already public and used by many tools
	DesktopAppID   = 2040
	DesktopAppHash = "b18441a1ff607e10a989891a5462e627"
)

Variables

This section is empty.

Functions

func ExtFromMime

func ExtFromMime(mime string) string

ExtFromMime returns file extension from MIME type

func FindLargestPhotoSize

func FindLargestPhotoSize(sizes []tg.PhotoSizeClass) *tg.PhotoSize

FindLargestPhotoSize finds the largest photo size from available sizes

func MatchURL

func MatchURL(urlStr string) bool

MatchURL checks if a URL string matches Telegram message patterns

func SessionExists

func SessionExists() bool

SessionExists checks if a Telegram session exists

func SessionFile

func SessionFile() string

SessionFile returns the full path to the desktop session file

func SessionPath

func SessionPath() string

SessionPath returns the path where Telegram session is stored Uses ~/.config/vget/telegram/ to match vget's standard config directory

Types

type ChannelInfo

type ChannelInfo struct {
	ID         int64
	AccessHash int64
	Title      string
	Username   string
}

ChannelInfo holds basic channel information for display

type DownloadOptions added in v0.11.2

type DownloadOptions struct {
	URL        string
	OutputPath string
	Takeout    bool // Use takeout session for lower rate limits
	ProgressFn func(downloaded, total int64)
}

DownloadOptions configures the download behavior

type DownloadResult

type DownloadResult struct {
	Title    string
	Filename string
	Size     int64
}

DownloadResult contains the result of a Telegram download

func Download

func Download(urlStr string, outputPath string, progressFn func(downloaded, total int64)) (*DownloadResult, error)

Download downloads media from a Telegram URL directly. This combines extraction and download because Telegram requires the download to happen within the authenticated client context.

func DownloadWithOptions added in v0.11.2

func DownloadWithOptions(opts DownloadOptions) (*DownloadResult, error)

DownloadWithOptions downloads media with configurable options including takeout mode

type ExtractedMedia

type ExtractedMedia struct {
	Title    string
	Filename string
	Ext      string
	Size     int64
	Width    int
	Height   int
	IsVideo  bool
	IsAudio  bool
	IsPhoto  bool
}

ExtractedMedia contains extracted media information

func ExtractDocumentInfo

func ExtractDocumentInfo(doc *tg.Document, messageText string, msgID int) *ExtractedMedia

ExtractDocumentInfo extracts metadata from a Telegram document

type Extractor

type Extractor struct{}

Extractor handles Telegram media extraction

func (*Extractor) Extract

func (e *Extractor) Extract(urlStr string) (*MediaInfo, error)

Extract retrieves media info from a Telegram URL

func (*Extractor) Match

func (e *Extractor) Match(u *url.URL) bool

Match checks if URL is a Telegram message URL

func (*Extractor) Name

func (e *Extractor) Name() string

Name returns the extractor name

type MediaInfo

type MediaInfo struct {
	ID       string
	Title    string
	Uploader string
	URL      string
	Ext      string
	Width    int
	Height   int
	Size     int64
	IsVideo  bool
	IsAudio  bool
	IsPhoto  bool
}

MediaInfo contains extracted media information for the extractor interface

type Message

type Message struct {
	ChannelUsername string // For public channels/users
	ChannelID       int64  // For private channels (from /c/ URLs)
	MessageID       int
	IsPrivate       bool
}

Message represents a parsed Telegram message URL

func ParseURL

func ParseURL(urlStr string) (*Message, error)

ParseURL parses a t.me URL into its components

type TakeoutSession added in v0.11.2

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

TakeoutSession manages a Telegram takeout session for bulk downloads with lower rate limits. Takeout is Telegram's official data export feature.

func NewTakeoutSession added in v0.11.2

func NewTakeoutSession(api *tg.Client) *TakeoutSession

NewTakeoutSession creates a new takeout session manager

func (*TakeoutSession) Active added in v0.11.2

func (t *TakeoutSession) Active() bool

Active returns true if a takeout session is active

func (*TakeoutSession) Finish added in v0.11.2

func (t *TakeoutSession) Finish(ctx context.Context) error

Finish closes the takeout session

func (*TakeoutSession) ID added in v0.11.2

func (t *TakeoutSession) ID() int64

ID returns the current takeout session ID

func (*TakeoutSession) Middleware added in v0.11.2

func (t *TakeoutSession) Middleware() telegram.Middleware

Middleware returns a telegram.Middleware that wraps all requests with takeout

func (*TakeoutSession) Start added in v0.11.2

func (t *TakeoutSession) Start(ctx context.Context) error

Start initiates a takeout session with Telegram This enables lower flood wait limits for bulk downloads

Jump to

Keyboard shortcuts

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