-
-
Notifications
You must be signed in to change notification settings - Fork 543
Multiple images support #889
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
d854541
Add an Image class to the extractor
AudricV 78ce657
Add an ImageSuffix class to the extractor
AudricV 2f3ee8a
Replace avatar and thumbnail URLs attributes and methods to List<Imag…
AudricV ca1d4a6
Replace avatar and thumbnail URLs attributes and methods to List<Imag…
AudricV 0f4a5a8
Replace avatar and thumbnail URLs attributes and methods to List<Imag…
AudricV 9d80985
Replace avatar and thumbnail URLs attributes and methods to List<Imag…
AudricV d56b880
Replace avatar and thumbnail URLs attributes and methods to List<Imag…
AudricV adfad08
[YouTube] Add utility methods to get images from InfoItems and thumbn…
AudricV 4cc99f9
[YouTube] Apply changes in InfoItemExtractors except YouTube Music ones
AudricV c1981ed
[YouTube] Apply changes in Extractors except YoutubeMusicSearchExtractor
AudricV 266cd1f
[YouTube] Apply changes in YoutubeMusicSearchExtractor and split its …
AudricV 7f81821
[SoundCloud] Add utility methods to get images from track JSON object…
AudricV a3a74cd
[SoundCloud] Apply changes in InfoItemExtractors and return track use…
AudricV 31da5be
[SoundCloud] Apply changes in Extractors
AudricV 81c0d80
[PeerTube] Add utility methods to get avatars and banners of accounts…
AudricV 6f83315
[PeerTube] Add utility method to get thumbnails of playlists and videos
AudricV 0a6011a
[PeerTube] Apply changes in InfoItemExtractors
AudricV 4e6fb36
[PeerTube] Apply changes in Extractors and remove usages of default a…
AudricV 4b80d73
[Bandcamp] Add utility methods to get multiple images
AudricV 7e01eaa
[Bandcamp] Apply changes in InfoItemExtractors
AudricV 71cda03
[Bandcamp] Apply changes in Extractors
AudricV 2f40861
[MediaCCC] Add utility methods to get image lists from conference log…
AudricV 306068a
[MediaCCC] Apply changes in InfoItemExtractors
AudricV e16d521
[MediaCCC] Apply changes in Extractors
AudricV 70fb3aa
Update BaseExtractorTests image methods' name
AudricV 5158472
Apply changes in DefaultTests and add utility method to test image lists
AudricV 434e885
Add utility methods in ExtractorAsserts to check whether a collection…
AudricV d381f3b
Update avatar, banners and thumbnail methods' name and apply changes …
AudricV 2c436d4
[YouTube] Add utility test method to test images in YoutubeTestsUtils
AudricV 93a2103
[YouTube] Apply changes in extractor tests
AudricV 1d72bac
[SoundCloud] Apply changes in extractor tests
AudricV ba5315c
[PeerTube] Apply changes in extractor tests
AudricV 2578f22
[Bandcamp] Add utility test method to test images
AudricV 0292c4f
[Bandcamp] Apply changes in extractor tests
AudricV e8bfd20
[MediaCCC] Apply changes in extractor tests
AudricV File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
211 changes: 211 additions & 0 deletions
211
extractor/src/main/java/org/schabi/newpipe/extractor/Image.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,211 @@ | ||
| package org.schabi.newpipe.extractor; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import java.io.Serializable; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Class representing images in the extractor. | ||
| * | ||
| * <p> | ||
| * An image has four properties: its URL, its height, its width and its estimated quality level. | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * Depending of the services, the height, the width or both properties may be not known. | ||
| * Implementations <b>must use</b> the relevant unknown constants in this case | ||
| * ({@link #HEIGHT_UNKNOWN} and {@link #WIDTH_UNKNOWN}), to ensure properly the lack of knowledge | ||
| * of one or both of these properties to extractor clients. | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * They should also respect the ranges defined in the estimated image resolution levels as much as | ||
| * possible, to ensure consistency to extractor clients. | ||
| * </p> | ||
| */ | ||
| public final class Image implements Serializable { | ||
|
|
||
| /** | ||
| * Constant representing that the height of an {@link Image} is unknown. | ||
| */ | ||
| public static final int HEIGHT_UNKNOWN = -1; | ||
|
|
||
| /** | ||
| * Constant representing that the width of an {@link Image} is unknown. | ||
| */ | ||
| public static final int WIDTH_UNKNOWN = -1; | ||
|
|
||
| @Nonnull | ||
| private final String url; | ||
| private final int height; | ||
| private final int width; | ||
| @Nonnull | ||
| private final ResolutionLevel estimatedResolutionLevel; | ||
|
|
||
| /** | ||
| * Construct an {@link Image} instance. | ||
| * | ||
| * @param url the URL to the image, which should be not null or empty | ||
| * @param height the image's height | ||
| * @param width the image's width | ||
| * @param estimatedResolutionLevel the image's estimated resolution level, which must not be | ||
| * null | ||
| * @throws NullPointerException if {@code estimatedResolutionLevel} is null | ||
| */ | ||
| public Image(@Nonnull final String url, | ||
| final int height, | ||
| final int width, | ||
| @Nonnull final ResolutionLevel estimatedResolutionLevel) | ||
| throws NullPointerException { | ||
| this.url = url; | ||
| this.height = height; | ||
| this.width = width; | ||
| this.estimatedResolutionLevel = Objects.requireNonNull( | ||
| estimatedResolutionLevel, "estimatedResolutionLevel is null"); | ||
| } | ||
|
|
||
| /** | ||
| * Get the URL of this {@link Image}. | ||
| * | ||
| * @return the {@link Image}'s URL. | ||
| */ | ||
| @Nonnull | ||
| public String getUrl() { | ||
| return url; | ||
| } | ||
|
|
||
| /** | ||
| * Get the height of this {@link Image}. | ||
| * | ||
| * <p> | ||
| * If it is unknown, {@link #HEIGHT_UNKNOWN} is returned instead. | ||
| * </p> | ||
| * | ||
| * @return the {@link Image}'s height or {@link #HEIGHT_UNKNOWN} | ||
| */ | ||
| public int getHeight() { | ||
| return height; | ||
| } | ||
|
|
||
| /** | ||
| * Get the width of this {@link Image}. | ||
| * | ||
| * <p> | ||
| * If it is unknown, {@link #WIDTH_UNKNOWN} is returned instead. | ||
| * </p> | ||
| * | ||
| * @return the {@link Image}'s width or {@link #WIDTH_UNKNOWN} | ||
| */ | ||
| public int getWidth() { | ||
| return width; | ||
| } | ||
|
|
||
| /** | ||
| * Get the estimated resolution level of this image. | ||
| * | ||
| * <p> | ||
| * If it is unknown, {@link ResolutionLevel#UNKNOWN} is returned instead. | ||
| * </p> | ||
| * | ||
| * @return the estimated resolution level, which is never {@code null} | ||
| * @see ResolutionLevel | ||
| */ | ||
| @Nonnull | ||
| public ResolutionLevel getEstimatedResolutionLevel() { | ||
| return estimatedResolutionLevel; | ||
| } | ||
|
|
||
| /** | ||
| * Get a string representation of this {@link Image} instance. | ||
| * | ||
| * <p> | ||
| * The representation will be in the following format, where {@code url}, {@code height}, | ||
| * {@code width} and {@code estimatedResolutionLevel} represent the corresponding properties: | ||
| * <br> | ||
| * <br> | ||
| * {@code Image {url=url, height='height, width=width, | ||
| * estimatedResolutionLevel=estimatedResolutionLevel}'} | ||
| * </p> | ||
| * | ||
| * @return a string representation of this {@link Image} instance | ||
| */ | ||
| @Nonnull | ||
| @Override | ||
| public String toString() { | ||
| return "Image {" + "url=" + url + ", height=" + height + ", width=" + width | ||
| + ", estimatedResolutionLevel=" + estimatedResolutionLevel + "}"; | ||
| } | ||
|
|
||
| /** | ||
| * The estimated resolution level of an {@link Image}. | ||
| * | ||
| * <p> | ||
| * Some services don't return the size of their images, but we may know for a specific image | ||
| * type that a service returns, according to real data, an approximation of the resolution | ||
| * level. | ||
| * </p> | ||
| */ | ||
| public enum ResolutionLevel { | ||
|
|
||
| /** | ||
| * The high resolution level. | ||
| * | ||
| * <p> | ||
| * This level applies to images with a height greater than or equal to 720px. | ||
| * </p> | ||
| */ | ||
| HIGH, | ||
|
|
||
| /** | ||
| * The medium resolution level. | ||
| * | ||
| * <p> | ||
| * This level applies to images with a height between 175px inclusive and 720px exclusive. | ||
| * </p> | ||
| */ | ||
| MEDIUM, | ||
|
|
||
| /** | ||
| * The low resolution level. | ||
| * | ||
| * <p> | ||
| * This level applies to images with a height between 1px inclusive and 175px exclusive. | ||
| * </p> | ||
| */ | ||
| LOW, | ||
|
|
||
| /** | ||
| * The unknown resolution level. | ||
| * | ||
| * <p> | ||
| * This value is returned when the extractor doesn't know what resolution level an image | ||
| * could have, for example if the extractor loops in an array of images with different | ||
| * resolution levels without knowing the height. | ||
| * </p> | ||
| */ | ||
| UNKNOWN; | ||
|
|
||
| /** | ||
| * Get a {@link ResolutionLevel} based from the given height. | ||
| * | ||
| * @param heightPx the height from which returning the good {@link ResolutionLevel} | ||
| * @return the {@link ResolutionLevel} corresponding to the height provided. See the | ||
| * {@link ResolutionLevel} values for details about what value is returned. | ||
| */ | ||
| public static ResolutionLevel fromHeight(final int heightPx) { | ||
| if (heightPx <= 0) { | ||
| return UNKNOWN; | ||
| } | ||
|
|
||
| if (heightPx < 175) { | ||
| return LOW; | ||
| } | ||
|
|
||
| if (heightPx < 720) { | ||
| return MEDIUM; | ||
| } | ||
|
|
||
| return HIGH; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.