license.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package pgc
  2. import "fmt"
  3. const (
  4. _definition = "SD"
  5. )
  6. // License Owner Request message
  7. // License represents the data that we need to send to the license owner for auditing
  8. type License struct {
  9. TId string
  10. InputTime string
  11. Sign string
  12. XMLData *XMLData
  13. }
  14. // XMLData reprensents the main body of xml data sent to license owner
  15. type XMLData struct {
  16. Service *Service `xml:"Service"`
  17. }
  18. // Service body+head
  19. type Service struct {
  20. ID string `xml:"id,attr"`
  21. Head *Head
  22. Body *Body
  23. }
  24. // Head some header info
  25. type Head struct {
  26. TradeID string `xml:"TradeId"`
  27. Date string
  28. Count int
  29. }
  30. // Body Media list
  31. type Body struct {
  32. ProgramSetList *PSList `xml:"programSetList"`
  33. }
  34. // PSList is short for programSetList
  35. type PSList struct {
  36. ProgramSet []*PS `xml:"programSet"`
  37. }
  38. // PS is short for ProgramSet
  39. type PS struct {
  40. ProgramSetID string `xml:"programSetId"`
  41. ProgramSetName string `xml:"programSetName"`
  42. ProgramSetClass string `xml:"programSetClass"`
  43. ProgramSetType string `xml:"programSetType"`
  44. ProgramSetPoster string `xml:"programSetPoster"`
  45. Portrait string `xml:"portrait"` // upper's portrait
  46. Producer string `xml:"producer"` // upper's name
  47. PublishDate string `xml:"publishDate"`
  48. Copyright string `xml:"copyright"`
  49. ProgramCount int `xml:"programCount"`
  50. CREndData string `xml:"cREndDate"`
  51. DefinitionType string `xml:"definitionType"`
  52. CpCode string `xml:"cpCode"`
  53. PayStatus int `xml:"payStatus"`
  54. PrimitiveName string `xml:"primitiveName"`
  55. Alias string `xml:"alias"`
  56. Zone string `xml:"zone"`
  57. LeadingRole string `xml:"leadingRole"`
  58. ProgramSetDesc string `xml:"programSetDesc"`
  59. Staff string `xml:"Staff"`
  60. SubGenre string `xml:"subGenre"`
  61. ProgramList *ProgramList `xml:"programList,omitempty"`
  62. }
  63. // ProgramList contains different EP
  64. type ProgramList struct {
  65. Program []*Program `xml:"program"`
  66. }
  67. // Program represents one EP data
  68. type Program struct {
  69. ProgramID string `xml:"programId"`
  70. ProgramName string `xml:"programName"`
  71. ProgramPoster string `xml:"programPoster"`
  72. ProgramLength int `xml:"programLength"`
  73. PublishDate string `xml:"publishDate"`
  74. IfPreview int `xml:"ifPreview"`
  75. Number string `xml:"number"`
  76. DefinitionType string `xml:"definitionType"`
  77. PlayCount int `xml:"playCount"`
  78. Drm int `xml:"drm"`
  79. ProgramMediaList *PMList `xml:"programMediaList"`
  80. ProgramDesc string `xml:"programDesc"`
  81. }
  82. // PMList is short for programMediaList
  83. type PMList struct {
  84. ProgramMedia []*PMedia `xml:"programMedia"`
  85. }
  86. // PMedia is short for ProgramMedia
  87. type PMedia struct {
  88. MediaID string `xml:"mediaId"`
  89. PlayURL string `xml:"playUrl"`
  90. Definition string `xml:"definition"`
  91. HTMLURL string `xml:"htmlUrl"`
  92. }
  93. // MakePMedia is used to construct PMedia structure
  94. func MakePMedia(prefix, playurl string, cid int64) *PMedia {
  95. return &PMedia{
  96. MediaID: fmt.Sprintf("%s%d", prefix, cid),
  97. PlayURL: playurl,
  98. Definition: _definition,
  99. HTMLURL: playurl,
  100. }
  101. }
  102. // Document is the result structure of license owner's response
  103. type Document struct {
  104. Response *Response
  105. }
  106. // Response is the main content of response
  107. type Response struct {
  108. TradeID string `xml:"TradeId"`
  109. ResponseCode string
  110. ResponseInfo string
  111. ResponseTime string `xml:"responseTime"`
  112. ErrorList *ErrorList
  113. }
  114. // ErrorList is the list of error returned by the license owner
  115. type ErrorList struct {
  116. Error *Error
  117. }
  118. // Error one error body
  119. type Error struct {
  120. ID string `xml:"Id"`
  121. Message string
  122. }
  123. // DelBody is the bodu message of deletion
  124. type DelBody struct {
  125. ProgramList *ProgramList `xml:"programList"`
  126. }
  127. // CreatePMedia creates PMedia struct
  128. func CreatePMedia(prefix string, epid int, url string) *PMedia {
  129. return &PMedia{
  130. MediaID: prefix + fmt.Sprintf("%d", epid),
  131. PlayURL: url,
  132. Definition: "SD",
  133. HTMLURL: url,
  134. }
  135. }
  136. // CreateProgram creates program
  137. func CreateProgram(prefix string, ep *TVEpContent) *Program {
  138. r := &Program{
  139. ProgramID: prefix + fmt.Sprintf("%d", ep.ID),
  140. ProgramName: ep.LongTitle,
  141. ProgramPoster: ep.Cover,
  142. ProgramLength: int(ep.Length * 60),
  143. PublishDate: "1970-01-01",
  144. IfPreview: 0,
  145. Number: ep.Title,
  146. DefinitionType: "SD",
  147. PlayCount: 0,
  148. Drm: ep.PayStatus,
  149. }
  150. r.isPay()
  151. return r
  152. }
  153. // ReqEpLicCall is the request struct for epLicCall function
  154. type ReqEpLicCall struct {
  155. EpLic *License
  156. SID int64
  157. Conts []*Content
  158. }
  159. // isPay .
  160. func (p *Program) isPay() {
  161. if p.Drm == 2 {
  162. p.Drm = 0
  163. } else {
  164. p.Drm = 1
  165. }
  166. }