func (s *ReScrape) Execute(wid int) { movie := s.dto.Movie.(*model.Movie) // lib.Notify(s.bus, "import:progress", fmt.Sprintf("RESCRAPE REQUESTED (%d) [%d] %s", wid, movie.Id, movie.Title)) mlog.Info("RESCRAPE REQUESTED (%d) [%d] %s", wid, movie.Id, movie.Title) now := time.Now().UTC().Format(time.RFC3339) movie.Modified = now id := movie.Tmdb_Id err := _scrape(wid, s.tmdb, id, movie) if err != nil { // lib.Notify(s.bus, "import:progress", fmt.Sprintf("RESCRAPE FAILED (%d) [%d] %s: %s", wid, movie.Id, movie.Title, err)) mlog.Warning("RESCRAPE FAILED (%d) [%d] %s: %s", wid, movie.Id, movie.Title, err) s.bus.Pub(nil, "/event/workunit/done") return } s.dto.BaseUrl = s.tmdb.BaseUrl s.dto.SecureBaseUrl = s.tmdb.SecureBaseUrl // lib.Notify(s.bus, "import:progress", fmt.Sprintf("RESCRAPE COMPLETED (%d) [%d] %s", wid, movie.Id, movie.Title)) mlog.Info("RESCRAPE COMPLETED (%d) [%d] %s", wid, movie.Id, movie.Title) msg := &pubsub.Message{Payload: s.dto} s.bus.Pub(msg, "/event/movie/rescraped") }
func (c *Connection) Writer() { ticker := time.NewTicker(pingPeriod) defer func() { ticker.Stop() c.Ws.Close() }() // mlog.Info("before write loop") for { select { case message, ok := <-c.Send: if !ok { c.write(websocket.CloseMessage, []byte{}) mlog.Warning("Closing socket ...") return } if err := c.write(websocket.TextMessage, message); err != nil { mlog.Warning("Unable to write to websocket: %s", err.Error()) return } // c.Ws.SetWriteDeadline(time.Now().Add(writeWait)) // if err := c.Ws.WriteJSON(message); err != nil { // mlog.Error(err) // return // } case <-ticker.C: if err := c.write(websocket.PingMessage, []byte{}); err != nil { mlog.Info("error with ping: %s", err.Error()) return } } } }
// disconnectBotFromServer Функция отключает бота от игрового сервера func disconnectBotFromServer(id int) error { mlog.Trace("Функция: disconnectBotFromServer") var err error bot, ok := mbot[id] if !ok { err = errors.New(fmt.Sprintf("В mbot нет бота с указанным индексом. id = %d", id)) mlog.Error(err) return err } if !bot.Connected { mlog.Warning("Бот уже отключен от сервера.") return nil } bot.Connected = false mbot[id] = bot mlog.Trace("Функция: disconnectBotFromServer. Бот отключен от сервера.") return nil }
// connectBotToServer Функция получает uid и token с сайта mail.ru и подключается к игровому серверу func connectBotToServer(id int) error { mlog.Trace("Функция: connectBotToServer") var err error bot, ok := mbot[id] if !ok { err = errors.New(fmt.Sprintf("В mbot нет бота с указанным индексом. id = %d", id)) mlog.Error(err) return err } if bot.Connected { mlog.Warning("Бот уже подключен к серверу.") return nil } uid, uid2, token, err := getUidAndToken(bot.Login, bot.Password) if err != nil { mlog.Error(err) return err } mlog.Trace("Функция: connectBotToServer. uid = %v, uid2 = %v, token = %v", uid, uid2, token) bot.Connected = true mbot[id] = bot mlog.Trace("Функция: connectBotToServer. Бот подключен к серверу.") return nil }
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") }
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())) }