|
30 | 30 | import java.io.IOException; |
31 | 31 | import java.net.URLEncoder; |
32 | 32 | import java.nio.charset.StandardCharsets; |
| 33 | +import java.security.MessageDigest; |
| 34 | +import java.security.NoSuchAlgorithmException; |
33 | 35 | import java.time.Duration; |
34 | | -import java.util.ArrayList; |
35 | | -import java.util.Collections; |
36 | | -import java.util.List; |
37 | | -import java.util.Set; |
| 36 | +import java.util.*; |
38 | 37 | import java.util.function.Consumer; |
39 | 38 | import java.util.function.Function; |
40 | 39 | import java.util.regex.Pattern; |
41 | 40 | import java.util.stream.Collectors; |
42 | 41 |
|
43 | 42 | public class DeezerAudioSourceManager extends ExtendedAudioSourceManager implements HttpConfigurable, AudioSearchManager, AudioLyricsManager { |
| 43 | + private static final byte[] decryptionKeyHash = new byte[] { |
| 44 | + 52, 76, 41, -118, 120, -123, 48, 72, -58, 74, 16, 75, 82, 101, -70, -33, 15, -66, 111, -38, -80, 71, 103, 11, -75, -120, -101, -9, 66, -53, -38, -16 |
| 45 | + }; |
44 | 46 |
|
45 | 47 | public static final Pattern URL_PATTERN = Pattern.compile("(https?://)?(www\\.)?deezer\\.com/(?<countrycode>[a-zA-Z]{2}/)?(?<type>track|album|playlist|artist)/(?<identifier>[0-9]+)"); |
46 | 48 | public static final String SEARCH_PREFIX = "dzsearch:"; |
@@ -75,12 +77,26 @@ public DeezerAudioSourceManager(String masterDecryptionKey, @Nullable String arl |
75 | 77 | throw new IllegalArgumentException("Deezer master key must be set"); |
76 | 78 | } |
77 | 79 |
|
| 80 | + if (!validateDecryptionKey(masterDecryptionKey)) { |
| 81 | + log.warn("Deezer master decryption key is possibly invalid, playback may not work!"); |
| 82 | + } |
| 83 | + |
78 | 84 | this.masterDecryptionKey = masterDecryptionKey; |
79 | 85 | this.tokenTracker = new DeezerTokenTracker(this, arl); |
80 | 86 | this.formats = formats != null && formats.length > 0 ? formats : DeezerAudioTrack.TrackFormat.DEFAULT_FORMATS; |
81 | 87 | this.httpInterfaceManager = HttpClientTools.createCookielessThreadLocalManager(); |
82 | 88 | } |
83 | 89 |
|
| 90 | + public boolean validateDecryptionKey(String masterDecryptionKey) { |
| 91 | + try { |
| 92 | + MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); |
| 93 | + messageDigest.update(masterDecryptionKey.getBytes(StandardCharsets.UTF_8)); |
| 94 | + return Arrays.equals(messageDigest.digest(), decryptionKeyHash); |
| 95 | + } catch (NoSuchAlgorithmException e) { |
| 96 | + return false; |
| 97 | + } |
| 98 | + } |
| 99 | + |
84 | 100 | static void checkResponse(JsonBrowser json, String message) throws IllegalStateException { |
85 | 101 | if (json == null) { |
86 | 102 | throw new IllegalStateException(message + "No response"); |
|
0 commit comments