Commits

sillyfrog committed 8716a15

Change the default file naming convention to include additional informaiton now available about the show

Comments (0)

Files changed (1)

python-iview/daily-scrape.py

 def getoutputpath(show):
     '''Given a show dict, return the path the final file should be saved to.
     '''
-    fn = validfilename(show['title'] + os.path.splitext(show['url'])[1])
+    title = show['title']
+    match = re.match('(.*) Episode (\d+) (.*)', title)
+    if not match:
+        print '*************************'
+        print 'Unknown title pattern: %r' % (title)
+        print 'show dict:', show
+        # Use old naming method
+        fn = show['title']
+    else:
+        seriesname, episodenum, episode = match.groups()
+        match = re.match(r'.*_\d{2}_(\d{2})_(\d{2})\..*', show['url'])
+        seriesnum, episodenum = match.groups()
+        fn = '%s - s%se%s - %s' % (show['seriestitle'], seriesnum, episodenum, episode)
+    fn = validfilename(fn + os.path.splitext(show['url'])[1])
     outputdir = os.path.join(BASE_OUTPUT_PATH, 
                     validfilename(show['seriestitle']))
     if not os.path.isdir(outputdir):
     os.chdir(sys.path[0])
     
     # Sleep time for first run, check last run time
-    sleeptime = 10 # Sleep for 10 seconds after startup to allow the PC to get a network connection
+    sleeptime = 5 # Sleep for 5 seconds after startup to allow the PC to get a network connection
     lastscrape = getlastrun()
     now = time.time()
     if (now - lastscrape) < RUN_FREQ: