Skip to content

Commit

Permalink
Merge pull request #10 from PercyDan54/fuck-netease
Browse files Browse the repository at this point in the history
Parse timestamp with string split again
  • Loading branch information
MATRIX-feather authored Sep 22, 2024
2 parents ce6b1b9 + 74b33bb commit 893d7ca
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public AbstractTracker(TrackerHub hub)
AlwaysPresent = true;

#if DEBUG

InternalChild = new OsuSpriteText
{
Text = $"{this}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ public void GetLyricFor(long id)

public readonly BindableDouble Offset = new BindableDouble
{
MaxValue = 3000,
MinValue = -3000
MaxValue = 60000,
MinValue = -60000
};

private readonly Bindable<bool> autoSave = new Bindable<bool>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,14 @@ public List<Lyric> ToLyricList()
propertyDetected = false;

//处理属性

//时间
string timeProperty = propertyName.Replace(":", ".");

//如果是时间属性
if (timeProperty[0].IsDigit())
if (propertyName[0].IsDigit())
{
lyrics.Add(new Lyric
{
Time = timeProperty.ToMilliseconds()
Time = propertyName.ToMilliseconds()
});
}

Expand Down Expand Up @@ -130,13 +128,12 @@ public List<Lyric> ToLyricList()
//处理属性

//时间
string timeProperty = propertyName.Replace(":", ".");

//如果是时间属性
if (timeProperty[0].IsDigit())
if (propertyName[0].IsDigit())
{
//添加当前时间到times
times.Add(timeProperty.ToMilliseconds());
times.Add(propertyName.ToMilliseconds());
}

//todo: 在此放置对其他属性的处理逻辑
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,18 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Globalization;

namespace osu.Game.Rulesets.IGPlayer.Feature.Player.Plugins.Bundle.CloudMusic.Misc
{
public static class StringExtensions
{
public static int ToMilliseconds(this string src)
{
int result;
string[] spilt = src.Split(".");
string[] spilt = src.Split(":");
int.TryParse(spilt[0], out int minutes);
double.TryParse(spilt[1], out double seconds);

string formatString = "";

for (int i = 0; i < spilt.Length; i++)
{
int length = spilt[i].Length;

switch (i)
{
case 0:
formatString += new string('m', length);
break;

case 1:
formatString += new string('s', length);
break;

case 2:
formatString += new string('f', length);
break;
}

if (i < spilt.Length - 1)
formatString += @"\.";
}

try
{
var timeSpan = TimeSpan.ParseExact($"{src}", formatString, new DateTimeFormatInfo());
result = (int)timeSpan.TotalMilliseconds;
}
catch (Exception e)
{
string reason = e.Message;

if (e is FormatException)
reason = "格式有误, 请检查原歌词是否正确";

Logging.LogError(e, $"无法将\"{src}\"转换为歌词时间: {reason}");
result = int.MaxValue;
}

return result;
return minutes * 60000 + (int)Math.Round(seconds * 1000);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private void initToolbox()
Origin = Anchor.TopRight,
Current = plugin.Offset,
LabelText = CloudMusicStrings.LocalOffset,
KeyboardStep = 100,
RelativeSizeAxes = Axes.X,
Padding = new MarginPadding { Right = 10 }
},
Expand Down

0 comments on commit 893d7ca

Please sign in to comment.