Beispiel #1
0
        static public async Task <ClipboardDetectedEventArgs> CheckClipboard()
        {
            ClipboardDetectedEventArgs clipboardValue = null;

            DataPackageView dataPackageView = Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.WebLink))
            {
                var uri = await dataPackageView.GetWebLinkAsync();

                if (uri.OriginalString == prevContent)
                {
                    return(null);
                }

                clipboardValue = ExtractNicoContentId(uri);

                prevContent = uri.OriginalString;
            }
            else if (dataPackageView.Contains(StandardDataFormats.Text))
            {
                string text = await dataPackageView.GetTextAsync();

                if (prevContent == text)
                {
                    return(null);
                }
                try
                {
                    if (Uri.TryCreate(text, UriKind.Absolute, out var uri))
                    {
                        clipboardValue = ExtractNicoContentId(uri);
                    }
                    else
                    {
                        clipboardValue = ExtractNicoContentId(text);
                    }
                }
                catch
                {
                }
                prevContent = text;
            }

            return(clipboardValue);
        }
Beispiel #2
0
        static private ClipboardDetectedEventArgs ExtractNicoContentId(string contentId)
        {
            ClipboardDetectedEventArgs clipboardValue = null;

            if (Mntone.Nico2.NiconicoRegex.IsVideoId(contentId))
            {
                clipboardValue = new ClipboardDetectedEventArgs()
                {
                    Type = ContentType.Video,
                    Id   = contentId
                };
            }
            else if (Mntone.Nico2.NiconicoRegex.IsLiveId(contentId))
            {
                clipboardValue = new ClipboardDetectedEventArgs()
                {
                    Type = ContentType.Live,
                    Id   = contentId
                };
            }

            return(clipboardValue);
        }
Beispiel #3
0
        static private ClipboardDetectedEventArgs ExtractNicoContentId(Uri url)
        {
            ClipboardDetectedEventArgs clipboardValue = null;

            var match = NicoContentRegex.Match(url.OriginalString);

            if (match.Success)
            {
                var hostNameGroup    = match.Groups[1];
                var contentTypeGroup = match.Groups[3];
                var contentIdGroup   = match.Groups[4];

                var contentId = contentIdGroup.Value;

                if (Mntone.Nico2.NiconicoRegex.IsVideoId(contentId))
                {
                    clipboardValue = new ClipboardDetectedEventArgs()
                    {
                        Type = ContentType.Video,
                        Id   = contentId
                    };
                }
                else if (Mntone.Nico2.NiconicoRegex.IsLiveId(contentId))
                {
                    clipboardValue = new ClipboardDetectedEventArgs()
                    {
                        Type = ContentType.Live,
                        Id   = contentId
                    };
                }
                else if (contentTypeGroup.Success)
                {
                    var contentType = contentTypeGroup.Value;
                    switch (contentType)
                    {
                    case "watch":
                        clipboardValue = new ClipboardDetectedEventArgs()
                        {
                            Type = ContentType.Video,
                            Id   = contentId
                        };
                        break;

                    case "mylist":
                        clipboardValue = new ClipboardDetectedEventArgs()
                        {
                            Type = ContentType.Mylist,
                            Id   = contentId
                        };
                        break;

                    case "community":
                        clipboardValue = new ClipboardDetectedEventArgs()
                        {
                            Type = ContentType.Community,
                            Id   = contentId
                        };
                        break;

                    case "user":
                        clipboardValue = new ClipboardDetectedEventArgs()
                        {
                            Type = ContentType.User,
                            Id   = contentId
                        };
                        break;
                    }
                }
                else if (hostNameGroup.Success)
                {
                    var hostName = hostNameGroup.Value;

                    if (hostName == "ch.nicovideo.jp")
                    {
                        // TODO: クリップボードから受け取ったチャンネルIdを開く
                        clipboardValue = new ClipboardDetectedEventArgs()
                        {
                            Type = ContentType.Channel,
                            Id   = contentId
                        };
                    }
                }
            }

            return(clipboardValue);
        }