<!--#include file="conn.asp"-->
<%
dim action,rtype,rpage,rkey,rday,ids,apicn,apicp,app_apiver

if app_api=0 then writeE "closed"
action = be("get","ac")
rtype = be("get","t")
rpage = be("get","pg")
rkey = be("get","wd") : rkey = chkSql(rkey,true)
rday = be("get","h")

if not isNum(rtype)  then rtype=0 else rtype=clng(rtype)
if not isNum(rpage) then rpage=1 else rpage=clng(rpage)
if rpage < 1 then rpage = 1
if not isNum(rday)  then rday=0 else rday=clng(rday)

app_apiver="5.0"
apicp=10

select case action
	case "videolist"
		call cj
	case else
		call list
end select
dispseObj()

sub cj
	dim i,sql,rs,whereStr,rscount,xml,xmla
	dim pagecount,tempurl,temppic,temptn,typearr,vlink,plink
	ids = be("get","ids")
	ids = chkSql(ids,true)
	
	apicn = "maccmsapi-videolist" & rtype & "-" & rpage & "-" & rkey & "-" & rday & "-" & replace(ids,",","")
	if chkCache(apicn) then
		writeE getCache(apicn)
	end if
	
	xmla = "<?xml version=""1.0"" encoding=""utf-8""?>"
	xmla = xmla & "<rss version="""&app_apiver&""">"
	
	sql = " select * from {pre}vod where 1=1 "
    On Error Resume Next
	if ids<>"" then
		sql = sql & " and d_id in ("& ids &")"
	end if
	if rtype>0 then
		sql = sql &  " and d_type="&rtype
	end if
	if rday >0 then
		if app_dbtype = "access" then
			whereStr =  " and DateDiff('h',d_time,#"&now()&"#)<"&rday
		else
			whereStr =  " and DateDiff(hh,d_time,getdate())<"&rday
		end if
		sql = sql & whereStr
	end if
	
    sql = sql & " order by d_time asc "
	Set rs = objdb.db(sql,"rs1")
	If Err.number <> 0 Then
		writeA "err：" & Err.Description & "<br>" & sql
		err.clear
		exit sub
	end If
	
	if not rs.eof then
		
		rs.PageSize = app_apipagenum
		if rs.pagecount > 0 then rs.AbsolutePage = rpage : pagecount = rs.pagecount
		if rs.PageSize > rs.recordcount then rscount = rs.recordcount else : rscount = rs.PageSize
		
		xml = xml & "<list page="""&rpage&""" pagecount="""&pagecount&""" pagesize="""&app_apipagenum&""" recordcount="""&rscount&""">"
		
		for i = 1 to rscount
			if rs.eof then exit for
			tempurl = urlDeal(rs("d_playurl"),rs("d_playfrom"))
	    	if instr(","&rs("d_pic"),"http://") then temppic = rs("d_pic") else temppic = app_apicjflag & rs("d_pic")
	    	typearr = getValueByArray(cachevodtype, rs("d_type"))
	    	temptn = typearr(1)
			plink = app_siteurl & objTemplate.getVodPlayUrl(rs("d_id"),rs("d_name"),rs("d_enname"),rs("d_addtime"),rs("d_type"),typearr(1),typearr(2),1,1)
			
	    	xml = xml & "<video>"
	    	xml = xml & "<last>"&rs("d_time")&"</last>"
			xml = xml & "<id>"&rs("d_id")&"</id>"
			xml = xml & "<tid>"&rs("d_type")&"</tid>"
			xml = xml & "<name><![CDATA["&rs("d_name")&"]]></name>"
			xml = xml & "<type>"&temptn&"</type>"
			xml = xml & "<pic>"&temppic&"</pic>"
			xml = xml & "<lang>"&rs("d_language")&"</lang>"
			xml = xml & "<area>"&rs("d_area")&"</area>"
			xml = xml & "<year>"&rs("d_year")&"</year>"
			xml = xml & "<state>"&rs("d_state")&"</state>"
			xml = xml & "<note><![CDATA["&rs("d_remarks")&"]]></note>"
			xml = xml & "<actor><![CDATA["&rs("d_starring")&"]]></actor>"
			xml = xml & "<director><![CDATA["&rs("d_directed")&"]]></director>"
			xml = xml & "<dl>"&tempurl&"</dl>"
			xml = xml & "<des><![CDATA["&rs("d_content")&"]]></des>"
			'xml = xml & "<vlink><![CDATA["&vlink&"]]></vlink>"
			xml = xml & "<reurl><![CDATA["&plink&"]]></reurl>"
			xml = xml & "</video>"
			rs.movenext
			if rs.eof then exit for
		next
		xml = xml & "</list>"
		
	end if
	objdb.c(rs)
	xmla = xmla & xml & "</rss>"
	
	setCache apicn,xmla
	writeA xmla
end sub

sub list
	dim rs,rsurl,sql,xml,typearr,vlink,plink
	
	apicn = "maccmsapi-list-" & rtype & "-" & rpage & "-" & rkey & "-" & rday
	
	if chkCache(apicn) then
		writeE getCache(apicn)
	end if
	
	xml = "<?xml version=""1.0"" encoding=""utf-8""?>"
	xml = xml & "<rss version="""&app_apiver&""">"
	
	sql = "select d_id,d_name,d_enname,d_type,d_time,d_remarks,d_playfrom,d_addtime from {pre}vod where 1=1 "
	if rtype > 0 then sql = sql & " and d_type=" & rtype
	if app_apivodfilter <> "" then  sql = sql & " " & app_apivodfilter
	if rkey <> "" then sql = sql & " and d_name like '%"&rkey&"%' "
	sql = sql & " order by d_time desc"
	
	set rs = objdb.db(sql,"rs1")
	if Err.number <> 0 Then
		writeA "err：" & Err.Description & "<br>" & sql
		err.clear
		exit sub
	end if
	
	if rs.eof then
		xml = xml & "<list page="""&rpage&""" pagecount=""0"" pagesize="""&app_apipagenum&""" recordcount=""0"">"
	else
    	dim i
		rs.PageSize = app_apipagenum
	    rs.AbsolutePage = rpage
	    xml = xml & "<list page="""&rpage&""" pagecount="""&rs.PageCount&""" pagesize="""&app_apipagenum&""" recordcount="""&rs.RecordCount&""">"
	  	for i = 1 to rs.PageSize
		  	if rs.eof then exit for
			typearr = getValueByArray(cachevodtype, rs("d_type"))
			plink = app_siteurl & objTemplate.getVodPlayUrl(rs("d_id"),rs("d_name"),rs("d_enname"),rs("d_addtime"),rs("d_type"),typearr(1),typearr(2),1,1)
			
			xml = xml & "<video>"
			xml = xml & "<last>"&rs("d_time")&"</last>"
			xml = xml & "<id>"&rs("d_id")&"</id>"
			xml = xml & "<tid>"&rs("d_type")&"</tid>"
			xml = xml & "<name><![CDATA["&rs("d_name")&"]]></name>"
			xml = xml & "<type>"&typearr(1)&"</type>"
			xml = xml & "<dt>"&replaceStr(rs("d_playfrom"),"$$$",",")&"</dt>"
			xml = xml & "<note><![CDATA["&rs("d_remarks")&"]]></note>"
			'xml = xml & "<vlink><![CDATA["&vlink&"]]></vlink>"
			xml = xml & "<reurl><![CDATA["&plink&"]]></reurl>"
			xml = xml & "</video>"
			rs.MoveNext
		next 
	end if
	xml = xml & "</list>"
	
	xml = xml & "<class>"
	sql = "select * from {pre}vod_type where 1=1 "
	if app_apitypefilter <> "" then	sql = sql & app_apitypefilter
	set rs = objdb.db(sql,"rs1")
	do while not rs.eof
		xml = xml & "<ty id="""&rs("t_id")&""">"&rs("t_name")&"</ty>"
		rs.movenext
	loop
	xml = xml & "</class>"
	objdb.c(rs)
	
	xml = xml & "</rss>"
	objdb.c(rs)
	if rpage<=apicp then
		setCache apicn,xml
	end if
	writeA xml
end sub

function urlDeal(byval url,byval from)
	dim str,arr1,arr1count,arr2,arr2count,i,j
	arr1 = split(url,"$$$") : arr1count = ubound(arr1)
	arr2 = split(from,"$$$") : arr2count = ubound(arr2)
	For i = 0 To arr2count
		If arr1count >= i Then
			str = str & "<dd flag="""& arr2(i) &"""><![CDATA[" & arr1(i)& "]]></dd>"
		end if
	next
	str = replaceStr(str,chr(10),"#")
	str = replaceStr(str,chr(13),"#")
	str = replaceStr(str,"##","#")
	urlDeal = str
end function
%>