'////////////////////////////////////////////////////////////////////////
'// BTJUNKIE SCRIPT FOR 9.4
'// WRITTEN BY: Chriso
'// Return the latest feeds from BTJunkie.org
'////////////////////////////////////////////////////////////////////////

'// Return Script Information
Sub Script(Name, Major, Minor, Build, Author, Commands, Description)
	Name = "BTJunkie Script"
	Major = 1
	Minor = 1
	Build = 0
	Author = "Chriso"
	Commands = "btaudio, btanime, btgames, btsoftware, bttv, btunsorted, btvideo"
	Description = "Return the latest feeds from btjunkie.org"
End Sub

'// Called when the script is loaded for a particular bot
Sub Event_Load()
	CreateCommand "btall", "BTJunkie", "Command_BT", "", "[limit]", "Return the latest audio feeds from btjunkie.org", 1, True
	CreateCommand "btaudio", "BTJunkie", "Command_BT", "", "[limit]", "Return the latest audio feeds from btjunkie.org", 1, True
	CreateCommand "btanime", "BTJunkie", "Command_BT", "", "[limit]", "Return the latest anime feeds from btjunkie.org", 1, True
	CreateCommand "btgames", "BTJunkie", "Command_BT", "", "[limit]", "Return the latest game feeds from btjunkie.org", 1, True
	CreateCommand "btsoftware", "BTJunkie", "Command_BT", "", "[limit]", "Return the latest software feeds from btjunkie.org", 1, True
	CreateCommand "bttv", "BTJunkie", "Command_BT", "", "[limit]", "Return the latest TV feeds from btjunkie.org", 1, True
	CreateCommand "btunsorted", "BTJunkie", "Command_BT", "", "[limit]", "Return the latest unsorted feeds from btjunkie.org", 1, True
	CreateCommand "btvideo", "BTJunkie", "Command_BT", "", "[limit]", "Return the latest video feeds from btjunkie.org", 1, True
End Sub

'// Callback for all btjunkie commands
Sub Command_BT(CS)
	Dim xmlCat, xmlCatName, Total
	Total = 0
	xmlCat = 0
	xmlCatName = "ALL"
	If Len(CS.Message) Then Total = CInt(CS.Message)
	If Total = 0 Then Total = 999999
	Select Case LCase(CS.Command)
	Case "btall"
		xmlCat = 0
		xmlCatName = "ALL"
	Case "btaudio"
		xmlCat = 1
		xmlCatName = "AUDIO"
	Case "btanime"
		xmlCat = 7
		xmlCatName = "ANIME"
	Case "btgames"
		xmlCat = 2
		xmlCatName = "GAMES"
	Case "btsoftware"
		xmlCat = 3
		xmlCatName = "SOFTWARE"
	Case "bttv"
		xmlCat = 4
		xmlCatName = "TV SHOWS"
	Case "btunsorted"
		xmlCat = 5
		xmlCatName = "UNSORTED"
	Case "btvideo"
		xmlCat = 6
		xmlCatName = "VIDEO"
	End Select
	
	If scInet.StillExecuting Then
		AddChat vbRed, "Still executing last request..."
	Else
		Dim XML, F, C
		C = 1
		XML = scInet.OpenURL("http://btjunkie.org/rss.xml?c=" & xmlCat)
		F = InStr(XML, "<item>")
		AddChat &H808080, "-----------------------------------------------------------------------------"
		AddChat &H808080, "LATEST RSS FEEDS FROM BTJUNKIE - CATEGORY: " & xmlCatName
		AddChat &H808080, "-----------------------------------------------------------------------------"
		
		Do Until F = 0 Or C > Total
			XML = Mid(XML, F + 6)
			C = C + 1
			Dim Feed, Title, Link, PubDate
			Feed = Split(XML, "</item>")(0)
			Title = Split(Feed, "<title>")(1)
			Title = Split(Title, "</title>")(0)
			Link = Split(Feed, "<link>")(1)
			Link = Split(Link, "</link>")(0)
			PubDate = Split(Feed, "<pubDate>")(1)
			PubDate = Split(PubDate, "</pubDate>")(0)
			
			AddChat &H00AB7424&, "<b>" & Title & "</b>"
			AddChat vbWhite, "- <b>Published: </b>" & PubDate
			AddChat vbWhite, "- <b>Download:</b> " & Link 
			AddChat vbWhite, ""
			
			F = InStr(XML, "<item>")
		Loop
	End If 
End Sub