Exemplo n.º 1
0
// 最新入库
func (this *IndexController) Newly() {
	// 定义两个SC_Info列表
	var infos, hots []models.SC_Info

	// 获取热门种子列表
	models.GetDataByQuery(models.DbInfo, 0, 5, "-hot", nil, &hots)
	// 设置热门列表
	this.Data["HotList"] = hots

	// 获取最新入库列表
	models.GetDataByQuery(models.DbInfo, 0, 15, "-puttime", nil, &infos)
	// 设置最新入库列表
	this.Data["Lists"] = infos

	// 定义一个SC_Search列表
	var wesearch []models.SC_Search

	// 获取大家都在搜
	models.GetDataByQuery(models.DbSearch, 0, 10, "-searchtime", nil, &wesearch)
	// 设置大家都在搜
	this.Data["SearchList"] = wesearch

	this.TplNames = "new.html"
}
Exemplo n.º 2
0
// 首页
func (this *IndexController) Index() {
	// 如果当前是简体中文
	if this.Lang == "zh-CN" {
		// 获取配置中的cnhotlist内容
		str := beego.AppConfig.String("cnhotlist")
		// 如果内容长度大于0
		if len(str) > 0 {
			// 以|分割字符串
			strs := strings.Split(str, "|")
			// 定义一个HotList列表
			var hotlist []HotList

			// 对分割的字符串数组循环处理
			for _, s := range strs {
				// 定义一个HotList结构
				h := HotList{
					Caption: s,
				}
				// 将定义的HotList加入到列表中
				hotlist = append(hotlist, h)
			}

			// 设置热门列表
			this.Data["HotList"] = hotlist
		}
	} else {
		// 定义一个Info列表
		var infos []models.SC_Info
		// 获取热门种子列表
		models.GetDataByQuery(models.DbInfo, 0, 20, "-hot", nil, &infos)
		// 设置热门列表
		this.Data["HotList"] = infos
	}

	// 输出模板
	this.TplNames = "index.html"
}
Exemplo n.º 3
0
// 搜索页
func (this *IndexController) Search() {
	// 获取搜索关键字
	key := this.Ctx.Input.Param(":k")
	// 获取排序方式
	sort := this.Ctx.Input.Param(":sort")
	// 设置排序方式
	this.Data["Sort"] = sort
	if sort == "" {
		this.Data["Sort"] = "puttime"
		sort = "-hot"
	}

	sort = "-" + sort

	// 设置搜索词
	this.Data["Key"] = key

	// 定义两个SC_Info列表
	var infos, newlist, hots []models.SC_Info

	// 获取热门种子列表
	models.GetDataByQuery(models.DbInfo, 0, 5, "-hot", nil, &hots)
	// 设置热门列表
	this.Data["HotList"] = hots

	// 获取最新入库
	models.GetDataByQuery(models.DbInfo, 0, 10, "-puttime", nil, &newlist)
	// 设置最新入库
	this.Data["NewList"] = newlist

	// 设置查询条件
	query := bson.M{"$or": []bson.M{bson.M{"caption": bson.M{"$regex": bson.RegEx{key, "i"}}}, bson.M{"keys": bson.M{"$regex": bson.RegEx{key, "i"}}}}}

	// 获取种子数量
	count := models.Count(models.DbInfo, query)

	// 设置数量
	this.Data["Nums"] = count

	// 获取分页数据
	page := pagination.NewPaginator(this.Ctx.Request, 15, count)
	// 设置分页数据
	this.Data["paginator"] = page

	// 获取种子列表
	models.GetDataByQuery(models.DbInfo, page.Offset(), 15, sort, query, &infos)
	// 设置种子列表
	this.Data["Lists"] = infos

	// 定义三个SC_Search列表
	var randomlist, lastsearch, relevantsearch []models.SC_Search

	// 设置查询条件
	query = bson.M{"$or": []bson.M{bson.M{"caption": bson.M{"$regex": bson.RegEx{key, "i"}}}}}
	// 获取相关搜索
	models.GetDataByQuery(models.DbSearch, 0, 10, "-searchtime", query, &relevantsearch)
	// 设置相关搜索
	this.Data["RelevantList"] = relevantsearch

	// 获取热门搜索
	models.GetDataByQuery(models.DbSearch, 0, 10, "-views", nil, &randomlist)
	// 设置热门搜索
	this.Data["RandomList"] = randomlist

	// 获取最近搜索
	models.GetDataByQuery(models.DbSearch, 0, 10, "-searchtime", nil, &lastsearch)
	// 设置最后搜索
	this.Data["LastSearch"] = lastsearch

	// 定义一个SC_Search
	var scsearch models.SC_Search
	// 设置关键字
	scsearch.Caption = key
	// 设置查询次数
	scsearch.Views = 1
	// 设置查询到的数据总量
	scsearch.Count = count
	// 保存数据
	scsearch.Save()

	// 自增查询次数
	models.SaveLog(time.Now().Format("20060102"), "searchnums")

	// 输出模板
	this.TplNames = "list.html"
}
Exemplo n.º 4
0
// 显示页
func (this *IndexController) View() {
	// 获取InfoHash
	infohash := this.Ctx.Input.Param(":infohash")

	// 将infohash转换为大写
	infohash = strings.ToUpper(infohash)

	// 定义一个SC_Info
	var scinfo models.SC_Info

	// 获取种子信息
	models.GetOneByQuery(models.DbInfo, bson.M{"infohash": infohash}, &scinfo)

	if scinfo.InfoHash == "" {
		// 如果infohash为空或小于40则报错
		this.Abort("404")
	}

	// 设置种子标题
	this.Data["Caption"] = scinfo.Caption

	// 定义两个SC_Info列表
	var hots []models.SC_Info

	// 获取热门种子列表
	models.GetDataByQuery(models.DbInfo, 0, 5, "-hot", nil, &hots)
	// 设置热门列表
	this.Data["HotList"] = hots

	// 自增下载次数
	models.SetAdd(models.DbInfo, bson.M{"infohash": infohash}, "views", true)

	// 设置创建时间
	this.Data["CreateTime"] = scinfo.CreateTime
	// 设置入库时间
	this.Data["PutTime"] = scinfo.PutTime
	// 设置文件大小
	this.Data["Length"] = scinfo.Length
	// 设置关键词
	this.Data["Keys"] = scinfo.Keys
	// 设置种子热度
	this.Data["Hot"] = scinfo.Hot
	// 设置文件数量
	this.Data["FileCount"] = scinfo.FileCount
	// 设置InfoHash
	this.Data["InfoHash"] = scinfo.InfoHash
	// 设置文件列表
	this.Data["FileList"] = scinfo.FileList
	// 设置下载链接
	this.Data["Down"] = fmt.Sprintf("http://btcache.me/torrent/%s", scinfo.InfoHash)

	// 二维码文件是否存在
	if _, err := os.Stat("/static/qrcode/" + scinfo.InfoHash[0:1] + "/" + scinfo.InfoHash[1:2] + "/" + scinfo.InfoHash[2:3] + "/" + scinfo.InfoHash[3:4] + "/" + scinfo.InfoHash[4:5] + "/" + scinfo.InfoHash[5:6] + "/" + scinfo.InfoHash[6:7] + "/" + scinfo.InfoHash + ".png"); err != nil {
		// 存在则设置二维码图片
		this.Data["Qrcode"] = "/static/qrcode/" + scinfo.InfoHash[0:1] + "/" + scinfo.InfoHash[1:2] + "/" + scinfo.InfoHash[2:3] + "/" + scinfo.InfoHash[3:4] + "/" + scinfo.InfoHash[4:5] + "/" + scinfo.InfoHash[5:6] + "/" + scinfo.InfoHash[6:7] + "/" + scinfo.InfoHash + ".png"
	}

	// 自增查看次数
	models.SaveLog(time.Now().Format("20060102"), "viewnums")

	// 输出模板
	this.TplNames = "view.html"
}
Exemplo n.º 5
0
// 入库主函数
func Put() {
	// 设置最大允许使用CPU核心数
	runtime.GOMAXPROCS(2)
	// 定义一个通道
	chReq := make(chan models.SC_Hash, 10)
	// 定义一个通道
	chRes := make(chan string, 10)

	// 无限循环入库种子
	for {
		// 获取未入库hash总量
		allcount := models.Count(models.DbHash, bson.M{"isput": false, "invalid": bson.M{"$lte": 3}})

		// 如果数量小于1
		if allcount < 1 {
			// 停顿10秒
			time.Sleep(10 * time.Second)
			// 跳过本次循环
			continue
		}

		for ai := 0; ai < allcount; {
			// 定义一个SC_Hash列表
			var sc_hash []models.SC_Hash
			// 获取100条infohash
			models.GetDataByQuery(models.DbHash, ai, (ai + 100), "-hot", bson.M{"isput": false, "invalid": bson.M{"$lte": 3}}, &sc_hash)
			// 获取到的总量
			count := len(sc_hash)

			// 循环处理infohash, 每次处理进程为自定义进程数
			for i := 0; i < 10; i++ {
				go func() {
					// 循环处理
					for {
						// 循环接受通道传递过来的infohash
						schash := <-chReq

						// 检查infohash是否已经入库
						if models.Has(models.DbInfo, bson.M{"infohash": strings.ToUpper(schash.InfoHash)}) {
							// 入库则输出跳过信息
							chRes <- fmt.Sprintf("'%s' Skip......", schash.InfoHash)
							// 将hash设置为已入库
							models.SetPut(schash.InfoHash)
							// 跳过本次循环
							continue
						}

						// 定义一个string变量, 记录处理结果
						var str string

						// 入库种子信息
						ret, err := PullTorrent(schash.InfoHash)
						if err == nil && ret == 0 {
							// 设置成功信息
							str = fmt.Sprintf("Storage InfoHash '%s' Success......", schash.InfoHash)
						} else {
							// 设置失败信息
							str = fmt.Sprintf("Can not download '%s' torrent file......", schash.InfoHash)
						}
						// 传递处理结果
						chRes <- str
					}
				}()
			}

			go func() {
				// 定义一个hashs列表
				hashs := make([]models.SC_Hash, count)

				// 循环将infohash加入hashs列表
				for i := 0; i < count; i++ {
					hashs[i] = sc_hash[i]
				}

				// 传递infohash给通道
				for i := 0; i < count; i++ {
					chReq <- hashs[i]
				}
			}()

			// 循环处理入库结果
			for i := 0; i < count; i++ {
				// 接收入库结果
				str := <-chRes

				// 如果允许显示则显示
				if models.DbConfig.ShowMsg && str != "" {
					fmt.Println(str)
				} else {
					// 否则不显示
					_ = str
				}
			}
		}
	}
}