public Task <ICurrentUserInfo> GetCurrentUserInfo(IBrowserProfile browserProfile) { var cc = GetCookieContainer(browserProfile); var cookies = Tools.ExtractCookies(cc); var info = new CurrentUserInfo(); string name = null; string displayName = null; foreach (var cookie in cookies) { switch (cookie.Name) { case "login": name = cookie.Value; break; case "twilight-user": { //"{\"authToken\":\"rkpavalsbvBovec0qj2l5r5q0mnlm4\",\"displayName\":\"abckk\",\"id\":\"124821926\",\"login\":\"ob112\",\"roles\":{\"isStaff\":false},\"version\":2}" var decoded = System.Web.HttpUtility.UrlDecode(cookie.Value); var match = Regex.Match(decoded, "\"displayName\":\"([^\"]+)\""); if (match.Success) { displayName = match.Groups[1].Value; } } break; } } info.Username = displayName ?? name; info.IsLoggedIn = !string.IsNullOrEmpty(name); return(Task.FromResult <ICurrentUserInfo>(info)); }
public async Task ConnectAsync(string input, IBrowserProfile browserProfile) { CanConnect = false; CanDisconnect = true; try { _channelName = GetChannelName(input); var cc = GetCookieContainer(browserProfile); //cookieの例 //language=ja; _ga=GA1.2.1920479743.1518016680; unique_id=eTRVJSWTkPRuT1uLoWBbg5aQ5CaM4Ljo; __utmz=165406266.1520768529.6.4.utmcsr=twitch.tv|utmccn=(referral)|utmcmd=referral|utmcct=/kv501k/dashboard; __gads=ID=ef2e7365c12367c1:T=1523611207:S=ALNI_MbbhnPy2IqfXsKZVSa-OeOBuKGsPg; Unique_ID=2c6b62cbb53a4a7493a3129ef8b38002; mp_809576468572134f909dffa6bd0dcfcf_mixpanel=%7B%22distinct_id%22%3A%20%2216170d840fb315-054303055d0714-d35346d-1fa400-16170d840fc9f0%22%2C%22%24initial_referrer%22%3A%20%22https%3A%2F%2Fwww.twitch.tv%2Fsettings%2Fprofile%22%2C%22%24initial_referring_domain%22%3A%20%22www.twitch.tv%22%7D; __utma=165406266.1920479743.1518016680.1524682833.1526145797.8; Unique_ID_v2=2c6b62cbb53a4a7493a3129ef8b38002; session_unique_id=ArrQHYWS55SLOCTQKdvFME0Nc57Qn1vH; _gid=GA1.2.511219589.1540912015; persistent=270919349%3A%3Arptndai1hlfiz2x658fjs56i63kq9v; sudo=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIyNzA5MTkzNDkiLCJhdWQiOlsic3VkbyJdLCJleHAiOjE1NDA5MjAwMjAsImlhdCI6MTU0MDkxNjQyMH0=.pY5YvJrcvb6o5j67qsNXrT9YBZO8e2NO-qictdIp15fC6efmbd8ivys-tNA6Zot7AwckDd8JsmKqwAQPEBJAiA==; bits_sudo=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIyNzA5MTkzNDkiLCJhdWQiOlsic3VkbyIsImJpdHMiXSwiZXhwIjoxNTQxNTIxMjIwLCJpYXQiOjE1NDA5MTY0MjB9.k7pm0x6PvcvL8B9R4d-VYFz4nrL_fR-4ozWWO7o4boSIKHY3uxOzW3FseLTEr0CZ7T_oeXLyHE_6pw1bWaj3Qg==; login=ryu8107; name=ryu8107; last_login=2018-10-30T16:20:20Z; api_token=14a0b0a43fc8d41a279adf0865317921; device_cookie=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL3Bhc3Nwb3J0LnR3aXRjaC50diIsInN1YiI6InJ5dTgxMDciLCJhdWQiOiJicnV0ZS1mb3JjZS1wcm90ZWN0aW9uIiwiZXhwIjoxNTU2NDY4NDIwLCJpYXQiOjE1NDA5MTY0MjAsIm5vbmNlIjoiTzBtWXJBYkVXU1ZULXJ5XzRIOXd3a3BlQTBPdjNSOUtMVmI5enRaNlZQbz0ifQ%3D%3D.uzFfEDu2yN17Dswjt8nEDaXlaqg4ZZUETOwql-x-WiboJw0hgNYgWFGbN_1FWJsO5OswcKxFB5dbaMfuYhNFIA%3D%3D; twilight-user={%22authToken%22:%22qlxy239ugu4we0rzvs5u9fcpcuvjj4%22%2C%22displayName%22:%22RYU8107%22%2C%22id%22:%22270919349%22%2C%22login%22:%22ryu8107%22%2C%22roles%22:{%22isStaff%22:false}%2C%22version%22:2}; auth-token=qlxy239ugu4we0rzvs5u9fcpcuvjj4; server_session_id=19358718db714130bdefc3b898bcccf9 var cookies = Tools.ExtractCookies(cc); foreach (var cookie in cookies) { if (cookie.Name == "auth-token") { _oauthToken = cookie.Value; } else if (cookie.Name == "login") { _name = cookie.Value; } } _commentCounter = new CommentCounter(); _provider = CreateMessageProvider(); _provider.Opened += Provider_Opened; _provider.Received += Provider_Received; var messageProviderTask = _provider.ReceiveAsync(); var metaProvider = CreateMetadataProvider(_channelName); metaProvider.MetadataUpdated += MetaProvider_MetadataUpdated; var metaProviderTask = metaProvider.ReceiveAsync(); var tasks = new List <Task>(); tasks.Add(messageProviderTask); tasks.Add(metaProviderTask); while (tasks.Count > 0) { var t = await Task.WhenAny(tasks); if (t == messageProviderTask) { try { await messageProviderTask; } catch (Exception ex) { _logger.LogException(ex); } tasks.Remove(messageProviderTask); try { metaProvider.Disconnect(); await metaProviderTask; } catch (Exception ex) { _logger.LogException(ex); } tasks.Remove(metaProviderTask); break; } else { try { await metaProviderTask; } catch (Exception ex) { _logger.LogException(ex); } tasks.Remove(metaProviderTask); } } } finally { CanConnect = true; CanDisconnect = false; } }