Commit 78e5f86b authored by Jürgen Enge's avatar Jürgen Enge

restore from backup

parent 8da5ec53
......@@ -126,9 +126,6 @@ func main() {
fm,
log)
cb := memocrawler.NewCrawlerBanner(cr, config.Banner.Timeout.Duration, config.Banner.Folder, config.Banner.Timestamp)
cr.SetCrawlerBanner(cb)
cl := memocrawler.NewCrawlerLinkcheck(cr, config.Crawler.Timeout.Duration, config.Crawler.HeaderSize)
cr.SetCrawlerLinkcheck(cl)
......
......@@ -45,7 +45,6 @@ type Crawler struct {
bannerfolder string
bannertimeout time.Duration
mapping *memostream.FileMapper
cb *CrawlerBanner
cl *CrawlerLinkcheck
jobQueue *JobQueue
jobChannel chan *Job
......@@ -104,10 +103,6 @@ type Metadata struct {
SFMatches []SFMatches `json:"siegfried"'`
}
func (cr *Crawler) SetCrawlerBanner(cb *CrawlerBanner) {
cr.cb = cb
}
func (cr *Crawler) SetCrawlerLinkcheck(cl *CrawlerLinkcheck) {
cr.cl = cl
}
......
// This file is part of Memobase Crawler which is released under GPLv3.
// See file license.txt for full license details.
//
// Author Juergen Enge <juergen@info-age.net>
//
// This code uses elements from
// * "Mediaserver" (Center for Digital Matter HGK FHNW, Basel)
// * "Remote Exhibition Project" (info-age GmbH, Basel)
//
package memocrawler
import (
"context"
"fmt"
"github.com/goph/emperror"
"gitlab.switch.ch/memoriav/memobase-2020/streaming-server/memostream"
"io/ioutil"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"
)
type CrawlerBanner struct {
crawler *Crawler
timeout time.Duration
folder string
timestamp string
}
func NewCrawlerBanner(crawler *Crawler,
Timeout time.Duration,
Folder string,
Timestamp string,
) *CrawlerBanner {
return &CrawlerBanner{
crawler: crawler,
timeout: Timeout,
folder: Folder,
timestamp: Timestamp,
}
}
func (cb *CrawlerBanner) getBanner(entry *memostream.MediaEntry) (string, error) {
var prg string
var params []string
var inputfilename string
var err error
if entry.Protocol == memostream.Media_File {
inputfilename, err = cb.crawler.mapping.Get(entry.URI)
if runtime.GOOS == "windows" {
inputfilename = strings.Replace(filepath.ToSlash(inputfilename), "c:", "/mnt/c", -1)
}
} else {
inputfilename = entry.URI.String()
}
if err != nil {
return "", emperror.Wrapf(err, "cannot get path for signature %s", entry.Signature)
}
outputfilename := filepath.Join(cb.folder, fmt.Sprintf("%s.png", entry.Signature))
// todo: bad hack for windows wsl...
if runtime.GOOS == "windows" {
prg = "wsl.exe"
params = append(params, cb.crawler.ffmpeg)
outputfilename = strings.Replace(filepath.ToSlash(outputfilename), "c:", "/mnt/c", -1)
} else {
prg = cb.crawler.ffmpeg
}
params = append(params,
"-ss", "00:00:12",
"-i", inputfilename,
"-vframes", "1",
"-q:v", "2",
outputfilename)
ctx, cancel := context.WithTimeout(context.Background(), cb.timeout)
defer cancel() // The cancel should be deferred so resources are cleaned up
cmd := exec.CommandContext(ctx, prg, params...)
stderr, err := cmd.StderrPipe()
if err != nil {
return "", emperror.Wrapf(err, "cannot get stderr output pipe")
}
output, err := cmd.Output()
if err != nil {
slurp, _ := ioutil.ReadAll(stderr)
return "", emperror.Wrapf(err, "cannot execute %s %s: %s", prg, strings.Join(params, " "), slurp)
}
cb.crawler.log.Debugf("banner: %s %s // %s", prg, strings.Join(params, ""), string(output))
return fmt.Sprintf("%s.png", entry.Signature), nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment