-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathTools.cs
56 lines (54 loc) · 1.61 KB
/
Tools.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Common;
using Newtonsoft.Json;
using SitePlugin;
namespace MixchSitePlugin
{
class LiveUrlInfo
{
public string LiveId { get; set; }
public string Environment { get; set; }
}
static class Tools
{
private const string regexLiveUrl = "([a-z]*)\\.?mixch\\.tv/u/(?<id>[0-9]+)/live";
public static async Task<LiveUrlInfo> GetLiveId(IDataSource dataSource, string input)
{
// LIVE_ID
// https://mixch.tv/u/LIVE_ID/live
var liveUrlInfo = new LiveUrlInfo();
var match = Regex.Match(input, regexLiveUrl);
if (match.Success)
{
liveUrlInfo.Environment = match.Groups[1].Value;
if (liveUrlInfo.Environment == "")
{
liveUrlInfo.Environment = "torte";
}
liveUrlInfo.LiveId = match.Groups[2].Value;
}
else
{
throw new InvalidInputException();
}
return liveUrlInfo;
}
public static bool IsValidUrl(string input)
{
return Regex.IsMatch(input, regexLiveUrl);
}
public static string ElapsedToString(int elapsed)
{
var t = TimeSpan.FromSeconds(elapsed);
return t.Hours == 0 ? t.ToString("mm\\:ss") : t.ToString("h\\:mm\\:ss");
}
}
}