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 May 12, 2024
1 parent 2f5cd87 commit 76c7702
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 @@ -205,6 +205,7 @@
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.NekoXConfig;

import tw.nekomimi.nekogram.utils.NeteaseEmbed;
import xyz.nextalone.nagram.NaConfig;

import static xyz.nextalone.nagram.helper.MessageHelper.showForwardDate;
Expand Down Expand Up @@ -5588,6 +5589,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 tw.nekomimi.nekogram.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 76c7702

Please sign in to comment.