Esempio n. 1
0
        public string[] ParseKey(string line)
        {
            if (!downloadingM3u8KeyTip)
            {
                LOGGER.PrintLine(strings.downloadingM3u8Key, LOGGER.Warning);
                downloadingM3u8KeyTip = true;
            }
            string[] tmp    = line.Replace(HLSTags.ext_x_key + ":", "").Split(',');
            string[] key    = new string[] { "NONE", "", "" };
            string   u_l    = Global.GetTagAttribute(lastKeyLine.Replace(HLSTags.ext_x_key + ":", ""), "URI");
            string   method = Global.GetTagAttribute(line.Replace(HLSTags.ext_x_key + ":", ""), "METHOD");
            string   uri    = Global.GetTagAttribute(line.Replace(HLSTags.ext_x_key + ":", ""), "URI");
            string   iv     = Global.GetTagAttribute(line.Replace(HLSTags.ext_x_key + ":", ""), "IV");

            //存在加密
            if (method != "")
            {
                if (method != "AES-128")
                {
                    LOGGER.PrintLine(string.Format(strings.notSupportMethod, method), LOGGER.Error);
                    DownloadManager.BinaryMerge = true;
                    return(new string[] { $"{method}(NOTSUPPORTED)", "", "" });
                }
                //METHOD
                key[0] = method;
                //URI
                key[1] = uri;
                if (u_l == uri)
                {
                    key[1] = m3u8CurrentKey[1];
                }
                else
                {
                    LOGGER.WriteLine(strings.downloadingM3u8Key + " " + key[1]);
                    if (key[1].StartsWith("http"))
                    {
                        string keyUrl = key[1];
                        if (isQiQiuYun)
                        {
                            /*string encKey = Encoding.Default.GetString(Global.HttpDownloadFileToBytes(keyUrl, Headers));
                             * var indexs = "0-1-2-3-4-5-6-7-8-10-11-12-14-15-16-18".Split('-');
                             * if (encKey.Length == 20)
                             * {
                             *  var algorithmCharCode = (int)Encoding.ASCII.GetBytes(encKey)[0];
                             *  var algorithmChar = Encoding.ASCII.GetString(new byte[] { (byte)algorithmCharCode });
                             *  var algorithmCharStart = Global.GetNum(algorithmChar, 36) % 7;
                             *  var firstAlgorithmCharCode = (int)Encoding.ASCII.GetBytes(encKey)[algorithmCharStart];
                             *  var firstAlgorithmChar = Encoding.ASCII.GetString(new byte[] { (byte)firstAlgorithmCharCode });
                             *  var secondAlgorithmCharCode = (int)Encoding.ASCII.GetBytes(encKey)[algorithmCharStart + 1];
                             *  var secondAlgorithmChar = Encoding.ASCII.GetString(new byte[] { (byte)secondAlgorithmCharCode });
                             *  var algorithmNum = Global.GetNum(firstAlgorithmChar + secondAlgorithmChar, 36) % 3;
                             *
                             *  if (algorithmNum == 1)
                             *  {
                             *      indexs = "0-1-2-3-4-5-6-7-18-16-15-13-12-11-10-8".Split('-');
                             *  }
                             *  else if (algorithmNum == 0)
                             *  {
                             *      indexs = "0-1-2-3-4-5-6-7-8-10-11-12-14-15-16-18".Split('-');
                             *  }
                             *  else if (algorithmNum == 2)
                             *  {
                             *      var a_CODE = (int)Encoding.ASCII.GetBytes("a")[0];
                             *
                             *      var c9 = (int)Encoding.ASCII.GetBytes(encKey)[8];
                             *      var c9t = (int)Encoding.ASCII.GetBytes(encKey)[9];
                             *      var c10 = (int)Encoding.ASCII.GetBytes(encKey)[10];
                             *      var c10t = (int)Encoding.ASCII.GetBytes(encKey)[11];
                             *      var c14 = (int)Encoding.ASCII.GetBytes(encKey)[15];
                             *      var c14t = (int)Encoding.ASCII.GetBytes(encKey)[16];
                             *      var c15 = (int)Encoding.ASCII.GetBytes(encKey)[17];
                             *      var c15t = (int)Encoding.ASCII.GetBytes(encKey)[18];
                             *
                             *      var c9r = c9 - a_CODE + (Global.GetNum(Encoding.ASCII.GetString(new byte[] { (byte)c9t }), 10) + 1) * 26 - a_CODE;
                             *      var c10r = c10 - a_CODE + (Global.GetNum(Encoding.ASCII.GetString(new byte[] { (byte)c10t }), 10) + 1) * 26 - a_CODE;
                             *      var c14r = c14 - a_CODE + (Global.GetNum(Encoding.ASCII.GetString(new byte[] { (byte)c14t }), 10) + 1) * 26 - a_CODE;
                             *      var c15r = c15 - a_CODE + (Global.GetNum(Encoding.ASCII.GetString(new byte[] { (byte)c15t }), 10) + 2) * 26 - a_CODE;
                             *
                             *      //构造key
                             *      key[1] = Convert.ToBase64String(
                             *          new byte[]
                             *          {
                             *              Encoding.ASCII.GetBytes(encKey)[0],
                             *              Encoding.ASCII.GetBytes(encKey)[1],
                             *              Encoding.ASCII.GetBytes(encKey)[2],
                             *              Encoding.ASCII.GetBytes(encKey)[3],
                             *              Encoding.ASCII.GetBytes(encKey)[4],
                             *              Encoding.ASCII.GetBytes(encKey)[5],
                             *              Encoding.ASCII.GetBytes(encKey)[6],
                             *              Encoding.ASCII.GetBytes(encKey)[7],
                             *              (byte)c9r,
                             *              (byte)c10r,
                             *              Encoding.ASCII.GetBytes(encKey)[12],
                             *              Encoding.ASCII.GetBytes(encKey)[13],
                             *              Encoding.ASCII.GetBytes(encKey)[14],
                             *              (byte)c14r,
                             *              (byte)c15r,
                             *              Encoding.ASCII.GetBytes(encKey)[19]
                             *          }
                             *      );
                             *      //IV
                             *      key[2] = i;
                             *      return key;
                             *  }
                             * }
                             * else if (encKey.Length == 17)
                             * {
                             *  indexs = "1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16".Split('-');
                             * }
                             * else
                             * {
                             *  indexs = "1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16".Split('-');
                             * }
                             *
                             * string decKey = "";
                             * foreach (var _i in indexs)
                             * {
                             *  decKey += encKey[Convert.ToInt32(_i)];
                             * }
                             * key[1] = Convert.ToBase64String(Encoding.Default.GetBytes(decKey));*/

                            key[1] = Convert.ToBase64String(Global.HttpDownloadFileToBytes(keyUrl, "User-Agent:Mozilla/5.0 (Linux; U; Android 7.0; zh-cn; 15 Plus Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/9.4 Mobile Safari/537.36"));
                        } //气球云
                        else if (key[1].Contains("imooc.com/"))
                        {
                            key[1] = DecodeImooc.DecodeKey(Global.GetWebSource(key[1], Headers));
                        }
                        else
                        {
                            if (keyUrl.Contains("https://keydeliver.linetv.tw/jurassicPark"))  //linetv
                            {
                                keyUrl = keyUrl + "?time=" + Global.GetTimeStamp(false);
                            }
                            key[1] = Convert.ToBase64String(Global.HttpDownloadFileToBytes(keyUrl, Headers));
                        }
                    }
                    //DMM网站
                    else if (key[1].StartsWith("base64:"))
                    {
                        key[1] = key[1].Replace("base64:", "");
                    }
                    else
                    {
                        string keyUrl = CombineURL(BaseUrl, key[1]);
                        if (keyUrl.Contains("edu.51cto.com")) //51cto
                        {
                            string lessonId = Global.GetQueryString("lesson_id", keyUrl);
                            keyUrl = keyUrl + "&sign=" + Decode51CtoKey.GetSign(lessonId);
                            var encodeKey = Encoding.UTF8.GetString(Global.HttpDownloadFileToBytes(keyUrl, Headers));
                            key[1] = Decode51CtoKey.GetDecodeKey(encodeKey, lessonId);
                        }
                        else
                        {
                            key[1] = Convert.ToBase64String(Global.HttpDownloadFileToBytes(keyUrl, Headers));//keyUrl读取key
                        }
                    }
                }
                //IV
                key[2] = iv;
            }

            return(key);
        }
