mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-07-11 15:31:22 +08:00
feat: support multiple parser additions and include media size in Twitter parser
This commit is contained in:
@@ -20,10 +20,10 @@ func GetParsers() []parser.Parser {
|
|||||||
return parsers
|
return parsers
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddParser(p parser.Parser) {
|
func AddParser(p ...parser.Parser) {
|
||||||
parsersMu.Lock()
|
parsersMu.Lock()
|
||||||
defer parsersMu.Unlock()
|
defer parsersMu.Unlock()
|
||||||
parsers = append(parsers, p)
|
parsers = append(parsers, p...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -60,9 +60,16 @@ func (p *TwitterParser) Parse(u string) (*parser.Item, error) {
|
|||||||
}
|
}
|
||||||
resources := make([]parser.Resource, 0, len(fxResp.Tweet.Media.All))
|
resources := make([]parser.Resource, 0, len(fxResp.Tweet.Media.All))
|
||||||
for _, media := range fxResp.Tweet.Media.All {
|
for _, media := range fxResp.Tweet.Media.All {
|
||||||
|
var size int64
|
||||||
|
resp, err := p.client.Get(media.URL)
|
||||||
|
if err == nil {
|
||||||
|
size = resp.ContentLength
|
||||||
|
resp.Body.Close()
|
||||||
|
}
|
||||||
resources = append(resources, parser.Resource{
|
resources = append(resources, parser.Resource{
|
||||||
URL: media.URL,
|
URL: media.URL,
|
||||||
Filename: path.Base(strings.Split(media.URL, "?")[0]),
|
Filename: path.Base(strings.Split(media.URL, "?")[0]),
|
||||||
|
Size: size,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
item := &parser.Item{
|
item := &parser.Item{
|
||||||
|
|||||||
Reference in New Issue
Block a user