Ejemplo n.º 1
0
func (r *Runner) initCrawler() {
	man := crawler.NewManager(r.Config.TownUser, r.Config.TownPassword, "town", r.RecvChan)
	man.SetClient(func() crawler.Client { return town.NewClient() })
	man.SetParser(func() crawler.Parser { return &town.TownParser{} })
	r.Manager["town"] = man

	/*man2 := crawler.NewManager(r.Config.GhostUser, r.Config.GhostPassword, "ghost", r.RecvChan)
	man2.SetClient(func() crawler.Client { return ghost.NewClient() })
	man2.SetParser(func() crawler.Parser { return &ghost.GhostParser{} })
	r.Manager["ghost"] = man2*/
}
Ejemplo n.º 2
0
func (r *Releases) ThankReleaseWithId(id int64) ([]byte, error) {
	var rel data.Release

	err := r.db.Where("id = ?", id).First(&rel).Error
	if err != nil {
		return nil, err
	}

	if rel.Nzb == "" {
		tc := town.NewClient()
		tc.User = r.conf.TownUser
		tc.Password = r.conf.TownPassword

		err = tc.Login()
		if err != nil {
			return nil, err
		}

		tp, err := town.NewTownPostParserWithClient(rel.Url, tc)
		if err != nil {
			return nil, err
		}

		postid, err := tp.GetPostId()
		if err != nil {
			return nil, err
		}

		token, err := tp.GetSecurityToken()
		if err != nil {
			return nil, err
		}

		err = tc.ThankPost(postid, token)
		if err != nil {
			return nil, err
		}

		tp, err = town.NewTownPostParserWithClient(rel.Url, tc)
		if err != nil {
			return nil, err
		}

		url := tp.GetNzbUrl()
		passwd := tp.GetPassword()

		err = r.db.Model(&rel).First(&rel).UpdateColumns(data.Release{Nzb: url, Password: passwd}).Error
		if err != nil {
			return nil, err
		}

		retval := map[string]interface{}{
			"id":       id,
			"nzb":      url,
			"passwort": passwd,
		}

		by, err := json.Marshal(retval)
		return by, err
	} else {
		retval := map[string]interface{}{
			"id":       id,
			"nzb":      rel.Nzb,
			"passwort": rel.Password,
		}

		by, err := json.Marshal(retval)
		return by, err
	}

}