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

Feature: Add Attachment class with URL support and download functionality #139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Sp5rky
Copy link

@Sp5rky Sp5rky commented Mar 8, 2025

feat(Attachment): Add URL support and download functionality to Attachment class

Description

This PR introduces several enhancements to the Attachment class within the devine/core/tracks/attachment.py file:

URL Support:

  • Added the ability to create an Attachment from a URL. This includes downloading the file to a temporary directory if a URL is provided.
  • Added url and session parameters to the constructor.
  • Added a new class method from_url to streamline the creation of attachments from URLs.

Mime Type Handling:

  • Expanded MIME type support to include .jpg, .jpeg, and .png file extensions.

Example Code in Service.

if title.data["info"]["poster"]:
    poster_url = title.data["info"]["poster"]
    
    try:
        thumbnail_name = title.data["meta"]["title"]["en"] + " thumbnail"
    except (KeyError, TypeError):
        thumbnail_name = "thumbnail"
    
    try:
        thumbnail_attachment = Attachment.from_url(
            url=poster_url,
            name=thumbnail_name,
            mime_type="image/jpeg",
            description="Thumbnail",
            session=self.session,
        )
        tracks.attachments.append(thumbnail_attachment)
    except Exception as e:
        self.log.warning(f"Failed to download thumbnail: {e}")

Sp5rky added 2 commits March 7, 2025 23:57

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…functionality
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant