1 Commits

Author SHA1 Message Date
ef5bc2f597 extract thubnail picture size from raw bytes in backend 2021-05-12 23:29:47 +02:00
2 changed files with 23 additions and 25 deletions

View File

@ -1,9 +1,12 @@
package videoparser
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"image/jpeg"
"log"
"os/exec"
"strconv"
)
@ -76,6 +79,16 @@ func parseFFmpegPic(path string) (*string, error) {
if strEncPic == "" {
return nil, nil
}
// extract dimensions of picture
reader := bytes.NewReader(stdout)
im, err := jpeg.DecodeConfig(reader)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d %d\n", im.Width, im.Height)
// todo use this information somewhere...
backpic64 := fmt.Sprintf("data:image/jpeg;base64,%s", strEncPic)
return &backpic64, nil
@ -106,6 +119,11 @@ func getVideoAttributes(path string) *VideoAttributes {
return nil
}
// nil slice check of track array
if len(t.Media.Track) == 0 {
return nil
}
duration, err := strconv.ParseFloat(t.Media.Track[0].Duration, 32)
filesize, err := strconv.Atoi(t.Media.Track[0].FileSize)
width, err := strconv.Atoi(t.Media.Track[1].Width)

View File

@ -15,8 +15,6 @@ interface Props extends RouteComponentProps<{id: string}> {}
interface State {
loaded: boolean;
error: number;
Showname: string;
}
interface Episode {
@ -26,46 +24,28 @@ interface Episode {
Episode: number;
}
interface EpisodeData {
error: number;
episodes: Episode[];
ShowName: string;
}
export class EpisodePage extends React.Component<Props, State> {
episodes: Episode[] = [];
state = {
loaded: false,
error: 0,
Showname: ''
loaded: false
};
componentDidMount(): void {
callAPI(APINode.TVShow, {action: 'getEpisodes', ShowID: parseInt(this.props.match.params.id, 10)}, (data: EpisodeData) => {
if (data.error !== 0) {
this.setState({error: data.error, loaded: true});
} else {
this.episodes = data.episodes;
this.setState({loaded: true, Showname: data.ShowName});
}
callAPI(APINode.TVShow, {action: 'getEpisodes', ShowID: parseInt(this.props.match.params.id, 10)}, (episodes: Episode[]) => {
this.episodes = episodes;
this.setState({loaded: true});
});
}
render(): JSX.Element {
// check if content is loaded
if (!this.state.loaded) {
return <>loading...</>;
}
// check if there is an error to display
if (this.state.error !== 0) {
return <>Error code: {this.state.error}</>;
}
return (
<>
<PageTitle title={this.state.Showname} subtitle={this.episodes.length + ' Episodes'} />
<PageTitle title='TV Shows' subtitle='' />
<SideBar>
<SideBarTitle>Infos:</SideBarTitle>
<Line />