-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
TMessagesProj/src/main/java/tw/nekomimi/nekogram/utils/NeteaseEmbed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |