-
-
Save futurisupport/0df0fa3cd74b4512f1d6506118790821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import clr | |
clr.AddReference('System.Net') | |
clr.AddReference('System.Xml') | |
clr.AddReference('System.Web') | |
clr.AddReference('System.Windows.Forms') | |
from System import * | |
from System.Xml import * | |
from System.Net import * | |
from System.IO import * | |
from System.Text import * | |
from System.Collections.Generic import * | |
from System.Environment import * | |
from System.Threading import * | |
# Important! Set this location to where you have configured the CrowdControl Downloader to use as its File Location | |
file = "C:\\audiovau\\CrowdControl\\ccDownload.txt" | |
lines = Array[str](['']) | |
fileLastRead = DateTime.UtcNow.AddSeconds(-3) | |
def GetSong(slot=0): | |
try: | |
return lines[slot] | |
except Exception, e: | |
print 'CrowdControl: Exception in GetSong ' + e.Message | |
return '' | |
def ReadFile(): | |
global lines | |
global fileLastRead | |
#don't bother to read if it was read too recently | |
if fileLastRead > DateTime.UtcNow.AddSeconds(-2): #don't read it too often | |
return | |
print 'CrowdControl: Reading CC file' | |
lines = File.ReadAllLines(file) | |
fileLastRead = DateTime.UtcNow | |
print 'CrowdControl: Printing file contents...' | |
for l in lines: | |
print '\t' + l | |
def GetCCSongForSlot(item): | |
print 'CrowdControl: GetCCSongForSlot' | |
#attempt to read the file | |
try: | |
ReadFile() | |
except: | |
print 'CrowdControl: Exception reading CC file' | |
#look backwards from the passed-in ID. | |
try: | |
evalItem = None | |
if item != None: | |
evalItem = item.PreviousItem | |
if evalItem == None: | |
print 'CrowdControl: PreviousItem is null' | |
print 'CrowdControl: Working on ' + item.Id.ToString() | |
if evalItem != None: | |
slotsFoundBeforeNow = 0 | |
count = 0 | |
while count < 20: | |
count = count + 1 | |
#keep looking past groups, non-scripts, and non-play events | |
if evalItem.HasChildren or (not evalItem.Name.Contains('{ccSlot}')) or (not evalItem.IsPlayEvent): | |
evalItem = evalItem.PreviousItem | |
continue | |
#we stop if we find something that's completed or running | |
if evalItem.IsPlaying or evalItem.IsDone: | |
break | |
slotsFoundBeforeNow = slotsFoundBeforeNow + 1 | |
evalItem = evalItem.PreviousItem | |
song = GetSong(slotsFoundBeforeNow) | |
print 'CrowdControl: Song for slot ' + slotsFoundBeforeNow.ToString() + ' (' + item.Id.ToString() + ') is ' + song | |
return song | |
except Exception, e: | |
print 'CrowdControl: Exception in GetCCSongForSlot ' + e.StackTrace + ' and message is ' + e.Message | |
def ccSlot(): | |
return GetCCSongForSlot(ScheduleItem) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment