Skip to content

Commit

Permalink
Merge pull request #12 from navicore/bypass_patterns_fix_file_too_long
Browse files Browse the repository at this point in the history
Bypass patterns fix file too long
  • Loading branch information
meeb committed Oct 18, 2023
2 parents 6b70c92 + 9e2ecb8 commit e35d4a7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ another format with the `--format` argument. Common Bandcamp download formats ar
| `alac` | Apple lossless format. Large file sizes. Original quality. |
| `wav` | Uncompressed audio format. Biggest file size. Original quality. |

You can also use `-i` or `--ignore` to bypass artists that have data issues that
your OS can not handle.

```bash
$ bandcampsync --cookies cookies.txt --directory /path/to/music --ignore "badband"
```

# Contributing

Expand Down
13 changes: 12 additions & 1 deletion bandcampsync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@
log = logger.get_logger('sync')


def do_sync(cookies_path, cookies, dir_path, media_format, temp_dir_root):
def do_sync(cookies_path, cookies, dir_path, media_format, temp_dir_root, ign_patterns):
local_media = LocalMedia(media_dir=dir_path)
bandcamp = Bandcamp(cookies=cookies)
bandcamp.verify_authentication()
bandcamp.load_purchases()
for item in bandcamp.purchases:

# Check if any ignore pattern matches the band name
ignored = False
for pattern in ign_patterns.split():
if pattern.lower() in item.band_name.lower():
log.warning(f'Skipping item due to ignore pattern: "{pattern}" found in "{item.band_name}"')
ignored = True
break
if ignored:
continue

local_path = local_media.get_path_for_purchase(item)
if local_media.is_locally_downloaded(item, local_path):
log.info(f'Already locally downloaded, skipping: "{item.band_name} / {item.item_title}" '
Expand Down
10 changes: 8 additions & 2 deletions bin/bandcampsync
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,27 @@ if __name__ == '__main__':
help='Path to the cookies file')
parser.add_argument('-d', '--directory', required=True,
help='Path to the directory to download media to')
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=None,
parser.add_argument('-t', '--temp-dir', default='',
help='Path to use for temporary downloads')
args = parser.parse_args()
if args.version:
print(f'BandcampSync version: {version}', file=sys.stdout)
sys.exit(0)
cookies_path = Path(args.cookies).resolve()
dir_path = Path(args.directory).resolve()
ign_patterns = args.ignore
media_format = args.format
if not cookies_path.is_file():
raise ValueError(f'Cookies file does not exist: {cookies_path}')
if not dir_path.is_dir():
raise ValueError(f'Directory does not exist: {dir_path}')
if args.ignore:
patterns = args.ignore
log.warning(f'BandcampSync is bypassing: {patterns}')
if args.temp_dir:
temp_dir = Path(args.temp_dir).resolve()
if not temp_dir.is_dir():
Expand All @@ -46,5 +52,5 @@ if __name__ == '__main__':
with open(cookies_path, 'rt') as f:
cookies = f.read().strip()
log.info(f'Loaded cookies from "{cookies_path}"')
do_sync(cookies_path, cookies, dir_path, media_format, temp_dir)
do_sync(cookies_path, cookies, dir_path, media_format, temp_dir, ign_patterns)
log.info(f'Done')
5 changes: 3 additions & 2 deletions bin/bandcampsync-service
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CatchShutdownSignal:
self.shutdown = False
signal.signal(signal.SIGINT, self.got_exit_signal)
signal.signal(signal.SIGTERM, self.got_exit_signal)

def got_exit_signal(self, *args, **kwargs):
self.shutdown = True

Expand All @@ -30,6 +30,7 @@ if __name__ == '__main__':
cookies_path_env = os.getenv('COOKIES_FILE', '/config/cookies.txt')
dir_path_env = os.getenv('DIRECTORY', '/downloads')
media_format_env = os.getenv('FORMAT', 'flac')
ign_patterns = os.getenv('IGNORE', '')
run_daily_at_env = os.getenv('RUN_DAILY_AT', '3')
exit_after_run_env = os.getenv('EXIT_AFTER_RUN', '0')
temp_dir_env = os.getenv('TEMP_DIR', '')
Expand Down Expand Up @@ -71,7 +72,7 @@ if __name__ == '__main__':
try:
while not catch_shutdown.shutdown:
log.info(f'Starting synchronisation')
do_sync(cookies_path, cookies, dir_path, media_format_env, temp_dir)
do_sync(cookies_path, cookies, dir_path, media_format_env, temp_dir, ign_patterns)
random_delay = randrange(0, 3600)
time_now = datetime.now(tz).replace(microsecond=0)
time_tomorrow = time_now + timedelta(days=1)
Expand Down

0 comments on commit e35d4a7

Please sign in to comment.