Skip to content

Commit 1f08d28

Browse files
authored
Merge pull request #889 from AudricV/multiple-images-support
Multiple images support
2 parents 7294675 + e8bfd20 commit 1f08d28

File tree

104 files changed

+2924
-1559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2924
-1559
lines changed
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
package org.schabi.newpipe.extractor;
2+
3+
import javax.annotation.Nonnull;
4+
import java.io.Serializable;
5+
import java.util.Objects;
6+
7+
/**
8+
* Class representing images in the extractor.
9+
*
10+
* <p>
11+
* An image has four properties: its URL, its height, its width and its estimated quality level.
12+
* </p>
13+
*
14+
* <p>
15+
* Depending of the services, the height, the width or both properties may be not known.
16+
* Implementations <b>must use</b> the relevant unknown constants in this case
17+
* ({@link #HEIGHT_UNKNOWN} and {@link #WIDTH_UNKNOWN}), to ensure properly the lack of knowledge
18+
* of one or both of these properties to extractor clients.
19+
* </p>
20+
*
21+
* <p>
22+
* They should also respect the ranges defined in the estimated image resolution levels as much as
23+
* possible, to ensure consistency to extractor clients.
24+
* </p>
25+
*/
26+
public final class Image implements Serializable {
27+
28+
/**
29+
* Constant representing that the height of an {@link Image} is unknown.
30+
*/
31+
public static final int HEIGHT_UNKNOWN = -1;
32+
33+
/**
34+
* Constant representing that the width of an {@link Image} is unknown.
35+
*/
36+
public static final int WIDTH_UNKNOWN = -1;
37+
38+
@Nonnull
39+
private final String url;
40+
private final int height;
41+
private final int width;
42+
@Nonnull
43+
private final ResolutionLevel estimatedResolutionLevel;
44+
45+
/**
46+
* Construct an {@link Image} instance.
47+
*
48+
* @param url the URL to the image, which should be not null or empty
49+
* @param height the image's height
50+
* @param width the image's width
51+
* @param estimatedResolutionLevel the image's estimated resolution level, which must not be
52+
* null
53+
* @throws NullPointerException if {@code estimatedResolutionLevel} is null
54+
*/
55+
public Image(@Nonnull final String url,
56+
final int height,
57+
final int width,
58+
@Nonnull final ResolutionLevel estimatedResolutionLevel)
59+
throws NullPointerException {
60+
this.url = url;
61+
this.height = height;
62+
this.width = width;
63+
this.estimatedResolutionLevel = Objects.requireNonNull(
64+
estimatedResolutionLevel, "estimatedResolutionLevel is null");
65+
}
66+
67+
/**
68+
* Get the URL of this {@link Image}.
69+
*
70+
* @return the {@link Image}'s URL.
71+
*/
72+
@Nonnull
73+
public String getUrl() {
74+
return url;
75+
}
76+
77+
/**
78+
* Get the height of this {@link Image}.
79+
*
80+
* <p>
81+
* If it is unknown, {@link #HEIGHT_UNKNOWN} is returned instead.
82+
* </p>
83+
*
84+
* @return the {@link Image}'s height or {@link #HEIGHT_UNKNOWN}
85+
*/
86+
public int getHeight() {
87+
return height;
88+
}
89+
90+
/**
91+
* Get the width of this {@link Image}.
92+
*
93+
* <p>
94+
* If it is unknown, {@link #WIDTH_UNKNOWN} is returned instead.
95+
* </p>
96+
*
97+
* @return the {@link Image}'s width or {@link #WIDTH_UNKNOWN}
98+
*/
99+
public int getWidth() {
100+
return width;
101+
}
102+
103+
/**
104+
* Get the estimated resolution level of this image.
105+
*
106+
* <p>
107+
* If it is unknown, {@link ResolutionLevel#UNKNOWN} is returned instead.
108+
* </p>
109+
*
110+
* @return the estimated resolution level, which is never {@code null}
111+
* @see ResolutionLevel
112+
*/
113+
@Nonnull
114+
public ResolutionLevel getEstimatedResolutionLevel() {
115+
return estimatedResolutionLevel;
116+
}
117+
118+
/**
119+
* Get a string representation of this {@link Image} instance.
120+
*
121+
* <p>
122+
* The representation will be in the following format, where {@code url}, {@code height},
123+
* {@code width} and {@code estimatedResolutionLevel} represent the corresponding properties:
124+
* <br>
125+
* <br>
126+
* {@code Image {url=url, height='height, width=width,
127+
* estimatedResolutionLevel=estimatedResolutionLevel}'}
128+
* </p>
129+
*
130+
* @return a string representation of this {@link Image} instance
131+
*/
132+
@Nonnull
133+
@Override
134+
public String toString() {
135+
return "Image {" + "url=" + url + ", height=" + height + ", width=" + width
136+
+ ", estimatedResolutionLevel=" + estimatedResolutionLevel + "}";
137+
}
138+
139+
/**
140+
* The estimated resolution level of an {@link Image}.
141+
*
142+
* <p>
143+
* Some services don't return the size of their images, but we may know for a specific image
144+
* type that a service returns, according to real data, an approximation of the resolution
145+
* level.
146+
* </p>
147+
*/
148+
public enum ResolutionLevel {
149+
150+
/**
151+
* The high resolution level.
152+
*
153+
* <p>
154+
* This level applies to images with a height greater than or equal to 720px.
155+
* </p>
156+
*/
157+
HIGH,
158+
159+
/**
160+
* The medium resolution level.
161+
*
162+
* <p>
163+
* This level applies to images with a height between 175px inclusive and 720px exclusive.
164+
* </p>
165+
*/
166+
MEDIUM,
167+
168+
/**
169+
* The low resolution level.
170+
*
171+
* <p>
172+
* This level applies to images with a height between 1px inclusive and 175px exclusive.
173+
* </p>
174+
*/
175+
LOW,
176+
177+
/**
178+
* The unknown resolution level.
179+
*
180+
* <p>
181+
* This value is returned when the extractor doesn't know what resolution level an image
182+
* could have, for example if the extractor loops in an array of images with different
183+
* resolution levels without knowing the height.
184+
* </p>
185+
*/
186+
UNKNOWN;
187+
188+
/**
189+
* Get a {@link ResolutionLevel} based from the given height.
190+
*
191+
* @param heightPx the height from which returning the good {@link ResolutionLevel}
192+
* @return the {@link ResolutionLevel} corresponding to the height provided. See the
193+
* {@link ResolutionLevel} values for details about what value is returned.
194+
*/
195+
public static ResolutionLevel fromHeight(final int heightPx) {
196+
if (heightPx <= 0) {
197+
return UNKNOWN;
198+
}
199+
200+
if (heightPx < 175) {
201+
return LOW;
202+
}
203+
204+
if (heightPx < 720) {
205+
return MEDIUM;
206+
}
207+
208+
return HIGH;
209+
}
210+
}
211+
}

