Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
lasers
NewPipeExtractor
Commits
c2525916
Unverified
Commit
c2525916
authored
Feb 12, 2021
by
Tobi
Committed by
GitHub
Feb 12, 2021
Browse files
Merge pull request #539 from B0pol/yt-channel-continuation
[YouTube]: Fixed channel continuation
parents
c4b91836
b0f356dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java
View file @
c2525916
...
...
@@ -20,9 +20,7 @@ import org.schabi.newpipe.extractor.utils.Utils;
import
javax.annotation.Nonnull
;
import
java.io.IOException
;
import
static
org
.
schabi
.
newpipe
.
extractor
.
services
.
youtube
.
YoutubeParsingHelper
.
fixThumbnailUrl
;
import
static
org
.
schabi
.
newpipe
.
extractor
.
services
.
youtube
.
YoutubeParsingHelper
.
getJsonResponse
;
import
static
org
.
schabi
.
newpipe
.
extractor
.
services
.
youtube
.
YoutubeParsingHelper
.
getTextFromObject
;
import
static
org
.
schabi
.
newpipe
.
extractor
.
services
.
youtube
.
YoutubeParsingHelper
.*;
import
static
org
.
schabi
.
newpipe
.
extractor
.
utils
.
JsonUtils
.
EMPTY_STRING
;
import
static
org
.
schabi
.
newpipe
.
extractor
.
utils
.
Utils
.
isNullOrEmpty
;
...
...
@@ -230,9 +228,9 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
.
getArray
(
"contents"
).
getObject
(
0
).
getObject
(
"itemSectionRenderer"
)
.
getArray
(
"contents"
).
getObject
(
0
).
getObject
(
"gridRenderer"
);
collectStreamsFrom
(
collector
,
gridRenderer
.
getArray
(
"items"
));
final
JsonObject
continuation
=
collectStreamsFrom
(
collector
,
gridRenderer
.
getArray
(
"items"
));
nextPage
=
getNextPageFrom
(
gridRenderer
.
getArray
(
"
continuation
s"
)
);
nextPage
=
getNextPageFrom
(
continuation
);
}
return
new
InfoItemsPage
<>(
collector
,
nextPage
);
...
...
@@ -252,36 +250,47 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
final
JsonArray
ajaxJson
=
getJsonResponse
(
page
.
getUrl
(),
getExtractorLocalization
());
JsonObject
sectionListContinuation
=
ajaxJson
.
getObject
(
1
).
getObject
(
"response"
)
.
get
Object
(
"continuationContents"
).
getObject
(
"
gri
dContinuation"
);
.
get
Array
(
"onResponseReceivedActions"
).
getObject
(
0
).
getObject
(
"
appen
dContinuation
ItemsAction
"
);
collectStreamsFrom
(
collector
,
sectionListContinuation
.
getArray
(
"
i
tems"
));
final
JsonObject
continuation
=
collectStreamsFrom
(
collector
,
sectionListContinuation
.
getArray
(
"
continuationI
tems"
));
return
new
InfoItemsPage
<>(
collector
,
getNextPageFrom
(
sectionListContinuation
.
getArray
(
"
continuation
s"
)
));
return
new
InfoItemsPage
<>(
collector
,
getNextPageFrom
(
continuation
));
}
private
Page
getNextPageFrom
(
final
Json
Array
continuations
)
{
private
Page
getNextPageFrom
(
final
Json
Object
continuations
)
{
if
(
isNullOrEmpty
(
continuations
))
{
return
null
;
}
final
JsonObject
nextC
ontinuation
Data
=
continuations
.
getObject
(
0
).
getObject
(
"nextC
ontinuation
Data
"
);
final
String
continuation
=
nextC
ontinuation
Data
.
getString
(
"continuatio
n"
);
final
String
clickTrackingParams
=
nextC
ontinuation
Data
.
getString
(
"clickTrackingParams"
);
final
JsonObject
c
ontinuation
Endpoint
=
continuations
.
getObject
(
"c
ontinuation
Endpoint
"
);
final
String
continuation
=
c
ontinuation
Endpoint
.
getObject
(
"continuationCommand"
).
getString
(
"toke
n"
);
final
String
clickTrackingParams
=
c
ontinuation
Endpoint
.
getString
(
"clickTrackingParams"
);
return
new
Page
(
"https://www.youtube.com/browse_ajax?ctoken="
+
continuation
+
"&continuation="
+
continuation
+
"&itct="
+
clickTrackingParams
);
}
private
void
collectStreamsFrom
(
StreamInfoItemsCollector
collector
,
JsonArray
videos
)
throws
ParsingException
{
/**
* Collect streams from an array of items
*
* @param collector the collector where videos will be commited
* @param videos the array to get videos from
* @return the continuation object
* @throws ParsingException if an error happened while extracting
*/
private
JsonObject
collectStreamsFrom
(
StreamInfoItemsCollector
collector
,
JsonArray
videos
)
throws
ParsingException
{
collector
.
reset
();
final
String
uploaderName
=
getName
();
final
String
uploaderUrl
=
getUrl
();
final
TimeAgoParser
timeAgoParser
=
getTimeAgoParser
();
for
(
Object
video
:
videos
)
{
if
(((
JsonObject
)
video
).
has
(
"gridVideoRenderer"
))
{
JsonObject
continuation
=
null
;
for
(
Object
object
:
videos
)
{
final
JsonObject
video
=
(
JsonObject
)
object
;
if
(
video
.
has
(
"gridVideoRenderer"
))
{
collector
.
commit
(
new
YoutubeStreamInfoItemExtractor
(
((
JsonObject
)
video
)
.
getObject
(
"gridVideoRenderer"
),
timeAgoParser
)
{
video
.
getObject
(
"gridVideoRenderer"
),
timeAgoParser
)
{
@Override
public
String
getUploaderName
()
{
return
uploaderName
;
...
...
@@ -292,8 +301,12 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
return
uploaderUrl
;
}
});
}
else
if
(
video
.
has
(
"continuationItemRenderer"
))
{
continuation
=
video
.
getObject
(
"continuationItemRenderer"
);
}
}
return
continuation
;
}
private
JsonObject
getVideoTab
()
throws
ParsingException
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment