Skip to content

Commit

Permalink
feat: 视频封面优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Aug 29, 2024
1 parent 4c1132e commit ba9282a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 44 deletions.
10 changes: 5 additions & 5 deletions client/packets/oidb/group_video_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ func BuildGroupVideoUploadReq(groupUin uint32, video *message.ShortVideoElement)
SubFileType: 0,
}, {
FileInfo: &oidb.FileInfo{
FileSize: video.ThumbSize,
FileHash: hex.EncodeToString(video.ThumbMd5),
FileSha1: hex.EncodeToString(video.ThumbSha1),
FileSize: video.Thumb.Size,
FileHash: hex.EncodeToString(video.Thumb.Md5),
FileSha1: hex.EncodeToString(video.Thumb.Sha1),
FileName: "video.jpg",
Type: &oidb.FileType{
Type: 1,
PicFormat: 0,
VideoFormat: 0,
VoiceFormat: 0,
},
Width: 1920,
Height: 1080,
Width: video.Thumb.Width,
Height: video.Thumb.Height,
Time: 0,
Original: 0,
},
Expand Down
10 changes: 5 additions & 5 deletions client/packets/oidb/private_video_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ func BuildPrivateVideoUploadReq(targetUid string, video *message.ShortVideoEleme
SubFileType: 0,
}, {
FileInfo: &oidb.FileInfo{
FileSize: video.ThumbSize,
FileHash: hex.EncodeToString(video.ThumbMd5),
FileSha1: hex.EncodeToString(video.ThumbSha1),
FileSize: video.Thumb.Size,
FileHash: hex.EncodeToString(video.Thumb.Md5),
FileSha1: hex.EncodeToString(video.Thumb.Sha1),
FileName: "video.jpg",
Type: &oidb.FileType{
Type: 1,
PicFormat: 0,
VideoFormat: 0,
VoiceFormat: 0,
},
Width: 1920,
Height: 1080,
Width: video.Thumb.Width,
Height: video.Thumb.Height,
Time: 0,
Original: 0,
},
Expand Down
4 changes: 2 additions & 2 deletions client/richmedia.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (c *QQClient) VideoUploadPrivate(targetUid string, video *message.ShortVide
if err != nil {
return nil, err
}
err = c.highwayUpload(1002, video.Thumb, uint64(video.ThumbSize), md5, extStream)
err = c.highwayUpload(1002, video.Thumb.Stream, uint64(video.Thumb.Size), md5, extStream)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -446,7 +446,7 @@ func (c *QQClient) VideoUploadGroup(groupUin uint32, video *message.ShortVideoEl
if err != nil {
return nil, err
}
err = c.highwayUpload(1006, video.Thumb, uint64(video.ThumbSize), md5, extStream)
err = c.highwayUpload(1006, video.Thumb.Stream, uint64(video.Thumb.Size), md5, extStream)
if err != nil {
return nil, err
}
Expand Down
75 changes: 49 additions & 26 deletions message/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"path/filepath"
"strconv"

"github.com/LagrangeDev/LagrangeGo/utils"

"github.com/LagrangeDev/LagrangeGo/utils/audio"

"github.com/tidwall/gjson"
Expand Down Expand Up @@ -104,23 +106,29 @@ type (
}

ShortVideoElement struct {
Name string
Uuid []byte
Size uint32
ThumbSize uint32
Url string
Duration uint32
Name string
Uuid []byte
Size uint32
Url string
Duration uint32

// send
Thumb io.ReadSeeker
Summary string
Md5 []byte
Sha1 []byte
ThumbMd5 []byte
ThumbSha1 []byte
Stream io.ReadSeeker
MsgInfo *oidb.MsgInfo
Compat *message.VideoFile
Thumb *VideoThumb
Summary string
Md5 []byte
Sha1 []byte
Stream io.ReadSeeker
MsgInfo *oidb.MsgInfo
Compat *message.VideoFile
}

VideoThumb struct {
Stream io.ReadSeeker
Size uint32
Md5 []byte
Sha1 []byte
Width uint32
Height uint32
}

LightAppElement struct {
Expand Down Expand Up @@ -252,18 +260,14 @@ func NewSteramVideo(r io.ReadSeeker, thumb io.ReadSeeker, Summary ...string) *Sh
summary = Summary[0]
}
md5, sha1, length := crypto.ComputeMd5AndSha1AndLength(r)
thumbMd5, thumbSha1, thumbSize := crypto.ComputeMd5AndSha1AndLength(thumb)
return &ShortVideoElement{
Size: uint32(length),
ThumbSize: uint32(thumbSize),
Thumb: thumb,
Summary: summary,
Md5: md5,
Sha1: sha1,
ThumbMd5: thumbMd5,
ThumbSha1: thumbSha1,
Stream: r,
Compat: &message.VideoFile{},
Size: uint32(length),
Thumb: NewVideoThumb(thumb),
Summary: summary,
Md5: md5,
Sha1: sha1,
Stream: r,
Compat: &message.VideoFile{},
}
}

Expand All @@ -275,6 +279,25 @@ func NewFileVideo(path string, thumb []byte, Summary ...string) (*ShortVideoElem
return NewSteramVideo(file, bytes.NewReader(thumb), Summary...), nil
}

func NewVideoThumb(r io.ReadSeeker) *VideoThumb {
width := uint32(1920)
height := uint32(1080)
md5, sha1, size := crypto.ComputeMd5AndSha1AndLength(r)
_, imgSize, err := utils.ImageResolve(r)
if err == nil {
width = uint32(imgSize.Width)
height = uint32(imgSize.Height)
}
return &VideoThumb{
Stream: r,
Size: uint32(size),
Md5: md5,
Sha1: sha1,
Width: width,
Height: height,
}
}

func NewFile(data []byte, fileName string) *FileElement {
return NewStreamFile(bytes.NewReader(data), fileName)
}
Expand Down
14 changes: 8 additions & 6 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,14 @@ func parseMessageElements(msg []*message.Elem) []IMessageElement {
if elem.VideoFile != nil {
return []IMessageElement{
&ShortVideoElement{
Name: elem.VideoFile.FileName,
Uuid: utils.S2B(elem.VideoFile.FileUuid),
Size: uint32(elem.VideoFile.FileSize),
ThumbSize: uint32(elem.VideoFile.ThumbFileSize),
Md5: elem.VideoFile.FileMd5,
ThumbMd5: elem.VideoFile.ThumbFileMd5,
Name: elem.VideoFile.FileName,
Uuid: utils.S2B(elem.VideoFile.FileUuid),
Size: uint32(elem.VideoFile.FileSize),
Md5: elem.VideoFile.FileMd5,
Thumb: &VideoThumb{
Size: uint32(elem.VideoFile.ThumbFileSize),
Md5: elem.VideoFile.ThumbFileMd5,
},
},
}
}
Expand Down

0 comments on commit ba9282a

Please sign in to comment.