internal string[] ExtractActions(string content)
        {
            Match objResult  = SignatureRegexes.actionsObjRegexp.Match(content);
            Match funcResult = SignatureRegexes.actionsFuncRegexp.Match(content);

            if (!objResult.Success || !funcResult.Success)
            {
                return(null);
            }

            string obj      = objResult.Groups[1].Value.Replace("\\$", "\\\\$");
            string objBody  = objResult.Groups[2].Value.Replace("\\$", "\\\\$");
            string funcBody = funcResult.Groups[1].Value.Replace("\\$", "\\\\$");

            Match reverseResult = SignatureRegexes.reverseRegexp.Match(objBody);
            Match sliceResult   = SignatureRegexes.sliceRegexp.Match(objBody);
            Match spliceResult  = SignatureRegexes.spliceRegexp.Match(objBody);
            Match swapResult    = SignatureRegexes.swapRegexp.Match(objBody);

            string reverseKey = DataFormatTools.CleanQuotations(reverseResult.Groups[1].Value.Replace("\\$", "\\\\$"));
            string sliceKey   = DataFormatTools.CleanQuotations(sliceResult.Groups[1].Value.Replace("\\$", "\\\\$"));
            string spliceKey  = DataFormatTools.CleanQuotations(spliceResult.Groups[1].Value.Replace("\\$", "\\\\$"));
            string swapKey    = DataFormatTools.CleanQuotations(swapResult.Groups[1].Value.Replace("\\$", "\\\\$"));

            string keys     = "(" + string.Join("|", reverseKey, sliceKey, spliceKey, swapKey) + ")";
            string keyStr   = "(?:a=)?" + obj + "(?:\\." + keys + "|\\['" + keys + "'\\]|\\[\"" + keys + "\"\\])\\(a,(\\d+)\\)";
            Regex  keyRegex = new Regex(keyStr);

            List <string> tokens = new List <string>();

            MatchCollection matches = keyRegex.Matches(funcBody);

            foreach (Match m in matches)
            {
                string key = m.Groups[1].Value ?? m.Groups[2].Value ?? m.Groups[3].Value;

                if (key == swapKey)
                {
                    tokens.Add("w" + m.Groups[4].Value);
                }
                else if (key == reverseKey)
                {
                    tokens.Add("r");
                }
                else if (key == sliceKey)
                {
                    tokens.Add("s" + m.Groups[4].Value);
                }
                else if (key == spliceKey)
                {
                    tokens.Add("p" + m.Groups[4].Value);
                }
            }

            return(tokens.ToArray());
        }
Exemple #2
0
        public JObject GetPageConfig(string videoId)
        {
            WebClient httpClient = new WebClient();
            string    result     = httpClient.DownloadString("https://youtube.com/watch?v=" + videoId);
            string    configJson = DataFormatTools.ExtractBetween(result, "ytplayer.config = ", ";ytplayer.load");

            if (configJson == null)
            {
                return(null);
            }

            return(JObject.Parse(configJson));
        }