<commit_before>﻿using Codeplex.Data;
using SRNicoNico.Models.NicoNicoViewer;
using SRNicoNico.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;

namespace SRNicoNico.Models.NicoNicoWrapper {
    public class NicoNicoPublicMylist {

        private string MylistUrl;

        private TabItemViewModel Owner;

        public NicoNicoPublicMylist(TabItemViewModel vm, string mylistUrl) {

            Owner = vm;
            MylistUrl = mylistUrl;
        }


        public async Task<NicoNicoPublicMylistGroupEntry> GetMylistAsync() {

            try {


                var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(MylistUrl);

                var index = a.IndexOf("Jarty.globals(");

                if(index == -1) {

                    return null;
                }

                //該当JavaScriptの部分から取得
                var globals = a.Substring(index);

                //改行で分割
                var splitted = globals.Split('\n');

                //正規表現でダブルクォーテ内の名前を取得
                var regex = new Regex("\"(.*)\"");

                string nickname = null;
                string userid = null;
                string mylistname = null;
                string description = null;

                string json = null;

                foreach(var text in splitted) {

                    //マイリストオーナーだったら
                    if(text.Contains("mylist_owner:")) {

                        //マイリストオーナーのニックネームを取得
                        nickname = text.Substring(text.IndexOf("nickname: "));

                        var match = regex.Match(nickname);

                        //グループから取得
                        nickname = match.Groups[1].Value;
                        continue;
                    }

                    if(nickname != null && text.Contains("user_id:")) {

                        userid = new Regex(@"\d+").Match(text).Value;
                        continue;
                    }

                    if(userid != null && text.Contains("name:")) {

                        mylistname = regex.Match(text).Groups[1].Value;
                        continue;
                    }
                    if(mylistname != null && text.Contains("description:")) {

                        description = regex.Match(text).Groups[1].Value;
                        continue;
                    }
                    if(description != null && text.Contains("Mylist.preload(")) {

                        //Json取得
                        json = text.Substring(text.IndexOf(",") + 1, text.Length - text.IndexOf(",") - 3);
                        break;
                    }
                }

                var ret = new NicoNicoPublicMylistGroupEntry();

                ret.OwnerName = @"<a href=""http://www.nicovideo.jp/user/" + userid + @""">" + nickname + "</a> さんの公開マイリスト";
                ret.Name = mylistname;
                ret.Description = description;

                //\nを改行に置換
                ret.Description = ret.Description.Replace("\\n", "<br>").Replace("\\r", "");

                ret.Description = HyperLinkReplacer.Replace(ret.Description);

                var list = new List<NicoNicoMylistEntry>();

                StoreItems(json, list);

                ret.Data = list;

                return ret;
            } catch(RequestFailed) {

                Owner.Status = "公開マイリストの取得に失敗しました";
                return null;
            }

        }<commit_msg>fixed #84<commit_after>﻿using Codeplex.Data;
using SRNicoNico.Models.NicoNicoViewer;
using SRNicoNico.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;

namespace SRNicoNico.Models.NicoNicoWrapper {
    public class NicoNicoPublicMylist {

        private string MylistUrl;

        private TabItemViewModel Owner;

        public NicoNicoPublicMylist(TabItemViewModel vm, string mylistUrl) {

            Owner = vm;
            MylistUrl = mylistUrl;
        }


        public async Task<NicoNicoPublicMylistGroupEntry> GetMylistAsync() {

            try {


                var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(MylistUrl);

                var index = a.IndexOf("Jarty.globals(");

                if(index == -1) {

                    return null;
                }

                //該当JavaScriptの部分から取得
                var globals = a.Substring(index);

                //改行で分割
                var splitted = globals.Split('\n');

                //正規表現でダブルクォーテ内の名前を取得
                var regex = new Regex("\"(.*)\"");

                string nickname = null;
                string userid = null;
                string mylistname = null;
                string description = null;

                string json = null;

                foreach(var text in splitted) {

                    //マイリストオーナーだったら
                    if(text.Contains("mylist_owner:")) {

                        //マイリストオーナーのニックネームを取得
                        nickname = text.Substring(text.IndexOf("nickname: "));

                        var match = regex.Match(nickname);

                        //グループから取得
                        nickname = match.Groups[1].Value;
                        continue;
                    }

                    if(nickname != null && text.Contains("user_id:")) {

                        userid = new Regex(@"\d+").Match(text).Value;
                        continue;
                    }

                    if(userid != null && text.Contains("name:")) {

                        mylistname = regex.Match(text).Groups[1].Value;
                        continue;
                    }
                    if(mylistname != null && text.Contains("description:")) {

                        description = regex.Match(text).Groups[1].Value;
                        continue;
                    }
                    if(description != null && text.Contains("Mylist.preload(")) {

                        //Json取得
                        json = text.Substring(text.IndexOf(",") + 1, text.Length - text.IndexOf(",") - 3);
                        break;
                    }
                }

                var ret = new NicoNicoPublicMylistGroupEntry();

                ret.OwnerName = @"<a href=""http://www.nicovideo.jp/user/" + userid + @""">" + nickname + "</a> さんの公開マイリスト";
                ret.Name = mylistname;
                ret.Description = description;

                //\nを改行に置換
                ret.Description = ret.Description.Replace("\\n", "<br>").Replace("\\r", "");

                ret.Description = HyperLinkReplacer.Replace(ret.Description);

                var list = new List<NicoNicoMylistEntry>();

                if(json != null) {

                    StoreItems(json, list);
                }


                ret.Data = list;

                return ret;
            } catch(RequestFailed) {

                Owner.Status = "公開マイリストの取得に失敗しました";
                return null;
            }

        }
{'fraction_non_alphanumeric': 0.10676901605024425, 'fraction_numerical': 0.001953942777390091, 'mean_word_length': 1.262709188506473, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '134148', 'n_tokens_mistral': 2094, 'n_tokens_neox': 1899, 'n_words': 335}