Use an event ID

This commit is contained in:
Gabriel Augendre 2018-11-19 18:21:56 +01:00
parent 03138d3809
commit f76e8bbf42

View file

@ -35,10 +35,10 @@ func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) {
return bt, nil return bt, nil
} }
func scrapeVideos(startId string, fieldsToSend chan common.MapStr, done chan bool) { const BaseUrl = "https://www.youtube.com"
const BaseUrl = "https://www.youtube.com" const BaseSuffix = "/watch?v="
const BaseSuffix = "/watch?v="
func scrapeVideos(startId string, fieldsToSend chan common.MapStr, done chan bool) {
videoCollector := colly.NewCollector( videoCollector := colly.NewCollector(
colly.AllowedDomains("youtube.com", "www.youtube.com"), colly.AllowedDomains("youtube.com", "www.youtube.com"),
colly.Async(true), colly.Async(true),
@ -117,6 +117,10 @@ func (bt *Youtubebeat) Run(b *beat.Beat) error {
Timestamp: time.Now(), Timestamp: time.Now(),
Fields: fields, Fields: fields,
} }
id := strings.Replace(fields["url"].(string), BaseUrl+BaseSuffix, "", -1)
event.SetID(id)
bt.client.Publish(event) bt.client.Publish(event)
logp.Info("Event sent") logp.Info("Event sent")
} }