Exemple #1
0
func Play(btService *bittorrent.BTService) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		uri := ctx.Request.URL.Query().Get("uri")
		if uri == "" {
			return
		}
		fileIndex := -1
		index := ctx.Request.URL.Query().Get("index")
		if index != "" {
			fIndex, err := strconv.Atoi(index)
			if err == nil {
				fileIndex = fIndex
			}
		}
		torrent := bittorrent.NewTorrent(uri)
		magnet := torrent.Magnet()
		boosters := url.Values{
			"tr": providers.DefaultTrackers,
		}
		magnet += "&" + boosters.Encode()
		player := bittorrent.NewBTPlayer(btService, magnet, config.Get().KeepFilesAfterStop == false, fileIndex)
		if player.Buffer() != nil {
			return
		}
		hostname := "localhost"
		if localIP, err := util.LocalIP(); err == nil {
			hostname = localIP.String()
		}
		rUrl, _ := url.Parse(fmt.Sprintf("http://%s:%d/files/%s", hostname, config.ListenPort, player.PlayURL()))
		ctx.Redirect(302, rUrl.String())
	}
}
Exemple #2
0
func Play(btService *bittorrent.BTService) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		uri := ctx.Request.URL.Query().Get("uri")
		index := ctx.Request.URL.Query().Get("index")
		resume := ctx.Request.URL.Query().Get("resume")

		if uri == "" && resume == "" {
			return
		}

		fileIndex := -1
		if index != "" {
			fIndex, err := strconv.Atoi(index)
			if err == nil {
				fileIndex = fIndex
			}
		}

		resumeIndex := -1
		if resume != "" {
			rIndex, err := strconv.Atoi(resume)
			if err == nil && rIndex >= 0 {
				resumeIndex = rIndex
			}
		}

		magnet := ""
		infoHash := ""
		if uri != "" {
			torrent := bittorrent.NewTorrent(uri)
			magnet = torrent.Magnet()
			infoHash = torrent.InfoHash
			boosters := url.Values{
				"tr": bittorrent.DefaultTrackers,
			}
			magnet += "&" + boosters.Encode()
		}

		player := bittorrent.NewBTPlayer(btService, magnet, fileIndex, resumeIndex, infoHash)
		if player.Buffer() != nil {
			return
		}
		hostname := "localhost"
		if localIP, err := util.LocalIP(); err == nil {
			hostname = localIP.String()
		}
		rUrl, _ := url.Parse(fmt.Sprintf("http://%s:%d/files/%s", hostname, config.ListenPort, player.PlayURL()))
		ctx.Redirect(302, rUrl.String())
	}
}
Exemple #3
0
func Play(btService *bittorrent.BTService) gin.HandlerFunc {
	return func(ctx *gin.Context) {
		uri := ctx.Request.URL.Query().Get("uri")
		index := ctx.Request.URL.Query().Get("index")
		resume := ctx.Request.URL.Query().Get("resume")
		contentType := ctx.Request.URL.Query().Get("type")
		tmdb := ctx.Request.URL.Query().Get("tmdb")
		runtime := ctx.Request.URL.Query().Get("runtime")

		if uri == "" && resume == "" {
			return
		}

		fileIndex := -1
		if index != "" {
			fIndex, err := strconv.Atoi(index)
			if err == nil {
				fileIndex = fIndex
			}
		}

		resumeIndex := -1
		if resume != "" {
			rIndex, err := strconv.Atoi(resume)
			if err == nil && rIndex >= 0 {
				resumeIndex = rIndex
			}
		}

		tmdbId := -1
		if tmdb != "" {
			id, err := strconv.Atoi(tmdb)
			if err == nil && id >= 0 {
				tmdbId = id
			}
		}

		runTime := -1
		if tmdb != "" {
			runtimeInt, err := strconv.Atoi(runtime)
			if err == nil && runtimeInt >= 0 {
				runTime = runtimeInt
			}
		}

		magnet := ""
		infoHash := ""
		if uri != "" {
			torrent := bittorrent.NewTorrent(uri)
			magnet = torrent.Magnet()
			infoHash = torrent.InfoHash
			boosters := url.Values{
				"tr": bittorrent.DefaultTrackers,
			}
			magnet += "&" + boosters.Encode()
		}

		params := bittorrent.BTPlayerParams{
			URI:         magnet,
			InfoHash:    infoHash,
			FileIndex:   fileIndex,
			ResumeIndex: resumeIndex,
			ContentType: contentType,
			TMDBId:      tmdbId,
			Runtime:     runTime,
		}

		player := bittorrent.NewBTPlayer(btService, params)
		if player.Buffer() != nil {
			return
		}

		rUrl, _ := url.Parse(fmt.Sprintf("%s/files/%s", util.GetHTTPHost(), player.PlayURL()))
		ctx.Redirect(302, rUrl.String())
	}
}