-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsync_runner.py
More file actions
90 lines (72 loc) · 2.92 KB
/
Copy pathsync_runner.py
File metadata and controls
90 lines (72 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
"""
Container-friendly bandcampsync runner.
Takes cookies as a direct string argument (no temp files needed).
bandcampsync uses curl_cffi directly for TLS fingerprinting.
"""
import sys
import argparse
from pathlib import Path
from bandcampsync import version, do_sync
from bandcampsync.options import BandcampSyncOptions
from bandcampsync.logger import get_logger
log = get_logger('sync_runner')
def main():
parser = argparse.ArgumentParser(
prog='sync_runner',
description='Container-friendly bandcampsync runner that accepts cookies directly',
)
parser.add_argument('-v', '--version', action='store_true',
help='Displays the bandcampsync version and exits')
parser.add_argument('-C', '--cookies-string', required=True,
help='Cookies string directly (not a file path)')
parser.add_argument('-d', '--directory', required=True,
help='Path to the directory to download media to')
parser.add_argument('-I', '--ignore-file', default='',
help='Path to the ignore file')
parser.add_argument('-i', '--ignore', default='',
help='A space-delimited list of patterns matching artists to bypass')
parser.add_argument('-f', '--format', default='flac',
help='Media format to download, defaults to "flac"')
parser.add_argument('-t', '--temp-dir', default='',
help='Path to use for temporary downloads')
parser.add_argument('-n', '--notify-url', default='',
help='URL to notify with a GET request when any new downloads have completed')
args = parser.parse_args()
if args.version:
print(f'BandcampSync version: {version}', file=sys.stdout)
sys.exit(0)
cookies = args.cookies_string
dir_path = Path(args.directory).resolve()
ign_file_path = Path(args.ignore_file).resolve() if args.ignore_file else None
ign_patterns = args.ignore
media_format = args.format
if not dir_path.is_dir():
raise ValueError(f'Directory does not exist: {dir_path}')
if args.ignore:
log.warning(f'BandcampSync is bypassing: {ign_patterns}')
if args.temp_dir:
temp_dir = Path(args.temp_dir).resolve()
if not temp_dir.is_dir():
raise ValueError(f'Temporary directory does not exist: {temp_dir}')
else:
temp_dir = None
if args.notify_url:
notify_url = args.notify_url
log.info(f'BandcampSync will notify: {notify_url}')
else:
notify_url = None
log.info(f'BandcampSync v{version} starting (container mode)')
log.info(f'Cookies loaded from command line argument')
do_sync(BandcampSyncOptions(
cookies=cookies,
dir_path=dir_path,
media_format=media_format,
temp_dir_root=temp_dir,
ign_file_path=ign_file_path,
ign_patterns=ign_patterns,
notify_url=notify_url,
))
log.info('Done')
if __name__ == '__main__':
main()