m3u8
This commit is contained in:
		@@ -36,4 +36,8 @@ func 生成配置文件() {
 | 
			
		||||
	viper.Set("oss.endpoint", "")
 | 
			
		||||
	viper.Set("oss.accessID", "")
 | 
			
		||||
	viper.Set("oss.accessKey", "")
 | 
			
		||||
 | 
			
		||||
	viper.Set("video.endpoint", "")
 | 
			
		||||
	viper.Set("video.accessKeyID", "")
 | 
			
		||||
	viper.Set("video.accessKey", "")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										113
									
								
								models/video.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								models/video.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,113 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	openapi  "github.com/alibabacloud-go/darabonba-openapi/client"
 | 
			
		||||
	//util  "github.com/alibabacloud-go/tea-utils/service"
 | 
			
		||||
	//console  "github.com/alibabacloud-go/tea-console/client"
 | 
			
		||||
	env  "github.com/alibabacloud-go/darabonba-env/client"
 | 
			
		||||
	vod20170321  "github.com/alibabacloud-go/vod-20170321/v2/client"
 | 
			
		||||
	"github.com/alibabacloud-go/tea/tea"
 | 
			
		||||
 | 
			
		||||
	"log"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"regexp"
 | 
			
		||||
	"github.com/spf13/viper"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 使用AK&SK初始化账号Client  
 | 
			
		||||
func InitVodClient (accessKeyId *string, accessKeySecret *string, regionId *string) (_result *vod20170321.Client, _err error) {
 | 
			
		||||
	config := &openapi.Config{}
 | 
			
		||||
	config.AccessKeyId = accessKeyId
 | 
			
		||||
	config.AccessKeySecret = accessKeySecret
 | 
			
		||||
	config.RegionId = regionId
 | 
			
		||||
	_result = &vod20170321.Client{}
 | 
			
		||||
	_result, _err = vod20170321.NewClient(config)
 | 
			
		||||
	return _result, _err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetVideoM3U8(content string) (blob string) {
 | 
			
		||||
	if len(regexp.MustCompile(`image.gameuiux.cn`).FindStringSubmatch(content)) > 0 {
 | 
			
		||||
		key := regexp.MustCompile(`^https?://image.gameuiux.cn/`).ReplaceAllString(content, "")
 | 
			
		||||
 | 
			
		||||
		// 从OSS中读取视频
 | 
			
		||||
		bucket := GetBucket("gameui-image2")
 | 
			
		||||
		body, err := bucket.GetObject(key)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Println("读取视频失败", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		defer body.Close()
 | 
			
		||||
 | 
			
		||||
		// 先打印出视频对象
 | 
			
		||||
		fmt.Println(body)
 | 
			
		||||
 | 
			
		||||
		// 配置
 | 
			
		||||
		accessKeyID := viper.GetString("video.accessKeyID")
 | 
			
		||||
		accessKeySecret := viper.GetString("video.accessKey")
 | 
			
		||||
		//endpoint := viper.GetString("video.endpoint")
 | 
			
		||||
		regionId := "cn-shanghai"
 | 
			
		||||
 | 
			
		||||
		// 连接点播服务的OSS
 | 
			
		||||
		client, _err := InitVodClient(env.GetEnv(tea.String(accessKeyID)), env.GetEnv(tea.String(accessKeySecret)), ®ionId)
 | 
			
		||||
		if _err != nil {
 | 
			
		||||
		  return _err.Error()
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		fmt.Println(client)
 | 
			
		||||
 | 
			
		||||
		return "空"
 | 
			
		||||
 | 
			
		||||
		//// 1.获取视频上传地址和凭证,并生成视频信息
 | 
			
		||||
		//createUploadVideoRequest := &vod20170321.CreateUploadVideoRequest{
 | 
			
		||||
		//	Title: args[1],
 | 
			
		||||
		//	FileName: args[2],
 | 
			
		||||
		//}
 | 
			
		||||
		//createUploadVideoResponse, _err := client.CreateUploadVideo(createUploadVideoRequest)
 | 
			
		||||
		//if _err != nil {
 | 
			
		||||
		//	return _err.Error()
 | 
			
		||||
		//}
 | 
			
		||||
		//console.Log(util.ToJSONString(tea.ToMap(createUploadVideoResponse)))
 | 
			
		||||
		//// 媒体id
 | 
			
		||||
		//uploadVideoId := createUploadVideoResponse.Body.VideoId
 | 
			
		||||
		//console.Log(uploadVideoId)
 | 
			
		||||
		//// 如果视频文件过大,上传超时后可以刷新视频凭证,然后继续上传
 | 
			
		||||
		//refreshUploadVideoRequest := &vod20170321.RefreshUploadVideoRequest{
 | 
			
		||||
		//	VideoId: uploadVideoId,
 | 
			
		||||
		//}
 | 
			
		||||
		//refreshUploadVideoReponse, _err := client.RefreshUploadVideo(refreshUploadVideoRequest)
 | 
			
		||||
		//if _err != nil {
 | 
			
		||||
		//	return _err
 | 
			
		||||
		//}
 | 
			
		||||
		//console.Log(util.ToJSONString(tea.ToMap(refreshUploadVideoReponse)))
 | 
			
		||||
		//// 2.oss视频文件上传,需要用户实现
 | 
			
		||||
		//// 3.上传过程中,获取媒体上传详情
 | 
			
		||||
		//getUploadDetailsRequest := &vod20170321.GetUploadDetailsRequest{
 | 
			
		||||
		//	MediaIds: uploadVideoId,
 | 
			
		||||
		//}
 | 
			
		||||
		//getUploadDetailsReponse, _err := client.GetUploadDetails(getUploadDetailsRequest)
 | 
			
		||||
		//if _err != nil {
 | 
			
		||||
		//	return _err
 | 
			
		||||
		//}
 | 
			
		||||
		//console.Log(util.ToJSONString(tea.ToMap(getUploadDetailsReponse)))
 | 
			
		||||
		//// 4.媒体上传完成之后,可以获取媒体播放信息进行播放
 | 
			
		||||
		//// 4.1 通过播放凭证播放
 | 
			
		||||
		//getPlayInfoRequest := &vod20170321.GetPlayInfoRequest{
 | 
			
		||||
		//	VideoId: uploadVideoId,
 | 
			
		||||
		//}
 | 
			
		||||
		//getPlayInfoReponse, _err := client.GetPlayInfo(getPlayInfoRequest)
 | 
			
		||||
		//if _err != nil {
 | 
			
		||||
		//	return _err
 | 
			
		||||
		//}
 | 
			
		||||
		//console.Log(util.ToJSONString(tea.ToMap(getPlayInfoReponse)))
 | 
			
		||||
		//// 4.2 通过播放地址播放
 | 
			
		||||
		//getVideoPlayAuthRequest := &vod20170321.GetVideoPlayAuthRequest{
 | 
			
		||||
		//	VideoId: uploadVideoId,
 | 
			
		||||
		//}
 | 
			
		||||
		//getVideoPlayAuthReponse, _err := client.GetVideoPlayAuth(getVideoPlayAuthRequest)
 | 
			
		||||
		//if _err != nil {
 | 
			
		||||
		//	return _err
 | 
			
		||||
		//}
 | 
			
		||||
		//console.Log(util.ToJSONString(tea.ToMap(getVideoPlayAuthReponse)))
 | 
			
		||||
	}
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user