add go unit test
send status messages when tvshow reindexing
This commit is contained in:
		@@ -2,7 +2,6 @@ package videoparser
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"openmediacenter/apiGo/api/types"
 | 
					 | 
				
			||||||
	"openmediacenter/apiGo/database"
 | 
						"openmediacenter/apiGo/database"
 | 
				
			||||||
	"openmediacenter/apiGo/videoparser/tmdb"
 | 
						"openmediacenter/apiGo/videoparser/tmdb"
 | 
				
			||||||
	"regexp"
 | 
						"regexp"
 | 
				
			||||||
@@ -10,17 +9,19 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func startTVShowReindex(files []Show, sett types.SettingsType) {
 | 
					func startTVShowReindex(files []Show) {
 | 
				
			||||||
	// have fun with db insertions here!
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	allTVshows := getAllTVShows()
 | 
						allTVshows := getAllTVShows()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, file := range files {
 | 
						for _, file := range files {
 | 
				
			||||||
		// insert new TVShow entry if not existing.
 | 
							// insert new TVShow entry if not existing.
 | 
				
			||||||
		insertShowIfNotExisting(file, allTVshows)
 | 
							insertShowIfNotExisting(file, allTVshows)
 | 
				
			||||||
 | 
							AppendMessage("Processing show: " + file.Name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		insertEpisodesIfNotExisting(file)
 | 
							insertEpisodesIfNotExisting(file)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						AppendMessage("reindex finished successfully!")
 | 
				
			||||||
 | 
						SendEvent("stop")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func insertEpisodesIfNotExisting(show Show) {
 | 
					func insertEpisodesIfNotExisting(show Show) {
 | 
				
			||||||
@@ -44,11 +45,9 @@ func insertEpisodesIfNotExisting(show Show) {
 | 
				
			|||||||
	diff := difference(show.files, dbepisodes)
 | 
						diff := difference(show.files, dbepisodes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, s := range diff {
 | 
						for _, s := range diff {
 | 
				
			||||||
 | 
							AppendMessage("Adding Episode: " + s)
 | 
				
			||||||
		insertEpisode(s, show.Name)
 | 
							insertEpisode(s, show.Name)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	fmt.Println("diff is...")
 | 
					 | 
				
			||||||
	fmt.Println(len(diff))
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func insertEpisode(path string, ShowName string) {
 | 
					func insertEpisode(path string, ShowName string) {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										13
									
								
								apiGo/videoparser/ReIndexTVShows_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								apiGo/videoparser/ReIndexTVShows_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					package videoparser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestDifference(t *testing.T) {
 | 
				
			||||||
 | 
						arr1 := []string{"test1", "test2", "test3"}
 | 
				
			||||||
 | 
						arr2 := []string{"test1", "test3"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						res := difference(arr1, arr2)
 | 
				
			||||||
 | 
						if len(res) != 1 || res[0] != "test2" {
 | 
				
			||||||
 | 
							t.Errorf("wrong difference result.")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -112,15 +112,13 @@ func StartTVShowReindex() {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fmt.Println(files)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		fmt.Println(err.Error())
 | 
							fmt.Println(err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// start reindex process
 | 
						// start reindex process
 | 
				
			||||||
	AppendMessage("Starting Reindexing!")
 | 
						AppendMessage("Starting Reindexing!")
 | 
				
			||||||
	go startTVShowReindex(files, mSettings)
 | 
						go startTVShowReindex(files)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func StartCleanup() {
 | 
					func StartCleanup() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user