From 774e662c87569471a56c90c9bddfb909fa3a0f59 Mon Sep 17 00:00:00 2001 From: Nevar Angelo Date: Fri, 5 Nov 2010 14:06:21 +0200 Subject: [PATCH 1/2] Allow comments in batch file --- youtube-dl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube-dl b/youtube-dl index b099ffd15..24cc454a8 100644 --- a/youtube-dl +++ b/youtube-dl @@ -2212,7 +2212,7 @@ if __name__ == '__main__': batchfd = open(opts.batchfile, 'r') batchurls = batchfd.readlines() batchurls = [x.strip() for x in batchurls] - batchurls = [x for x in batchurls if len(x) > 0] + batchurls = [x for x in batchurls if len(x) > 0 and not re.search(r'^[#/;]', x)] except IOError: sys.exit(u'ERROR: batch file could not be read') all_urls = batchurls + args From e1d8dc153a13b59d271f0f070d8ee07aeafaecc6 Mon Sep 17 00:00:00 2001 From: Nevar Angelo Date: Fri, 5 Nov 2010 14:30:40 +0200 Subject: [PATCH 2/2] Added option --auto-number This allows for numbering URLs to preserve download order. eg. Will preserve order of playlist items. eg. Will preserve order of URLs in file specified by -a or --batch-file. --- youtube-dl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/youtube-dl b/youtube-dl index 24cc454a8..e1d5141b8 100644 --- a/youtube-dl +++ b/youtube-dl @@ -214,6 +214,7 @@ class FileDownloader(object): _download_retcode = None _num_downloads = None _screen_file = None + _auto_number = None def __init__(self, params): """Create a FileDownloader object with the given options.""" @@ -222,6 +223,7 @@ class FileDownloader(object): self._download_retcode = 0 self._num_downloads = 0 self._screen_file = [sys.stdout, sys.stderr][params.get('logtostderr', False)] + self._auto_number = 1 self.params = params @staticmethod @@ -414,6 +416,8 @@ class FileDownloader(object): template_dict = dict(info_dict) template_dict['epoch'] = unicode(long(time.time())) template_dict['ord'] = unicode('%05d' % self._num_downloads) + template_dict['autonumber'] = '%03d' % self._auto_number + self._auto_number += 1 filename = self.params['outtmpl'] % template_dict except (ValueError, KeyError), err: self.trouble(u'ERROR: invalid system charset or erroneous output template') @@ -2171,6 +2175,8 @@ if __name__ == '__main__': action='store_true', dest='usetitle', help='use title in file name', default=False) filesystem.add_option('-l', '--literal', action='store_true', dest='useliteral', help='use literal title in file name', default=False) + filesystem.add_option('-A', '--auto-number', + action='store_true', dest='autonumber', help='number downloaded URLs starting from 001', default=False) filesystem.add_option('-o', '--output', dest='outtmpl', metavar='TEMPLATE', help='output filename template') filesystem.add_option('-a', '--batch-file', @@ -2224,8 +2230,8 @@ if __name__ == '__main__': parser.error(u'using .netrc conflicts with giving username/password') if opts.password is not None and opts.username is None: parser.error(u'account username missing') - if opts.outtmpl is not None and (opts.useliteral or opts.usetitle): - parser.error(u'using output template conflicts with using title or literal title') + if opts.outtmpl is not None and (opts.useliteral or opts.usetitle or opts.autonumber): + parser.error(u'using output template conflicts with using title, literal title or auto number') if opts.usetitle and opts.useliteral: parser.error(u'using title conflicts with using literal title') if opts.username is not None and opts.password is None: @@ -2284,8 +2290,11 @@ if __name__ == '__main__': or (opts.format == '-1' and opts.usetitle and u'%(stitle)s-%(id)s-%(format)s.%(ext)s') or (opts.format == '-1' and opts.useliteral and u'%(title)s-%(id)s-%(format)s.%(ext)s') or (opts.format == '-1' and u'%(id)s-%(format)s.%(ext)s') + or (opts.usetitle and opts.autonumber and u'%(autonumber)s-%(stitle)s-%(id)s.%(ext)s') + or (opts.useliteral and opts.autonumber and u'%(autonumber)s-%(title)s-%(id)s.%(ext)s') or (opts.usetitle and u'%(stitle)s-%(id)s.%(ext)s') or (opts.useliteral and u'%(title)s-%(id)s.%(ext)s') + or (opts.autonumber and u'%(autonumber)s-%(id)s.%(ext)s') or u'%(id)s.%(ext)s'), 'ignoreerrors': opts.ignoreerrors, 'ratelimit': opts.ratelimit,