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

imageUtils rewrite #769

Merged
merged 8 commits into from
Apr 9, 2021
Merged

imageUtils rewrite #769

merged 8 commits into from
Apr 9, 2021

Conversation

heyhippari
Copy link
Contributor

@heyhippari heyhippari commented Feb 20, 2021

Rewrites the utility functions to get image URLs, based on Jellyfin-web.

  • Allows for image-type preference and proper fallback (For example, Thumbs will be preferred for thumb-shaped cards, but fallback to backdrops, then primary images)
  • Properly handles parent items
  • Adds blurhash + fallback for artist and person details page

Thumbs with Backdrop fallback

image

Proper episode images

image

@heyhippari heyhippari mentioned this pull request Feb 20, 2021
16 tasks
@sonarcloud
Copy link

sonarcloud bot commented Feb 20, 2021

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

No Coverage information No Coverage information
13.2% 13.2% Duplication

@codecov
Copy link

codecov bot commented Feb 20, 2021

Codecov Report

Merging #769 (389b8c8) into master (0214efb) will decrease coverage by 1.07%.
The diff coverage is 17.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #769      +/-   ##
==========================================
- Coverage   68.44%   67.36%   -1.08%     
==========================================
  Files          24       24              
  Lines         786      806      +20     
  Branches      141      144       +3     
==========================================
+ Hits          538      543       +5     
- Misses        228      243      +15     
  Partials       20       20              
