Skip to content

Commit

Permalink
feat: netease embed player
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Jun 10, 2024
1 parent 25b57ac commit 6197733
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
import xyz.nextalone.gen.Config;
import xyz.nextalone.nnngram.config.ConfigManager;
import xyz.nextalone.nnngram.utils.Defines;
import xyz.nextalone.nnngram.utils.NeteaseEmbed;
import xyz.nextalone.nnngram.utils.StringUtils;
import xyz.nextalone.nnngram.utils.Utils;

Expand Down Expand Up @@ -5615,6 +5616,7 @@ private void setMessageContent(MessageObject messageObject, MessageObject.Groupe

drawInstantView = hasLinkPreview && webpage.cached_page != null;
String siteName = hasLinkPreview ? webpage.site_name : null;
NeteaseEmbed.fixWebPage(webpage);
hasEmbed = hasLinkPreview && !TextUtils.isEmpty(webpage.embed_url) && !messageObject.isGif() && !"instagram".equalsIgnoreCase(siteName);
boolean slideshow = false;
String webpageType = webpage != null ? webpage.type : null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package xyz.nextalone.nnngram.utils

import org.telegram.tgnet.TLRPC;

public class NeteaseEmbed {

public static boolean isNeteaseWebPage(String url) {
return url != null && url.startsWith("music.163.com/");
}

public static String getNeteaseAlbumId(String url) {
if (url.contains("album")) {
return url.replace("music.163.com/album?id=", "");
}
return null;
}

public static String getNeteaseAlbumEmbed(String id) {
return "https://music.163.com/outchain/player?type=1&auto=1&id=" + id;
}

public static String getNeteaseSongId(String url) {
if (url.contains("song")) {
return url.replace("music.163.com/song?id=", "");
}
return null;
}

public static String getNeteaseSongEmbed(String id) {
return "https://music.163.com/outchain/player?type=2&auto=1&id=" + id;
}

public static void fixWebPage(TLRPC.WebPage webpage) {
if (webpage == null || !isNeteaseWebPage(webpage.display_url)) {
return;
}
String albumId = getNeteaseAlbumId(webpage.display_url);
String songId = getNeteaseSongId(webpage.display_url);
if (albumId != null) {
webpage.embed_url = getNeteaseAlbumEmbed(albumId);
webpage.embed_type = "iframe";
webpage.embed_width = 300;
webpage.embed_height = 380;
}
if (songId != null) {
webpage.embed_url = getNeteaseSongEmbed(songId);
webpage.embed_type = "iframe";
webpage.embed_width = 300;
webpage.embed_height = 380;
}
}
}

0 comments on commit 6197733

Please sign in to comment.