Skip to content

Commit

Permalink
Fix test failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Nov 30, 2022
1 parent 9c23326 commit c70e29e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,8 @@ public static boolean isHardcodedYoutubeMusicKeyValid() throws IOException,
.end().done().getBytes(StandardCharsets.UTF_8);
// @formatter:on

final var headers = new HashMap<>(getOriginReferrerHeaders("https://music.youtube.com"));
final var headers = new HashMap<>(getOriginReferrerHeaders("https://music.youtube.com",
"music.youtube.com"));
headers.put("X-YouTube-Client-Name", List.of(HARDCODED_YOUTUBE_MUSIC_KEY[1]));
headers.put("X-YouTube-Client-Version", List.of(HARDCODED_YOUTUBE_MUSIC_KEY[2]));
headers.put("Content-Type", List.of("application/json"));
Expand Down Expand Up @@ -1411,8 +1412,19 @@ public static Map<String, List<String>> getClientInfoHeaders()
* @param url The URL to be set as the origin and referrer.
*/
public static Map<String, List<String>> getOriginReferrerHeaders(@Nonnull final String url) {
final var urlList = List.of(url);
return Map.of("Origin", urlList, "Referer", urlList);
return getOriginReferrerHeaders(url, url);
}

/**
* Returns an unmodifiable {@link Map} containing the {@code Origin} and {@code Referer}
* headers set to the given values.
*
* @param origin The origin.
* @param referrer The referrer.
*/
public static Map<String, List<String>> getOriginReferrerHeaders(
@Nonnull final String origin, @Nonnull final String referrer) {
return Map.of("Origin", List.of(origin), "Referer", List.of(referrer));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -117,8 +116,8 @@ public void onFetchPage(@Nonnull final Downloader downloader)
.end().done().getBytes(StandardCharsets.UTF_8);
// @formatter:on

final Map<String, List<String>> headers = new HashMap<>(getOriginReferrerHeaders(
"https://music.youtube.com"));
final var headers = new HashMap<>(getOriginReferrerHeaders("https://music.youtube.com",
"music.youtube.com"));
headers.put("X-YouTube-Client-Name", List.of(youtubeMusicKeys[1]));
headers.put("X-YouTube-Client-Version", List.of(youtubeMusicKeys[2]));
headers.put("Content-Type", List.of("application/json"));
Expand Down Expand Up @@ -251,8 +250,8 @@ public InfoItemsPage<InfoItem> getPage(final Page page)
.end().done().getBytes(StandardCharsets.UTF_8);
// @formatter:on

final Map<String, List<String>> headers = new HashMap<>(getOriginReferrerHeaders(
"https://music.youtube.com"));
final var headers = new HashMap<>(getOriginReferrerHeaders("https://music.youtube.com",
"music.youtube.com"));
headers.put("X-YouTube-Client-Name", List.of(youtubeMusicKeys[1]));
headers.put("X-YouTube-Client-Version", List.of(youtubeMusicKeys[2]));
headers.put("Content-Type", List.of("application/json"));
Expand Down

0 comments on commit c70e29e

Please sign in to comment.