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

95 lines
3.1 KiB
C#

using System;
using System.Text;
using Crosstales.Radio.Model.Enum;
using Crosstales.Radio.Util;
using UnityEngine;
namespace Crosstales.Radio.Model.Entry
{
[Serializable]
public class RadioEntryURL : BaseRadioEntry
{
[Tooltip("URL (add the protocol-type 'http://', 'file://' etc.) with the radios.")]
[Header("Source Settings")]
public string URL;
[Tooltip("Prefixes for URLs, like 'http://' (default: URLPrefix.None).")]
public URLPrefix Prefix;
[Tooltip("Data format of the resource with the radios (default: DataFormatURL.Stream).")]
public DataFormatURL DataFormat;
[Tooltip("Reads only the given number of radio stations (default: : 0 (= all))")]
public int ReadNumberOfStations;
public string FinalURL
{
get
{
if (Prefix == URLPrefix.Http)
{
return Constants.PREFIX_HTTP + URL.Trim();
}
if (Prefix == URLPrefix.Https)
{
return Constants.PREFIX_HTTPS + URL.Trim();
}
if (Prefix == URLPrefix.File)
{
return Constants.PREFIX_FILE + URL.Trim();
}
if (Prefix == URLPrefix.PersistentDataPath)
{
return Constants.PREFIX_FILE + Application.persistentDataPath + '/' + URL.Trim();
}
if (Prefix == URLPrefix.DataPath)
{
return Constants.PREFIX_FILE + Application.dataPath + '/' + URL.Trim();
}
if (Prefix == URLPrefix.TempPath)
{
return Constants.PREFIX_FILE + Constants.PREFIX_TEMP_PATH + URL.Trim();
}
return URL.Trim();
}
}
public RadioEntryURL(BaseRadioEntry entry, string url, DataFormatURL dataFormat = DataFormatURL.Stream, int readNumberOfStations = 0)
: base(entry.Name, entry.ForceName, entry.EnableSource, entry.Station, entry.Genres, entry.Rating, entry.Description, entry.Icon, entry.Format, entry.Bitrate, entry.ChunkSize, entry.BufferSize, entry.ExcludedCodec)
{
URL = url;
DataFormat = dataFormat;
ReadNumberOfStations = readNumberOfStations;
}
public RadioEntryURL(RadioStation entry, string url, DataFormatURL dataFormat = DataFormatURL.Stream, int readNumberOfStations = 0)
: base(entry.Name, true, true, entry.Station, entry.Genres, entry.Rating, entry.Description, entry.Icon, entry.Format, entry.Bitrate, entry.ChunkSize, entry.BufferSize, entry.ExcludedCodec)
{
URL = url;
DataFormat = dataFormat;
ReadNumberOfStations = readNumberOfStations;
}
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder(base.ToString());
stringBuilder.Append(GetType().Name);
stringBuilder.Append(Constants.TEXT_TOSTRING_START);
stringBuilder.Append("URL='");
stringBuilder.Append(URL);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("Prefix='");
stringBuilder.Append(Prefix);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("DataFormat='");
stringBuilder.Append(DataFormat);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER);
stringBuilder.Append("ReadNumberOfStations='");
stringBuilder.Append(ReadNumberOfStations);
stringBuilder.Append(Constants.TEXT_TOSTRING_DELIMITER_END);
stringBuilder.Append(Constants.TEXT_TOSTRING_END);
return stringBuilder.ToString();
}
}
}