예제 #1
0
        public async Task RemoveMediaFromCollectionAndDatabase(IMediaItem media)
        {
            if (media is TrackItem)
            {
                var trackItem = media as TrackItem;
                var trackDB   = LoadTrackById(trackItem.Id);
                if (trackDB == null)
                {
                    return;
                }
                musicDatabase.Remove(trackDB);

                var albumDB = LoadAlbum(trackItem.AlbumId);
                if (albumDB == null)
                {
                    return;
                }
                var albumTracks = LoadTracksByAlbumId(albumDB.Id);
                if (!albumTracks.Any())
                {
                    Albums.Remove(Albums.FirstOrDefault(x => x.Id == trackItem.AlbumId));
                    musicDatabase.Remove(albumDB);
                }

                var artistDB = LoadArtist(trackItem.ArtistId);
                if (artistDB == null)
                {
                    return;
                }
                var artistAlbums = LoadAlbums(artistDB.Id);
                if (!artistAlbums.Any())
                {
                    Artists.Remove(Artists.FirstOrDefault(x => x.Id == trackItem.ArtistId));
                    musicDatabase.Remove(artistDB);
                }

                await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Tracks.Remove(Tracks.FirstOrDefault(x => x.Path == trackItem.Path));

                    var playingTrack = Locator.MediaPlaybackViewModel.PlaybackService.Playlist.FirstOrDefault(x => x.Id == trackItem.Id);
                    if (playingTrack != null)
                    {
                        Locator.MediaPlaybackViewModel.PlaybackService.Playlist.Remove(playingTrack);
                    }
                });
            }
            else if (media is VideoItem)
            {
                var videoItem = media as VideoItem;
                var videoDb   = LoadVideoById(videoItem.Id);
                if (videoDb == null)
                {
                    return;
                }
                videoDatabase.Remove(videoDb);

                Videos.Remove(Videos.FirstOrDefault(x => x.Path == videoItem.Path));
            }
        }
예제 #2
0
        private void DownloadProgress(DownloadOperation download)
        {
            double percent = 100;

            if (download.Progress.TotalBytesToReceive > 0)
            {
                percent = download.Progress.BytesReceived * 100 / download.Progress.TotalBytesToReceive;
            }

            DeviceContent content = Videos.FirstOrDefault(i => i.SourceName == download.ResultFile.Name);

            if (content == null)
            {
                content = EventVideos.FirstOrDefault(i => i.SourceName == download.ResultFile.Name);
            }

            if (content == null)
            {
                content = EventImages.FirstOrDefault(i => i.SourceName == download.ResultFile.Name);
            }

            if (content != null)
            {
                content.Progress = percent;
            }
        }
예제 #3
0
        private void DeviceInstanceVideoDeleted(object sender, VideoDeletedEventArgs e)
        {
            var video = Videos.FirstOrDefault(v => v.Name == e.Name);

            ExecuteOnDispatcher(() =>
            {
                if (video != null)
                {
                    Videos.Remove(video);
                }
            });
        }
예제 #4
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);
        }
예제 #5
0
        public async Task DeleteVideo(string id)
        {
            const string url = "http://www.nicovideo.jp/api/deflist/delete?id_list[0][]={0}&token={1}";

            var video = Videos.FirstOrDefault(v => v.VideoId == id);

            if (video != null)
            {
                // 削除用URLを作成
                var txt = await GetStringAsync(string.Format(url, await GetItemId(id), await GetToken()));

                // 自身から削除
                Videos.Remove(video);

                MainViewModel.Instance.TemporaryCount = Videos.Count;
            }
        }
예제 #6
0
 private void _timer_Tick(object sender, object e)
 {
     if (SelectedVideo == null)
     {
         SelectedVideo = Videos.FirstOrDefault();
     }
     else
     {
         int pos = Videos.IndexOf(SelectedVideo);
         if (pos < Videos.Count - 1)
         {
             SelectedVideo = Videos[pos + 1];
         }
         else
         {
             SelectedVideo = Videos.FirstOrDefault();
         }
     }
 }
예제 #7
0
        /// <summary>
        /// ビデオ情報を取得します。
        /// </summary>
        /// <param name="id">取得したいビデオID</param>
        /// <param name="reload">既存情報をリロードするか</param>
        /// <returns>ビデオ情報</returns>
        public VideoModel GetVideo(string id, bool reload = false)
        {
            var video = Videos.FirstOrDefault(v => v.VideoId == id);

            if (video != null)
            {
                if (reload)
                {
                    video.Reload();
                }
                return(video);
            }
            else
            {
                var tmp = new VideoModel(id);

                Videos.Add(tmp);

                return(tmp);
            }
        }