Impacted Files Coverage Δ
client/store/tvShows.ts 40.00% <ø> (ø)
client/utils/playbackUtils.ts 36.84% <ø> (ø)
client/mixins/itemHelper.ts 34.21% <7.14%> (-5.48%) ⬇️
client/utils/items.ts 88.88% <57.14%> (-7.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0214efb...389b8c8. Read the comment docs.

@heyhippari heyhippari mentioned this pull request Feb 27, 2021
@jellyfin-bot jellyfin-bot added the merge conflict Something has merge conflicts label Mar 23, 2021
@jellyfin-bot jellyfin-bot added vue Pull requests that edit or add Vue files pinia Pull requests or issues that deal with Pinia stores labels Apr 4, 2021
@heyhippari heyhippari removed the merge conflict Something has merge conflicts label Apr 4, 2021
@heyhippari heyhippari marked this pull request as ready for review April 4, 2021 15:45
client/components/Item/PersonList.vue Outdated Show resolved Hide resolved
client/mixins/imageHelper.ts Show resolved Hide resolved
v-if="item.ImageTags && item.ImageTags.Primary"
:item="item"
/>
<v-icon v-else size="128" dark>mdi-account</v-icon>
Copy link
Member

Choose a reason for hiding this comment

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

Why not do this fallback on BlurhashImage like all the items does?

BlurhashImage also has slots now, no need for v-else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly because this happens:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

576fdf1 fixes this by using slots properly in blurhash-image (There's no need to make a condition, you define the default content by putting it into the slot)

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a clue why this is happening. Maybe we can make the v-if here an v-if-else? I don't have a idea why this is happening, we're already getting artist images with proper icons in the home header.

I originally placed the condition so BlurhashImage is smart enough to provide icons for fallbacks but we're still able to pass our own custom slots in case we needed a different component or other needs.

You shouldn't need those slots in any case, I'm testing your changes locally to see what could be going on.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, something strange iis going on. Master is showing me the mid-account icon for artists that don't have an image in the Home Header. Your PR shows the mdi-disc icon instead.

Artists that have images don't have any overlapping icon, so I think you should remove the passed slots altogether and let BlurhashImage handle it like we do in HomeHeader's master and artist cards.

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 don't have a clue why this is happening. Maybe we can make the v-if here an v-if-else? I don't have a idea why this is happening, we're already getting artist images with proper icons in the home header.

That part of the code is completely gone.

The way you define a slot's default content isn't with v-if and v-else, but by putting the default inside of the slot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You shouldn't need those slots in any case, I'm testing your changes locally to see what could be going on.

I removed the ones for the main artist and person images.

However one still remains in PersonList. In order to remove it, we should rework getShapeFromItemType to take BaseItemDto | BaseItemPerson. But that touches stuff outside of this PR's scope, so I'd rather do it in a followup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, something strange iis going on. Master is showing me the mid-account icon for artists that don't have an image in the Home Header. Your PR shows the mdi-disc icon instead.

It has always showed mdi-disc in the home header for me, since the home header lists albums, not persons.

client/pages/artist/_itemId/index.vue Outdated Show resolved Hide resolved
client/pages/person/_itemId/index.vue Outdated Show resolved Hide resolved
client/utils/items.ts Outdated Show resolved Hide resolved
<v-fade-transition>
<img
v-show="!loading"
:key="`blurhashimage-${item.Id}`"
Copy link
Member

Choose a reason for hiding this comment

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

How does this work when the component is not remounted? (I.e item update or audio controls)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works just fine for me.

@neopc10
Copy link

neopc10 commented Apr 4, 2021

Would this PR be a good opportunity to include usage of Primary Poster images for the latest media in a mixed library? I know those libraries have been largely untouched but for cosmetics this would go a long way.

image

@heyhippari
Copy link
Contributor Author

Would this PR be a good opportunity to include usage of Primary Poster images for the latest media in a mixed library? I know those libraries have been largely untouched but for cosmetics this would go a long way.

The logic in this is the exact same as what the web client does, so whatever it uses for images is what this uses too. If that's not the case for mixed libraries, there may be changes needed elsewhere, which would probably fall under another PR :/

@neopc10
Copy link

neopc10 commented Apr 4, 2021

Web is using thumb images. Movies have always used Primary and TV Shows in the past few versions moved to Primary but the mixed were left behind.

@heyhippari
Copy link
Contributor Author

@neopc10 I fixed the shape issue in 80d2bdf. The images all use the Primary, like other sections do (See the screenshot below)

image

@jellyfin-bot jellyfin-bot added the merge conflict Something has merge conflicts label Apr 6, 2021
Copy link
Member

@ThibaultNocchi ThibaultNocchi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@ferferga ferferga left a comment

Choose a reason for hiding this comment

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

I confirm that there aren't issues while switching between tracks in audiocontrols (with a caveat, see review comments).

The issues with people (only tested music artists) I commented in my other review persist though:

Master
image

This branch
image

(We expect album covers now or artist images?)

Also, in some places artists has images and in some other they don't:
image

However, in other item "You may also like":
image

There are some other cases where the image is present in the library cards but not in the artist page:

image
image

I found this happens when you're navigating from a place where the image doesn't exist as well. So, if I click in the library card, I can see the image. However, if I find that artist through "You may also like", there are no images. Same applies with home header and I guess to every place where the image isn't displayed correctly. Following links in albums to artist also reproduce this problem

Comment on lines 13 to 15
<template #placeholder>
<v-icon size="16">mdi-account</v-icon>
</template>
Copy link
Member

Choose a reason for hiding this comment

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

Why we need this? If you want to override the sizing, you can pass iconSize prop to BlurhashImage, the rest (component type being icon, icon that will be used) is exactly the same output that BlurhashImage will generate for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because this doesn't use BaseItemDto, but BaseItemPerson.

Copy link
Member

Choose a reason for hiding this comment

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

@MrTimscampi Shouldn't we then instruct BlurhashImage to handle those? Right now they don't have a blurhash as well because this. As you moved everything to a single function in imageHelper I guess this should be possible without much hassle.

I'd rather we get it merged without this as the placeholder mess is very difficult to maintain and having everything centered (like image rescaling on resize, the fallbacks and so on) in blurhashimage turned out to be great in the long term (this PR would have been massive for instance :P)

Comment on lines +28 to +30
<v-avatar color="card">
<blurhash-image :item="relatedItem" icon-size="16" />
</v-avatar>
Copy link
Member

Choose a reason for hiding this comment

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

Above you want exactly what you do here

this.onError();
}
this.image = imageInfo.url;
this.tag = imageInfo.tag ? imageInfo.tag : 'no-image-tag';
Copy link
Member

Choose a reason for hiding this comment

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

Why not set it to null instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Holdover from jf-web, thanks for catching it 😋

maxWidth: 96
}) || '',
this.getImageInfo(this.getCurrentItem, {
width: 96
Copy link
Member

@ferferga ferferga Apr 7, 2021

Choose a reason for hiding this comment

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

Maybe we should define in all these functions the height to be 100% sure that the size we get is the one we really expect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The server won't cut them if we specify the height too, as far as I'm aware. It will just try to make the image fit in the box you send it.


return aspectRatio;
},
getImageInfo(
Copy link
Member

Choose a reason for hiding this comment

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

Why all the documentation for this function is completely gone? I think it was really useful, as the image logic is getting more and more complex everyday

:punch="punch"
class="absolute"
/>
<div ref="imageElement">
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we use better the img element to pass it to the function?

Copy link
Member

Choose a reason for hiding this comment

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

After testing what I comment on #769 (comment) both in your branch and in master, I see that the Cast & Crew images have a far superior resolution in your branch than in master, which makes me suspect that I was indeed right about this change.

Maybe, being the child absolute positioned, the size can't be determined correctly and it's loading full resolution?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That wasn't working, probably because the image doesn't contain anything and is absolute.

This element has the same size anyway, and is technically our image component.

Comment on lines 4 to 13
<v-fade-transition>
<blurhash-canvas
v-if="hash"
:hash="hash"
:width="width"
:height="height"
:punch="punch"
class="absolute"
/>
</v-fade-transition>
Copy link
Member

Choose a reason for hiding this comment

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

We don't need a v-fade transition here. On fast connections the images load so fast that the transition is longer than the time that it takes to load the connection, so we want to show the blurhash as soon as possible without any fancy thing. The image is another thing though.

With your branch, the transition when switching tracks is very "abrupt" if that makes sense.

Comment on lines -26 to +28
<div v-if="!$slots.placeholder" class="absolute icon img">
<v-icon
class="absolute text--disabled"
:size="iconSize"
color="white"
dark
>
<slot v-else name="placeholder">
<v-icon class="absolute text--disabled" :size="iconSize">
{{ getItemIcon(item) }}
</v-icon>
</div>
<slot v-else name="placeholder" />
</slot>
Copy link
Member

Choose a reason for hiding this comment

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

What if somewhere we don't want an icon placeholder but something else instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You just use the slot and set whatever you want inside of it.

This is how slots work. What is inside the slot definition is the default. Then you override it by defining a template for that slot when calling the component.

@heyhippari
Copy link
Contributor Author

The issues with people (only tested music artists) I commented in my other review persist though

If fixed this locally, but it's important to note a few things:

  • We're listing albums and not artists, so the disc makes more sense
  • It's only showing a person because HomeHeaderItem is currently fetching the parent items. With this PR, this isn't necessary at all (as pointed out before, items have all the necessary tags and blurhashes), so the next step after this is completely removing the related items thing, which will lead to having discs there anyway.

Also, in some places artists has images and in some other they don't

I am not able to reproduce this using a 10.7.1 server and this branch.

There are some other cases where the image is present in the library cards but not in the artist page

Same thing, I'm not able to reproduce it.

I found this happens when you're navigating from a place where the image doesn't exist as well. So, if I click in the library card, I can see the image. However, if I find that artist through "You may also like", there are no images. Same applies with home header and I guess to every place where the image isn't displayed correctly. Following links in albums to artist also reproduce this problem

Doing this gives me images all the time:

  • Home header => View details => By { artist }
    Image shows up
  • Library => Click on card => By { artist }
    Image shows up
  • Library => Click on artist link on card
    Image shows up
  • On artist page => You may also like
    Image shows up

@heyhippari heyhippari force-pushed the image-refactor branch 2 times, most recently from 81fa362 to 0612997 Compare April 7, 2021 17:34
Mixed libraries do not have a CollectionType property, for some reason. As such, they used square
cards, which is not correct. This switches the default shape to portrait, which fixes the issue.
@heyhippari heyhippari removed the merge conflict Something has merge conflicts label Apr 9, 2021
@sonarcloud
Copy link

sonarcloud bot commented Apr 9, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 16 Code Smells

No Coverage information No Coverage information
1.0% 1.0% Duplication

@heyhippari heyhippari merged commit cf0649b into jellyfin:master Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pinia Pull requests or issues that deal with Pinia stores vue Pull requests that edit or add Vue files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants