Пример #1
0
func (d *Dal) deleteMovie(msg *pubsub.Message) {
	movie := msg.Payload.(*model.Movie)

	// d.count = 0

	lib.Notify(d.bus, "prune:delete", fmt.Sprintf("STARTED DELETING [%d] %s", movie.Id, movie.Title))

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

	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)
	}

	tx.Commit()

	lib.Notify(d.bus, "prune:delete", fmt.Sprintf("FINISHED DELETING [%d] %s", movie.Id, movie.Title))
}
Пример #2
0
func (c *Core) importMovies(msg *pubsub.Message) {
	t0 := time.Now()
	// mlog.Info("Begin movie scanning ...")
	lib.Notify(c.bus, "import:begin", "Import process started")

	c.wg.Add(1)

	c.bus.Pub(nil, "/command/movie/scan")
	//	msg.Reply <- &c.settings.Config
	// mlog.Info("Import finished")

	go func() {
		c.wg.Wait()
		// �t := float64(time.Since(t0)) / 1e9
		lib.Notify(c.bus, "import:end", fmt.Sprintf("Import process finished (%s elapsed)", time.Since(t0).String()))
	}()

}
Пример #3
0
func (s *Scrape) Execute(wid int) {
	movie := s.dto.Movie.(*model.Movie)

	lib.Notify(s.bus, "import:progress", fmt.Sprintf("SCRAPE REQUESTED (%d) [%s]", wid, movie.Title))

	now := time.Now().UTC().Format(time.RFC3339)
	movie.Added = now
	movie.Modified = now

	movie.Score = 0

	lib.Notify(s.bus, "import:progress", fmt.Sprintf("STARTED TMDB (%d) [%s]", wid, movie.Title))
	movies, err := s.tmdb.SearchMovie(movie.Title)
	if err != nil {
		s.bus.Pub(nil, "/event/workunit/done")

		mlog.Error(err)
		return
	}

	if movies.Total_Results == 0 {
		lib.Notify(s.bus, "import:progress", fmt.Sprintf("TMDB: NO MATCH FOUND (%d) [%s]", wid, movie.Title))

		msg := &pubsub.Message{Payload: s.dto}
		s.bus.Pub(msg, "/event/movie/tmdbnotfound")

		return
	} else if movies.Total_Results > 1 {
		lib.Notify(s.bus, "import:progress", fmt.Sprintf("TMDB: MORE THAN ONE (%d) [%s]", wid, movie.Title))
	}

	id := movies.Results[0].Id

	_scrape(wid, s.tmdb, id, movie)

	s.dto.BaseUrl = s.tmdb.BaseUrl
	s.dto.SecureBaseUrl = s.tmdb.SecureBaseUrl

	lib.Notify(s.bus, "import:progress", fmt.Sprintf("SCRAPE COMPLETED (%d) [%s]", wid, movie.Title))

	msg := &pubsub.Message{Payload: s.dto}
	s.bus.Pub(msg, "/event/movie/scraped")
}
Пример #4
0
func (c *Caching) Execute(wid int) {
	defer c.bus.Pub(nil, "/event/workunit/done")

	coverPath := filepath.Join(c.path, "img", "p", c.cover)
	if _, err := os.Stat(coverPath); err == nil && !c.forced {
		lib.Notify(c.bus, "import:progress", fmt.Sprintf("COVER DOWNLOAD SKIPPED (%d) [%d] %s (%s)", wid, c.id, c.title, c.cover))
	} else {
		if err := lib.Download(c.url+"original"+c.cover, coverPath); err == nil {
			lib.Notify(c.bus, "import:progress", fmt.Sprintf("COVER DOWNLOADED (%d) [%d] %s (%s)", wid, c.id, c.title, c.cover))
		} else {
			lib.Notify(c.bus, "import:progress", fmt.Sprintf("UNABLE TO DOWNLOAD COVER (%d) [%d] %s (%s)", wid, c.id, c.title, c.cover))
		}
	}

	thumbPath := filepath.Join(c.path, "img", "t", c.cover)
	if _, err := os.Stat(thumbPath); err == nil && !c.forced {
		lib.Notify(c.bus, "import:progress", fmt.Sprintf("THUMB GENERATION SKIPPED (%d) [%d] %s (%s)", wid, c.id, c.title, c.cover))
	} else {
		if err := lib.ResizeImage(coverPath, thumbPath); err == nil {
			lib.Notify(c.bus, "import:progress", fmt.Sprintf("THUMB CREATED (%d) [%d] %s (%s)", wid, c.id, c.title, c.cover))
		} else {
			lib.Notify(c.bus, "import:progress", fmt.Sprintf("UNABLE TO CREATE THUMB (%d) [%d] %s (%s)", wid, c.id, c.title, c.cover))
		}
	}

	backdropPath := filepath.Join(c.path, "img", "b", c.backdrop)
	if _, err := os.Stat(backdropPath); err == nil && !c.forced {
		lib.Notify(c.bus, "import:progress", fmt.Sprintf("BACKDROP DOWNLOAD SKIPPED (%d) [%d] %s (%s)", wid, c.id, c.title, c.cover))
	} else {
		if err := lib.Download(c.url+"original"+c.backdrop, backdropPath); err == nil {
			lib.Notify(c.bus, "import:progress", fmt.Sprintf("BACKDROP DOWNLOADED (%d) [%d] %s (%s)", wid, c.id, c.title, c.cover))
		} else {
			lib.Notify(c.bus, "import:progress", fmt.Sprintf("UNABLE TO DOWNLOAD BACKDROP (%d) [%d] %s (%s)", wid, c.id, c.title, c.cover))
		}
	}

	// event := "/event/movie/cached"
	// if c.forced {
	// 	event += "/forced"
	// }

	// cached := &pubsub.Message{}
	// c.bus.Pub(cached, event)
}
Пример #5
0
func (c *Core) doMovieFound(msg *pubsub.Message) {
	movie := msg.Payload.(*model.Movie)

	check := &pubsub.Message{Payload: movie, Reply: make(chan interface{}, 3)}
	c.bus.Pub(check, "/command/movie/exists")

	reply := <-check.Reply
	exists := reply.(bool)

	if exists {
		mlog.Info("SKIPPED: exists [%s] (%s)", movie.Title, movie.Location)
	} else {
		lib.Notify(c.bus, "import:progress", fmt.Sprintf("NEW: [%s] (%s)", movie.Title, movie.Location))

		c.wg.Add(1)
		c.bus.Pub(msg, "/command/movie/scrape")
	}
}
Пример #6
0
func (s *Scanner) scanMovies(msg *pubsub.Message) {
	defer s.bus.Pub(nil, "/event/workunit/done")

	// folders := []string{
	// 	"/Volumes/hal-films",
	// 	"/Volumes/wopr-films",
	// }

	// ping := "ping -c1 %s > /dev/null && echo \"YES\" || echo \"NO\""
	// lib.Notify(s.bus, "import:begin", "Import process started")

	if s.settings.UnraidMode {
		// folders := []string{
		// 	`/mnt/user/films`,
		// }
		// filenames := []string{
		// 	"wopr:/mnt/user/films/bluray/ There Be Dragons (2011)/BDMV/BACKUP/MovieObject.bdmv",
		// 	"wopr:/mnt/user/films/bluray/ There Be Dragons (2011)/BDMV/BACKUP/index.bdmv",
		// 	"wopr:/mnt/user/films/bluray/ There Be Dragons (2011)/BDMV/MovieObject.bdmv",
		// 	"wopr:/mnt/user/films/bluray/ There Be Dragons (2011)/BDMV/index.bdmv",
		// 	"wopr:/mnt/user/films/bluray/ There Be Dragons (2011)/CERTIFICATE/BACKUP/id.bdmv",
		// 	"wopr:/mnt/user/films/bluray/ There Be Dragons (2011)/CERTIFICATE/id.bdmv",
		// 	"wopr:/mnt/user/films/bluray/'71 (2014)/BDMV/BACKUP/MovieObject.bdmv",
		// 	"wopr:/mnt/user/films/bluray/'71 (2014)/BDMV/BACKUP/index.bdmv",
		// 	"wopr:/mnt/user/films/bluray/'71 (2014)/BDMV/MovieObject.bdmv",
		// 	"wopr:/mnt/user/films/bluray/'71 (2014)/BDMV/index.bdmv",
		// 	"wopr:/mnt/user/films/bluray/10 Things I Hate About You (1999)/BDMV/BACKUP/MovieObject.bdmv",
		// 	"wopr:/mnt/user/films/bluray/10 Things I Hate About You (1999)/BDMV/BACKUP/index.bdmv",
		// 	"wopr:/mnt/user/films/bluray/10 Things I Hate About You (1999)/BDMV/MovieObject.bdmv",
		// 	"wopr:/mnt/user/films/bluray/10 Things I Hate About You (1999)/BDMV/index.bdmv",
		// 	"wopr:/mnt/user/films/bluray/12 Years A Slave (2013)/BDMV/BACKUP/MovieObject.bdmv",
		// 	"wopr:/mnt/user/films/bluray/12 Years A Slave (2013)/BDMV/BACKUP/index.bdmv",
		// 	"wopr:/mnt/user/films/bluray/12 Years A Slave (2013)/BDMV/MovieObject.bdmv",
		// 	"wopr:/mnt/user/films/bluray/12 Years A Slave (2013)/BDMV/index.bdmv",
		// 	"wopr:/mnt/user/films/bluray/12 Years A Slave (2013)/CERTIFICATE/BACKUP/id.bdmv",
		// 	"wopr:/mnt/user/films/bluray/12 Years A Slave (2013)/CERTIFICATE/id.bdmv",
		// 	"wopr:/mnt/user/films/bluray/13 (2010)/BDMV/BACKUP/MovieObject.bdmv",
		// 	"wopr:/mnt/user/films/bluray/13 (2010)/BDMV/BACKUP/index.bdmv",
		// 	"wopr:/mnt/user/films/bluray/13 (2010)/BDMV/MovieObject.bdmv",
		// 	"wopr:/mnt/user/films/bluray/13 (2010)/BDMV/index.bdmv",
		// 	"wopr:/mnt/user/films/bluray/13 (2010)/CERTIFICATE/BACKUP/id.bdmv",
		// 	"wopr:/mnt/user/films/bluray/13 (2010)/CERTIFICATE/id.bdmv",
		// 	"wopr:/mnt/user/films/blurip/10 Things I Hate About You (1999)/movie.mkv",
		// }

		// mlog.Info("started analysis")
		// s.analyze(filenames)
		// mlog.Info("finished analysis")

		for _, host := range s.settings.UnraidHosts {
			// Create new request to service go.micro.srv.example, method Example.Call
			req := client.NewRequest("io.jbrodriguez.mediagui.agent."+host, "Agent.Scan", &agent.ScanReq{
				// Folders: s.settings.MediaFolders,
				Folders: s.settings.MediaFolders,
				Mask:    s.includedMask,
			})

			rsp := &agent.ScanRsp{}

			// Call service
			if err := client.Call(context.Background(), req, rsp); err != nil {
				mlog.Warning("Unable to connect to service (%s): %s", "io.jbrodriguez.mediagui.agent."+host, err)
				lib.Notify(s.bus, "import:progress", "Unable to connect to host "+host)
				// lib.Notify(s.bus, "import:end", "Import process finished")
				// return
				continue
			}

			s.analyze(rsp.Filenames)
		}
	} else {
		for _, folder := range s.settings.MediaFolders {
			err := s.walk(folder)
			if err != nil {
				mlog.Warning("Unable to scan folder (%s): %s", folder, err)
			}
		}
	}

	// lib.Notify(s.bus, "import:end", "Import process finished")
}
Пример #7
0
func (c *Core) pruneMovies(msg *pubsub.Message) {
	t0 := time.Now()

	lib.Notify(c.bus, "prune:begin", "Started Prune Process")

	options := &lib.Options{Offset: 0, Limit: 99999999999999, SortBy: "title", SortOrder: "asc"}
	all := &pubsub.Message{Payload: options, Reply: make(chan interface{}, capacity)}
	c.bus.Pub(all, "/get/movies")

	reply := <-all.Reply
	dto := reply.(*model.MoviesDTO)

	if c.settings.UnraidMode {
		for _, item := range dto.Items {
			// mlog.Info("Item is %s (%s)", item.Title, item.Location)

			index := strings.Index(item.Location, ":")

			host := item.Location[:index]
			location := item.Location[index+1:]

			req := client.NewRequest("io.jbrodriguez.mediagui.agent."+host, "Agent.Exists", &agent.ExistsReq{
				Location: location,
			})

			rsp := &agent.ExistsRsp{}

			if err := client.Call(context.Background(), req, rsp); err != nil {
				mlog.Warning("Unable to connect to service (%s): %s", "io.jbrodriguez.mediagui.agent."+host, err)
				// lib.Notify(s.bus, "import:progress", "Unable to connect to host "+host)
				// lib.Notify(s.bus, "import:end", "Import process finished")
				// return
				continue
			}

			if !rsp.Exists {
				lib.Notify(c.bus, "prune:selected", fmt.Sprintf("UP FOR DELETION: [%d] %s (%s))", item.Id, item.Title, item.Location))

				movie := &pubsub.Message{Payload: item, Reply: make(chan interface{}, capacity)}
				c.bus.Pub(movie, "/command/movie/delete")
			}
		}
	} else {
		for _, item := range dto.Items {
			matches := c.re.FindStringSubmatch(item.Location)
			if len(matches) == 0 {
				continue
			}

			folder := filepath.Join("/Volumes", matches[1])
			if !c.maps[folder] {
				// mlog.Info("Folder not mapped (%s): %s", folder, item.Location)
				continue
			}

			// mlog.Info("Folder mapped (%s): %s", folder, item.Location)

			if _, err := os.Stat(item.Location); err != nil {
				if os.IsNotExist(err) {
					lib.Notify(c.bus, "prune:selected", fmt.Sprintf("UP FOR DELETION: [%d] %s (%s))", item.Id, item.Title, item.Location))

					movie := &pubsub.Message{Payload: item, Reply: make(chan interface{}, capacity)}
					c.bus.Pub(movie, "/command/movie/delete")
				}
			}
		}
	}

	// for _, folder := range c.settings.MediaFolders {
	// 	mlog.Info("folder: %s", folder)
	// 	if _, err := os.Stat(folder); err != nil {
	// 		if os.IsNotExist(err) {
	// 			lib.Notify(c.bus, "prune:error", fmt.Sprintf("Folder %s is not present. Aborting Prune process.", folder))
	// 			return
	// 		}
	// 	}
	// }

	// lib.Notify(c.bus, "prune:end", "Finished Prune Process")
	lib.Notify(c.bus, "prune:end", fmt.Sprintf("Prune process finished (%s elapsed)", time.Since(t0).String()))

}