Added --format

This commit is contained in:
Leon Haag-Fank 2024-04-04 16:59:25 +02:00
parent 9254afe406
commit 2bf591363e

11
zeit-dl
View file

@ -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)