Merge branch 'main' of https://github.com/govdbot/govd
All checks were successful
Build and deploy / build-and-push-image (push) Successful in 8m40s
All checks were successful
Build and deploy / build-and-push-image (push) Successful in 8m40s
This commit is contained in:
commit
b90ca1d436
5 changed files with 70 additions and 63 deletions
|
@ -134,7 +134,7 @@ func HandleInlineCached(
|
||||||
PhotoFileId: format.FileID,
|
PhotoFileId: format.FileID,
|
||||||
Title: resultTitle,
|
Title: resultTitle,
|
||||||
Caption: mediaCaption,
|
Caption: mediaCaption,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}
|
}
|
||||||
case "video":
|
case "video":
|
||||||
result = &gotgbot.InlineQueryResultCachedVideo{
|
result = &gotgbot.InlineQueryResultCachedVideo{
|
||||||
|
@ -142,14 +142,14 @@ func HandleInlineCached(
|
||||||
VideoFileId: format.FileID,
|
VideoFileId: format.FileID,
|
||||||
Title: resultTitle,
|
Title: resultTitle,
|
||||||
Caption: mediaCaption,
|
Caption: mediaCaption,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}
|
}
|
||||||
case "audio":
|
case "audio":
|
||||||
result = &gotgbot.InlineQueryResultCachedAudio{
|
result = &gotgbot.InlineQueryResultCachedAudio{
|
||||||
Id: resultID,
|
Id: resultID,
|
||||||
AudioFileId: format.FileID,
|
AudioFileId: format.FileID,
|
||||||
Caption: mediaCaption,
|
Caption: mediaCaption,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}
|
}
|
||||||
case "document":
|
case "document":
|
||||||
result = &gotgbot.InlineQueryResultCachedDocument{
|
result = &gotgbot.InlineQueryResultCachedDocument{
|
||||||
|
@ -157,7 +157,7 @@ func HandleInlineCached(
|
||||||
DocumentFileId: format.FileID,
|
DocumentFileId: format.FileID,
|
||||||
Title: resultTitle,
|
Title: resultTitle,
|
||||||
Caption: mediaCaption,
|
Caption: mediaCaption,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return errors.New("unsupported input file type")
|
return errors.New("unsupported input file type")
|
||||||
|
@ -211,7 +211,7 @@ func StartInlineTask(
|
||||||
Title: "share",
|
Title: "share",
|
||||||
InputMessageContent: &gotgbot.InputTextMessageContent{
|
InputMessageContent: &gotgbot.InputTextMessageContent{
|
||||||
MessageText: "loading media plese wait...",
|
MessageText: "loading media plese wait...",
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
|
LinkPreviewOptions: &gotgbot.LinkPreviewOptions{
|
||||||
IsDisabled: true,
|
IsDisabled: true,
|
||||||
},
|
},
|
||||||
|
|
|
@ -29,7 +29,7 @@ func (b Client) RequestWithContext(
|
||||||
params["allow_sending_without_reply"] = "true"
|
params["allow_sending_without_reply"] = "true"
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(method, "send") || strings.HasPrefix(method, "edit") {
|
if strings.HasPrefix(method, "send") || strings.HasPrefix(method, "edit") {
|
||||||
params["parse_mode"] = "HTML"
|
params["parse_mode"] = gotgbot.ParseModeHTML
|
||||||
}
|
}
|
||||||
val, err := b.BotClient.RequestWithContext(ctx, token, method, params, data, opts)
|
val, err := b.BotClient.RequestWithContext(ctx, token, method, params, data, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
111
models/media.go
111
models/media.go
|
@ -17,6 +17,28 @@ import (
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
fileTypeDocument = "document"
|
||||||
|
fileTypePhoto = "photo"
|
||||||
|
fileTypeVideo = "video"
|
||||||
|
fileTypeAudio = "audio"
|
||||||
|
|
||||||
|
fileExtMP4 = "mp4"
|
||||||
|
fileExtWebM = "webm"
|
||||||
|
fileExtMP3 = "mp3"
|
||||||
|
fileExtM4A = "m4a"
|
||||||
|
fileExtFLAC = "flac"
|
||||||
|
fileExtOGG = "oga"
|
||||||
|
fileExtJPEG = "jpeg"
|
||||||
|
fileExtWebP = "webp"
|
||||||
|
fileExtJPG = "jpg"
|
||||||
|
fileExtGIF = "gif"
|
||||||
|
fileExtOGV = "ogv"
|
||||||
|
fileExtAVI = "avi"
|
||||||
|
fileExtMKV = "mkv"
|
||||||
|
fileExtMOV = "mov"
|
||||||
|
)
|
||||||
|
|
||||||
type Media struct {
|
type Media struct {
|
||||||
ID uint `json:"-"`
|
ID uint `json:"-"`
|
||||||
ContentID string `gorm:"not null;index" json:"content_id"`
|
ContentID string `gorm:"not null;index" json:"content_id"`
|
||||||
|
@ -305,7 +327,7 @@ func getTypePriority(mediaType enums.MediaType) int64 {
|
||||||
// getFormatInfo returns the file extension and the InputMedia type.
|
// getFormatInfo returns the file extension and the InputMedia type.
|
||||||
func (format *MediaFormat) GetFormatInfo() (string, string) {
|
func (format *MediaFormat) GetFormatInfo() (string, string) {
|
||||||
if format.Type == enums.MediaTypePhoto {
|
if format.Type == enums.MediaTypePhoto {
|
||||||
return "jpeg", "photo"
|
return fileExtJPEG, fileTypePhoto
|
||||||
}
|
}
|
||||||
|
|
||||||
videoCodec := format.VideoCodec
|
videoCodec := format.VideoCodec
|
||||||
|
@ -313,45 +335,30 @@ func (format *MediaFormat) GetFormatInfo() (string, string) {
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case videoCodec == enums.MediaCodecAVC && audioCodec == enums.MediaCodecAAC:
|
case videoCodec == enums.MediaCodecAVC && audioCodec == enums.MediaCodecAAC:
|
||||||
return "mp4", "video"
|
return fileExtMP4, fileTypeVideo
|
||||||
case videoCodec == enums.MediaCodecAVC && audioCodec == enums.MediaCodecMP3:
|
case videoCodec == enums.MediaCodecAVC && audioCodec == enums.MediaCodecMP3:
|
||||||
return "mp4", "video"
|
return fileExtMP4, fileTypeVideo
|
||||||
case videoCodec == enums.MediaCodecHEVC && audioCodec == enums.MediaCodecAAC:
|
case videoCodec == enums.MediaCodecHEVC && audioCodec == enums.MediaCodecAAC:
|
||||||
return "mp4", "document"
|
return fileExtMP4, fileTypeDocument
|
||||||
case videoCodec == enums.MediaCodecHEVC && audioCodec == enums.MediaCodecMP3:
|
case videoCodec == enums.MediaCodecHEVC && audioCodec == enums.MediaCodecMP3:
|
||||||
return "mp4", "document"
|
return fileExtMP4, fileTypeDocument
|
||||||
case videoCodec == enums.MediaCodecAV1 && audioCodec == enums.MediaCodecOpus:
|
|
||||||
return "webm", "document"
|
|
||||||
case videoCodec == enums.MediaCodecAV1 && audioCodec == enums.MediaCodecFLAC:
|
|
||||||
return "webm", "document"
|
|
||||||
case videoCodec == enums.MediaCodecVP9 && audioCodec == enums.MediaCodecOpus:
|
|
||||||
return "webm", "document"
|
|
||||||
case videoCodec == enums.MediaCodecVP9 && audioCodec == enums.MediaCodecFLAC:
|
|
||||||
return "webm", "document"
|
|
||||||
case videoCodec == enums.MediaCodecAVC && audioCodec == "":
|
case videoCodec == enums.MediaCodecAVC && audioCodec == "":
|
||||||
return "mp4", "video"
|
return fileExtMP4, fileTypeVideo
|
||||||
case videoCodec == enums.MediaCodecHEVC && audioCodec == "":
|
case videoCodec == enums.MediaCodecHEVC && audioCodec == "":
|
||||||
return "mp4", "document"
|
return fileExtMP4, fileTypeDocument
|
||||||
case videoCodec == enums.MediaCodecAV1 && audioCodec == "":
|
|
||||||
return "webm", "document"
|
|
||||||
case videoCodec == enums.MediaCodecVP9 && audioCodec == "":
|
|
||||||
return "webm", "document"
|
|
||||||
case videoCodec == enums.MediaCodecVP8 && audioCodec == "":
|
|
||||||
return "webm", "document"
|
|
||||||
case videoCodec == enums.MediaCodecWebP && audioCodec == "":
|
case videoCodec == enums.MediaCodecWebP && audioCodec == "":
|
||||||
return "webp", "video"
|
return fileExtWebP, fileTypeVideo
|
||||||
case videoCodec == "" && audioCodec == enums.MediaCodecMP3:
|
case videoCodec == "" && audioCodec == enums.MediaCodecMP3:
|
||||||
return "mp3", "audio"
|
return fileExtMP3, fileTypeAudio
|
||||||
case videoCodec == "" && audioCodec == enums.MediaCodecAAC:
|
case videoCodec == "" && audioCodec == enums.MediaCodecAAC:
|
||||||
return "m4a", "audio"
|
return fileExtM4A, fileTypeAudio
|
||||||
case videoCodec == "" && audioCodec == enums.MediaCodecOpus:
|
|
||||||
return "webm", "document"
|
|
||||||
case videoCodec == "" && audioCodec == enums.MediaCodecFLAC:
|
case videoCodec == "" && audioCodec == enums.MediaCodecFLAC:
|
||||||
return "flac", "document"
|
return fileExtFLAC, fileTypeDocument
|
||||||
case videoCodec == "" && audioCodec == enums.MediaCodecVorbis:
|
case videoCodec == "" && audioCodec == enums.MediaCodecVorbis:
|
||||||
return "oga", "document"
|
return fileExtOGG, fileTypeDocument
|
||||||
default:
|
default:
|
||||||
return "webm", "document"
|
// all other cases, we return webm as document
|
||||||
|
return fileExtWebM, fileTypeDocument
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,7 +394,8 @@ func (format *MediaFormat) GetInputMedia(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if inputMediaType == "video" {
|
switch inputMediaType {
|
||||||
|
case fileTypeVideo:
|
||||||
return &gotgbot.InputMediaVideo{
|
return &gotgbot.InputMediaVideo{
|
||||||
Media: fileInputMedia,
|
Media: fileInputMedia,
|
||||||
Thumbnail: thumbnailFileInputMedia,
|
Thumbnail: thumbnailFileInputMedia,
|
||||||
|
@ -396,10 +404,9 @@ func (format *MediaFormat) GetInputMedia(
|
||||||
Duration: format.Duration,
|
Duration: format.Duration,
|
||||||
Caption: messageCaption,
|
Caption: messageCaption,
|
||||||
SupportsStreaming: true,
|
SupportsStreaming: true,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
case fileTypeAudio:
|
||||||
if inputMediaType == "audio" {
|
|
||||||
return &gotgbot.InputMediaAudio{
|
return &gotgbot.InputMediaAudio{
|
||||||
Media: fileInputMedia,
|
Media: fileInputMedia,
|
||||||
Thumbnail: thumbnailFileInputMedia,
|
Thumbnail: thumbnailFileInputMedia,
|
||||||
|
@ -407,25 +414,24 @@ func (format *MediaFormat) GetInputMedia(
|
||||||
Performer: format.Artist,
|
Performer: format.Artist,
|
||||||
Title: format.Title,
|
Title: format.Title,
|
||||||
Caption: messageCaption,
|
Caption: messageCaption,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
case fileTypePhoto:
|
||||||
if inputMediaType == "photo" {
|
|
||||||
return &gotgbot.InputMediaPhoto{
|
return &gotgbot.InputMediaPhoto{
|
||||||
Media: fileInputMedia,
|
Media: fileInputMedia,
|
||||||
Caption: messageCaption,
|
Caption: messageCaption,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
case fileTypeDocument:
|
||||||
if inputMediaType == "document" {
|
|
||||||
return &gotgbot.InputMediaDocument{
|
return &gotgbot.InputMediaDocument{
|
||||||
Media: fileInputMedia,
|
Media: fileInputMedia,
|
||||||
Thumbnail: thumbnailFileInputMedia,
|
Thumbnail: thumbnailFileInputMedia,
|
||||||
Caption: messageCaption,
|
Caption: messageCaption,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}, nil
|
}, nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unknown input type: %s", inputMediaType)
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("unknown input type: %s", inputMediaType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (format *MediaFormat) GetInputMediaWithFileID(
|
func (format *MediaFormat) GetInputMediaWithFileID(
|
||||||
|
@ -433,35 +439,34 @@ func (format *MediaFormat) GetInputMediaWithFileID(
|
||||||
) (gotgbot.InputMedia, error) {
|
) (gotgbot.InputMedia, error) {
|
||||||
_, inputMediaType := format.GetFormatInfo()
|
_, inputMediaType := format.GetFormatInfo()
|
||||||
fileInputMedia := gotgbot.InputFileByID(format.FileID)
|
fileInputMedia := gotgbot.InputFileByID(format.FileID)
|
||||||
if inputMediaType == "video" {
|
switch inputMediaType {
|
||||||
|
case fileTypeVideo:
|
||||||
return &gotgbot.InputMediaVideo{
|
return &gotgbot.InputMediaVideo{
|
||||||
Media: fileInputMedia,
|
Media: fileInputMedia,
|
||||||
Caption: messageCaption,
|
Caption: messageCaption,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
case fileTypeAudio:
|
||||||
if inputMediaType == "audio" {
|
|
||||||
return &gotgbot.InputMediaAudio{
|
return &gotgbot.InputMediaAudio{
|
||||||
Media: fileInputMedia,
|
Media: fileInputMedia,
|
||||||
Caption: messageCaption,
|
Caption: messageCaption,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
case fileTypePhoto:
|
||||||
if inputMediaType == "photo" {
|
|
||||||
return &gotgbot.InputMediaPhoto{
|
return &gotgbot.InputMediaPhoto{
|
||||||
Media: fileInputMedia,
|
Media: fileInputMedia,
|
||||||
Caption: messageCaption,
|
Caption: messageCaption,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
case fileTypeDocument:
|
||||||
if inputMediaType == "document" {
|
|
||||||
return &gotgbot.InputMediaDocument{
|
return &gotgbot.InputMediaDocument{
|
||||||
Media: fileInputMedia,
|
Media: fileInputMedia,
|
||||||
Caption: messageCaption,
|
Caption: messageCaption,
|
||||||
ParseMode: "HTML",
|
ParseMode: gotgbot.ParseModeHTML,
|
||||||
}, nil
|
}, nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unknown input type: %s", inputMediaType)
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("unknown input type: %s", inputMediaType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (format *MediaFormat) GetFileName() string {
|
func (format *MediaFormat) GetFileName() string {
|
||||||
|
|
|
@ -41,7 +41,7 @@ func DefaultConfig() *models.DownloadConfig {
|
||||||
|
|
||||||
func DownloadFile(
|
func DownloadFile(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
URLList []string,
|
urlList []string,
|
||||||
fileName string,
|
fileName string,
|
||||||
config *models.DownloadConfig,
|
config *models.DownloadConfig,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
|
@ -50,7 +50,7 @@ func DownloadFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
var errs []error
|
var errs []error
|
||||||
for _, fileURL := range URLList {
|
for _, fileURL := range urlList {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return "", ctx.Err()
|
return "", ctx.Err()
|
||||||
|
@ -118,7 +118,7 @@ func DownloadFileWithSegments(
|
||||||
|
|
||||||
func DownloadFileInMemory(
|
func DownloadFileInMemory(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
URLList []string,
|
urlList []string,
|
||||||
config *models.DownloadConfig,
|
config *models.DownloadConfig,
|
||||||
) (*bytes.Reader, error) {
|
) (*bytes.Reader, error) {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
|
@ -126,7 +126,7 @@ func DownloadFileInMemory(
|
||||||
}
|
}
|
||||||
|
|
||||||
var errs []error
|
var errs []error
|
||||||
for _, fileURL := range URLList {
|
for _, fileURL := range urlList {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
package parser
|
package parser
|
||||||
|
|
||||||
|
// todo
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue