示例#1
0
文件: pruner.go 项目: sh4t/mediabase
func (self *Pruner) Start() {
	mlog.Info("starting Pruner service ...")

	go self.react()

	mlog.Info("Pruner service started")
}
示例#2
0
文件: core.go 项目: sh4t/mediabase
func (self *Core) Start() {
	mlog.Info("starting core service ...")

	events := []fsm.EventDesc{
		{Name: "import", Src: []string{"idle", "scanning"}, Dst: "scanning"},
		{Name: "found", Src: []string{"scanning"}, Dst: "scanning"},
		{Name: "scraped", Src: []string{"scanning"}, Dst: "scanning"},
		{Name: "status", Src: []string{"idle", "scanning"}, Dst: "scanning"},
		{Name: "finish", Src: []string{"scanning"}, Dst: "idle"},
	}

	// some initialization
	self.fsm = fsm.NewFSM(
		"idle",
		events,
		fsm.Callbacks{
			"import":  self.importer,
			"found":   self.found,
			"scraped": self.scraped,
			"finish":  self.finish,
		},
	)

	self.context = message.Context{Message: "Idle", Backdrop: "/mAwd34SAC8KqBKRm2MwHPLhLDU5.jpg", Completed: false}

	go self.react()

	mlog.Info("core service started")
}
示例#3
0
文件: scanner.go 项目: sh4t/mediabase
func (self *Scanner) Start() {
	mlog.Info("starting scanner service ...")

	mlog.Info("compiling regular expressions ...")

	// test:="I am leaving from home in a while"
	// prepositionsRegex := make([]*regexp.Regexp, len(preps))
	// for i := 0; i < len(preps); i++ {
	// prepositionsRegex[i]=regexp.MustCompile(`\b`+preps[i]+`\b`)
	// }

	// for i := 0; i < len(prepositionsRegex); i++ {
	// fmt.Println(prepositionsRegex[i].String())
	// if loc := prepositionsRegex[i].FindStringIndex(test); loc != nil{
	// fmt.Println(test[loc[0]:loc[1]], "found at: ", loc[0])
	// break

	self.re = make([]*helper.Rexp, 0)

	for _, regex := range self.Config.MediaRegexs {
		self.re = append(self.re, &helper.Rexp{Exp: regexp.MustCompile(regex)})
	}

	// self.re[0] = &helper.Rexp{Exp: regexp.MustCompile(`(?i)/volumes/.*?/(?P<Resolution>.*?)/(?P<Name>.*?)\s\((?P<Year>\d\d\d\d)\)/(?:.*/)*bdmv/index.(?P<FileType>bdmv)$`)}
	// self.re[1] = &helper.Rexp{Exp: regexp.MustCompile(`(?i)/volumes/.*?/(?P<Resolution>.*?)/(?P<Name>.*?)\s\((?P<Year>\d\d\d\d)\)/(?:.*/)*.*\.(?P<FileType>iso|img|nrg|mkv|avi|xvid|ts|mpg|dvr-ms|mdf|wmv)$`)}
	// self.re[2] = &helper.Rexp{Exp: regexp.MustCompile(`(?i)/volumes/.*?/(?P<Resolution>.*?)/(?P<Name>.*?)\s\((?P<Year>\d\d\d\d)\)/(?:.*/)*(?:video_ts|hv000i01)\.(?P<FileType>ifo)$`)}

	self.includedMask = ".bdmv|.iso|.img|.nrg|.mkv|.avi|.xvid|.ts|.mpg|.dvr-ms|.mdf|.wmv|.ifo"

	go self.react()

	mlog.Info("scanner service started")
}
示例#4
0
文件: cache.go 项目: sh4t/mediabase
func (self *Cache) Start() {
	mlog.Info("starting cache service ...")

	self.workpool = workpool.New(4, 2000)

	go self.react()

	mlog.Info("cache service started")
}
示例#5
0
文件: core.go 项目: sh4t/mediabase
func (self *Core) doMovieRescraped(media *message.Media) {
	go func() {
		mlog.Info("UPDATING MOVIE [%s]", media.Movie.Title)
		self.Bus.UpdateMovie <- media.Movie
	}()

	go func() {
		mlog.Info("CACHING MEDIA [%s]", media.Movie.Title)
		media.BasePath = self.Config.DataDir
		self.Bus.CacheMedia <- media
	}()
}
示例#6
0
文件: scanner.go 项目: sh4t/mediabase
func (self *Scanner) walker(folder string) error {

	if folder[len(folder)-1] != '/' {
		folder = folder + "/"
	}

	err := filepath.Walk(folder, func(path string, f os.FileInfo, err error) error {
		if err != nil {
			mlog.Info("from-start err: %s", err)
		}

		// mlog.Info("maldito: %s", path)

		if !strings.Contains(self.includedMask, strings.ToLower(filepath.Ext(path))) {
			// mlog.Info("[%s] excluding %s", filepath.Ext(path), path)
			return nil
		}

		comparePath := strings.TrimPrefix(path, folder)
		// mlog.Info("folder: %s, comparePath: %s", folder, comparePath)
		// TODO: remove folder from path to match against rexp

		for i := 0; i < 3; i++ {
			// match := self.re[i].FindStringSubmatch(strings.ToLower(path))
			// if match == nil {
			// 	continue
			// }
			var rmap = self.re[i].Match(comparePath)
			if rmap == nil {
				continue
			}

			var resolution string
			var ok bool
			if resolution, ok = rmap["Resolution"]; !ok {
				resolution = ""
			}

			movie := &message.Movie{Title: rmap["Name"], File_Title: rmap["Name"], Year: rmap["Year"], Resolution: resolution, FileType: rmap["FileType"], Location: path}
			mlog.Info("FOUND [%s] (%s)", movie.Title, movie.Location)

			self.Bus.MovieFound <- movie

			return nil
		}

		return nil
	})

	return err
}
示例#7
0
文件: core.go 项目: sh4t/mediabase
func (self *Core) doMovieScraped(media *message.Media) {
	go func() {
		mlog.Info("STORING MOVIE [%s]", media.Movie.Title)
		self.Bus.StoreMovie <- media.Movie
	}()

	go func() {
		mlog.Info("CACHING MEDIA [%s]", media.Movie.Title)
		media.BasePath = self.Config.DataDir
		self.Bus.CacheMedia <- media

		self.fsm.Event("scrape", media.Movie)
	}()
}
示例#8
0
文件: config.go 项目: sh4t/mediabase
func (self *Config) Save() {
	b, err := json.MarshalIndent(self, "", "   ")
	if err != nil {
		mlog.Info("couldn't marshal: %s", err)
		return
	}

	path := filepath.Join(self.DataDir, "config.json")
	err = ioutil.WriteFile(path, b, 0644)
	if err != nil {
		mlog.Info("WriteFileJson ERROR: %+v", err)
	}

	mlog.Info("saved as: %s", string(b))
}
示例#9
0
文件: scanner.go 项目: sh4t/mediabase
func (self *Scanner) doScanMovies(reply chan string) {
	mlog.Info("inside ScanMovies")

	reply <- "Movie scannning process started ..."

	for _, folder := range self.Config.MediaFolders {
		err := self.walker(folder)
		if err != nil {
			mlog.Info("Unable to scan movies: %s", err)
		}

		mlog.Info("Completed scan of folder: %s", folder)
	}

	self.Bus.ImportMoviesFinished <- 1
}
示例#10
0
文件: config.go 项目: sh4t/mediabase
func (self *Config) Init(version string) {
	self.Version = version

	runtime := runtime.GOOS

	switch runtime {
	case "darwin":
		self.DataDir = filepath.Join(os.Getenv("HOME"), ".mediabase/")
	case "linux":
		self.DataDir = filepath.Join(os.Getenv("HOME"), ".mediabase/")
	case "windows":
		self.DataDir = filepath.Join(os.Getenv("APPDATA"), "mediabase\\")
	}

	path := filepath.Join(self.DataDir, "log")
	if _, err := os.Stat(path); os.IsNotExist(err) {
		if err = os.Mkdir(path, 0755); err != nil {
			log.Printf("FATAL: Unable to create folder %s: %s", path, err)
			os.Exit(255)
		}
	}

	// os.Setenv("GIN_MODE", "release")
	mlog.Start(mlog.LevelInfo, filepath.Join(self.DataDir, "log", "mediabase.log"))
	mlog.Info("mediabase v%s starting up on %s ...", self.Version, runtime)

	self.setupOperatingEnv()

	self.LoadConfig()
	self.LoadRegex()
}
示例#11
0
文件: server.go 项目: sh4t/mediabase
func (self *Server) Start() {
	mlog.Info("starting server service")

	self.r = gin.New()

	self.r.Use(gin.Recovery())
	// self.r.Use(helper.Logging())

	path := filepath.Join(".", "web")

	var abs string
	var err error
	if abs, err = filepath.Abs(path); err != nil {
		mlog.Info("unable to get absolute path: %s, ", err)
		return
	}

	mlog.Info("server root path is: %s", abs)

	// self.r.Use(static.Serve("./web/"))
	self.r.Use(static.Serve(path))
	self.r.NoRoute(self.redirect)

	api := self.r.Group(apiVersion)
	{
		api.GET("/movies/cover", self.getCover)
		api.POST("/movies", self.getMovies)
		api.POST("/movies/search", self.searchMovies)

		api.GET("/movies/duplicates", self.getDuplicates)

		api.PUT("/movies/watched", self.watchedMovie)
		api.POST("/movies/fix", self.fixMovie)
		api.POST("/movies/prune", self.pruneMovies)

		api.GET("/import", self.importMovies)
		api.GET("/import/status", self.importMoviesStatus)

		api.GET("/config", self.getConfig)
		api.PUT("/config", self.saveConfig)
	}

	mlog.Info("service started listening on %s:%s", self.Config.Host, self.Config.Port)

	go self.r.Run(fmt.Sprintf("%s:%s", self.Config.Host, self.Config.Port))
}
示例#12
0
文件: scraper.go 项目: sh4t/mediabase
func (self *Scraper) Start() {
	mlog.Info("starting scraper service ...")

	var err error
	self.tmdb, err = tmdb.NewClient("e610ded10c3f47d05fe797961d90fea6", false)
	if err != nil {
		mlog.Fatalf("unable to create tmdb client: %s", err)
	}

	self.workpool = workpool.New(12, 4000)

	go self.react()

	// go self.workpool.Balance()

	mlog.Info("scraper service started")
}
示例#13
0
文件: server.go 项目: sh4t/mediabase
func (self *Server) searchMovies(c *gin.Context) {
	mlog.Info("searchMovies: are you a head honcho ?")

	var options message.Options

	c.Bind(&options)

	mlog.Info("anyway the wind blows: %+v", options)

	msg := message.Movies{Options: options, Reply: make(chan *message.MoviesDTO)}
	self.Bus.SearchMovies <- &msg
	reply := <-msg.Reply

	// mlog.Info("%s", reply)

	c.JSON(200, &reply)
}
示例#14
0
文件: dal.go 项目: sh4t/mediabase
func (self *Dal) doGetMovies(msg *message.Movies) {
	tx, err := self.db.Begin()
	if err != nil {
		mlog.Fatalf("unable to begin transaction: %s", err)
	}

	options := msg.Options
	mlog.Info("what is: %+v", options)

	stmt, err := tx.Prepare(fmt.Sprintf("select rowid, title, original_title, file_title, year, runtime, tmdb_id, imdb_id, overview, tagline, resolution, filetype, location, cover, backdrop, genres, vote_average, vote_count, countries, added, modified, last_watched, all_watched, count_watched, score, director, writer, actors, awards, imdb_rating, imdb_votes from movie order by %s %s limit ? offset ?", options.SortBy, options.SortOrder))
	if err != nil {
		mlog.Fatalf("unable to prepare transaction: %s", err)
	}
	defer stmt.Close()

	rows, err := stmt.Query(options.Limit, options.Current)
	if err != nil {
		mlog.Fatalf("unable to prepare transaction: %s", self.err)
	}

	items := make([]*message.Movie, 0)

	if self.count == 0 {
		err = self.countRows.QueryRow().Scan(&self.count)
		if err != nil {
			mlog.Fatalf("unable to count rows: %s", err)
		}
	}

	var count = 0
	for rows.Next() {
		movie := message.Movie{}
		rows.Scan(&movie.Id, &movie.Title, &movie.Original_Title, &movie.File_Title, &movie.Year, &movie.Runtime, &movie.Tmdb_Id, &movie.Imdb_Id, &movie.Overview, &movie.Tagline, &movie.Resolution, &movie.FileType, &movie.Location, &movie.Cover, &movie.Backdrop, &movie.Genres, &movie.Vote_Average, &movie.Vote_Count, &movie.Production_Countries, &movie.Added, &movie.Modified, &movie.Last_Watched, &movie.All_Watched, &movie.Count_Watched, &movie.Score, &movie.Director, &movie.Writer, &movie.Actors, &movie.Awards, &movie.Imdb_Rating, &movie.Imdb_Votes)
		items = append(items, &movie)
		count++
	}
	rows.Close()

	tx.Commit()

	mlog.Info("Listed %d movies", count)
	mlog.Info("Representing %d movies", self.count)

	msg.Reply <- &message.MoviesDTO{Count: self.count, Movies: items}
}
示例#15
0
文件: server.go 项目: sh4t/mediabase
func (self *Server) importMovies(c *gin.Context) {
	mlog.Info("importMovies: you know .. i got here")

	msg := message.Status{Reply: make(chan *message.Context)}
	self.Bus.ImportMovies <- &msg
	reply := <-msg.Reply

	c.JSON(200, &reply)
}
示例#16
0
文件: dal.go 项目: sh4t/mediabase
func (self *Dal) Start() {
	mlog.Info("starting dal service ...")

	self.dbase = filepath.Join(".", "db", "mediabase.db")
	self.db, self.err = sql.Open("sqlite3", self.dbase)
	if self.err != nil {
		mlog.Fatalf("open database: %s (%s)", self.err, self.dbase)
	}

	stmtExist := self.prepare(`select name from sqlite_master where type='table' and name='movie'`)
	defer stmtExist.Close()

	var name string
	err := stmtExist.QueryRow().Scan(&name)
	if err != nil {
		mlog.Fatalf("unable to check for existence of movie database: %s (%s)", self.err, self.dbase)
	}

	if name != "movie" {
		mlog.Info("Initializing database schema ...")
		self.initSchema()
	}

	self.count = 0
	self.searchCount = 0
	self.searchArgs = ""

	self.countRows = self.prepare("select count(*) from movie;")
	self.listMovies = self.prepare("select rowid, title, original_title, file_title, year, runtime, tmdb_id, imdb_id, overview, tagline, resolution, filetype, location, cover, backdrop, genres, vote_average, vote_count, countries, added, modified, last_watched, all_watched, count_watched, score, director, writer, actors, awards, imdb_rating, imdb_votes from movie order by ? desc limit ? offset ?")
	self.listByRuntime = self.prepare("select rowid, title, original_title, file_title, year, runtime, tmdb_id, imdb_id, overview, tagline, resolution, filetype, location, cover, backdrop, genres, vote_average, vote_count, countries, added, modified, last_watched, all_watched, count_watched, score, director, writer, actors, awards, imdb_rating, imdb_votes from movie order by runtime")
	self.listMoviesToFix = self.prepare("select rowid, title, original_title, file_title, year, runtime, tmdb_id, imdb_id, overview, tagline, resolution, filetype, location, cover, backdrop, genres, vote_average, vote_count, countries, added, modified, last_watched, all_watched, count_watched, score, director, writer, actors, awards, imdb_rating, imdb_votes from movie where original_title = 'FIXMOV23'")

	var abs string
	if abs, err = filepath.Abs(self.dbase); err != nil {
		mlog.Info("unable to get absolute path: %s, ", err)
		return
	}

	mlog.Info("connected to database (%s)", abs)

	// self.initSchema()

	go self.react()
}
示例#17
0
文件: dal.go 项目: sh4t/mediabase
func (self *Dal) Stop() {
	self.listMoviesToFix.Close()
	self.listByRuntime.Close()
	self.listMovies.Close()
	// self.searchMovies.Close()
	// self.storeMovie.Close()
	self.db.Close()

	mlog.Info("dal service stopped")
}
示例#18
0
文件: cache.go 项目: sh4t/mediabase
func (self *Cache) requestWork(media *message.Media) {
	mlog.Info("CACHE MEDIA REQUESTED [%s]", media.Movie.Title)

	gig := &CacheGig{
		media,
		self.Config.DataDir,
	}

	self.workpool.PostWork("cachegig", gig)
}
示例#19
0
文件: dal.go 项目: sh4t/mediabase
func (self *Dal) doWatchedMovie(msg *message.SingleMovie) {
	mlog.Info("STARTED UPDATING WATCHED MOVIE %s (%s)", msg.Movie.Title, msg.Movie.Last_Watched)

	tx, err := self.db.Begin()
	if err != nil {
		mlog.Fatalf("at begin: %s", err)
	}

	stmt, err := tx.Prepare("update movie set last_watched = ?, all_watched = ?, count_watched = ?, score = ?, modified = ? where rowid = ?")
	if err != nil {
		tx.Rollback()
		mlog.Fatalf("at prepare: %s", err)
	}
	defer stmt.Close()

	now := time.Now().UTC().Format(time.RFC3339)

	var all_watched string
	count_watched := msg.Movie.Count_Watched
	if !strings.Contains(msg.Movie.All_Watched, msg.Movie.Last_Watched) {
		count_watched++
		if msg.Movie.All_Watched == "" {
			all_watched = msg.Movie.Last_Watched
		} else {
			all_watched += "|" + msg.Movie.Last_Watched
		}
	}

	_, err = stmt.Exec(msg.Movie.Last_Watched, all_watched, count_watched, msg.Movie.Score, now, msg.Movie.Id)
	if err != nil {
		tx.Rollback()
		mlog.Fatalf("at exec: %s", err)
	}

	tx.Commit()
	mlog.Info("FINISHED UPDATING WATCHED MOVIE %s", msg.Movie.Title)

	msg.Movie.All_Watched = all_watched
	msg.Movie.Count_Watched = count_watched
	msg.Movie.Modified = now

	msg.Reply <- msg.Movie
}
示例#20
0
文件: dal.go 项目: sh4t/mediabase
func (self *Dal) doStoreMovie(movie *message.Movie) {
	self.count = 0

	mlog.Info("STARTED SAVING %s [%d]", movie.Title)

	tx, err := self.db.Begin()
	if err != nil {
		mlog.Fatalf("at begin: %s", err)
	}

	// stmt, err := tx.Prepare("insert into movie(title, original_title, file_title, year, runtime, tmdb_id, imdb_id, overview, tagline, resolution, filetype, location, cover, backdrop, genres, director, vote_average, vote_count, countries, added, modified, last_watched, all_watched, count_watched) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")

	stmt, err := tx.Prepare("insert into movie(title, original_title, file_title, year, runtime, tmdb_id, imdb_id, overview, tagline, resolution, filetype, location, cover, backdrop, genres, vote_average, vote_count, countries, added, modified, last_watched, all_watched, count_watched, score, director, writer, actors, awards, imdb_rating, imdb_votes) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
	if err != nil {
		tx.Rollback()
		mlog.Fatalf("at prepare: %s", err)
	}
	defer stmt.Close()

	_, err = stmt.Exec(movie.Title, movie.Original_Title, movie.File_Title, movie.Year, movie.Runtime, movie.Tmdb_Id, movie.Imdb_Id, movie.Overview, movie.Tagline, movie.Resolution, movie.FileType, movie.Location, movie.Cover, movie.Backdrop,
		movie.Genres, movie.Vote_Average, movie.Vote_Count, movie.Production_Countries, movie.Added, movie.Modified, movie.Last_Watched, movie.All_Watched, movie.Count_Watched, movie.Score, movie.Director, movie.Writer, movie.Actors, movie.Awards,
		movie.Imdb_Rating, movie.Imdb_Votes)
	if err != nil {
		tx.Rollback()
		mlog.Fatalf("at exec: %s", err)
	}

	// mlog.Info("Movie is %v", movie)

	// _, self.err = self.storeMovie.Exec(movie.Title, movie.Year, movie.Resolution, movie.FileType, movie.Location)
	// if self.err != nil {
	// 	mlog.Fatalf("at storemovie: %s", self.err)
	// }

	tx.Commit()
	mlog.Info("FINISHED SAVING %s", movie.Title)

	// _, self.err = self.storeMovie.Exec(movie.Name, movie.Year, movie.Resolution, movie.Type, movie.Path, movie.Picture)
	// if self.err != nil {
	// 	mlog.Fatalf(self.err)
	// }
}
示例#21
0
文件: pruner.go 项目: sh4t/mediabase
func (self *Pruner) doPruneMovies(reply chan string) {
	mlog.Info("Looking for something to prune")

	options := message.Options{Current: 0, Limit: 99999999999999, SortBy: "title", SortOrder: "asc"}
	msg := message.Movies{Options: options, Reply: make(chan *message.MoviesDTO)}
	self.Bus.GetMovies <- &msg
	dto := <-msg.Reply

	for _, item := range dto.Movies {
		if _, err := os.Stat(item.Location); err != nil {
			if os.IsNotExist(err) {
				mlog.Info("UP FOR DELETION: [%d] %s (%s))", item.Id, item.Title, item.Location)
				self.Bus.DeleteMovie <- item
			}
		}

	}

	reply <- "Tudo Bom"
}
示例#22
0
文件: server.go 项目: sh4t/mediabase
func (self *Server) pruneMovies(c *gin.Context) {
	mlog.Info("pruning .. i got here")

	msg := message.PruneMovies{Reply: make(chan string)}
	self.Bus.PruneMovies <- &msg
	reply := <-msg.Reply

	data := struct {
		Description string
	}{Description: reply}
	c.JSON(200, &data)
}
示例#23
0
文件: dal.go 项目: sh4t/mediabase
func (self *Dal) doDeleteMovie(movie *message.Movie) {
	self.count = 0

	mlog.Info("STARTED DELETING [%d] %s", movie.Id, movie.Title)

	tx, err := self.db.Begin()
	if err != nil {
		mlog.Fatalf("at begin: %s", err)
	}

	// stmt, err := tx.Prepare("insert into movie(title, original_title, file_title, year, runtime, tmdb_id, imdb_id, overview, tagline, resolution, filetype, location, cover, backdrop, genres, director, vote_average, vote_count, countries, added, modified, last_watched, all_watched, count_watched) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")

	stmt, err := tx.Prepare("delete from movie where rowid = ?")
	if err != nil {
		tx.Rollback()
		mlog.Fatalf("at prepare: %s", err)
	}
	defer stmt.Close()

	_, err = stmt.Exec(movie.Id)
	if err != nil {
		tx.Rollback()
		mlog.Fatalf("at exec: %s", err)
	}

	// mlog.Info("Movie is %v", movie)

	// _, self.err = self.storeMovie.Exec(movie.Title, movie.Year, movie.Resolution, movie.FileType, movie.Location)
	// if self.err != nil {
	// 	mlog.Fatalf("at storemovie: %s", self.err)
	// }

	tx.Commit()
	mlog.Info("FINISHED DELETING [%d] %s", movie.Id, movie.Title)

	// _, self.err = self.storeMovie.Exec(movie.Name, movie.Year, movie.Resolution, movie.Type, movie.Path, movie.Picture)
	// if self.err != nil {
	// 	mlog.Fatalf(self.err)
	// }
}
示例#24
0
文件: bus.go 项目: sh4t/mediabase
func (self *Bus) Start() {
	mlog.Info("bus starting up ...")

	self.GetConfig = make(chan *message.GetConfig)
	self.SaveConfig = make(chan *message.SaveConfig)
	self.ConfigChanged = make(chan *message.ConfigChanged)

	self.ImportMovies = make(chan *message.Status)
	self.ImportMoviesStatus = make(chan *message.Status)
	self.ScanMovies = make(chan *message.ScanMovies)
	self.ScrapeMovie = make(chan *message.Movie)

	self.MovieFound = make(chan *message.Movie)
	self.MovieScraped = make(chan *message.Media)
	self.MovieRescraped = make(chan *message.Media)

	self.ImportMoviesFinished = make(chan int)

	self.PruneMovies = make(chan *message.PruneMovies)

	self.GetCover = make(chan *message.Movies)
	self.GetMovies = make(chan *message.Movies)
	self.ShowDuplicates = make(chan *message.Movies)
	self.ListByRuntime = make(chan *message.Movies)
	self.SearchMovies = make(chan *message.Movies)
	self.CheckMovie = make(chan *message.CheckMovie)
	self.FixMovies = make(chan int)
	// self.GetMoviesToFix = make(chan *message.Movies)
	self.RescrapeMovies = make(chan *message.MoviesDTO)

	self.WatchedMovie = make(chan *message.SingleMovie)
	self.FixMovie = make(chan *message.SingleMovie)

	self.StoreMovie = make(chan *message.Movie)
	self.DeleteMovie = make(chan *message.Movie)
	self.CacheMedia = make(chan *message.Media)
	self.UpdateMovie = make(chan *message.Movie)

	mlog.Info("bus started ...")
}
示例#25
0
文件: scraper.go 项目: sh4t/mediabase
func (self *Scraper) requestWork(movie *message.Movie) {
	mlog.Info("WORK REQUESTED [%s]", movie.Title)

	c := make(chan *message.Media)

	gig := &Gig{
		self.Bus,
		self.tmdb,
		&message.Media{BaseUrl: "", SecureBaseUrl: "", BasePath: "", Movie: movie, Forced: false},
		c,
	}

	self.workpool.PostWork("gig", gig)

	// mlog.Info("[%s] RUNNING SCRAPING [%s]", movie.Title)
	media := <-c

	// mlog.Info("[%s] FINISHED SCRAPING", media.Movie.Title)
	self.Bus.MovieScraped <- media

	mlog.Info("WORK COMPLETED [%s]", movie.Title)
}
示例#26
0
文件: dal.go 项目: sh4t/mediabase
func (self *Dal) doShowDuplicates(msg *message.Movies) {
	mlog.Info("started from the bottom now we're here")

	tx, err := self.db.Begin()
	if err != nil {
		mlog.Fatalf("unable to begin transaction: %s", err)
	}

	// rows, err := self.listMovies.Query()
	// if err != nil {
	// 	mlog.Fatalf("unable to prepare transaction: %s", err)
	// }

	// rows, err := self.db.Query("select rowid, title, original_title, file_title, year, runtime, tmdb_id, imdb_id, overview, tagline, resolution, filetype, location, cover, backdrop, genres, vote_average, vote_count, countries, added, modified, last_watched, all_watched, count_watched from movie where title in (select title from movie group by title having count(*) > 1);")
	rows, err := self.db.Query("select a.rowid, a.title, a.original_title, a.file_title, a.year, a.runtime, a.tmdb_id, a.imdb_id, a.overview, a.tagline, a.resolution, a.filetype, a.location, a.cover, a.backdrop, a.genres, a.vote_average, a.vote_count, a.countries, a.added, a.modified, a.last_watched, a.all_watched, a.count_watched, a.score, a.director, a.writer, a.actors, a.awards, a.imdb_rating, a.imdb_votes from movie a join (select title, year from movie group by title, year having count(*) > 1) b on a.title = b.title and a.year = b.year;")
	if err != nil {
		mlog.Fatalf("unable to prepare transaction: %s", self.err)
	}

	items := make([]*message.Movie, 0)

	var count uint64 = 0

	for rows.Next() {
		movie := message.Movie{}
		rows.Scan(&movie.Id, &movie.Title, &movie.Original_Title, &movie.File_Title, &movie.Year, &movie.Runtime, &movie.Tmdb_Id, &movie.Imdb_Id, &movie.Overview, &movie.Tagline, &movie.Resolution, &movie.FileType, &movie.Location, &movie.Cover, &movie.Backdrop, &movie.Genres, &movie.Vote_Average, &movie.Vote_Count, &movie.Production_Countries, &movie.Added, &movie.Modified, &movie.Last_Watched, &movie.All_Watched, &movie.Count_Watched, &movie.Score, &movie.Director, &movie.Writer, &movie.Actors, &movie.Awards, &movie.Imdb_Rating, &movie.Imdb_Votes)
		items = append(items, &movie)
		count++
	}
	rows.Close()

	tx.Commit()

	mlog.Info("Found %d duplicate movies", count)

	msg.Reply <- &message.MoviesDTO{Count: count, Movies: items}
}
示例#27
0
文件: scraper.go 项目: sh4t/mediabase
func (self *Scraper) fixMoviesWork(dto *message.MoviesDTO) {
	mlog.Info("FIX MOVIES WORK REQUESTED FOR [%d] movies", dto.Count)

	c := make(chan *message.Media)

	for i := range dto.Movies {
		gig := &FixMovieGig{
			self.Bus,
			self.tmdb,
			&message.Media{BaseUrl: "", SecureBaseUrl: "", BasePath: "", Movie: dto.Movies[i], Forced: true},
			c,
		}

		self.workpool.PostWork("fixMovieGig", gig)

		// mlog.Info("[%s] RUNNING SCRAPING [%s]", movie.Title)
		media := <-c

		// mlog.Info("[%s] FINISHED SCRAPING", media.Movie.Title)
		self.Bus.MovieRescraped <- media
	}

	mlog.Info("FIX MOVIES WORK COMPLETED FOR [%d]", dto.Count)
}
示例#28
0
文件: dal.go 项目: sh4t/mediabase
func (self *Dal) doUpdateMovie(movie *message.Movie) {
	mlog.Info("STARTED UPDATING %s", movie.Title)

	tx, err := self.db.Begin()
	if err != nil {
		mlog.Fatalf("at begin: %s", err)
	}

	stmt, err := tx.Prepare("update movie set title = ?, original_title = ?, year = ?, runtime = ?, tmdb_id = ?, imdb_id = ?, overview = ?, tagline = ?, cover = ?, backdrop = ?, genres = ?, vote_average = ?, vote_count = ?, countries = ?, modified = ?, director = ?, writer = ?, actors = ?, awards = ?, imdb_rating = ?, imdb_votes = ? where rowid = ?")
	if err != nil {
		tx.Rollback()
		mlog.Fatalf("at prepare: %s", err)
	}
	defer stmt.Close()

	_, err = stmt.Exec(movie.Title, movie.Original_Title, movie.Year, movie.Runtime, movie.Tmdb_Id, movie.Imdb_Id, movie.Overview, movie.Tagline, movie.Cover, movie.Backdrop, movie.Genres, movie.Vote_Average, movie.Vote_Count, movie.Production_Countries, movie.Modified, movie.Director, movie.Writer, movie.Actors, movie.Awards, movie.Imdb_Rating, movie.Imdb_Votes, movie.Id)
	if err != nil {
		tx.Rollback()
		mlog.Fatalf("at exec: %s", err)
	}

	tx.Commit()
	mlog.Info("FINISHED UPDATING %s", movie.Title)
}
示例#29
0
文件: server.go 项目: sh4t/mediabase
func (self *Server) getMovies(c *gin.Context) {
	var options message.Options

	c.Bind(&options)

	mlog.Info("bocelli: %+v", options)

	msg := message.Movies{Options: options, Reply: make(chan *message.MoviesDTO)}
	self.Bus.GetMovies <- &msg
	reply := <-msg.Reply

	// mlog.Info("response is: %s", reply)

	c.JSON(200, &reply)
}
示例#30
0
文件: server.go 项目: sh4t/mediabase
func (self *Server) fixMovie(c *gin.Context) {
	var movie message.Movie

	c.Bind(&movie)
	mlog.Info("%+v", movie)

	msg := message.SingleMovie{Movie: &movie, Reply: make(chan *message.Movie)}
	self.Bus.FixMovie <- &msg

	data := struct {
		Status bool `json:"status"`
	}{Status: true}

	c.JSON(200, &data)
}