-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
98 lines (79 loc) · 2.79 KB
/
Program.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//the recommended way to parse youtube url
string getvideoid(string url)
{
if (url == null) { throw new ArgumentNullException("url"); }
var uri = new Uri(url);
var viewParam = System.Web.HttpUtility.ParseQueryString(uri.Query).Get("v");
if (viewParam == null)
{
if (url.Contains("youtube.com/v/") || url.Contains("youtu.be/"))
{
viewParam = url.Substring(url.LastIndexOf("/") + 1);
if (viewParam.Length > 10)
{
char[] charArray = viewParam.ToCharArray();
Array.Reverse(charArray);
var tempstr = new string(charArray);
tempstr = tempstr.Remove(0, tempstr.Length - 11);
char[] charArray2 = tempstr.ToCharArray();
Array.Reverse(charArray2);
viewParam = new string(charArray2);
}
}
else
{
throw new Exception("Can't parse the url");
}
}
if (viewParam == null || viewParam == "") { throw new Exception("Can't parse the url"); }
return viewParam;
}
//xamarin doesnt support system.web so use this
string getvideoidxamarin(string url)
{
if (url == null) { throw new ArgumentNullException("url"); }
var viewParam = url;
if (url.Contains("watch?v="))
{
viewParam = url.Substring(url.LastIndexOf("watch?v=") + 8);
char[] charArray = viewParam.ToCharArray();
Array.Reverse(charArray);
var tempstr = new string(charArray);
tempstr = tempstr.Remove(0, tempstr.Length - 11);
char[] charArray2 = tempstr.ToCharArray();
Array.Reverse(charArray2);
viewParam = new string(charArray2);
}
else if (url.Contains("youtube.com/v/") || url.Contains("youtu.be/"))
{
viewParam = url.Substring(url.LastIndexOf("/") + 1);
if (viewParam.Length > 10)
{
char[] charArray = viewParam.ToCharArray();
Array.Reverse(charArray);
var tempstr = new string(charArray);
tempstr = tempstr.Remove(0, tempstr.Length - 11);
char[] charArray2 = tempstr.ToCharArray();
Array.Reverse(charArray2);
viewParam = new string(charArray2);
}
}
else
{
throw new Exception("Can't parse the url");
}
if (viewParam == null || viewParam == "") { throw new Exception("Can't parse the url"); }
return viewParam;
}
//get string between two strings
string GetBetween(string strSource, string strStart, string strEnd)
{
if (strSource.Contains(strStart) && strSource.Contains(strEnd))
{
int Start, End;
Start = strSource.IndexOf(strStart, 0) + strStart.Length;
End = strSource.IndexOf(strEnd, Start);
return strSource.Substring(Start, End - Start);
}
return "";
}