Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[furaffinity] Add 'thumbnail' (#1284) and 'folders' properties #5824

Merged
merged 2 commits into from
Jul 17, 2024

Conversation

theorangesauce
Copy link
Contributor

Retrieve 'thumbnail' and 'folders' properties for each post. A test case is included for each property.

'thumbnail':

  • Preview image used for search results, writing posts, music, etc.
  • URL format: <post_id>@600-<directory_containing_full_image>.jpg (usually matches the number at the start of the 'filename' property, but not always)
  • Uses 600px version; other sizes exist, but 600px seems to be the largest

'folders':

  • A list of all gallery folders containing this post
  • Folder name format: [<folder_category> - ]<folder_name>
  • Only accurate on new layout; old layout does not show folders, so if old layout is active, 'folders' defaults to an empty list

Users can now use --filter with folder names, providing a workaround for #1817.

In the future, 'thumbnail' could be used to automatically download thumbnails for writing, music, and other non-image posts, which would fully resolve #1284.

Retrieve 'thumbnail' and 'folders' properties for each post.
'thumbnail' (mikf#1284):
 - Preview image used for search results, writing posts, music, etc.
 - Filename format: <post_id>@600-<directory_containing_full_image>.jpg
'Folders' (related to mikf#1817):
 - A list of all gallery folders containing this post
 - Folder name format: [<folder_category> - ]<folder_name>
 - Only works on new layout; old layout does not show folders, so list will be empty

A test is included for each property.
Forgot to remove this from a previous implementation attempt
Comment on lines +116 to +118
data["folders"] = [rh(folder) for folder in extr(
'<h3>Listed in Folders</h3>',
'</section>').split('</a>') if rh(folder) != '']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data["folders"] = [rh(folder) for folder in extr(
'<h3>Listed in Folders</h3>',
'</section>').split('</a>') if rh(folder) != '']
data["folders"] = folders = []
for folder in extr(
"<h3>Listed in Folders</h3>", "</section>").split("</a>"):
folder = rh(folder)
if folder:
folders.append(folder)

More code, but it calls remove_html() only once.
Walrus operator would be useful here when using a list comprehension, but that's Python 3.8+.

@@ -132,11 +135,16 @@ def _parse_post(self, post_id):
data["_description"] = extr(
'<td valign="top" align="left" width="70%" class="alt1" '
'style="padding:8px">', ' </td>')
data["folders"] = [] # folders not present in old layout
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data["folders"] = [] # folders not present in old layout
data["folders"] = () # folders not present in old layout

Empty tuple is more lightweight than constructing a new empty list every time.

Comment on lines +144 to +147
data["thumbnail"] = (
'https://t.furaffinity.net/' +
str(data['id']) + '@600-' +
data['url'].split('/')[-2] + '.jpg')
Copy link
Owner

@mikf mikf Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data["thumbnail"] = (
'https://t.furaffinity.net/' +
str(data['id']) + '@600-' +
data['url'].split('/')[-2] + '.jpg')
data["thumbnail"] = "https://t.furaffinity.net/{}@600-{}.jpg".format(
post_id, path.rsplit("/", 2)[1])

A format string is simpler and rsplit is a bit faster here.
We can also reuse some variables instead of accessing data.

@mikf mikf merged commit 4f3be2f into mikf:master Jul 17, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Furaffinity thumbnails
2 participants