Esempio n. 1
0
 /// <summary>
 /// ダウンロード待ちリストに追加します。
 /// </summary>
 /// <param name="v">追加するデータ</param>
 public void AddDownload(VideoModel v)
 {
     if (!Downloads.Any(d => d.VideoId == v.VideoId))
     {
         Downloads.Add(v);
     }
 }
Esempio n. 2
0
        private async Task Download(VideoModel vm)
        {
            using (var handler = new HttpClientHandler())
                using (var client = new HttpClient(handler))
                {
                    client.Timeout = new TimeSpan(1, 0, 0);

                    // ログインクッキー設定
                    handler.CookieContainer = await SettingModel.Instance.GetCookies();

                    // 対象動画にジャンプ
                    await client.PostAsync("http://www.nicovideo.jp/watch/" + vm.VideoId, null);

                    // 動画URL全文を取得
                    var flvurl = await client.GetStringAsync("http://flapi.nicovideo.jp/api/getflv/" + vm.VideoId);

                    flvurl = Uri.UnescapeDataString(flvurl);
                    flvurl = Regex.Match(flvurl, @"&url=.*").Value.Replace("&url=", "");

                    // TODO 逐次ダウンロードの方法
                    var bytes = await client.GetByteArrayAsync(flvurl);

                    File.WriteAllBytes(CreateFilename(vm), bytes);
                }
        }
Esempio n. 3
0
        public VideoModel GetVideo(string id)
        {
            var video = Videos.FirstOrDefault(v => v.VideoId == id);

            if (video == null)
            {
                video = new VideoModel()
                {
                    VideoId = id
                };
                Videos.Add(video);
            }

            return(video);
        }
Esempio n. 4
0
        /// <summary>
        /// ダウンロード先パスを作成します。
        /// </summary>
        /// <param name="vm">VideoModel</param>
        /// <returns></returns>
        private string CreateFilename(VideoModel vm)
        {
            var dir = SettingModel.Instance.DownloadDirectory;

            switch (SettingModel.Instance.DownloadFileName)
            {
            case DownloadFileName.ID:
                return(Path.Combine(dir, vm.VideoId + ".mp4"));

            case DownloadFileName.Title:
                return(Path.Combine(dir, vm.Title + ".mp4"));

            case DownloadFileName.TitleAndID:
                return(Path.Combine(dir, vm.VideoId + "_" + vm.Title + ".mp4"));

            default:
                return(Path.Combine(dir, vm.VideoId + ".mp4"));
            }
        }