1
0
Fork 0
mirror of https://github.com/mwalbeck/podfox.git synced 2025-04-14 01:59:04 +00:00

rollback to split threading into separate dev branch from config settings

This commit is contained in:
Christopher Martin 2015-11-08 16:23:07 -06:00
parent 636971f2fe
commit eca11139e6

View file

@ -11,7 +11,7 @@ Usage:
podfox.py rename <shortname> <newname> [-c=<path>] podfox.py rename <shortname> <newname> [-c=<path>]
Options: Options:
-c --config=<path> Specify an alternate config file [default: ~/.podfox.json] -c --config=<path> Specify an alternate config file [default: ~/.podfox.json ]
-h --help Show this help -h --help Show this help
""" """
# (C) 2015 Bastian Reitemeier # (C) 2015 Bastian Reitemeier
@ -21,7 +21,6 @@ from colorama import Fore, Back, Style
from docopt import docopt from docopt import docopt
from os.path import expanduser from os.path import expanduser
from sys import exit from sys import exit
from threading import Thread, active_count
import colorama import colorama
import feedparser import feedparser
import json import json
@ -183,42 +182,17 @@ def episodes_from_feed(d):
def download_multiple(feed, maxnum): def download_multiple(feed, maxnum):
if "maxthreads" in CONFIGURATION.keys():
maxthreads = CONFIGURATION['maxthreads']
else:
maxthreads = maxnum
for episode in feed['episodes']: for episode in feed['episodes']:
if maxnum == 0: if maxnum == 0:
break break
if not episode['downloaded']: if not episode['downloaded']:
#TODO: multithreading #TODO: multithreading
downloadthread = download_thread(feed['shortname'], episode['url']) download_single(feed['shortname'], episode['url'])
downloadthread.start()
#download_single(feed['shortname'], episode['url'])
episode['downloaded'] = True episode['downloaded'] = True
maxnum -= 1 maxnum -= 1
while active_count() > maxthreads:
try:
downloadthread.join(60)
except RuntimeError:
pass
overwrite_config(feed) overwrite_config(feed)
class download_thread(Thread):
def __init__(self, folder, url):
Thread.__init__(self)
self.folder = folder
self.url = url
self.daemon = True
def run(self):
download_single(self.folder, self.url)
def download_single(folder, url): def download_single(folder, url):
base = CONFIGURATION['podcast-directory'] base = CONFIGURATION['podcast-directory']
filename = url.split('/')[-1] filename = url.split('/')[-1]
@ -232,7 +206,7 @@ def download_single(folder, url):
c.setopt(c.FOLLOWLOCATION, True) c.setopt(c.FOLLOWLOCATION, True)
c.perform() c.perform()
c.close() c.close()
print("{:s} done.".format(filename)) print("done.")
def available_feeds(): def available_feeds():
@ -300,6 +274,7 @@ if __name__ == '__main__':
arguments = docopt(__doc__, version='p0d 0.01') arguments = docopt(__doc__, version='p0d 0.01')
# before we do anything with the commands, # before we do anything with the commands,
# find the configuration file # find the configuration file
configfile = expanduser(arguments["--config"]) configfile = expanduser(arguments["--config"])
with open(configfile) as conf_file: with open(configfile) as conf_file: