Initial commit
This commit is contained in:
commit
262601edb8
2025 files changed
+218754
No files matched your search
@@ -0,0 +1,110 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine;
|
||||
using TagLib;
|
||||
using System;
|
||||
using BangerTypes;
|
||||
using NAudio.Wave;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
|
||||
namespace MenuAndSongs
|
||||
{
|
||||
public class FindSongs
|
||||
{
|
||||
public static List<string> Find(string songPath)
|
||||
{
|
||||
if (!Directory.Exists(songPath))
|
||||
Directory.CreateDirectory(songPath);
|
||||
|
||||
List<string> ls = Directory
|
||||
.GetFiles(songPath)
|
||||
.Where(file => Regex.IsMatch(file, ".*\\.mp3"))
|
||||
.ToList();
|
||||
|
||||
return ls;
|
||||
}
|
||||
|
||||
public static Song ParseRHYS(string rhysPath, Sprite defaultImage)
|
||||
{
|
||||
string jsonContent = System.IO.File.ReadAllText(rhysPath);
|
||||
Rhys rhys = JsonUtility.FromJson<Rhys>(jsonContent);
|
||||
|
||||
string title = "<b>" + (rhys.title ?? "Title not found") + "</b>";
|
||||
string artist = String.IsNullOrEmpty(rhys.artist) ? "Artist not found" : "By: <b>" + rhys.artist + "</b>";
|
||||
string album = "Album information not available";
|
||||
|
||||
TimeSpan duration = TimeSpan.FromSeconds(rhys.track_time);
|
||||
string formattedTimeSpan = string.Format("{0:D2}:{1:D2}:{2:D2}",
|
||||
(int)duration.TotalHours,
|
||||
duration.Minutes,
|
||||
duration.Seconds);
|
||||
|
||||
Sprite coverImage;
|
||||
if (!string.IsNullOrEmpty(rhys.cover_art))
|
||||
{
|
||||
byte[] imageBytes = Convert.FromBase64String(rhys.cover_art);
|
||||
Texture2D texture = new Texture2D(2, 2);
|
||||
texture.LoadImage(imageBytes);
|
||||
coverImage = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
||||
}
|
||||
else
|
||||
{
|
||||
coverImage = defaultImage;
|
||||
}
|
||||
|
||||
var notes = rhys.notes;
|
||||
Debug.Log("NOTES: ");
|
||||
Debug.Log(notes);
|
||||
|
||||
return new()
|
||||
{
|
||||
Title = title,
|
||||
Artist = artist,
|
||||
Album = album,
|
||||
DurationSpan = duration,
|
||||
Duration = formattedTimeSpan,
|
||||
CoverArt = coverImage,
|
||||
Clip = LoadAudioFromBase64(rhys.audio)
|
||||
};
|
||||
}
|
||||
|
||||
private static AudioClip LoadAudioFromBase64(string base64String)
|
||||
{
|
||||
// Decode Base64 String to byte array
|
||||
byte[] mp3Bytes = Convert.FromBase64String(base64String);
|
||||
|
||||
// Create a temporary file path
|
||||
string tempFilePath = Path.Combine(Application.persistentDataPath, "tempMp3File.mp3");
|
||||
System.IO.File.WriteAllBytes(tempFilePath, mp3Bytes);
|
||||
|
||||
// Load the AudioClip synchronously
|
||||
AudioClip clip = LoadAudioSync(tempFilePath);
|
||||
|
||||
// Optionally delete the temporary file if no longer needed
|
||||
System.IO.File.Delete(tempFilePath);
|
||||
|
||||
return clip;
|
||||
}
|
||||
|
||||
private static AudioClip LoadAudioSync(string filePath)
|
||||
{
|
||||
UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip("file://" + filePath, AudioType.MPEG);
|
||||
var operation = uwr.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
; // Busy wait - not recommended
|
||||
|
||||
if (uwr.result == UnityWebRequest.Result.Success)
|
||||
{
|
||||
return DownloadHandlerAudioClip.GetContent(uwr);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Error loading audio clip: " + uwr.error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 653a02710366ea592b0b57a41d8d165a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MenuAndSongs
|
||||
{
|
||||
[CreateAssetMenu(fileName = "SongData", menuName = "Custom/Song Data")]
|
||||
public class SongData : ScriptableObject
|
||||
{
|
||||
public static string songPath;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87a87ffb34f411f57934067574b91792
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user