MediaListModel.go 3.13 KB
Newer Older
吴贤德's avatar
吴贤德 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package Wasu

import (
	"encoding/json"
	"fmt"
	"github.com/sirupsen/logrus"
	"src/Common/Request"
	"src/Config"
	"unsafe"
)

/**
	{
	"currentPage":1,
	"pageNum":1,
	"pageSize":2,
	"total":2,
	"list":[
	{
	"jsonUrl":"http://115.29.7.64:8092/XmlData/incrementJson?date=20190625&version=20190625150313",
	"md5":"a3e0d11328e0feb3114921851f39ac41",
	"newsId":"2018239",
	"newsName":"冰雪女王",
	"playUrl":"http://downloader.media.wasu.tv/data13/ott/344/2015-08/10/adc0650a31a5211ec6d0b1c9fdb10274/5d1496be/1439187357125_958916.ts"
	}
	]
	}
**/

type Media struct {
31 32 33 34 35 36 37 38 39
	Spid 		string 	`json:"spid"`
	PushMode 	string 	`json:"push_mode"` //是否自动转推:0手动,1自动
	JsonUrl 	string 	`json:"jsonUrl"`
	NewsId		string	`json:"newsId"`
	NewsName	string	`json:"newsName"`
	NodeId		string	`json:"nodeId"`
	NodeName	string	`json:"nodeName"`
	// Md5			string 	`json:"md5"`
	// PlayUrl		string	`json:"playUrl"`
吴贤德's avatar
吴贤德 committed
40 41 42 43 44 45 46 47 48 49 50 51
}

type MediaList struct {
	CurrentPage int   `json:"currentPage"`
	PageNum     int   `json:"pageNum"`
	PageSize    int   `json:"pageSize"`
	Total       int   `json:"total"`
	List        []*Media `json:"list"`
}

type MediaListModel struct {
	Config *Config.Config
52
	Spid string
吴贤德's avatar
吴贤德 committed
53 54 55
}

func (this *MediaListModel) FetchList(date string, page int) *MediaList {
56 57 58 59 60 61 62 63 64 65 66 67 68 69
	//wasu_api_incrementList, ok := this.Config.Sys.Get("wasu_api_incrementList")
	wasu_api_incrementList := ""
	config,ok := this.Config.Sps.Get(this.Spid)
	if ok {
		conf,ok:=config.(map[string]interface{})
		if ok {
			wasu_api_incrementList=conf["wasu_api_incrementList"].(string)
		}
	}

	if wasu_api_incrementList == "" {
		logrus.Error("PULL SP :",this.Spid," 缺少配置项:wasu_api_incrementList")
	}

吴贤德's avatar
吴贤德 committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
	mediaList := new(MediaList)
	if ok {
		url := fmt.Sprintf("%s?date=%s&page=%d", wasu_api_incrementList, date, page)

		data, err := Request.Get(url)
		if err == nil {
			json.Unmarshal([]byte(data), mediaList)
		}
	}
	return mediaList
}

func (this *MediaListModel) UpdateMediaList(mediaList *MediaList) bool {
	l := len(mediaList.List)
	nOk := 0
	for _, media := range mediaList.List {
		if this.UpdateMedia(media) {
			nOk++
		}
	}
	b := false
	if nOk == l {
		b = true
	}
	logrus.Debugln("UpdateMediaList : ok/total :", nOk, "/", l)
	return b
}

func (this *MediaListModel) UpdateMedia(media *Media) bool {
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
	media.Spid = this.Spid
	wasu_incrementList_push_mode:="";
	config,ok := this.Config.Sps.Get(this.Spid)
	if ok {
		conf,ok:=config.(map[string]interface{})
		if ok {
			wasu_incrementList_push_mode=conf["wasu_incrementList_push_mode"].(string)
		}
	}

	if wasu_incrementList_push_mode == "" {
		logrus.Error("PULL SP :",this.Spid," 缺少配置项:wasu_incrementList_push_mode")
		wasu_incrementList_push_mode="0"
	}

	media.PushMode=wasu_incrementList_push_mode;


吴贤德's avatar
吴贤德 committed
117 118 119 120
	center_api_media_update, ok := this.Config.Sys.Get("center_api_media_update")
	b := false
	if ok {
		inData, _ := json.Marshal(media)
121
		//fmt.Printf("****** media_info : %v",media)
吴贤德's avatar
吴贤德 committed
122
		data, err := Request.Post(center_api_media_update.(string), *(*string)(unsafe.Pointer(&inData)))
123
		//data, err := Request.Post(center_api_media_update.(string), string(inData))
吴贤德's avatar
吴贤德 committed
124 125 126 127 128 129 130 131 132
		if err == nil {
			if data == "true" {
				b = true
			}
		}
	}

	return b
}