Files
2026-02-21 16:45:37 +08:00

241 lines
7.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using Crosstales.Radio.Model.Enum;
using Crosstales.Radio.Util;
using UnityEngine;
namespace Crosstales.Radio.Model
{
[Serializable]
public class RadioStation
{
[Tooltip("Name of the radio station.")]
[Header("Station Settings")]
public string Name;
[Tooltip("URL of the station.")]
public string Url;
[Tooltip("Name of the station.")]
[Header("Meta Data")]
public string Station;
[Tooltip("Genres of the radio.")]
public string Genres;
[Range(0f, 6f)]
[Tooltip("Your rating of the radio.")]
public float Rating;
[Multiline]
[Tooltip("Description of the radio station.")]
public string Description;
[Tooltip("Icon to represent the radio station.")]
public Sprite Icon;
[Tooltip("Audio format of the station.")]
[Header("Stream Settings")]
public AudioFormat Format = AudioFormat.MP3;
[Tooltip("Bitrate in kbit/s (default: 128).")]
public int Bitrate = Config.DEFAULT_BITRATE;
[Tooltip("Size of the streaming-chunk in KB (default: 32).")]
public int ChunkSize = Config.DEFAULT_CHUNKSIZE;
[Tooltip("Size of the local buffer in KB (default: 64).")]
public int BufferSize = Config.DEFAULT_BUFFERSIZE;
[Tooltip("Exclude this station if the current RadioPlayer codec is equals this one (default: AudioCodec.None).")]
[Header("Codec Settings")]
public AudioCodec ExcludedCodec;
[HideInInspector]
public long TotalDataSize;
[HideInInspector]
public int TotalDataRequests;
[HideInInspector]
public float TotalPlayTime;
public readonly List<RecordInfo> PlayedRecords = new List<RecordInfo>();
private const char splitCharText = ';';
public RadioStation()
{
}
public RadioStation(string name, string url, AudioFormat format)
{
Name = name.CTToTitleCase();
Url = url;
Format = format;
}
public RadioStation(string name, string url, AudioFormat format, string station, string genres, int bitrate, float rating, string description, Sprite icon, int chunkSize = 64, int bufferSize = 64, AudioCodec excludeCodec = AudioCodec.None)
: this(name, url, format)
{
Station = station;
Genres = genres;
Bitrate = bitrate;
Rating = rating;
Description = description;
Icon = icon;
ChunkSize = chunkSize;
BufferSize = bufferSize;
ExcludedCodec = excludeCodec;
}
public string ToTextLine(bool detailed = false)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(Name);
stringBuilder.Append(';');
stringBuilder.Append(Url);
stringBuilder.Append(';');
stringBuilder.Append("Stream");
stringBuilder.Append(';');
stringBuilder.Append(Format);
stringBuilder.Append(';');
stringBuilder.Append(Station);
stringBuilder.Append(';');
stringBuilder.Append(Genres);
stringBuilder.Append(';');
stringBuilder.Append(Bitrate);
stringBuilder.Append(';');
stringBuilder.Append(Rating);
stringBuilder.Append(';');
stringBuilder.Append(Description);
stringBuilder.Append(';');
stringBuilder.Append(ExcludedCodec);
if (detailed)
{
stringBuilder.Append(';');
stringBuilder.Append(ChunkSize);
stringBuilder.Append(';');
stringBuilder.Append(BufferSize);
}
return stringBuilder.ToString();
}
public string ToShortString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("Name='");
stringBuilder.Append(Name);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Url='");
stringBuilder.Append(Url);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Station='");
stringBuilder.Append(Station);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Genres='");
stringBuilder.Append(Genres);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Rating='");
stringBuilder.Append(Rating);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Description='");
stringBuilder.Append(Description);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Icon='");
stringBuilder.Append(Icon);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("AudioFormat='");
stringBuilder.Append(Format);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Bitrate='");
stringBuilder.Append(Bitrate);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("ChunkSize='");
stringBuilder.Append(ChunkSize);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("BufferSize='");
stringBuilder.Append(BufferSize);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("ExcludedCodec='");
stringBuilder.Append(ExcludedCodec);
stringBuilder.Append("'");
return stringBuilder.ToString();
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
RadioStation radioStation = obj as RadioStation;
if (radioStation == null)
{
return false;
}
return Url == radioStation.Url;
}
public override int GetHashCode()
{
return Url.GetHashCode();
}
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(GetType().Name);
stringBuilder.Append(Constants.TEXT_TOSTRING_START);
stringBuilder.Append("Name='");
stringBuilder.Append(Name);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Url='");
stringBuilder.Append(Url);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Station='");
stringBuilder.Append(Station);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Genres='");
stringBuilder.Append(Genres);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Rating='");
stringBuilder.Append(Rating);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Description='");
stringBuilder.Append(Description);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Icon='");
stringBuilder.Append(Icon);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("AudioFormat='");
stringBuilder.Append(Format);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Bitrate='");
stringBuilder.Append(Bitrate);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("ChunkSize='");
stringBuilder.Append(ChunkSize);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("BufferSize='");
stringBuilder.Append(BufferSize);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("ExcludedCodec='");
stringBuilder.Append(ExcludedCodec);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("TotalDataSize='");
stringBuilder.Append(TotalDataSize);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("TotalDataRequests='");
stringBuilder.Append(TotalDataRequests);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("TotalPlayTime='");
stringBuilder.Append(TotalPlayTime);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER_END);
stringBuilder.Append(Constants.TEXT_TOSTRING_END);
return stringBuilder.ToString();
}
}
}