예제 #8
0
        public async Task LoadFeed()
        {
            string feed = null;

            using (var client = new HttpClient())
            {
                try
                {
                    feed = await client.GetStringAsync("https://s.ch9.ms/Feeds/RSS");
                }
                catch { }
            }

            if (feed != null)
            {
                var parser = new RssParser();
                var rss    = parser.Parse(feed);

                List <Video> videos = new List <Video>();

                foreach (var element in rss)
                {
                    videos.Add(new Video()
                    {
                        Summary     = element.Summary,
                        Title       = element.Title,
                        Author      = element.Author,
                        PublishDate = element.PublishDate,
                        ImageUrl    = element.ImageUrl
                    });
                }

                Videos        = videos.OrderByDescending(v => v.PublishDate).ToList();
                SelectedVideo = Videos.FirstOrDefault();
            }
        }
예제 #9
0
        public async Task InitializeRelatedVideos()
        {
            if (!HasVideoDescription)
            {
                return;
            }

            using (var releaser = await _InitializeLock.LockAsync())
            {
                if (_IsInitialized)
                {
                    return;
                }

                // ニコスクリプトで指定されたジャンプ先動画
                if (_JumpVideoId != null)
                {
                    var video = await NicoVideoProvider.GetNicoVideoInfo(_JumpVideoId, requireLatest : true);

                    if (video != null)
                    {
                        JumpVideo = new VideoInfoControlViewModel(video);
                        RaisePropertyChanged(nameof(JumpVideo));
                    }
                }

                // 再生中アイテムのタイトルと投稿者説明文に含まれる動画IDの動画タイトルを比較して
                // タイトル文字列が近似する動画をシリーズ動画として取り込む
                // 違うっぽい動画も投稿者が提示したい動画として確保
                var sourceVideo = Database.NicoVideoDb.Get(CurrentVideoId);
                var videoIds    = _VideoViewerHelpInfo.GetVideoIds();
                List <Database.NicoVideo> seriesVideos = new List <Database.NicoVideo>();
                seriesVideos.Add(sourceVideo);
                foreach (var id in videoIds)
                {
                    var video = await NicoVideoProvider.GetNicoVideoInfo(id, requireLatest : true);

                    var titleSimilarity = sourceVideo.Title.CalculateSimilarity(video.Title);
                    if (titleSimilarity > _SeriesVideosTitleSimilarityValue)
                    {
                        seriesVideos.Add(video);
                    }
                    else
                    {
                        var otherVideo = new VideoInfoControlViewModel(video);
                        OtherVideos.Add(otherVideo);
                    }
                }


                // シリーズ動画として集めたアイテムを投稿日が新しいものが最後尾になるよう並び替え
                // シリーズ動画に番兵として仕込んだ現在再生中のアイテムの位置と動画数を比べて
                // 動画数が上回っていた場合は次動画が最後尾にあると決め打ちで取得する
                var orderedSeriesVideos = seriesVideos.OrderBy(x => x.PostedAt).ToList();
                var currentVideoIndex   = orderedSeriesVideos.IndexOf(sourceVideo);
                if (orderedSeriesVideos.Count - 1 > currentVideoIndex)
                {
                    var nextVideo = orderedSeriesVideos.Last();
                    NextVideo = new VideoInfoControlViewModel(nextVideo);

                    orderedSeriesVideos.Remove(nextVideo);

                    RaisePropertyChanged(nameof(NextVideo));
                }

                // 次動画を除いてシリーズ動画っぽいアイテムを投稿者が提示したい動画として優先表示されるようにする
                orderedSeriesVideos.Remove(sourceVideo);
                orderedSeriesVideos.Reverse();
                foreach (var video in orderedSeriesVideos)
                {
                    var videoVM = new VideoInfoControlViewModel(video);
                    OtherVideos.Insert(0, videoVM);
                }

                RaisePropertyChanged(nameof(OtherVideos));


                // チャンネル動画で次動画が見つからなかった場合は
                // チャンネル動画一覧から次動画をサジェストする
                if (sourceVideo.Owner.UserType == Mntone.Nico2.Videos.Thumbnail.UserType.Channel &&
                    NextVideo == null
                    )
                {
                    // DBからチャンネル情報を取得
                    var db_channelInfo = Database.NicoChannelInfoDb.GetFromRawId(sourceVideo.Owner.OwnerId);
                    if (db_channelInfo == null)
                    {
                        db_channelInfo = new Database.NicoChannelInfo()
                        {
                            RawId        = sourceVideo.Owner.OwnerId,
                            ThumbnailUrl = sourceVideo.Owner.IconUrl,
                            Name         = sourceVideo.Owner.ScreenName
                        };
                    }

                    // チャンネル動画の一覧を取得する
                    // ページアクセスが必要なので先頭ページを取って
                    // 全体の分量を把握してから全ページ取得を行う
                    List <ChannelVideoInfo> channelVideos = new List <ChannelVideoInfo>();
                    var channelVideosFirstPage            = await ChannelProvider.GetChannelVideo(sourceVideo.Owner.OwnerId, 0);

                    var uncheckedCount = channelVideosFirstPage.TotalCount - channelVideosFirstPage.Videos.Count;
                    if (channelVideosFirstPage.TotalCount != 0)
                    {
                        channelVideos.AddRange(channelVideosFirstPage.Videos);

                        var uncheckedPageCount = (int)Math.Ceiling((double)uncheckedCount / 20); /* チャンネル動画1ページ = 20 動画 */
                        foreach (var page in Enumerable.Range(1, uncheckedPageCount))
                        {
                            var channelVideoInfo = await ChannelProvider.GetChannelVideo(sourceVideo.Owner.OwnerId, page);

                            channelVideos.AddRange(channelVideoInfo.Videos);
                        }

                        db_channelInfo.Videos = channelVideos;
                    }

                    Database.NicoChannelInfoDb.AddOrUpdate(db_channelInfo);


                    var collectionView = new AdvancedCollectionView(db_channelInfo.Videos);
                    collectionView.SortDescriptions.Add(new SortDescription(nameof(ChannelVideoInfo.PostedAt), SortDirection.Ascending));
                    collectionView.SortDescriptions.Add(new SortDescription(nameof(ChannelVideoInfo.ItemId), SortDirection.Ascending));
                    collectionView.RefreshSorting();

                    var item = collectionView.FirstOrDefault(x => (x as ChannelVideoInfo).Title == sourceVideo.Title);
                    var pos  = collectionView.IndexOf(item);
                    if (pos >= 0)
                    {
                        var nextVideo = collectionView.ElementAtOrDefault(pos + 1) as ChannelVideoInfo;
                        if (nextVideo != null)
                        {
                            var videoVM = new ChannelVideoListItemViewModel(nextVideo.ItemId);
                            videoVM.IsRequirePayment = nextVideo.IsRequirePayment;
                            videoVM.SetTitle(nextVideo.Title);
                            videoVM.SetSubmitDate(nextVideo.PostedAt);
                            videoVM.SetThumbnailImage(nextVideo.ThumbnailUrl);
                            videoVM.SetVideoDuration(nextVideo.Length);
                            videoVM.SetDescription(nextVideo.ViewCount, nextVideo.CommentCount, nextVideo.MylistCount);

                            NextVideo = videoVM;
                            RaisePropertyChanged(nameof(NextVideo));
                        }
                    }
                }

                // マイリスト
                var relatedMylistIds = _VideoViewerHelpInfo.GetMylistIds();
                foreach (var mylistId in relatedMylistIds)
                {
                    var mylistDetails = await MylistProvider.GetMylistGroupDetail(mylistId);

                    if (mylistDetails.IsOK)
                    {
                        Mylists.Add(new MylistGroupListItem(mylistDetails.MylistGroup));
                    }
                }

                RaisePropertyChanged(nameof(Mylists));

                var videos = await Video.GetRelatedVideos(CurrentVideoId);

                Videos = videos.Select(x =>
                {
                    var vm = new VideoInfoControlViewModel(x);
                    return(vm);
                })
                         .ToList();

                CurrentVideo = Videos.FirstOrDefault(x => x.RawVideoId == CurrentVideoId);

                RaisePropertyChanged(nameof(Videos));
                RaisePropertyChanged(nameof(CurrentVideo));


                _IsInitialized = true;
            }
        }
 private void Load(string name, TimeSpan?startPosition = null)
 {
     SelectedVideo = Videos.FirstOrDefault(v => v.Name == name);
     StartPosition = startPosition;
 }