-
-
Notifications
You must be signed in to change notification settings - Fork 975
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
Conversation
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
data["folders"] = [rh(folder) for folder in extr( | ||
'<h3>Listed in Folders</h3>', | ||
'</section>').split('</a>') if rh(folder) != ''] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
data["thumbnail"] = ( | ||
'https://t.furaffinity.net/' + | ||
str(data['id']) + '@600-' + | ||
data['url'].split('/')[-2] + '.jpg') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
Retrieve 'thumbnail' and 'folders' properties for each post. A test case is included for each property.
'thumbnail':
'folders':
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.