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

[Enhancement] Readable filenames not available for subscribestar attachments #1609

Closed
fake-name opened this issue Jun 10, 2021 · 1 comment
Closed

Comments

@fake-name
Copy link

Currently, subscribestar attachments can have nice human-readable filenames. However, the actual linked file is named with a random UUID.

There seems to be no way to access this currently, which is supported by looking at the source.

Patching _media_from_post() to include it is pretty simple:

    @staticmethod
    def _media_from_post(html):
        media = []

        gallery = text.extract(html, 'data-gallery="', '"')[0]
        if gallery:
            media.extend(
                item for item in json.loads(text.unescape(gallery))
                if "/previews/" not in item["url"]
            )

        attachments = text.extract(
            html, 'class="uploads-docs"', 'data-role="post-edit_form"')[0]
        if attachments:
            for att in attachments.split('class="doc_preview"')[1:]:
                media.append({
                    "id"  : text.parse_int(text.extract(att, 'data-upload-id="', '"')[0]),
                    "url" : text.extract(att, 'href="', '"')[0],
                    "nice_name" : text.extract(att, 'doc_preview-title">', '</span')[0],
                    "type": "attachment",
                })

        return media
@mikf
Copy link
Owner

mikf commented Jun 10, 2021

Updated it so filename fields now use readable names for attachments and the regular UUIDs if those are not available. (d09bc5b).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants