func TYTD.GetVideoId(v)
{
    func IsValidId(_v)
                {
                    if(_v.Count != 11) return false;
                    each(var item : _v)
                    {
                        if(!(item.IsLetter() || item.IsDigit() || item == '-' || item == '_')) return false;
                    }
                    return true;
                }
                if(TypeOf(v) != "String") return null;
                if(IsValidId(v)) return v;
                each(var __re : ["youtube\\..+?/watch.*?v=(.*?)(?:&|/|$)","youtu\\.be/(.*?)(?:\\?|&|/|$)","youtube\\..+?/embed/(.*?)(?:\\?|&|/|$)","youtube\\..+?/shorts/(.*?)(?:\\?|&|/|$)","youtube\\..+?/live/(.*?)(?:\\?|&|/|$)"])
                {
                    var __r = new Regex(__re);
                    var __s = __r.Search(v);
                    if(__s.Count == 2)
                    {
                        __r=__s[1].Text;
                        if(IsValidId(__r))
                        {
                            return __r;
                        }
                    }
                }
                return null;

}
func TYTD.GetPlaylistId(pid)
{
    func IsValidId(v)
                {
                    if(v.Count < 2) return false;
                    each(var item : v)
                    {
                        if(!(item.IsLetter() || item.IsDigit() || item == '-' || item == '_')) return false;
                    }
                    return true;
                }
                if(TypeOf(pid) != "String") return null;
                if(IsValidId(pid)) return pid;
                each(var __re : ["youtube\\..+?/playlist.*?list=(.*?)(?:&|/|$)","youtube\\..+?/watch.*?list=(.*?)(?:&|/|$)","youtu\\.be/.*?/.*?list=(.*?)(?:&|/|$)","youtube\\..+?/embed/.*?/.*?list=(.*?)(?:&|/|$)"])
                {
                    var __r = new Regex(__re);
                    var __s = __r.Search(pid);
                    if(__s.Count == 2)
                    {
                        __r=__s[1].Text;
                        if(IsValidId(__r))
                        {
                            return __r;
                        }
                    }
                }
                return null;
}
func TYTD.GetChannelId(cid)
{
        func IsValidId(v)
                {
                    if(v.Count != 24) return false;
                    if(!v.StartsWith("UC")) return false;
                    each(var item : v)
                    {
                        if(!(item.IsLetter() || item.IsDigit() || item == '-' || item == '_')) return false;
                    }
                    return true;
                }
                if(TypeOf(cid) != "String") return null;
                if(IsValidId(cid)) return cid;
                each(var __re : ["youtube\\..+?/channel/(.*?)(?:\\?|&|/|$)"])
                {
                    var __r = new Regex(__re);
                    var __s = __r.Search(cid);
                    if(__s.Count == 2)
                    {
                        __r=__s[1].Text;
                        if(IsValidId(__r))
                        {
                            return __r;
                        }
                    }
                }
                return null;

}