diff --git a/zeit-dl b/zeit-dl index 4047d20..8225f0e 100755 --- a/zeit-dl +++ b/zeit-dl @@ -2,6 +2,7 @@ import os import re +from datetime import datetime import argparse from playwright.sync_api import sync_playwright @@ -18,6 +19,7 @@ def main(): parser.add_argument('-i', '--issue', type=str, help='Ausgabe (meistens DD.MM.YYYY)') parser.add_argument('-t', '--type', type=str, choices=['pdf', 'epub', 'mp3'], default='pdf', help='Dateiformat') parser.add_argument('-f', '--force', action='store_true', help='Redownload file even if already present') + parser.add_argument('--format', type=str, default="{abo}_{issue}.{ext}", help='Filename format') args = parser.parse_args() if args.user is None or args.pwd is None: parser.error('You need to supply a username and password') @@ -55,7 +57,14 @@ def download(page, args): page.goto(EPAPER+'/abo/'+args.abo+'/'+args.issue) issue = args.issue - filename = '{}-{}.{}'.format(args.abo, issue, args.type) + try: + published = datetime.strptime(issue, '%d.%m.%Y') + except ValueError: + published = None + filename = args.format.format(abo=args.abo, issue=issue, ext=args.type) + if published is not None: + filename = published.strftime(filename) + filepath = os.path.join(args.out, filename) if os.path.isfile(filepath): print('Issue already exists:', filepath)