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
|
||||
}
|
||||
|
||||
func AddParser(p parser.Parser) {
|
||||
func AddParser(p ...parser.Parser) {
|
||||
parsersMu.Lock()
|
||||
defer parsersMu.Unlock()
|
||||
parsers = append(parsers, p)
|
||||
parsers = append(parsers, p...)
|
||||
}
|
||||
|
||||
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))
|
||||
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{
|
||||
URL: media.URL,
|
||||
Filename: path.Base(strings.Split(media.URL, "?")[0]),
|
||||
Size: size,
|
||||
})
|
||||
}
|
||||
item := &parser.Item{
|
||||
|
||||
Reference in New Issue
Block a user