new logo,
partly implement tvshow reindex * add tvshow to db * add episodes to db new route switcher for tvshows
This commit is contained in:
parent
5656428de7
commit
6d41b86120
@ -1,7 +1,123 @@
|
|||||||
package videoparser
|
package videoparser
|
||||||
|
|
||||||
import "openmediacenter/apiGo/api/types"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"openmediacenter/apiGo/api/types"
|
||||||
|
"openmediacenter/apiGo/database"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
func startTVShowReindex(files []Show, sett types.SettingsType) {
|
func startTVShowReindex(files []Show, sett types.SettingsType) {
|
||||||
// have fun with db insertions here!
|
// have fun with db insertions here!
|
||||||
|
|
||||||
|
allTVshows := getAllTVShows()
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
// insert new TVShow entry if not existing.
|
||||||
|
insertShowIfNotExisting(file, allTVshows)
|
||||||
|
|
||||||
|
insertEpisodesIfNotExisting(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func insertEpisodesIfNotExisting(show Show) {
|
||||||
|
query := fmt.Sprintf("SELECT tvshow_episodes.name, season, episode FROM tvshow_episodes JOIN tvshow t on t.id = tvshow_episodes.tvshow_id WHERE t.name='%s'", show.Name)
|
||||||
|
rows := database.Query(query)
|
||||||
|
|
||||||
|
var dbepisodes []string
|
||||||
|
for rows.Next() {
|
||||||
|
var epname string
|
||||||
|
var season int
|
||||||
|
var episode int
|
||||||
|
err := rows.Scan(&epname, &season, &episode)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
dbepisodes = append(dbepisodes, fmt.Sprintf("%s S%02dE%02d.mp4", epname, season, episode))
|
||||||
|
}
|
||||||
|
|
||||||
|
// get those episodes that are missing in db
|
||||||
|
diff := difference(show.files, dbepisodes)
|
||||||
|
|
||||||
|
for _, s := range diff {
|
||||||
|
insertEpisode(s, show.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("diff is...")
|
||||||
|
fmt.Println(diff)
|
||||||
|
}
|
||||||
|
|
||||||
|
func insertEpisode(path string, ShowName string) {
|
||||||
|
seasonRegex := regexp.MustCompile("S[0-9][0-9]")
|
||||||
|
episodeRegex := regexp.MustCompile("E[0-9][0-9]")
|
||||||
|
matchENDPattern := regexp.MustCompile(" S[0-9][0-9]E[0-9][0-9].+$")
|
||||||
|
|
||||||
|
seasonStr := seasonRegex.FindString(path)[1:]
|
||||||
|
episodeStr := episodeRegex.FindString(path)[1:]
|
||||||
|
extString := matchENDPattern.FindString(path)
|
||||||
|
name := strings.TrimSuffix(path, extString)
|
||||||
|
|
||||||
|
season, err := strconv.ParseInt(seasonStr, 10, 8)
|
||||||
|
episode, err := strconv.ParseInt(episodeStr, 10, 8)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
query := fmt.Sprintf(`
|
||||||
|
INSERT INTO tvshow_episodes (name, season, poster, tvshow_id, episode)
|
||||||
|
VALUES ('%s', %d, '%s', (SELECT tvshow.id FROM tvshow WHERE tvshow.name='%s'), %d)`, name, season, "", ShowName, episode)
|
||||||
|
err = database.Edit(query)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// difference returns the elements in `a` that aren't in `b`.
|
||||||
|
func difference(a, b []string) []string {
|
||||||
|
mb := make(map[string]struct{}, len(b))
|
||||||
|
for _, x := range b {
|
||||||
|
mb[x] = struct{}{}
|
||||||
|
}
|
||||||
|
var diff []string
|
||||||
|
for _, x := range a {
|
||||||
|
if _, found := mb[x]; !found {
|
||||||
|
diff = append(diff, x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return diff
|
||||||
|
}
|
||||||
|
|
||||||
|
func insertShowIfNotExisting(show Show, allShows *[]string) {
|
||||||
|
// if show already exists return
|
||||||
|
fmt.Println(*allShows)
|
||||||
|
for _, s := range *allShows {
|
||||||
|
if s == show.Name {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo load tmdb pic
|
||||||
|
query := fmt.Sprintf("INSERT INTO tvshow (name, thumbnail) VALUES ('%s', '%s')", show.Name, "")
|
||||||
|
err := database.Edit(query)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAllTVShows() *[]string {
|
||||||
|
query := "SELECT name FROM tvshow"
|
||||||
|
rows := database.Query(query)
|
||||||
|
|
||||||
|
var res []string
|
||||||
|
for rows.Next() {
|
||||||
|
var show string
|
||||||
|
rows.Scan(&show)
|
||||||
|
|
||||||
|
res = append(res, show)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &res
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,6 @@ func newChatSender() *ChatSender {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ChatSender) TestCall() {
|
|
||||||
fmt.Println("hello world")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *ChatSender) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (t *ChatSender) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
|
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
|
||||||
OriginPatterns: []string{"*"},
|
OriginPatterns: []string{"*"},
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 3.1 KiB |
@ -2,14 +2,14 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
<link rel="icon" href="%PUBLIC_URL%/logo_circle.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<meta name="theme-color" content="#000000" />
|
<meta name="theme-color" content="#000000" />
|
||||||
<meta
|
<meta
|
||||||
name="description"
|
name="description"
|
||||||
content="A Application to run a Mediacenter in your local network"
|
content="A Application to run a Mediacenter in your local network"
|
||||||
/>
|
/>
|
||||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo_circle.png" />
|
||||||
<!--
|
<!--
|
||||||
manifest.json provides metadata used when your web app is installed on a
|
manifest.json provides metadata used when your web app is installed on a
|
||||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 9.4 KiB |
BIN
public/logo_circle.png
Normal file
BIN
public/logo_circle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
@ -3,6 +3,7 @@ import Preview from '../../elements/Preview/Preview';
|
|||||||
import {APINode, callAPI} from '../../utils/Api';
|
import {APINode, callAPI} from '../../utils/Api';
|
||||||
import {TVShow} from '../../types/ApiTypes';
|
import {TVShow} from '../../types/ApiTypes';
|
||||||
import DynamicContentContainer from '../../elements/DynamicContentContainer/DynamicContentContainer';
|
import DynamicContentContainer from '../../elements/DynamicContentContainer/DynamicContentContainer';
|
||||||
|
import {Route, Switch, useRouteMatch} from 'react-router-dom';
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
@ -26,16 +27,27 @@ class TVShowPage extends React.Component<Props, State> {
|
|||||||
|
|
||||||
render(): JSX.Element {
|
render(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<>
|
<DynamicContentContainer
|
||||||
<DynamicContentContainer
|
renderElement={(elem): JSX.Element => (
|
||||||
renderElement={(elem): JSX.Element => (
|
<Preview name={elem.Name} picLoader={(callback): void => callback('')} linkPath={'/tvshows/' + elem.Id} />
|
||||||
<Preview name={elem.Name} picLoader={(callback): void => callback('')} linkPath={'/tvshows/' + elem.Id} />
|
)}
|
||||||
)}
|
data={this.state.loading ? [] : this.data}
|
||||||
data={this.state.loading ? [] : this.data}
|
/>
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TVShowPage;
|
export default function (): JSX.Element {
|
||||||
|
let match = useRouteMatch();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Switch>
|
||||||
|
<Route path={`${match.path}/:episodeID`}>
|
||||||
|
<div>hey from episode page</div>
|
||||||
|
</Route>
|
||||||
|
<Route path={match.path}>
|
||||||
|
<TVShowPage />
|
||||||
|
</Route>
|
||||||
|
</Switch>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user