extractor/src/main/java/org/schabi/newpipe/extractor/InfoItem.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1-
package org.schabi.newpipe.extractor;
2-
31
/*
42
* Created by Christian Schabesberger on 11.02.17.
53
*
64
* Copyright (C) Christian Schabesberger 2017 <[email protected]>
7-
* InfoItem.java is part of NewPipe.
5+
* InfoItem.java is part of NewPipe Extractor.
86
*
9-
* NewPipe is free software: you can redistribute it and/or modify
7+
* NewPipe Extractor is free software: you can redistribute it and/or modify
108
* it under the terms of the GNU General Public License as published by
119
* the Free Software Foundation, either version 3 of the License, or
1210
* (at your option) any later version.
1311
*
14-
* NewPipe is distributed in the hope that it will be useful,
12+
* NewPipe Extractor is distributed in the hope that it will be useful,
1513
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1614
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1715
* GNU General Public License for more details.
1816
*
1917
* You should have received a copy of the GNU General Public License
20-
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
18+
* along with NewPipe Extractor. If not, see <https://www.gnu.org/licenses/>.
2119
*/
2220

21+
package org.schabi.newpipe.extractor;
22+
23+
import javax.annotation.Nonnull;
2324
import java.io.Serializable;
25+
import java.util.List;
2426

