Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Use the default provider categories during ingestion #635

Merged
merged 7 commits into from
Aug 3, 2022

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Jul 28, 2022

Fixes

Fixes WordPress/openverse#1683 by @dhruvkb

Description

This PR adds a default category to media items in the MediaStore's clean_media_metadata method.
With this change, this is how category for an item is determined:

  • if a provider script can assign different categories, it should set the item category in the get_record_data method (or when calling add_item with old scripts).
  • MediaStore uses the category value a provider script passes.
  • If the category is None, MediaStore tries to add the category that is default for provider, and is listed in provider_details.py module.

Testing Instructions

Run one of the data collection DAGs until you see Wrote 100 lines to the disc in the Pull data task log. Stop the DAG. Wait a couple of seconds until the DAG finishes, and then check the data in the database (I use DataGrip connected to the localhost's DB). The category column should be filled. For example, for "clevelandmuseum", category should be set to digitized_artwork, and for "sciencemuseum", it should be set to photograph.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Signed-off-by: Olga Bulat <obulat@gmail.com>
@openverse-bot openverse-bot added ✨ goal: improvement Improvement to an existing user-facing feature 💻 aspect: code Concerns the software code in the repository 🟨 priority: medium Not blocking but should be addressed soon labels Jul 28, 2022
Signed-off-by: Olga Bulat <obulat@gmail.com>
Signed-off-by: Olga Bulat <obulat@gmail.com>
@obulat obulat marked this pull request as ready for review July 28, 2022 13:23
@obulat obulat requested a review from a team as a code owner July 28, 2022 13:23
Copy link
Contributor

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

Looks straightforward! Just one question.

openverse_catalog/dags/common/storage/media.py Outdated Show resolved Hide resolved
openverse_catalog/dags/common/storage/image.py Outdated Show resolved Hide resolved
obulat and others added 2 commits August 1, 2022 07:31
Co-authored-by: Madison Swain-Bowden <bowdenm@spu.edu>
Signed-off-by: Olga Bulat <obulat@gmail.com>
Copy link
Contributor

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

Looks great!

@AetherUnbound AetherUnbound mentioned this pull request Aug 2, 2022
7 tasks
@@ -121,7 +121,6 @@ class ImageCategory(Enum):

# Default image category by source
DEFAULT_IMAGE_CATEGORY = {
"flickr": ImageCategory.PHOTOGRAPH.value,
Copy link
Member

Choose a reason for hiding this comment

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

Did you mention why this is being removed? As I understand Flickr is exclusively photos (and some videos) and not illustrations or other media types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Flickr returns one of 3 type values, and we set the category as photograph only to the photos, not screenshots or other:

def _get_category(image_data):
    """
    Flickr has three types:
        0 for photos
        1 for screenshots
        3 for other
    Treating everything different from photos as unknown.
    """
    if "content_type" in image_data and image_data["content_type"] == "0":
        return ImageCategory.PHOTOGRAPH.value
    return None

So, even before this PR, Flickr script was using photograph as the category for type 0. I don't know if we should investigate what types 1 and 3 are, and whether we can use them for categorizing as well.

@@ -6,6 +6,7 @@

from common.extensions import extract_filetype
from common.licenses import is_valid_license_info
from common.loader import provider_details as prov
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think I personally prefer the full provider here instead of prov because it's clearer, but it doesn't matter much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the full provider here, but it's prov in all of the provider scripts, so I just used this for consistency (so that I don't have to change what I copy-pasted :) ) Do you think we should open an issue to replace provider with prov, @zackkrida?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to using the full name rather than an alias 😄 I think an issue for that would be excellent! It'd be a solid "good first issue" as well

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

LGTM! Some small nits (take them or leave them) but otherwise looks great. Successfully saw the digitized_artwork category on my 6k Cleveland Museum local DAG run.

Co-authored-by: Zack Krida <zackkrida@pm.me>
@obulat obulat merged commit a2e1d50 into main Aug 3, 2022
@obulat obulat deleted the add/default_category_in_MediaStore branch August 3, 2022 04:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository ✨ goal: improvement Improvement to an existing user-facing feature 🟨 priority: medium Not blocking but should be addressed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move default categories from API to providers scripts
4 participants