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

Move twitch URLs to appropriate class, fix #51 #57

Merged
merged 4 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class TwitchConstants {
static final String TWITCH_GRAPHQL_BASE_URL = "https://gql.twitch.tv/gql";
static final String TWITCH_URL = "https://www.twitch.tv";
static final String TWITCH_IMAGE_PREVIEW_URL = "https://static-cdn.jtvnw.net/previews-ttv/live_user_%s-440x248.jpg";
static final String METADATA_PAYLOAD = "{\"operationName\":\"StreamMetadata\",\"variables\":{\"channelLogin\":\"%s\"},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"1c719a40e481453e5c48d9bb585d971b8b372f8ebb105b17076722264dfa5b3e\"}}}";
static final String ACCESS_TOKEN_PAYLOAD = "{\"operationName\":\"PlaybackAccessToken_Template\",\"query\":\"query PlaybackAccessToken_Template($login: String!,$isLive:Boolean!,$vodID:ID!,$isVod:Boolean!,$playerType:String!){streamPlaybackAccessToken(channelName:$login,params:{platform:\\\"web\\\",playerBackend:\\\"mediaplayer\\\",playerType:$playerType})@include(if:$isLive){value signature __typename}videoPlaybackAccessToken(id:$vodID,params:{platform:\\\"web\\\",playerBackend:\\\"mediaplayer\\\",playerType:$playerType})@include(if:$isVod){value signature __typename}}\",\"variables\":{\"isLive\":true,\"login\":\"%s\",\"isVod\":false,\"vodID\":\"\",\"playerType\":\"site\"}}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public String getSourceName() {

@Override
public AudioItem loadItem(AudioPlayerManager manager, AudioReference reference) {
String streamName = getChannelIdentifierFromUrl(reference.identifier);
// Using root because the turkish lowercase "i" does not have the little dot above the letter when defaulted
String streamName = getChannelIdentifierFromUrl(reference.identifier).toLowerCase(Locale.ROOT);
devoxin marked this conversation as resolved.
Show resolved Hide resolved
if (streamName == null) {
return null;
}
Expand All @@ -79,26 +80,24 @@ public AudioItem loadItem(AudioPlayerManager manager, AudioReference reference)

if (channelInfo == null || channelInfo.get("stream").get("type").isNull()) {
return AudioReference.NO_TRACK;
} else {
String title = channelInfo.get("lastBroadcast").get("title").text();

final String thumbnail = String.format(
"https://static-cdn.jtvnw.net/previews-ttv/live_user_%s-440x248.jpg",
// Using root because the turkish lowercase "i" does not have the little dot above the letter when defaulted
streamName.toLowerCase(Locale.ROOT)
);

return new TwitchStreamAudioTrack(new AudioTrackInfo(
title,
streamName,
Units.DURATION_MS_UNKNOWN,
reference.identifier,
true,
reference.identifier,
thumbnail,
null
), this);
}
String title = channelInfo.get("lastBroadcast").get("title").text();

final String thumbnail = String.format(
TwitchConstants.TWITCH_IMAGE_PREVIEW_URL,
streamName
);

return new TwitchStreamAudioTrack(new AudioTrackInfo(
title,
streamName,
Units.DURATION_MS_UNKNOWN,
reference.identifier,
true,
reference.identifier,
thumbnail,
null
), this);
}

@Override
Expand Down Expand Up @@ -194,7 +193,7 @@ private JsonBrowser fetchStreamChannelInfo(String channelId) {

private void initRequestHeaders() {
try (HttpInterface httpInterface = getHttpInterface()) {
HttpGet get = new HttpGet("https://www.twitch.tv");
HttpGet get = new HttpGet(TwitchConstants.TWITCH_URL);
get.setHeader("Accept", "text/html");
CloseableHttpResponse response = httpInterface.execute(get);
HttpClientTools.assertSuccessWithContent(response, "twitch main page");
Expand Down