def edit_metadata(path, tags, metadata, source, rls_data, recompress): """ The metadata editing portion of the uploading process. This sticks the user into an infinite loop where the metadata process is repeated until the user decides it is ready for upload. """ while True: metadata = review_metadata(metadata, metadata_validator) tag_files(path, tags, metadata) tags = check_tags(path) if recompress: recompress_path(path) path = rename_folder(path, metadata) rename_files(path, tags, metadata, source) check_folder_structure(path) if click.confirm( click.style( "\nWould you like to upload the torrent? (No to re-run metadata " "section)", fg="magenta", bold=True, ), default=True, ): metadata["tags"] = convert_genres(metadata["genres"]) break # Refresh tags to accomodate differences in file structure. tags = gather_tags(path) tags = gather_tags(path) audio_info = gather_audio_info(path) return path, metadata, tags, audio_info
def specs(path, no_delete_specs, format_output): """Generate and open spectrals for a folder""" audio_info = gather_audio_info(path) _, sids = check_spectrals(path, audio_info, check_lma=False) spath = os.path.join(path, "Spectrals") spectral_urls = handle_spectrals_upload_and_deletion( spath, sids, delete_spectrals=not no_delete_specs) filenames = list(audio_info.keys()) if spectral_urls: output = [] for spec_id, urls in spectral_urls.items(): if format_output: output.append( f'[hide={filenames[spec_id]}][img={"][img=".join(urls)}][/hide]' ) else: output.append(f'{filenames[spec_id]}: {" ".join(urls)}') output = "\n".join(output) click.secho(output) if config.COPY_UPLOADED_URL_TO_CLIPBOARD: pyperclip.copy(output) if no_delete_specs: click.secho(f'Spectrals saved to {os.path.join(path, "Spectrals")}', fg="green")
def _determine_files_actions(path): convert_files = [] copy_files = [os.path.join(r, f) for r, _, files in os.walk(path) for f in files] audio_info = gather_audio_info(path) for figle in copy(copy_files): for info_figle, figle_info in audio_info.items(): if figle.endswith(info_figle) and figle_info["precision"] == 24: convert_files.append((figle, figle_info["sample rate"])) copy_files.remove(figle) return convert_files, copy_files
def checkspecs(tracker, torrent_id, path): """Will check the spectrals of a given torrent based on local files.\n By default checks the folder the script is run from. Can add spectrals to a torrent description and report a torrent as lossy web. """ if not torrent_id: click.secho("No torrent id provided.", fg="red") torrent_id = click.prompt( click.style( """Input a torrent id or a URL containing one. Tracker in a URL will override -t flag.""", fg="magenta", bold=True, ), ) if "/torrents.php" in torrent_id: base_url = parse.urlparse(torrent_id).netloc if base_url in salmon.trackers.tracker_url_code_map.keys(): # this will overide -t tracker tracker = salmon.trackers.tracker_url_code_map[base_url] else: click.echo('Unrecognised tracker!') raise click.Abort torrent_id = int( parse.parse_qs(parse.urlparse(torrent_id).query)['torrentid'][0]) elif torrent_id.strip().isdigit(): torrent_id = int(torrent_id) else: click.echo('Not a valid torrent!') raise click.Abort tracker = salmon.trackers.validate_tracker(None, 'tracker', tracker) gazelle_site = salmon.trackers.get_class(tracker)() req = loop.run_until_complete( gazelle_site.request("torrent", id=torrent_id)) path = os.path.join(path, html.unescape(req['torrent']['filePath'])) source_url = None source = req['torrent']['media'] click.echo(f"Generating spectrals for {source} sourced: {path}") track_data = gather_audio_info(path) post_upload_spectral_check(gazelle_site, path, torrent_id, None, track_data, source, source_url)
def tag(path, source, encoding, overwrite): """Interactively tag an album""" click.secho(f"\nProcessing {path}", fg="cyan", bold=True) standardize_tags(path) tags = gather_tags(path) audio_info = gather_audio_info(path) rls_data = construct_rls_data(tags, audio_info, source, encoding, overwrite=overwrite) metadata = get_metadata(path, tags, rls_data) metadata = review_metadata(metadata, metadata_validator_base) tag_files(path, tags, metadata) download_cover_if_nonexistent(path, metadata["cover"]) tags = check_tags(path) path = rename_folder(path, metadata) rename_files(path, tags, metadata) check_folder_structure(path) click.secho(f"\nProcessed {path}", fg="cyan", bold=True)
def upload( gazelle_site, path, group_id, source, lossy, spectrals, encoding, existing=None, overwrite_meta=False, recompress=False, source_url=None, searchstrs=None, request_id=None, spectrals_after=False, ): """Upload an album folder to Gazelle Site Offer the choice to upload to another tracker after completion.""" path = os.path.abspath(path) if not source: source = _prompt_source() audio_info = gather_audio_info(path) hybrid = check_hybrid(audio_info) standardize_tags(path) tags = gather_tags(path) rls_data = construct_rls_data( tags, audio_info, source, encoding, existing=existing, overwrite=overwrite_meta, prompt_encoding=True, ) try: if rls_data["encoding"] == "24bit Lossless" and click.confirm( click.style( "24bit detected. Do you want to check whether might be upconverted?", fg="magenta", ), default=True, ): upload_upconvert_test(path) if group_id is None: searchstrs = generate_dupe_check_searchstrs( rls_data["artists"], rls_data["title"], rls_data["catno"]) group_id = check_existing_group(gazelle_site, searchstrs) if spectrals_after: lossy_master = False # We tell the uploader not to worry about it being lossy until later. else: lossy_master, spectral_ids = check_spectrals( path, audio_info, lossy, spectrals) metadata = get_metadata(path, tags, rls_data) download_cover_if_nonexistent(path, metadata["cover"]) path, metadata, tags, audio_info = edit_metadata( path, tags, metadata, source, rls_data, recompress) if not group_id: group_id = recheck_dupe(gazelle_site, searchstrs, metadata) click.echo() track_data = concat_track_data(tags, audio_info) except click.Abort: return click.secho(f"\nAborting upload...", fg="red") except AbortAndDeleteFolder: shutil.rmtree(path) return click.secho(f"\nDeleted folder, aborting upload...", fg="red") lossy_comment = None if spectrals_after: spectral_urls = None else: if lossy_master: lossy_comment = generate_lossy_approval_comment( source_url, list(track_data.keys())) click.echo() spectrals_path = os.path.join(path, "Spectrals") spectral_urls = handle_spectrals_upload_and_deletion( spectrals_path, spectral_ids) # Shallow copy to avoid errors on multiple uploads in one session. remaining_gazelle_sites = list(salmon.trackers.tracker_list) tracker = gazelle_site.site_code while True: # Loop until we don't want to upload to any more sites. if not tracker: if spectrals_after: # Here we are checking the spectrals after uploading to the first site # if they were not done before. lossy_master, lossy_comment, spectral_urls = post_upload_spectral_check( gazelle_site, path, torrent_id, None, track_data, source, source_url) spectrals_after = False click.secho("Would you like to upload to another tracker? ", fg="magenta", nl=False) tracker = salmon.trackers.choose_tracker(remaining_gazelle_sites) gazelle_site = salmon.trackers.get_class(tracker)() click.secho(f"Uploading to {gazelle_site.base_url}", fg="cyan") searchstrs = generate_dupe_check_searchstrs( rls_data["artists"], rls_data["title"], rls_data["catno"]) group_id = check_existing_group(gazelle_site, searchstrs, metadata) remaining_gazelle_sites.remove(tracker) if not request_id and config.CHECK_REQUESTS: request_id = check_requests(gazelle_site, searchstrs) torrent_id = prepare_and_upload( gazelle_site, path, group_id, metadata, track_data, hybrid, lossy_master, spectral_urls, lossy_comment, request_id, ) if lossy_master: report_lossy_master( gazelle_site, torrent_id, spectral_urls, track_data, source, lossy_comment, source_url=source_url, ) url = "{}/torrents.php?torrentid={}".format(gazelle_site.base_url, torrent_id) click.secho( f"\nSuccessfully uploaded {url} ({os.path.basename(path)}).", fg="green", bold=True, ) if config.COPY_UPLOADED_URL_TO_CLIPBOARD: pyperclip.copy(url) tracker = None request_id = None if not remaining_gazelle_sites or not config.MULTI_TRACKER_UPLOAD: return click.secho(f"\nDone uploading this release.", fg="green")
def upload( path, group_id, source, lossy, spectrals, encoding, existing=None, overwrite_meta=False, recompress=False, source_url=None, searchstrs=None, ): """Upload an album folder to RED""" path = os.path.abspath(path) if not source: source = _prompt_source() audio_info = gather_audio_info(path) hybrid = check_hybrid(audio_info) standardize_tags(path) tags = gather_tags(path) rls_data = construct_rls_data( tags, audio_info, source, encoding, existing=existing, overwrite=overwrite_meta, prompt_encoding=True, ) try: if group_id is None: searchstrs = generate_dupe_check_searchstrs( rls_data["artists"], rls_data["title"], rls_data["catno"]) group_id = check_existing_group(searchstrs) lossy_master, spectral_ids = check_spectrals(path, audio_info, lossy, spectrals) metadata = get_metadata(path, tags, rls_data) download_cover_if_nonexistent(path, metadata["cover"]) path, metadata, tags, audio_info = edit_metadata( path, tags, metadata, source, rls_data, recompress) if not group_id: group_id = recheck_dupe(searchstrs, metadata) click.echo() track_data = concat_track_data(tags, audio_info) except click.Abort: return click.secho(f"\nAborting upload...", fg="red") except AbortAndDeleteFolder: shutil.rmtree(path) return click.secho(f"\nDeleted folder, aborting upload...", fg="red") lossy_comment = None if lossy_master: lossy_comment = generate_lossy_approval_comment( source_url, list(track_data.keys())) click.echo() spectrals_path = os.path.join(path, "Spectrals") spectral_urls = handle_spectrals_upload_and_deletion( spectrals_path, spectral_ids) torrent_id, group_id = prepare_and_upload( path, group_id, metadata, track_data, hybrid, lossy_master, spectral_urls, lossy_comment, ) if lossy_master: report_lossy_master( torrent_id, spectral_urls, track_data, source, lossy_comment, source_url=source_url, ) url = f"https://redacted.ch/torrents.php?id={group_id}&torrentid={torrent_id}" click.secho( f"\nSuccessfully uploaded {url} ({os.path.basename(path)}).", fg="green", bold=True, ) if config.COPY_UPLOADED_URL_TO_CLIPBOARD: pyperclip.copy(url)