1. hholcombe
  2. iviewautodownload

Commits

hholcombe  committed 90faddb

You know what's great about external dependencies that provide little benefit? Nothing.

Now uses ConfigParser for the settings instead of YAML.

Doesn't copy the metadata to the transcode path if not transcoding.

  • Participants
  • Parent commits 8355eec
  • Branches default

Comments (0)

Files changed (3)

File python-iview/daily_scrape.py

View file
 import re
 import urllib
 import shutil
-import yaml
+import ConfigParser
 
 import iview.config
 import iview.fetch
 import iview.comm
 
-SETTINGS_FILE = 'settings.yaml'
+SETTINGS_FILE = 'settings.ini'
+
+config = ConfigParser.ConfigParser()
 
 with open(SETTINGS_FILE, 'r') as f:
-    SETTINGS = yaml.load(f.read())
-
+    config.readfp(f)
 
 INVALID_FILENAME_CHARACTERS = r'\/:?*"<>|'
 SCREEN_WIDTH = 79
     '''Given a show dict, return the full path the file should be saved to.
     '''
     fn = showfilename(show) + os.path.splitext(show['url'])[1]
-    outputdir = os.path.join(SETTINGS['base_output_path'], showfolder(show))
+    outputdir = os.path.join(config.get('paths', 'base_output_path'), showfolder(show))
     if not os.path.isdir(outputdir):
         os.mkdir(outputdir)
     ret = os.path.join(outputdir, fn)
     if not show['thumb'] or show['thumb'] == '(none)':
         # Don't bother doing anything if there is no thumbnail
         return
-    outputdir = os.path.join(SETTINGS['base_output_path'], showfolder(show), 'metadata')
+    outputdir = os.path.join(config.get('paths', 'base_output_path'), showfolder(show), 'metadata')
     artfn = os.path.join(outputdir, showfilename(show) + '.jpg')
     print "Art path: %r" % (artfn)
     if os.path.isfile(artfn):
     urlf.close()
     outf.close()
 
-    # Copy to the TRANSCODED_OUTPUT_PATH
-    outputdir2 = os.path.join(SETTINGS['transcoded_output_path'], showfolder(show), 'metadata')
-    artfn2 = os.path.join(outputdir2, showfilename(show) + '.jpg')
-    if not os.path.isdir(outputdir2):
-        os.mkdir(outputdir2)
-    shutil.copy(artfn, artfn2)
+    if int(config.get('options', 'transcode')):
+        # Copy to the TRANSCODED_OUTPUT_PATH
+        outputdir2 = os.path.join(config.get('paths', 'transcoded_output_path'), showfolder(show), 'metadata')
+        artfn2 = os.path.join(outputdir2, showfilename(show) + '.jpg')
+        if not os.path.isdir(outputdir2):
+            os.mkdir(outputdir2)
+        shutil.copy(artfn, artfn2)
 
 def showfolder(show):
     '''
         seriestitle = seriesmatch.group(1).strip()
     return validfilename(seriestitle)
 
-def transode(show):
+def transcode(show):
     '''Called when a show download is complete.
     '''
     srcpath = show['filename']
 
-    outputdir = os.path.join(SETTINGS['transcoded_output_path'], showfolder(show))
+    outputdir = os.path.join(config.get('paths', 'transcoded_output_path'), showfolder(show))
     outputpath = os.path.join(
         outputdir,
         validfilename(os.path.basename(show['filename']))
         if success:
             DOWNLOADED.append(show['filename'])
             print "Successfully downloaded %s" % (show['title'])
-            if SETTINGS['transcode']:
+            if int(config.get('options', 'transcode')):
                 transcode(show)
         else:
             print "Error downloading."
 def savelastrun():
     '''Saves the last time of a complete run.
     '''
-    SETTINGS['last_scrape'] = time.time()
+    config.set('tracking', 'last_scrape', time.time())
     with open(SETTINGS_FILE, 'w') as f:
-        yaml.dump(SETTINGS, f)
+        config.write(f)
 
 def main():
     os.chdir(sys.path[0])
 
     # Sleep time for first run, check last run time
     sleeptime = 5 # Sleep for 5 seconds after startup to allow the PC to get a network connection
-    lastscrape = SETTINGS['last_scrape']
+    lastscrape = float(config.get('tracking', 'last_scrape'))
     now = time.time()
-    run_freq = SETTINGS['run_freq']
+    run_freq = int(config.get('options', 'run_freq'))
     if (now - lastscrape) < run_freq:
         sleeptime = lastscrape + run_freq - now
     print now, sleeptime, lastscrape
         time.sleep(sleeptime)
 
         # Get the show list we want to watch...
-        srclist = SETTINGS['show_list']
+        srclist = config.get('shows', 'showlist')
+        srclist = [show.strip() for show in srclist.split(';')]
 
         # Init the lib
         iview.comm.get_config()
             for show in DOWNLOADED:
                 print "    %s" % (show)
 
-        if SETTINGS['run_once']:
+        if int(config.get('options', 'run_once')):
             break
 
 def test():
  'videocodecid': 'avc1',
  'videoframerate': '25.00',
  'width': '640.00'}
-    postdownload(sampleshow)
+    transcode(sampleshow)
 
 
 if __name__ == '__main__':

File python-iview/settings.ini

View file
+# Remember, 0 is False, 1 is True
+
+[paths]
+base_output_path = C:\base\path
+transcoded_output_path = C:\transcoded\path
+
+[options]
+# Number of seconds in between runs. If RUN_ONCE is True, the most frequently it will run.
+run_freq = 28800 # 8 hours
+# If True (1), will only run once then exit
+run_once = 1
+# Whether to transcode or not
+transcode = 0
+
+[tracking]
+# Unix time of last run
+last_scrape = 1315716353.11
+
+[shows]
+# Uses the python fnmatch module - which allows matching using "?" and "*" like a DOS or shell command line
+# This is NOT case sensitive
+showlist = Play School*;
+	*Octonauts*;
+    Bob the builder*;
+

File python-iview/settings.yaml

-base_output_path: C:\base\path
-transcoded_output_path: C:\transcoded\path
-# Frequency to run - every 8 hours. If RUN_ONCE is True, the most frequently it will run.
-run_freq: 8 * 60 *60
-# If True, will only run once then exit
-run_once: True
-# Unix time of last run
-last_run: 0
-# Whether to transcode or not
-transcode: True
-
-# Uses the python fnmatch module - which allows matching using "?" and "*" like a DOS or shell command line
-# this is NOT case sensitive
-show_list:
-- 'Mister maker*'
-- 'Play School*'
-- 'Peppa Pig*'
-- 'Bob the Builder*'
-- '*Octonauts*'