Commit 76a0e8d7 authored by Markus Seidl's avatar Markus Seidl

* Add fbi as photo handler (instead of reencoding into video)

* Updated photo handling and video/photo detection
* Added /disk_free command
parent 5175f36d
......@@ -7,8 +7,8 @@ import (
"log"
"os"
"rgifbot/config"
"rgifbot/encoder/ffmpeg"
"strings"
"syscall"
"time"
tb "gopkg.in/tucnak/telebot.v2"
......@@ -46,10 +46,40 @@ func CCTelegramLoop(handler func(message Message) (timestamp time.Time, err erro
registerExitCommand(b)
registerPasswordCommand(b)
registerDiskFreeCommand(b)
b.Start()
}
func registerDiskFreeCommand(b *tb.Bot) {
b.Handle("/disk_free", func(m *tb.Message) {
if !isAllowed(b, m) {
return
}
wd, err := os.Getwd()
if err != nil {
sendMediaResponse(err, b, m, emptyTimestamp)
return
}
var stat syscall.Statfs_t
err = syscall.Statfs(wd, &stat)
if err != nil {
sendMediaResponse(err, b, m, emptyTimestamp)
return
}
avail := float32(stat.Bavail * uint64(stat.Bsize))
unit := "Bytes"
if avail < 1024 {
}
_, _ = b.Send(m.Sender, fmt.Sprintf("Disk free %g %s", avail, unit))
})
}
func registerPhotoHandler(b *tb.Bot, handler func(message Message) (timestamp time.Time, err error)) {
b.Handle(tb.OnPhoto, func(m *tb.Message) {
if !isAllowed(b, m) {
......@@ -70,7 +100,7 @@ func registerPhotoHandler(b *tb.Bot, handler func(message Message) (timestamp ti
return
}
f = ffmpeg.Convert(f)
// f = ffmpeg.Convert(f)
timestamp, err := handler(Message{Url: "", File: f})
sendMediaResponse(err, b, m, timestamp)
......
package display
import (
"github.com/h2non/filetype"
"io/ioutil"
"log"
"os/exec"
"rgifbot/config"
"rgifbot/player/fbi"
"rgifbot/player/mplayer"
"rgifbot/player/omxplayer"
"rgifbot/simpledb"
......@@ -45,12 +48,22 @@ func DisplayLoop(db *simpledb.Database) {
}
func execute(conf config.BotConfig, file string) {
log.Printf("Playing <%s>\n", file)
buf, _ := ioutil.ReadFile(file)
if conf.Player == "mplayer" {
mplayer.PlayAndWait(file)
} else if conf.Player == "omxplayer" {
omxplayer.PlayAndWait(conf, file)
isVideo := filetype.IsVideo(buf)
if isVideo {
log.Printf("Playing <%s>\n", file)
if conf.Player == "mplayer" {
mplayer.PlayAndWait(file)
} else if conf.Player == "omxplayer" {
omxplayer.PlayAndWait(conf, file)
}
} else {
log.Printf("Showing <%s>\n", file)
fbi.PlayAndWait(conf, file)
}
}
......
......@@ -15,7 +15,10 @@ func Convert(infile *os.File) (outfile *os.File) {
// we are making a switch, so the infile is supposed to be closed outside, but we close it in this function
// on the other side we are not closing outfile, which is then closed outside.
outfile, _ = ioutil.TempFile("", "ffmpeg")
outfile, err := ioutil.TempFile("", "ffmpeg")
if err != nil {
log.Printf("Error while creating tempfile <%s>", err.Error())
}
args := []string{infile.Name(), outfile.Name(), "test"}
......
module rgifbot
require (
github.com/h2non/filetype v1.0.5 // indirect
github.com/pkg/errors v0.8.0
gopkg.in/h2non/filetype.v1 v1.0.5 // indirect
gopkg.in/tucnak/telebot.v2 v2.0.0-20181213002246-6451db130825
)
github.com/h2non/filetype v1.0.5 h1:Esu2EFM5vrzNynnGQpj0nxhCkzVQh2HRY7AXUh/dyJM=
github.com/h2non/filetype v1.0.5/go.mod h1:isekKqOuhMj+s/7r3rIeTErIRy4Rub5uBWHfvMusLMU=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
gopkg.in/h2non/filetype.v1 v1.0.5 h1:CC1jjJjoEhNVbMhXYalmGBhOBK2V70Q1N850wt/98/Y=
gopkg.in/h2non/filetype.v1 v1.0.5/go.mod h1:M0yem4rwSX5lLVrkEuRRp2/NinFMD5vgJ4DlAhZcfNo=
gopkg.in/tucnak/telebot.v2 v2.0.0-20181213002246-6451db130825 h1:wcmZZzTudW+TVMQvA2nSdOemWGgo5LO5WDxrLu7/PZk=
gopkg.in/tucnak/telebot.v2 v2.0.0-20181213002246-6451db130825/go.mod h1:EmWSFwexO5JPTHiU7gDd9HMCCiyatACwO0HhuKNsOd0=
package fbi
import (
"log"
"os/exec"
"rgifbot/config"
)
func PlayAndWait(config config.BotConfig, file string) {
var args []string
app := "/usr/bin/fbi"
args = append(args, "-t", "5", "--once", "-d", "/dev/fb0", "--noverbose", "--autozoom",
file)
cmd := &exec.Cmd{
Path: app,
Args: args,
}
log.Printf("Executing: %s %v", app, args)
temp, err := cmd.CombinedOutput()
log.Print(err)
log.Print(string(temp))
}
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