Exemple #1
0
        /// <summary>
        /// Apply the decrypted signature to the stream manifest.
        /// </summary>
        public static void ApplySignature(ObscuredContainer streamContainer, string js)
        {
            int numSignaturesFound = 0;

            foreach (KeyValuePair <string, object> s in streamContainer)
            {             // Iterate over each stream and sign the URLs
                ObscuredContainer stream = (ObscuredContainer)s.Value;
                string            URL    = stream.GetValue <string>("url");
                if (URL.Contains("signature="))
                {                 // Sometimes, signature is provided directly by YT, so we can skip the whole signature descrambling
                    numSignaturesFound++;
                    continue;
                }

                // Get, decode and save signature
                string cipheredSignature = stream.GetValue <string>("s");
                string signature         = Cipher.DecodeSignature(js, cipheredSignature);
                stream["url"] = URL + "&signature=" + signature;

                /*YouTube.Log(string.Format (
                 *      "Descrambled Signature for ITag={0} \n \t s={1} \n \t signature={2}",
                 *      stream.GetValue<string>("itag"),
                 *      cipheredSignature,
                 *      signature));*/
            }

            if (numSignaturesFound > 0)
            {
                CSTube.Log(string.Format("{0} out of {1} URLs already contained a signature!", numSignaturesFound, streamContainer.Count));
            }
        }
Exemple #2
0
        /// <summary>
        /// Retrieves an arbitrary attribute from the specified container.
        /// Path separated by / and \ expects respective container tree.
        /// Returns default(T) on failure to retrive the attribute.
        /// </summary>
        public static T TryGetAttribute <T>(ObscuredContainer container, string path)
        {
            string[]          cmd = path.Split('\\', '/');
            ObscuredContainer cur = container;

            for (int i = 0; i < cmd.Length - 1; i++)
            {             // Follows the specified path down the container hierarchy if possible
                cur = cur.GetValue <ObscuredContainer>(cmd[i]);
                if (cur == null)
                {
                    return(default(T));
                }
            }
            return(cur.GetValue <T>(cmd[cmd.Length - 1]));
        }
Exemple #3
0
        /// <summary>
        /// Descrambles data of all streams at the given args position and breaks them down into individual parameters.
        /// Result is written into back into the given position as a parsed ObscuredContainer and returned
        /// </summary>
        public static ObscuredContainer ApplyDescrambler(ObscuredContainer args, string streamKey)
        {
            // Break up individual streams
            string[]          streamBundle    = args.GetValue <string>(streamKey).Split(',');
            ObscuredContainer streamContainer = new ObscuredContainer();

            foreach (string streamRaw in streamBundle)
            {             // Descramble and index stream data
                NameValueCollection streamParsed = HttpUtility.ParseQueryString(streamRaw);
                ObscuredContainer   streamInfo   = ObscuredContainer.FromDictionary(
                    streamParsed.AllKeys.ToDictionary(k => k, k => (object)HttpUtility.UrlDecode(streamParsed[k]))
                    );
                streamContainer.Add(streamRaw, streamInfo);
            }
            // Write descrambled data back into args
            args[streamKey] = streamContainer;

            /*YouTube.Log(string.Format (
             *      "Applying Descrambler: \n \t " +
             *              string.Join(" \n \t ", streamContainer.Select(s =>
             *                              string.Join("; ", ((ObscuredContainer)s.Value).Select(p => (string)p.Key + "=" + (string)p.Value))
             *              ))
             * ));*/

            return(streamContainer);
        }
Exemple #4
0
        /// <summary>
        /// Read value of the give attribute collection into the class members
        /// Affects type, URL, ITag and Abr
        /// </summary>
        private void ReadAttributeValues(ObscuredContainer attributes)
        {
            if (attributes.ContainsKey("type"))
            {
                type = attributes.GetValue <string>("type");
            }

            if (attributes.ContainsKey("url"))
            {
                URL = attributes.GetValue <string>("url");
            }

            if (attributes.ContainsKey("itag"))
            {
                ITag = attributes.GetValue <string>("itag");
            }

            if (attributes.ContainsKey("abr"))
            {
                Abr = attributes.GetValue <string>("abr");
            }
        }
Exemple #5
0
 /// <summary>
 /// Construct a Caption and reads meta-data (no HTTP fetch)
 /// </summary>
 public Caption(ObscuredContainer captionTrack)
 {
     url  = captionTrack.GetValue <string>("baseUrl");
     name = captionTrack.GetValue <ObscuredContainer>("name").GetValue <string>("simpleText");
     code = captionTrack.GetValue <string>("languageCode");
 }