-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stream.cs
81 lines (73 loc) · 2.59 KB
/
Stream.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
78
79
80
81
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using NutzCode.MPVPlayer.WPF.Wrapper.Annotations;
using NutzCode.MPVPlayer.WPF.Wrapper.Models;
namespace NutzCode.MPVPlayer.WPF.Wrapper
{
public class Stream : INotifyPropertyChanged
{
private bool _selected;
public int Id { get; set; }
public string Title { get; set; }
public string Language { get; set; }
public string ExternalFilename { get; set; }
public bool Selected
{
get { return _selected; }
set
{
_selected = value;
OnPropertyChanged();
}
}
public string RealTitle => ToString();
public event PropertyChangedEventHandler PropertyChanged;
public override string ToString()
{
string str = string.Empty;
if (!string.IsNullOrEmpty(Language))
{
if (Language.Length == 3)
str += GetLanguageFromCode3(Language, Language);
else if (Language.Length == 2)
str += GetLanguageFromCode2(Language, Language);
else
str += Language;
if (str.Length > 0)
str = str.Substring(0, 1).ToUpperInvariant() + str.Substring(1);
}
if (!string.IsNullOrEmpty(Title))
str += " (" + Title + ")";
if (!string.IsNullOrEmpty(ExternalFilename))
{
string extension = Path.GetExtension(ExternalFilename);
if (!string.IsNullOrEmpty(extension))
str += " [" + extension + "]";
}
if (str == string.Empty)
str = "Unknown";
return str;
}
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private static string GetLanguageFromCode3(string code3, string full)
{
Language l = Models.Language.Languages.FirstOrDefault(a => a.Code3 == code3);
if (l == null)
return full;
return l.Name;
}
private static string GetLanguageFromCode2(string code2, string full)
{
Language l = Models.Language.Languages.FirstOrDefault(a => a.Code2 == code2);
if (l == null)
return full;
return l.Name;
}
}
}