Bladeren bron

Use `MD_QUALITY` to specify the minimal allowed quality to download without confirmation

Deben Oldert 6 jaren geleden
bovenliggende
commit
71f08bd0e8
3 gewijzigde bestanden met toevoegingen van 22 en 6 verwijderingen
  1. 10 0
      main.py
  2. 8 3
      settings.py
  3. 4 3
      sites/helper/download.py

+ 10 - 0
main.py

@@ -16,6 +16,8 @@ def init():
 
     directory(os.getenv('MD_SAVEDIR', '~/Music/iTunes/iTunes Media/Automatically Add to iTunes'))
 
+    quality(os.getenv('MD_QUALITY', '300'))
+
 
 def main():
     init()
@@ -131,6 +133,14 @@ def directory(dir=None):
     return True
 
 
+def quality(quality=None):
+    if quality is None:
+        quality = console.ask_input('Enter minimal quality for auto download')
+    Settings.MinQuality = int(quality)
+    console.output('Minimal quality for auto downloading is set to {0}'.format(Settings.MinQuality), level=console.DBG_INFO)
+    return True
+
+
 def last(items=None):
     global search_cache
     if items is not None:

+ 8 - 3
settings.py

@@ -1,7 +1,12 @@
-import console as console
-
-
 class Settings:
+    # Directory to permanently save the file (ENV: MD_SAVEDIR)
     SaveDir = None
+
+    # Directory to temporary download the file (ENV: MD_TMP)
     tmpDir = '/tmp'
+
+    # Minimal debug level (ENV: MD_LOGGING)
     Debuglvl = None
+
+    # Minimal bitrate to auto download the file (ENV: MD_QUALITY)
+    MinQuality = 300

+ 4 - 3
sites/helper/download.py

@@ -50,10 +50,11 @@ def download(item, type='GET', parameters=None, headers=None, cookies=None, stre
 
                 console.output('Bitrate: {0}kbps'.format(int(item.bitrate)))
 
-            ans = console.ask_input('Continue downloading? [y/n]')
+            if int(item.bitrate) < Settings.MinQuality:
+                ans = console.ask_input('Continue downloading? [y/n]')
 
-            if ans != 'y':
-                return
+                if ans != 'y':
+                    return
 
     savefileprogress(name, full_name, file, item)