2527
public abstract class InfoItem implements Serializable {
2628
private final InfoType infoType;
2729
private final int serviceId;
2830
private final String url;
2931
private final String name;
30-
private String thumbnailUrl;
32+
@Nonnull
33+
private List<Image> thumbnails = List.of();
3134

3235
public InfoItem(final InfoType infoType,
3336
final int serviceId,
@@ -55,12 +58,13 @@ public String getName() {
5558
return name;
5659
}
5760

58-
public void setThumbnailUrl(final String thumbnailUrl) {
59-
this.thumbnailUrl = thumbnailUrl;
61+
public void setThumbnails(@Nonnull final List<Image> thumbnails) {
62+
this.thumbnails = thumbnails;
6063
}
6164

62-
public String getThumbnailUrl() {
63-
return thumbnailUrl;
65+
@Nonnull
66+
public List<Image> getThumbnails() {
67+
return thumbnails;
6468
}
6569

6670
@Override

extractor/src/main/java/org/schabi/newpipe/extractor/InfoItemExtractor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
import org.schabi.newpipe.extractor.exceptions.ParsingException;
44

5+
import javax.annotation.Nonnull;
6+
import java.util.List;
7+
58
public interface InfoItemExtractor {
69
String getName() throws ParsingException;
710
String getUrl() throws ParsingException;
8-
String getThumbnailUrl() throws ParsingException;
11+
@Nonnull
12+
List<Image> getThumbnails() throws ParsingException;
913
}

extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1-
package org.schabi.newpipe.extractor.channel;
2-
3-
import org.schabi.newpipe.extractor.Extractor;
4-
import org.schabi.newpipe.extractor.StreamingService;
5-
import org.schabi.newpipe.extractor.exceptions.ParsingException;
6-
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
7-
8-
import javax.annotation.Nonnull;
9-
import java.util.List;
10-
111
/*
122
* Created by Christian Schabesberger on 25.07.16.
133
*
144
* Copyright (C) Christian Schabesberger 2016 <[email protected]>
15-
* ChannelExtractor.java is part of NewPipe.
5+
* ChannelExtractor.java is part of NewPipe Extractor.
166
*
17-
* NewPipe is free software: you can redistribute it and/or modify
7+
* NewPipe Extractor is free software: you can redistribute it and/or modify
188
* it under the terms of the GNU General Public License as published by
199
* the Free Software Foundation, either version 3 of the License, or
2010
* (at your option) any later version.
2111
*
22-
* NewPipe is distributed in the hope that it will be useful,
12+
* NewPipe Extractor is distributed in the hope that it will be useful,
2313
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2414
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2515
* GNU General Public License for more details.
2616
*
2717
* You should have received a copy of the GNU General Public License
28-
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
18+
* along with NewPipe Extractor. If not, see <https://www.gnu.org/licenses/>.
2919
*/
3020

21+
package org.schabi.newpipe.extractor.channel;
22+
23+
import org.schabi.newpipe.extractor.Extractor;
24+
import org.schabi.newpipe.extractor.Image;
25+
import org.schabi.newpipe.extractor.StreamingService;
26+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
27+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
28+
29+
import javax.annotation.Nonnull;
30+
import java.util.List;
31+
3132
public abstract class ChannelExtractor extends Extractor {
3233

3334
public static final long UNKNOWN_SUBSCRIBER_COUNT = -1;
@@ -36,14 +37,17 @@ protected ChannelExtractor(final StreamingService service, final ListLinkHandler
3637
super(service, linkHandler);
3738
}
3839

39-
public abstract String getAvatarUrl() throws ParsingException;
40-
public abstract String getBannerUrl() throws ParsingException;
40+
@Nonnull
41+
public abstract List<Image> getAvatars() throws ParsingException;
42+
@Nonnull
43+
public abstract List<Image> getBanners() throws ParsingException;
4144
public abstract String getFeedUrl() throws ParsingException;
4245
public abstract long getSubscriberCount() throws ParsingException;
4346
public abstract String getDescription() throws ParsingException;
4447
public abstract String getParentChannelName() throws ParsingException;
4548
public abstract String getParentChannelUrl() throws ParsingException;
46-
public abstract String getParentChannelAvatarUrl() throws ParsingException;
49+
@Nonnull
50+
public abstract List<Image> getParentChannelAvatars() throws ParsingException;
4751
public abstract boolean isVerified() throws ParsingException;
4852
@Nonnull
4953
public abstract List<ListLinkHandler> getTabs() throws ParsingException;

0 commit comments

Comments
 (0)