예제 #1
0
        public async Task <List <NicoNicoHistoryEntry> > GetAccountHistoryAsync()
        {
            try {
                var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(HistoryUrl);

                var doc = new HtmlDocument();
                doc.LoadHtml(a);

                var list = doc.DocumentNode.SelectNodes("//div[@id='historyList']/div");

                var ret = new List <NicoNicoHistoryEntry>();

                if (list != null)
                {
                    foreach (var entry in list)
                    {
                        var item = new NicoNicoHistoryEntry();

                        item.VideoId      = entry.SelectSingleNode("div/h5/a").Attributes["href"].Value.Substring(6);
                        item.ThumbNailUrl = entry.SelectSingleNode("div/a/img").Attributes["data-original"].Value;
                        item.Title        = entry.SelectSingleNode("div/h5/a").InnerText.Trim();

                        //削除された動画だとぬるぽになる
                        var time = entry.SelectSingleNode("div/span[@class='videoTime']");

                        if (time != null)
                        {
                            item.Length = time.InnerText.Trim();
                        }

                        var date = TimeRegex.Match(entry.SelectSingleNode("div[@class='section']/p").ChildNodes["#text"].InnerText.Trim());


                        //これはひどい
                        item.WatchDate  = UnixTime.ToUnixTime(new DateTime(int.Parse(date.Groups[1].Value), int.Parse(date.Groups[2].Value), int.Parse(date.Groups[3].Value), int.Parse(date.Groups[4].Value), int.Parse(date.Groups[5].Value), 0));
                        item.WatchCount = entry.SelectSingleNode("div[@class='section']/p/span").InnerText;

                        ret.Add(item);
                    }
                }
                Owner.Status = "";
                return(ret);
            } catch (RequestFailed) {
                Owner.Status = "アカウントの視聴履歴の取得に失敗しました";
                return(null);
            }
        }
예제 #2
0
        public async Task <List <NicoNicoHistoryEntry> > GetLocalHistoryAsync()
        {
            if (File.Exists(LocalHistoryLocation))
            {
                try {
                    using (var stream = new StreamReader(LocalHistoryLocation)) {
                        var ret = new List <NicoNicoHistoryEntry>();
                        var a   = Encoding.UTF8.GetString(Convert.FromBase64String(await stream.ReadToEndAsync()));

                        dynamic json = DynamicJson.Parse(a);

                        foreach (var entry in json.history)
                        {
                            var item = new NicoNicoHistoryEntry();

                            item.VideoId      = entry.video_id;
                            item.ThumbNailUrl = entry.thumbnail_url;
                            item.Title        = entry.title;
                            item.Length       = entry.length;
                            item.WatchDate    = (long)entry.watchdate;
                            item.WatchCount   = entry.watchcount;

                            ret.Add(item);
                        }

                        return(ret);
                    }
                } catch (Exception) {
                    Owner.Status = "ローカルの視聴履歴の取得に失敗しました。ファイルが壊れている可能性があります";
                    return(null);
                }
            }
            else        //ファイルが無い 初回起動か何かかな

            //ファイルがないときはアカウントの視聴履歴をコピーして使おうかね
            {
                return(await GetAccountHistoryAsync());;
            }
        }