Skip to content

Commit

Permalink
Merge pull request #62 from 1gintonic/61_post_link_for_download
Browse files Browse the repository at this point in the history
Use Full Post Link for Download
  • Loading branch information
prof79 authored Jun 28, 2024
2 parents 3d5ffde + e556b99 commit 7be59db
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
10 changes: 5 additions & 5 deletions config/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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",
)
Expand Down Expand Up @@ -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
Expand Down
23 changes: 12 additions & 11 deletions download/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
16 changes: 16 additions & 0 deletions utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7be59db

Please sign in to comment.