diff --git a/config/args.py b/config/args.py index ad81081..60cd154 100644 --- a/config/args.py +++ b/config/args.py @@ -13,7 +13,7 @@ from errors import ConfigError from textio import print_debug, print_warning -from utils.common import is_valid_post_id, save_config_or_raise +from utils.common import is_valid_post_id, save_config_or_raise, get_post_id_from_request def parse_args() -> argparse.Namespace: @@ -124,10 +124,10 @@ def parse_args() -> argparse.Namespace: '--single', required=False, default=None, - metavar='POST_ID', + metavar='REQUESTED_POST', dest='download_mode_single', help='Use "Single" download mode. This will download a single post ' - "by ID from an arbitrary creator. " + "by link or ID from an arbitrary creator. " "A post ID must be at least 10 characters and consist of digits only." "Example - https://fansly.com/post/1283998432982 -> ID is: 1283998432982", ) @@ -386,13 +386,13 @@ def map_args_to_config(args: argparse.Namespace, config: FanslyConfig) -> bool: download_mode_set = True if args.download_mode_single is not None: - post_id = args.download_mode_single + post_id = get_post_id_from_request(args.download_mode_single) config.download_mode = DownloadMode.SINGLE if not is_valid_post_id(post_id): raise ConfigError( f"Argument error - '{post_id}' is not a valid post ID. " - "At least 10 characters/only digits required." + "For an ID at least 10 characters/only digits are required." ) config.post_id = post_id diff --git a/download/single.py b/download/single.py index 885de79..65f9b14 100644 --- a/download/single.py +++ b/download/single.py @@ -9,7 +9,7 @@ from config import FanslyConfig from fileio.dedupe import dedupe_init from textio import input_enter_continue, print_error, print_info, print_warning -from utils.common import is_valid_post_id +from utils.common import is_valid_post_id, get_post_id_from_request def download_single_post(config: FanslyConfig, state: DownloadState): @@ -31,22 +31,23 @@ def download_single_post(config: FanslyConfig, state: DownloadState): ) else: - print_info(f"Please enter the ID of the post you would like to download." - f"\n{17*' '}After you click on a post, it will show in your browsers URL bar." + print_info(f"Please enter the link or the ID of the post you would like to download." + f"\n{17*' '}After you click on a post, the ID will show in your browser's URL bar." ) print() while True: - post_id = input(f"\n{17*' '}► Post ID: ") + requested_post = input(f"\n{17*' '}► Post Link or ID: ") + post_id = get_post_id_from_request(requested_post) if is_valid_post_id(post_id): break else: - print_error(f"The input string '{post_id}' can not be a valid post ID." - f"\n{22*' '}The last few numbers in the url is the post ID" + print_error(f"The input string '{requested_post}' can not be a valid post link or ID." + f"\n{22*' '}The last few numbers in the URL are the post ID" f"\n{22*' '}Example: 'https://fansly.com/post/1283998432982'" - f"\n{22*' '}In the example, '1283998432982' would be the post ID.", + f"\n{22*' '}In the example, '1283998432982' is the post ID.", 17 ) @@ -83,9 +84,9 @@ def download_single_post(config: FanslyConfig, state: DownloadState): state.creator_name = creator_username if creator_display_name and creator_username: - print_info(f"Inspecting a post by {creator_display_name} (@{creator_username})") + print_info(f"Inspecting post {post_id} by {creator_display_name} (@{creator_username})") else: - print_info(f"Inspecting a post by {creator_username.capitalize()}") + print_info(f"Inspecting post {post_id} by {creator_username.capitalize()}") # Deferred deduplication init because directory may have changed # depending on post creator (!= configured creator) @@ -102,8 +103,8 @@ def download_single_post(config: FanslyConfig, state: DownloadState): ) else: - print_warning(f"Could not find any accessible content in the single post.") + print_warning(f"Could not find any accessible content in post {post_id}.") else: - print_error(f"Failed single post download. Response code: {post_response.status_code}\n{post_response.text}", 20) + print_error(f"Failed to download post {post_id}. Response code: {post_response.status_code}\n{post_response.text}", 20) input_enter_continue(config.interactive) diff --git a/utils/common.py b/utils/common.py index 6bd5cdb..71742f9 100644 --- a/utils/common.py +++ b/utils/common.py @@ -79,6 +79,22 @@ def is_valid_post_id(post_id: str) -> bool: ) +def get_post_id_from_request(requested_post: str) -> str: + """Strips post_id from a post link if necessary. + Otherwise, the post_id is returned directly + + :param requested_post: The request made by the user. + :type requested_post: str + + :return: The extracted post_id. + :rtype: str + """ + post_id = requested_post + if requested_post.startswith("https://fansly.com/"): + post_id = requested_post.split('/')[-1] + return post_id + + def open_location(filepath: Path, open_folder_when_finished: bool, interactive: bool) -> bool: """Opens the download directory in the platform's respective file manager application once the download process has finished.