Project

General

Profile

AxiaProStream » TractPluginXML.lua

Oksana Ishutina, 16/03/2023 11:37

 
-- <nowplaying>
-- <ARTIST><![CDATA['artist']]></ARTIST>
-- <TITLE><![CDATA['title']]></TITLE>
-- </nowplaying>
--
-- ------------------------------------------------------------------
-- MetaData Filter. Copyright (C) 2011 Tls Corporation
-- Author: Ioan L. Rus
--
-- Lines that start with two dashes (like this line) are comments.
--
-- Metadata filters are written in a very simple programming
-- language named Lua. Additional information about the language
-- and it's syntax can be found at http://www.lua.org.
--
-- This file implements a metadata filter that parses XML data.
-- For this example,
--
-- <?xml version="1.0" ?>
-- <nowplaying>
-- <ARTIST><![CDATA[Chris Tomlin]]></ARTIST>
-- <TITLE><![CDATA[I Will Follow]]></TITLE>
-- <ARTIST_WEB><![CDATA[ArtistWeb C. Tomlin]]></ARTIST_WEB>
-- <TITLE_WEB><![CDATA[TitleWeb I Will Folow]]></TITLE_WEB>
-- </nowplaying>
--
-- the XML data expected will look like this:
--
-- <CurrentEvent>
-- <Artist>Chris Tomlin</Artist>
-- <Title>I Will Follow</Title>
-- <ArtistWeb>ArtistWeb C. Tomlin</ArtistWeb>
-- <TitleWeb>TitleWeb I Will Folow</TitleWeb>
-- </CurrentEvent>


-- ------------------------------------------------------------------

-- This tells the application that we wish to use an XML parser.
-- It is also possible (and in some cases more appropriate) to
-- use a line or character parser. Please see the other filter
-- examples for details.
UseXmlParser()

-- This function is called when a connection to the metadata
-- server is first established.
function OnConnect(clientAddress)
-- The print function sends data back to the client.
-- For this example we don't send anything back.
-- print("Hello ",clientAddress,"\r\n")
end

-- These functions are called by the application when a piece
-- of XML data is parsed. The functions extract the metadata
-- info then call SendMetaDataSong(title,url) to pass the info
-- back to the application to be included in the out going
-- streams.

-- TODO: Fill in the url to point to your website (or
-- any website where the listener can get more info
-- about the artist or song being played.
url=""

-- Work fields
currentElement=""
cuttype=""
artist=""
title=""
artist_web=""
title_web=""

-- Called when an XML element start has been parsed. The name
-- of the element and a table of attributes are provided.
function OnElementStart(elementName,elementAttributeTable)

if elementName=="nowplaying" then
-- Reset all work fields
currentElement=""
artist=""
title=""
artist_web=""
title_web=""

else
-- Remember which element this is
currentElement=elementName

end
end

-- Called when the end of an element is detected.
function OnElementEnd(elementName)
-- LogInfo("XML Parser Sample: OnElementEnd\n")
if elementName=="nowplaying" then

local display=artist_web
if artist_web=="" then
-- If the artist_web is blank then rerplace artist_web by artist
display=artist
end

local display_title=title_web
if display_title=="" then
-- If the title_web is blank then rerplace it by title
display_title=title
end

if display~="" then
-- If the display is not blank then add
-- a dash as a separator and the title
display=display .. " - " .. display_title
else
display=display_title
end

LogInfo("TractPlugin: SendInfo('",display,"','",url,"')\n")
SendMetaDataSong(display,url)
end
end

-- Called when character data (outside of element tags) is
-- parsed. Please note that this will include any spaces,
-- tab characters or new line characters used to format the
-- XML data.
--
-- NOTE: You do not need to define functions that are not used.
function OnCharacterData(ch)

local char=string.char(ch) -- Convert character number to letter

if currentElement=="TITLE" then
-- Append character to title variable
title=title .. char

elseif currentElement=="ARTIST" then
-- Append character to artist variable
artist=artist .. char

elseif currentElement=="ARTIST_WEB" then
-- Append character to artist_web variable
artist_web=artist_web .. char

elseif currentElement=="TITLE_WEB" then
-- Append character to title variable
title_web=title_web .. char
end
end

-- Called when an XML comment is detected. The comment string
-- contains the text of the comment.
--
-- NOTE: You do not need to define functions that are not used.
-- function OnComment(comment)
-- end

-- Marks the start of a CDATA section. Not used very often.
--
-- NOTE: You do not need to define functions that are not used.
-- function OnCdataStart()
-- end

-- Marks the start of a CDATA section. Not used very often.
--
-- NOTE: You do not need to define functions that are not used.
-- function OnCdataEnd()
-- end

-- NOTE: The line and character notification functions are
-- still called even for the XML parser. If you do not need
-- them, then just don't define them.
-- This function is called by the application each time a metadata
-- character is received.
function OnCharacterReceived(charNumber)
-- The lines below will echo the characters sent by the
-- metadata source back. This is useful when developing
-- the filter and for debugging. In this example, we
-- do nothing.
--
--local letter=string.char(charNumber) -- Convert character number to letter
--print(letter)
end
(2-2/5)
Add picture from clipboard (Maximum size: 742 MB)