Esempio n. 2
0
        public string[] ParseKey(string line)
        {
            if (!downloadingM3u8KeyTip)
            {
                LOGGER.PrintLine(strings.downloadingM3u8Key, LOGGER.Warning);
                downloadingM3u8KeyTip = true;
            }
            string[] tmp = line.Replace(HLSTags.ext_x_key + ":", "").Split(',');
            string[] key = new string[] { "NONE", "", "" };
            string   u_l = Global.GetTagAttribute(lastKeyLine.Replace(HLSTags.ext_x_key + ":", ""), "URI");
            string   m   = Global.GetTagAttribute(line.Replace(HLSTags.ext_x_key + ":", ""), "METHOD");
            string   u   = Global.GetTagAttribute(line.Replace(HLSTags.ext_x_key + ":", ""), "URI");
            string   i   = Global.GetTagAttribute(line.Replace(HLSTags.ext_x_key + ":", ""), "IV");

            //存在加密
            if (m != "")
            {
                if (m != "AES-128")
                {
                    LOGGER.PrintLine(string.Format(strings.notSupportMethod, m), LOGGER.Error);
                    DownloadManager.BinaryMerge = true;
                    return(new string[] { $"{m}(NOTSUPPORTED)", "", "" });
                }
                //METHOD
                key[0] = m;
                //URI
                key[1] = u;
                if (u_l == u)
                {
                    key[1] = m3u8CurrentKey[1];
                }
                else
                {
                    LOGGER.WriteLine(strings.downloadingM3u8Key + " " + key[1]);
                    if (key[1].StartsWith("http"))
                    {
                        string keyUrl = key[1];
                        if (isQiQiuYun)
                        {
                            string encKey = Encoding.Default.GetString(Global.HttpDownloadFileToBytes(keyUrl, Headers));
                            var    indexs = "0-1-2-3-4-5-6-7-8-10-11-12-14-15-16-18".Split('-');
                            if (encKey.Length == 20)
                            {
                                var algorithmCharCode       = (int)Encoding.ASCII.GetBytes(encKey)[0];
                                var algorithmChar           = Encoding.ASCII.GetString(new byte[] { (byte)algorithmCharCode });
                                var algorithmCharStart      = Global.GetNum(algorithmChar, 36) % 7;
                                var firstAlgorithmCharCode  = (int)Encoding.ASCII.GetBytes(encKey)[algorithmCharStart];
                                var firstAlgorithmChar      = Encoding.ASCII.GetString(new byte[] { (byte)firstAlgorithmCharCode });
                                var secondAlgorithmCharCode = (int)Encoding.ASCII.GetBytes(encKey)[algorithmCharStart + 1];
                                var secondAlgorithmChar     = Encoding.ASCII.GetString(new byte[] { (byte)secondAlgorithmCharCode });
                                var algorithmNum            = Global.GetNum(firstAlgorithmChar + secondAlgorithmChar, 36) % 3;

                                if (algorithmNum == 1)
                                {
                                    indexs = "0-1-2-3-4-5-6-7-18-16-15-13-12-11-10-8".Split('-');
                                }
                                else if (algorithmNum == 0)
                                {
                                    indexs = "0-1-2-3-4-5-6-7-8-10-11-12-14-15-16-18".Split('-');
                                }
                                else if (algorithmNum == 2)
                                {
                                    var a_CODE = (int)Encoding.ASCII.GetBytes("a")[0];

                                    var c9   = (int)Encoding.ASCII.GetBytes(encKey)[8];
                                    var c9t  = (int)Encoding.ASCII.GetBytes(encKey)[9];
                                    var c10  = (int)Encoding.ASCII.GetBytes(encKey)[10];
                                    var c10t = (int)Encoding.ASCII.GetBytes(encKey)[11];
                                    var c14  = (int)Encoding.ASCII.GetBytes(encKey)[15];
                                    var c14t = (int)Encoding.ASCII.GetBytes(encKey)[16];
                                    var c15  = (int)Encoding.ASCII.GetBytes(encKey)[17];
                                    var c15t = (int)Encoding.ASCII.GetBytes(encKey)[18];

                                    var c9r  = c9 - a_CODE + (Global.GetNum(Encoding.ASCII.GetString(new byte[] { (byte)c9t }), 10) + 1) * 26 - a_CODE;
                                    var c10r = c10 - a_CODE + (Global.GetNum(Encoding.ASCII.GetString(new byte[] { (byte)c10t }), 10) + 1) * 26 - a_CODE;
                                    var c14r = c14 - a_CODE + (Global.GetNum(Encoding.ASCII.GetString(new byte[] { (byte)c14t }), 10) + 1) * 26 - a_CODE;
                                    var c15r = c15 - a_CODE + (Global.GetNum(Encoding.ASCII.GetString(new byte[] { (byte)c15t }), 10) + 2) * 26 - a_CODE;

                                    //构造key
                                    key[1] = Convert.ToBase64String(
                                        new byte[]
                                    {
                                        Encoding.ASCII.GetBytes(encKey)[0],
                                        Encoding.ASCII.GetBytes(encKey)[1],
                                        Encoding.ASCII.GetBytes(encKey)[2],
                                        Encoding.ASCII.GetBytes(encKey)[3],
                                        Encoding.ASCII.GetBytes(encKey)[4],
                                        Encoding.ASCII.GetBytes(encKey)[5],
                                        Encoding.ASCII.GetBytes(encKey)[6],
                                        Encoding.ASCII.GetBytes(encKey)[7],
                                        (byte)c9r,
                                        (byte)c10r,
                                        Encoding.ASCII.GetBytes(encKey)[12],
                                        Encoding.ASCII.GetBytes(encKey)[13],
                                        Encoding.ASCII.GetBytes(encKey)[14],
                                        (byte)c14r,
                                        (byte)c15r,
                                        Encoding.ASCII.GetBytes(encKey)[19]
                                    }
                                        );
                                    //IV
                                    key[2] = i;
                                    return(key);
                                }
                            }
                            else if (encKey.Length == 17)
                            {
                                indexs = "1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16".Split('-');
                            }
                            else
                            {
                                indexs = "1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16".Split('-');
                            }

                            string decKey = "";
                            foreach (var _i in indexs)
                            {
                                decKey += encKey[Convert.ToInt32(_i)];
                            }
                            key[1] = Convert.ToBase64String(Encoding.Default.GetBytes(decKey));
                        } //气球云
                        else if (key[1].Contains("imooc.com/"))
                        {
                            key[1] = DecodeImooc.DecodeKey(Global.GetWebSource(key[1], Headers));
                        }
                        else
                        {
                            if (keyUrl.Contains("https://keydeliver.linetv.tw/jurassicPark"))  //linetv
                            {
                                keyUrl = keyUrl + "?time=" + Global.GetTimeStamp(false);
                            }
                            key[1] = Convert.ToBase64String(Global.HttpDownloadFileToBytes(keyUrl, Headers));
                        }
                    }
                    //DMM网站
                    else if (key[1].StartsWith("base64:"))
                    {
                        key[1] = key[1].Replace("base64:", "");
                    }
                    else
                    {
                        string keyUrl = CombineURL(BaseUrl, key[1]);
                        if (keyUrl.Contains("edu.51cto.com")) //51cto
                        {
                            string lessonId = Global.GetQueryString("lesson_id", keyUrl);
                            keyUrl = keyUrl + "&sign=" + Decode51CtoKey.GetSign(lessonId);
                            var encodeKey = Encoding.UTF8.GetString(Global.HttpDownloadFileToBytes(keyUrl, Headers));
                            key[1] = Decode51CtoKey.GetDecodeKey(encodeKey, lessonId);
                        }
                        else
                        {
                            key[1] = Convert.ToBase64String(Global.HttpDownloadFileToBytes(keyUrl, Headers));
                        }
                    }
                }
                //IV
                key[2] = i;
            }

            return(key);
        }