Introduce "--images" flag to enable image link parsing and disable image link parsing by default.

develop
Icedream 2016-07-26 20:36:36 +02:00
parent 6d70e02641
commit b37a15ac1f
Signed by: icedream
GPG Key ID: 1573F6D8EFE4D0CF
2 changed files with 32 additions and 16 deletions

12
main.go
View File

@ -32,6 +32,8 @@ func main() {
var soundcloudClientId string
var soundcloudClientSecret string
var webEnableImages bool
var debug bool
var useTLS bool
var server string
@ -58,9 +60,14 @@ func main() {
// Youtube config
kingpin.Flag("youtube-key", "The API key to use to access the YouTube API.").StringVar(&youtubeApiKey)
// SoundCloud config
kingpin.Flag("soundcloud-id", "The SoundCloud ID.").StringVar(&soundcloudClientId)
kingpin.Flag("soundcloud-secret", "The SoundCloud secret.").StringVar(&soundcloudClientSecret)
// Web parser config
kingpin.Flag("images", "Enables parsing links of images. Disabled by default for legal reasons.").BoolVar(&webEnableImages)
kingpin.Parse()
if len(nickname) == 0 {
@ -100,7 +107,10 @@ func main() {
must(m.RegisterParser(new(wikipedia.Parser)))
// Load web parser
must(m.RegisterParser(new(web.Parser)))
webParser := &web.Parser{
EnableImages: webEnableImages,
}
must(m.RegisterParser(webParser))
// IRC
conn := m.AntifloodIrcConn(irc.IRC(nickname, ident))

View File

@ -33,7 +33,9 @@ const (
maxHtmlSize = 8 * 1024
)
type Parser struct{}
type Parser struct {
EnableImages bool
}
func (p *Parser) Init() error {
return nil
@ -119,6 +121,7 @@ func (p *Parser) Parse(u *url.URL, referer *url.URL) (result parsers.ParseResult
result.Information[0]["Title"] = noTitleStr
}
case "image/png", "image/jpeg", "image/gif":
if p.EnableImages {
// No need to limit the reader to a specific size here as
// image.DecodeConfig only reads as much as needed anyways.
@ -134,8 +137,11 @@ func (p *Parser) Parse(u *url.URL, referer *url.URL) (result parsers.ParseResult
info["Size"] = uint64(resp.ContentLength)
}
result.Information = []map[string]interface{}{info}
log.Printf("Got through: %+v!", info)
}
break
}
fallthrough
default:
// TODO - Implement generic head info?
result.Ignored = true