11package org .schabi .newpipe .extractor .services .youtube .extractors ;
22
3- import com .grack .nanojson .JsonObject ;
4- import com .grack .nanojson .JsonParser ;
5- import com .grack .nanojson .JsonParserException ;
63import java .io .IOException ;
74import javax .annotation .Nonnull ;
85import javax .annotation .Nullable ;
9- import org .jsoup .Jsoup ;
106import org .jsoup .nodes .Document ;
117import org .jsoup .nodes .Element ;
128import org .schabi .newpipe .extractor .StreamingService ;
@@ -50,7 +46,16 @@ public String getName() throws ParsingException {
5046 @ Override
5147 public String getThumbnailUrl () throws ParsingException {
5248 try {
53- return doc .select ("ol[class*=\" playlist-videos-list\" ] li" ).first ().attr ("data-thumbnail-url" );
49+ Element li = doc .select ("ol[class*=\" playlist-videos-list\" ] li" ).first ();
50+ String videoId = li .attr ("data-video-id" );
51+ if (videoId != null && !videoId .isEmpty ()) {
52+ //higher quality
53+ return getThumbnailUrlFromId (videoId );
54+ } else {
55+ //lower quality
56+ return doc .select ("ol[class*=\" playlist-videos-list\" ] li" ).first ()
57+ .attr ("data-thumbnail-url" );
58+ }
5459 } catch (Exception e ) {
5560 throw new ParsingException ("Could not get playlist thumbnail" , e );
5661 }
@@ -146,21 +151,18 @@ public String getName() throws ParsingException {
146151 }
147152
148153 @ Override
149- public long getDuration () throws ParsingException {
154+ public long getDuration () {
150155 //Not present in doc
151156 return 0 ;
152157 }
153158
154159 @ Override
155160 public String getUploaderName () throws ParsingException {
156- try {
157- return li .select (
158- "div[class=\" playlist-video-description\" ]"
159- + "span[class=\" video-uploader-byline\" ]" )
160- .first ()
161- .text ();
162- } catch (Exception e ) {
163- throw new ParsingException ("Could not get uploader" , e );
161+ String uploaderName = li .attr ("data-video-username" );
162+ if (uploaderName == null || uploaderName .isEmpty ()) {
163+ throw new ParsingException ("Could not get uploader name" );
164+ } else {
165+ return uploaderName ;
164166 }
165167 }
166168
@@ -184,13 +186,16 @@ public long getViewCount() {
184186 @ Override
185187 public String getThumbnailUrl () throws ParsingException {
186188 try {
187- return "https://i.ytimg.com/vi/" + streamLinkHandlerFactory .fromUrl (getUrl ()).getId ()
188- + "/hqdefault.jpg" ;
189+ return getThumbnailUrlFromId (streamLinkHandlerFactory .fromUrl (getUrl ()).getId ());
189190 } catch (Exception e ) {
190191 throw new ParsingException ("Could not get thumbnail url" , e );
191192 }
192193 }
193194 });
194195 }
195196 }
197+
198+ private String getThumbnailUrlFromId (String videoId ) {
199+ return "https://i.ytimg.com/vi/" + videoId + "/hqdefault.jpg" ;
200+ }
196201}
0 commit comments