def test_get_filepaths(): assert list(get_filepaths(TEST_FILEPATHS)) == TEST_FILEPATHS assert list(get_filepaths([TEST_DIR])) == TEST_FILEPATHS assert list(get_filepaths([str(TEST_DIR)])) == TEST_FILEPATHS assert list(get_filepaths(TEST_DIR / 'test_file.1')) == [TEST_DIR / 'test_file.1'] assert list(get_filepaths(TEST_FILEPATHS, exclude_paths=['test_file'])) == [] assert list(get_filepaths(TEST_FILEPATHS, exclude_regexes=['test_.*'])) == [] assert list(get_filepaths(TEST_DIR, exclude_paths=['test_file'])) == [] assert list(get_filepaths(TEST_DIR, exclude_regexes=['test_.*'])) == [] assert list(get_filepaths(TEST_DIR, exclude_globs=['test_*.*'])) == []
def get_local_songs(paths, *, filters=None, max_depth=math.inf, exclude_paths=None, exclude_regexes=None, exclude_globs=None): logger.log('NORMAL', "Loading local songs") local_songs = [ filepath for filepath in get_filepaths(paths, max_depth=max_depth, exclude_paths=exclude_paths, exclude_regexes=exclude_regexes, exclude_globs=exclude_globs) if audio_metadata.determine_format(filepath) in [ audio_metadata.FLAC, audio_metadata.MP3, audio_metadata.OggOpus, audio_metadata.OggVorbis, audio_metadata.WAVE, ] ] logger.info("Found {} local songs", len(local_songs)) matched_songs = filter_metadata(local_songs, filters) return matched_songs
def do_create(args): torrent_info = SortedDict() filepaths = get_filepaths( args.input, max_depth=args.max_depth, exclude_paths=args.exclude_paths, exclude_regexes=args.exclude_regexes, exclude_globs=args.exclude_globs ) creation_dates = [ args[option] for option in [ 'created_in', 'created_on', 'created_before', 'created_after', ] if option in args ] modification_dates = [ args[option] for option in [ 'modified_in', 'modified_on', 'modified_before', 'modified_after', ] if option in args ] filepaths = filter_filepaths_by_dates( filepaths, creation_dates=creation_dates, modification_dates=modification_dates, ) filepaths = list(filepaths) if not filepaths: sys.exit("\nNo files matching criteria found.") data_size = calculate_data_size(filepaths) piece_size = calculate_piece_size(data_size, threshold=args.piece_threshold) if not args.trackers: private = False else: private = args.private if args.input.is_dir(): info_dict = create_dir_info_dict( args.input, filepaths, data_size, piece_size, private, args.source, args.md5, show_progress=args.show_progress, ) elif args.input.is_file(): info_dict = create_file_info_dict( filepaths, data_size, piece_size, private, args.source, args.md5, show_progress=args.show_progress, ) torrent_info['info'] = info_dict if args.trackers: torrent_info['announce'] = args.trackers[0][0] if len(args.trackers) > 1 or len(args.trackers[0]) > 1: torrent_info['announce-list'] = args.trackers if args.created_by is not None: torrent_info['created by'] = args.created_by if args.comment is not None: torrent_info['comment'] = args.comment torrent_info['creation date'] = pendulum.now('utc').int_timestamp torrent_info['encoding'] = 'UTF-8' write_torrent_file(args.output, torrent_info) outputs = generate_summary_outputs(torrent_info, show_files=args.show_files) render(outputs)