-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQiyiConfig.cs
77 lines (66 loc) · 2.21 KB
/
QiyiConfig.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.IO;
using System.Globalization;
using System.Text;
namespace qsv2flv
{
/// <summary>
/// Description of IqiyiFolderConverter.
/// </summary>
public class QiyiConfig
{
private string configFilePath;
private Dictionary<string,string> configs;
public QiyiConfig(string configFilePath)
{
this.configFilePath = configFilePath;
this.configs = null;
}
public string Series
{
get { return this["clm"]; }
}
public string Title
{
get { return this["episode"] + " " + this["subTitle"]; }
}
private string this[string configName]
{
get
{
if(this.configs == null)
this.parseConfig();
return this.configs[configName];
}
}
private void parseConfig()
{
this.configs = new Dictionary<string,string>();
foreach(string line in File.ReadAllLines(this.configFilePath))
{
int sep = line.IndexOf("=");
if(sep>0)
this.configs[line.Substring(0,sep)] = this.unicodeDecode(line.Substring(sep+1).Trim());
}
}
private string unicodeDecode(string str)
{
string result = "";
if(str.Length<6)
result = str;
else if(str.StartsWith(@"\u",StringComparison.CurrentCultureIgnoreCase))
{
string code1 = str.Substring(2,2),
code2 = str.Substring(4,2);
byte[] bytes = new byte[2];
bytes[1] = byte.Parse(int.Parse(code1, NumberStyles.HexNumber).ToString());
bytes[0] = byte.Parse(int.Parse(code2, NumberStyles.HexNumber).ToString());
result = Encoding.Unicode.GetString(bytes) + this.unicodeDecode(str.Substring(6));
}
else
result = str.Substring(0,1) + this.unicodeDecode(str.Substring(1));
return result;
}
}
}