Skip to content

Instantly share code, notes, and snippets.

@Ionshard
Created June 27, 2010 17:14
Show Gist options
  • Select an option

  • Save Ionshard/455024 to your computer and use it in GitHub Desktop.

Select an option

Save Ionshard/455024 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Eli Criffield
import os
import urllib2
import re
import sys
from BeautifulSoup import BeautifulSoup
from time import sleep
def fw(file,data):
fd = open(file,'w')
fd.write(data)
fd.close()
if len(sys.argv) > 1 and sys.argv[1] == '-l':
url='http://www.dogstarradio.com/now_playing.php'
urlfd = urllib2.urlopen(url)
soup = BeautifulSoup(urlfd.read())
urlfd.close()
for chan in range(1,200):
try:
stream = soup.find('div', {'id' : 'channel%s'%chan})['onclick']
except (TypeError, KeyError):
pass
else:
stream = re.search(r'listenLaunch\(\'(\w+)\',\'(\w+)\',\'(\w+)\',\'(.+)\'\);',stream).groups()[1]
stream = stream.rstrip().lstrip()
try:
os.symlink(str(chan),stream)
except OSError:
os.unlink(stream)
os.symlink(str(chan),stream)
print "ln -s %s %s"%(chan,stream) #DEBUG
url='http://www.DogstarRadio.com/tracker.txt'
while True:
urlfd = urllib2.urlopen(url)
firstLoop = True
for line in urlfd:
if firstLoop:
fw('lastupdate',line)
if line == '---\n' or firstLoop:
chan = urlfd.readline().rstrip()
longname = urlfd.readline().rstrip()
artist = urlfd.readline().rstrip()
track = urlfd.readline().rstrip()
cat = urlfd.readline().rstrip()
try:
os.mkdir(chan)
except OSError:
pass
longnameFile = os.path.join(chan,'longname')
artistFile = os.path.join(chan,'artist')
trackFile = os.path.join(chan,'track')
catFile = os.path.join(chan,'catagory')
artistTrackFile = os.path.join(chan,'artistTrack')
#print "%s %s-%s"%(longname,artist,track) #DEBUG
fw(longnameFile,longname)
fw(artistFile,artist)
fw(trackFile,track)
fw(catFile,cat)
fw(artistTrackFile,'%s-%s'%(artist,track))
firstLoop = False
urlfd.close()
sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment