List song titles from CDN
This commit is contained in:
parent
ace6df9dfe
commit
2aa0829bfc
@ -5,28 +5,84 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace TJAPlayer3
|
||||
{
|
||||
internal class API
|
||||
{
|
||||
public API(int selectedCDN)
|
||||
|
||||
public class APISongData
|
||||
{
|
||||
public string SongTitle;
|
||||
}
|
||||
|
||||
#region [ContractResolver override for properties]
|
||||
|
||||
public class SongContractResolver : DefaultContractResolver
|
||||
{
|
||||
private Dictionary<string, string> PropertyMappings { get; set; }
|
||||
|
||||
public SongContractResolver(DBCDN.CDNData cdnData)
|
||||
{
|
||||
this.PropertyMappings = new Dictionary<string, string>
|
||||
{
|
||||
{"SongTitle", cdnData.Hooks.title["default"]},
|
||||
};
|
||||
}
|
||||
|
||||
protected override string ResolvePropertyName(string propertyName)
|
||||
{
|
||||
string resolvedName = null;
|
||||
var resolved = this.PropertyMappings.TryGetValue(propertyName, out resolvedName);
|
||||
return (resolved) ? resolvedName : base.ResolvePropertyName(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public API(DBCDN.CDNData selectedCDN)
|
||||
{
|
||||
cdnData = selectedCDN;
|
||||
FetchedSongsList = new APISongData[0];
|
||||
}
|
||||
|
||||
public APISongData[] FetchedSongsList;
|
||||
|
||||
public void tLoadSongsFromInternalCDN()
|
||||
{
|
||||
string url = cdnData.BaseUrl + cdnData.SongList;
|
||||
|
||||
|
||||
var _fetched = GetCallAPI(url);
|
||||
|
||||
_fetched.Wait();
|
||||
|
||||
if (_fetched.Result != null)
|
||||
FetchedSongsList = _fetched.Result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async Task<object> PostCallAPI(string url, object jsonObject)
|
||||
#region [private]
|
||||
|
||||
private DBCDN.CDNData cdnData;
|
||||
|
||||
private async Task<APISongData[]> GetCallAPI(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
var content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");
|
||||
var response = await client.PostAsync(url, content);
|
||||
var response = await client.GetAsync(url).ConfigureAwait(false);
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
var jsonString = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<object>(jsonString);
|
||||
var jsonString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
var settings = new JsonSerializerSettings();
|
||||
settings.ContractResolver = new SongContractResolver(cdnData);
|
||||
return JsonConvert.DeserializeObject<APISongData[]>(jsonString, settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -37,26 +93,8 @@ namespace TJAPlayer3
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<object> GetCallAPI(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
var response = await client.GetAsync(url);
|
||||
if (response != null)
|
||||
{
|
||||
var jsonString = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<object>(jsonString);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -174,6 +174,39 @@ namespace TJAPlayer3
|
||||
|
||||
#endregion
|
||||
|
||||
#region [Song list menu]
|
||||
|
||||
if (currentMenu == ECurrentMenu.CDN_SONGS)
|
||||
{
|
||||
_ref = this.ttkCDNSongList;
|
||||
_selector = cdnSongListIndex;
|
||||
|
||||
int baseY = 360;
|
||||
|
||||
for (int i = -4; i < 4; i++)
|
||||
{
|
||||
int pos = (_ref.Length * 5 + _selector + i) % _ref.Length;
|
||||
|
||||
CTexture tmpTex = TJAPlayer3.stage選曲.act曲リスト.ResolveTitleTexture(_ref[pos]);
|
||||
|
||||
if (_selector != pos)
|
||||
{
|
||||
tmpTex.color4 = C変換.ColorToColor4(Color.DarkGray);
|
||||
TJAPlayer3.Tx.OnlineLounge_Song_Box?.tUpdateColor4(C変換.ColorToColor4(Color.DarkGray));
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpTex.color4 = C変換.ColorToColor4(Color.White);
|
||||
TJAPlayer3.Tx.OnlineLounge_Song_Box?.tUpdateColor4(C変換.ColorToColor4(Color.White));
|
||||
}
|
||||
|
||||
TJAPlayer3.Tx.OnlineLounge_Song_Box?.t2D拡大率考慮上中央基準描画(TJAPlayer3.app.Device, 350, baseY + 100 * i);
|
||||
tmpTex.t2D拡大率考慮上中央基準描画(TJAPlayer3.app.Device, 350, baseY + 18 + 100 * i);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
@ -284,6 +317,26 @@ namespace TJAPlayer3
|
||||
TJAPlayer3.Skin.sound取消音.t再生する();
|
||||
else
|
||||
{
|
||||
if (currentMenu == ECurrentMenu.CDN_SONGS)
|
||||
{
|
||||
apiMethods = new API(dbCDNData);
|
||||
apiMethods.tLoadSongsFromInternalCDN();
|
||||
|
||||
#region [Generate song list values]
|
||||
|
||||
this.ttkCDNSongList = new TitleTextureKey[apiMethods.FetchedSongsList.Length + 1];
|
||||
|
||||
this.ttkCDNSongList[0] = new TitleTextureKey(CLangManager.LangInstance.GetString(401), this.pfOLFont, Color.White, Color.DarkRed, 1000);
|
||||
|
||||
for (int i = 0; i < apiMethods.FetchedSongsList.Length; i++)
|
||||
{
|
||||
this.ttkCDNSongList[i + 1] = new TitleTextureKey(apiMethods.FetchedSongsList[i].SongTitle, this.pfOLFont, Color.White, Color.DarkRed, 1000);
|
||||
}
|
||||
|
||||
this.cdnSongListIndex = 0;
|
||||
|
||||
#endregion
|
||||
}
|
||||
TJAPlayer3.Skin.sound決定音.t再生する();
|
||||
}
|
||||
|
||||
@ -338,6 +391,10 @@ namespace TJAPlayer3
|
||||
|
||||
cdnOptMenuIndex += val;
|
||||
}
|
||||
else if (currentMenu == ECurrentMenu.CDN_SONGS)
|
||||
{
|
||||
cdnSongListIndex = (ttkCDNSongList.Length + cdnSongListIndex + val) % ttkCDNSongList.Length;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -376,6 +433,7 @@ namespace TJAPlayer3
|
||||
|
||||
private DBCDN dbCDN;
|
||||
private DBCDN.CDNData dbCDNData;
|
||||
private API apiMethods;
|
||||
|
||||
// Main Menu
|
||||
private TitleTextureKey[] ttkMainMenuOpt;
|
||||
@ -391,6 +449,10 @@ namespace TJAPlayer3
|
||||
private ECurrentMenu[] cdnOptMenu;
|
||||
private int cdnOptMenuIndex;
|
||||
|
||||
// CDN List songs option
|
||||
private TitleTextureKey[] ttkCDNSongList;
|
||||
private int cdnSongListIndex;
|
||||
|
||||
private class CMenuInfo
|
||||
{
|
||||
public CMenuInfo(string ttl)
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"Pidgey's TJADB CDN" : {
|
||||
"baseUrl": "https://dev.pidgey.net:8443/",
|
||||
"baseUrl": "https://dev.pidgey.net/",
|
||||
"download": {
|
||||
"en": "download/en/",
|
||||
"default": "download/orig/",
|
||||
|
Loading…
Reference in New Issue
Block a user