From 6d41b861200abacb3f026b165f07cd99947317b6 Mon Sep 17 00:00:00 2001 From: lukas Date: Mon, 19 Apr 2021 20:31:56 +0200 Subject: [PATCH] new logo, partly implement tvshow reindex * add tvshow to db * add episodes to db new route switcher for tvshows --- apiGo/videoparser/ReIndexTVShows.go | 118 +++++++++++++++++++++++- apiGo/videoparser/WebSocketConnector.go | 4 - public/favicon.ico | Bin 3150 -> 0 bytes public/index.html | 4 +- public/logo192.png | Bin 5347 -> 0 bytes public/logo512.png | Bin 9664 -> 0 bytes public/logo_circle.png | Bin 0 -> 25699 bytes src/pages/TVShowPage/TVShowPage.tsx | 30 ++++-- 8 files changed, 140 insertions(+), 16 deletions(-) delete mode 100644 public/favicon.ico delete mode 100644 public/logo192.png delete mode 100644 public/logo512.png create mode 100644 public/logo_circle.png diff --git a/apiGo/videoparser/ReIndexTVShows.go b/apiGo/videoparser/ReIndexTVShows.go index dee9ec0..7f5336c 100644 --- a/apiGo/videoparser/ReIndexTVShows.go +++ b/apiGo/videoparser/ReIndexTVShows.go @@ -1,7 +1,123 @@ 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) { // 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 } diff --git a/apiGo/videoparser/WebSocketConnector.go b/apiGo/videoparser/WebSocketConnector.go index a1fe5ca..7aaac6f 100644 --- a/apiGo/videoparser/WebSocketConnector.go +++ b/apiGo/videoparser/WebSocketConnector.go @@ -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) { c, err := websocket.Accept(w, r, &websocket.AcceptOptions{ OriginPatterns: []string{"*"}, diff --git a/public/favicon.ico b/public/favicon.ico deleted file mode 100644 index bcd5dfd67cd0361b78123e95c2dd96031f27f743..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3150 zcmaKtc{Ei0AIGn;MZ^<@lHD*OV;K7~W1q3jSjJcqNywTkMOhP*k~Oj?GO|6{m(*C2 zC7JA+hN%%Bp7T4;J@?%2_x=5zbI<2~->=X60stMr0B~{wzpi9D0MG|# zyuANt7z6;uz%?PEfAnimLl^)6h5ARwGXemG2>?hqQv-I^Gpyh$JH}Ag92}3{$a#z& zd`il2Sb#$U&e&4#^4R|GTgk!Qs+x*PCL{2+`uB5mqtnqLaaw`*H2oqJ?XF(zUACc2 zSibBrdQzcidqv*TK}rpEv1ie&;Famq2IK5%4c}1Jt2b1x_{y1C!?EU)@`_F)yN*NK z)(u03@%g%uDawwXGAMm%EnP9FgoucUedioDwL~{6RVO@A-Q$+pwVRR%WYR>{K3E&Q zzqzT!EEZ$_NHGYM6&PK#CGUV$pTWsiI5#~m>htoJ!vbc0=gm3H8sz8KzIiVN5xdCT z%;}`UH2Pc8))1VS-unh?v4*H*NIy5On{MRKw7BTmOO9oE2UApwkCl9Z?^dod9M^#w z51tEZhf+#dpTo#GDDy#kuzoIjMjZ?%v*h$ z*vwUMOjGc?R0(FjLWkMD)kca4z6~H45FIzQ!Zzu&-yWyMdCBsDr2`l}Q{8fH$H@O< z$&snNzbqLk?(GIe?!PVh?F~2qk4z^rMcp$P^hw^rUPjyCyoNTRw%;hNOwrCoN?G0E z!wT^=4Loa9@O{t;Wk(Nj=?ms1Z?UN_;21m%sUm?uib=pg&x|u)8pP#l--$;B9l47n zUUnMV0sXLe*@Gv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Llupt>9dRs_SPQbv7BLYyC#qv16E-y@XZ= z-!p7I%#r-BVi$nQq3&ssRc_IC%R6$tA&^s_l46880~Wst3@>(|EO<}T4~ci~#!=e; zD)B>o%1+$ksURD1p7I-<3ehlFyVkqrySf&gg>Bp0Z9?JaG|gyTZ{Cb8SdvAWVmFX7v2ohs!OCc!Udk zUITUpmZ33rKLI#(&lDj}cKA#dpL4Fil=$5pu_wi1XJR!llw` zSItPBDEdMHk2>c7#%lBxZHHvtVUOZ$}v?=?AT~9!Jcqa@IJGuMg(s^7r>pcTrd)pS`{5Cu8WPey` z9)!!OUUY@L%9Q+bZa*S5`3f_|lFCPN6kdp_M2>{le8;cn^XUsPa+TUk47qd6)IBR% zk*&Ip?!Ge_gmmdj)BX}P_5o@VI2*wbZ^>UhFju}0gQZh!pP%4XT9{@w;G#b3XK8sN zF(7i$Jv(IM$8Akys9dhP^^~H2(7BfJp}yDW1#@!CL-!mGcSCnJ599WK9MV@yo_u$v MDeX2GIKR{Qf5okjU;qFB diff --git a/public/index.html b/public/index.html index 92fbfdd..880a2f1 100644 --- a/public/index.html +++ b/public/index.html @@ -2,14 +2,14 @@ - + - +