#!/usr/bin/env python import sys, os, pprint, re, urllib if __name__ == '__main__': if len (sys.argv) > 1 and sys.argv[1] == 'colbert': show_id = 18252 else: show_id = 934 shows = {} statusfile = os.path.expanduser ("~/.dailyshow") try: shows.update (eval (file (statusfile).read ())) except: pass base = "http://www.comedycentral.com/sitewide/media_player/" ds = urllib.urlopen (base + "browseresults.jhtml?showId=%d"%show_id).read () clips = re.findall ("(?ims)]*class=\"results_desc\">.*?", ds) clips.reverse () try: count = 0; for i in clips: m = re.search ("(?ims)href=\"(play\.jhtml\?itemId=[0-9]+)\">([^<]*) --([^<]+)", i) if m: url = base + m.group (1) title = m.group (2).strip () desc = m.group (3).strip () if url not in shows.keys (): vidpage = urllib.urlopen (url).read () mov = re.search ("(?ims)]*?src=\"([^?\"]+\?)[^\"].*?(clip=[^\"&]+)[^\"]*\"", vidpage) if mov: mov = mov.group (1) + mov.group (2) shows[url] = (title, desc, mov, show_id) print title print desc print mov print os.system ("mplayer -fs -cache 3000 -playlist %s" % mov) print print title print desc print mov # continue count += 1 if count >= 1: break os.system ("mv -f %s %s~" % (statusfile, statusfile)) f = file (statusfile, "w") f.write (pprint.pformat (shows)) f.close () except KeyboardInterrupt: pass