Skip to content
Snippets Groups Projects
Commit 4878ce98 authored by Christian Pointner's avatar Christian Pointner
Browse files

added parser for file metadata

parent a807a135
No related branches found
No related tags found
No related merge requests found
......@@ -94,6 +94,12 @@ func (st *Store) UpdateFileImportState(group string, id uint64, state ImportStat
is["source__import__state"] = state
is["source__import__success"] = success
// TODO: this should probably be called more explicit?
if state == ImportDone {
// TODO: handle returned error...
st.SyncFileMetadata(group, id)
}
if err := st.db.Model(&file).Where("group_name = ?", group).Update(is).Error; err != nil {
return nil, err
}
......
//
// tank
//
// Import and Playlist Daemon for autoradio project
//
//
// Copyright (C) 2017-2018 Christian Pointner <equinox@helsinki.at>
//
// This file is part of tank.
//
// tank is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// tank is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with tank. If not, see <http://www.gnu.org/licenses/>.
//
package store
import (
"bytes"
"context"
"encoding/json"
"fmt"
"os/exec"
"time"
)
type ffprobeFormat struct {
NumStreams uint `json:"nb_streams"`
FormatName string `json:"format_name"`
DurationSec string `json:"duration"`
Size string `json:"size"`
BitRate string `json:"bit_rate"`
Tags map[string]string `json:"tags"`
}
type ffprobeOutput struct {
Format ffprobeFormat `json:"format"`
}
func (st *Store) SyncFileMetadata(group string, id uint64) (err error) {
filename := st.GetFilePath(group, id)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// cmd := exec.CommandContext(ctx, "ffprobe", "-hide_banner", "-print_format", "json", "-show_format", filename)
cmd := exec.CommandContext(ctx, "ffprobe", "-print_format", "json", "-show_format", filename)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr // TODO: handle stderr...
if err = cmd.Run(); err != nil {
return
}
var output ffprobeOutput
jd := json.NewDecoder(&stdout)
if err := jd.Decode(&output); err != nil {
return err
}
// TODO: store metadata in database
fmt.Printf("ffprobe output: %+v", output)
return
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment