Esempio n. 1
0
func (r *ReleasesCommand) exportNZB(c *kingpin.ParseContext) error {
	cfg := loadConfig(*configfile)
	if *debug {
		logrus.SetLevel(logrus.DebugLevel)
	}

	dbh := db.NewDBHandle(cfg.DB.Name, cfg.DB.Username, cfg.DB.Password, cfg.DB.Verbose)

	var rel types.Release
	err := dbh.DB.First(&rel, r.ReleaseID).Error
	if err != nil {
		return err
	}

	filename := r.FilePath
	if filename == "" {
		filename = rel.Name + ".nzb"
	}
	fullpath := path.Join(r.DirPath, filename)

	fmt.Printf("Writing NZB for %s to %s\n", rel.Name, fullpath)
	err = ioutil.WriteFile(fullpath, []byte(rel.NZB), 0644)

	if err != nil {
		return err
	}

	return nil
}
Esempio n. 2
0
func (s *BinariesCommand) run(c *kingpin.ParseContext) error {
	if *debug {
		logrus.SetLevel(logrus.DebugLevel)
	}
	cfg := loadConfig(*configfile)

	dbh := db.NewDBHandle(cfg.DB.Name, cfg.DB.Username, cfg.DB.Password, cfg.DB.Verbose)
	return dbh.MakeBinaries()
}
Esempio n. 3
0
func commonInit() (*config.Config, *db.Handle) {
	if *debug {
		logrus.SetLevel(logrus.DebugLevel)
	}
	cfg := loadConfig(*configfile)

	dbh := db.NewDBHandle(cfg.DB.Name, cfg.DB.Username, cfg.DB.Password, cfg.DB.Verbose)

	return cfg, dbh
}
Esempio n. 4
0
File: api.go Progetto: hobeone/gonab
// RunAPIServer sets up and starts a server to provide the NewzNab API
func RunAPIServer(cfg *config.Config) {
	dbh := db.NewDBHandle(cfg.DB.Name, cfg.DB.Username, cfg.DB.Password, cfg.DB.Verbose)
	n := configRoutes(dbh)
	fmt.Println("Starting server on :8078")
	n.Run(":8078")
}
Esempio n. 5
0
func (regeximporter *RegexImporter) run(c *kingpin.ParseContext) error {
	if *debug {
		logrus.SetLevel(logrus.DebugLevel)
	}
	logrus.Infof("Reading config %s\n", *configfile)

	cfg := loadConfig(*configfile)
	url := cfg.Regex.URL
	logrus.Infof("Crawling %v", url)

	b, err := getURL(url)
	if err != nil {
		return err
	}
	var collectionRegexRaw []byte
	if cfg.Regex.CollectionURL != "" {
		logrus.Infof("CollectionURL set, crawling: %s", cfg.Regex.CollectionURL)
		collectionRegexRaw, err = getURL(cfg.Regex.CollectionURL)
		if err != nil {
			return err
		}
	}

	var regexes []*types.Regex
	var collectionRegexes []*types.Regex
	switch cfg.Regex.Type {
	case "nnplus":
		regexes, err = parseNewzNabRegexes(b)
	case "nzedb":
		regexes, err = parseNzedbRegexes(b, "release")
		collectionRegexes, err = parseNzedbRegexes(collectionRegexRaw, "collection")
	default:
		return fmt.Errorf("Unknown Regex type: %s", cfg.Regex.Type)
	}
	if err != nil {
		return err
	}
	logrus.Infof("Parsed %d regexes from %s", len(regexes), url)

	dbh := db.NewDBHandle(cfg.DB.Name, cfg.DB.Username, cfg.DB.Password, cfg.DB.Verbose)
	newcount := 0
	tx := dbh.DB.Begin()
	tx.Where("id < ?", 100000).Delete(&types.Regex{})
	for _, dbregex := range regexes {
		err = tx.Create(dbregex).Error
		if err != nil {
			logrus.Errorf("Error saving regex: %v", err)
			tx.Rollback()
			return err
		}
		newcount++
	}
	tx.Where("id < ?", 100000).Delete(&types.Regex{Kind: "collection"})
	for _, dbregex := range collectionRegexes {
		err = tx.Create(dbregex).Error
		if err != nil {
			logrus.Errorf("Error saving collection regex: %v", err)
			tx.Rollback()
			return err
		}
		newcount++
	}
	tx.Commit()
	logrus.Infof("Saved %d regexes.", newcount)
	return nil
}
Esempio n. 6
0
func (s *ScanCommand) scan(c *kingpin.ParseContext) error {
	if *debug {
		logrus.SetLevel(logrus.DebugLevel)
	}
	cfg := loadConfig(*configfile)

	if s.MaxConns < 1 {
		s.MaxConns = cfg.NewsServer.MaxConns
	}
	if s.MaxConns < 1 {
		s.MaxConns = 1
	}

	dbh := db.NewDBHandle(cfg.DB.Name, cfg.DB.Username, cfg.DB.Password, cfg.DB.Verbose)
	var groups []types.Group
	if s.Group != "" {
		g, err := dbh.FindGroupByName(s.Group)
		if err != nil {
			return fmt.Errorf("Error getting group %s, have you added it?", s.Group)
		}
		groups = []types.Group{*g}
	} else {
		var err error
		groups, err = dbh.GetActiveGroups()
		if err != nil {
			return err
		}
		if len(groups) == 0 {
			return fmt.Errorf("No active groups to scan.")
		}
	}
	logrus.Debugf("Got %d groups to scan.", len(groups))

	connsToMake := s.MaxConns
	if len(groups) < s.MaxConns {
		connsToMake = len(groups)
	}

	reqchan := make(chan *scanRequest)
	respchan := make(chan *scanResponse, len(groups))
	var wg sync.WaitGroup

	for i := 0; i < connsToMake; i++ {
		g, err := NewGroupScanner(cfg, dbh, fmt.Sprintf("%d", i))
		if g != nil {
			defer g.Close()
		}
		if err != nil {
			return err
		}
		fmt.Printf("Started scanner %d\n", i)
		wg.Add(1)
		go g.ScanLoop(reqchan, &wg)
	}

	for _, g := range groups {
		logrus.Debugf("Requesting scan of %s", g.Name)
		reqchan <- &scanRequest{
			Group:        g.Name,
			Max:          s.MaxArticles,
			MaxChunk:     s.MaxChunk,
			ResponseChan: respchan,
		}
	}
	close(reqchan) // Causes workers to exit
	wg.Wait()
	close(respchan) // Causes range below to be non-infinite

	for r := range respchan {
		fmt.Printf("Finished scanning %s\n", r.Group)
		fmt.Printf("  %d new Messages\n", r.Articles)
		fmt.Printf("Error: %s\n", r.Error)
	}

	return nil
}