From 8f7b9df8f9c606fe7d0963a2f9c89c6bd6251c95 Mon Sep 17 00:00:00 2001 From: flyself <1432593898@qq.com> Date: Sun, 10 Oct 2021 16:07:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=B7=B2=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E7=9A=84=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Core/Common.cs | 440 ---------- src/Core/Downloader.cs | 534 ------------ src/Core/FFmpegHelper.cs | 254 ------ src/Core/FileDownloadUtil.cs | 198 ----- src/Core/UserSpaceOld.cs | 148 ---- src/Core/Utils.cs | 430 --------- src/Core/api/danmaku/BiliDanmaku.cs | 36 - src/Core/api/danmaku/DanmakuProtobuf.cs | 115 --- src/Core/api/danmaku/proto/Danmaku.cs | 814 ------------------ src/Core/api/danmaku/proto/Danmaku.proto | 20 - .../api/fileDownload/FileDownloadConfig.cs | 42 - .../api/fileDownload/FileDownloadEvent.cs | 24 - .../api/fileDownload/FileDownloadHelper.cs | 317 ------- src/Core/api/fileDownload/FileDownloadInfo.cs | 77 -- src/Core/api/fileDownload/FileInfo.cs | 43 - .../api/fileDownload/ThreadDownloadInfo.cs | 11 - src/Core/api/history/History.cs | 90 -- src/Core/api/history/ToView.cs | 58 -- src/Core/api/login/LoginHelper.cs | 231 ----- src/Core/api/users/UserInfo.cs | 81 -- src/Core/api/users/UserRelation.cs | 290 ------- src/Core/api/users/UserSpace.cs | 520 ----------- src/Core/api/users/UserStatus.cs | 83 -- src/Core/aria2cNet/Aria2c.cs | 433 ---------- .../aria2cNet/client/AriaClientWebSocket.cs | 111 --- src/Core/danmaku2ass/Bilibili.cs | 163 ---- src/Core/danmaku2ass/Collision.cs | 61 -- src/Core/danmaku2ass/Config.cs | 55 -- src/Core/danmaku2ass/Creater.cs | 88 -- src/Core/danmaku2ass/Danmaku.cs | 12 - src/Core/danmaku2ass/Dictionary.cs | 6 - src/Core/danmaku2ass/Display.cs | 406 --------- src/Core/danmaku2ass/Filter.cs | 89 -- src/Core/danmaku2ass/Producer.cs | 105 --- src/Core/danmaku2ass/Studio.cs | 84 -- src/Core/danmaku2ass/Subtitle.cs | 155 ---- src/Core/danmaku2ass/Utils.cs | 228 ----- src/Core/entity/BangumiMedia.cs | 35 - src/Core/entity/BangumiSeason.cs | 199 ----- src/Core/entity/CheeseList.cs | 44 - src/Core/entity/CheeseSeason.cs | 52 -- src/Core/entity/Danmu.cs | 25 - src/Core/entity/FavFolder.cs | 49 -- src/Core/entity/FavResource.cs | 54 -- src/Core/entity/LoginUrl.cs | 50 -- src/Core/entity/MyInfo.cs | 96 --- src/Core/entity/Nav.cs | 88 -- src/Core/entity/PlayUrl.cs | 89 -- src/Core/entity/Stat.cs | 21 - src/Core/entity/UserSettings.cs | 31 - src/Core/entity/VideoDetail.cs | 28 - src/Core/entity/VideoView.cs | 207 ----- src/Core/entity2/history/History.cs | 101 --- src/Core/entity2/history/ToView.cs | 60 -- src/Core/entity2/users/BangumiFollow.cs | 103 --- src/Core/entity2/users/FollowingGroup.cs | 33 - .../entity2/users/FollowingGroupContent.cs | 42 - src/Core/entity2/users/MyInfo.cs | 166 ---- src/Core/entity2/users/RelationBlacks.cs | 43 - src/Core/entity2/users/RelationFollow.cs | 56 -- src/Core/entity2/users/RelationWhisper.cs | 43 - src/Core/entity2/users/SpaceChannelList.cs | 48 -- src/Core/entity2/users/SpaceChannelVideo.cs | 103 --- src/Core/entity2/users/SpaceCheese.cs | 65 -- src/Core/entity2/users/SpaceFavoriteFolder.cs | 79 -- .../users/SpaceFavoriteFolderResource.cs | 89 -- src/Core/entity2/users/SpaceInfo.cs | 77 -- src/Core/entity2/users/SpacePublication.cs | 150 ---- src/Core/entity2/users/SpaceSettings.cs | 46 - src/Core/entity2/users/UpStat.cs | 31 - src/Core/entity2/users/UserRelationStat.cs | 28 - src/Core/settings/ReadMe.md | 167 ---- src/Core/settings/Settings.class.cs | 90 -- src/Core/settings/Settings.cs | 132 --- .../Aria2cNet}/AriaManager.cs | 53 +- .../Aria2cNet/Client}/AriaClient.cs | 29 +- .../Client/Entity}/AriaAddMetalink.cs | 2 +- .../Client/Entity}/AriaAddTorrent.cs | 2 +- .../Aria2cNet/Client/Entity}/AriaAddUri.cs | 2 +- .../Client/Entity}/AriaChangeOption.cs | 2 +- .../Client/Entity}/AriaChangePosition.cs | 2 +- .../Aria2cNet/Client/Entity}/AriaChangeUri.cs | 2 +- .../Aria2cNet/Client/Entity}/AriaError.cs | 2 +- .../Aria2cNet/Client/Entity}/AriaGetFiles.cs | 3 +- .../Client/Entity}/AriaGetGlobalStat.cs | 29 +- .../Aria2cNet/Client/Entity}/AriaGetOption.cs | 2 +- .../Aria2cNet/Client/Entity}/AriaGetPeers.cs | 3 +- .../Client/Entity}/AriaGetServers.cs | 3 +- .../Client/Entity}/AriaGetSessionInfo.cs | 3 +- .../Aria2cNet/Client/Entity}/AriaGetUris.cs | 2 +- .../Aria2cNet/Client/Entity}/AriaOption.cs | 2 +- .../Aria2cNet/Client/Entity}/AriaPause.cs | 2 +- .../Aria2cNet/Client/Entity}/AriaRemove.cs | 2 +- .../Client/Entity}/AriaSaveSession.cs | 2 +- .../Aria2cNet/Client/Entity}/AriaSendData.cs | 3 +- .../Aria2cNet/Client/Entity}/AriaShutdown.cs | 2 +- .../Client/Entity}/AriaTellStatus.cs | 44 +- .../Aria2cNet/Client/Entity}/AriaUri.cs | 2 +- .../Aria2cNet/Client/Entity}/AriaVersion.cs | 3 +- .../Client/Entity}/SystemListMethods.cs | 2 +- .../Client/Entity}/SystemListNotifications.cs | 2 +- .../Client/Entity}/SystemMulticall.cs | 2 +- .../Client/Entity}/SystemMulticallMathod.cs | 2 +- .../Aria2cNet/Client/HowChangePosition.cs | 12 + src/DownKyi.Core/Aria2cNet/DownloadStatus.cs | 12 + .../Aria2cNet/Server}/AriaConfig.cs | 25 +- .../Server/AriaConfigFileAllocation.cs | 12 + .../Aria2cNet/Server/AriaConfigLogLevel.cs | 14 + .../Aria2cNet/Server}/AriaServer.cs | 24 +- .../BiliApi/Bangumi/BangumiInfo.cs | 68 ++ .../BiliApi/Bangumi/BangumiType.cs | 22 + .../BiliApi/Bangumi/Models/BangumiArea.cs | 13 + .../BiliApi/Bangumi/Models/BangumiEpisode.cs | 53 ++ .../BiliApi/Bangumi/Models/BangumiMedia.cs | 46 + .../BiliApi/Bangumi/Models/BangumiPositive.cs | 13 + .../BiliApi/Bangumi/Models/BangumiSeason.cs | 79 ++ .../Bangumi/Models/BangumiSeasonInfo.cs | 25 + .../BiliApi/Bangumi/Models/BangumiSection.cs | 20 + .../BiliApi/Bangumi/Models/BangumiStat.cs | 25 + .../BiliApi/Bangumi/Models/BangumiUpInfo.cs | 22 + .../BiliApi/BiliUtils}/BvId.cs | 2 +- .../BiliApi/BiliUtils/Constant.cs | 18 + .../BiliApi/BiliUtils}/DanmakuSender.cs | 7 +- .../BiliApi/BiliUtils/ParseEntrance.cs | 455 ++++++++++ src/DownKyi.Core/BiliApi/Cheese/CheeseInfo.cs | 70 ++ .../BiliApi/Cheese/Models/CheeseBrief.cs | 17 + .../BiliApi/Cheese/Models/CheeseEpisode.cs | 43 + .../Cheese/Models/CheeseEpisodeList.cs | 26 + .../Cheese/Models/CheeseEpisodePage.cs | 17 + .../BiliApi/Cheese/Models/CheeseImg.cs | 13 + .../BiliApi/Cheese/Models/CheeseStat.cs | 13 + .../BiliApi/Cheese/Models/CheeseUpInfo.cs | 23 + .../BiliApi/Cheese/Models/CheeseView.cs | 69 ++ src/DownKyi.Core/BiliApi/Login/LoginHelper.cs | 147 ++++ .../BiliApi/Login}/LoginInfo.cs | 34 +- .../BiliApi/Login/LoginQR.cs} | 89 +- .../BiliApi/Login/Models}/LoginStatus.cs | 14 +- .../BiliApi/Login/Models}/LoginUrl.cs | 10 +- .../Login/Models}/UserInfoForNavigation.cs | 12 +- .../BiliApi/Models/BaseModel.cs} | 6 +- src/DownKyi.Core/BiliApi/Models/Dimension.cs | 14 + src/DownKyi.Core/BiliApi/Models/VideoOwner.cs | 14 + src/DownKyi.Core/BiliApi/Video/Dynamic.cs | 40 + .../BiliApi/Video/Models/DynamicVideoView.cs | 55 ++ .../BiliApi/Video/Models/RankingVideoView.cs | 47 + .../BiliApi/Video/Models/RegionDynamic.cs | 27 + .../BiliApi/Video/Models/RegionRanking.cs | 20 + .../BiliApi/Video/Models/UgcArc.cs | 43 + .../BiliApi/Video/Models/UgcEpisode.cs | 29 + .../BiliApi/Video/Models/UgcSeason.cs | 32 + .../BiliApi/Video/Models/UgcSection.cs | 20 + .../BiliApi/Video/Models/UgcStat.cs | 29 + .../BiliApi/Video/Models/VideoDescription.cs | 18 + .../BiliApi/Video/Models/VideoPage.cs | 25 + .../BiliApi/Video/Models/VideoPagelist.cs | 19 + .../BiliApi/Video/Models/VideoStat.cs | 35 + .../BiliApi/Video/Models/VideoSubtitle.cs | 55 ++ .../BiliApi/Video/Models/VideoView.cs | 81 ++ src/DownKyi.Core/BiliApi/Video/Ranking.cs | 40 + src/DownKyi.Core/BiliApi/Video/VideoInfo.cs | 105 +++ .../BiliApi/VideoStream/Models/PlayUrl.cs | 46 + .../BiliApi/VideoStream/Models/PlayUrlDash.cs | 20 + .../VideoStream/Models/PlayUrlDashVideo.cs | 35 + .../BiliApi/VideoStream/Models/PlayUrlDurl.cs | 22 + .../Models/PlayUrlSupportFormat.cs | 19 + .../BiliApi/VideoStream/VideoStream.cs | 101 +++ src/DownKyi.Core/BiliApi/WebClient.cs | 142 +++ .../BiliApi/Zone}/VideoZone.cs | 21 +- src/DownKyi.Core/BiliApi/Zone/ZoneAttr.cs | 19 + src/DownKyi.Core/DownKyi.Core.csproj | 226 +++++ src/DownKyi.Core/Logging/LogInfo.cs | 55 ++ src/DownKyi.Core/Logging/LogLevel.cs | 28 + src/DownKyi.Core/Logging/LogManager.cs | 450 ++++++++++ src/DownKyi.Core/Properties/AssemblyInfo.cs | 36 + .../Settings/AfterDownloadOperation.cs | 10 + src/DownKyi.Core/Settings/AllowStatus.cs | 9 + .../Settings/DanmakuLayoutAlgorithm.cs | 9 + .../Settings/DownloadFinishedSort.cs | 8 + .../Settings/Models/AboutSettings.cs | 11 + .../Settings/Models/AppSettings.cs | 12 + .../Settings/Models/BasicSettings.cs | 14 + .../Settings/Models/DanmakuSettings.cs | 19 + .../Settings/Models/NetworkSettings.cs | 23 + .../Settings/Models/UserInfoSettings.cs | 10 + .../Settings/Models/VideoSettings.cs | 22 + src/DownKyi.Core/Settings/ParseScope.cs | 10 + .../Settings/SettingsManager.About.cs} | 35 +- .../Settings/SettingsManager.Basic.cs} | 83 +- .../Settings/SettingsManager.Danmaku.cs} | 119 +-- .../Settings/SettingsManager.Network.cs} | 118 +-- .../Settings/SettingsManager.UserInfo.cs | 44 + .../Settings/SettingsManager.Video.cs} | 193 +++-- src/DownKyi.Core/Settings/SettingsManager.cs | 81 ++ src/DownKyi.Core/Settings/VideoCodecs.cs | 9 + src/DownKyi.Core/Storage/Constant.cs | 65 ++ src/DownKyi.Core/Storage/Database/Cover.cs | 11 + src/DownKyi.Core/Storage/Database/CoverDb.cs | 130 +++ src/DownKyi.Core/Storage/Database/DbHelper.cs | 104 +++ src/DownKyi.Core/Storage/Database/Header.cs | 10 + src/DownKyi.Core/Storage/Database/HeaderDb.cs | 110 +++ src/DownKyi.Core/Storage/StorageCover.cs | 208 +++++ src/DownKyi.Core/Storage/StorageHeader.cs | 164 ++++ src/DownKyi.Core/Storage/StorageManager.cs | 136 +++ src/DownKyi.Core/Storage/StorageUtils.cs | 58 ++ src/DownKyi.Core/Utils/Debug/Console.cs | 139 +++ .../Utils/Encryptor/Encryptor.File.cs} | 93 +- .../Utils/Encryptor/Encryptor.String.cs | 70 ++ src/DownKyi.Core/Utils/Encryptor/Hash.cs | 68 ++ src/DownKyi.Core/Utils/Format.cs | 168 ++++ src/DownKyi.Core/Utils/HardDisk.cs | 52 ++ src/DownKyi.Core/Utils/ListHelper.cs | 42 + .../Utils}/MachineCode.cs | 7 +- src/DownKyi.Core/Utils/ObjectHelper.cs | 172 ++++ src/DownKyi.Core/Utils/QRCode.cs | 41 + .../Utils/StringLogicalComparer.cs | 75 ++ src/DownKyi.Core/Utils/Validator/Number.cs | 29 + src/DownKyi.Core/Utils/Web.cs | 8 + src/DownKyi.Core/packages.config | 8 + 218 files changed, 5966 insertions(+), 10262 deletions(-) delete mode 100644 src/Core/Common.cs delete mode 100644 src/Core/Downloader.cs delete mode 100644 src/Core/FFmpegHelper.cs delete mode 100644 src/Core/FileDownloadUtil.cs delete mode 100644 src/Core/UserSpaceOld.cs delete mode 100644 src/Core/Utils.cs delete mode 100644 src/Core/api/danmaku/BiliDanmaku.cs delete mode 100644 src/Core/api/danmaku/DanmakuProtobuf.cs delete mode 100644 src/Core/api/danmaku/proto/Danmaku.cs delete mode 100644 src/Core/api/danmaku/proto/Danmaku.proto delete mode 100644 src/Core/api/fileDownload/FileDownloadConfig.cs delete mode 100644 src/Core/api/fileDownload/FileDownloadEvent.cs delete mode 100644 src/Core/api/fileDownload/FileDownloadHelper.cs delete mode 100644 src/Core/api/fileDownload/FileDownloadInfo.cs delete mode 100644 src/Core/api/fileDownload/FileInfo.cs delete mode 100644 src/Core/api/fileDownload/ThreadDownloadInfo.cs delete mode 100644 src/Core/api/history/History.cs delete mode 100644 src/Core/api/history/ToView.cs delete mode 100644 src/Core/api/login/LoginHelper.cs delete mode 100644 src/Core/api/users/UserInfo.cs delete mode 100644 src/Core/api/users/UserRelation.cs delete mode 100644 src/Core/api/users/UserSpace.cs delete mode 100644 src/Core/api/users/UserStatus.cs delete mode 100644 src/Core/aria2cNet/Aria2c.cs delete mode 100644 src/Core/aria2cNet/client/AriaClientWebSocket.cs delete mode 100644 src/Core/danmaku2ass/Bilibili.cs delete mode 100644 src/Core/danmaku2ass/Collision.cs delete mode 100644 src/Core/danmaku2ass/Config.cs delete mode 100644 src/Core/danmaku2ass/Creater.cs delete mode 100644 src/Core/danmaku2ass/Danmaku.cs delete mode 100644 src/Core/danmaku2ass/Dictionary.cs delete mode 100644 src/Core/danmaku2ass/Display.cs delete mode 100644 src/Core/danmaku2ass/Filter.cs delete mode 100644 src/Core/danmaku2ass/Producer.cs delete mode 100644 src/Core/danmaku2ass/Studio.cs delete mode 100644 src/Core/danmaku2ass/Subtitle.cs delete mode 100644 src/Core/danmaku2ass/Utils.cs delete mode 100644 src/Core/entity/BangumiMedia.cs delete mode 100644 src/Core/entity/BangumiSeason.cs delete mode 100644 src/Core/entity/CheeseList.cs delete mode 100644 src/Core/entity/CheeseSeason.cs delete mode 100644 src/Core/entity/Danmu.cs delete mode 100644 src/Core/entity/FavFolder.cs delete mode 100644 src/Core/entity/FavResource.cs delete mode 100644 src/Core/entity/LoginUrl.cs delete mode 100644 src/Core/entity/MyInfo.cs delete mode 100644 src/Core/entity/Nav.cs delete mode 100644 src/Core/entity/PlayUrl.cs delete mode 100644 src/Core/entity/Stat.cs delete mode 100644 src/Core/entity/UserSettings.cs delete mode 100644 src/Core/entity/VideoDetail.cs delete mode 100644 src/Core/entity/VideoView.cs delete mode 100644 src/Core/entity2/history/History.cs delete mode 100644 src/Core/entity2/history/ToView.cs delete mode 100644 src/Core/entity2/users/BangumiFollow.cs delete mode 100644 src/Core/entity2/users/FollowingGroup.cs delete mode 100644 src/Core/entity2/users/FollowingGroupContent.cs delete mode 100644 src/Core/entity2/users/MyInfo.cs delete mode 100644 src/Core/entity2/users/RelationBlacks.cs delete mode 100644 src/Core/entity2/users/RelationFollow.cs delete mode 100644 src/Core/entity2/users/RelationWhisper.cs delete mode 100644 src/Core/entity2/users/SpaceChannelList.cs delete mode 100644 src/Core/entity2/users/SpaceChannelVideo.cs delete mode 100644 src/Core/entity2/users/SpaceCheese.cs delete mode 100644 src/Core/entity2/users/SpaceFavoriteFolder.cs delete mode 100644 src/Core/entity2/users/SpaceFavoriteFolderResource.cs delete mode 100644 src/Core/entity2/users/SpaceInfo.cs delete mode 100644 src/Core/entity2/users/SpacePublication.cs delete mode 100644 src/Core/entity2/users/SpaceSettings.cs delete mode 100644 src/Core/entity2/users/UpStat.cs delete mode 100644 src/Core/entity2/users/UserRelationStat.cs delete mode 100644 src/Core/settings/ReadMe.md delete mode 100644 src/Core/settings/Settings.class.cs delete mode 100644 src/Core/settings/Settings.cs rename src/{Core/aria2cNet => DownKyi.Core/Aria2cNet}/AriaManager.cs (73%) rename src/{Core/aria2cNet/client => DownKyi.Core/Aria2cNet/Client}/AriaClient.cs (98%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaAddMetalink.cs (91%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaAddTorrent.cs (91%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaAddUri.cs (92%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaChangeOption.cs (91%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaChangePosition.cs (91%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaChangeUri.cs (92%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaError.cs (90%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaGetFiles.cs (96%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaGetGlobalStat.cs (78%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaGetOption.cs (91%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaGetPeers.cs (96%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaGetServers.cs (96%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaGetSessionInfo.cs (94%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaGetUris.cs (92%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaOption.cs (99%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaPause.cs (91%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaRemove.cs (91%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaSaveSession.cs (91%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaSendData.cs (96%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaShutdown.cs (91%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaTellStatus.cs (73%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaUri.cs (88%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/AriaVersion.cs (95%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/SystemListMethods.cs (92%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/SystemListNotifications.cs (92%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/SystemMulticall.cs (91%) rename src/{Core/aria2cNet/client/entity => DownKyi.Core/Aria2cNet/Client/Entity}/SystemMulticallMathod.cs (86%) create mode 100644 src/DownKyi.Core/Aria2cNet/Client/HowChangePosition.cs create mode 100644 src/DownKyi.Core/Aria2cNet/DownloadStatus.cs rename src/{Core/aria2cNet/server => DownKyi.Core/Aria2cNet/Server}/AriaConfig.cs (78%) create mode 100644 src/DownKyi.Core/Aria2cNet/Server/AriaConfigFileAllocation.cs create mode 100644 src/DownKyi.Core/Aria2cNet/Server/AriaConfigLogLevel.cs rename src/{Core/aria2cNet/server => DownKyi.Core/Aria2cNet/Server}/AriaServer.cs (91%) create mode 100644 src/DownKyi.Core/BiliApi/Bangumi/BangumiInfo.cs create mode 100644 src/DownKyi.Core/BiliApi/Bangumi/BangumiType.cs create mode 100644 src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiArea.cs create mode 100644 src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiEpisode.cs create mode 100644 src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiMedia.cs create mode 100644 src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiPositive.cs create mode 100644 src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSeason.cs create mode 100644 src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSeasonInfo.cs create mode 100644 src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSection.cs create mode 100644 src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiStat.cs create mode 100644 src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiUpInfo.cs rename src/{Core/api/utils => DownKyi.Core/BiliApi/BiliUtils}/BvId.cs (97%) create mode 100644 src/DownKyi.Core/BiliApi/BiliUtils/Constant.cs rename src/{Core/api/utils => DownKyi.Core/BiliApi/BiliUtils}/DanmakuSender.cs (95%) create mode 100644 src/DownKyi.Core/BiliApi/BiliUtils/ParseEntrance.cs create mode 100644 src/DownKyi.Core/BiliApi/Cheese/CheeseInfo.cs create mode 100644 src/DownKyi.Core/BiliApi/Cheese/Models/CheeseBrief.cs create mode 100644 src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisode.cs create mode 100644 src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisodeList.cs create mode 100644 src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisodePage.cs create mode 100644 src/DownKyi.Core/BiliApi/Cheese/Models/CheeseImg.cs create mode 100644 src/DownKyi.Core/BiliApi/Cheese/Models/CheeseStat.cs create mode 100644 src/DownKyi.Core/BiliApi/Cheese/Models/CheeseUpInfo.cs create mode 100644 src/DownKyi.Core/BiliApi/Cheese/Models/CheeseView.cs create mode 100644 src/DownKyi.Core/BiliApi/Login/LoginHelper.cs rename src/{Core/api/login => DownKyi.Core/BiliApi/Login}/LoginInfo.cs (50%) rename src/{Core/api/login/Login.cs => DownKyi.Core/BiliApi/Login/LoginQR.cs} (55%) rename src/{Core/entity2/login => DownKyi.Core/BiliApi/Login/Models}/LoginStatus.cs (78%) rename src/{Core/entity2/login => DownKyi.Core/BiliApi/Login/Models}/LoginUrl.cs (72%) rename src/{Core/entity2/login => DownKyi.Core/BiliApi/Login/Models}/UserInfoForNavigation.cs (92%) rename src/{Core/entity2/BaseEntity.cs => DownKyi.Core/BiliApi/Models/BaseModel.cs} (92%) create mode 100644 src/DownKyi.Core/BiliApi/Models/Dimension.cs create mode 100644 src/DownKyi.Core/BiliApi/Models/VideoOwner.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Dynamic.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/DynamicVideoView.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/RankingVideoView.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/RegionDynamic.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/RegionRanking.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/UgcArc.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/UgcEpisode.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/UgcSeason.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/UgcSection.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/UgcStat.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/VideoDescription.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/VideoPage.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/VideoPagelist.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/VideoStat.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/VideoSubtitle.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Models/VideoView.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/Ranking.cs create mode 100644 src/DownKyi.Core/BiliApi/Video/VideoInfo.cs create mode 100644 src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrl.cs create mode 100644 src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDash.cs create mode 100644 src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDashVideo.cs create mode 100644 src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDurl.cs create mode 100644 src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlSupportFormat.cs create mode 100644 src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs create mode 100644 src/DownKyi.Core/BiliApi/WebClient.cs rename src/{Core => DownKyi.Core/BiliApi/Zone}/VideoZone.cs (97%) create mode 100644 src/DownKyi.Core/BiliApi/Zone/ZoneAttr.cs create mode 100644 src/DownKyi.Core/DownKyi.Core.csproj create mode 100644 src/DownKyi.Core/Logging/LogInfo.cs create mode 100644 src/DownKyi.Core/Logging/LogLevel.cs create mode 100644 src/DownKyi.Core/Logging/LogManager.cs create mode 100644 src/DownKyi.Core/Properties/AssemblyInfo.cs create mode 100644 src/DownKyi.Core/Settings/AfterDownloadOperation.cs create mode 100644 src/DownKyi.Core/Settings/AllowStatus.cs create mode 100644 src/DownKyi.Core/Settings/DanmakuLayoutAlgorithm.cs create mode 100644 src/DownKyi.Core/Settings/DownloadFinishedSort.cs create mode 100644 src/DownKyi.Core/Settings/Models/AboutSettings.cs create mode 100644 src/DownKyi.Core/Settings/Models/AppSettings.cs create mode 100644 src/DownKyi.Core/Settings/Models/BasicSettings.cs create mode 100644 src/DownKyi.Core/Settings/Models/DanmakuSettings.cs create mode 100644 src/DownKyi.Core/Settings/Models/NetworkSettings.cs create mode 100644 src/DownKyi.Core/Settings/Models/UserInfoSettings.cs create mode 100644 src/DownKyi.Core/Settings/Models/VideoSettings.cs create mode 100644 src/DownKyi.Core/Settings/ParseScope.cs rename src/{Core/settings/Settings.about.cs => DownKyi.Core/Settings/SettingsManager.About.cs} (53%) rename src/{Core/settings/Settings.base.cs => DownKyi.Core/Settings/SettingsManager.Basic.cs} (53%) rename src/{Core/settings/Settings.danmaku.cs => DownKyi.Core/Settings/SettingsManager.Danmaku.cs} (64%) rename src/{Core/settings/Settings.network.cs => DownKyi.Core/Settings/SettingsManager.Network.cs} (69%) create mode 100644 src/DownKyi.Core/Settings/SettingsManager.UserInfo.cs rename src/{Core/settings/Settings.video.cs => DownKyi.Core/Settings/SettingsManager.Video.cs} (50%) create mode 100644 src/DownKyi.Core/Settings/SettingsManager.cs create mode 100644 src/DownKyi.Core/Settings/VideoCodecs.cs create mode 100644 src/DownKyi.Core/Storage/Constant.cs create mode 100644 src/DownKyi.Core/Storage/Database/Cover.cs create mode 100644 src/DownKyi.Core/Storage/Database/CoverDb.cs create mode 100644 src/DownKyi.Core/Storage/Database/DbHelper.cs create mode 100644 src/DownKyi.Core/Storage/Database/Header.cs create mode 100644 src/DownKyi.Core/Storage/Database/HeaderDb.cs create mode 100644 src/DownKyi.Core/Storage/StorageCover.cs create mode 100644 src/DownKyi.Core/Storage/StorageHeader.cs create mode 100644 src/DownKyi.Core/Storage/StorageManager.cs create mode 100644 src/DownKyi.Core/Storage/StorageUtils.cs create mode 100644 src/DownKyi.Core/Utils/Debug/Console.cs rename src/{Core/Encryptor.cs => DownKyi.Core/Utils/Encryptor/Encryptor.File.cs} (67%) create mode 100644 src/DownKyi.Core/Utils/Encryptor/Encryptor.String.cs create mode 100644 src/DownKyi.Core/Utils/Encryptor/Hash.cs create mode 100644 src/DownKyi.Core/Utils/Format.cs create mode 100644 src/DownKyi.Core/Utils/HardDisk.cs create mode 100644 src/DownKyi.Core/Utils/ListHelper.cs rename src/{Core => DownKyi.Core/Utils}/MachineCode.cs (96%) create mode 100644 src/DownKyi.Core/Utils/ObjectHelper.cs create mode 100644 src/DownKyi.Core/Utils/QRCode.cs create mode 100644 src/DownKyi.Core/Utils/StringLogicalComparer.cs create mode 100644 src/DownKyi.Core/Utils/Validator/Number.cs create mode 100644 src/DownKyi.Core/Utils/Web.cs create mode 100644 src/DownKyi.Core/packages.config diff --git a/src/Core/Common.cs b/src/Core/Common.cs deleted file mode 100644 index 61ac6ab..0000000 --- a/src/Core/Common.cs +++ /dev/null @@ -1,440 +0,0 @@ -using System; -using System.Text.RegularExpressions; - -namespace Core -{ - public static class Common - { - // 配置文件所在路径 - public static readonly string ConfigPath = "./Config/"; - - // 日志、历史等文件所在路径 - public static readonly string RecordPath = "./Config/"; - - /// - /// 判断字符串是否以http或https开头,且域名为bilibili.com - /// - /// - /// - public static bool IsUrl(string input) - { - if (input.StartsWith("http://") || input.StartsWith("https://")) - { - if (input.Contains("www.bilibili.com")) { return true; } - else { return false; } - } - else { return false; } - } - - - /// - /// 判断是否为avid - /// - /// - /// - public static bool IsAvid(string input) - { - if (input.StartsWith("av")) - { - bool isInt = Regex.IsMatch(input.Remove(0, 2), @"^\d+$"); - return isInt; - } - return false; - } - - /// - /// 判断是否为bvid - /// - /// - /// - public static bool IsBvid(string input) - { - if (input.StartsWith("BV") && input.Length == 12) - { - return true; - } - return false; - } - - /// - /// 判断是否是用户空间的url - /// - /// - /// - public static bool IsUserSpaceUrl(string input) - { - if (input.StartsWith("http://") || input.StartsWith("https://")) - { - if (input.Contains("space.bilibili.com")) - { - return true; - } - else { return false; } - } - else { return false; } - } - - /// - /// 判断是否是用户id - /// - /// - /// - public static bool IsUserId(string input) - { - string inputLower = input.ToLower(); - if (inputLower.StartsWith("uid:")) - { - string uid = inputLower.TrimStart(new char[] { 'u', 'i', 'd', ':' }); - return IsInt(uid); - } - else if (inputLower.StartsWith("uid")) - { - string uid = inputLower.TrimStart(new char[] { 'u', 'i', 'd' }); - return IsInt(uid); - } - else { return false; } - } - - /// - /// 获取用户id - /// - /// - /// - public static long GetUserId(string url) - { - string[] strList = url.Split('?'); - string baseUrl = strList[0]; - - var match = Regex.Match(baseUrl, @"\d+"); - if (match.Success) - { - return GetInt(match.Value); - } - else - { - return -1; - } - } - - /// - /// 从url中解析id,包括bvid和番剧的id - /// - /// - /// - public static string GetVideoId(string url) - { - string[] strList = url.Split('?'); - string baseUrl = strList[0]; - - string[] str2List = baseUrl.Split('/'); - string id = str2List[str2List.Length - 1]; - - if (id == "") - { - // 字符串末尾 - return str2List[str2List.Length - 2]; - } - - return id; - } - - /// - /// 判断是视频还是番剧 - /// - /// - /// - public static VideoType GetVideoType(string url) - { - if (url.ToLower().Contains("/video/bv")) - { - return VideoType.VIDEO; - } - - if (url.ToLower().Contains("/video/av")) - { - return VideoType.VIDEO_AV; - } - - if (url.ToLower().Contains("/bangumi/play/ss")) - { - return VideoType.BANGUMI_SEASON; - } - - if (url.ToLower().Contains("/bangumi/play/ep")) - { - return VideoType.BANGUMI_EPISODE; - } - - if (url.ToLower().Contains("/bangumi/media/md")) - { - return VideoType.BANGUMI_MEDIA; - } - - if (url.ToLower().Contains("/cheese/play/ss")) - { - return VideoType.CHEESE_SEASON; - } - - if (url.ToLower().Contains("/cheese/play/ep")) - { - return VideoType.CHEESE_EPISODE; - } - - return VideoType.NONE; - } - - /// - /// 格式化Duration时间 - /// - /// - /// - public static string FormatDuration(long duration) - { - string formatDuration; - if (duration / 60 > 0) - { - long dur = duration / 60; - if (dur / 60 > 0) - { - formatDuration = $"{dur / 60}h{dur % 60}m{duration % 60}s"; - } - else - { - formatDuration = $"{duration / 60}m{duration % 60}s"; - } - } - else - { - formatDuration = $"{duration}s"; - } - return formatDuration; - } - - /// - /// 格式化Duration时间,格式为00:00:00 - /// - /// - /// - public static string FormatDuration2(long duration) - { - string formatDuration; - if (duration / 60 > 0) - { - long dur = duration / 60; - if (dur / 60 > 0) - { - formatDuration = string.Format("{0:D2}", dur / 60) + ":" + string.Format("{0:D2}", dur % 60) + ":" + string.Format("{0:D2}", duration % 60); - } - else - { - formatDuration = "00:" + string.Format("{0:D2}", duration / 60) + ":" + string.Format("{0:D2}", duration % 60); - } - } - else - { - formatDuration = "00:00:" + string.Format("{0:D2}", duration); - } - return formatDuration; - } - - /// - /// 格式化Duration时间,格式为00:00 - /// - /// - /// - public static string FormatDuration3(long duration) - { - string formatDuration; - if (duration / 60 > 0) - { - long dur = duration / 60; - if (dur / 60 > 0) - { - formatDuration = string.Format("{0:D2}", dur / 60) + ":" + string.Format("{0:D2}", dur % 60) + ":" + string.Format("{0:D2}", duration % 60); - } - else - { - formatDuration = string.Format("{0:D2}", duration / 60) + ":" + string.Format("{0:D2}", duration % 60); - } - } - else - { - formatDuration = "00:" + string.Format("{0:D2}", duration); - } - return formatDuration; - } - - /// - /// 格式化数字,超过10000的数字将单位改为万,超过100000000的数字将单位改为亿,并保留1位小数 - /// - /// - /// - public static string FormatNumber(long number) - { - if (number > 99999999) - { - return (number / 100000000.0f).ToString("F1") + "亿"; - } - - if (number > 9999) - { - return (number / 10000.0f).ToString("F1") + "万"; - } - else - { - return number.ToString(); - } - } - - /// - /// 去除非法字符 - /// - /// - /// - public static string FormatFileName(string originName) - { - string destName = originName; - // Windows中不能作为文件名的字符 - destName = destName.Replace("\\", " "); - destName = destName.Replace("/", " "); - destName = destName.Replace(":", " "); - destName = destName.Replace("*", " "); - destName = destName.Replace("?", " "); - destName = destName.Replace("\"", " "); - destName = destName.Replace("<", " "); - destName = destName.Replace(">", " "); - destName = destName.Replace("|", " "); - - // 转义字符 - destName = destName.Replace("\a", ""); - destName = destName.Replace("\b", ""); - destName = destName.Replace("\f", ""); - destName = destName.Replace("\n", ""); - destName = destName.Replace("\r", ""); - destName = destName.Replace("\t", ""); - destName = destName.Replace("\v", ""); - - // 控制字符 - destName = Regex.Replace(destName, @"\p{C}+", string.Empty); - - return destName.Trim(); - } - - /// - /// 格式化网速 - /// - /// - /// - public static string FormatSpeed(float speed) - { - string formatSpeed; - if (speed <= 0) - { - formatSpeed = "0B/s"; - } - else if (speed < 1024) - { - formatSpeed = speed.ToString("#.##") + "B/s"; - } - else if (speed < 1024 * 1024) - { - formatSpeed = (speed / 1024).ToString("#.##") + "KB/s"; - } - else - { - formatSpeed = (speed / 1024 / 1024).ToString("#.##") + "MB/s"; - } - return formatSpeed; - } - - /// - /// 格式化字节大小,可用于文件大小的显示 - /// - /// - /// - public static string FormatFileSize(long fileSize) - { - string formatFileSize; - if (fileSize <= 0) - { - formatFileSize = "0B"; - } - else if (fileSize < 1024) - { - formatFileSize = fileSize.ToString() + "B"; - } - else if (fileSize < 1024 * 1024) - { - formatFileSize = (fileSize / 1024.0).ToString("#.##") + "KB"; - } - else if (fileSize < 1024 * 1024 * 1024) - { - formatFileSize = (fileSize / 1024.0 / 1024.0).ToString("#.##") + "MB"; - } - else - { - formatFileSize = (fileSize / 1024.0 / 1024.0 / 1024.0).ToString("#.##") + "GB"; - } - return formatFileSize; - } - - private static long GetInt(string value) - { - if (IsInt(value)) - { - return long.Parse(value); - } - else - { - return -1; - } - } - - private static bool IsInt(string value) - { - return Regex.IsMatch(value, @"^\d+$"); - } - - } - - - /// - /// 支持的视频类型 - /// - public enum VideoType - { - NONE, - VIDEO, // 对应 /video/BV - VIDEO_AV, // 对应 /video/av - // BANGUMI, // BANGUMI细分为以下三个部分 - BANGUMI_SEASON, // 对应 /bangumi/play/ss - BANGUMI_EPISODE, // 对应 /bangumi/play/ep - BANGUMI_MEDIA, // 对应 /bangumi/media/md - CHEESE_SEASON, // 对应 /cheese/play/ss - CHEESE_EPISODE // 对应 /cheese/play/ep - } - - /// - /// 线程 - /// - public enum ThreadStatus - { - MAIN_UI, // 主线程 - START_PARSE, // 开始解析url - ADD_ALL_TO_DOWNLOAD, - START_DOWNLOAD - } - - /// - /// 视频的编码格式,flv也视为编码放这里 - /// - [Serializable] - public enum VideoCodec - { - NONE = 1, - AVC, - HEVC, - FLV - } - -} diff --git a/src/Core/Downloader.cs b/src/Core/Downloader.cs deleted file mode 100644 index 02e3459..0000000 --- a/src/Core/Downloader.cs +++ /dev/null @@ -1,534 +0,0 @@ -using Core.entity; -using Core.settings; -using Newtonsoft.Json; -using System; -using System.Net; -using System.Text.RegularExpressions; - -namespace Core -{ - public static class Downloader - { - /// - /// 获得远程文件的大小 - /// - /// - /// - /// - public static long GetRemoteFileSize(string url, string referer) - { - try - { - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); - request.Method = "GET"; - request.Timeout = 30 * 1000; - request.UserAgent = Utils.GetUserAgent(); - //request.ContentType = "text/html;charset=UTF-8"; - request.Headers["accept-language"] = "zh-CN,zh;q=0.9,en;q=0.8"; - request.Referer = referer; - - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - return response.ContentLength; - } - catch (Exception e) - { - Console.WriteLine("GetRemoteFileSize()发生异常: {0}", e); - return 0; - } - } - - /// - /// 获得视频详情及播放列表 - /// - /// - /// - public static VideoViewData GetVideoInfo(string bvid, long aid, string referer, bool isBackup = false) - { - string url; - if (bvid != null) - { - url = $"https://api.bilibili.com/x/web-interface/view?bvid={bvid}"; - } - else if (aid >= 0) - { - url = $"https://api.bilibili.com/x/web-interface/view?aid={aid}"; - } - else - { return null; } - - // 采用备用的api,只能获取cid - if (isBackup) - { - string backupUrl = $"https://api.bilibili.com/x/player/pagelist?bvid={bvid}&jsonp=jsonp"; - url = backupUrl; - } - - string response = Utils.RequestWeb(url, referer); - - try - { - VideoView videoView; - if (isBackup) - { - Pagelist pagelist = JsonConvert.DeserializeObject(response); - - videoView = new VideoView - { - code = pagelist.code, - message = pagelist.message, - ttl = pagelist.ttl - }; - videoView.data.pages = pagelist.data; - } - else - { - videoView = JsonConvert.DeserializeObject(response); - } - - if (videoView != null) - { - if (videoView.data != null) - { - return videoView.data; - } - else - { - return null; - - // 进入备选的url中 - //return GetVideoInfo(bvid, referer, true); - } - } - else - { - return null; - } - } - catch (JsonReaderException e) - { - Console.WriteLine("GetVideoInfo()发生JsonReader异常: {0}", e); - return null; - } - catch (Exception e) - { - Console.WriteLine("GetVideoInfo()发生异常: {0}", e); - return null; - } - } - - /// - /// 通过seasonId获得番剧的剧集详情 - /// - /// - /// - public static BangumiSeasonResult GetBangumiSeason(long seasonId, string referer) - { - string url = $"https://api.bilibili.com/pgc/view/web/season?season_id={seasonId}"; - string response = Utils.RequestWeb(url, referer); - - try - { - BangumiSeason bangumiSeason = JsonConvert.DeserializeObject(response); - if (bangumiSeason != null) { return bangumiSeason.result; } - else { return null; } - } - catch (JsonReaderException e) - { - Console.WriteLine("GetBangumiSeason()发生JsonReader异常: {0}", e); - return null; - } - catch (Exception e) - { - Console.WriteLine("GetBangumiSeason()发生异常: {0}", e); - return null; - } - } - - public static long GetBangumiSeasonIdByMedia(long mediaId, string referer) - { - string url = $"https://api.bilibili.com/pgc/review/user?media_id={mediaId}"; - string response = Utils.RequestWeb(url, referer); - - try - { - BangumiMedia bangumiMedia = JsonConvert.DeserializeObject(response); - if (bangumiMedia.result.media != null) { return bangumiMedia.result.media.season_id; } - else { return 0; } - } - catch (JsonReaderException e) - { - Console.WriteLine("GetBangumiSeasonIdByMedia()发生JsonReader异常: {0}", e); - return 0; - } - catch (Exception e) - { - Console.WriteLine("GetBangumiSeasonIdByMedia()发生异常: {0}", e); - return 0; - } - } - - public static long GetBangumiSeasonIdByEpisode(long episode, string referer) - { - string url = $"https://www.bilibili.com/bangumi/play/ep{episode}"; - string response = Utils.RequestWeb(url, referer); - - // "ssId": 28324, - string pattern = "\"ssId\":\\s?\\d+,"; - Regex regex = new Regex(pattern); - Match match = regex.Match(response); - - // 删除多余的字符 - string ssId = match.Value.Replace("ssId", ""); - ssId = ssId.Replace("\"", ""); - ssId = ssId.Replace(":", ""); - ssId = ssId.Replace(" ", ""); - ssId = ssId.Replace(",", ""); - - long seasonId; - try - { - seasonId = long.Parse(ssId); - } - catch (FormatException e) - { - Console.WriteLine("GetBangumiSeasonIdByEpisode()发生异常: {0}", e); - return 0; - } - return seasonId; - } - - /// - /// 通过ep_id获得课程的信息 - /// - /// - /// - /// - public static CheeseSeasonData GetCheeseSeason(long seasonId, long episode, string referer) - { - string url = $"https://api.bilibili.com/pugv/view/web/season?"; - if (seasonId != 0) - { - url += $"season_id={seasonId}"; - } - else if (episode != 0) - { - url += $"ep_id={episode}"; - } - - string response = Utils.RequestWeb(url, referer); - - try - { - CheeseSeason cheeseSeason = JsonConvert.DeserializeObject(response); - if (cheeseSeason != null) { return cheeseSeason.data; } - else { return null; } - } - catch (JsonReaderException e) - { - Console.WriteLine("GetCheeseSeason()发生JsonReader异常: {0}", e); - return null; - } - catch (Exception e) - { - Console.WriteLine("GetCheeseSeason()发生异常: {0}", e); - return null; - } - } - - //public static long GetCheeseEpisodeIdBySeasonId(long seasonId, string referer) - //{ - // string url = $"https://api.bilibili.com/pugv/view/web/ep/list?season_id={seasonId}&pn=1"; - // string response = Utils.RequestWeb(url, referer); - - // try - // { - // CheeseList cheeseList = JsonConvert.DeserializeObject(response); - // if (cheeseList.data.items != null && cheeseList.data.items.Count > 0) - // { - // return cheeseList.data.items[0].id; - // } - // else { return 0; } - // } - // catch (JsonReaderException e) - // { - // Console.WriteLine("发生异常: {0}", e); - // return 0; - // } - //} - - /// - /// 获得音视频流链接 - /// - /// 视频的bvid - /// 视频的cid - public static PlayUrlData GetStreamInfo(string bvid, long avid, long cid, long episodeId, int quality, string referer, bool isProxy = false, int proxy = 0) - { - string baseUrlVideo = "https://api.bilibili.com/x/player/playurl"; - string baseUrlSeason = "https://api.bilibili.com/pgc/player/web/playurl"; - string baseUrlCheese = "https://api.bilibili.com/pugv/player/web/playurl"; - string baseUrl; - VideoType videoType = Common.GetVideoType(referer); - switch (videoType) - { - case VideoType.VIDEO: - baseUrl = baseUrlVideo; - break; - case VideoType.VIDEO_AV: - baseUrl = baseUrlVideo; - break; - case VideoType.BANGUMI_SEASON: - baseUrl = baseUrlSeason; - break; - case VideoType.BANGUMI_EPISODE: - baseUrl = baseUrlSeason; - break; - case VideoType.BANGUMI_MEDIA: - baseUrl = baseUrlSeason; - break; - case VideoType.CHEESE_SEASON: - baseUrl = baseUrlCheese; - break; - case VideoType.CHEESE_EPISODE: - baseUrl = baseUrlCheese; - break; - default: - baseUrl = baseUrlVideo; - break; - } - // TODO 没有的参数不加入url - //string url = $"{baseUrl}?cid={cid}&bvid={bvid}&avid={avid}&ep_id={episodeId}&qn={quality}&otype=json&fourk=1&fnver=0&fnval=16"; - string url = $"{baseUrl}?cid={cid}&qn={quality}&otype=json&fourk=1&fnver=0&fnval=16"; - if (bvid != null) - { - url += $"&bvid={bvid}"; - } - if (avid != 0) - { - url += $"&avid={avid}"; - } - if (episodeId != 0) - { - url += $"&ep_id={episodeId}"; - } - - // 代理网址 - //https://www.biliplus.com/BPplayurl.php?cid=180873425&qn=116&type=&otype=json&fourk=1&bvid=BV1pV411o7yD&ep_id=317925&fnver=0&fnval=16&module=pgc - if (isProxy && proxy == 1) - { - string proxyUrl1 = "https://www.biliplus.com/BPplayurl.php"; - url = $"{proxyUrl1}?cid={cid}&bvid={bvid}&qn={quality}&otype=json&fourk=1&fnver=0&fnval=16&module=pgc"; - } - else if (isProxy && proxy == 2) - { - string proxyUrl2 = "https://biliplus.ipcjs.top/BPplayurl.php"; - url = $"{proxyUrl2}?cid={cid}&bvid={bvid}&qn={quality}&otype=json&fourk=1&fnver=0&fnval=16&module=pgc"; - } - - string response = Utils.RequestWeb(url, referer); - //Console.WriteLine(response); - - try - { - PlayUrl playUrl; - if (isProxy) - { - PlayUrlData playUrlData = JsonConvert.DeserializeObject(response); - - playUrl = new PlayUrl - { - result = playUrlData - }; - } - else - { - playUrl = JsonConvert.DeserializeObject(response); - } - - if (playUrl != null) - { - if (playUrl.data != null) { return playUrl.data; } - if (playUrl.result != null) { return playUrl.result; } - - // 无法从B站获取数据,进入代理网站 - if (Settings.GetInstance().IsLiftingOfRegion() == ALLOW_STATUS.YES) - { - switch (proxy) - { - case 0: - return GetStreamInfo(bvid, avid, cid, episodeId, quality, referer, true, 1); - case 1: - return GetStreamInfo(bvid, avid, cid, episodeId, quality, referer, true, 2); - case 2: - return null; - } - } - - return null; - } - else { return null; } - } - catch (JsonReaderException e) - { - Console.WriteLine("GetStreamInfo()发生JsonReader异常: {0}", e); - return null; - } - catch (Exception e) - { - Console.WriteLine("GetStreamInfo()发生异常: {0}", e); - return null; - } - } - - //public static List GetAllDanmaku(long cid, long publishTime, string referer) - //{ - // List danmakus = new List(); - - // // 设置视频发布日期 - // DateTime publishDate = new DateTime(1970, 1, 1); - // publishDate = publishDate.AddSeconds(publishTime); - - // // 获得有弹幕的日期date - // List danmakuDateList = new List(); - // while (true) - // { - // string month = publishDate.ToString("yyyy-MM"); - // string url = $"https://api.bilibili.com/x/v2/dm/history/index?type=1&oid={cid}&month={month}"; - // string response = Utils.RequestWeb(url, referer); - - // DanmuDate danmakuDate; - // try - // { - // danmakuDate = JsonConvert.DeserializeObject(response); - // } - // catch (Exception e) - // { - // Console.WriteLine("GetAllDanmaku()发生异常: {0}", e); - // continue; - // } - // if (danmakuDate != null || danmakuDate.data != null) { danmakuDateList.AddRange(danmakuDate.data); } - - // if (publishDate.CompareTo(DateTime.Now) > 0) { break; } - // publishDate = publishDate.AddMonths(1); - // Thread.Sleep(100); - // } - - // // 获取弹幕 - // foreach (var date in danmakuDateList) - // { - // Console.WriteLine(date); - - // List danmakusOfOneDay = GetDanmaku(cid, date); - - // foreach (Danmaku danmaku in danmakusOfOneDay) - // { - // if (danmakus.Find(it => it.DanmuId == danmaku.DanmuId) == null) - // { - // danmakus.Add(danmaku); - // } - // } - // } - - // // 按弹幕发布时间排序 - // danmakus = danmakus.OrderBy(it => it.Timestamp).ToList(); - - // return danmakus; - //} - - //public static List GetDanmaku(long cid, string date, string referer) - //{ - // string url = $"https://api.bilibili.com/x/v2/dm/history?type=1&oid={cid}&date={date}"; - // string response = Utils.RequestWeb(url, referer); - - // // - // // {"code":-101,"message":"账号未登录","ttl":1} - // if (response.Contains("")) - // { - // List danmakus = new List(); - - // XmlDocument doc = new XmlDocument(); - // doc.LoadXml(response); - // // 取得节点名为d的XmlNode集合 - // XmlNodeList danmuList = doc.GetElementsByTagName("d"); - // foreach (XmlNode node in danmuList) - // { - // // 返回的是文字内容 - // string nodeText = node.InnerText; - // // 节点p属性值 - // string childValue = node.Attributes["p"].Value; - // // 拆分属性 - // string[] attrs = childValue.Split(','); - - // Danmaku danmaku = new Danmaku - // { - // Text = nodeText, - // Time = float.Parse(attrs[0]), - // Type = int.Parse(attrs[1]), - // Fontsize = int.Parse(attrs[2]), - // Color = long.Parse(attrs[3]), - // Timestamp = long.Parse(attrs[4]), - // Pool = int.Parse(attrs[5]), - // UserId = attrs[6], - // DanmuId = attrs[7] - // }; - // danmakus.Add(danmaku); - // } - - // return danmakus; - // } - // else - // { - // DanmuFromWeb danmu = JsonConvert.DeserializeObject(response); - // if (danmu != null) { Console.WriteLine(danmu.message); } - // return null; - // } - //} - - ///// - ///// 获取弹幕,不需要登录信息,只能获取3000条弹幕 - ///// - ///// - ///// - //public static List GetDanmaku(long cid, string referer) - //{ - // string url = $"https://api.bilibili.com/x/v1/dm/list.so?oid={cid}"; - // string response = Utils.RequestWeb(url, referer); - - // if (response.Contains("")) - // { - // List danmakus = new List(); - - // XmlDocument doc = new XmlDocument(); - // doc.LoadXml(response); - // // 取得节点名为d的XmlNode集合 - // XmlNodeList danmuList = doc.GetElementsByTagName("d"); - // foreach (XmlNode node in danmuList) - // { - // // 返回的是文字内容 - // string nodeText = node.InnerText; - // // 节点p属性值 - // string childValue = node.Attributes["p"].Value; - // // 拆分属性 - // string[] attrs = childValue.Split(','); - - // Danmaku danmaku = new Danmaku - // { - // Text = nodeText, - // Time = float.Parse(attrs[0]), - // Type = int.Parse(attrs[1]), - // Fontsize = int.Parse(attrs[2]), - // Color = long.Parse(attrs[3]), - // Timestamp = long.Parse(attrs[4]), - // Pool = int.Parse(attrs[5]), - // UserId = attrs[6], - // DanmuId = attrs[7] - // }; - // danmakus.Add(danmaku); - // } - - // return danmakus; - // } - // return null; - //} - - } -} diff --git a/src/Core/FFmpegHelper.cs b/src/Core/FFmpegHelper.cs deleted file mode 100644 index adfb4d7..0000000 --- a/src/Core/FFmpegHelper.cs +++ /dev/null @@ -1,254 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Windows; -using System.Windows.Controls; - -namespace Core -{ - public static class FFmpegHelper - { - - /// - /// 合并音频和视频 - /// - /// - /// - /// - public static bool MergeVideo(string video1, string video2, string destVideo) - { - string param = $"-i \"{video1}\" -i \"{video2}\" -acodec copy -vcodec copy -f mp4 \"{destVideo}\""; - if (video1 == null || !File.Exists(video1)) - { - param = $"-i \"{video2}\" -acodec copy -vcodec copy -f mp4 \"{destVideo}\""; - } - if (video2 == null || !File.Exists(video2)) - { - param = $"-i \"{video1}\" -acodec copy -vcodec copy -f mp4 \"{destVideo}\""; - } - if (!File.Exists(video1) && !File.Exists(video2)) { return false; } - - // 如果存在 - try { File.Delete(destVideo); } - catch (IOException e) - { - Console.WriteLine("MergeVideo()发生IO异常: {0}", e); - return false; - } - - ExcuteProcess("ffmpeg.exe", param, null, (s, e) => Console.WriteLine(e.Data)); - - try - { - if (video1 != null) { File.Delete(video1); } - if (video2 != null) { File.Delete(video2); } - } - catch (IOException e) - { - Console.WriteLine("MergeVideo()发生IO异常: {0}", e); - } - - return true; - } - - /// - /// 拼接多个视频 - /// - /// - /// - /// - /// - public static bool ConcatVideo(string workingDirectory, List flvFiles, string destVideo) - { - // contact的文件名,不包含路径 - string concatFileName = Guid.NewGuid().ToString("N") + "_concat.txt"; - try - { - string contact = ""; - foreach (string flv in flvFiles) - { - contact += $"file '{flv}'\n"; - } - - FileStream fileStream = new FileStream(workingDirectory + "/" + concatFileName, FileMode.Create); - StreamWriter streamWriter = new StreamWriter(fileStream); - //开始写入 - streamWriter.Write(contact); - //清空缓冲区 - streamWriter.Flush(); - //关闭流 - streamWriter.Close(); - fileStream.Close(); - } - catch (Exception e) - { - Console.WriteLine("ConcatVideo()发生异常: {0}", e); - return false; - } - - // ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mkv - // 加上-y,表示如果有同名文件,则默认覆盖 - string param = $"-f concat -safe 0 -i {concatFileName} -c copy \"{destVideo}\" -y"; - ExcuteProcess("ffmpeg.exe", param, workingDirectory, (s, e) => Console.WriteLine(e.Data)); - - // 删除临时文件 - try - { - // 删除concat文件 - File.Delete(workingDirectory + "/" + concatFileName); - - foreach (string flv in flvFiles) - { - File.Delete(flv); - } - } - catch (Exception e) - { - Console.WriteLine("ConcatVideo()发生异常: {0}", e); - } - - return true; - } - - /// - /// 去水印,非常消耗cpu资源 - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static void Delogo(string video, string destVideo, int x, int y, int width, int height, TextBox output = null, Window window = null) - { - // ffmpeg -i "video.mp4" -vf delogo=x=1670:y=50:w=180:h=70:show=1 "delogo.mp4" - string param = $"-i \"{video}\" -vf delogo=x={x}:y={y}:w={width}:h={height} \"{destVideo}\" -hide_banner"; - ExcuteProcess("ffmpeg.exe", param, - null, (s, e) => - { - Console.WriteLine(e.Data); - if (output != null && window != null) - { - window.Dispatcher.Invoke(new Action(() => - { - output.Text += e.Data + "\n"; - output.ScrollToEnd(); - })); - } - }); - } - - /// - /// 从一个视频中仅提取音频 - /// - /// 源视频 - /// 目标音频 - /// 输出信息 - /// - public static void ExtractAudio(string video, string audio, TextBox output = null, Window window = null) - { - // 抽取音频命令 - // ffmpeg -i 3.mp4 -vn -y -acodec copy 3.aac - // ffmpeg -i 3.mp4 -vn -y -acodec copy 3.m4a - string param = $"-i \"{video}\" -vn -y -acodec copy \"{audio}\" -hide_banner"; - ExcuteProcess("ffmpeg.exe", param, - null, (s, e) => - { - Console.WriteLine(e.Data); - if (output != null && window != null) - { - window.Dispatcher.Invoke(new Action(() => - { - output.Text += e.Data + "\n"; - output.ScrollToEnd(); - })); - } - }); - } - - /// - /// 从一个视频中仅提取视频 - /// - /// 源视频 - /// 目标视频 - /// 输出信息 - /// - public static void ExtractVideo(string video, string destVideo, TextBox output = null, Window window = null) - { - // 提取视频 (Extract Video) - // ffmpeg -i Life.of.Pi.has.subtitles.mkv -vcodec copy –an videoNoAudioSubtitle.mp4 - string param = $"-i \"{video}\" -y -vcodec copy -an \"{destVideo}\" -hide_banner"; - ExcuteProcess("ffmpeg.exe", param, - null, (s, e) => - { - Console.WriteLine(e.Data); - if (output != null && window != null) - { - window.Dispatcher.Invoke(new Action(() => - { - output.Text += e.Data + "\n"; - output.ScrollToEnd(); - })); - } - }); - } - - /// - /// 提取视频的帧,输出为图片 - /// - /// - /// - /// - public static void ExtractFrame(string video, string image, uint number) - { - // 提取帧 - // ffmpeg -i caiyilin.wmv -vframes 1 wm.bmp - string param = $"-i \"{video}\" -y -vframes {number} \"{image}\""; - ExcuteProcess("ffmpeg.exe", param, null, (s, e) => Console.WriteLine(e.Data)); - } - - - /// - /// 执行一个控制台程序 - /// - /// 程序名称 - /// 参数 - /// 工作路径 - /// 输出重定向 - private static void ExcuteProcess(string exe, string arg, string workingDirectory, DataReceivedEventHandler output) - { - using (var p = new Process()) - { - p.StartInfo.FileName = exe; - p.StartInfo.Arguments = arg; - - // 工作目录 - if (workingDirectory != null) - { - p.StartInfo.WorkingDirectory = workingDirectory; - } - - p.StartInfo.UseShellExecute = false; //输出信息重定向 - p.StartInfo.CreateNoWindow = true; - p.StartInfo.RedirectStandardError = true; - p.StartInfo.RedirectStandardOutput = true; - - // 将 StandardErrorEncoding 改为 UTF-8 才不会出现中文乱码 - p.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; - p.StartInfo.StandardErrorEncoding = System.Text.Encoding.UTF8; - - p.OutputDataReceived += output; - p.ErrorDataReceived += output; - - p.Start(); //启动线程 - p.BeginOutputReadLine(); - p.BeginErrorReadLine(); - p.WaitForExit(); //等待进程结束 - } - } - } - -} diff --git a/src/Core/FileDownloadUtil.cs b/src/Core/FileDownloadUtil.cs deleted file mode 100644 index 5501720..0000000 --- a/src/Core/FileDownloadUtil.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System; -using System.IO; -using System.Net; - -namespace Core -{ - // from https://www.jianshu.com/p/f31910ed8435 - public class FileDownloadUtil - { - private string url; //文件下载网络地址 - private string referer; //访问url的referer - private string path; //文件下载位置,如d:/download - private string filename; //文件名,如test.jpg - private string fileId; //文件ID,文件唯一标识,一般为UUID - - private System.Threading.Timer FileTimer; // 定时器 - private readonly int SPD_INTERVAL_SEC = 1; // 每隔多少秒计算一次速度 - private long FileTemp = 0; // 临时储存长度 - private float FileSpeed = 0; // //SPD_INTERVAL_SEC秒下载字节数 - - // 下载进度回调 - public delegate void ProgressChangedHandler(int progress, string fileId); - public event ProgressChangedHandler ProgressChanged; - protected virtual void OnProgressChanged(int progress, string fileId) - { - ProgressChanged?.Invoke(progress, fileId); - } - - public delegate void ProgressChanged2Handler(long totalBytes, long totalDownloadedByte, float speed, string fileId); - public event ProgressChanged2Handler ProgressChanged2; - protected virtual void OnProgressChanged2(long totalBytes, long totalDownloadedByte, float speed, string fileId) - { - ProgressChanged2?.Invoke(totalBytes, totalDownloadedByte, speed, fileId); - } - - // 下载结果回调 - public delegate void DownloadFinishHandler(bool isSuccess, string downloadPath, string fileId, string msg = null); - public event DownloadFinishHandler DownloadFinish; - protected virtual void OnDownloadFinish(bool isSuccess, string downloadPath, string fileId, string msg = null) - { - DownloadFinish?.Invoke(isSuccess, downloadPath, fileId, msg); - } - - //通过网络链接直接下载任意文件 - public FileDownloadUtil Init(string url, string referer, string path, string filename, string fileId) - { - this.url = url; - this.referer = referer; - this.path = path; - this.filename = filename; - this.fileId = fileId; - - return this; - } - - public void Download() - { - Download(url, path, filename, fileId); - } - - private void Download(string url, string path, string filename, string fileId) - { - - if (!Directory.Exists(path)) //判断文件夹是否存在 - Directory.CreateDirectory(path); - path = path + "\\" + filename; - - // 临时文件 "bilidownkyi\\" - string tempFile = Path.GetTempPath() + "downkyi." + Guid.NewGuid().ToString("N"); - //string tempFile = path + ".temp"; - - try - { - if (File.Exists(tempFile)) - { - File.Delete(tempFile); //存在则删除 - } - if (File.Exists(path)) - { - File.Delete(path); //存在则删除 - } - } - catch (IOException e) - { - Console.WriteLine("Download()发生IO异常: {0}", e); - } - - FileStream fs = null; - HttpWebRequest request = null; - HttpWebResponse response = null; - Stream responseStream = null; - try - { - //创建临时文件 - fs = new FileStream(tempFile, FileMode.Append, FileAccess.Write, FileShare.ReadWrite); - request = WebRequest.Create(url) as HttpWebRequest; - request.Method = "GET"; - request.Timeout = 60 * 1000; - request.UserAgent = Utils.GetUserAgent(); - //request.ContentType = "text/html;charset=UTF-8"; - request.Headers["accept-language"] = "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"; - //request.Headers["accept-encoding"] = "gzip, deflate, br"; - request.Headers["origin"] = "https://www.bilibili.com"; - request.Referer = referer; - - // 构造cookie - // web端请求视频链接时没有加入cookie - //if (!url.Contains("getLogin")) - //{ - // CookieContainer cookies = Login.GetLoginInfoCookies(); - // if (cookies != null) - // { - // request.CookieContainer = cookies; - // } - //} - - //发送请求并获取相应回应数据 - response = request.GetResponse() as HttpWebResponse; - //直到request.GetResponse()程序才开始向目标网页发送Post请求 - responseStream = response.GetResponseStream(); - byte[] bArr = new byte[1024]; - long totalBytes = response.ContentLength; //通过响应头获取文件大小,前提是响应头有文件大小 - int size = responseStream.Read(bArr, 0, (int)bArr.Length); //读取响应流到bArr,读取大小 - float percent = 0; //用来保存计算好的百分比 - long totalDownloadedByte = 0; //总共下载字节数 - - FileTimer = new System.Threading.Timer(SpeedTimer, null, 0, SPD_INTERVAL_SEC * 1000); - while (size > 0) //while (totalBytes > totalDownloadedByte) //while循环读取响应流 - { - fs.Write(bArr, 0, size); //写到临时文件 - // 定期刷新数据到磁盘,影响下载速度 - //fs.Flush(true); - - totalDownloadedByte += size; - FileTemp += size; - size = responseStream.Read(bArr, 0, (int)bArr.Length); - percent = (float)totalDownloadedByte / (float)totalBytes * 100; - - // 下载进度回调 - OnProgressChanged((int)percent, fileId); - OnProgressChanged2(totalBytes, totalDownloadedByte, FileSpeed, fileId); - } - - try - { - if (File.Exists(path)) - { - File.Delete(path); //存在则删除 - } - } - catch (IOException e) - { - Console.WriteLine("Download()发生IO异常: {0}", e); - } - - if (fs != null) - fs.Close(); - File.Move(tempFile, path); //重命名为正式文件 - OnDownloadFinish(true, path, fileId, null); //下载完成,成功回调 - } - catch (Exception ex) - { - Console.WriteLine("Download()发生异常: {0}", ex); - OnDownloadFinish(false, null, fileId, ex.Message); //下载完成,失败回调 - } - finally - { - if (fs != null) - fs.Close(); - if (request != null) - request.Abort(); - if (response != null) - response.Close(); - if (responseStream != null) - responseStream.Close(); - - try - { - if (File.Exists(tempFile)) - { - File.Delete(tempFile); //存在则删除 - } - } - catch (IOException e) - { - Console.WriteLine("Download()发生IO异常: {0}", e); - } - } - } - - private void SpeedTimer(object state) - { - FileSpeed = FileTemp / SPD_INTERVAL_SEC; //SPD_INTERVAL_SEC秒下载字节数, - FileTemp = 0; //清空临时储存 - } - - } -} diff --git a/src/Core/UserSpaceOld.cs b/src/Core/UserSpaceOld.cs deleted file mode 100644 index 88bd659..0000000 --- a/src/Core/UserSpaceOld.cs +++ /dev/null @@ -1,148 +0,0 @@ -using Core.entity; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; - -namespace Core -{ - public static class UserSpaceOld - { - - /// - /// 获取我创建的收藏夹 - /// - /// - /// - public static FavFolderData GetCreatedFavFolder(long mid) - { - string url = $"https://api.bilibili.com/x/v3/fav/folder/created/list?up_mid={mid}&ps=50"; - return GetAllFavFolder(url); - } - - /// - /// 获取我收藏的收藏夹 - /// - /// - /// - public static FavFolderData GetCollectedFavFolder(long mid) - { - string url = $"https://api.bilibili.com/x/v3/fav/folder/collected/list?up_mid={mid}&ps=50"; - return GetAllFavFolder(url); - } - - private static FavFolderData GetAllFavFolder(string baseUrl) - { - FavFolderData userFavoriteData = new FavFolderData - { - count = 0, - list = new List() - }; - int i = 0; - while (true) - { - i++; - string url = baseUrl + $"&pn={i}"; - - var data = GetFavFolder(url); - if (data == null) - { break; } - if (data.count == 0 || data.list == null) - { break; } - - userFavoriteData.list.AddRange(data.list); - } - userFavoriteData.count = userFavoriteData.list.Count; - return userFavoriteData; - } - - private static FavFolderData GetFavFolder(string url) - { - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - FavFolder favFolder = JsonConvert.DeserializeObject(response); - if (favFolder == null || favFolder.data == null) { return null; } - - return favFolder.data; - } - catch (Exception e) - { - Console.WriteLine("GetFavFolder()发生异常: {0}", e); - return null; - } - } - - /// - /// 获得某个收藏夹的内容 - /// - /// - /// - public static List GetAllFavResource(long mediaId) - { - string baseUrl = $"https://api.bilibili.com/x/v3/fav/resource/list?media_id={mediaId}&ps=20"; - List medias = new List(); - - int i = 0; - while (true) - { - i++; - string url = baseUrl + $"&pn={i}"; - - var data = GetFavResource(url); - if (data == null || data.Count == 0) - { break; } - - medias.AddRange(data); - } - return medias; - } - - private static List GetFavResource(string url) - { - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - FavResource favResource = JsonConvert.DeserializeObject(response); - if (favResource == null || favResource.data == null) { return null; } - return favResource.data.medias; - } - catch (Exception e) - { - Console.WriteLine("GetFavResource()发生异常: {0}", e); - return null; - } - } - - - /// - /// 获取订阅番剧的数量 - /// 废弃 - /// - /// - /// - //public static int GetBangumiFollowList(long mid) - //{ - // string url = $"https://space.bilibili.com/ajax/Bangumi/getList?mid={mid}"; - // string referer = "https://www.bilibili.com"; - // string response = Utils.RequestWeb(url, referer); - - // try - // { - // BangumiList bangumiList = JsonConvert.DeserializeObject(response); - // if (bangumiList == null || bangumiList.data == null) { return -1; } - - // return bangumiList.data.count; - // } - // catch (Exception e) - // { - // Console.WriteLine("发生异常: {0}", e); - // return 0; - // } - //} - - } -} diff --git a/src/Core/Utils.cs b/src/Core/Utils.cs deleted file mode 100644 index f27fc64..0000000 --- a/src/Core/Utils.cs +++ /dev/null @@ -1,430 +0,0 @@ -using Brotli; -using Core.api.login; -using Core.history; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Net; -using System.Runtime.Serialization.Formatters.Binary; -using System.Text; - -namespace Core -{ - public static class Utils - { - /// - /// 随机的UserAgent - /// - /// userAgent - public static string GetUserAgent() - { - string[] userAgents = { - // Chrome - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36", - - // 新版Edge - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36 Edg/83.0.478.58", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.66", - - // IE 11 - "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)", - - // 火狐 - "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0", - - // Opera - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36 OPR/63.0.3368.43", - - // MacOS Chrome - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36", - - // MacOS Safari - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15" - }; - - var time = DateTime.Now; - - Random random = new Random(time.GetHashCode()); - int number = random.Next(0, userAgents.Length - 1); - - return userAgents[number]; - } - - /// - /// 发送get或post请求 - /// - /// - /// - /// - /// - /// - public static string RequestWeb(string url, string referer = null, string method = "GET", Dictionary parameters = null, int retry = 3) - { - // 重试次数 - if (retry <= 0) { return ""; } - - // post请求,发送参数 - if (method == "POST" && parameters != null) - { - StringBuilder builder = new StringBuilder(); - int i = 0; - foreach (var item in parameters) - { - if (i > 0) builder.Append("&"); - builder.AppendFormat("{0}={1}", item.Key, item.Value); - i++; - } - - url += "?" + builder.ToString(); - } - - try - { - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); - request.Method = method; - request.Timeout = 30 * 1000; - request.UserAgent = GetUserAgent(); - //request.ContentType = "application/json,text/html,application/xhtml+xml,application/xml;charset=UTF-8"; - request.Headers["accept-language"] = "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"; - request.Headers["accept-encoding"] = "gzip, deflate, br"; - - //request.Headers["sec-fetch-dest"] = "empty"; - //request.Headers["sec-fetch-mode"] = "cors"; - //request.Headers["sec-fetch-site"] = "same-site"; - - // referer - if (referer != null) - { - request.Referer = referer; - } - - // 构造cookie - if (!url.Contains("getLogin")) - { - request.Headers["origin"] = "https://www.bilibili.com"; - - CookieContainer cookies = LoginHelper.GetInstance().GetLoginInfoCookies(); - if (cookies != null) - { - request.CookieContainer = cookies; - } - } - - //// post请求,发送参数 - //if (method == "POST" && parameters != null) - //{ - // StringBuilder builder = new StringBuilder(); - // int i = 0; - // foreach (var item in parameters) - // { - // if (i > 0) builder.Append("&"); - // builder.AppendFormat("{0}={1}", item.Key, item.Value); - // i++; - // } - // byte[] data = Encoding.UTF8.GetBytes(builder.ToString()); - // request.ContentLength = data.Length; - - // Stream reqStream = request.GetRequestStream(); - // reqStream.Write(data, 0, data.Length); - // reqStream.Close(); - - // Console.WriteLine("\n" + builder.ToString() + "\t" + data.Length + "\n"); - //} - - //HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - //Stream responseStream = response.GetResponseStream(); - //StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8); - //string str = streamReader.ReadToEnd(); - //streamReader.Close(); - //responseStream.Close(); - - string html = string.Empty; - using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) - { - if (response.ContentEncoding.ToLower().Contains("gzip")) - { - using (GZipStream stream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress)) - { - using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) - { - html = reader.ReadToEnd(); - } - } - } - else if (response.ContentEncoding.ToLower().Contains("deflate")) - { - using (DeflateStream stream = new DeflateStream(response.GetResponseStream(), CompressionMode.Decompress)) - { - using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) - { - html = reader.ReadToEnd(); - } - } - } - else if (response.ContentEncoding.ToLower().Contains("br")) - { - using (BrotliStream stream = new BrotliStream(response.GetResponseStream(), CompressionMode.Decompress)) - { - using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) - { - html = reader.ReadToEnd(); - } - } - } - else - { - using (Stream stream = response.GetResponseStream()) - { - using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) - { - html = reader.ReadToEnd(); - } - } - } - } - - return html; - } - catch (WebException e) - { - Console.WriteLine("RequestWeb()发生Web异常: {0}", e); - return RequestWeb(url, referer, method, parameters, retry - 1); - } - catch (IOException e) - { - Console.WriteLine("RequestWeb()发生IO异常: {0}", e); - return RequestWeb(url, referer, method, parameters, retry - 1); - } - catch (Exception e) - { - Console.WriteLine("RequestWeb()发生其他异常: {0}", e); - return RequestWeb(url, referer, method, parameters, retry - 1); - } - } - - /// - /// 解析二维码登录返回的url,用于设置cookie - /// - /// - /// - public static CookieContainer ParseCookie(string url) - { - CookieContainer cookieContainer = new CookieContainer(); - - if (url == null || url == "") { return cookieContainer; } - - string[] strList = url.Split('?'); - if (strList.Count() < 2) { return cookieContainer; } - - string[] strList2 = strList[1].Split('&'); - if (strList2.Count() == 0) { return cookieContainer; } - - // 获取expires - string expires = strList2.FirstOrDefault(it => it.Contains("Expires")).Split('=')[1]; - DateTime dateTime = DateTime.Now; - dateTime = dateTime.AddSeconds(int.Parse(expires)); - - foreach (var item in strList2) - { - string[] strList3 = item.Split('='); - if (strList3.Count() < 2) { continue; } - - string name = strList3[0]; - string value = strList3[1]; - - // 不需要 - if (name == "Expires" || name == "gourl") { continue; } - - // 添加cookie - cookieContainer.Add(new Cookie(name, value, "/", ".bilibili.com") { Expires = dateTime }); -#if DEBUG - Console.WriteLine(name + ": " + value + "\t" + cookieContainer.Count); -#endif - } - - return cookieContainer; - } - - /// - /// 将CookieContainer中的所有的Cookie读出来 - /// - /// - /// - public static List GetAllCookies(CookieContainer cc) - { - List lstCookies = new List(); - - Hashtable table = (Hashtable)cc.GetType().InvokeMember("m_domainTable", - System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | - System.Reflection.BindingFlags.Instance, null, cc, new object[] { }); - - foreach (object pathList in table.Values) - { - SortedList lstCookieCol = (SortedList)pathList.GetType().InvokeMember("m_list", - System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField - | System.Reflection.BindingFlags.Instance, null, pathList, new object[] { }); - foreach (CookieCollection colCookies in lstCookieCol.Values) - foreach (Cookie c in colCookies) lstCookies.Add(c); - } - - return lstCookies; - } - - /// - /// 写入cookies到磁盘 - /// - /// - /// - /// - public static bool WriteCookiesToDisk(string file, CookieContainer cookieJar) - { - return WriteObjectToDisk(file, cookieJar); - } - - /// - /// 从磁盘读取cookie - /// - /// - /// - public static CookieContainer ReadCookiesFromDisk(string file) - { - return (CookieContainer)ReadObjectFromDisk(file); - } - - /// - /// 写入历史数据到磁盘 - /// - /// - /// - /// - public static bool WriteHistoryToDisk(string file, HistoryEntity history) - { - return WriteObjectToDisk(file, history); - } - - /// - /// 从磁盘读取历史数据 - /// - /// - /// - public static HistoryEntity ReadHistoryFromDisk(string file) - { - return (HistoryEntity)ReadObjectFromDisk(file); - } - - /// - /// 写入序列化对象到磁盘 - /// - /// - /// - /// - public static bool WriteObjectToDisk(string file, object obj) - { - try - { - using (Stream stream = File.Create(file)) - { -#if DEBUG - Console.Out.Write("Writing object to disk... "); -#endif - BinaryFormatter formatter = new BinaryFormatter(); - formatter.Serialize(stream, obj); -#if DEBUG - Console.Out.WriteLine("Done."); -#endif - return true; - } - } - catch (IOException e) - { - Console.WriteLine("WriteObjectToDisk()发生IO异常: {0}", e); - return false; - } - catch (Exception e) - { - //Console.Out.WriteLine("Problem writing object to disk: " + e.GetType()); - Console.WriteLine("WriteObjectToDisk()发生异常: {0}", e); - return false; - } - } - - /// - /// 从磁盘读取序列化对象 - /// - /// - /// - public static object ReadObjectFromDisk(string file) - { - try - { - using (Stream stream = File.Open(file, FileMode.Open)) - { -#if DEBUG - Console.Out.Write("Reading object from disk... "); -#endif - BinaryFormatter formatter = new BinaryFormatter(); -#if DEBUG - Console.Out.WriteLine("Done."); -#endif - return formatter.Deserialize(stream); - } - } - catch (IOException e) - { - Console.WriteLine("ReadObjectFromDisk()发生IO异常: {0}", e); - return null; - } - catch (Exception e) - { - //Console.Out.WriteLine("Problem reading object from disk: " + e.GetType()); - Console.WriteLine("ReadObjectFromDisk()发生异常: {0}", e); - return null; - } - } - - /// - /// 生成二维码 - /// - /// 信息 - /// 版本 1 ~ 40 - /// 像素点大小 - /// 图标路径 - /// 图标尺寸 - /// 图标边框厚度 - /// 二维码白边 - /// 位图 - public static Bitmap EncodeQRCode(string msg, int version, int pixel, string icon_path, int icon_size, int icon_border, bool white_edge) - { - QRCoder.QRCodeGenerator code_generator = new QRCoder.QRCodeGenerator(); - - QRCoder.QRCodeData code_data = code_generator.CreateQrCode(msg, QRCoder.QRCodeGenerator.ECCLevel.H/* 这里设置容错率的一个级别 */, true, false, QRCoder.QRCodeGenerator.EciMode.Utf8, version); - - QRCoder.QRCode code = new QRCoder.QRCode(code_data); - - Bitmap icon; - if (icon_path == null || icon_path == "") - { - icon = null; - } - else - { - icon = new Bitmap(icon_path); - } - - Bitmap bmp = code.GetGraphic(pixel, Color.Black, Color.White, icon, icon_size, icon_border, white_edge); - return bmp; - } - - } - -} diff --git a/src/Core/api/danmaku/BiliDanmaku.cs b/src/Core/api/danmaku/BiliDanmaku.cs deleted file mode 100644 index 6218273..0000000 --- a/src/Core/api/danmaku/BiliDanmaku.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace Core.api.danmaku.entity -{ - public class BiliDanmaku - { - public long Id { get; set; } //弹幕dmID - public int Progress { get; set; } //出现时间 - public int Mode { get; set; } //弹幕类型 - public int Fontsize { get; set; } //文字大小 - public uint Color { get; set; } //弹幕颜色 - public string MidHash { get; set; } //发送者UID的HASH - public string Content { get; set; } //弹幕内容 - public long Ctime { get; set; } //发送时间 - public int Weight { get; set; } //权重 - //public string Action { get; set; } //动作? - public int Pool { get; set; } //弹幕池 - - public override string ToString() - { - //return base.ToString(); - - string separator = "\n"; - return $"id: {Id}{separator}" + - $"progress: {Progress}{separator}" + - $"mode: {Mode}{separator}" + - $"fontsize: {Fontsize}{separator}" + - $"color: {Color}{separator}" + - $"midHash: {MidHash}{separator}" + - $"content: {Content}{separator}" + - $"ctime: {Ctime}{separator}" + - $"weight: {Weight}{separator}" + - //$"action: {Action}{separator}" + - $"pool: {Pool}"; - } - - } -} diff --git a/src/Core/api/danmaku/DanmakuProtobuf.cs b/src/Core/api/danmaku/DanmakuProtobuf.cs deleted file mode 100644 index e2c8180..0000000 --- a/src/Core/api/danmaku/DanmakuProtobuf.cs +++ /dev/null @@ -1,115 +0,0 @@ -using Core.api.danmaku.entity; -using System; -using System.Collections.Generic; -using System.IO; - -namespace Core.api.danmaku -{ - /// - /// protobuf弹幕 - /// - public class DanmakuProtobuf - { - private static DanmakuProtobuf instance; - - /// - /// 获取DanmakuProtobuf实例 - /// - /// - public static DanmakuProtobuf GetInstance() - { - if (instance == null) - { - instance = new DanmakuProtobuf(); - } - return instance; - } - - /// - /// 隐藏DanmakuProtobuf()方法,必须使用单例模式 - /// - private DanmakuProtobuf() { } - - /// - /// 下载6分钟内的弹幕,返回弹幕列表 - /// - /// 稿件avID - /// 视频CID - /// 分包,每6分钟一包 - /// - public List GetDanmakuProto(long avid, long cid, int segmentIndex) - { - string url = $"https://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid={cid}&pid={avid}&segment_index={segmentIndex}"; - string referer = "https://www.bilibili.com"; - - FileDownloadUtil fileDownload = new FileDownloadUtil(); - fileDownload.Init(url, referer, Path.GetTempPath() + "downkyi/danmaku", $"{cid}-{segmentIndex}.proto", "DanmakuProtobuf"); - fileDownload.Download(); - - var danmakuList = new List(); - - DmSegMobileReply danmakus; - try - { - using (var input = File.OpenRead(Path.GetTempPath() + $"downkyi/danmaku/{cid}-{segmentIndex}.proto")) - { - danmakus = DmSegMobileReply.Parser.ParseFrom(input); - if (danmakus == null || danmakus.Elems == null) - { - return danmakuList; - } - - foreach (var dm in danmakus.Elems) - { - var danmaku = new BiliDanmaku - { - Id = dm.Id, - Progress = dm.Progress, - Mode = dm.Mode, - Fontsize = dm.Fontsize, - Color = dm.Color, - MidHash = dm.MidHash, - Content = dm.Content, - Ctime = dm.Ctime, - Weight = dm.Weight, - //Action = dm.Action, - Pool = dm.Pool - }; - danmakuList.Add(danmaku); - } - } - } - catch (Exception e) - { -#if DEBUG - Console.WriteLine("发生异常: {0}", e); -#endif - return null; - } - - return danmakuList; - } - - /// - /// 下载所有弹幕,返回弹幕列表 - /// - /// 稿件avID - /// 视频CID - /// - public List GetAllDanmakuProto(long avid, long cid) - { - var danmakuList = new List(); - - int segmentIndex = 0; - while (true) - { - segmentIndex += 1; - var danmakus = GetDanmakuProto(avid, cid, segmentIndex); - if (danmakus == null) { break; } - danmakuList.AddRange(danmakus); - } - return danmakuList; - } - - } -} diff --git a/src/Core/api/danmaku/proto/Danmaku.cs b/src/Core/api/danmaku/proto/Danmaku.cs deleted file mode 100644 index 75fb7b6..0000000 --- a/src/Core/api/danmaku/proto/Danmaku.cs +++ /dev/null @@ -1,814 +0,0 @@ -// -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: Danmaku.proto -// -#pragma warning disable 1591, 0612, 3021 -#region Designer generated code - -using pb = global::Google.Protobuf; -using pbc = global::Google.Protobuf.Collections; -using pbr = global::Google.Protobuf.Reflection; -using scg = global::System.Collections.Generic; -/// Holder for reflection information generated from Danmaku.proto -public static partial class DanmakuReflection { - - #region Descriptor - /// File descriptor for Danmaku.proto - public static pbr::FileDescriptor Descriptor { - get { return descriptor; } - } - private static pbr::FileDescriptor descriptor; - - static DanmakuReflection() { - byte[] descriptorData = global::System.Convert.FromBase64String( - string.Concat( - "Cg1EYW5tYWt1LnByb3RvIsgBCgtEYW5tYWt1RWxlbRIKCgJpZBgBIAEoAxIQ", - "Cghwcm9ncmVzcxgCIAEoBRIMCgRtb2RlGAMgASgFEhAKCGZvbnRzaXplGAQg", - "ASgFEg0KBWNvbG9yGAUgASgNEg8KB21pZEhhc2gYBiABKAkSDwoHY29udGVu", - "dBgHIAEoCRINCgVjdGltZRgIIAEoAxIOCgZ3ZWlnaHQYCSABKAUSDgoGYWN0", - "aW9uGAogASgJEgwKBHBvb2wYCyABKAUSDQoFaWRTdHIYDCABKAkiLwoQRG1T", - "ZWdNb2JpbGVSZXBseRIbCgVlbGVtcxgBIAMoCzIMLkRhbm1ha3VFbGVtYgZw", - "cm90bzM=")); - descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, - new pbr::FileDescriptor[] { }, - new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::DanmakuElem), global::DanmakuElem.Parser, new[]{ "Id", "Progress", "Mode", "Fontsize", "Color", "MidHash", "Content", "Ctime", "Weight", "Action", "Pool", "IdStr" }, null, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::DmSegMobileReply), global::DmSegMobileReply.Parser, new[]{ "Elems" }, null, null, null, null) - })); - } - #endregion - -} -#region Messages -public sealed partial class DanmakuElem : pb::IMessage -#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - , pb::IBufferMessage -#endif -{ - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new DanmakuElem()); - private pb::UnknownFieldSet _unknownFields; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pbr::MessageDescriptor Descriptor { - get { return global::DanmakuReflection.Descriptor.MessageTypes[0]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public DanmakuElem() { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public DanmakuElem(DanmakuElem other) : this() { - id_ = other.id_; - progress_ = other.progress_; - mode_ = other.mode_; - fontsize_ = other.fontsize_; - color_ = other.color_; - midHash_ = other.midHash_; - content_ = other.content_; - ctime_ = other.ctime_; - weight_ = other.weight_; - action_ = other.action_; - pool_ = other.pool_; - idStr_ = other.idStr_; - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public DanmakuElem Clone() { - return new DanmakuElem(this); - } - - /// Field number for the "id" field. - public const int IdFieldNumber = 1; - private long id_; - /// - ///弹幕dmID - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Id { - get { return id_; } - set { - id_ = value; - } - } - - /// Field number for the "progress" field. - public const int ProgressFieldNumber = 2; - private int progress_; - /// - ///出现时间 - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int Progress { - get { return progress_; } - set { - progress_ = value; - } - } - - /// Field number for the "mode" field. - public const int ModeFieldNumber = 3; - private int mode_; - /// - ///弹幕类型 - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int Mode { - get { return mode_; } - set { - mode_ = value; - } - } - - /// Field number for the "fontsize" field. - public const int FontsizeFieldNumber = 4; - private int fontsize_; - /// - ///文字大小 - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int Fontsize { - get { return fontsize_; } - set { - fontsize_ = value; - } - } - - /// Field number for the "color" field. - public const int ColorFieldNumber = 5; - private uint color_; - /// - ///弹幕颜色 - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public uint Color { - get { return color_; } - set { - color_ = value; - } - } - - /// Field number for the "midHash" field. - public const int MidHashFieldNumber = 6; - private string midHash_ = ""; - /// - ///发送者UID的HASH - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string MidHash { - get { return midHash_; } - set { - midHash_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - - /// Field number for the "content" field. - public const int ContentFieldNumber = 7; - private string content_ = ""; - /// - ///弹幕内容 - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string Content { - get { return content_; } - set { - content_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - - /// Field number for the "ctime" field. - public const int CtimeFieldNumber = 8; - private long ctime_; - /// - ///发送时间 - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Ctime { - get { return ctime_; } - set { - ctime_ = value; - } - } - - /// Field number for the "weight" field. - public const int WeightFieldNumber = 9; - private int weight_; - /// - ///权重 - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int Weight { - get { return weight_; } - set { - weight_ = value; - } - } - - /// Field number for the "action" field. - public const int ActionFieldNumber = 10; - private string action_ = ""; - /// - ///动作? - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string Action { - get { return action_; } - set { - action_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - - /// Field number for the "pool" field. - public const int PoolFieldNumber = 11; - private int pool_; - /// - ///弹幕池 - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int Pool { - get { return pool_; } - set { - pool_ = value; - } - } - - /// Field number for the "idStr" field. - public const int IdStrFieldNumber = 12; - private string idStr_ = ""; - /// - ///弹幕dmID(字串形式) - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string IdStr { - get { return idStr_; } - set { - idStr_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override bool Equals(object other) { - return Equals(other as DanmakuElem); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool Equals(DanmakuElem other) { - if (ReferenceEquals(other, null)) { - return false; - } - if (ReferenceEquals(other, this)) { - return true; - } - if (Id != other.Id) return false; - if (Progress != other.Progress) return false; - if (Mode != other.Mode) return false; - if (Fontsize != other.Fontsize) return false; - if (Color != other.Color) return false; - if (MidHash != other.MidHash) return false; - if (Content != other.Content) return false; - if (Ctime != other.Ctime) return false; - if (Weight != other.Weight) return false; - if (Action != other.Action) return false; - if (Pool != other.Pool) return false; - if (IdStr != other.IdStr) return false; - return Equals(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override int GetHashCode() { - int hash = 1; - if (Id != 0L) hash ^= Id.GetHashCode(); - if (Progress != 0) hash ^= Progress.GetHashCode(); - if (Mode != 0) hash ^= Mode.GetHashCode(); - if (Fontsize != 0) hash ^= Fontsize.GetHashCode(); - if (Color != 0) hash ^= Color.GetHashCode(); - if (MidHash.Length != 0) hash ^= MidHash.GetHashCode(); - if (Content.Length != 0) hash ^= Content.GetHashCode(); - if (Ctime != 0L) hash ^= Ctime.GetHashCode(); - if (Weight != 0) hash ^= Weight.GetHashCode(); - if (Action.Length != 0) hash ^= Action.GetHashCode(); - if (Pool != 0) hash ^= Pool.GetHashCode(); - if (IdStr.Length != 0) hash ^= IdStr.GetHashCode(); - if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); - } - return hash; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - output.WriteRawMessage(this); - #else - if (Id != 0L) { - output.WriteRawTag(8); - output.WriteInt64(Id); - } - if (Progress != 0) { - output.WriteRawTag(16); - output.WriteInt32(Progress); - } - if (Mode != 0) { - output.WriteRawTag(24); - output.WriteInt32(Mode); - } - if (Fontsize != 0) { - output.WriteRawTag(32); - output.WriteInt32(Fontsize); - } - if (Color != 0) { - output.WriteRawTag(40); - output.WriteUInt32(Color); - } - if (MidHash.Length != 0) { - output.WriteRawTag(50); - output.WriteString(MidHash); - } - if (Content.Length != 0) { - output.WriteRawTag(58); - output.WriteString(Content); - } - if (Ctime != 0L) { - output.WriteRawTag(64); - output.WriteInt64(Ctime); - } - if (Weight != 0) { - output.WriteRawTag(72); - output.WriteInt32(Weight); - } - if (Action.Length != 0) { - output.WriteRawTag(82); - output.WriteString(Action); - } - if (Pool != 0) { - output.WriteRawTag(88); - output.WriteInt32(Pool); - } - if (IdStr.Length != 0) { - output.WriteRawTag(98); - output.WriteString(IdStr); - } - if (_unknownFields != null) { - _unknownFields.WriteTo(output); - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (Id != 0L) { - output.WriteRawTag(8); - output.WriteInt64(Id); - } - if (Progress != 0) { - output.WriteRawTag(16); - output.WriteInt32(Progress); - } - if (Mode != 0) { - output.WriteRawTag(24); - output.WriteInt32(Mode); - } - if (Fontsize != 0) { - output.WriteRawTag(32); - output.WriteInt32(Fontsize); - } - if (Color != 0) { - output.WriteRawTag(40); - output.WriteUInt32(Color); - } - if (MidHash.Length != 0) { - output.WriteRawTag(50); - output.WriteString(MidHash); - } - if (Content.Length != 0) { - output.WriteRawTag(58); - output.WriteString(Content); - } - if (Ctime != 0L) { - output.WriteRawTag(64); - output.WriteInt64(Ctime); - } - if (Weight != 0) { - output.WriteRawTag(72); - output.WriteInt32(Weight); - } - if (Action.Length != 0) { - output.WriteRawTag(82); - output.WriteString(Action); - } - if (Pool != 0) { - output.WriteRawTag(88); - output.WriteInt32(Pool); - } - if (IdStr.Length != 0) { - output.WriteRawTag(98); - output.WriteString(IdStr); - } - if (_unknownFields != null) { - _unknownFields.WriteTo(ref output); - } - } - #endif - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int CalculateSize() { - int size = 0; - if (Id != 0L) { - size += 1 + pb::CodedOutputStream.ComputeInt64Size(Id); - } - if (Progress != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Progress); - } - if (Mode != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Mode); - } - if (Fontsize != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Fontsize); - } - if (Color != 0) { - size += 1 + pb::CodedOutputStream.ComputeUInt32Size(Color); - } - if (MidHash.Length != 0) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(MidHash); - } - if (Content.Length != 0) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Content); - } - if (Ctime != 0L) { - size += 1 + pb::CodedOutputStream.ComputeInt64Size(Ctime); - } - if (Weight != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Weight); - } - if (Action.Length != 0) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Action); - } - if (Pool != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Pool); - } - if (IdStr.Length != 0) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(IdStr); - } - if (_unknownFields != null) { - size += _unknownFields.CalculateSize(); - } - return size; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(DanmakuElem other) { - if (other == null) { - return; - } - if (other.Id != 0L) { - Id = other.Id; - } - if (other.Progress != 0) { - Progress = other.Progress; - } - if (other.Mode != 0) { - Mode = other.Mode; - } - if (other.Fontsize != 0) { - Fontsize = other.Fontsize; - } - if (other.Color != 0) { - Color = other.Color; - } - if (other.MidHash.Length != 0) { - MidHash = other.MidHash; - } - if (other.Content.Length != 0) { - Content = other.Content; - } - if (other.Ctime != 0L) { - Ctime = other.Ctime; - } - if (other.Weight != 0) { - Weight = other.Weight; - } - if (other.Action.Length != 0) { - Action = other.Action; - } - if (other.Pool != 0) { - Pool = other.Pool; - } - if (other.IdStr.Length != 0) { - IdStr = other.IdStr; - } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - input.ReadRawMessage(this); - #else - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); - break; - case 8: { - Id = input.ReadInt64(); - break; - } - case 16: { - Progress = input.ReadInt32(); - break; - } - case 24: { - Mode = input.ReadInt32(); - break; - } - case 32: { - Fontsize = input.ReadInt32(); - break; - } - case 40: { - Color = input.ReadUInt32(); - break; - } - case 50: { - MidHash = input.ReadString(); - break; - } - case 58: { - Content = input.ReadString(); - break; - } - case 64: { - Ctime = input.ReadInt64(); - break; - } - case 72: { - Weight = input.ReadInt32(); - break; - } - case 82: { - Action = input.ReadString(); - break; - } - case 88: { - Pool = input.ReadInt32(); - break; - } - case 98: { - IdStr = input.ReadString(); - break; - } - } - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); - break; - case 8: { - Id = input.ReadInt64(); - break; - } - case 16: { - Progress = input.ReadInt32(); - break; - } - case 24: { - Mode = input.ReadInt32(); - break; - } - case 32: { - Fontsize = input.ReadInt32(); - break; - } - case 40: { - Color = input.ReadUInt32(); - break; - } - case 50: { - MidHash = input.ReadString(); - break; - } - case 58: { - Content = input.ReadString(); - break; - } - case 64: { - Ctime = input.ReadInt64(); - break; - } - case 72: { - Weight = input.ReadInt32(); - break; - } - case 82: { - Action = input.ReadString(); - break; - } - case 88: { - Pool = input.ReadInt32(); - break; - } - case 98: { - IdStr = input.ReadString(); - break; - } - } - } - } - #endif - -} - -public sealed partial class DmSegMobileReply : pb::IMessage -#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - , pb::IBufferMessage -#endif -{ - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new DmSegMobileReply()); - private pb::UnknownFieldSet _unknownFields; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pbr::MessageDescriptor Descriptor { - get { return global::DanmakuReflection.Descriptor.MessageTypes[1]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public DmSegMobileReply() { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public DmSegMobileReply(DmSegMobileReply other) : this() { - elems_ = other.elems_.Clone(); - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public DmSegMobileReply Clone() { - return new DmSegMobileReply(this); - } - - /// Field number for the "elems" field. - public const int ElemsFieldNumber = 1; - private static readonly pb::FieldCodec _repeated_elems_codec - = pb::FieldCodec.ForMessage(10, global::DanmakuElem.Parser); - private readonly pbc::RepeatedField elems_ = new pbc::RepeatedField(); - /// - ///弹幕条目 - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public pbc::RepeatedField Elems { - get { return elems_; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override bool Equals(object other) { - return Equals(other as DmSegMobileReply); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool Equals(DmSegMobileReply other) { - if (ReferenceEquals(other, null)) { - return false; - } - if (ReferenceEquals(other, this)) { - return true; - } - if(!elems_.Equals(other.elems_)) return false; - return Equals(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override int GetHashCode() { - int hash = 1; - hash ^= elems_.GetHashCode(); - if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); - } - return hash; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - output.WriteRawMessage(this); - #else - elems_.WriteTo(output, _repeated_elems_codec); - if (_unknownFields != null) { - _unknownFields.WriteTo(output); - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - elems_.WriteTo(ref output, _repeated_elems_codec); - if (_unknownFields != null) { - _unknownFields.WriteTo(ref output); - } - } - #endif - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int CalculateSize() { - int size = 0; - size += elems_.CalculateSize(_repeated_elems_codec); - if (_unknownFields != null) { - size += _unknownFields.CalculateSize(); - } - return size; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(DmSegMobileReply other) { - if (other == null) { - return; - } - elems_.Add(other.elems_); - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - input.ReadRawMessage(this); - #else - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); - break; - case 10: { - elems_.AddEntriesFrom(input, _repeated_elems_codec); - break; - } - } - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); - break; - case 10: { - elems_.AddEntriesFrom(ref input, _repeated_elems_codec); - break; - } - } - } - } - #endif - -} - -#endregion - - -#endregion Designer generated code diff --git a/src/Core/api/danmaku/proto/Danmaku.proto b/src/Core/api/danmaku/proto/Danmaku.proto deleted file mode 100644 index 71f4f54..0000000 --- a/src/Core/api/danmaku/proto/Danmaku.proto +++ /dev/null @@ -1,20 +0,0 @@ -syntax = "proto3"; - -message DanmakuElem { - int64 id = 1; //弹幕dmID - int32 progress = 2; //出现时间 - int32 mode = 3; //弹幕类型 - int32 fontsize = 4; //文字大小 - uint32 color = 5; //弹幕颜色 - string midHash = 6; //发送者UID的HASH - string content = 7; //弹幕内容 - int64 ctime = 8; //发送时间 - int32 weight = 9; //权重 - string action = 10; //动作? - int32 pool = 11; //弹幕池 - string idStr = 12; //弹幕dmID(字串形式) -} - -message DmSegMobileReply { - repeated DanmakuElem elems = 1; //弹幕条目 -} diff --git a/src/Core/api/fileDownload/FileDownloadConfig.cs b/src/Core/api/fileDownload/FileDownloadConfig.cs deleted file mode 100644 index 7bea76d..0000000 --- a/src/Core/api/fileDownload/FileDownloadConfig.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Core.api.fileDownload -{ - [Serializable] - internal class FileDownloadConfig - { - public long DownloadSize { get; set; } - public long TotalSize { get; set; } - public Queue DownloadQueue { get; set; } - - /// - /// 保存文件下载的配置信息,包括总字节数、已下载字节数、下载队列信息 - /// - /// - /// - /// - /// - public static void SaveConfig(string configFile, long downloadSize, long totalSize, Queue downloadQueue) - { - var config = new FileDownloadConfig() - { - DownloadSize = downloadSize, - TotalSize = totalSize, - DownloadQueue = downloadQueue - }; - Utils.WriteObjectToDisk(configFile, config); - } - - /// - /// 读取文件下载的配置信息,包括总字节数、已下载字节数、下载队列信息 - /// - /// - /// - public static FileDownloadConfig ReadConfig(string configFile) - { - return (FileDownloadConfig)Utils.ReadObjectFromDisk(configFile); - } - - } -} diff --git a/src/Core/api/fileDownload/FileDownloadEvent.cs b/src/Core/api/fileDownload/FileDownloadEvent.cs deleted file mode 100644 index d641257..0000000 --- a/src/Core/api/fileDownload/FileDownloadEvent.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Core.api.fileDownload -{ - public class FileDownloadEvent - { - - //private long _downloadSize; - //private long _totalSize; - public FileDownloadEvent() { } - - // 每秒下载的速度 B/s - public float Speed { get; set; } - - public float Percent - { - get { return DownloadSize * 100.0f / TotalSize; } - } - - public long DownloadSize { get; set; } - - public long TotalSize { get; set; } - - - } -} diff --git a/src/Core/api/fileDownload/FileDownloadHelper.cs b/src/Core/api/fileDownload/FileDownloadHelper.cs deleted file mode 100644 index de0ad49..0000000 --- a/src/Core/api/fileDownload/FileDownloadHelper.cs +++ /dev/null @@ -1,317 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net; -using System.Threading; -using System.Threading.Tasks; - -namespace Core.api.fileDownload -{ - public class FileDownloadHelper - { - private const int DOWNLOAD_BUFFER_SIZE = 102400; //每次下载量 100KB - private const int THREAD_BUFFER_SIZE = 10485760; //每个线程每次最大下载大小 设为10MB 不能太小 否则会创建太多的request对象 - public delegate void ErrorMakedEventHandler(string errorstring); - public event ErrorMakedEventHandler ErrorMakedEvent; - public delegate void DownloadEventHandler(FileDownloadEvent e); - public event DownloadEventHandler DownloadEvent; - public delegate void StopEventHandler(); - public event StopEventHandler StopEvent; - private object locker = new object(); - private long downloadSize = 0; //已经下载的字节 - private CancellationTokenSource cancelTokenSource = new CancellationTokenSource(); - private ManualResetEvent mre = new ManualResetEvent(true); //初始化不等待 - private AutoResetEvent eventFinished = new AutoResetEvent(false); - - private void ThreadWork(string url, FileStream fs, Queue downQueue) - { - mre.WaitOne(); - if (cancelTokenSource.IsCancellationRequested) - { - return; - } - - Monitor.Enter(downQueue); - if (downQueue.Count == 0) - { - return; - } - ThreadDownloadInfo downInfo = downQueue.Dequeue(); - Monitor.Exit(downQueue); - - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); - request.AddRange(downInfo.StartLength); //设置Range值 - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - Stream ns = response.GetResponseStream(); - byte[] nbytes = new byte[DOWNLOAD_BUFFER_SIZE]; - int temp = 0; - int nReadSize = 0; - byte[] buffer = new byte[downInfo.Length]; //文件写入缓冲 - nReadSize = ns.Read(nbytes, 0, Math.Min(DOWNLOAD_BUFFER_SIZE, downInfo.Length)); - while (temp < downInfo.Length) - { - mre.WaitOne(); - Buffer.BlockCopy(nbytes, 0, buffer, temp, nReadSize); - lock (locker) - { - downloadSize += nReadSize; - } - temp += nReadSize; - nReadSize = ns.Read(nbytes, 0, Math.Min(DOWNLOAD_BUFFER_SIZE, downInfo.Length - temp)); - } - - lock (locker) - { - fs.Seek(downInfo.StartLength, SeekOrigin.Begin); - fs.Write(buffer, 0, buffer.Length); - } - - ns.Close(); - ThreadWork(url, fs, downQueue); - } - - public async void StartDownload(FileDownloadInfo info) - { - if (string.IsNullOrEmpty(info.DownLoadUrl)) - { throw new Exception("下载地址不能为空!"); } - if (!info.DownLoadUrl.ToLower().StartsWith("http://") || !info.DownLoadUrl.ToLower().StartsWith("https://")) - { throw new Exception("非法的下载地址!"); } - - downloadSize = 0; - await Task.Run(() => - { - try - { - long totalSize = 0; - long threadInitedLength = 0; //分配线程任务的下载量 - - #region 获取文件信息 - //打开网络连接 - HttpWebRequest initRequest = (HttpWebRequest)WebRequest.Create(info.DownLoadUrl); - WebResponse initResponse = initRequest.GetResponse(); - FileInfo fileMsg = FileInfo.GetFileMessage(initResponse); - totalSize = fileMsg.Length; - if ((!string.IsNullOrEmpty(fileMsg.FileName)) && info.LocalSaveFolder != null) - { - info.SavePath = Path.Combine(info.LocalSaveFolder, fileMsg.FileName); - } - //ReaderWriterLock readWriteLock = new ReaderWriterLock(); - #endregion - - #region 读取配置文件 - string configPath = info.SavePath.Substring(0, info.SavePath.LastIndexOf(".")) + ".cfg"; - FileDownloadConfig initInfo = null; - if (File.Exists(configPath) && (info.IsNew == false)) - { - initInfo = FileDownloadConfig.ReadConfig(configPath); - downloadSize = (long)initInfo.DownloadSize; - totalSize = (long)initInfo.TotalSize; - } - #endregion - - #region 计算速度 - //Stopwatch MyStopWatch = new Stopwatch(); - long lastDownloadSize = 0; //上次下载量 - bool isSendCompleteEvent = false; //是否完成 - Timer timer = new Timer(new TimerCallback((o) => - { - if (!isSendCompleteEvent) - { - FileDownloadEvent e = new FileDownloadEvent(); - e.DownloadSize = downloadSize; - e.TotalSize = totalSize; - if (totalSize > 0 && downloadSize == totalSize) - { - e.Speed = 0; - isSendCompleteEvent = true; - eventFinished.Set(); - } - else - { - e.Speed = downloadSize - lastDownloadSize; - lastDownloadSize = downloadSize; //更新上次下载量 - } - - DownloadEvent(e); - } - - }), null, 0, 1000); - #endregion - - string tempPath = info.SavePath.Substring(0, info.SavePath.LastIndexOf(".")) + ".dat"; - - #region 多线程下载 - //分配下载队列 - Queue downQueue = null; - if (initInfo == null || info.IsNew) - { - downQueue = new Queue(); //下载信息队列 - while (threadInitedLength < totalSize) - { - ThreadDownloadInfo downInfo = new ThreadDownloadInfo(); - downInfo.StartLength = threadInitedLength; - downInfo.Length = (int)Math.Min(Math.Min(THREAD_BUFFER_SIZE, totalSize - threadInitedLength), totalSize / info.ThreadCount); //下载量 - downQueue.Enqueue(downInfo); - threadInitedLength += downInfo.Length; - } - } - else - { - downQueue = initInfo.DownloadQueue; - } - - FileStream fs = new FileStream(tempPath, FileMode.OpenOrCreate); - fs.SetLength(totalSize); - int threads = info.ThreadCount; - - for (int i = 0; i < info.ThreadCount; i++) - { - ThreadPool.QueueUserWorkItem((state) => - { - ThreadWork(info.DownLoadUrl, fs, downQueue); - if (Interlocked.Decrement(ref threads) == 0) - { - (state as AutoResetEvent).Set(); - } - }, eventFinished); - } - - //等待所有线程完成 - eventFinished.WaitOne(); - if (fs != null) - { - fs.Close(); - } - fs = null; - if (File.Exists(info.SavePath)) - { - File.Delete(info.SavePath); - } - - if (downloadSize == totalSize) - { - File.Move(tempPath, info.SavePath); - File.Delete(configPath); - } - - if (cancelTokenSource.IsCancellationRequested && StopEvent != null) - { - StopEvent(); - //保存配置文件 - FileDownloadConfig.SaveConfig(configPath, downloadSize, totalSize, downQueue); - } - #endregion - - } - catch (Exception ex) - { - ErrorMakedEvent?.Invoke(ex.Message); - } - }); - - } - - public void Stop() - { - cancelTokenSource.Cancel(); - } - - public void Suspend() - { - mre.Reset(); - } - - public void Resume() - { - mre.Set(); - } - - //#region 获取文件信息 - //public class FileMessage - //{ - // public long Length { get; set; } - // public string FileName { get; set; } - //} - - //public FileMessage GetFileMessage(WebResponse response) - //{ - // FileMessage info = new FileMessage(); - - // if (response.Headers["Content-Disposition"] != null) - // { - // Match match = Regex.Match(response.Headers["Content-Disposition"], "filename=(.*)"); - // if (match.Success) - // { - // string fileName = match.Groups[1].Value; - // Encoding encoding = Encoding.UTF8; - // string str = (response as HttpWebResponse).CharacterSet; - // if (!string.IsNullOrEmpty(str)) - // { - // encoding = Encoding.GetEncoding(str); - // } - // info.FileName = System.Web.HttpUtility.UrlDecode(fileName, encoding); - // } - // } - - // if (response.Headers["Content-Length"] != null) - // { - // info.Length = long.Parse(response.Headers.Get("Content-Length")); - // } - // else - // { - // info.Length = response.ContentLength; - // } - - // return info; - //} - - - //#endregion - - //private void SaveConfig(string configPath, long downloadSize, long totalSize, Queue downQueue) - //{ - // stringBuilder sb = new stringBuilder(); - // sb.Append(downloadSize + ";" + totalSize + ";"); - // foreach (ThreadDownloadInfo info in downQueue) - // { - // sb.Append("(" + info.startLength + ","); - // sb.Append(info.length + ");"); - // } - - // byte[] buffer = Encoding.UTF8.GetBytes(sb.Tostring()); - // string str = Convert.ToBase64string(buffer); - // File.WriteAllText(configPath, str); - //} - - //private List ReadConfig(string configPath) - //{ - // List list = new List(); - // string str = File.ReadAllText(configPath); - // byte[] buffer = Convert.FromBase64string(str); - // str =Encoding.UTF8.Getstring(buffer); - // lock (locker) - // { - // string[] split = str.Split(';'); - // long downloadSize = Convert.ToInt64(split[0]); - // long totalSize = Convert.ToInt64(split[1]); - // Queue downQueue = new Queue(); //下载信息队列 - // foreach (Match match in Regex.Matches(str, "\\((\\d+),(\\d+)\\);")) - // { - // ThreadDownloadInfo downInfo = new ThreadDownloadInfo(); - // downInfo.startLength = Convert.ToInt64(match.Groups[1].Value); - // downInfo.length = Convert.ToInt32(match.Groups[2].Value); - // downQueue.Enqueue(downInfo); - // } - - // list.Add(downloadSize); - // list.Add(totalSize); - // list.Add(downQueue); - // } - - // return list; - //} - - - } - -} diff --git a/src/Core/api/fileDownload/FileDownloadInfo.cs b/src/Core/api/fileDownload/FileDownloadInfo.cs deleted file mode 100644 index e40cbc6..0000000 --- a/src/Core/api/fileDownload/FileDownloadInfo.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.IO; - -namespace Core.api.fileDownload -{ - public class FileDownloadInfo - { - - - // 下载地址 - public string DownLoadUrl { get; set; } - - private string _localSaveFolder; - // 本地保存路径 - public string LocalSaveFolder - { - get { return _localSaveFolder; } - set - { _localSaveFolder = value; } - } - - // 包含文件名的完整保存路径 - private string _savePath; - public string SavePath - { - get - { - if (_savePath == null) - { - if (_localSaveFolder == null) - { - throw new Exception("本地保存路径不能为空"); - } - - _savePath = Path.Combine(_localSaveFolder, Path.GetFileName(DownLoadUrl)); - - if (File.Exists(_savePath)) - { - if (IsNew) - { - if (IsOver) - { - File.Delete(_savePath); - } - else - { - _savePath = _savePath.Substring(0, _savePath.LastIndexOf(".")) + "(2)" + _savePath.Substring(_savePath.LastIndexOf(".")); - } - } - } - } - - return _savePath; - } - set - { - _savePath = value; - } - } - - private int _threadCount = 1; - ////// 线程数 - public int ThreadCount - { - get { return _threadCount; } - set { _threadCount = value; } - } - - ////// 是否覆盖已存在的文件 - public bool IsOver { get; set; } - - ////// 是否重新下载 - public bool IsNew { get; set; } - - - } -} diff --git a/src/Core/api/fileDownload/FileInfo.cs b/src/Core/api/fileDownload/FileInfo.cs deleted file mode 100644 index 934f84d..0000000 --- a/src/Core/api/fileDownload/FileInfo.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Net; -using System.Text.RegularExpressions; - -namespace Core.api.fileDownload -{ - internal class FileInfo - { - public long Length { get; set; } - public string FileName { get; set; } - - /// - /// 获取远程文件的信息 - /// - /// - /// - public static FileInfo GetFileMessage(WebResponse response) - { - FileInfo info = new FileInfo(); - - if (response.Headers["Content-Disposition"] != null) - { - Match match = Regex.Match(response.Headers["Content-Disposition"], "filename=(.*)"); - if (match.Success) - { - string fileName = match.Groups[1].Value; - info.FileName = WebUtility.UrlDecode(fileName); - } - } - - if (response.Headers["Content-Length"] != null) - { - info.Length = long.Parse(response.Headers.Get("Content-Length")); - } - else - { - info.Length = response.ContentLength; - } - - return info; - } - - } -} diff --git a/src/Core/api/fileDownload/ThreadDownloadInfo.cs b/src/Core/api/fileDownload/ThreadDownloadInfo.cs deleted file mode 100644 index f1e4364..0000000 --- a/src/Core/api/fileDownload/ThreadDownloadInfo.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Core.api.fileDownload -{ - internal class ThreadDownloadInfo - { - // 开始位置 - public long StartLength { get; set; } - - // 下载量 - public int Length { get; set; } - } -} diff --git a/src/Core/api/history/History.cs b/src/Core/api/history/History.cs deleted file mode 100644 index c02e92a..0000000 --- a/src/Core/api/history/History.cs +++ /dev/null @@ -1,90 +0,0 @@ -using Core.entity2.history; -using Newtonsoft.Json; -using System; - -namespace Core.api.history -{ - /// - /// 历史记录 - /// - public class History - { - private static History instance; - - /// - /// 获取UserInfo实例 - /// - /// - public static History GetInstance() - { - if (instance == null) - { - instance = new History(); - } - return instance; - } - - /// - /// History()方法,必须使用单例模式 - /// - private History() { } - - /// - /// 获取历史记录列表(视频、直播、专栏) - /// startId和startTime必须同时使用才有效,分别对应结果中的max和view_at,默认为0 - /// - /// 历史记录开始目标ID - /// 历史记录开始时间 - /// 每页项数 - /// 历史记录ID类型 - /// - public HistoryData GetHistory(long startId, long startTime, int ps = 30, HistoryBusiness business = HistoryBusiness.ARCHIVE) - { - string businessStr = string.Empty; - switch (business) - { - case HistoryBusiness.ARCHIVE: - businessStr = "archive"; - break; - case HistoryBusiness.PGC: - businessStr = "pgc"; - break; - case HistoryBusiness.LIVE: - businessStr = "live"; - break; - case HistoryBusiness.ARTICLE_LIST: - businessStr = "article-list"; - break; - case HistoryBusiness.ARTICLE: - businessStr = "article"; - break; - } - string url = $"https://api.bilibili.com/x/web-interface/history/cursor?max={startId}&view_at={startTime}&ps={ps}&business={businessStr}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var history = JsonConvert.DeserializeObject(response); - if (history == null || history.Data == null) { return null; } - return history.Data; - } - catch (Exception e) - { - Console.WriteLine("GetHistory()发生异常: {0}", e); - return null; - } - } - - } - - public enum HistoryBusiness - { - ARCHIVE = 1, // 稿件 - PGC, // 番剧(影视) - LIVE, // 直播 - ARTICLE_LIST, // 文集 - ARTICLE, // 文章 - } - -} diff --git a/src/Core/api/history/ToView.cs b/src/Core/api/history/ToView.cs deleted file mode 100644 index ceff6ef..0000000 --- a/src/Core/api/history/ToView.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Core.entity2.history; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; - -namespace Core.api.history -{ - /// - /// 获取稍后再看列表 - /// - public class ToView - { - private static ToView instance; - - /// - /// 获取ToView实例 - /// - /// - public static ToView GetInstance() - { - if (instance == null) - { - instance = new ToView(); - } - return instance; - } - - /// - /// 隐藏ToView()方法,必须使用单例模式 - /// - private ToView() { } - - /// - /// 获取稍后再看视频列表 - /// - /// - public List GetHistoryToView() - { - string url = "https://api.bilibili.com/x/v2/history/toview/web"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var toView = JsonConvert.DeserializeObject(response); - if (toView == null || toView.Data == null) { return null; } - return toView.Data.List; - } - catch (Exception e) - { - Console.WriteLine("GetHistoryToView()发生异常: {0}", e); - return null; - } - } - - } - -} diff --git a/src/Core/api/login/LoginHelper.cs b/src/Core/api/login/LoginHelper.cs deleted file mode 100644 index 7d23378..0000000 --- a/src/Core/api/login/LoginHelper.cs +++ /dev/null @@ -1,231 +0,0 @@ -using Core.settings; -using System; -using System.Drawing; -using System.IO; -using System.Net; -using System.Windows.Media.Imaging; - -namespace Core.api.login -{ - public class LoginHelper - { - private static LoginHelper instance; - - /// - /// 获取LoginHelper实例 - /// - /// - public static LoginHelper GetInstance() - { - if (instance == null) - { - instance = new LoginHelper(); - } - return instance; - } - - /// - /// 隐藏LoginHelper()方法,必须使用单例模式 - /// - private LoginHelper() { } - - private static readonly string LOCAL_LOGIN_INFO = Common.ConfigPath + "Login"; - private static readonly string SecretKey = "Ps*rB$TGaM#&JvOe"; // 16位密码,ps:密码位数没有限制,可任意设置 - - /// - /// 获得登录二维码 - /// - /// - public BitmapImage GetLoginQRCode() - { - try - { - string loginUrl = Login.GetInstance().GetLoginUrl().Data.Url; - return GetLoginQRCode(loginUrl); - } - catch (Exception e) - { - Console.WriteLine("GetLoginQRCode()发生异常: {0}", e); - return null; - } - } - - /// - /// 根据输入url生成二维码 - /// - /// - /// - public BitmapImage GetLoginQRCode(string url) - { - // 设置的参数影响app能否成功扫码 - Bitmap qrCode = Utils.EncodeQRCode(url, 10, 10, null, 0, 0, false); - - MemoryStream ms = new MemoryStream(); - qrCode.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); - byte[] bytes = ms.GetBuffer(); - ms.Close(); - - BitmapImage image = new BitmapImage(); - image.BeginInit(); - image.StreamSource = new MemoryStream(bytes); - image.EndInit(); - return image; - } - - /// - /// 保存登录的cookies到文件 - /// - /// - /// - public bool SaveLoginInfoCookies(string url) - { - if (!Directory.Exists(Common.ConfigPath)) - { - Directory.CreateDirectory(Common.ConfigPath); - } - - string tempFile = LOCAL_LOGIN_INFO + "-" + Guid.NewGuid().ToString("N"); - CookieContainer cookieContainer = Utils.ParseCookie(url); - - bool isSucceed = Utils.WriteCookiesToDisk(tempFile, cookieContainer); - if (isSucceed) - { - // 加密密钥,增加机器码 - string password = SecretKey + MachineCode.GetMachineCodeString(); - - try - { - Encryptor.EncryptFile(tempFile, LOCAL_LOGIN_INFO, password); - } - catch (Exception e) - { - Console.WriteLine("SaveLoginInfoCookies()发生异常: {0}", e); - return false; - } - } - - if (File.Exists(tempFile)) - { - File.Delete(tempFile); - } - return isSucceed; - } - - /// - /// 获得登录的cookies - /// - /// - public CookieContainer GetLoginInfoCookies() - { - string tempFile = LOCAL_LOGIN_INFO + "-" + Guid.NewGuid().ToString("N"); - - if (File.Exists(LOCAL_LOGIN_INFO)) - { - try - { - // 加密密钥,增加机器码 - string password = SecretKey + MachineCode.GetMachineCodeString(); - Encryptor.DecryptFile(LOCAL_LOGIN_INFO, tempFile, password); - } - catch (CryptoHelpException e) - { - Console.WriteLine("GetLoginInfoCookies()发生异常: {0}", e); - if (File.Exists(tempFile)) - { - File.Delete(tempFile); - } - return null; - } - catch (FileNotFoundException e) - { - Console.WriteLine("GetLoginInfoCookies()发生异常: {0}", e); - if (File.Exists(tempFile)) - { - File.Delete(tempFile); - } - return null; - } - catch (DirectoryNotFoundException e) - { - Console.WriteLine("GetLoginInfoCookies()发生异常: {0}", e); - if (File.Exists(tempFile)) - { - File.Delete(tempFile); - } - return null; - } - catch (Exception e) - { - Console.WriteLine("GetLoginInfoCookies()发生异常: {0}", e); - if (File.Exists(tempFile)) - { - File.Delete(tempFile); - } - return null; - } - } - else { return null; } - - CookieContainer cookies = Utils.ReadCookiesFromDisk(tempFile); - - if (File.Exists(tempFile)) - { - File.Delete(tempFile); - } - return cookies; - } - - /// - /// 返回登录信息的cookies的字符串 - /// - /// - public string GetLoginInfoCookiesString() - { - var cookieContainer = GetLoginInfoCookies(); - if (cookieContainer == null) - { - return ""; - } - - var cookies = Utils.GetAllCookies(cookieContainer); - - string cookie = string.Empty; - foreach (var item in cookies) - { - cookie += item.ToString() + ";"; - } - return cookie.TrimEnd(';'); - } - - /// - /// 注销登录 - /// - /// - public bool Logout() - { - if (File.Exists(LOCAL_LOGIN_INFO)) - { - try - { - File.Delete(LOCAL_LOGIN_INFO); - - Settings.GetInstance().SetUserInfo(new UserInfoForSetting - { - Mid = -1, - Name = "", - IsLogin = false, - IsVip = false - }); - return true; - } - catch (IOException e) - { - Console.WriteLine("Logout()发生异常: {0}", e); - return false; - } - } - return false; - } - - } -} diff --git a/src/Core/api/users/UserInfo.cs b/src/Core/api/users/UserInfo.cs deleted file mode 100644 index 5c0d421..0000000 --- a/src/Core/api/users/UserInfo.cs +++ /dev/null @@ -1,81 +0,0 @@ -using Core.entity2.users; -using Newtonsoft.Json; -using System; - -namespace Core.api.users -{ - /// - /// 用户基本信息 - /// - public class UserInfo - { - private static UserInfo instance; - - /// - /// 获取UserInfo实例 - /// - /// - public static UserInfo GetInstance() - { - if (instance == null) - { - instance = new UserInfo(); - } - return instance; - } - - /// - /// 隐藏UserInfo()方法,必须使用单例模式 - /// - private UserInfo() { } - - /// - /// 用户详细信息1 (用于空间) - /// - /// 目标用户UID - /// - public SpaceInfo GetInfoForSpace(long mid) - { - string url = $"https://api.bilibili.com/x/space/acc/info?mid={mid}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var spaceInfo = JsonConvert.DeserializeObject(response); - if (spaceInfo == null || spaceInfo.Data == null) { return null; } - return spaceInfo.Data; - } - catch (Exception e) - { - Console.WriteLine("GetInfoForSpace()发生异常: {0}", e); - return null; - } - } - - /// - /// 本用户详细信息 - /// - /// - public MyInfo GetMyInfo() - { - string url = "https://api.bilibili.com/x/space/myinfo"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var myInfo = JsonConvert.DeserializeObject(response); - if (myInfo == null || myInfo.Data == null) { return null; } - return myInfo.Data; - } - catch (Exception e) - { - Console.WriteLine("GetMyInfo()发生异常: {0}", e); - return null; - } - } - - } - -} diff --git a/src/Core/api/users/UserRelation.cs b/src/Core/api/users/UserRelation.cs deleted file mode 100644 index b7e432e..0000000 --- a/src/Core/api/users/UserRelation.cs +++ /dev/null @@ -1,290 +0,0 @@ -using Core.entity2.users; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; - -namespace Core.api.users -{ - /// - /// 用户关系相关 - /// - public class UserRelation - { - private static UserRelation instance; - - /// - /// 获取UserRelation实例 - /// - /// - public static UserRelation GetInstance() - { - if (instance == null) - { - instance = new UserRelation(); - } - return instance; - } - - /// - /// 隐藏UserRelation()方法,必须使用单例模式 - /// - private UserRelation() { } - - /// - /// 查询用户粉丝明细 - /// - /// 目标用户UID - /// 页码 - /// 每页项数 - /// - public RelationFollow GetFollowers(long mid, int pn, int ps) - { - string url = $"https://api.bilibili.com/x/relation/followers?vmid={mid}&pn={pn}&ps={ps}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var relationFollower = JsonConvert.DeserializeObject(response); - if (relationFollower == null || relationFollower.Data == null) { return null; } - return relationFollower.Data; - } - catch (Exception e) - { - Console.WriteLine("GetFollowers()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询用户所有的粉丝明细 - /// - /// 目标用户UID - /// - public List GetAllFollowers(long mid) - { - List result = new List(); - - int i = 0; - while (true) - { - i++; - int ps = 50; - - var data = GetFollowers(mid, i, ps); - //if (data == null) { continue; } - - if (data == null || data.List == null || data.List.Count == 0) - { break; } - - result.AddRange(data.List); - } - - return result; - } - - /// - /// 查询用户关注明细 - /// - /// 目标用户UID - /// 页码 - /// 每页项数 - /// 排序方式 - /// - public RelationFollow GetFollowings(long mid, int pn, int ps, FollowingOrder order = FollowingOrder.DEFAULT) - { - string orderType = ""; - if (order == FollowingOrder.ATTENTION) - { - orderType = "attention"; - } - - string url = $"https://api.bilibili.com/x/relation/followings?vmid={mid}&pn={pn}&ps={ps}&order_type={orderType}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var relationFollower = JsonConvert.DeserializeObject(response); - if (relationFollower == null || relationFollower.Data == null) { return null; } - return relationFollower.Data; - } - catch (Exception e) - { - Console.WriteLine("GetFollowings()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询用户所有的关注明细 - /// - /// 目标用户UID - /// 排序方式 - /// - public List GetAllFollowings(long mid, FollowingOrder order = FollowingOrder.DEFAULT) - { - List result = new List(); - - int i = 0; - while (true) - { - i++; - int ps = 50; - - var data = GetFollowings(mid, i, ps, order); - //if (data == null) { continue; } - - if (data == null || data.List == null || data.List.Count == 0) - { break; } - - result.AddRange(data.List); - } - - return result; - } - - /// - /// 查询悄悄关注明细 - /// - /// 页码 - /// 每页项数 - /// - public List GetWhispers(int pn, int ps) - { - string url = $"https://api.bilibili.com/x/relation/whispers?pn={pn}&ps={ps}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var relationWhisper = JsonConvert.DeserializeObject(response); - if (relationWhisper == null || relationWhisper.Data == null) { return null; } - return relationWhisper.Data; - } - catch (Exception e) - { - Console.WriteLine("GetWhispers()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询黑名单明细 - /// - /// 页码 - /// 每页项数 - /// - public List GetBlacks(int pn, int ps) - { - string url = $"https://api.bilibili.com/x/relation/blacks?pn={pn}&ps={ps}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var relationBlack = JsonConvert.DeserializeObject(response); - if (relationBlack == null || relationBlack.Data == null) { return null; } - return relationBlack.Data; - } - catch (Exception e) - { - Console.WriteLine("GetBlacks()发生异常: {0}", e); - return null; - } - } - - // 关注分组相关,只能查询当前登录账户的信息 - - /// - /// 查询关注分组列表 - /// - /// - public List GetFollowingGroup() - { - string url = $"https://api.bilibili.com/x/relation/tags"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var followingGroup = JsonConvert.DeserializeObject(response); - if (followingGroup == null || followingGroup.Data == null) { return null; } - return followingGroup.Data; - } - catch (Exception e) - { - Console.WriteLine("GetFollowingGroup()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询关注分组明细 - /// - /// 分组ID - /// 页数 - /// 每页项数 - /// 排序方式 - /// - public List GetFollowingGroupContent(int tagId, int pn, int ps, FollowingOrder order = FollowingOrder.DEFAULT) - { - string orderType = ""; - if (order == FollowingOrder.ATTENTION) - { - orderType = "attention"; - } - - string url = $"https://api.bilibili.com/x/relation/tag?tagid={tagId}&pn={pn}&ps={ps}&order_type={orderType}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var content = JsonConvert.DeserializeObject(response); - if (content == null || content.Data == null) { return null; } - return content.Data; - } - catch (Exception e) - { - Console.WriteLine("GetFollowingGroupContent()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询所有的关注分组明细 - /// - /// 分组ID - /// 排序方式 - /// - public List GetAllFollowingGroupContent(int tagId, FollowingOrder order = FollowingOrder.DEFAULT) - { - List result = new List(); - - int i = 0; - while (true) - { - i++; - int ps = 50; - - var data = GetFollowingGroupContent(tagId, i, ps, order); - - if (data == null || data.Count == 0) - { break; } - - result.AddRange(data); - } - - return result; - } - - } - - public enum FollowingOrder - { - DEFAULT = 1, // 按照关注顺序排列,默认 - ATTENTION // 按照最常访问排列 - } - -} diff --git a/src/Core/api/users/UserSpace.cs b/src/Core/api/users/UserSpace.cs deleted file mode 100644 index 4661fda..0000000 --- a/src/Core/api/users/UserSpace.cs +++ /dev/null @@ -1,520 +0,0 @@ -using Core.entity2.users; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Core.api.users -{ - /// - /// 用户空间信息 - /// - public class UserSpace - { - private static UserSpace instance; - - /// - /// 获取UserSpace实例 - /// - /// - public static UserSpace GetInstance() - { - if (instance == null) - { - instance = new UserSpace(); - } - return instance; - } - - /// - /// 隐藏UserSpace()方法,必须使用单例模式 - /// - private UserSpace() { } - - /// - /// 查询空间设置 - /// - /// - /// - public SpaceSettings GetSpaceSettings(long mid) - { - string url = $"https://space.bilibili.com/ajax/settings/getSettings?mid={mid}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var settings = JsonConvert.DeserializeObject(response); - if (settings == null || settings.Data == null || !settings.Status) { return null; } - - return settings.Data; - } - catch (Exception e) - { - Console.WriteLine("GetSpaceSettings()发生异常: {0}", e); - return null; - } - } - - /// - /// 获取用户投稿视频的所有分区 - /// - /// 用户id - /// - public List GetPublicationType(long mid) - { - int pn = 1; - int ps = 1; - var publication = GetPublication(mid, pn, ps); - return GetPublicationType(publication); - } - - /// - /// 获取用户投稿视频的所有分区 - /// - /// 用户id - /// - public List GetPublicationType(SpacePublicationList publication) - { - if (publication == null || publication.Tlist == null) - { - return null; - } - - List result = new List(); - JObject typeList = JObject.Parse(publication.Tlist.ToString("N")); - foreach (var item in typeList) - { - var value = JsonConvert.DeserializeObject(item.Value.ToString()); - result.Add(value); - } - return result; - } - - /// - /// 查询用户所有的投稿视频明细 - /// - /// 用户id - /// 排序 - /// 视频分区 - /// 搜索关键词 - /// - public async Task> GetAllPublication(long mid, int tid = 0, PublicationOrder order = PublicationOrder.PUBDATE, string keyword = "") - { - List result = new List(); - - await Task.Run(() => - { - int i = 0; - while (true) - { - i++; - int ps = 100; - - var data = GetPublication(mid, i, ps, tid, order, keyword); - //if (data == null) { continue; } - - if (data == null || data.Vlist == null || data.Vlist.Count == 0) - { break; } - - result.AddRange(data.Vlist); - } - }); - - return result; - } - - /// - /// 查询用户投稿视频明细 - /// - /// 用户id - /// 页码 - /// 每页的视频数 - /// 排序 - /// 视频分区 - /// 搜索关键词 - /// - public SpacePublicationList GetPublication(long mid, int pn, int ps, int tid = 0, PublicationOrder order = PublicationOrder.PUBDATE, string keyword = "") - { - string url = $"https://api.bilibili.com/x/space/arc/search?mid={mid}&pn={pn}&ps={ps}&order={order.ToString("G").ToLower()}&tid={tid}&keyword={keyword}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - // 忽略play的值为“--”时的类型错误 - var settings = new JsonSerializerSettings - { - Error = (sender, args) => - { - if (Equals(args.ErrorContext.Member, "play") && - args.ErrorContext.OriginalObject.GetType() == typeof(SpacePublicationListVideo)) - { - args.ErrorContext.Handled = true; - } - } - }; - - var spacePublication = JsonConvert.DeserializeObject(response, settings); - if (spacePublication == null || spacePublication.Data == null) { return null; } - return spacePublication.Data.List; - } - catch (Exception e) - { - Console.WriteLine("GetPublication()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询用户频道列表 - /// - /// 用户id - /// - public List GetChannelList(long mid) - { - string url = $"https://api.bilibili.com/x/space/channel/list?mid={mid}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var spaceChannel = JsonConvert.DeserializeObject(response); - if (spaceChannel == null || spaceChannel.Data == null) { return null; } - return spaceChannel.Data.List; - } - catch (Exception e) - { - Console.WriteLine("GetChannelList()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询用户频道中的所有视频 - /// - /// - /// - /// - public List GetAllChannelVideoList(long mid, long cid) - { - List result = new List(); - - int i = 0; - while (true) - { - i++; - int ps = 100; - - var data = GetChannelVideoList(mid, cid, i, ps); - if (data == null || data.Count == 0) - { break; } - - result.AddRange(data); - } - return result; - } - - /// - /// 查询用户频道中的视频 - /// - /// - /// - /// - /// - /// - public List GetChannelVideoList(long mid, long cid, int pn, int ps) - { - string url = $"https://api.bilibili.com/x/space/channel/video?mid={mid}&cid={cid}&pn={pn}&ps={ps}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var spaceChannelVideo = JsonConvert.DeserializeObject(response); - if (spaceChannelVideo == null || spaceChannelVideo.Data == null || spaceChannelVideo.Data.List == null) - { return null; } - return spaceChannelVideo.Data.List.Archives; - } - catch (Exception e) - { - Console.WriteLine("GetChannelVideoList()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询用户创建的视频收藏夹 - /// - /// 目标用户UID - /// 页码 - /// 每页项数 - /// - public List GetCreatedFavoriteFolder(long mid, int pn, int ps) - { - string url = $"https://api.bilibili.com/x/v3/fav/folder/created/list?up_mid={mid}&pn={pn}&ps={ps}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var favoriteFolder = JsonConvert.DeserializeObject(response); - if (favoriteFolder == null || favoriteFolder.Data == null || favoriteFolder.Data.List == null) - { return null; } - return favoriteFolder.Data.List; - } - catch (Exception e) - { - Console.WriteLine("GetCreatedFavoriteFolder()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询所有的用户创建的视频收藏夹 - /// - /// 目标用户UID - /// - public List GetAllCreatedFavoriteFolder(long mid) - { - List result = new List(); - - int i = 0; - while (true) - { - i++; - int ps = 50; - - var data = GetCreatedFavoriteFolder(mid, i, ps); - if (data == null || data.Count == 0) - { break; } - - result.AddRange(data); - } - return result; - } - - /// - /// 查询用户收藏的视频收藏夹 - /// - /// 目标用户UID - /// 页码 - /// 每页项数 - /// - public List GetCollectedFavoriteFolder(long mid, int pn, int ps) - { - string url = $"https://api.bilibili.com/x/v3/fav/folder/collected/list?up_mid={mid}&pn={pn}&ps={ps}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var favoriteFolder = JsonConvert.DeserializeObject(response); - if (favoriteFolder == null || favoriteFolder.Data == null || favoriteFolder.Data.List == null) - { return null; } - return favoriteFolder.Data.List; - } - catch (Exception e) - { - Console.WriteLine("GetCollectedFavoriteFolder()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询所有的用户收藏的视频收藏夹 - /// - /// 目标用户UID - /// - public List GetAllCollectedFavoriteFolder(long mid) - { - List result = new List(); - - int i = 0; - while (true) - { - i++; - int ps = 50; - - var data = GetCollectedFavoriteFolder(mid, i, ps); - if (data == null || data.Count == 0) - { break; } - - result.AddRange(data); - } - return result; - } - - /// - /// 查询视频收藏夹的内容 - /// - /// 收藏夹ID - /// 页码 - /// 每页项数 - /// - public List GetFavoriteFolderResource(long mediaId, int pn, int ps) - { - string url = $"https://api.bilibili.com/x/v3/fav/resource/list?media_id={mediaId}&pn={pn}&ps={ps}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var resource = JsonConvert.DeserializeObject(response); - if (resource == null || resource.Data == null || resource.Data.Medias == null) - { return null; } - return resource.Data.Medias; - } - catch (Exception e) - { - Console.WriteLine("GetFavoriteFolderResource()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询视频收藏夹的所有内容 - /// - /// 收藏夹ID - /// - public List GetAllFavoriteFolderResource(long mediaId) - { - List result = new List(); - - int i = 0; - while (true) - { - i++; - int ps = 20; - - var data = GetFavoriteFolderResource(mediaId, i, ps); - if (data == null || data.Count == 0) - { break; } - - result.AddRange(data); - } - return result; - } - - /// - /// 查询用户发布的课程列表 - /// - /// 目标用户UID - /// 页码 - /// 每页项数 - /// - public List GetCheese(long mid, int pn, int ps) - { - string url = $"https://api.bilibili.com/pugv/app/web/season/page?mid={mid}&pn={pn}&ps={ps}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var cheese = JsonConvert.DeserializeObject(response); - if (cheese == null || cheese.Data == null || cheese.Data.Items == null) - { return null; } - return cheese.Data.Items; - } - catch (Exception e) - { - Console.WriteLine("GetCheese()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询用户发布的所有课程列表 - /// - /// 目标用户UID - /// - public List GetAllCheese(long mid) - { - List result = new List(); - - int i = 0; - while (true) - { - i++; - int ps = 50; - - var data = GetCheese(mid, i, ps); - if (data == null || data.Count == 0) - { break; } - - result.AddRange(data); - } - return result; - } - - /// - /// 查询用户追番(追剧)明细 - /// - /// 目标用户UID - /// 查询类型 - /// 页码 - /// 每页项数 - /// - public BangumiFollowData GetBangumiFollow(long mid, BangumiType type, int pn, int ps) - { - string url = $"https://api.bilibili.com/x/space/bangumi/follow/list?vmid={mid}&type={type:D}&pn={pn}&ps={ps}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var bangumiFollow = JsonConvert.DeserializeObject(response); - if (bangumiFollow == null || bangumiFollow.Data == null) - { return null; } - return bangumiFollow.Data; - } - catch (Exception e) - { - Console.WriteLine("GetBangumiFollow()发生异常: {0}", e); - return null; - } - } - - /// - /// 查询用户所有的追番(追剧)明细 - /// - /// 目标用户UID - /// 查询类型 - /// - public List GetAllBangumiFollow(long mid, BangumiType type) - { - List result = new List(); - - int i = 0; - while (true) - { - i++; - int ps = 30; - - var data = GetBangumiFollow(mid, type, i, ps); - if (data == null || data.List == null || data.List.Count == 0) - { break; } - - result.AddRange(data.List); - } - return result; - } - - } - - - public enum PublicationOrder - { - PUBDATE = 1, // 最新发布,默认 - CLICK, // 最多播放 - STOW // 最多收藏 - } - - public enum BangumiType - { - ANIME = 1, // 番剧 - EPISODE = 2 // 剧集、电影 - } - -} diff --git a/src/Core/api/users/UserStatus.cs b/src/Core/api/users/UserStatus.cs deleted file mode 100644 index 3dcbb6a..0000000 --- a/src/Core/api/users/UserStatus.cs +++ /dev/null @@ -1,83 +0,0 @@ -using Core.entity2.users; -using Newtonsoft.Json; -using System; - -namespace Core.api.users -{ - /// - /// 用户状态数 - /// - public class UserStatus - { - private static UserStatus instance; - - /// - /// 获取UserStatus实例 - /// - /// - public static UserStatus GetInstance() - { - if (instance == null) - { - instance = new UserStatus(); - } - return instance; - } - - /// - /// 隐藏UserStatus()方法,必须使用单例模式 - /// - private UserStatus() { } - - /// - /// 关系状态数 - /// - /// - /// - public UserRelationStat GetUserRelationStat(long mid) - { - string url = $"https://api.bilibili.com/x/relation/stat?vmid={mid}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var userRelationStat = JsonConvert.DeserializeObject(response); - if (userRelationStat == null || userRelationStat.Data == null) { return null; } - return userRelationStat.Data; - } - catch (Exception e) - { - Console.WriteLine("GetUserRelationStat()发生异常: {0}", e); - return null; - } - } - - /// - /// UP主状态数 - /// - /// 注:该接口需要任意用户登录,否则不会返回任何数据 - /// - /// - /// - public UpStat GetUpStat(long mid) - { - string url = $"https://api.bilibili.com/x/space/upstat?mid={mid}"; - string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); - - try - { - var upStat = JsonConvert.DeserializeObject(response); - if (upStat == null || upStat.Data == null) { return null; } - return upStat.Data; - } - catch (Exception e) - { - Console.WriteLine("GetUpStat()发生异常: {0}", e); - return null; - } - } - - } -} diff --git a/src/Core/aria2cNet/Aria2c.cs b/src/Core/aria2cNet/Aria2c.cs deleted file mode 100644 index 6067942..0000000 --- a/src/Core/aria2cNet/Aria2c.cs +++ /dev/null @@ -1,433 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Net.WebSockets; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -// 代码来源 -// https://blog.csdn.net/haibin258/article/details/87905628 - -// Aria2详细信息请看 -// https://aria2.github.io/manual/en/html/aria2c.html#rpc-interface - -// 废弃 -namespace Core.aria2cNet -{ - //定义一个类用于转码成JSON字符串发送给Aria2 json-rpc接口 - public class JsonClass - { - public string Jsonrpc { get; set; } - public string Id { get; set; } - public string Method { get; set; } - public List Params { get; set; } - } - - public class Aria2 - { - public static ClientWebSocket webSocket; // 用于连接到Aria2Rpc的客户端 - public static CancellationToken cancellationToken; // 传播有关应取消操作的通知 - - /// - /// 连接Aria2Rpc服务器 - /// - /// - /// - public static async Task ConnectServer(string uri) - { - webSocket = new ClientWebSocket(); // 用于连接到Aria2Rpc的客户端 - cancellationToken = new CancellationToken(); // 传播有关应取消操作的通知 - bool status = false; //储存连接状态 - try - { - //连接服务器 - await webSocket.ConnectAsync(new Uri(uri), cancellationToken); - } - catch - { - status = false; - } - //检查连接是否成功 - if (webSocket.State == WebSocketState.Open) - { - status = true; - } - return status; - } - - - /// - /// JsonClass类转为json格式 - /// - /// - /// - private static string ToJson(JsonClass json) - { - string str = "{" + "\"jsonrpc\":\"" + json.Jsonrpc + "\",\"id\":\"" + json.Id + "\",\"method\":\"" + json.Method + "\",\"params\":["; - for (int i = 0; i < json.Params.Count; i++) - { - if (json.Method == "aria2.addUri") - { - str += "[\"" + json.Params[i] + "\"]"; - } - else if (json.Method == "aria2.tellStatus") - { - if (i == 0) - { - str += "\"" + json.Params[i] + "\""; - } - else - { - str += "[\"" + json.Params[i] + "\"]"; - } - } - else - { - str += "\"" + json.Params[i] + "\""; - } - if (json.Params.Count - 1 > i) - { - str += ","; - } - } - str += "]}"; - //最后得到类似 - //{"jsonrpc":"2.0","id":"qwer","method":"aria2.addUri","params:"[["http://www.baidu.com"]]} - return str; - } - - - /// - /// 发送json并返回json消息 - /// - /// - /// - private static async Task SendAndReceive(JsonClass json) - { - string str = ToJson(json); - try - { - //发送json数据 - await webSocket.SendAsync(new ArraySegment(Encoding.UTF8.GetBytes(str)), WebSocketMessageType.Text, true, cancellationToken); - var result = new byte[1024]; - //接收数据 - await webSocket.ReceiveAsync(new ArraySegment(result), new CancellationToken()); - str += "\r\n" + Encoding.UTF8.GetString(result, 0, result.Length) + "\r\n"; - } - catch - { - str = "连接错误"; - } - return str; - } - - - /// - /// 添加新的下载 - /// - /// - /// - public static async Task AddUri(string uri) - { - var json = new JsonClass - { - Jsonrpc = "2.0", - Id = "qwer", - Method = "aria2.addUri" - }; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(uri); - json.Params = paramslist; - string str = await SendAndReceive(json); - return str; - } - - - /// - /// 上传“.torrent”文件添加BitTorrent下载 - /// - /// - /// - public static async Task AddTorrent(string path) - { - string str = ""; - string fsbase64 = ""; - byte[] fs = File.ReadAllBytes(path); - fsbase64 = Convert.ToBase64String(fs); //转为Base64编码 - - var json = new JsonClass(); - json.Jsonrpc = "2.0"; - json.Id = "qwer"; - json.Method = "aria2.addTorrent"; - List paramslist = new List(); - //添加“.torrent”文件本地地址 - paramslist.Add(fsbase64); - json.Params = paramslist; - str = await SendAndReceive(json); - return str; - } - - - /// - /// 删除已经停止的任务,强制删除请使用ForceRemove方法 - /// - /// - /// - public static async Task Remove(string gid) - { - string str = ""; - var json = new JsonClass - { - Jsonrpc = "2.0", - Id = "qwer", - Method = "aria2.remove" - }; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(gid); - json.Params = paramslist; - str = await SendAndReceive(json); - return str; - } - - - /// - /// 强制删除 - /// - /// - /// - public static async Task ForceRemove(string gid) - { - string str = ""; - var json = new JsonClass - { - Jsonrpc = "2.0", - Id = "qwer", - Method = "aria2.forceRemove" - }; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(gid); - json.Params = paramslist; - str = await SendAndReceive(json); - return str; - } - - - /// - /// 暂停下载,强制暂停请使用ForcePause方法 - /// - /// - /// - public static async Task Pause(string gid) - { - string str = ""; - var json = new JsonClass - { - Jsonrpc = "2.0", - Id = "qwer", - Method = "aria2.pause" - }; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(gid); - json.Params = paramslist; - str = await SendAndReceive(json); - return str; - } - - - /// - /// 暂停全部任务 - /// - /// - /// - public static async Task PauseAll() - { - string str = ""; - var json = new JsonClass(); - json.Jsonrpc = "2.0"; - json.Id = "qwer"; - json.Method = "aria2.pauseAll"; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(""); - json.Params = paramslist; - str = await Aria2.SendAndReceive(json); - return str; - } - - - /// - /// 强制暂停下载 - /// - /// - /// - public static async Task ForcePause(string gid) - { - string str = ""; - var json = new JsonClass(); - json.Jsonrpc = "2.0"; - json.Id = "qwer"; - json.Method = "aria2.forcePause"; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(gid); - json.Params = paramslist; - str = await Aria2.SendAndReceive(json); - return str; - } - - - /// - /// 强制暂停全部下载 - /// - /// - /// - public static async Task ForcePauseAll() - { - string str = ""; - var json = new JsonClass(); - json.Jsonrpc = "2.0"; - json.Id = "qwer"; - json.Method = "aria2.forcePauseAll"; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(""); - json.Params = paramslist; - str = await Aria2.SendAndReceive(json); - return str; - } - - - /// - /// 把正在下载的任务状态改为等待下载 - /// - /// - /// - public static async Task PauseToWaiting(string gid) - { - string str = ""; - var json = new JsonClass(); - json.Jsonrpc = "2.0"; - json.Id = "qwer"; - json.Method = "aria2.unpause"; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(gid); - json.Params = paramslist; - str = await Aria2.SendAndReceive(json); - return str; - } - - - /// - /// 把全部在下载的任务状态改为等待下载 - /// - /// - /// - public static async Task PauseToWaitingAll() - { - string str = ""; - var json = new JsonClass(); - json.Jsonrpc = "2.0"; - json.Id = "qwer"; - json.Method = "aria2.unpauseAll"; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(""); - json.Params = paramslist; - str = await Aria2.SendAndReceive(json); - return str; - } - - - /// - /// 返回下载进度 - /// - /// - /// - public static async Task TellStatus(string gid) - { - string str = ""; - var json = new JsonClass(); - json.Jsonrpc = "2.0"; - json.Id = "qwer"; - json.Method = "aria2.tellStatus"; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(gid); - paramslist.Add("completedLength\", \"totalLength\",\"downloadSpeed"); - - json.Params = paramslist; - str = await Aria2.SendAndReceive(json); - return str; - } - - - /// - /// 返回全局统计信息,例如整体下载和上载速度 - /// - /// - /// - public static async Task GetGlobalStat(string gid) - { - string str = ""; - var json = new JsonClass(); - json.Jsonrpc = "2.0"; - json.Id = "qwer"; - json.Method = "aria2.getGlobalStat"; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(gid); - json.Params = paramslist; - str = await Aria2.SendAndReceive(json); - return str; - } - - - /// - /// 返回由gid(字符串)表示的下载中使用的URI 。响应是一个结构数组 - /// - /// - /// - public static async Task GetUris(string gid) - { - string str = ""; - var json = new JsonClass(); - json.Jsonrpc = "2.0"; - json.Id = "qwer"; - json.Method = "aria2.getUris"; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(gid); - json.Params = paramslist; - str = await Aria2.SendAndReceive(json); - return str; - } - - - /// - /// 返回由gid(字符串)表示的下载文件列表 - /// - /// - /// - public static async Task GetFiles(string gid) - { - string str = ""; - var json = new JsonClass(); - json.Jsonrpc = "2.0"; - json.Id = "qwer"; - json.Method = "aria2.getFiles"; - List paramslist = new List(); - //添加下载地址 - paramslist.Add(gid); - json.Params = paramslist; - str = await Aria2.SendAndReceive(json); - return str; - } - - } -} diff --git a/src/Core/aria2cNet/client/AriaClientWebSocket.cs b/src/Core/aria2cNet/client/AriaClientWebSocket.cs deleted file mode 100644 index 71e88e8..0000000 --- a/src/Core/aria2cNet/client/AriaClientWebSocket.cs +++ /dev/null @@ -1,111 +0,0 @@ -using Core.aria2cNet.client.entity; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Net.WebSockets; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace Core.aria2cNet.client -{ - public class AriaClientWebSocket - { - private static readonly string JSONRPC = "2.0"; - private static readonly string TOKEN = "downkyi"; - - public static ClientWebSocket webSocket; // 用于连接到Aria2Rpc的客户端 - public static CancellationToken cancellationToken; // 传播有关应取消操作的通知 - public static bool Status; // 储存连接状态 - - /// - /// 连接Aria2Rpc服务器 - /// - /// - /// - public static async Task ConnectServerAsync(string uri) - { - webSocket = new ClientWebSocket(); // 用于连接到Aria2Rpc的客户端 - cancellationToken = new CancellationToken(); // 传播有关应取消操作的通知 - Status = false; // 储存连接状态 - - try - { - //连接服务器 - await webSocket.ConnectAsync(new Uri(uri), cancellationToken); - } - catch - { - Status = false; - } - //检查连接是否成功 - if (webSocket.State == WebSocketState.Open) - { - Status = true; - } - return Status; - } - - /// - /// add - /// - /// - /// - public static async Task AddUriAsync(List uris) - { - AriaSendOption option = new AriaSendOption - { - Out = "index测试.html", - Dir = "home/" - }; - - List ariaParams = new List - { - "token:" + TOKEN, - uris, - option - }; - - AriaSendData ariaSend = new AriaSendData - { - Id = Guid.NewGuid().ToString("N"), - Jsonrpc = JSONRPC, - Method = "aria2.addUri", - Params = ariaParams - }; - - string sendJson = JsonConvert.SerializeObject(ariaSend); - - string result = await SendAndReceiveAsync(sendJson); - return result; - } - - - /// - /// 发送并接受数据 - /// - /// - /// - private static async Task SendAndReceiveAsync(string sendJson) - { - string result; - try - { - //发送json数据 - await webSocket.SendAsync(new ArraySegment(Encoding.UTF8.GetBytes(sendJson)), WebSocketMessageType.Text, true, cancellationToken); - byte[] receive = new byte[1024]; - //接收数据 - await webSocket.ReceiveAsync(new ArraySegment(receive), new CancellationToken()); - result = Encoding.UTF8.GetString(receive).TrimEnd('\0'); - } - catch - { - result = "{\"id\":null,\"jsonrpc\":\"2.0\",\"error\":{\"code\":-2020,\"message\":\"连接错误\"}}"; - } - return result; - } - - - - } -} diff --git a/src/Core/danmaku2ass/Bilibili.cs b/src/Core/danmaku2ass/Bilibili.cs deleted file mode 100644 index ada39a6..0000000 --- a/src/Core/danmaku2ass/Bilibili.cs +++ /dev/null @@ -1,163 +0,0 @@ -using Core.api.danmaku; -using System.Collections.Generic; - -namespace Core.danmaku2ass -{ - public class Bilibili - { - private static Bilibili instance; - - private Dictionary config = new Dictionary - { - { "top_filter", false }, - { "bottom_filter", false }, - { "scroll_filter", false } - }; - - private readonly Dictionary mapping = new Dictionary - { - { 1, "scroll" }, - { 2, "scroll" }, - { 3, "scroll" }, - { 4, "bottom" }, - { 5, "top" }, - { 6, "scroll" }, // 逆向滚动弹幕,还是当滚动处理 - { 7, "none" }, // 高级弹幕,暂时不要考虑 - { 8, "none" }, // 代码弹幕,暂时不要考虑 - { 9, "none" } // BAS弹幕,暂时不要考虑 - }; - - // 弹幕标准字体大小 - private readonly int normalFontSize = 25; - - /// - /// 获取Bilibili实例 - /// - /// - public static Bilibili GetInstance() - { - if (instance == null) - { - instance = new Bilibili(); - } - - return instance; - } - - /// - /// 隐藏Bilibili()方法,必须使用单例模式 - /// - private Bilibili() { } - - /// - /// 是否屏蔽顶部弹幕 - /// - /// - /// - public Bilibili SetTopFilter(bool isFilter) - { - config["top_filter"] = isFilter; - return this; - } - - /// - /// 是否屏蔽底部弹幕 - /// - /// - /// - public Bilibili SetBottomFilter(bool isFilter) - { - config["bottom_filter"] = isFilter; - return this; - } - - /// - /// 是否屏蔽滚动弹幕 - /// - /// - /// - public Bilibili SetScrollFilter(bool isFilter) - { - config["scroll_filter"] = isFilter; - return this; - } - - public void Create(long avid, long cid, Config subtitleConfig, string assFile) - { - // 弹幕转换 - var biliDanmakus = DanmakuProtobuf.GetInstance().GetAllDanmakuProto(avid, cid); - - // 按弹幕出现顺序排序 - biliDanmakus.Sort((x, y) => { return x.Progress.CompareTo(y.Progress); }); - - var danmakus = new List(); - foreach (var biliDanmaku in biliDanmakus) - { - var danmaku = new Danmaku - { - // biliDanmaku.Progress单位是毫秒,所以除以1000,单位变为秒 - Start = biliDanmaku.Progress / 1000.0f, - Style = mapping[biliDanmaku.Mode], - Color = (int)biliDanmaku.Color, - Commenter = biliDanmaku.MidHash, - Content = biliDanmaku.Content, - SizeRatio = 1.0f * biliDanmaku.Fontsize / normalFontSize - }; - - danmakus.Add(danmaku); - } - - // 弹幕预处理 - Producer producer = new Producer(config, danmakus); - producer.StartHandle(); - - // 字幕生成 - var keepedDanmakus = producer.KeepedDanmakus; - var studio = new Studio(subtitleConfig, keepedDanmakus); - studio.StartHandle(); - studio.CreateAssFile(assFile); - } - - public Dictionary GetResolution(int quality) - { - var resolution = new Dictionary - { - { "width", 0 }, - { "height", 0 } - }; - - switch (quality) - { - // 240P 极速(仅mp4方式) - case 6: - break; - // 360P 流畅 - case 16: - break; - // 480P 清晰 - case 32: - break; - // 720P 高清(登录) - case 64: - break; - // 720P60 高清(大会员) - case 74: - break; - // 1080P 高清(登录) - case 80: - break; - // 1080P+ 高清(大会员) - case 112: - break; - // 1080P60 高清(大会员) - case 116: - break; - // 4K 超清(大会员)(需要fourk=1) - case 120: - break; - } - return resolution; - } - - } -} diff --git a/src/Core/danmaku2ass/Collision.cs b/src/Core/danmaku2ass/Collision.cs deleted file mode 100644 index 8a78f1e..0000000 --- a/src/Core/danmaku2ass/Collision.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Core.danmaku2ass -{ - /// - /// 碰撞处理 - /// - public class Collision - { - private readonly int lineCount; - private readonly List leaves; - - public Collision(int lineCount) - { - this.lineCount = lineCount; - leaves = Leaves(); - } - - private List Leaves() - { - var ret = new List(lineCount); - for (int i = 0; i < lineCount; i++) ret.Add(0); - return ret; - } - - /// - /// 碰撞检测 - /// 返回行号和时间偏移 - /// - /// - /// - public Tuple Detect(Display display) - { - List beyonds = new List(); - for (int i = 0; i < leaves.Count; i++) - { - float beyond = display.Danmaku.Start - leaves[i]; - // 某一行有足够空间,直接返回行号和 0 偏移 - if (beyond >= 0) - { - return Tuple.Create(i, 0f); - } - beyonds.Add(beyond); - } - - // 所有行都没有空间了,那么找出哪一行能在最短时间内让出空间 - float soon = beyonds.Max(); - int lineIndex = beyonds.IndexOf(soon); - float offset = -soon; - return Tuple.Create(lineIndex, offset); - } - - public void Update(float leave, int lineIndex, float offset) - { - leaves[lineIndex] = Utils.IntCeiling(leave + offset); - } - - } -} diff --git a/src/Core/danmaku2ass/Config.cs b/src/Core/danmaku2ass/Config.cs deleted file mode 100644 index f9a2669..0000000 --- a/src/Core/danmaku2ass/Config.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; - -namespace Core.danmaku2ass -{ - public class Config - { - public string Title = "Downkyi"; - public int ScreenWidth = 1920; - public int ScreenHeight = 1080; - public string FontName = "黑体"; - public int BaseFontSize; // 字体大小,像素 - // 限制行数 - private int lineCount; - public int LineCount - { - get { return lineCount; } - set - { - if (value == 0) - { - lineCount = (int)Math.Floor(ScreenHeight / BaseFontSize * 1.0); - } - else - { - lineCount = value; - } - } - } - public string LayoutAlgorithm; // 布局算法,async/sync - public int TuneDuration; // 微调时长 - public int DropOffset; // 丢弃偏移 - public int BottomMargin; // 底部边距 - public int CustomOffset; // 自定义偏移 - public string HeaderTemplate = @"[Script Info] -; Script generated by Downkyi Danmaku Converter -; https://github.com/FlySelfLog/downkyi -Title: {title} -ScriptType: v4.00+ -Collisions: Normal -PlayResX: {width} -PlayResY: {height} -Timer: 10.0000 -WrapStyle: 2 -ScaledBorderAndShadow: no - -[V4+ Styles] -Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding -Style: Default,{fontname},54,&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,0,0,0,0,100,100,0.00,0.00,1,2.00,0.00,2,30,30,120,0 -Style: Alternate,{fontname},36,&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,0,0,0,0,100,100,0.00,0.00,1,2.00,0.00,2,30,30,84,0 -Style: Danmaku,{fontname},{fontsize},&H00FFFFFF,&H00FFFFFF,&H00000000,&H00000000,0,0,0,0,100,100,0.00,0.00,1,1.00,0.00,2,30,30,30,0 - -[Events] -Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"; - } -} diff --git a/src/Core/danmaku2ass/Creater.cs b/src/Core/danmaku2ass/Creater.cs deleted file mode 100644 index 6ce664a..0000000 --- a/src/Core/danmaku2ass/Creater.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System.Collections.Generic; - -namespace Core.danmaku2ass -{ - /// - /// 创建器 - /// - public class Creater - { - public Config Config; - public List Danmakus; - public List Subtitles; - public string Text; - - public Creater(Config config, List danmakus) - { - Config = config; - Danmakus = danmakus; - Subtitles = SetSubtitles(); - Text = SetText(); - } - - protected List SetSubtitles() - { - var scroll = new Collision(Config.LineCount); - var stayed = new Collision(Config.LineCount); - Dictionary collisions = new Dictionary - { - { "scroll", scroll }, - { "top", stayed }, - { "bottom", stayed } - }; - - List subtitles = new List(); - foreach (var danmaku in Danmakus) - { - // 丢弃不支持的 - if (danmaku.Style == "none") - { - continue; - } - - // 创建显示方式对象 - var display = Display.Factory(Config, danmaku); - var collision = collisions[danmaku.Style]; - var detect = collision.Detect(display); - int lineIndex = detect.Item1; - float waitingOffset = detect.Item2; - - // 超过容忍的偏移量,丢弃掉此条弹幕 - if (waitingOffset > Config.DropOffset) - { - continue; - } - - // 接受偏移,更新碰撞信息 - display.Relayout(lineIndex); - collision.Update(display.Leave, lineIndex, waitingOffset); - - // 再加上自定义偏移 - float offset = waitingOffset + Config.CustomOffset; - Subtitle subtitle = new Subtitle(danmaku, display, offset); - - subtitles.Add(subtitle); - } - return subtitles; - } - - protected string SetText() - { - string header = Config.HeaderTemplate - .Replace("{title}", Config.Title) - .Replace("{width}", Config.ScreenWidth.ToString()) - .Replace("{height}", Config.ScreenHeight.ToString()) - .Replace("{fontname}", Config.FontName) - .Replace("{fontsize}", Config.BaseFontSize.ToString()); - - string events = string.Empty; - foreach (var subtitle in Subtitles) - { - events += "\n" + subtitle.Text; - } - - return header + events; - } - - } -} diff --git a/src/Core/danmaku2ass/Danmaku.cs b/src/Core/danmaku2ass/Danmaku.cs deleted file mode 100644 index 4661318..0000000 --- a/src/Core/danmaku2ass/Danmaku.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Core.danmaku2ass -{ - public class Danmaku - { - public float Start { get; set; } - public string Style { get; set; } - public int Color { get; set; } - public string Commenter { get; set; } - public string Content { get; set; } - public float SizeRatio { get; set; } - } -} diff --git a/src/Core/danmaku2ass/Dictionary.cs b/src/Core/danmaku2ass/Dictionary.cs deleted file mode 100644 index 839431b..0000000 --- a/src/Core/danmaku2ass/Dictionary.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Core.danmaku2ass -{ - public class Dictionary - { - } -} \ No newline at end of file diff --git a/src/Core/danmaku2ass/Display.cs b/src/Core/danmaku2ass/Display.cs deleted file mode 100644 index 5df85de..0000000 --- a/src/Core/danmaku2ass/Display.cs +++ /dev/null @@ -1,406 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; - -namespace Core.danmaku2ass -{ - /// - /// 显示方式 - /// - public class Display - { - public Config Config; - public Danmaku Danmaku; - public int LineIndex; - - public int FontSize; - public bool IsScaled; - public int MaxLength; - public int Width; - public int Height; - - public Tuple Horizontal; - public Tuple Vertical; - - public int Duration; - public int Leave; - - protected Display() { } - - public Display(Config config, Danmaku danmaku) - { - Config = config; - Danmaku = danmaku; - LineIndex = 0; - - IsScaled = SetIsScaled(); - FontSize = SetFontSize(); - MaxLength = SetMaxLength(); - Width = SetWidth(); - Height = SetHeight(); - - Horizontal = SetHorizontal(); - Vertical = SetVertical(); - - Duration = SetDuration(); - Leave = SetLeave(); - } - - /// - /// 根据弹幕样式自动创建对应的 Display 类 - /// - /// - public static Display Factory(Config config, Danmaku danmaku) - { - Dictionary dict = new Dictionary - { - { "scroll", new ScrollDisplay(config, danmaku) }, - { "top", new TopDisplay(config, danmaku) }, - { "bottom", new BottomDisplay(config, danmaku) } - }; - return dict[danmaku.Style]; - } - - /// - /// 字体大小 - /// 按用户自定义的字体大小来缩放 - /// - /// - protected int SetFontSize() - { - if (IsScaled) - { - Console.WriteLine($"{Danmaku.SizeRatio}"); - } - return Utils.IntCeiling(Config.BaseFontSize * Danmaku.SizeRatio); - } - - /// - /// 字体是否被缩放过 - /// - /// - protected bool SetIsScaled() - { - return !Math.Round(Danmaku.SizeRatio, 2).Equals(1.0); - //return Danmaku.SizeRatio.Equals(1.0f); - } - - /// - /// 最长的行字符数 - /// - /// - protected int SetMaxLength() - { - string[] lines = Danmaku.Content.Split('\n'); - int maxLength = 0; - foreach (string line in lines) - { - int length = Utils.DisplayLength(line); - if (maxLength < length) - { - maxLength = length; - } - } - return maxLength; - } - - /// - /// 整条字幕宽度 - /// - /// - protected int SetWidth() - { - float charCount = MaxLength;// / 2; - return Utils.IntCeiling(FontSize * charCount); - } - - /// - /// 整条字幕高度 - /// - /// - protected int SetHeight() - { - int lineCount = Danmaku.Content.Split('\n').Length; - return lineCount * FontSize; - } - - /// - /// 出现和消失的水平坐标位置 - /// 默认在屏幕中间 - /// - /// - protected virtual Tuple SetHorizontal() - { - int x = (int)Math.Floor(Config.ScreenWidth / 2.0); - return Tuple.Create(x, x); - } - - /// - /// 出现和消失的垂直坐标位置 - /// 默认在屏幕中间 - /// - /// - protected virtual Tuple SetVertical() - { - int y = (int)Math.Floor(Config.ScreenHeight / 2.0); - return Tuple.Create(y, y); - } - - /// - /// 整条字幕的显示时间 - /// - /// - protected virtual int SetDuration() - { - int baseDuration = 3 + Config.TuneDuration; - if (baseDuration <= 0) - { - baseDuration = 0; - } - float charCount = MaxLength / 2; - - int value; - if (charCount < 6) - { - value = baseDuration + 1; - } - else if (charCount < 12) - { - value = baseDuration + 2; - } - else - { - value = baseDuration + 3; - } - return value; - } - - /// - /// 离开碰撞时间 - /// - /// - protected virtual int SetLeave() - { - return (int)(Danmaku.Start + Duration); - } - - /// - /// 按照新的行号重新布局 - /// - /// - public void Relayout(int lineIndex) - { - LineIndex = lineIndex; - Horizontal = SetHorizontal(); - Vertical = SetVertical(); - } - - } - - /// - /// 顶部 - /// - public class TopDisplay : Display - { - public TopDisplay(Config config, Danmaku danmaku) : base(config, danmaku) - { - Console.WriteLine("TopDisplay constructor."); - } - - /// - /// - /// - /// - protected override Tuple SetVertical() - { - // 这里 y 坐标为 0 就是最顶行了 - int y = LineIndex * Config.BaseFontSize; - return Tuple.Create(y, y); - } - } - - /// - /// 底部 - /// - public class BottomDisplay : Display - { - public BottomDisplay(Config config, Danmaku danmaku) : base(config, danmaku) - { - Console.WriteLine("BottomDisplay constructor."); - } - - /// - /// - /// - /// - protected override Tuple SetVertical() - { - // 要让字幕不超出底部,减去高度 - int y = Config.ScreenHeight - (LineIndex * Config.BaseFontSize) - Height; - // 再减去自定义的底部边距 - y -= Config.BottomMargin; - return Tuple.Create(y, y); - } - } - - /// - /// 滚动 - /// - public class ScrollDisplay : Display - { - public int Distance; - public int Speed; - - public ScrollDisplay(Config config, Danmaku danmaku) : base() - { - Console.WriteLine("ScrollDisplay constructor."); - - Config = config; - Danmaku = danmaku; - LineIndex = 0; - - IsScaled = SetIsScaled(); - FontSize = SetFontSize(); - MaxLength = SetMaxLength(); - Width = SetWidth(); - Height = SetHeight(); - - Horizontal = SetHorizontal(); - Vertical = SetVertical(); - - Distance = SetDistance(); - Speed = SetSpeed(); - - Duration = SetDuration(); - Leave = SetLeave(); - } - - /// - /// ASS 的水平位置参考点是整条字幕文本的中点 - /// - /// - protected override Tuple SetHorizontal() - { - int x1 = Config.ScreenWidth + (int)Math.Floor(Width / 2.0); - int x2 = 0 - (int)Math.Floor(Width / 2.0); - return Tuple.Create(x1, x2); - } - - protected override Tuple SetVertical() - { - int baseFontSize = Config.BaseFontSize; - - // 垂直位置,按基准字体大小算每一行的高度 - int y = (LineIndex + 1) * baseFontSize; - - // 个别弹幕可能字体比基准要大,所以最上的一行还要避免挤出顶部屏幕 - // 坐标不能小于字体大小 - if (y < FontSize) - { - y = FontSize; - } - return Tuple.Create(y, y); - } - - /// - /// 字幕坐标点的移动距离 - /// - /// - protected int SetDistance() - { - Tuple x = Horizontal; - return x.Item1 - x.Item2; - } - - /// - /// 字幕每个字的移动的速度 - /// - /// - protected int SetSpeed() - { - // 基准时间,就是每个字的移动时间 - // 12 秒加上用户自定义的微调 - int baseDuration = 12 + Config.TuneDuration; - if (baseDuration <= 0) - { - baseDuration = 1; - } - return Utils.IntCeiling(Config.ScreenWidth / baseDuration); - } - - /// - /// 计算每条弹幕的显示时长,同步方式 - /// 每个弹幕的滚动速度都一样,辨认度好,适合观看剧集类视频。 - /// - /// - public int SyncDuration() - { - return Distance / Speed; - } - - /// - /// 计算每条弹幕的显示时长,异步方式 - /// 每个弹幕的滚动速度都不一样,动态调整,辨认度低,适合观看 MTV 类视频。 - /// - /// - public int AsyncDuration() - { - int baseDuration = 6 + Config.TuneDuration; - if (baseDuration <= 0) - { - baseDuration = 0; - } - float charCount = MaxLength / 2; - - int value; - if (charCount < 6) - { - value = (int)(baseDuration + charCount); - } - else if (charCount < 12) - { - value = baseDuration + (int)(charCount / 2); - } - else if (charCount < 24) - { - value = baseDuration + (int)(charCount / 3); - } - else - { - value = baseDuration + 10; - } - return value; - } - - /// - /// 整条字幕的移动时间 - /// - /// - protected override int SetDuration() - { - string methodName = Config.LayoutAlgorithm.Substring(0, 1).ToUpper() + Config.LayoutAlgorithm.Substring(1); - methodName += "Duration"; - MethodInfo method = typeof(ScrollDisplay).GetMethod(methodName); - if (method != null) - { - return (int)method.Invoke(this, null); - } - return 0; - } - - /// - /// 离开碰撞时间 - /// - /// - protected override int SetLeave() - { - // 对于滚动样式弹幕来说,就是最后一个字符离开最右边缘的时间 - // 坐标是字幕中点,在屏幕外和内各有半个字幕宽度 - // 也就是跑过一个字幕宽度的路程 - float duration = Width / Speed; - return (int)(Danmaku.Start + duration); - } - - } - -} diff --git a/src/Core/danmaku2ass/Filter.cs b/src/Core/danmaku2ass/Filter.cs deleted file mode 100644 index 1fb6e23..0000000 --- a/src/Core/danmaku2ass/Filter.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Core.danmaku2ass -{ - /// - /// 过滤器基类 - /// - public class Filter - { - public virtual List DoFilter(List danmakus) - { - throw new NotImplementedException("使用了过滤器的未实现的方法。"); - } - } - - /// - /// 顶部样式过滤器 - /// - public class TopFilter : Filter - { - public override List DoFilter(List danmakus) - { - List keep = new List(); - foreach (var danmaku in danmakus) - { - if (danmaku.Style == "top") - { - continue; - } - keep.Add(danmaku); - } - return keep; - } - } - - /// - /// 底部样式过滤器 - /// - public class BottomFilter : Filter - { - public override List DoFilter(List danmakus) - { - List keep = new List(); - foreach (var danmaku in danmakus) - { - if (danmaku.Style == "bottom") - { - continue; - } - keep.Add(danmaku); - } - return keep; - } - } - - /// - /// 滚动样式过滤器 - /// - public class ScrollFilter : Filter - { - public override List DoFilter(List danmakus) - { - List keep = new List(); - foreach (var danmaku in danmakus) - { - if (danmaku.Style == "scroll") - { - continue; - } - keep.Add(danmaku); - } - return keep; - } - } - - /// - /// 自定义过滤器 - /// - public class CustomFilter : Filter - { - public override List DoFilter(List danmakus) - { - // TODO - return base.DoFilter(danmakus); - } - } - -} diff --git a/src/Core/danmaku2ass/Producer.cs b/src/Core/danmaku2ass/Producer.cs deleted file mode 100644 index 2ebf885..0000000 --- a/src/Core/danmaku2ass/Producer.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Core.danmaku2ass -{ - public class Producer - { - public Dictionary Config; - public Dictionary Filters; - public List Danmakus; - public List KeepedDanmakus; - public Dictionary FilterDetail; - - public Producer(Dictionary config, List danmakus) - { - Config = config; - Danmakus = danmakus; - } - - public void StartHandle() - { - LoadFilter(); - ApplyFilter(); - } - - public void LoadFilter() - { - Filters = new Dictionary(); - if (Config["top_filter"]) - { - Filters.Add("top_filter", new TopFilter()); - } - if (Config["bottom_filter"]) - { - Filters.Add("bottom_filter", new BottomFilter()); - } - if (Config["scroll_filter"]) - { - Filters.Add("scroll_filter", new ScrollFilter()); - } - //if (Config["custom_filter"]) - //{ - // Filters.Add("custom_filter", new CustomFilter()); - //} - - } - - public void ApplyFilter() - { - Dictionary filterDetail = new Dictionary() { - { "top_filter",0}, - { "bottom_filter",0}, - { "scroll_filter",0}, - //{ "custom_filter",0} - }; - - List danmakus = Danmakus; - //string[] orders = { "top_filter", "bottom_filter", "scroll_filter", "custom_filter" }; - string[] orders = { "top_filter", "bottom_filter", "scroll_filter" }; - foreach (var name in orders) - { - Filter filter; - try - { - filter = Filters[name]; - } - catch (Exception e) - { - Console.WriteLine("ApplyFilter()发生异常: {0}", e); - continue; - } - - int count = danmakus.Count; - danmakus = filter.DoFilter(danmakus); - filterDetail[name] = count - danmakus.Count; - } - - KeepedDanmakus = danmakus; - FilterDetail = filterDetail; - } - - public Dictionary Report() - { - int blockedCount = 0; - foreach (int count in FilterDetail.Values) - { - blockedCount += count; - } - - int passedCount = KeepedDanmakus.Count; - int totalCount = blockedCount + passedCount; - - Dictionary ret = new Dictionary - { - { "blocked", blockedCount }, - { "passed", passedCount }, - { "total", totalCount } - }; - - return (Dictionary)ret.Concat(FilterDetail); - } - - } -} diff --git a/src/Core/danmaku2ass/Studio.cs b/src/Core/danmaku2ass/Studio.cs deleted file mode 100644 index be471ec..0000000 --- a/src/Core/danmaku2ass/Studio.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace Core.danmaku2ass -{ - /// - /// 字幕工程类 - /// - public class Studio - { - public Config Config; - public List Danmakus; - - public Creater Creater; - public int KeepedCount; - public int DropedCount; - - public Studio(Config config, List danmakus) - { - Config = config; - Danmakus = danmakus; - } - - public void StartHandle() - { - Creater = SetCreater(); - KeepedCount = SetKeepedCount(); - DropedCount = SetDropedCount(); - } - - /// - /// ass 创建器 - /// - /// - protected Creater SetCreater() - { - return new Creater(Config, Danmakus); - } - - /// - /// 保留条数 - /// - /// - protected int SetKeepedCount() - { - return Creater.Subtitles.Count(); - } - - /// - /// 丢弃条数 - /// - /// - protected int SetDropedCount() - { - return Danmakus.Count - KeepedCount; - } - - /// - /// 创建 ass 字幕 - /// - /// - public void CreateAssFile(string fileName) - { - CreateFile(fileName, Creater.Text); - } - - public void CreateFile(string fileName, string text) - { - File.WriteAllText(fileName, text); - } - - public Dictionary Report() - { - return new Dictionary() - { - {"total", Danmakus.Count}, - {"droped", DropedCount}, - {"keeped", KeepedCount}, - }; - } - - } -} diff --git a/src/Core/danmaku2ass/Subtitle.cs b/src/Core/danmaku2ass/Subtitle.cs deleted file mode 100644 index 1f46e4c..0000000 --- a/src/Core/danmaku2ass/Subtitle.cs +++ /dev/null @@ -1,155 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Core.danmaku2ass -{ - /// - /// 字幕 - /// - public class Subtitle - { - public Danmaku Danmaku; - public Display Display; - public float Offset; - - public float Start; - public float End; - public string Color; - public Dictionary Position; - public string StartMarkup; - public string EndMarkup; - public string ColorMarkup; - public string BorderMarkup; - public string FontSizeMarkup; - public string StyleMarkup; - public string LayerMarkup; - public string ContentMarkup; - public string Text; - - public Subtitle(Danmaku danmaku, Display display, float offset = 0) - { - Danmaku = danmaku; - Display = display; - Offset = offset; - - Start = SetStart(); - End = SetEnd(); - Color = SetColor(); - Position = SetPosition(); - StartMarkup = SetStartMarkup(); - EndMarkup = SetEndMarkup(); - ColorMarkup = SetColorMarkup(); - BorderMarkup = SetBorderMarkup(); - FontSizeMarkup = SetFontSizeMarkup(); - StyleMarkup = SetStyleMarkup(); - LayerMarkup = SetLayerMarkup(); - ContentMarkup = SetContentMarkup(); - Text = SetText(); - } - - protected float SetStart() - { - return Danmaku.Start + Offset; - } - - protected float SetEnd() - { - return Start + Display.Duration; - } - - protected string SetColor() - { - return Utils.Int2bgr(Danmaku.Color); - } - - protected Dictionary SetPosition() - { - Tuple x = Display.Horizontal; - Tuple y = Display.Vertical; - - Dictionary value = new Dictionary - { - { "x1", x.Item1 }, - { "x2", x.Item2 }, - { "y1", y.Item1 }, - { "y2", y.Item2 } - }; - return value; - } - - protected string SetStartMarkup() - { - return Utils.Second2hms(Start); - } - - protected string SetEndMarkup() - { - return Utils.Second2hms(End); - } - - protected string SetColorMarkup() - { - // 白色不需要加特别标记 - if (Color == "FFFFFF") - { - return ""; - } - return "\\c&H" + Color; - } - - protected string SetBorderMarkup() - { - // 暗色加个亮色边框,方便阅读 - if (Utils.IsDark(Danmaku.Color)) - { - //return "\\3c&HFFFFFF"; - return "\\3c&H000000"; - } - else - { - return "\\3c&H000000"; - } - //return ""; - } - - protected string SetFontSizeMarkup() - { - if (Display.IsScaled) - { - return $"\\fs{Display.FontSize}"; - } - return ""; - } - - protected string SetStyleMarkup() - { - if (Danmaku.Style == "scroll") - { - return $"\\move({Position["x1"]}, {Position["y1"]}, {Position["x2"]}, {Position["y2"]})"; - } - return $"\\a6\\pos({Position["x1"]}, {Position["y1"]})"; - } - - protected string SetLayerMarkup() - { - if (Danmaku.Style != "scroll") - { - return "-2"; - } - return "-1"; - } - - protected string SetContentMarkup() - { - string markup = StyleMarkup + ColorMarkup + BorderMarkup + FontSizeMarkup; - string content = Utils.CorrectTypos(Danmaku.Content); - return $"{{{markup}}}{content}"; - } - - protected string SetText() - { - return $"Dialogue: {LayerMarkup},{StartMarkup},{EndMarkup},Danmaku,,0000,0000,0000,,{ContentMarkup}"; - } - - } -} diff --git a/src/Core/danmaku2ass/Utils.cs b/src/Core/danmaku2ass/Utils.cs deleted file mode 100644 index 583cc89..0000000 --- a/src/Core/danmaku2ass/Utils.cs +++ /dev/null @@ -1,228 +0,0 @@ -using System; -using System.Linq; -using System.Text; - -namespace Core.danmaku2ass -{ - internal static class Utils - { - /// - /// 向上取整,返回int类型 - /// - /// - /// - public static int IntCeiling(float number) - { - return (int)Math.Ceiling(number); - } - - /// - /// 字符长度,1个汉字当2个英文 - /// - /// - /// - public static int DisplayLength(string text) - { - return Encoding.Default.GetBytes(text).Length; - } - - /// - /// 修正一些评论者的拼写错误 - /// - /// - /// - public static string CorrectTypos(string text) - { - text = text.Replace("/n", "\\N"); - text = text.Replace(">", ">"); - text = text.Replace("<", "<"); - return text; - } - - /// - /// 秒数转 时:分:秒 格式 - /// - /// - /// - public static string Second2hms(float seconds) - { - if (seconds < 0) - { - return "0:00:00.00"; - } - - int i = (int)Math.Floor(seconds / 1.0); - int dec = (int)(Math.Round(seconds % 1.0f, 2) * 100); - if (dec >= 100) - { - dec = 99; - } - - int min = (int)Math.Floor(i / 60.0); - int second = (int)(i % 60.0f); - - int hour = (int)Math.Floor(min / 60.0); - - return $"{hour:D}:{min:D2}:{second:D2}.{dec:D2}"; - } - - /// - /// 时:分:秒 格式转 秒数 - /// - /// - /// - public static float Hms2second(string hms) - { - string[] numbers = hms.Split(':'); - float seconds = 0; - - for (int i = 0; i < numbers.Length; i++) - { - seconds += (float)(float.Parse(numbers[numbers.Length - i - 1]) * Math.Pow(60, i)); - } - return seconds; - } - - /// - /// 同Hms2second(string hms),不过可以用 +/- 符号来连接多个 - /// 即 3:00-2:30 相当于 30 秒 - /// - /// - /// - public static float Xhms2second(string xhms) - { - string[] args = xhms.Replace("+", " +").Replace("-", " -").Split(' '); - float result = 0; - foreach (string hms in args) - { - result += Hms2second(hms); - } - return result; - } - - /// - /// 颜色值,整型转 RGB - /// - /// - /// - public static string Int2rgb(int integer) - { - return integer.ToString("X").PadLeft(6, '0'); ; - } - - /// - /// 颜色值,整型转 BGR - /// - /// - /// - public static string Int2bgr(int integer) - { - string rgb = Int2rgb(integer); - string bgr = rgb.Substring(4, 2) + rgb.Substring(2, 2) + rgb.Substring(0, 2); - return bgr; - } - - /// - /// 颜色值,整型转 HLS - /// - /// - /// - public static float[] Int2hls(int integer) - { - string rgb = Int2rgb(integer); - int[] rgb_decimals = { 0, 0, 0 }; - rgb_decimals[0] = int.Parse(rgb.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); - rgb_decimals[1] = int.Parse(rgb.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); - rgb_decimals[2] = int.Parse(rgb.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); - - int[] rgb_coordinates = { 0, 0, 0 }; - rgb_coordinates[0] = (int)Math.Floor(rgb_decimals[0] / 255.0); - rgb_coordinates[1] = (int)Math.Floor(rgb_decimals[1] / 255.0); - rgb_coordinates[2] = (int)Math.Floor(rgb_decimals[2] / 255.0); - float[] hls_corrdinates = Rgb2hls(rgb_coordinates); - - float[] hls = { 0, 0, 0 }; - hls[0] = hls_corrdinates[0] * 360; - hls[1] = hls_corrdinates[1] * 100; - hls[2] = hls_corrdinates[2] * 100; - return hls; - } - - /// - /// HLS: Hue, Luminance, Saturation - /// H: position in the spectrum - /// L: color lightness - /// S: color saturation - /// - /// - /// - private static float[] Rgb2hls(int[] rgb) - { - float[] hls = { 0, 0, 0 }; - int maxc = rgb.Max(); - int minc = rgb.Min(); - hls[1] = (minc + maxc) / 2.0f; - if (minc == maxc) - { - return hls; - } - - if (hls[1] <= 0.5) - { - hls[2] = (maxc - minc) / (maxc + minc); - } - else - { - hls[2] = (maxc - minc) / (2.0f - maxc - minc); - } - float rc = (maxc - rgb[0]) / (maxc - minc); - float gc = (maxc - rgb[1]) / (maxc - minc); - float bc = (maxc - rgb[2]) / (maxc - minc); - if (rgb[0] == maxc) - { - hls[0] = bc - gc; - } - else if (rgb[1] == maxc) - { - hls[0] = 2.0f + rc - bc; - } - else - { - hls[0] = 4.0f + gc - rc; - } - hls[0] = (hls[0] / 6.0f) % 1.0f; - return hls; - } - - /// - /// 是否属于暗色 - /// - /// - /// - public static bool IsDark(int integer) - { - if (integer == 0) - { - return true; - } - - float[] hls = Int2hls(integer); - float hue = hls[0]; - float lightness = hls[1]; - - // HSL 色轮见 - // http://zh.wikipedia.org/zh-cn/HSL和HSV色彩空间 - // 以下的数值都是我的主观判断认为是暗色 - if ((hue > 30 && hue < 210) && lightness < 33) - { - return true; - } - if ((hue < 30 || hue > 210) && lightness < 66) - { - return true; - } - return false; - } - - } -} diff --git a/src/Core/entity/BangumiMedia.cs b/src/Core/entity/BangumiMedia.cs deleted file mode 100644 index a56f8f2..0000000 --- a/src/Core/entity/BangumiMedia.cs +++ /dev/null @@ -1,35 +0,0 @@ -// 注释掉未使用的属性 -namespace Core.entity -{ - // https://api.bilibili.com/pgc/review/user?media_id=28228367 - class BangumiMedia - { - //public int code { get; set; } - //public string message { get; set; } - public BangumiMediaData result { get; set; } - } - - public class BangumiMediaData - { - public BangumiMediaDataMedia media { get; set; } - //public BangumiMediaDataReview review { get; set; } - } - - public class BangumiMediaDataMedia - { - // TODO 暂时只实现部分字段 - //public long media_id { get; set; } - - public long season_id { get; set; } - //public string share_url { get; set; } - //public string title { get; set; } - //public string type_name { get; set; } - } - - //public class BangumiMediaDataReview - //{ - // public int is_coin { get; set; } - // public int is_open { get; set; } - //} - -} diff --git a/src/Core/entity/BangumiSeason.cs b/src/Core/entity/BangumiSeason.cs deleted file mode 100644 index cc6dfa2..0000000 --- a/src/Core/entity/BangumiSeason.cs +++ /dev/null @@ -1,199 +0,0 @@ -using System.Collections.Generic; - -// 注释掉未使用的属性 -namespace Core.entity -{ - //https://api.bilibili.com/pgc/view/web/season?season_id=28324 - public class BangumiSeason - { - //public int code { get; set; } - //public string message { get; set; } - public BangumiSeasonResult result { get; set; } - } - - public class BangumiSeasonResult - { - //public BangumiSeasonResultActivity activity { get; set; } - //public string alias { get; set; } - //public string bkg_cover { get; set; } - public string cover { get; set; } - public List episodes { get; set; } - public string evaluate { get; set; } - //public string jp_title { get; set; } - //public string link { get; set; } - //public long media_id { get; set; } - //public int mode { get; set; } - //public BangumiSeasonResultNewEp new_ep { get; set; } - //public BangumiSeasonResultPositive positive { get; set; } - //public BangumiSeasonResultPublish publish { get; set; } - //public BangumiSeasonResultRating rating { get; set; } - //public string record { get; set; } - //public BangumiSeasonResultRights rights { get; set; } - //public long season_id { get; set; } - //public string season_title { get; set; } - //public List seasons { get; set; } - //public BangumiSeasonResultSeries series { get; set; } - //public string share_copy { get; set; } - //public string share_sub_title { get; set; } - //public string share_url { get; set; } - //public BangumiSeasonResultShow show { get; set; } - //public string square_cover { get; set; } - public BangumiSeasonResultStat stat { get; set; } - //public int status { get; set; } - //public string subtitle { get; set; } - public string title { get; set; } - //public int total { get; set; } - public int type { get; set; } - } - - //public class BangumiSeasonResultActivity - //{ - // public string head_bg_url { get; set; } - // public long id { get; set; } - // public string title { get; set; } - //} - - public class BangumiSeasonResultEpisodes - { - public long aid { get; set; } - //public string badge { get; set; } - //public BangumiSeasonResultBadgeInfo badge_info { get; set; } - //public int badge_type { get; set; } - public string bvid { get; set; } - public long cid { get; set; } - //public string cover { get; set; } - public BangumiSeasonResultEpisodesDimension dimension { get; set; } - //public string from { get; set; } - //public long id { get; set; } - //public string link { get; set; } - //public string long_title { get; set; } - //public long pub_time { get; set; } - //public string release_date { get; set; } - //public BangumiSeasonResultEpisodesRights rights { get; set; } - public string share_copy { get; set; } - //public string share_url { get; set; } - //public string short_link { get; set; } - //public int status { get; set; } - //public string subtitle { get; set; } - public string title { get; set; } - //public string vid { get; set; } - } - - //public class BangumiSeasonResultBadgeInfo - //{ - // public string bg_color { get; set; } - // public string bg_color_night { get; set; } - // public string text { get; set; } - //} - - public class BangumiSeasonResultEpisodesDimension - { - public int width { get; set; } - public int height { get; set; } - //public int rotate { get; set; } - } - - //public class BangumiSeasonResultEpisodesRights - //{ - // public int allow_dm { get; set; } - //} - - //public class BangumiSeasonResultNewEp - //{ - // public string desc { get; set; } - // public long id { get; set; } - // public int is_new { get; set; } - // public string title { get; set; } - //} - - //public class BangumiSeasonResultPositive - //{ - // public long id { get; set; } - // public string title { get; set; } - //} - - //public class BangumiSeasonResultPublish - //{ - // public int is_finish { get; set; } - // public int is_started { get; set; } - // public string pub_time { get; set; } - // public string pub_time_show { get; set; } - // public int unknow_pub_date { get; set; } - // public int weekday { get; set; } - //} - - //public class BangumiSeasonResultRating - //{ - // public long count { get; set; } - // public float score { get; set; } - //} - - //public class BangumiSeasonResultRights - //{ - // public int allow_bp { get; set; } - // public int allow_bp_rank { get; set; } - // public int allow_download { get; set; } - // public int allow_review { get; set; } - // public int area_limit { get; set; } - // public int ban_area_show { get; set; } - // public int can_watch { get; set; } - // public string copyright { get; set; } - // public int forbid_pre { get; set; } - // public int is_cover_show { get; set; } - // public int is_preview { get; set; } - // public int only_vip_download { get; set; } - // public string resource { get; set; } - // public int watch_platform { get; set; } - //} - - //public class BangumiSeasonResultSeasons - //{ - // public string badge { get; set; } - // public BangumiSeasonResultBadgeInfo badge_info { get; set; } - // public int badge_type { get; set; } - // public string cover { get; set; } - // public long media_id { get; set; } - // public BangumiSeasonResultSeasonsNewEp new_ep { get; set; } - // public long season_id { get; set; } - // public string season_title { get; set; } - // public int season_type { get; set; } - // public BangumiSeasonResultSeasonsStat stat { get; set; } - //} - - //public class BangumiSeasonResultSeasonsNewEp - //{ - // public string cover { get; set; } - // public long id { get; set; } - // public string index_show { get; set; } - //} - - //public class BangumiSeasonResultSeasonsStat - //{ - // public long favorites { get; set; } - // public long series_follow { get; set; } - // public long views { get; set; } - //} - - //public class BangumiSeasonResultSeries - //{ - // public long series_id { get; set; } - // public string series_title { get; set; } - //} - - //public class BangumiSeasonResultShow - //{ - // public int wide_screen { get; set; } - //} - - public class BangumiSeasonResultStat - { - public long coins { get; set; } - public long danmakus { get; set; } - public long favorites { get; set; } - public long likes { get; set; } - public long reply { get; set; } - public long share { get; set; } - public long views { get; set; } - } - -} diff --git a/src/Core/entity/CheeseList.cs b/src/Core/entity/CheeseList.cs deleted file mode 100644 index 905adec..0000000 --- a/src/Core/entity/CheeseList.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Collections.Generic; - -namespace Core.entity -{ - // https://api.bilibili.com/pugv/view/web/ep/list?season_id=112&pn=1 - public class CheeseList - { - public int code { get; set; } - public CheeseListData data { get; set; } - public string message { get; set; } - } - - public class CheeseListData - { - public List items { get; set; } - public CheeseListDataPage page { get; set; } - } - - public class CheeseListDataItem - { - public long aid { get; set; } - public long cid { get; set; } - public long duration { get; set; } - public string from { get; set; } - public long id { get; set; } // ep_id - public int index { get; set; } - public int page { get; set; } - public long play { get; set; } - public long release_date { get; set; } - public int status { get; set; } - public string title { get; set; } - public bool watched { get; set; } - public int watchedHistory { get; set; } - } - - public class CheeseListDataPage - { - public bool next { get; set; } // 是否还有下一页 - public int num { get; set; } // 当前页 - public int size { get; set; } // list大小 - public int total { get; set; } // 总的视频数量 - } - -} diff --git a/src/Core/entity/CheeseSeason.cs b/src/Core/entity/CheeseSeason.cs deleted file mode 100644 index 9933d8c..0000000 --- a/src/Core/entity/CheeseSeason.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.Generic; - -namespace Core.entity -{ - // https://api.bilibili.com/pugv/view/web/season?ep_id=2126 - class CheeseSeason - { - //public int code { get; set; } - public CheeseSeasonData data { get; set; } - //public string message { get; set; } - } - - public class CheeseSeasonData - { - - public string cover { get; set; } - - public List episodes { get; set; } - - public long season_id { get; set; } - - public CheeseSeasonDataStat stat { get; set; } - - public string subtitle { get; set; } - public string title { get; set; } - - } - - public class CheeseSeasonDataEpisode - { - public long aid { get; set; } - public long cid { get; set; } - public long duration { get; set; } - public string from { get; set; } - public long id { get; set; } // ep_id - public int index { get; set; } - public int page { get; set; } - public long play { get; set; } - public long release_date { get; set; } - public int status { get; set; } - public string title { get; set; } - public bool watched { get; set; } - public int watchedHistory { get; set; } - } - - public class CheeseSeasonDataStat - { - public long play { get; set; } - public string play_desc { get; set; } - } - -} diff --git a/src/Core/entity/Danmu.cs b/src/Core/entity/Danmu.cs deleted file mode 100644 index dae53c0..0000000 --- a/src/Core/entity/Danmu.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Collections.Generic; - -// 注释掉未使用的属性 -namespace Core.entity -{ - - public class DanmuDate - { - //{"code":0,"message":"0","ttl":1,"data":["2020-07-01","2020-07-02","2020-07-03","2020-07-04","2020-07-05","2020-07-06","2020-07-07","2020-07-08"]} - //public int code { get; set; } - //public string message { get; set; } - //public int ttl { get; set; } - public List data { get; set; } - } - - public class DanmuFromWeb - { - //public int code { get; set; } - public string message { get; set; } - //public int ttl { get; set; } - } - - - -} diff --git a/src/Core/entity/FavFolder.cs b/src/Core/entity/FavFolder.cs deleted file mode 100644 index 166f66e..0000000 --- a/src/Core/entity/FavFolder.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Collections.Generic; - -namespace Core.entity -{ - /// - /// https://api.bilibili.com/x/v3/fav/folder/created/list?pn=1&ps=10&up_mid=42018135 - /// https://api.bilibili.com/x/v3/fav/folder/collected/list?pn=1&ps=20&up_mid=42018135 - /// 上述两个网址都使用同一个class解析 - /// - public class FavFolder - { - //public int code { get; set; } - public FavFolderData data { get; set; } - //public string message { get; set; } - //public int ttl { get; set; } - } - - public class FavFolderData - { - public int count { get; set; } - public List list { get; set; } - } - - public class FavFolderDataList - { - public int attr { get; set; } - public string cover { get; set; } - public int cover_type { get; set; } - public long ctime { get; set; } - public int fav_state { get; set; } - public long fid { get; set; } - public long id { get; set; } - public string intro { get; set; } - public int media_count { get; set; } - public long mid { get; set; } - public long mtime { get; set; } - public int state { get; set; } - public string title { get; set; } - public FavFolderDataUpper upper { get; set; } - } - - public class FavFolderDataUpper - { - public string face { get; set; } - public long mid { get; set; } - public string name { get; set; } - } - -} diff --git a/src/Core/entity/FavResource.cs b/src/Core/entity/FavResource.cs deleted file mode 100644 index 1308cb6..0000000 --- a/src/Core/entity/FavResource.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Collections.Generic; - -namespace Core.entity -{ - // https://api.bilibili.com/x/v3/fav/resource/list?media_id=94341835&pn=1&ps=20 - public class FavResource - { - //public int code { get; set; } - public FavResourceData data { get; set; } - //public string message { get; set; } - //public int ttl { get; set; } - } - - public class FavResourceData - { - //public FavResourceDataInfo info{get;set;} - public List medias { get; set; } - } - - public class FavResourceDataMedia - { - public int attr { get; set; } - public string bv_id { get; set; } - public string bvid { get; set; } - public FavResourceDataMediaCnt_info cnt_info { get; set; } - public string cover { get; set; } - public long ctime { get; set; } - public long duration { get; set; } - public long fav_time { get; set; } - public long id { get; set; } - public string intro { get; set; } - public string link { get; set; } - public int page { get; set; } - public long pubtime { get; set; } - public string title { get; set; } - public int type { get; set; } - public FavResourceDataMediaUpper upper { get; set; } - } - - public class FavResourceDataMediaCnt_info - { - public long collect { get; set; } - public long danmaku { get; set; } - public long play { get; set; } - } - - public class FavResourceDataMediaUpper - { - public string face { get; set; } - public long mid { get; set; } - public string name { get; set; } - } - -} diff --git a/src/Core/entity/LoginUrl.cs b/src/Core/entity/LoginUrl.cs deleted file mode 100644 index a6638fd..0000000 --- a/src/Core/entity/LoginUrl.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 注释掉未使用的属性 -namespace Core.entity -{ - public class LoginUrl - { - //public int code { get; set; } - public LoginData data { get; set; } - public bool status { get; set; } - //public long ts { get; set; } - } - - public class LoginData - { - public string oauthKey { get; set; } - public string url { get; set; } - } - - - public class LoginInfo - { - public int code { get; set; } - public bool status { get; set; } - public string message { get; set; } - public string url { get; set; } - } - - public class LoginInfoScanning - { - public bool status { get; set; } - public int data { get; set; } - public string message { get; set; } - } - - public class LoginInfoReady - { - // {"code":0,"status":true,"ts":1594131179,"data":{"url":"https://passport.biligame.com/crossDomain?DedeUserID=42018135&DedeUserID__ckMd5=44e22fa30fe34ac4&Expires=15551000&SESSDATA=92334e44%2C1609683179%2C54db1%2A71&bili_jct=979b94fb3879c68574f02800d8a39484&gourl=https%3A%2F%2Fwww.bilibili.com"}} - - public int code { get; set; } - public bool status { get; set; } - - //public long ts { get; set; } - public LoginInfoData data { get; set; } - } - - public class LoginInfoData - { - public string url { get; set; } - } - -} diff --git a/src/Core/entity/MyInfo.cs b/src/Core/entity/MyInfo.cs deleted file mode 100644 index b939db3..0000000 --- a/src/Core/entity/MyInfo.cs +++ /dev/null @@ -1,96 +0,0 @@ -namespace Core.entity -{ - // https://api.bilibili.com/x/space/myinfo - public class MyInfo - { - //public int code { get; set; } - public MyInfoData data { get; set; } - public string message { get; set; } - //public int ttl { get; set; } - } - - public class MyInfoData - { - public long birthday { get; set; } - public float coins { get; set; } - public int email_status { get; set; } - public string face { get; set; } - public int follower { get; set; } - public int following { get; set; } - public int identification { get; set; } - public int is_deleted { get; set; } - public int is_fake_account { get; set; } - public int is_tourist { get; set; } - public int jointime { get; set; } - public int level { get; set; } - public MyInfoDataLevelExp level_exp { get; set; } - public long mid { get; set; } - public int moral { get; set; } - public string name { get; set; } - public MyInfoDataNamePlate nameplate { get; set; } - public MyInfoDataOfficial official { get; set; } - public MyInfoDataPendant pendant { get; set; } - public int pin_prompting { get; set; } - public int rank { get; set; } - public string sex { get; set; } - public string sign { get; set; } - public int silence { get; set; } - public int tel_status { get; set; } - public MyInfoDataVip vip { get; set; } - } - - public class MyInfoDataLevelExp - { - public int current_exp { get; set; } - public int current_level { get; set; } - public int current_min { get; set; } - public int next_exp { get; set; } - } - - public class MyInfoDataNamePlate - { - public string condition { get; set; } - public string image { get; set; } - public string image_small { get; set; } - public string level { get; set; } - public string name { get; set; } - public int nid { get; set; } - } - - public class MyInfoDataOfficial - { - public string desc { get; set; } - public int role { get; set; } - public string title { get; set; } - public int type { get; set; } - } - - public class MyInfoDataPendant - { - public int expire { get; set; } - public string image { get; set; } - public string image_enhance { get; set; } - public string name { get; set; } - public int pid { get; set; } - } - - public class MyInfoDataVip - { - public int avatar_subscript { get; set; } - public long due_date { get; set; } - public MyInfoDataVipLabel label { get; set; } - public string nickname_color { get; set; } - public int status { get; set; } - public int theme_type { get; set; } - public int type { get; set; } - public int vip_pay_type { get; set; } - } - - public class MyInfoDataVipLabel - { - public string label_theme { get; set; } - public string path { get; set; } - public string text { get; set; } - } - -} diff --git a/src/Core/entity/Nav.cs b/src/Core/entity/Nav.cs deleted file mode 100644 index 23c33ab..0000000 --- a/src/Core/entity/Nav.cs +++ /dev/null @@ -1,88 +0,0 @@ -// 注释掉未使用的属性 -namespace Core.entity -{ - public class Nav - { - //public int code { get; set; } - public NavData data { get; set; } - public string message { get; set; } - //public int ttl { get; set; } - } - - public class NavData - { - //public int allowance_count { get; set; } - //public int answer_status { get; set; } - //public int email_verified { get; set; } - public string face { get; set; } - //public bool has_shop { get; set; } - public bool isLogin { get; set; } - //public NavDataLevelInfo level_info { get; set; } - public long mid { get; set; } - //public int mobile_verified { get; set; } - public float money { get; set; } - //public int moral { get; set; } - //public NavDataOfficial official { get; set; } - //public NavDataOfficialVerify officialVerify { get; set; } - //public NavDataPendant pendant { get; set; } - //public int scores { get; set; } - //public string shop_url { get; set; } - public string uname { get; set; } - //public long vipDueDate { get; set; } - public int vipStatus { get; set; } - //public int vipType { get; set; } - //public int vip_avatar_subscript { get; set; } - //public NavDataVipLabel vip_label { get; set; } - //public string vip_nickname_color { get; set; } - //public int vip_pay_type { get; set; } - //public int vip_theme_type { get; set; } - public NavDataWallet wallet { get; set; } - } - - public class NavDataLevelInfo - { - public int current_exp { get; set; } - public int current_level { get; set; } - public int current_min { get; set; } - //public int next_exp { get; set; } // 当等级为6时,next_exp为string类型,值为"--" - } - - //public class NavDataOfficial - //{ - // public string desc { get; set; } - // public int role { get; set; } - // public string title { get; set; } - // public int type { get; set; } - //} - - //public class NavDataOfficialVerify - //{ - // public string desc { get; set; } - // public int type { get; set; } - //} - - //public class NavDataPendant - //{ - // public int expire { get; set; } - // public string image { get; set; } - // public string image_enhance { get; set; } - // public string name { get; set; } - // public int pid { get; set; } - //} - - //public class NavDataVipLabel - //{ - // public string label_theme { get; set; } - // public string path { get; set; } - // public string text { get; set; } - //} - - public class NavDataWallet - { - public float bcoin_balance { get; set; } - public float coupon_balance { get; set; } - public long coupon_due_time { get; set; } - public long mid { get; set; } - } - -} diff --git a/src/Core/entity/PlayUrl.cs b/src/Core/entity/PlayUrl.cs deleted file mode 100644 index b9131c9..0000000 --- a/src/Core/entity/PlayUrl.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System.Collections.Generic; - -// 注释掉未使用的属性 -namespace Core.entity -{ - public class PlayUrl - { - //public int code { get; set; } - public PlayUrlData data { get; set; } - public PlayUrlData result { get; set; } - //public string message { get; set; } - //public int ttl { get; set; } - } - - public class PlayUrlData - { - public List accept_description { get; set; } - //public string accept_format { get; set; } - public List accept_quality { get; set; } - public PlayUrlDataDash dash { get; set; } - //public string format { get; set; } - //public string from { get; set; } - //public string message { get; set; } - public int quality { get; set; } - //public string result { get; set; } - //public string seek_param { get; set; } - //public string seek_type { get; set; } - //public string timelength { get; set; } - //public int video_codecid { get; set; } - - public List durl { get; set; } - } - - public class PlayUrlDataDash - { - public List audio { get; set; } - public long duration { get; set; } - //public float minBufferTime { get; set; } - //public float min_buffer_time { get; set; } - public List video { get; set; } - } - - public class PlayUrlDataDashVideo - { - //public PlayUrlDataDashSegmentBaseCls SegmentBase { get; set; } - public List backupUrl { get; set; } - public List backup_url { get; set; } - //public long bandwidth { get; set; } - public string baseUrl { get; set; } - public string base_url { get; set; } - //public int codecid { get; set; } - public string codecs { get; set; } - public string frameRate { get; set; } - //public string frame_rate { get; set; } - public int height { get; set; } - public int id { get; set; } - public string mimeType { get; set; } - //public string mime_type { get; set; } - //public string sar { get; set; } - //public PlayUrlDataDashSegmentBaseCls2 segment_base { get; set; } - //public int startWithSap { get; set; } - //public int start_with_sap { get; set; } - public int width { get; set; } - } - - //public class PlayUrlDataDashSegmentBaseCls - //{ - // public string Initialization { get; set; } - // public string indexRange { get; set; } - //} - - //public class PlayUrlDataDashSegmentBaseCls2 - //{ - // public string initialization { get; set; } - // public string index_range { get; set; } - //} - - public class PlayUrlDUrl - { - //public int order { get; set; } - public long length { get; set; } - public long size { get; set; } - //public string ahead { get; set; } - //public string vhead { get; set; } - public string url { get; set; } - public List backup_url { get; set; } - } - -} diff --git a/src/Core/entity/Stat.cs b/src/Core/entity/Stat.cs deleted file mode 100644 index 60ca53c..0000000 --- a/src/Core/entity/Stat.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace Core.entity -{ - // https://api.bilibili.com/x/relation/stat?vmid=42018135 - public class Stat - { - //public int code { get; set; } - public StatData data { get; set; } - //public string message { get; set; } - //public int ttl { get; set; } - } - - public class StatData - { - public int black { get; set; } // 黑名单 - public int follower { get; set; } // 粉丝数 - public int following { get; set; } // 关注数 - public long mid { get; set; } // 用户id - public int whisper { get; set; } // 悄悄关注数 - } - -} diff --git a/src/Core/entity/UserSettings.cs b/src/Core/entity/UserSettings.cs deleted file mode 100644 index 39102d0..0000000 --- a/src/Core/entity/UserSettings.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace Core.entity -{ - // https://space.bilibili.com/ajax/settings/getSettings?mid=42018135 - public class UserSettings - { - public UserSettingsData data { get; set; } - public bool status { get; set; } - } - - public class UserSettingsData - { - // …… - - public UserSettingsDataToutu toutu { get; set; } - } - - - public class UserSettingsDataToutu - { - public string android_img { get; set; } - public long expire { get; set; } - public string ipad_img { get; set; } - public string iphone_img { get; set; } - public string l_img { get; set; } - public int platform { get; set; } - public string s_img { get; set; } - public int sid { get; set; } - public string thumbnail_img { get; set; } - } - -} diff --git a/src/Core/entity/VideoDetail.cs b/src/Core/entity/VideoDetail.cs deleted file mode 100644 index 4c35beb..0000000 --- a/src/Core/entity/VideoDetail.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Core.entity -{ - // https://api.bilibili.com/x/web-interface/view/detail?bvid=BV1TJ411h7E6 - public class VideoDetail - { - //public int code { get; set; } - public VideoDetailData data { get; set; } - //public string message { get; set; } - //public int ttl { get; set; } - } - - public class VideoDetailData - { - //public VideoDetailDataCard Card { get; set; } - //public VideoDetailDataRelated Related { get; set; } - //public VideoDetailDataReply Reply { get; set; } - //public VideoDetailDataTags Tags { get; set; } - public VideoDetailDataView View { get; set; } - } - - public class VideoDetailDataView - { - // ... - public string redirect_url { get; set; } - // ... - } - -} diff --git a/src/Core/entity/VideoView.cs b/src/Core/entity/VideoView.cs deleted file mode 100644 index 0f6989b..0000000 --- a/src/Core/entity/VideoView.cs +++ /dev/null @@ -1,207 +0,0 @@ -using System.Collections.Generic; - -// 注释掉未使用的属性 -namespace Core.entity -{ - public class VideoView - { - public int code { get; set; } - public VideoViewData data { get; set; } - public string message { get; set; } - public int ttl { get; set; } - } - - public class VideoViewData - { - public long aid { get; set; } - //public long attribute { get; set; } - public string bvid { get; set; } - //public long cid { get; set; } - //public int copyright { get; set; } - public long ctime { get; set; } - public string desc { get; set; } - //public VideoViewDataDimension dimension { get; set; } - //public long duration { get; set; } - //public string dynamic { get; set; } - //public VideoViewDataLabel label { get; set; } - //public long mission_id { get; set; } - //public bool no_cache { get; set; } - public VideoViewDataOwner owner { get; set; } - public List pages { get; set; } - public string pic { get; set; } - public long pubdate { get; set; } - //public VideoViewDataRights rights { get; set; } - //public long season_id { get; set; } - public VideoViewDataStat stat { get; set; } - //public int state { get; set; } - //public VideoViewDataSubtitle subtitle { get; set; } - public long tid { get; set; } - public string title { get; set; } - public string tname { get; set; } - //public VideoViewDataUgcSeason ugc_season { get; set; } - //public int videos { get; set; } - } - - public class VideoViewDataDimension - { - public int width { get; set; } - public int height { get; set; } - //public int rotate { get; set; } - } - - //public class VideoViewDataLabel - //{ - // public int type { get; set; } - //} - - public class VideoViewDataOwner - { - public string face { get; set; } - public long mid { get; set; } - public string name { get; set; } - } - - public class VideoViewDataPages - { - public long cid { get; set; } - public VideoViewDataDimension dimension { get; set; } - public long duration { get; set; } - //public string from { get; set; } - public int page { get; set; } - public string part { get; set; } - //public string vid { get; set; } - //public string weblink { get; set; } - } - - //public class VideoViewDataRights - //{ - // public int autoplay { get; set; } - // public int bp { get; set; } - // public int download { get; set; } - // public int elec { get; set; } - // public int hd5 { get; set; } - // public int is_cooperation { get; set; } - // public int movie { get; set; } - // public int no_background { get; set; } - // public int no_reprint { get; set; } - // public int pay { get; set; } - // public int ugc_pay { get; set; } - // public int ugc_pay_preview { get; set; } - //} - - public class VideoViewDataStat - { - public long aid { get; set; } - public long coin { get; set; } - public long danmaku { get; set; } - public long dislike { get; set; } - public string evaluation { get; set; } - public long favorite { get; set; } - public long his_rank { get; set; } - public long like { get; set; } - public long now_rank { get; set; } - public long reply { get; set; } - public long share { get; set; } - public long view { get; set; } - } - - //public class VideoViewDataSubtitle - //{ - // public bool allow_submit { get; set; } - // //public List list { get; set; } - //} - - //public class VideoViewDataUgcSeason - //{ - // public int attribute { get; set; } - // public string cover { get; set; } - // public int ep_count { get; set; } - // public long id { get; set; } - // public string intro { get; set; } - // public long mid { get; set; } - // public List sections { get; set; } - // public int sign_state { get; set; } - // public VideoViewDataStat stat { get; set; } - // public string title { get; set; } - //} - - //public class VideoViewDataUgcSeasonSections - //{ - // public List episodes { get; set; } - // public long id { get; set; } - // public long season_id { get; set; } - // public string title { get; set; } - // public int type { get; set; } - //} - - //public class VideoViewDataUgcSeasonStat - //{ - // public long coin { get; set; } - // public long danmaku { get; set; } - // public long favorite { get; set; } - // public long his_rank { get; set; } - // public long like { get; set; } - // public long now_rank { get; set; } - // public long reply { get; set; } - // public long season_id { get; set; } - // public long share { get; set; } - // public long view { get; set; } - //} - - //public class VideoViewDataUgcSeasonSectionsEpisodes - //{ - // public long aid { get; set; } - // public VideoViewDataUgcSeasonSectionsEpisodesArc arc { get; set; } - // public int attribute { get; set; } - // public long cid { get; set; } - // public long id { get; set; } - // public VideoViewDataUgcSeasonSectionsEpisodesPage page { get; set; } - // public long season_id { get; set; } - // public long section_id { get; set; } - // public string title { get; set; } - //} - - //public class VideoViewDataUgcSeasonSectionsEpisodesArc - //{ - // public long aid { get; set; } - // public int copyright { get; set; } - // public long ctime { get; set; } - // public string desc { get; set; } - // public VideoViewDataDimension dimension { get; set; } - // public long duration { get; set; } - // public string dynamic { get; set; } - // public VideoViewDataOwner owner { get; set; } - // public string pic { get; set; } - // public long pubdate { get; set; } - // public VideoViewDataRights rights { get; set; } - // public VideoViewDataStat stat { get; set; } - // public int state { get; set; } - // public long tid { get; set; } - // public string title { get; set; } - // public string tname { get; set; } - // public int videos { get; set; } - //} - - //public class VideoViewDataUgcSeasonSectionsEpisodesPage - //{ - // public long cid { get; set; } - // public VideoViewDataDimension dimension { get; set; } - // public long duration { get; set; } - // public string from { get; set; } - // public int page { get; set; } - // public string part { get; set; } - // public string vid { get; set; } - // public string weblink { get; set; } - //} - - - // https://api.bilibili.com/x/player/pagelist?bvid={bvid}&jsonp=jsonp - public class Pagelist - { - public int code { get; set; } - public List data { get; set; } - public string message { get; set; } - public int ttl { get; set; } - } - -} diff --git a/src/Core/entity2/history/History.cs b/src/Core/entity2/history/History.cs deleted file mode 100644 index 3ca3cd3..0000000 --- a/src/Core/entity2/history/History.cs +++ /dev/null @@ -1,101 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.history -{ - // https://api.bilibili.com/x/web-interface/history/cursor?max={startId}&view_at={startTime}&ps={ps}&business={businessStr} - [JsonObject] - public class HistoryOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public HistoryData Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class HistoryData : BaseEntity - { - [JsonProperty("cursor")] - public HistoryDataCursor Cursor { get; set; } - [JsonProperty("list")] - public List List { get; set; } - //public List tab { get; set; } - } - - [JsonObject] - public class HistoryDataCursor : BaseEntity - { - [JsonProperty("business")] - public string Business { get; set; } - [JsonProperty("max")] - public long Max { get; set; } - [JsonProperty("ps")] - public int Ps { get; set; } - [JsonProperty("view_at")] - public long ViewAt { get; set; } - } - - [JsonObject] - public class HistoryDataList : BaseEntity - { - [JsonProperty("author_face")] - public string AuthorFace { get; set; } - [JsonProperty("author_mid")] - public long AuthorMid { get; set; } - [JsonProperty("author_name")] - public string AuthorName { get; set; } - // ... - [JsonProperty("cover")] - public string Cover { get; set; } - // ... - [JsonProperty("duration")] - public long Duration { get; set; } - [JsonProperty("history")] - public HistoryDataListHistory History { get; set; } - // ... - [JsonProperty("new_desc")] - public string NewDesc { get; set; } - [JsonProperty("progress")] - public long Progress { get; set; } - [JsonProperty("show_title")] - public string ShowTitle { get; set; } - [JsonProperty("tag_name")] - public string TagName { get; set; } - [JsonProperty("title")] - public string Title { get; set; } - // ... - [JsonProperty("uri")] - public string Uri { get; set; } - [JsonProperty("videos")] - public int Videos { get; set; } - [JsonProperty("view_at")] - public long ViewAt { get; set; } - } - - [JsonObject] - public class HistoryDataListHistory : BaseEntity - { - [JsonProperty("business")] - public string Business { get; set; } - [JsonProperty("bvid")] - public string Bvid { get; set; } - [JsonProperty("cid")] - public long Cid { get; set; } - [JsonProperty("dt")] - public int Dt { get; set; } - [JsonProperty("epid")] - public long Epid { get; set; } - [JsonProperty("oid")] - public long Oid { get; set; } - [JsonProperty("page")] - public int Page { get; set; } - [JsonProperty("part")] - public string Part { get; set; } - } - -} diff --git a/src/Core/entity2/history/ToView.cs b/src/Core/entity2/history/ToView.cs deleted file mode 100644 index 8349682..0000000 --- a/src/Core/entity2/history/ToView.cs +++ /dev/null @@ -1,60 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.history -{ - // https://api.bilibili.com/x/v2/history/toview/web - [JsonObject] - public class ToViewOrigin : BaseEntity - { - //public int code { get; set; } - [JsonProperty("data")] - public ToViewData Data { get; set; } - //public string message { get; set; } - //public int ttl { get; set; } - } - - [JsonObject] - public class ToViewData : BaseEntity - { - [JsonProperty("count")] - public int Count { get; set; } - [JsonProperty("list")] - public List List { get; set; } - } - - [JsonObject] - public class ToViewDataList : BaseEntity - { - [JsonProperty("add_at")] - public long AddAt { get; set; } - [JsonProperty("aid")] - public long Aid { get; set; } - //public long attribute { get; set; } - [JsonProperty("bvid")] - public string Bvid { get; set; } - [JsonProperty("cid")] - public long Cid { get; set; } - // ... - [JsonProperty("owner")] - public ToViewDataListOwner Owner { get; set; } - // ... - [JsonProperty("pic")] - public string Cover { get; set; } - // ... - [JsonProperty("title")] - public string Title { get; set; } - } - - [JsonObject] - public class ToViewDataListOwner : BaseEntity - { - [JsonProperty("face")] - public string Face { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - } - -} diff --git a/src/Core/entity2/users/BangumiFollow.cs b/src/Core/entity2/users/BangumiFollow.cs deleted file mode 100644 index e26e875..0000000 --- a/src/Core/entity2/users/BangumiFollow.cs +++ /dev/null @@ -1,103 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/space/bangumi/follow/list?vmid={mid}&type={type}&pn={pn}&ps={ps} - [JsonObject] - public class BangumiFollowOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public BangumiFollowData Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class BangumiFollowData : BaseEntity - { - [JsonProperty("list")] - public List List { get; set; } - [JsonProperty("pn")] - public int Pn { get; set; } - [JsonProperty("ps")] - public int Ps { get; set; } - [JsonProperty("total")] - public int Total { get; set; } - } - - [JsonObject] - public class BangumiFollow : BaseEntity - { - [JsonProperty("areas")] - public List Areas { get; set; } - [JsonProperty("badge")] - public string Badge { get; set; } - [JsonProperty("badge_ep")] - public string BadgeEp { get; set; } - // ... - [JsonProperty("cover")] - public string Cover { get; set; } - [JsonProperty("evaluate")] - public string Evaluate { get; set; } - // ... - [JsonProperty("media_id")] - public long MediaId { get; set; } - // ... - [JsonProperty("new_ep")] - public BangumiFollowNewEp NewEp { get; set; } - [JsonProperty("progress")] - public string Progress { get; set; } - // ... - [JsonProperty("season_id")] - public long SeasonId { get; set; } - [JsonProperty("season_status")] - public int SeasonStatus { get; set; } - [JsonProperty("season_title")] - public string SeasonTitle { get; set; } - [JsonProperty("season_type")] - public int SeasonType { get; set; } - [JsonProperty("season_type_name")] - public string SeasonTypeName { get; set; } - // ... - [JsonProperty("title")] - public string Title { get; set; } - [JsonProperty("total_count")] - public int TotalCount { get; set; } - [JsonProperty("url")] - public string Url { get; set; } - } - - [JsonObject] - public class BangumiFollowAreas : BaseEntity - { - [JsonProperty("id")] - public int Id { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - } - - [JsonObject] - public class BangumiFollowNewEp : BaseEntity - { - [JsonProperty("cover")] - public string Cover { get; set; } - [JsonProperty("duration")] - public long Duration { get; set; } - [JsonProperty("id")] - public long Id { get; set; } - [JsonProperty("index_show")] - public string IndexShow { get; set; } - [JsonProperty("long_title")] - public string LongTitle { get; set; } - [JsonProperty("pub_time")] - public string PubTime { get; set; } - [JsonProperty("title")] - public string Title { get; set; } - } - -} diff --git a/src/Core/entity2/users/FollowingGroup.cs b/src/Core/entity2/users/FollowingGroup.cs deleted file mode 100644 index 35d4162..0000000 --- a/src/Core/entity2/users/FollowingGroup.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/relation/tags - [JsonObject] - public class FollowingGroupOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public List Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class FollowingGroup : BaseEntity - { - [JsonProperty("count")] - public int Count { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - [JsonProperty("tagid")] - public int TagId { get; set; } - [JsonProperty("tip")] - public string Tip { get; set; } - } - -} diff --git a/src/Core/entity2/users/FollowingGroupContent.cs b/src/Core/entity2/users/FollowingGroupContent.cs deleted file mode 100644 index 8c0275b..0000000 --- a/src/Core/entity2/users/FollowingGroupContent.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/relation/tag?tagid={tagId}&pn={pn}&ps={ps}&order_type={orderType} - [JsonObject] - public class FollowingGroupContentOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public List Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class FollowingGroupContent : BaseEntity - { - [JsonProperty("attribute")] - public int Attribute { get; set; } - // ... - [JsonProperty("face")] - public string Face { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - // ... - [JsonProperty("sign")] - public string Sign { get; set; } - [JsonProperty("special")] - public int Special { get; set; } - [JsonProperty("tag")] - public List Tag { get; set; } - [JsonProperty("uname")] - public string Name { get; set; } - // ... - } - -} diff --git a/src/Core/entity2/users/MyInfo.cs b/src/Core/entity2/users/MyInfo.cs deleted file mode 100644 index eaef6eb..0000000 --- a/src/Core/entity2/users/MyInfo.cs +++ /dev/null @@ -1,166 +0,0 @@ -using Newtonsoft.Json; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/space/myinfo - [JsonObject] - public class MyInfoOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public MyInfo Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class MyInfo : BaseEntity - { - [JsonProperty("birthday")] - public long Birthday { get; set; } - [JsonProperty("coins")] - public float Coins { get; set; } - [JsonProperty("email_status")] - public int EmailStatus { get; set; } - [JsonProperty("face")] - public string Face { get; set; } - [JsonProperty("follower")] - public int Follower { get; set; } - [JsonProperty("following")] - public int Following { get; set; } - [JsonProperty("identification")] - public int Identification { get; set; } - [JsonProperty("is_deleted")] - public int IsDeleted { get; set; } - [JsonProperty("is_fake_account")] - public int IsFakeAccount { get; set; } - [JsonProperty("is_tourist")] - public int IsTourist { get; set; } - [JsonProperty("jointime")] - public int Jointime { get; set; } - [JsonProperty("level")] - public int Level { get; set; } - [JsonProperty("level_exp")] - public MyInfoLevelExp LevelExp { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("moral")] - public int Moral { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - [JsonProperty("nameplate")] - public MyInfoNamePlate Nameplate { get; set; } - [JsonProperty("official")] - public MyInfoOfficial Official { get; set; } - [JsonProperty("pendant")] - public MyInfoPendant Pendant { get; set; } - [JsonProperty("pin_prompting")] - public int PinPrompting { get; set; } - [JsonProperty("rank")] - public int Rank { get; set; } - [JsonProperty("sex")] - public string Sex { get; set; } - [JsonProperty("sign")] - public string Sign { get; set; } - [JsonProperty("silence")] - public int Silence { get; set; } - [JsonProperty("tel_status")] - public int TelStatus { get; set; } - [JsonProperty("vip")] - public MyInfoVip Vip { get; set; } - } - - [JsonObject] - public class MyInfoLevelExp : BaseEntity - { - [JsonProperty("current_exp")] - public int CurrentExp { get; set; } - [JsonProperty("current_level")] - public int CurrentLevel { get; set; } - [JsonProperty("current_min")] - public int CurrentMin { get; set; } - [JsonProperty("next_exp")] - public int NextExp { get; set; } - } - - [JsonObject] - public class MyInfoNamePlate : BaseEntity - { - [JsonProperty("condition")] - public string Condition { get; set; } - [JsonProperty("image")] - public string Image { get; set; } - [JsonProperty("image_small")] - public string ImageSmall { get; set; } - [JsonProperty("level")] - public string Level { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - [JsonProperty("nid")] - public int Nid { get; set; } - } - - [JsonObject] - public class MyInfoOfficial : BaseEntity - { - [JsonProperty("desc")] - public string Desc { get; set; } - [JsonProperty("role")] - public int Role { get; set; } - [JsonProperty("title")] - public string Title { get; set; } - [JsonProperty("type")] - public int Type { get; set; } - } - - [JsonObject] - public class MyInfoPendant : BaseEntity - { - [JsonProperty("expire")] - public int Expire { get; set; } - [JsonProperty("image")] - public string Image { get; set; } - [JsonProperty("image_enhance")] - public string ImageEnhance { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - [JsonProperty("pid")] - public int Pid { get; set; } - } - - [JsonObject] - public class MyInfoVip : BaseEntity - { - [JsonProperty("avatar_subscript")] - public int AvatarSubscript { get; set; } - [JsonProperty("due_date")] - public long DueDate { get; set; } - [JsonProperty("label")] - public MyInfoDataVipLabel Label { get; set; } - [JsonProperty("nickname_color")] - public string NicknameColor { get; set; } - [JsonProperty("status")] - public int Status { get; set; } - [JsonProperty("theme_type")] - public int ThemeType { get; set; } - [JsonProperty("type")] - public int Type { get; set; } - [JsonProperty("vip_pay_type")] - public int VipPayType { get; set; } - } - - [JsonObject] - public class MyInfoDataVipLabel : BaseEntity - { - [JsonProperty("label_theme")] - public string LabelTheme { get; set; } - [JsonProperty("path")] - public string Path { get; set; } - [JsonProperty("text")] - public string Text { get; set; } - } - -} diff --git a/src/Core/entity2/users/RelationBlacks.cs b/src/Core/entity2/users/RelationBlacks.cs deleted file mode 100644 index 9ab962e..0000000 --- a/src/Core/entity2/users/RelationBlacks.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/relation/blacks?pn={pn}&ps={ps} - [JsonObject] - public class RelationBlackOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public List Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - public class RelationBlack : BaseEntity - { - [JsonProperty("attribute")] - public int Attribute { get; set; } - // ... - [JsonProperty("face")] - public string Face { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("mtime")] - public long Mtime { get; set; } - // ... - [JsonProperty("sign")] - public string Sign { get; set; } - [JsonProperty("special")] - public int Special { get; set; } - [JsonProperty("tag")] - public List Tag { get; set; } - [JsonProperty("uname")] - public string Name { get; set; } - // ... - } - -} diff --git a/src/Core/entity2/users/RelationFollow.cs b/src/Core/entity2/users/RelationFollow.cs deleted file mode 100644 index 7e9b6b3..0000000 --- a/src/Core/entity2/users/RelationFollow.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/relation/followers?vmid={mid}&pn={pn}&ps={ps} - // https://api.bilibili.com/x/relation/followings?vmid={mid}&pn={pn}&ps={ps}&order_type={orderType} - [JsonObject] - public class RelationFollowOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public RelationFollow Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class RelationFollow : BaseEntity - { - [JsonProperty("list")] - public List List { get; set; } - //[JsonProperty("re_version")] - //public long reVersion { get; set; } - [JsonProperty("total")] - public int Total { get; set; } - } - - [JsonObject] - public class RelationFollowInfo : BaseEntity - { - [JsonProperty("attribute")] - public int Attribute { get; set; } - // ... - [JsonProperty("face")] - public string Face { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("mtime")] - public long Mtime { get; set; } - // ... - [JsonProperty("sign")] - public string Sign { get; set; } - [JsonProperty("special")] - public int Special { get; set; } - [JsonProperty("tag")] - public List Tag { get; set; } - [JsonProperty("uname")] - public string Name { get; set; } - // ... - } - -} diff --git a/src/Core/entity2/users/RelationWhisper.cs b/src/Core/entity2/users/RelationWhisper.cs deleted file mode 100644 index 76a3c70..0000000 --- a/src/Core/entity2/users/RelationWhisper.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/relation/whispers?pn={pn}&ps={ps} - [JsonObject] - public class RelationWhisperOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public List Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - public class RelationWhisper : BaseEntity - { - [JsonProperty("attribute")] - public int Attribute { get; set; } - // ... - [JsonProperty("face")] - public string Face { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("mtime")] - public long Mtime { get; set; } - // ... - [JsonProperty("sign")] - public string Sign { get; set; } - [JsonProperty("special")] - public int Special { get; set; } - [JsonProperty("tag")] - public List Tag { get; set; } - [JsonProperty("uname")] - public string Name { get; set; } - // ... - } - -} diff --git a/src/Core/entity2/users/SpaceChannelList.cs b/src/Core/entity2/users/SpaceChannelList.cs deleted file mode 100644 index 19f6d97..0000000 --- a/src/Core/entity2/users/SpaceChannelList.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/space/channel/list?mid= - [JsonObject] - public class SpaceChannelOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public SpaceChannel Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class SpaceChannel : BaseEntity - { - [JsonProperty("count")] - public int Count { get; set; } - [JsonProperty("list")] - public List List { get; set; } - } - - [JsonObject] - public class SpaceChannelList : BaseEntity - { - [JsonProperty("cid")] - public long Cid { get; set; } - [JsonProperty("count")] - public int Count { get; set; } - [JsonProperty("cover")] - public string Cover { get; set; } - [JsonProperty("intro")] - public string Intro { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("mtime")] - public long Mtime { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - } - -} diff --git a/src/Core/entity2/users/SpaceChannelVideo.cs b/src/Core/entity2/users/SpaceChannelVideo.cs deleted file mode 100644 index 65a65bf..0000000 --- a/src/Core/entity2/users/SpaceChannelVideo.cs +++ /dev/null @@ -1,103 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/space/channel/video?mid={mid}&cid={cid}&pn={pn}&ps={ps} - [JsonObject] - public class SpaceChannelVideoOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public SpaceChannelVideo Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class SpaceChannelVideo : BaseEntity - { - [JsonProperty("list")] - public SpaceChannelVideoList List { get; set; } - [JsonProperty("page")] - public SpaceChannelVideoPage Page { get; set; } - } - - [JsonObject] - public class SpaceChannelVideoList : BaseEntity - { - [JsonProperty("archives")] - public List Archives { get; set; } - [JsonProperty("cid")] - public long Cid { get; set; } - [JsonProperty("count")] - public int Count { get; set; } - [JsonProperty("cover")] - public string Cover { get; set; } - [JsonProperty("intro")] - public string Intro { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("mtime")] - public long Mtime { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - } - - [JsonObject] - public class SpaceChannelVideoPage : BaseEntity - { - [JsonProperty("count")] - public int Count { get; set; } - [JsonProperty("num")] - public int Num { get; set; } - [JsonProperty("size")] - public int Size { get; set; } - } - - [JsonObject] - public class SpaceChannelVideoArchive : BaseEntity - { - [JsonProperty("aid")] - public long Aid { get; set; } - [JsonProperty("bvid")] - public string Bvid { get; set; } - [JsonProperty("cid")] - public long Cid { get; set; } - // ... - [JsonProperty("ctime")] - public long Ctime { get; set; } - [JsonProperty("desc")] - public string Desc { get; set; } - // ... - [JsonProperty("duration")] - public long Duration { get; set; } - // ... - [JsonProperty("pic")] - public string Pic { get; set; } - [JsonProperty("pubdate")] - public long Pubdate { get; set; } - // ... - [JsonProperty("stat")] - public SpaceChannelVideoArchiveStat Stat { get; set; } - // ... - [JsonProperty("tid")] - public int Tid { get; set; } - [JsonProperty("title")] - public string Title { get; set; } - [JsonProperty("tname")] - public string Tname { get; set; } - } - - [JsonObject] - public class SpaceChannelVideoArchiveStat : BaseEntity - { - // ... - [JsonProperty("view")] - public long View { get; set; } - } - -} diff --git a/src/Core/entity2/users/SpaceCheese.cs b/src/Core/entity2/users/SpaceCheese.cs deleted file mode 100644 index 0802ded..0000000 --- a/src/Core/entity2/users/SpaceCheese.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/pugv/app/web/season/page?mid={mid}&pn={pn}&ps={ps} - [JsonObject] - public class SpaceCheeseOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public SpaceCheeseList Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class SpaceCheeseList : BaseEntity - { - [JsonProperty("items")] - public List Items { get; set; } - [JsonProperty("page")] - public SpaceCheesePage Page { get; set; } - } - - [JsonObject] - public class SpaceCheese : BaseEntity - { - [JsonProperty("cover")] - public string Cover { get; set; } - [JsonProperty("ep_count")] - public int EpCount { get; set; } - [JsonProperty("link")] - public string Link { get; set; } - [JsonProperty("page")] - public int Page { get; set; } - [JsonProperty("play")] - public int Play { get; set; } - [JsonProperty("season_id")] - public long SeasonId { get; set; } - [JsonProperty("status")] - public string Status { get; set; } - [JsonProperty("subtitle")] - public string SubTitle { get; set; } - [JsonProperty("title")] - public string Title { get; set; } - } - - [JsonObject] - public class SpaceCheesePage : BaseEntity - { - [JsonProperty("next")] - public bool Next { get; set; } - [JsonProperty("num")] - public int Num { get; set; } - [JsonProperty("size")] - public int Size { get; set; } - [JsonProperty("total")] - public int Total { get; set; } - } - -} diff --git a/src/Core/entity2/users/SpaceFavoriteFolder.cs b/src/Core/entity2/users/SpaceFavoriteFolder.cs deleted file mode 100644 index 1b70cfc..0000000 --- a/src/Core/entity2/users/SpaceFavoriteFolder.cs +++ /dev/null @@ -1,79 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/v3/fav/folder/created/list?up_mid={mid}&pn={pn}&ps={ps} - // https://api.bilibili.com/x/v3/fav/folder/collected/list?up_mid={mid}&pn={pn}&ps={ps} - [JsonObject] - public class SpaceFavoriteFolderOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public SpaceFavoriteFolder Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class SpaceFavoriteFolder : BaseEntity - { - [JsonProperty("count")] - public int Count { get; set; } - [JsonProperty("has_more")] - public int HasMore { get; set; } - [JsonProperty("list")] - public List List { get; set; } - } - - [JsonObject] - public class SpaceFavoriteFolderList : BaseEntity - { - [JsonProperty("attr")] - public int Attr { get; set; } - [JsonProperty("cover")] - public string Cover { get; set; } - [JsonProperty("cover_type")] - public int CoverType { get; set; } - [JsonProperty("ctime")] - public long Ctime { get; set; } - [JsonProperty("fav_state")] - public int FavState { get; set; } - [JsonProperty("fid")] - public long Fid { get; set; } - [JsonProperty("id")] - public long Id { get; set; } - [JsonProperty("intro")] - public string Intro { get; set; } - [JsonProperty("link")] - public string Link { get; set; } - [JsonProperty("media_count")] - public int MediaCount { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("mtime")] - public long Mtime { get; set; } - [JsonProperty("state")] - public int State { get; set; } - [JsonProperty("title")] - public string Title { get; set; } - [JsonProperty("upper")] - public FavoriteFolderUpper Upper { get; set; } - // ... - } - - [JsonObject] - public class FavoriteFolderUpper : BaseEntity - { - [JsonProperty("face")] - public string Face { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - } - -} diff --git a/src/Core/entity2/users/SpaceFavoriteFolderResource.cs b/src/Core/entity2/users/SpaceFavoriteFolderResource.cs deleted file mode 100644 index bf050ad..0000000 --- a/src/Core/entity2/users/SpaceFavoriteFolderResource.cs +++ /dev/null @@ -1,89 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/v3/fav/resource/list?media_id={mediaId}&pn={pn}&ps={ps} - [JsonObject] - public class SpaceFavoriteFolderResourceOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public SpaceFavoriteFolderResource Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class SpaceFavoriteFolderResource : BaseEntity - { - [JsonProperty("has_more")] - public int HasMore { get; set; } - // ... - [JsonProperty("medias")] - public List Medias { get; set; } - } - - [JsonObject] - public class SpaceFavoriteFolderMedia : BaseEntity - { - [JsonProperty("attr")] - public int Attr { get; set; } - [JsonProperty("bv_id")] - public string BvId { get; set; } - [JsonProperty("bvid")] - public string Bvid { get; set; } - [JsonProperty("cnt_info")] - public SpaceFavoriteFolderMediaCntInfo CntInfo { get; set; } - [JsonProperty("cover")] - public string Cover { get; set; } - [JsonProperty("ctime")] - public long Ctime { get; set; } - [JsonProperty("duration")] - public long Duration { get; set; } - [JsonProperty("fav_time")] - public long FavTime { get; set; } - [JsonProperty("id")] - public long Id { get; set; } - [JsonProperty("intro")] - public string Intro { get; set; } - [JsonProperty("link")] - public string Link { get; set; } - [JsonProperty("page")] - public int Page { get; set; } - [JsonProperty("pubtime")] - public long Pubtime { get; set; } - [JsonProperty("title")] - public string Title { get; set; } - [JsonProperty("type")] - public int Type { get; set; } - [JsonProperty("upper")] - public SpaceFavoriteFolderMediaUpper Upper { get; set; } - } - - [JsonObject] - public class SpaceFavoriteFolderMediaCntInfo : BaseEntity - { - [JsonProperty("collect")] - public long Collect { get; set; } - [JsonProperty("danmaku")] - public long Danmaku { get; set; } - [JsonProperty("play")] - public long Play { get; set; } - } - - [JsonObject] - public class SpaceFavoriteFolderMediaUpper : BaseEntity - { - [JsonProperty("face")] - public string Face { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - } - -} diff --git a/src/Core/entity2/users/SpaceInfo.cs b/src/Core/entity2/users/SpaceInfo.cs deleted file mode 100644 index 1e888d8..0000000 --- a/src/Core/entity2/users/SpaceInfo.cs +++ /dev/null @@ -1,77 +0,0 @@ -using Newtonsoft.Json; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/space/acc/info?mid={mid} - [JsonObject] - public class SpaceInfoOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public SpaceInfo Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class SpaceInfo : BaseEntity - { - // ... - [JsonProperty("face")] - public string Face { get; set; } - [JsonProperty("fans_badge")] - public bool FansBadge { get; set; } - [JsonProperty("is_followed")] - public bool IsFollowed { get; set; } - // ... - [JsonProperty("level")] - public int Level { get; set; } - // ... - [JsonProperty("mid")] - public int Mid { get; set; } - // ... - [JsonProperty("name")] - public string Name { get; set; } - // ... - [JsonProperty("sex")] - public string Sex { get; set; } - // ... - [JsonProperty("sign")] - public string Sign { get; set; } - // ... - [JsonProperty("top_photo")] - public string TopPhoto { get; set; } - [JsonProperty("vip")] - public SpaceInfoVip Vip { get; set; } - } - - public class SpaceInfoVip - { - [JsonProperty("avatar_subscript")] - public int AvatarSubscript { get; set; } - [JsonProperty("label")] - public SpaceInfoVipLabel Label { get; set; } - [JsonProperty("nickname_color")] - public string NicknameColor { get; set; } - [JsonProperty("status")] - public int Status { get; set; } - [JsonProperty("theme_type")] - public int ThemeType { get; set; } - [JsonProperty("type")] - public int Type { get; set; } - } - - public class SpaceInfoVipLabel - { - [JsonProperty("label_theme")] - public string LabelTheme { get; set; } - [JsonProperty("path")] - public string Path { get; set; } - [JsonProperty("text")] - public string Text { get; set; } - } - -} diff --git a/src/Core/entity2/users/SpacePublication.cs b/src/Core/entity2/users/SpacePublication.cs deleted file mode 100644 index 13569cc..0000000 --- a/src/Core/entity2/users/SpacePublication.cs +++ /dev/null @@ -1,150 +0,0 @@ -using Newtonsoft.Json; -using System.Collections.Generic; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/space/arc/search - [JsonObject] - public class SpacePublicationOrigin : BaseEntity - { - //[JsonProperty("code")] - //public int Code { get; set; } - [JsonProperty("data")] - public SpacePublication Data { get; set; } - //[JsonProperty("message")] - //public string Message { get; set; } - //[JsonProperty("ttl")] - //public int Ttl { get; set; } - } - - [JsonObject] - public class SpacePublication : BaseEntity - { - [JsonProperty("list")] - public SpacePublicationList List { get; set; } - [JsonProperty("page")] - public SpacePublicationPage Page { get; set; } - } - - [JsonObject] - public class SpacePublicationList : BaseEntity - { - [JsonProperty("tlist")] - public SpacePublicationListType Tlist { get; set; } - [JsonProperty("vlist")] - public List Vlist { get; set; } - } - - [JsonObject] - public class SpacePublicationPage : BaseEntity - { - [JsonProperty("count")] - public int Count { get; set; } - [JsonProperty("pn")] - public int Pn { get; set; } - [JsonProperty("ps")] - public int Ps { get; set; } - } - - [JsonObject] - public class SpacePublicationListType : BaseEntity - { - [JsonProperty("1")] - public SpacePublicationListTypeVideoZone Douga { get; set; } - [JsonProperty("13")] - public SpacePublicationListTypeVideoZone Anime { get; set; } - [JsonProperty("167")] - public SpacePublicationListTypeVideoZone Guochuang { get; set; } - [JsonProperty("3")] - public SpacePublicationListTypeVideoZone Music { get; set; } - [JsonProperty("129")] - public SpacePublicationListTypeVideoZone Dance { get; set; } - [JsonProperty("4")] - public SpacePublicationListTypeVideoZone Game { get; set; } - [JsonProperty("36")] - public SpacePublicationListTypeVideoZone Technology { get; set; } - [JsonProperty("188")] - public SpacePublicationListTypeVideoZone Digital { get; set; } - [JsonProperty("223")] - public SpacePublicationListTypeVideoZone Car { get; set; } - [JsonProperty("160")] - public SpacePublicationListTypeVideoZone Life { get; set; } - [JsonProperty("211")] - public SpacePublicationListTypeVideoZone Food { get; set; } - [JsonProperty("217")] - public SpacePublicationListTypeVideoZone Animal { get; set; } - [JsonProperty("119")] - public SpacePublicationListTypeVideoZone Kichiku { get; set; } - [JsonProperty("155")] - public SpacePublicationListTypeVideoZone Fashion { get; set; } - [JsonProperty("202")] - public SpacePublicationListTypeVideoZone Information { get; set; } - [JsonProperty("5")] - public SpacePublicationListTypeVideoZone Ent { get; set; } - [JsonProperty("181")] - public SpacePublicationListTypeVideoZone Cinephile { get; set; } - [JsonProperty("177")] - public SpacePublicationListTypeVideoZone Documentary { get; set; } - [JsonProperty("23")] - public SpacePublicationListTypeVideoZone Movie { get; set; } - [JsonProperty("11")] - public SpacePublicationListTypeVideoZone Tv { get; set; } - } - - [JsonObject] - public class SpacePublicationListVideo : BaseEntity - { - [JsonProperty("aid")] - public long Aid { get; set; } - //[JsonProperty("author")] - //public string Author { get; set; } - [JsonProperty("bvid")] - public string Bvid { get; set; } - //[JsonProperty("comment")] - //public int Comment { get; set; } - //[JsonProperty("copyright")] - //public string Copyright { get; set; } - [JsonProperty("created")] - public long Created { get; set; } - //[JsonProperty("description")] - //public string Description { get; set; } - //[JsonProperty("hide_click")] - //public bool HideClick { get; set; } - //[JsonProperty("is_pay")] - //public int IsPay { get; set; } - //[JsonProperty("is_steins_gate")] - //public int IsSteinsGate { get; set; } - //[JsonProperty("is_union_video")] - //public int IsUnionVideo { get; set; } - [JsonProperty("length")] - public string Length { get; set; } - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("pic")] - public string Pic { get; set; } - [JsonProperty("play")] - public int Play { get; set; } - //[JsonProperty("review")] - //public int Review { get; set; } - //[JsonProperty("subtitle")] - //public string Subtitle { get; set; } - [JsonProperty("title")] - public string Title { get; set; } - [JsonProperty("typeid")] - public int Typeid { get; set; } - //[JsonProperty("video_review")] - //public int VideoReview { get; set; } - } - - [JsonObject] - public class SpacePublicationListTypeVideoZone : BaseEntity - { - [JsonProperty("count")] - public int Count { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - [JsonProperty("tid")] - public int Tid { get; set; } - } - -} diff --git a/src/Core/entity2/users/SpaceSettings.cs b/src/Core/entity2/users/SpaceSettings.cs deleted file mode 100644 index 6b7f140..0000000 --- a/src/Core/entity2/users/SpaceSettings.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Newtonsoft.Json; - -namespace Core.entity2.users -{ - // https://space.bilibili.com/ajax/settings/getSettings?mid={mid} - [JsonObject] - public class SpaceSettingsOrigin : BaseEntity - { - [JsonProperty("data")] - public SpaceSettings Data { get; set; } - [JsonProperty("status")] - public bool Status { get; set; } - } - - [JsonObject] - public class SpaceSettings : BaseEntity - { - // ... - [JsonProperty("toutu")] - public SpaceSettingsToutu Toutu { get; set; } - } - - [JsonObject] - public class SpaceSettingsToutu : BaseEntity - { - [JsonProperty("android_img")] - public string AndroidImg { get; set; } - [JsonProperty("expire")] - public long Expire { get; set; } - [JsonProperty("ipad_img")] - public string IpadImg { get; set; } - [JsonProperty("iphone_img")] - public string IphoneImg { get; set; } - [JsonProperty("l_img")] - public string Limg { get; set; } // 完整url为http://i0.hdslb.com/+相对路径 - [JsonProperty("platform")] - public int Platform { get; set; } - [JsonProperty("s_img")] - public string Simg { get; set; } // 完整url为http://i0.hdslb.com/+相对路径 - [JsonProperty("sid")] - public int Sid { get; set; } - [JsonProperty("thumbnail_img")] - public string ThumbnailImg { get; set; } - } - -} diff --git a/src/Core/entity2/users/UpStat.cs b/src/Core/entity2/users/UpStat.cs deleted file mode 100644 index c913ad9..0000000 --- a/src/Core/entity2/users/UpStat.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Newtonsoft.Json; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/space/upstat?mid={mid} - [JsonObject] - public class UpStatOrigin : BaseEntity - { - [JsonProperty("data")] - public UpStat Data { get; set; } - } - - [JsonObject] - public class UpStat : BaseEntity - { - [JsonProperty("archive")] - public UpStatArchive Archive { get; set; } - [JsonProperty("article")] - public UpStatArchive Article { get; set; } - [JsonProperty("likes")] - public long Likes { get; set; } - } - - [JsonObject] - public class UpStatArchive : BaseEntity - { - [JsonProperty("view")] - public long View { get; set; } // 视频播放量 - } - -} diff --git a/src/Core/entity2/users/UserRelationStat.cs b/src/Core/entity2/users/UserRelationStat.cs deleted file mode 100644 index 7a31e9a..0000000 --- a/src/Core/entity2/users/UserRelationStat.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Newtonsoft.Json; - -namespace Core.entity2.users -{ - // https://api.bilibili.com/x/relation/stat?vmid={mid} - [JsonObject] - public class UserRelationStatOrigin : BaseEntity - { - [JsonProperty("data")] - public UserRelationStat Data { get; set; } - } - - [JsonObject] - public class UserRelationStat : BaseEntity - { - [JsonProperty("black")] - public long Black { get; set; } - [JsonProperty("follower")] - public long Follower { get; set; } // 粉丝数 - [JsonProperty("following")] - public long Following { get; set; } // 关注数 - [JsonProperty("mid")] - public long Mid { get; set; } - [JsonProperty("whisper")] - public long Whisper { get; set; } - } - -} diff --git a/src/Core/settings/ReadMe.md b/src/Core/settings/ReadMe.md deleted file mode 100644 index 87b3072..0000000 --- a/src/Core/settings/ReadMe.md +++ /dev/null @@ -1,167 +0,0 @@ -# 设置 - -Settings类位于`Core.settings`命名空间中,采用单例模式调用。设置属性使用json格式保存,并将加密后的字符串保存到文件。 - -| 文件名 | 内容 | -| ------------------- | -------------------------------------- | -| Settings.cs | Settings类的基本属性,单例模式的代码等 | -| Settings.class.cs | SettingsEntity类等 | -| Settings.base.cs | `基本`设置的代码 | -| Settings.network.cs | `网络`设置的代码 | -| Settings.video.cs | `视频`设置的代码 | -| Settings.about.cs | `关于`设置的代码 | - -## 基本 - -获取/设置下载完成后的操作。 - -```c# -public AfterDownloadOperation GetAfterDownloadOperation(); -public bool SetAfterDownloadOperation(AfterDownloadOperation afterDownload); -``` - -## 网络 - -获取/设置是否解除地区限制。 - -```c# -public LiftingOfRegion IsLiftingOfRegion(); -public bool IsLiftingOfRegion(LiftingOfRegion isLiftingOfRegion); -``` - -获取/设置Aria服务器的端口号。 - -```c# -public int GetAriaListenPort(); -public bool SetAriaListenPort(int ariaListenPort); -``` - -获取/设置Aria日志等级。 - -```c# -public AriaConfigLogLevel GetAriaLogLevel(); -public bool SetAriaLogLevel(AriaConfigLogLevel ariaLogLevel); -``` - -获取/设置Aria最大同时下载数(任务数)。 - -```c# -public int GetAriaMaxConcurrentDownloads(); -public bool SetAriaMaxConcurrentDownloads(int ariaMaxConcurrentDownloads); -``` - -获取/设置Aria单文件最大线程数。 - -```c# -public int GetAriaSplit(); -public bool SetAriaSplit(int ariaSplit); -``` - -获取/设置Aria下载速度限制。 - -```c# -public int GetAriaMaxOverallDownloadLimit(); -public bool SetAriaMaxOverallDownloadLimit(int ariaMaxOverallDownloadLimit); -``` - -获取/设置Aria下载单文件速度限制。 - -```c# -public int GetAriaMaxDownloadLimit(); -public bool SetAriaMaxDownloadLimit(int ariaMaxDownloadLimit); -``` - -获取/设置Aria文件预分配。 - -```c# -public AriaConfigFileAllocation GetAriaFileAllocation(); -public bool SetAriaFileAllocation(AriaConfigFileAllocation ariaFileAllocation); -``` - -获取/设置是否开启Aria http代理。 - -```c# -public AriaHttpProxy IsAriaHttpProxy(); -public bool IsAriaHttpProxy(AriaHttpProxy isAriaHttpProxy); -``` - -获取/设置Aria的http代理的地址。 - -```c# -public string GetAriaHttpProxy(); -public bool SetAriaHttpProxy(string ariaHttpProxy); -``` - -获取/设置Aria的http代理的端口。 - -```c# -public int GetAriaHttpProxyListenPort(); -public bool SetAriaHttpProxyListenPort(int ariaHttpProxyListenPort); -``` - -## 视频 - -获取/设置优先下载的视频编码。 - -```c# -public VideoCodecs GetVideoCodecs(); -public bool SetVideoCodecs(VideoCodecs videoCodecs); -``` - -获取/设置优先下载画质。 - -```c# -public int GetQuality(); -public bool SetQuality(int quality); -``` - -获取/设置是否给视频增加序号。 - -```c# -public AddOrder IsAddOrder(); -public bool IsAddOrder(AddOrder isAddOrder); -``` - -获取/设置是否下载flv视频后转码为mp4。 - -```c# -public TranscodingFlvToMp4 IsTranscodingFlvToMp4(); -public bool IsTranscodingFlvToMp4(TranscodingFlvToMp4 isTranscodingFlvToMp4); -``` - -获取/设置下载目录。 - -```c# -public string GetSaveVideoRootPath(); -public bool SetSaveVideoRootPath(string path); -``` - -获取/设置是否使用默认下载目录。 - -```c# -public UseSaveVideoRootPath IsUseSaveVideoRootPath(); -public bool IsUseSaveVideoRootPath(UseSaveVideoRootPath isUseSaveVideoRootPath); -``` - -获取/设置是否为不同视频分别创建文件夹。 - -```c# -public CreateFolderForMedia IsCreateFolderForMedia(); -public bool IsCreateFolderForMedia(CreateFolderForMedia isCreateFolderForMedia); -``` - -## 关于 - -获取/设置是否接收测试版更新。 - -```c# -public ReceiveBetaVersion IsReceiveBetaVersion(); -public bool IsReceiveBetaVersion(ReceiveBetaVersion isReceiveBetaVersion); -``` - -获取/设置是否允许启动时检查更新。 - -```c# -public AutoUpdateWhenLaunch GetAutoUpdateWhenLaunch(); -public bool SetAutoUpdateWhenLaunch(AutoUpdateWhenLaunch autoUpdateWhenLaunch); -``` diff --git a/src/Core/settings/Settings.class.cs b/src/Core/settings/Settings.class.cs deleted file mode 100644 index 02a1ccd..0000000 --- a/src/Core/settings/Settings.class.cs +++ /dev/null @@ -1,90 +0,0 @@ -using Core.aria2cNet.server; - -namespace Core.settings -{ - public class SettingsEntity - { - public UserInfoForSetting UserInfo { get; set; } - - // 基本 - public AfterDownloadOperation AfterDownload { get; set; } - public ALLOW_STATUS IsListenClipboard { get; set; } - public ALLOW_STATUS IsAutoParseVideo { get; set; } - public DownloadFinishedSort DownloadFinishedSort { get; set; } - - // 网络 - public ALLOW_STATUS IsLiftingOfRegion { get; set; } - public int AriaListenPort { get; set; } - public AriaConfigLogLevel AriaLogLevel { get; set; } - public int AriaMaxConcurrentDownloads { get; set; } - public int AriaSplit { get; set; } - public int AriaMaxOverallDownloadLimit { get; set; } - public int AriaMaxDownloadLimit { get; set; } - public AriaConfigFileAllocation AriaFileAllocation { get; set; } - - public ALLOW_STATUS IsAriaHttpProxy { get; set; } - public string AriaHttpProxy { get; set; } - public int AriaHttpProxyListenPort { get; set; } - - // 视频 - public VideoCodecs VideoCodecs { get; set; } - public int Quality { get; set; } - public ALLOW_STATUS IsAddOrder { get; set; } - public ALLOW_STATUS IsTranscodingFlvToMp4 { get; set; } - public string SaveVideoRootPath { get; set; } - public ALLOW_STATUS IsUseSaveVideoRootPath { get; set; } - public ALLOW_STATUS IsCreateFolderForMedia { get; set; } - public ALLOW_STATUS IsDownloadDanmaku { get; set; } - public ALLOW_STATUS IsDownloadCover { get; set; } - - // 弹幕 - public ALLOW_STATUS DanmakuTopFilter { get; set; } - public ALLOW_STATUS DanmakuBottomFilter { get; set; } - public ALLOW_STATUS DanmakuScrollFilter { get; set; } - public ALLOW_STATUS IsCustomDanmakuResolution { get; set; } - public int DanmakuScreenWidth { get; set; } - public int DanmakuScreenHeight { get; set; } - public string DanmakuFontName { get; set; } - public int DanmakuFontSize { get; set; } - public int DanmakuLineCount { get; set; } - public DanmakuLayoutAlgorithm DanmakuLayoutAlgorithm { get; set; } - - // 关于 - public ALLOW_STATUS IsReceiveBetaVersion { get; set; } - public ALLOW_STATUS AutoUpdateWhenLaunch { get; set; } - } - - public class UserInfoForSetting - { - public long Mid { get; set; } - public string Name { get; set; } - public bool IsLogin { get; set; } // 是否登录 - public bool IsVip { get; set; } // 是否为大会员,未登录时为false - } - - public enum AfterDownloadOperation - { - NONE = 1, OPEN_FOLDER, CLOSE_APP, CLOSE_SYSTEM - } - - public enum ALLOW_STATUS - { - NONE = 0, YES, NO - } - - public enum DownloadFinishedSort - { - DOWNLOAD = 0, NUMBER - } - - public enum VideoCodecs - { - NONE = 0, AVC, HEVC - } - - public enum DanmakuLayoutAlgorithm - { - NONE = 0, ASYNC, SYNC - } - -} diff --git a/src/Core/settings/Settings.cs b/src/Core/settings/Settings.cs deleted file mode 100644 index bfef7d8..0000000 --- a/src/Core/settings/Settings.cs +++ /dev/null @@ -1,132 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.IO; - -namespace Core.settings -{ - public partial class Settings - { - private static Settings instance; - - /// - /// 获取Settings实例 - /// - /// - public static Settings GetInstance() - { - if (instance == null) - { - instance = new Settings(); - } - return instance; - } - - /// - /// 隐藏Settings()方法,必须使用单例模式 - /// - private Settings() - { - settingsEntity = GetEntity(); - } - - - // 内存中保存一份配置 - private readonly SettingsEntity settingsEntity; - - // 设置的配置文件 - private readonly string settingsName = Common.ConfigPath + "Settings"; - - // 密钥 - private readonly string password = "QA!M^gE@"; - - // 登录用户的mid - private readonly UserInfoForSetting userInfo = new UserInfoForSetting - { - Mid = -1, - Name = "", - IsLogin = false, - IsVip = false - }; - - private SettingsEntity GetEntity() - { - try - { - StreamReader streamReader = File.OpenText(settingsName); - string jsonWordTemplate = streamReader.ReadToEnd(); - streamReader.Close(); - - // 解密字符串 - jsonWordTemplate = Encryptor.DecryptString(jsonWordTemplate, password); - - return JsonConvert.DeserializeObject(jsonWordTemplate); - } - catch (FileNotFoundException e) - { - Console.WriteLine("GetEntity()发生异常: {0}", e); - return new SettingsEntity(); - } - catch (DirectoryNotFoundException e) - { - Console.WriteLine("GetEntity()发生异常: {0}", e); - return new SettingsEntity(); - } - catch (Exception e) - { - Console.WriteLine("GetEntity()发生异常: {0}", e); - return new SettingsEntity(); - } - } - - private bool SetEntity() - { - if (!Directory.Exists(Common.ConfigPath)) - { - Directory.CreateDirectory(Common.ConfigPath); - } - - string json = JsonConvert.SerializeObject(settingsEntity); - - // 加密字符串 - json = Encryptor.EncryptString(json, password); - try - { - File.WriteAllText(settingsName, json); - return true; - } - catch (IOException e) - { - Console.WriteLine("SetEntity()发生异常: {0}", e); - return false; - } - } - - /// - /// 获取登录用户信息 - /// - /// - public UserInfoForSetting GetUserInfo() - { - if (settingsEntity.UserInfo == null) - { - // 第一次获取,先设置默认值 - SetUserInfo(userInfo); - return userInfo; - } - return settingsEntity.UserInfo; - } - - /// - /// 设置中保存登录用户的信息,在index刷新用户状态时使用 - /// - /// - /// - public bool SetUserInfo(UserInfoForSetting userInfo) - { - settingsEntity.UserInfo = userInfo; - return SetEntity(); - } - - - } -} diff --git a/src/Core/aria2cNet/AriaManager.cs b/src/DownKyi.Core/Aria2cNet/AriaManager.cs similarity index 73% rename from src/Core/aria2cNet/AriaManager.cs rename to src/DownKyi.Core/Aria2cNet/AriaManager.cs index a3132ff..b2a8d45 100644 --- a/src/Core/aria2cNet/AriaManager.cs +++ b/src/DownKyi.Core/Aria2cNet/AriaManager.cs @@ -1,8 +1,8 @@ -using Core.aria2cNet.client; -using System; +using DownKyi.Core.Aria2cNet.Client; +using DownKyi.Core.Logging; using System.Threading; -namespace Core.aria2cNet +namespace DownKyi.Core.Aria2cNet { public class AriaManager { @@ -69,7 +69,8 @@ namespace Core.aria2cNet } if (status.Result.Result.ErrorCode != null && status.Result.Result.ErrorCode != "0") { - Console.WriteLine("ErrorMessage: " + status.Result.Result.ErrorMessage); + Utils.Debug.Console.PrintLine("ErrorMessage: " + status.Result.Result.ErrorMessage); + LogManager.Error("AriaManager", status.Result.Result.ErrorMessage); //// 如果返回状态码不是200,则继续 //if (status.Result.Result.ErrorMessage.Contains("The response status is not successful")) @@ -80,7 +81,8 @@ namespace Core.aria2cNet // aira中删除记录 var ariaRemove1 = AriaClient.RemoveDownloadResultAsync(gid); - Console.WriteLine(ariaRemove1); + Utils.Debug.Console.PrintLine(ariaRemove1); + LogManager.Debug("AriaManager", ariaRemove1.Result.Result); // 返回回调信息,退出函数 OnDownloadFinish(false, null, gid, status.Result.Result.ErrorMessage); @@ -114,46 +116,5 @@ namespace Core.aria2cNet } } - - //private async void Poll() - //{ - // while (true) - // { - // // 查询全局status - // var globalStatus = await AriaClient.GetGlobalStatAsync(); - // if (globalStatus == null || globalStatus.Result == null) { continue; } - - // long globalSpeed = long.Parse(globalStatus.Result.DownloadSpeed); - // // 回调 - // OnGetGlobalStatus(globalSpeed); - - // // 查询gid对应的项目的status - // foreach (var gid in gidList) - // { - // var status = await AriaClient.TellStatus(gid); - // if (status == null || status.Result == null) { continue; } - - // long totalLength = long.Parse(status.Result.TotalLength); - // long completedLength = long.Parse(status.Result.CompletedLength); - // long speed = long.Parse(status.Result.DownloadSpeed); - // // 回调 - // OnTellStatus(totalLength, completedLength, speed, gid); - // } - - // } - //} - } - - - /// - /// 下载状态 - /// - public enum DownloadStatus - { - SUCCESS = 1, - FAILED, - ABORT - } - } diff --git a/src/Core/aria2cNet/client/AriaClient.cs b/src/DownKyi.Core/Aria2cNet/Client/AriaClient.cs similarity index 98% rename from src/Core/aria2cNet/client/AriaClient.cs rename to src/DownKyi.Core/Aria2cNet/Client/AriaClient.cs index 0605cae..ee7f287 100644 --- a/src/Core/aria2cNet/client/AriaClient.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/AriaClient.cs @@ -1,4 +1,5 @@ -using Core.aria2cNet.client.entity; +using DownKyi.Core.Aria2cNet.Client.Entity; +using DownKyi.Core.Logging; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -7,9 +8,8 @@ using System.Net; using System.Text; using System.Threading.Tasks; -namespace Core.aria2cNet.client +namespace DownKyi.Core.Aria2cNet.Client { - /// /// http://aria2.github.io/manual/en/html/aria2c.html#methods /// @@ -1093,7 +1093,8 @@ namespace Core.aria2cNet.client } catch (WebException e) { - Console.WriteLine("Request()发生Web异常: {0}", e); + Utils.Debug.Console.PrintLine("Request()发生Web异常: {0}", e); + LogManager.Error("AriaClient", e); //return Request(url, parameters, retry - 1); string html = string.Empty; @@ -1106,34 +1107,24 @@ namespace Core.aria2cNet.client html = reader.ReadToEnd(); } } -#if DEBUG + Console.WriteLine($"本次请求使用的参数:{parameters}"); Console.WriteLine($"返回的web数据:{html}"); -#endif return html; } catch (IOException e) { - Console.WriteLine("Request()发生IO异常: {0}", e); + Utils.Debug.Console.PrintLine("Request()发生IO异常: {0}", e); + LogManager.Error("AriaClient", e); return Request(url, parameters, retry - 1); } catch (Exception e) { - Console.WriteLine("Request()发生其他异常: {0}", e); + Utils.Debug.Console.PrintLine("Request()发生其他异常: {0}", e); + LogManager.Error("AriaClient", e); return Request(url, parameters, retry - 1); } } } - - /// - /// changePosition函数的how参数 - /// - public enum HowChangePosition - { - POS_SET = 1, - POS_CUR, - POS_END - } - } diff --git a/src/Core/aria2cNet/client/entity/AriaAddMetalink.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaAddMetalink.cs similarity index 91% rename from src/Core/aria2cNet/client/entity/AriaAddMetalink.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaAddMetalink.cs index 72ba7e0..4101680 100644 --- a/src/Core/aria2cNet/client/entity/AriaAddMetalink.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaAddMetalink.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaAddMetalink diff --git a/src/Core/aria2cNet/client/entity/AriaAddTorrent.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaAddTorrent.cs similarity index 91% rename from src/Core/aria2cNet/client/entity/AriaAddTorrent.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaAddTorrent.cs index 6550577..80503ec 100644 --- a/src/Core/aria2cNet/client/entity/AriaAddTorrent.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaAddTorrent.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaAddTorrent diff --git a/src/Core/aria2cNet/client/entity/AriaAddUri.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaAddUri.cs similarity index 92% rename from src/Core/aria2cNet/client/entity/AriaAddUri.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaAddUri.cs index c6a5d33..fca6526 100644 --- a/src/Core/aria2cNet/client/entity/AriaAddUri.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaAddUri.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { //{ //"id": "downkyi", diff --git a/src/Core/aria2cNet/client/entity/AriaChangeOption.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaChangeOption.cs similarity index 91% rename from src/Core/aria2cNet/client/entity/AriaChangeOption.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaChangeOption.cs index 0d7edf0..b91a0e2 100644 --- a/src/Core/aria2cNet/client/entity/AriaChangeOption.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaChangeOption.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaChangeOption diff --git a/src/Core/aria2cNet/client/entity/AriaChangePosition.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaChangePosition.cs similarity index 91% rename from src/Core/aria2cNet/client/entity/AriaChangePosition.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaChangePosition.cs index 63bb749..1405e56 100644 --- a/src/Core/aria2cNet/client/entity/AriaChangePosition.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaChangePosition.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaChangePosition diff --git a/src/Core/aria2cNet/client/entity/AriaChangeUri.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaChangeUri.cs similarity index 92% rename from src/Core/aria2cNet/client/entity/AriaChangeUri.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaChangeUri.cs index 9e0851b..b9af10a 100644 --- a/src/Core/aria2cNet/client/entity/AriaChangeUri.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaChangeUri.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaChangeUri diff --git a/src/Core/aria2cNet/client/entity/AriaError.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaError.cs similarity index 90% rename from src/Core/aria2cNet/client/entity/AriaError.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaError.cs index 6017c19..4b967a3 100644 --- a/src/Core/aria2cNet/client/entity/AriaError.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaError.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { //"error": { // "code": 1, diff --git a/src/Core/aria2cNet/client/entity/AriaGetFiles.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetFiles.cs similarity index 96% rename from src/Core/aria2cNet/client/entity/AriaGetFiles.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetFiles.cs index 7be4289..34765e1 100644 --- a/src/Core/aria2cNet/client/entity/AriaGetFiles.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetFiles.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaGetFiles @@ -50,5 +50,4 @@ namespace Core.aria2cNet.client.entity return JsonConvert.SerializeObject(this); } } - } diff --git a/src/Core/aria2cNet/client/entity/AriaGetGlobalStat.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetGlobalStat.cs similarity index 78% rename from src/Core/aria2cNet/client/entity/AriaGetGlobalStat.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetGlobalStat.cs index daab88d..1dc6591 100644 --- a/src/Core/aria2cNet/client/entity/AriaGetGlobalStat.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetGlobalStat.cs @@ -1,21 +1,21 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { /* - { - "id": "qwer", - "jsonrpc": "2.0", - "result": { - "downloadSpeed": "0", - "numActive": "0", - "numStopped": "0", - "numStoppedTotal": "0", - "numWaiting": "0", - "uploadSpeed": "0" - } - } - */ + { + "id": "qwer", + "jsonrpc": "2.0", + "result": { + "downloadSpeed": "0", + "numActive": "0", + "numStopped": "0", + "numStoppedTotal": "0", + "numWaiting": "0", + "uploadSpeed": "0" + } + } + */ [JsonObject] public class AriaGetGlobalStat { @@ -63,5 +63,4 @@ namespace Core.aria2cNet.client.entity return JsonConvert.SerializeObject(this); } } - } diff --git a/src/Core/aria2cNet/client/entity/AriaGetOption.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetOption.cs similarity index 91% rename from src/Core/aria2cNet/client/entity/AriaGetOption.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetOption.cs index d809e01..3e7e6e1 100644 --- a/src/Core/aria2cNet/client/entity/AriaGetOption.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetOption.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaGetOption diff --git a/src/Core/aria2cNet/client/entity/AriaGetPeers.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetPeers.cs similarity index 96% rename from src/Core/aria2cNet/client/entity/AriaGetPeers.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetPeers.cs index e771e98..fa08242 100644 --- a/src/Core/aria2cNet/client/entity/AriaGetPeers.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetPeers.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaGetPeers @@ -59,5 +59,4 @@ namespace Core.aria2cNet.client.entity return JsonConvert.SerializeObject(this); } } - } diff --git a/src/Core/aria2cNet/client/entity/AriaGetServers.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetServers.cs similarity index 96% rename from src/Core/aria2cNet/client/entity/AriaGetServers.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetServers.cs index 9f2c685..7b6d8f2 100644 --- a/src/Core/aria2cNet/client/entity/AriaGetServers.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetServers.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaGetServers @@ -56,5 +56,4 @@ namespace Core.aria2cNet.client.entity return JsonConvert.SerializeObject(this); } } - } diff --git a/src/Core/aria2cNet/client/entity/AriaGetSessionInfo.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetSessionInfo.cs similarity index 94% rename from src/Core/aria2cNet/client/entity/AriaGetSessionInfo.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetSessionInfo.cs index 20b24be..76c9c6e 100644 --- a/src/Core/aria2cNet/client/entity/AriaGetSessionInfo.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetSessionInfo.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaGetSessionInfo @@ -34,5 +34,4 @@ namespace Core.aria2cNet.client.entity return JsonConvert.SerializeObject(this); } } - } diff --git a/src/Core/aria2cNet/client/entity/AriaGetUris.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetUris.cs similarity index 92% rename from src/Core/aria2cNet/client/entity/AriaGetUris.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetUris.cs index 86b8486..61b42ac 100644 --- a/src/Core/aria2cNet/client/entity/AriaGetUris.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaGetUris.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaGetUris diff --git a/src/Core/aria2cNet/client/entity/AriaOption.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaOption.cs similarity index 99% rename from src/Core/aria2cNet/client/entity/AriaOption.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaOption.cs index 709a140..4a3e6aa 100644 --- a/src/Core/aria2cNet/client/entity/AriaOption.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaOption.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaOption diff --git a/src/Core/aria2cNet/client/entity/AriaPause.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaPause.cs similarity index 91% rename from src/Core/aria2cNet/client/entity/AriaPause.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaPause.cs index 069ecd0..3aa20fc 100644 --- a/src/Core/aria2cNet/client/entity/AriaPause.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaPause.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaPause diff --git a/src/Core/aria2cNet/client/entity/AriaRemove.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaRemove.cs similarity index 91% rename from src/Core/aria2cNet/client/entity/AriaRemove.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaRemove.cs index a7c515c..5950c4d 100644 --- a/src/Core/aria2cNet/client/entity/AriaRemove.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaRemove.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaRemove diff --git a/src/Core/aria2cNet/client/entity/AriaSaveSession.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaSaveSession.cs similarity index 91% rename from src/Core/aria2cNet/client/entity/AriaSaveSession.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaSaveSession.cs index 09728ae..11f654e 100644 --- a/src/Core/aria2cNet/client/entity/AriaSaveSession.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaSaveSession.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaSaveSession diff --git a/src/Core/aria2cNet/client/entity/AriaSendData.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaSendData.cs similarity index 96% rename from src/Core/aria2cNet/client/entity/AriaSendData.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaSendData.cs index bbe6612..ffbe89a 100644 --- a/src/Core/aria2cNet/client/entity/AriaSendData.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaSendData.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaSendData @@ -50,5 +50,4 @@ namespace Core.aria2cNet.client.entity return JsonConvert.SerializeObject(this); } } - } diff --git a/src/Core/aria2cNet/client/entity/AriaShutdown.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaShutdown.cs similarity index 91% rename from src/Core/aria2cNet/client/entity/AriaShutdown.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaShutdown.cs index 490e140..45a688d 100644 --- a/src/Core/aria2cNet/client/entity/AriaShutdown.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaShutdown.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaShutdown diff --git a/src/Core/aria2cNet/client/entity/AriaTellStatus.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaTellStatus.cs similarity index 73% rename from src/Core/aria2cNet/client/entity/AriaTellStatus.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaTellStatus.cs index 8bea3f6..fa2c41f 100644 --- a/src/Core/aria2cNet/client/entity/AriaTellStatus.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaTellStatus.cs @@ -1,49 +1,8 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { - /* - { - "id": "qwer", - "jsonrpc": "2.0", - "result": { - "bitfield": "80", - "completedLength": "118188", - "connections": "0", - "dir": "D:\\home", - "downloadSpeed": "0", - "errorCode": "0", - "errorMessage": "", - "files": [ - { - "completedLength": "118188", - "index": "1", - "length": "118188", - "path": "D:/home/ariaTest.html", - "selected": "true", - "uris": [ - { - "status": "used", - "uri": "https://www.bilibili.com/" - }, - { - "status": "waiting", - "uri": "https://www.bilibili.com/" - } - ] - } - ], - "gid": "4e7f671a6134b5ac", - "numPieces": "1", - "pieceLength": "1048576", - "status": "complete", - "totalLength": "118188", - "uploadLength": "0", - "uploadSpeed": "0" - } -} - */ [JsonObject] public class AriaTellStatus { @@ -166,5 +125,4 @@ namespace Core.aria2cNet.client.entity return JsonConvert.SerializeObject(this); } } - } diff --git a/src/Core/aria2cNet/client/entity/AriaUri.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaUri.cs similarity index 88% rename from src/Core/aria2cNet/client/entity/AriaUri.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaUri.cs index 8d81837..28001bc 100644 --- a/src/Core/aria2cNet/client/entity/AriaUri.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaUri.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaUri diff --git a/src/Core/aria2cNet/client/entity/AriaVersion.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaVersion.cs similarity index 95% rename from src/Core/aria2cNet/client/entity/AriaVersion.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/AriaVersion.cs index 04c2a9a..d7ab742 100644 --- a/src/Core/aria2cNet/client/entity/AriaVersion.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/AriaVersion.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class AriaVersion @@ -38,5 +38,4 @@ namespace Core.aria2cNet.client.entity return JsonConvert.SerializeObject(this); } } - } diff --git a/src/Core/aria2cNet/client/entity/SystemListMethods.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/SystemListMethods.cs similarity index 92% rename from src/Core/aria2cNet/client/entity/SystemListMethods.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/SystemListMethods.cs index 31fb31a..96ce9da 100644 --- a/src/Core/aria2cNet/client/entity/SystemListMethods.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/SystemListMethods.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class SystemListMethods diff --git a/src/Core/aria2cNet/client/entity/SystemListNotifications.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/SystemListNotifications.cs similarity index 92% rename from src/Core/aria2cNet/client/entity/SystemListNotifications.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/SystemListNotifications.cs index a2697fc..68be4be 100644 --- a/src/Core/aria2cNet/client/entity/SystemListNotifications.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/SystemListNotifications.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class SystemListNotifications diff --git a/src/Core/aria2cNet/client/entity/SystemMulticall.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/SystemMulticall.cs similarity index 91% rename from src/Core/aria2cNet/client/entity/SystemMulticall.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/SystemMulticall.cs index f33dc93..b0da67d 100644 --- a/src/Core/aria2cNet/client/entity/SystemMulticall.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/SystemMulticall.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class SystemMulticall diff --git a/src/Core/aria2cNet/client/entity/SystemMulticallMathod.cs b/src/DownKyi.Core/Aria2cNet/Client/Entity/SystemMulticallMathod.cs similarity index 86% rename from src/Core/aria2cNet/client/entity/SystemMulticallMathod.cs rename to src/DownKyi.Core/Aria2cNet/Client/Entity/SystemMulticallMathod.cs index 0992681..3c8a71e 100644 --- a/src/Core/aria2cNet/client/entity/SystemMulticallMathod.cs +++ b/src/DownKyi.Core/Aria2cNet/Client/Entity/SystemMulticallMathod.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System.Collections.Generic; -namespace Core.aria2cNet.client.entity +namespace DownKyi.Core.Aria2cNet.Client.Entity { [JsonObject] public class SystemMulticallMathod diff --git a/src/DownKyi.Core/Aria2cNet/Client/HowChangePosition.cs b/src/DownKyi.Core/Aria2cNet/Client/HowChangePosition.cs new file mode 100644 index 0000000..f6246a2 --- /dev/null +++ b/src/DownKyi.Core/Aria2cNet/Client/HowChangePosition.cs @@ -0,0 +1,12 @@ +namespace DownKyi.Core.Aria2cNet.Client +{ + /// + /// changePosition函数的how参数 + /// + public enum HowChangePosition + { + POS_SET = 1, + POS_CUR, + POS_END + } +} diff --git a/src/DownKyi.Core/Aria2cNet/DownloadStatus.cs b/src/DownKyi.Core/Aria2cNet/DownloadStatus.cs new file mode 100644 index 0000000..a8c1d73 --- /dev/null +++ b/src/DownKyi.Core/Aria2cNet/DownloadStatus.cs @@ -0,0 +1,12 @@ +namespace DownKyi.Core.Aria2cNet +{ + /// + /// 下载状态 + /// + public enum DownloadStatus + { + SUCCESS = 1, + FAILED, + ABORT + } +} diff --git a/src/Core/aria2cNet/server/AriaConfig.cs b/src/DownKyi.Core/Aria2cNet/Server/AriaConfig.cs similarity index 78% rename from src/Core/aria2cNet/server/AriaConfig.cs rename to src/DownKyi.Core/Aria2cNet/Server/AriaConfig.cs index 683b718..8afa39d 100644 --- a/src/Core/aria2cNet/server/AriaConfig.cs +++ b/src/DownKyi.Core/Aria2cNet/Server/AriaConfig.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Core.aria2cNet.server +namespace DownKyi.Core.Aria2cNet.Server { /// /// Aria服务器的启动配置 @@ -24,27 +24,4 @@ namespace Core.aria2cNet.server public List Headers { get; set; } } - - /// - /// 日志等级 - /// - public enum AriaConfigLogLevel - { - DEBUG = 1, - INFO, - NOTICE, - WARN, - ERROR - } - - /// - /// 文件预分配 - /// - public enum AriaConfigFileAllocation - { - NONE = 1, // 没有预分配 - PREALLOC, // 预分配,默认 - FALLOC // NTFS建议使用 - } - } diff --git a/src/DownKyi.Core/Aria2cNet/Server/AriaConfigFileAllocation.cs b/src/DownKyi.Core/Aria2cNet/Server/AriaConfigFileAllocation.cs new file mode 100644 index 0000000..e00a9aa --- /dev/null +++ b/src/DownKyi.Core/Aria2cNet/Server/AriaConfigFileAllocation.cs @@ -0,0 +1,12 @@ +namespace DownKyi.Core.Aria2cNet.Server +{ + /// + /// 文件预分配 + /// + public enum AriaConfigFileAllocation + { + NONE = 1, // 没有预分配 + PREALLOC, // 预分配,默认 + FALLOC // NTFS建议使用 + } +} diff --git a/src/DownKyi.Core/Aria2cNet/Server/AriaConfigLogLevel.cs b/src/DownKyi.Core/Aria2cNet/Server/AriaConfigLogLevel.cs new file mode 100644 index 0000000..b1f4620 --- /dev/null +++ b/src/DownKyi.Core/Aria2cNet/Server/AriaConfigLogLevel.cs @@ -0,0 +1,14 @@ +namespace DownKyi.Core.Aria2cNet.Server +{ + /// + /// 日志等级 + /// + public enum AriaConfigLogLevel + { + DEBUG = 1, + INFO, + NOTICE, + WARN, + ERROR + } +} diff --git a/src/Core/aria2cNet/server/AriaServer.cs b/src/DownKyi.Core/Aria2cNet/Server/AriaServer.cs similarity index 91% rename from src/Core/aria2cNet/server/AriaServer.cs rename to src/DownKyi.Core/Aria2cNet/Server/AriaServer.cs index 9ff7fcd..ded9b16 100644 --- a/src/Core/aria2cNet/server/AriaServer.cs +++ b/src/DownKyi.Core/Aria2cNet/Server/AriaServer.cs @@ -1,4 +1,5 @@ -using Core.aria2cNet.client; +using DownKyi.Core.Aria2cNet.Client; +using DownKyi.Core.Logging; using System; using System.Diagnostics; using System.IO; @@ -7,7 +8,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -namespace Core.aria2cNet.server +namespace DownKyi.Core.Aria2cNet.Server { public static class AriaServer { @@ -70,7 +71,8 @@ namespace Core.aria2cNet.server } catch (Exception e) { - Console.WriteLine("StartServerAsync()发生其他异常: {0}", e); + Utils.Debug.Console.PrintLine("StartServerAsync()发生其他异常: {0}", e); + LogManager.Error("AriaServer", e); } } @@ -109,7 +111,9 @@ namespace Core.aria2cNet.server null, (s, e) => { if (e.Data == null || e.Data == "" || e.Data.Replace(" ", "") == "") { return; } - Console.WriteLine(e.Data); + Utils.Debug.Console.PrintLine(e.Data); + LogManager.Debug("AriaServer", e.Data); + if (output != null && window != null) { window.Dispatcher.Invoke(new Action(() => @@ -192,7 +196,8 @@ namespace Core.aria2cNet.server } catch (Exception e) { - Console.WriteLine("KillServer()发生异常: {0}", e); + Utils.Debug.Console.PrintLine("KillServer()发生异常: {0}", e); + LogManager.Error("AriaServer", e); } } return true; @@ -214,7 +219,8 @@ namespace Core.aria2cNet.server p.StartInfo.WorkingDirectory = workingDirectory; } - p.StartInfo.UseShellExecute = false; //输出信息重定向 + // 输出信息重定向 + p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; @@ -226,10 +232,12 @@ namespace Core.aria2cNet.server p.OutputDataReceived += output; p.ErrorDataReceived += output; - p.Start(); //启动线程 + // 启动线程 + p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); - p.WaitForExit(); //等待进程结束 + // 等待进程结束 + p.WaitForExit(); } } diff --git a/src/DownKyi.Core/BiliApi/Bangumi/BangumiInfo.cs b/src/DownKyi.Core/BiliApi/Bangumi/BangumiInfo.cs new file mode 100644 index 0000000..1aca793 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Bangumi/BangumiInfo.cs @@ -0,0 +1,68 @@ +using DownKyi.Core.BiliApi.Bangumi.Models; +using DownKyi.Core.Logging; +using Newtonsoft.Json; +using System; + +namespace DownKyi.Core.BiliApi.Bangumi +{ + public static class BangumiInfo + { + + /// + /// 剧集基本信息(mediaId方式) + /// + /// + /// + public static BangumiMedia BangumiMediaInfo(long mediaId) + { + string url = $"https://api.bilibili.com/pgc/review/user?media_id={mediaId}"; + string referer = "https://www.bilibili.com"; + string response = WebClient.RequestWeb(url, referer); + + try + { + var media = JsonConvert.DeserializeObject(response); + if (media != null && media.Result != null) { return media.Result.Media; } + else { return null; } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("BangumiMediaInfo()发生异常: {0}", e); + LogManager.Error("BangumiInfo", e); + return null; + } + } + + /// + /// 获取剧集明细(web端)(seasonId/episodeId方式) + /// + /// + /// + /// + public static BangumiSeason BangumiSeasonInfo(long seasonId = -1, long episodeId = -1) + { + string baseUrl = "https://api.bilibili.com/pgc/view/web/season"; + string referer = "https://www.bilibili.com"; + string url; + if (seasonId > -1) { url = $"{baseUrl}?season_id={seasonId}"; } + else if (episodeId > -1) { url = $"{baseUrl}?ep_id={episodeId}"; } + else { return null; } + + string response = WebClient.RequestWeb(url, referer); + + try + { + var bangumiSeason = JsonConvert.DeserializeObject(response); + if (bangumiSeason != null) { return bangumiSeason.Result; } + else { return null; } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("BangumiSeasonInfo()发生异常: {0}", e); + LogManager.Error("BangumiInfo", e); + return null; + } + } + + } +} diff --git a/src/DownKyi.Core/BiliApi/Bangumi/BangumiType.cs b/src/DownKyi.Core/BiliApi/Bangumi/BangumiType.cs new file mode 100644 index 0000000..fae5abc --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Bangumi/BangumiType.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Bangumi +{ + public static class BangumiType + { + public static Dictionary Type = new Dictionary() + { + { 1, "Anime" }, + { 2, "Movie" }, + { 3, "Documentary" }, + { 4, "Guochuang" }, + { 5, "TV" }, + { 6, "Unknown" }, + { 7, "Entertainment" }, + { 8, "Unknown" }, + { 9, "Unknown" }, + { 10, "Unknown" } + }; + + } +} diff --git a/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiArea.cs b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiArea.cs new file mode 100644 index 0000000..4ce21b6 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiArea.cs @@ -0,0 +1,13 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Bangumi.Models +{ + public class BangumiArea : BaseModel + { + [JsonProperty("id")] + public int Id { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiEpisode.cs b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiEpisode.cs new file mode 100644 index 0000000..4cee71e --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiEpisode.cs @@ -0,0 +1,53 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Bangumi.Models +{ + public class BangumiEpisode : BaseModel + { + [JsonProperty("aid")] + public long Aid { get; set; } + [JsonProperty("badge")] + public string Badge { get; set; } + // badge_info + // badge_type + [JsonProperty("bvid")] + public string Bvid { get; set; } + [JsonProperty("cid")] + public long Cid { get; set; } + [JsonProperty("cover")] + public string Cover { get; set; } + [JsonProperty("dimension")] + public Dimension Dimension { get; set; } + [JsonProperty("duration")] + public long Duration { get; set; } + [JsonProperty("from")] + public string From { get; set; } + [JsonProperty("id")] + public long Id { get; set; } + [JsonProperty("link")] + public string Link { get; set; } + [JsonProperty("long_title")] + public string LongTitle { get; set; } + [JsonProperty("pub_time")] + public long PubTime { get; set; } + // pv + // release_date + // rights + [JsonProperty("share_copy")] + public string ShareCopy { get; set; } + [JsonProperty("share_url")] + public string ShareUrl { get; set; } + [JsonProperty("short_link")] + public string ShortLink { get; set; } + // stat + [JsonProperty("status")] + public int Status { get; set; } + [JsonProperty("subtitle")] + public string Subtitle { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("vid")] + public string Vid { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiMedia.cs b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiMedia.cs new file mode 100644 index 0000000..d22667c --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiMedia.cs @@ -0,0 +1,46 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Bangumi.Models +{ + // https://api.bilibili.com/pgc/review/user + public class BangumiMediaOrigin : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + //[JsonProperty("ttl")] + //public int Ttl { get; set; } + [JsonProperty("result")] + public BangumiMediaData Result { get; set; } + } + + public class BangumiMediaData : BaseModel + { + [JsonProperty("media")] + public BangumiMedia Media { get; set; } + } + + public class BangumiMedia : BaseModel + { + [JsonProperty("areas")] + public List Areas { get; set; } + [JsonProperty("cover")] + public string Cover { get; set; } + [JsonProperty("media_id")] + public long MediaId { get; set; } + // new_ep + // rating + [JsonProperty("season_id")] + public long SeasonId { get; set; } + [JsonProperty("share_url")] + public string ShareUrl { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("type_name")] + public string TypeName { get; set; } + } + +} diff --git a/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiPositive.cs b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiPositive.cs new file mode 100644 index 0000000..acbfd2c --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiPositive.cs @@ -0,0 +1,13 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Bangumi.Models +{ + public class BangumiPositive : BaseModel + { + [JsonProperty("id")] + public long Id { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSeason.cs b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSeason.cs new file mode 100644 index 0000000..87d3dcf --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSeason.cs @@ -0,0 +1,79 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Bangumi.Models +{ + // https://api.bilibili.com/pgc/view/web/season + public class BangumiSeasonOrigin : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + //[JsonProperty("ttl")] + //public int Ttl { get; set; } + [JsonProperty("result")] + public BangumiSeason Result { get; set; } + } + + public class BangumiSeason : BaseModel + { + // activity + // alias + [JsonProperty("areas")] + public List Areas { get; set; } + [JsonProperty("bkg_cover")] + public string BkgCover { get; set; } + [JsonProperty("cover")] + public string Cover { get; set; } + [JsonProperty("episodes")] + public List Episodes { get; set; } + [JsonProperty("evaluate")] + public string Evaluate { get; set; } + // freya + // jp_title + [JsonProperty("link")] + public string Link { get; set; } + [JsonProperty("media_id")] + public long MediaId { get; set; } + // mode + // new_ep + // payment + [JsonProperty("positive")] + public BangumiPositive Positive { get; set; } + // publish + // rating + // record + // rights + [JsonProperty("season_id")] + public long SeasonId { get; set; } + [JsonProperty("season_title")] + public string SeasonTitle { get; set; } + [JsonProperty("seasons")] + public List Seasons { get; set; } + [JsonProperty("section")] + public List Section { get; set; } + // series + // share_copy + // share_sub_title + // share_url + // show + [JsonProperty("square_cover")] + public string SquareCover { get; set; } + [JsonProperty("stat")] + public BangumiStat Stat { get; set; } + // status + [JsonProperty("subtitle")] + public string Subtitle { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("total")] + public int Total { get; set; } + [JsonProperty("type")] + public int Type { get; set; } + [JsonProperty("up_info")] + public BangumiUpInfo UpInfo { get; set; } + } + +} diff --git a/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSeasonInfo.cs b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSeasonInfo.cs new file mode 100644 index 0000000..2adaf55 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSeasonInfo.cs @@ -0,0 +1,25 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Bangumi.Models +{ + public class BangumiSeasonInfo : BaseModel + { + [JsonProperty("badge")] + public string Badge { get; set; } + // badge_info + // badge_type + [JsonProperty("cover")] + public string Cover { get; set; } + [JsonProperty("media_id")] + public long MediaId { get; set; } + // new_ep + [JsonProperty("season_id")] + public long SeasonId { get; set; } + [JsonProperty("season_title")] + public string SeasonTitle { get; set; } + [JsonProperty("season_type")] + public int SeasonType { get; set; } + // stat + } +} diff --git a/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSection.cs b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSection.cs new file mode 100644 index 0000000..e416938 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiSection.cs @@ -0,0 +1,20 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Bangumi.Models +{ + public class BangumiSection : BaseModel + { + [JsonProperty("episode_id")] + public long EpisodeId { get; set; } + [JsonProperty("episodes")] + public List Episodes { get; set; } + [JsonProperty("id")] + public long Id { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("type")] + public int Type { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiStat.cs b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiStat.cs new file mode 100644 index 0000000..fac010d --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiStat.cs @@ -0,0 +1,25 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Bangumi.Models +{ + public class BangumiStat : BaseModel + { + [JsonProperty("coins")] + public long Coins { get; set; } + [JsonProperty("danmakus")] + public long Danmakus { get; set; } + [JsonProperty("favorite")] + public long Favorite { get; set; } + [JsonProperty("favorites")] + public long Favorites { get; set; } + [JsonProperty("likes")] + public long Likes { get; set; } + [JsonProperty("reply")] + public long Reply { get; set; } + [JsonProperty("share")] + public long Share { get; set; } + [JsonProperty("views")] + public long Views { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiUpInfo.cs b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiUpInfo.cs new file mode 100644 index 0000000..b7b8638 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Bangumi/Models/BangumiUpInfo.cs @@ -0,0 +1,22 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Bangumi.Models +{ + public class BangumiUpInfo : BaseModel + { + [JsonProperty("avatar")] + public string Avatar { get; set; } + // follower + // is_follow + [JsonProperty("mid")] + public long Mid { get; set; } + // pendant + // theme_type + [JsonProperty("uname")] + public string Name { get; set; } + // verify_type + // vip_status + // vip_type + } +} diff --git a/src/Core/api/utils/BvId.cs b/src/DownKyi.Core/BiliApi/BiliUtils/BvId.cs similarity index 97% rename from src/Core/api/utils/BvId.cs rename to src/DownKyi.Core/BiliApi/BiliUtils/BvId.cs index 3fcaad4..665bc50 100644 --- a/src/Core/api/utils/BvId.cs +++ b/src/DownKyi.Core/BiliApi/BiliUtils/BvId.cs @@ -1,6 +1,6 @@ using System; -namespace Core.api.utils +namespace DownKyi.Core.BiliApi.BiliUtils { public static class BvId { diff --git a/src/DownKyi.Core/BiliApi/BiliUtils/Constant.cs b/src/DownKyi.Core/BiliApi/BiliUtils/Constant.cs new file mode 100644 index 0000000..7b0ce8a --- /dev/null +++ b/src/DownKyi.Core/BiliApi/BiliUtils/Constant.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.BiliUtils +{ + public static class Constant + { + /// + /// 音质id及含义 + /// + public static Dictionary AudioQuality { get; } = new Dictionary() + { + { 30216, "64K" }, + { 30232, "132K" }, + { 30280, "192K" } + }; + + } +} diff --git a/src/Core/api/utils/DanmakuSender.cs b/src/DownKyi.Core/BiliApi/BiliUtils/DanmakuSender.cs similarity index 95% rename from src/Core/api/utils/DanmakuSender.cs rename to src/DownKyi.Core/BiliApi/BiliUtils/DanmakuSender.cs index 4801c74..9404f22 100644 --- a/src/Core/api/utils/DanmakuSender.cs +++ b/src/DownKyi.Core/BiliApi/BiliUtils/DanmakuSender.cs @@ -1,6 +1,6 @@ using System; -namespace Core.api.utils +namespace DownKyi.Core.BiliApi.BiliUtils { public static class DanmakuSender { @@ -111,6 +111,11 @@ namespace Core.api.utils return resultArray; } + /// + /// 查询弹幕发送者 + /// + /// + /// public static string FindDanmakuSender(string userId) { object[] deepCheckData = new object[2]; diff --git a/src/DownKyi.Core/BiliApi/BiliUtils/ParseEntrance.cs b/src/DownKyi.Core/BiliApi/BiliUtils/ParseEntrance.cs new file mode 100644 index 0000000..a499745 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/BiliUtils/ParseEntrance.cs @@ -0,0 +1,455 @@ +using DownKyi.Core.Utils.Validator; +using System.Text.RegularExpressions; + +namespace DownKyi.Core.BiliApi.BiliUtils +{ + /// + /// 解析输入的字符串 + /// 支持的格式有: + /// av号:av170001, AV170001, https://www.bilibili.com/video/av170001 + /// BV号:BV17x411w7KC, https://www.bilibili.com/video/BV17x411w7KC + /// 番剧(电影、电视剧)ss号:ss32982, SS32982, https://www.bilibili.com/bangumi/play/ss32982 + /// 番剧(电影、电视剧)ep号:ep317925, EP317925, https://www.bilibili.com/bangumi/play/ep317925 + /// 番剧(电影、电视剧)md号:md28228367, MD28228367, https://www.bilibili.com/bangumi/media/md28228367 + /// 课程ss号:https://www.bilibili.com/cheese/play/ss205 + /// 课程ep号:https://www.bilibili.com/cheese/play/ep3489 + /// 用户空间:uid928123, UID928123, uid:928123, UID:928123, https://space.bilibili.com/928123 + /// + public static class ParseEntrance + { + public static readonly string WwwUrl = "https://www.bilibili.com"; + public static readonly string MobileUrl = "https://m.bilibili.com"; + public static readonly string SpaceUrl = "https://space.bilibili.com"; + + public static readonly string VideoUrl = $"{WwwUrl}/video/"; + public static readonly string BangumiUrl = $"{WwwUrl}/bangumi/play/"; + public static readonly string BangumiMediaUrl = $"{WwwUrl}/bangumi/media/"; + public static readonly string CheeseUrl = $"{WwwUrl}/cheese/play/"; + + #region 视频 + + /// + /// 是否为av id + /// + /// + /// + public static bool IsAvId(string input) + { + return IsIntId(input, "av"); + } + + /// + /// 是否为av url + /// + /// + /// + public static bool IsAvUrl(string input) + { + string id = GetVideoId(input); + return IsAvId(id); + } + + /// + /// 获取av id + /// + /// + /// + public static long GetAvId(string input) + { + if (IsAvId(input)) + { + return Number.GetInt(input.Remove(0, 2)); + } + else if (IsAvUrl(input)) + { + return Number.GetInt(GetVideoId(input).Remove(0, 2)); + } + else + { + return -1; + } + } + + /// + /// 是否为bv id + /// + /// + /// + public static bool IsBvId(string input) + { + return input.StartsWith("BV") && input.Length == 12; + } + + /// + /// 是否为bv url + /// + /// + /// + public static bool IsBvUrl(string input) + { + string id = GetVideoId(input); + return IsBvId(id); + } + + /// + /// 获取bv id + /// + /// + /// + public static string GetBvId(string input) + { + if (IsBvId(input)) + { + return input; + } + else if (IsBvUrl(input)) + { + return GetVideoId(input); + } + else + { + return ""; + } + } + + #endregion + + #region 番剧(电影、电视剧) + + /// + /// 是否为番剧season id + /// + /// + /// + public static bool IsBangumiSeasonId(string input) + { + return IsIntId(input, "ss"); + } + + /// + /// 是否为番剧season url + /// + /// + /// + public static bool IsBangumiSeasonUrl(string input) + { + string id = GetBangumiId(input); + return IsBangumiSeasonId(id); + } + + /// + /// 获取番剧season id + /// + /// + /// + public static long GetBangumiSeasonId(string input) + { + if (IsBangumiSeasonId(input)) + { + return Number.GetInt(input.Remove(0, 2)); + } + else if (IsBangumiSeasonUrl(input)) + { + return Number.GetInt(GetBangumiId(input).Remove(0, 2)); + } + else + { + return -1; + } + } + + /// + /// 是否为番剧episode id + /// + /// + /// + public static bool IsBangumiEpisodeId(string input) + { + return IsIntId(input, "ep"); + } + + /// + /// 是否为番剧episode url + /// + /// + /// + public static bool IsBangumiEpisodeUrl(string input) + { + string id = GetBangumiId(input); + return IsBangumiEpisodeId(id); + } + + /// + /// 获取番剧episode id + /// + /// + /// + public static long GetBangumiEpisodeId(string input) + { + if (IsBangumiEpisodeId(input)) + { + return Number.GetInt(input.Remove(0, 2)); + } + else if (IsBangumiEpisodeUrl(input)) + { + return Number.GetInt(GetBangumiId(input).Remove(0, 2)); + } + else + { + return -1; + } + } + + /// + /// 是否为番剧media id + /// + /// + /// + public static bool IsBangumiMediaId(string input) + { + return IsIntId(input, "md"); + } + + /// + /// 是否为番剧media url + /// + /// + /// + public static bool IsBangumiMediaUrl(string input) + { + string id = GetBangumiId(input); + return IsBangumiMediaId(id); + } + + /// + /// 获取番剧media id + /// + /// + /// + public static long GetBangumiMediaId(string input) + { + if (IsBangumiMediaId(input)) + { + return Number.GetInt(input.Remove(0, 2)); + } + else if (IsBangumiMediaUrl(input)) + { + return Number.GetInt(GetBangumiId(input).Remove(0, 2)); + } + else + { + return -1; + } + } + + #endregion + + #region 课程 + + /// + /// 是否为课程season url + /// + /// + /// + public static bool IsCheeseSeasonUrl(string input) + { + string id = GetCheeseId(input); + return IsIntId(id, "ss"); + } + + /// + /// 获取课程season id + /// + /// + /// + public static long GetCheeseSeasonId(string input) + { + return IsCheeseSeasonUrl(input) ? Number.GetInt(GetCheeseId(input).Remove(0, 2)) : -1; + } + + /// + /// 是否为课程episode url + /// + /// + /// + public static bool IsCheeseEpisodeUrl(string input) + { + string id = GetCheeseId(input); + return IsIntId(id, "ep"); + } + + /// + /// 获取课程episode id + /// + /// + /// + public static long GetCheeseEpisodeId(string input) + { + return IsCheeseEpisodeUrl(input) ? Number.GetInt(GetCheeseId(input).Remove(0, 2)) : -1; + } + + #endregion + + #region 用户空间 + + /// + /// 是否为用户id + /// + /// + /// + public static bool IsUserId(string input) + { + if (input.ToLower().StartsWith("uid:")) + { + return Regex.IsMatch(input.Remove(0, 4), @"^\d+$"); + } + else if (input.ToLower().StartsWith("uid")) + { + return Regex.IsMatch(input.Remove(0, 3), @"^\d+$"); + } + else { return false; } + } + + /// + /// 是否为用户空间url + /// + /// + /// + public static bool IsUserUrl(string input) + { + string baseUrl = $"{SpaceUrl}/"; + string id = GetId(input, baseUrl); + return Number.IsInt(id); + } + + /// + /// 获取用户mid + /// + /// + /// + public static long GetUserId(string input) + { + if (input.ToLower().StartsWith("uid:")) + { + return Number.GetInt(input.Remove(0, 4)); + } + else if (input.ToLower().StartsWith("uid")) + { + return Number.GetInt(input.Remove(0, 3)); + } + else if (IsUserUrl(input)) + { + string baseUrl = $"{SpaceUrl}/"; + string id = GetId(input, baseUrl); + return Number.GetInt(id); + } + else + { + return -1; + } + } + + #endregion + + /// + /// 是否为网址 + /// + /// + /// + private static bool IsUrl(string input) + { + return input.StartsWith("http://") || input.StartsWith("https://"); + } + + /// + /// 将http转为https + /// + /// + private static string EnableHttps(string url) + { + if (!IsUrl(url)) { return null; } + + return url.Replace("http://", "https://"); + } + + /// + /// 去除url中的参数 + /// + /// + /// + private static string DeleteUrlParam(string url) + { + string[] strList = url.Split('?'); + + return strList[0].EndsWith("/") ? strList[0].TrimEnd('/') : strList[0]; + } + + /// + /// 从url中获取视频id(avid/bvid) + /// + /// + /// + private static string GetVideoId(string input) + { + return GetId(input, VideoUrl); + } + + /// + /// 从url中获取番剧id(ss/ep/md) + /// + /// + /// + private static string GetBangumiId(string input) + { + string id = GetId(input, BangumiUrl); + if (id != "") { return id; } + return GetId(input, BangumiMediaUrl); + } + + /// + /// 从url中获取课程id(ss/ep) + /// + /// + /// + private static string GetCheeseId(string input) + { + return GetId(input, CheeseUrl); + } + + /// + /// 是否为数字型id + /// + /// + /// + /// + private static bool IsIntId(string input, string prefix) + { + if (input.ToLower().StartsWith(prefix)) + { + return Regex.IsMatch(input.Remove(0, 2), @"^\d+$"); + } + return false; + } + + /// + /// 从url中获取id + /// + /// + /// + /// + private static string GetId(string input, string baseUrl) + { + if (!IsUrl(input)) { return ""; } + + string url = EnableHttps(input); + url = DeleteUrlParam(url); + + url = url.Replace(MobileUrl, WwwUrl); + + if (!url.StartsWith(baseUrl)) { return ""; } + + return url.Replace(baseUrl, ""); + } + + } +} diff --git a/src/DownKyi.Core/BiliApi/Cheese/CheeseInfo.cs b/src/DownKyi.Core/BiliApi/Cheese/CheeseInfo.cs new file mode 100644 index 0000000..1393d5a --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Cheese/CheeseInfo.cs @@ -0,0 +1,70 @@ +using DownKyi.Core.BiliApi.Cheese.Models; +using DownKyi.Core.Logging; +using Newtonsoft.Json; +using System; + +namespace DownKyi.Core.BiliApi.Cheese +{ + public static class CheeseInfo + { + + /// + /// 获取课程基本信息 + /// + /// + /// + /// + public static CheeseView CheeseViewInfo(long seasonId = -1, long episodeId = -1) + { + string baseUrl = "https://api.bilibili.com/pugv/view/web/season"; + string referer = "https://www.bilibili.com"; + string url; + if (seasonId > -1) { url = $"{baseUrl}?season_id={seasonId}"; } + else if (episodeId > -1) { url = $"{baseUrl}?ep_id={episodeId}"; } + else { return null; } + + string response = WebClient.RequestWeb(url, referer); + + try + { + var cheese = JsonConvert.DeserializeObject(response); + if (cheese != null) { return cheese.Data; } + else { return null; } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("CheeseViewInfo()发生异常: {0}", e); + LogManager.Error("CheeseInfo", e); + return null; + } + } + + /// + /// 获取课程分集列表 + /// + /// + /// + /// + /// + public static CheeseEpisodeList CheeseEpisodeList(long seasonId, int ps = 50, int pn = 1) + { + string url = $"https://api.bilibili.com/pugv/view/web/ep/list?season_id={seasonId}&pn={pn}&ps={ps}"; + string referer = "https://www.bilibili.com"; + string response = WebClient.RequestWeb(url, referer); + + try + { + var cheese = JsonConvert.DeserializeObject(response); + if (cheese != null) { return cheese.Data; } + else { return null; } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("CheeseEpisodeList()发生异常: {0}", e); + LogManager.Error("CheeseInfo", e); + return null; + } + } + + } +} diff --git a/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseBrief.cs b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseBrief.cs new file mode 100644 index 0000000..2b0159a --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseBrief.cs @@ -0,0 +1,17 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Cheese.Models +{ + public class CheeseBrief : BaseModel + { + // content + [JsonProperty("img")] + public List Img { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("type")] + public int Type { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisode.cs b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisode.cs new file mode 100644 index 0000000..5643e3d --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisode.cs @@ -0,0 +1,43 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Cheese.Models +{ + public class CheeseEpisode : BaseModel + { + [JsonProperty("aid")] + public long Aid { get; set; } + [JsonProperty("catalogue_index")] + public int CatalogueIndex { get; set; } + [JsonProperty("cid")] + public long Cid { get; set; } + [JsonProperty("cover")] + public string Cover { get; set; } + [JsonProperty("duration")] + public long Duration { get; set; } + [JsonProperty("from")] + public string From { get; set; } + [JsonProperty("id")] + public long Id { get; set; } + [JsonProperty("index")] + public int Index { get; set; } + [JsonProperty("page")] + public int Page { get; set; } + [JsonProperty("play")] + public long Play { get; set; } + [JsonProperty("play_way")] + public int PlayWay { get; set; } + [JsonProperty("play_way_format")] + public string PlayWayFormat { get; set; } + [JsonProperty("release_date")] + public long ReleaseDate { get; set; } + [JsonProperty("status")] + public int Status { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("watched")] + public bool Watched { get; set; } + [JsonProperty("watchedHistory")] + public int WatchedHistory { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisodeList.cs b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisodeList.cs new file mode 100644 index 0000000..aebc4c5 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisodeList.cs @@ -0,0 +1,26 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Cheese.Models +{ + // https://api.bilibili.com/pugv/view/web/ep/list + public class CheeseEpisodeListOrigin : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + [JsonProperty("data")] + public CheeseEpisodeList Data { get; set; } + } + + public class CheeseEpisodeList : BaseModel + { + [JsonProperty("items")] + public List Items { get; set; } + [JsonProperty("page")] + public CheeseEpisodePage Page { get; set; } + } + +} diff --git a/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisodePage.cs b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisodePage.cs new file mode 100644 index 0000000..d3145a3 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseEpisodePage.cs @@ -0,0 +1,17 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Cheese.Models +{ + public class CheeseEpisodePage : BaseModel + { + [JsonProperty("next")] + public bool Next { get; set; } + [JsonProperty("num")] + public int Num { get; set; } + [JsonProperty("size")] + public int Size { get; set; } + [JsonProperty("total")] + public int Total { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseImg.cs b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseImg.cs new file mode 100644 index 0000000..12a1fa1 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseImg.cs @@ -0,0 +1,13 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Cheese.Models +{ + public class CheeseImg : BaseModel + { + [JsonProperty("aspect_ratio")] + public double AspectRatio { get; set; } + [JsonProperty("url")] + public string Url { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseStat.cs b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseStat.cs new file mode 100644 index 0000000..226a41e --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseStat.cs @@ -0,0 +1,13 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Cheese.Models +{ + public class CheeseStat : BaseModel + { + [JsonProperty("play")] + public long Play { get; set; } + [JsonProperty("play_desc")] + public string PlayDesc { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseUpInfo.cs b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseUpInfo.cs new file mode 100644 index 0000000..f1a8da8 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseUpInfo.cs @@ -0,0 +1,23 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Cheese.Models +{ + public class CheeseUpInfo : BaseModel + { + [JsonProperty("avatar")] + public string Avatar { get; set; } + [JsonProperty("brief")] + public string Brief { get; set; } + [JsonProperty("follower")] + public long Follower { get; set; } + [JsonProperty("is_follow")] + public int IsFollow { get; set; } + [JsonProperty("link")] + public string Link { get; set; } + [JsonProperty("mid")] + public long Mid { get; set; } + [JsonProperty("uname")] + public string Name { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseView.cs b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseView.cs new file mode 100644 index 0000000..a6349a3 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Cheese/Models/CheeseView.cs @@ -0,0 +1,69 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Cheese.Models +{ + // https://api.bilibili.com/pugv/view/web/season + public class CheeseViewOrigin : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + [JsonProperty("data")] + public CheeseView Data { get; set; } + } + + public class CheeseView : BaseModel + { + // active_market + // activity_list + [JsonProperty("brief")] + public CheeseBrief Brief { get; set; } + // cooperation + // coupon + // course_content + // courses + [JsonProperty("cover")] + public string Cover { get; set; } + // ep_catalogue + // ep_count + // episode_page + // episode_sort + // episode_tag + [JsonProperty("episodes")] + public List Episodes { get; set; } + // faq + // faq1 + // live_ep_count + // opened_ep_count + // payment + // previewed_purchase_note + // purchase_format_note + // purchase_note + // purchase_protocol + // recommend_seasons 推荐课程 + // release_bottom_info + // release_info + // release_info2 + // release_status + [JsonProperty("season_id")] + public long SeasonId { get; set; } + [JsonProperty("share_url")] + public string ShareUrl { get; set; } + // short_link + [JsonProperty("stat")] + public CheeseStat Stat { get; set; } + // status + [JsonProperty("subtitle")] + public string Subtitle { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("up_info")] + public CheeseUpInfo UpInfo { get; set; } + // update_status + // user_status + } + +} diff --git a/src/DownKyi.Core/BiliApi/Login/LoginHelper.cs b/src/DownKyi.Core/BiliApi/Login/LoginHelper.cs new file mode 100644 index 0000000..342c893 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Login/LoginHelper.cs @@ -0,0 +1,147 @@ +using DownKyi.Core.Settings; +using DownKyi.Core.Settings.Models; +using DownKyi.Core.Utils; +using DownKyi.Core.Utils.Encryptor; +using System; +using System.IO; +using System.Net; + +namespace DownKyi.Core.BiliApi.Login +{ + public static class LoginHelper + { + // 本地位置 + private static readonly string LOCAL_LOGIN_INFO = Storage.StorageManager.GetLogin(); + + // 16位密码,ps:密码位数没有限制,可任意设置 + private static readonly string SecretKey = "EsOat*^y1QR!&0J6"; + + /// + /// 保存登录的cookies到文件 + /// + /// + /// + public static bool SaveLoginInfoCookies(string url) + { + string tempFile = LOCAL_LOGIN_INFO + "-" + Guid.NewGuid().ToString("N"); + CookieContainer cookieContainer = ObjectHelper.ParseCookie(url); + + bool isSucceed = ObjectHelper.WriteCookiesToDisk(tempFile, cookieContainer); + if (isSucceed) + { + // 加密密钥,增加机器码 + string password = SecretKey + MachineCode.GetMachineCodeString(); + + try + { + Encryptor.EncryptFile(tempFile, LOCAL_LOGIN_INFO, password); + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("SaveLoginInfoCookies()发生异常: {0}", e); + Logging.LogManager.Error(e); + return false; + } + } + + if (File.Exists(tempFile)) + { + File.Delete(tempFile); + } + return isSucceed; + } + + + /// + /// 获得登录的cookies + /// + /// + public static CookieContainer GetLoginInfoCookies() + { + string tempFile = LOCAL_LOGIN_INFO + "-" + Guid.NewGuid().ToString("N"); + + if (File.Exists(LOCAL_LOGIN_INFO)) + { + try + { + // 加密密钥,增加机器码 + string password = SecretKey + MachineCode.GetMachineCodeString(); + Encryptor.DecryptFile(LOCAL_LOGIN_INFO, tempFile, password); + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("GetLoginInfoCookies()发生异常: {0}", e); + Logging.LogManager.Error(e); + if (File.Exists(tempFile)) + { + File.Delete(tempFile); + } + return null; + } + } + else { return null; } + + CookieContainer cookies = ObjectHelper.ReadCookiesFromDisk(tempFile); + + if (File.Exists(tempFile)) + { + File.Delete(tempFile); + } + return cookies; + } + + /// + /// 返回登录信息的cookies的字符串 + /// + /// + public static string GetLoginInfoCookiesString() + { + var cookieContainer = GetLoginInfoCookies(); + if (cookieContainer == null) + { + return ""; + } + + var cookies = ObjectHelper.GetAllCookies(cookieContainer); + + string cookie = string.Empty; + foreach (var item in cookies) + { + cookie += item.ToString() + ";"; + } + return cookie.TrimEnd(';'); + } + + /// + /// 注销登录 + /// + /// + public static bool Logout() + { + if (File.Exists(LOCAL_LOGIN_INFO)) + { + try + { + File.Delete(LOCAL_LOGIN_INFO); + + SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings + { + Mid = -1, + Name = "", + IsLogin = false, + IsVip = false + }); + return true; + } + catch (IOException e) + { + Utils.Debug.Console.PrintLine("Logout()发生异常: {0}", e); + Logging.LogManager.Error(e); + return false; + } + } + return false; + } + + } +} diff --git a/src/Core/api/login/LoginInfo.cs b/src/DownKyi.Core/BiliApi/Login/LoginInfo.cs similarity index 50% rename from src/Core/api/login/LoginInfo.cs rename to src/DownKyi.Core/BiliApi/Login/LoginInfo.cs index 65dab40..2931f0c 100644 --- a/src/Core/api/login/LoginInfo.cs +++ b/src/DownKyi.Core/BiliApi/Login/LoginInfo.cs @@ -1,43 +1,25 @@ -using Core.entity2.login; +using DownKyi.Core.BiliApi.Login.Models; +using DownKyi.Core.Logging; using Newtonsoft.Json; using System; -namespace Core.api.login +namespace DownKyi.Core.BiliApi.Login { /// /// 登录基本信息 /// - public class LoginInfo + public static class LoginInfo { - private static LoginInfo instance; - - /// - /// 获取UserInfo实例 - /// - /// - public static LoginInfo GetInstance() - { - if (instance == null) - { - instance = new LoginInfo(); - } - return instance; - } - - /// - /// 隐藏LoginInfo()方法,必须使用单例模式 - /// - private LoginInfo() { } /// /// 导航栏用户信息 /// /// - public UserInfoForNavigation GetUserInfoForNavigation() + public static UserInfoForNavigation GetUserInfoForNavigation() { string url = "https://api.bilibili.com/x/web-interface/nav"; string referer = "https://www.bilibili.com"; - string response = Utils.RequestWeb(url, referer); + string response = WebClient.RequestWeb(url, referer); try { @@ -49,10 +31,10 @@ namespace Core.api.login } catch (Exception e) { - Console.WriteLine("GetUserInfoForNavigation()发生异常: {0}", e); + Utils.Debug.Console.PrintLine("GetUserInfoForNavigation()发生异常: {0}", e); + LogManager.Error("LoginInfo", e); return null; } } - } } diff --git a/src/Core/api/login/Login.cs b/src/DownKyi.Core/BiliApi/Login/LoginQR.cs similarity index 55% rename from src/Core/api/login/Login.cs rename to src/DownKyi.Core/BiliApi/Login/LoginQR.cs index 114ff90..1ad3544 100644 --- a/src/Core/api/login/Login.cs +++ b/src/DownKyi.Core/BiliApi/Login/LoginQR.cs @@ -1,41 +1,28 @@ -using Core.entity2.login; +using DownKyi.Core.BiliApi.Login.Models; +using DownKyi.Core.Logging; using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Windows.Media.Imaging; -namespace Core.api.login +namespace DownKyi.Core.BiliApi.Login { - public class Login + /// + /// 二维码登录 + /// + public static class LoginQR { - private static Login instance; - - /// - /// 获取Login实例 - /// - /// - public static Login GetInstance() - { - if (instance == null) - { - instance = new Login(); - } - return instance; - } - - /// - /// 隐藏Login()方法,必须使用单例模式 - /// - private Login() { } - /// /// 申请二维码URL及扫码密钥(web端) /// /// - public LoginUrlOrigin GetLoginUrl() + public static LoginUrlOrigin GetLoginUrl() { string getLoginUrl = "https://passport.bilibili.com/qrcode/getLoginUrl"; string referer = "https://passport.bilibili.com/login"; - string response = Utils.RequestWeb(getLoginUrl, referer); + string response = WebClient.RequestWeb(getLoginUrl, referer); try { @@ -44,7 +31,8 @@ namespace Core.api.login } catch (Exception e) { - Console.WriteLine("GetLoginUrl()发生异常: {0}", e); + Utils.Debug.Console.PrintLine("GetLoginUrl()发生异常: {0}", e); + LogManager.Error("LoginQR", e); return null; } } @@ -55,7 +43,7 @@ namespace Core.api.login /// /// /// - public LoginStatus GetLoginStatus(string oauthKey, string goUrl = "https://www.bilibili.com") + public static LoginStatus GetLoginStatus(string oauthKey, string goUrl = "https://www.bilibili.com") { string url = "https://passport.bilibili.com/qrcode/getLoginInfo"; string referer = "https://passport.bilibili.com/login"; @@ -66,7 +54,7 @@ namespace Core.api.login { "gourl", goUrl } }; - string response = Utils.RequestWeb(url, referer, "POST", parameters); + string response = WebClient.RequestWeb(url, referer, "POST", parameters); var loginInfo = new LoginStatus(); try @@ -98,10 +86,53 @@ namespace Core.api.login } catch (Exception e) { - Console.WriteLine("GetLoginInfo()发生异常: {0}", e); + Utils.Debug.Console.PrintLine("GetLoginInfo()发生异常: {0}", e); + LogManager.Error("LoginQR", e); + return null; + } + } + + + /// + /// 获得登录二维码 + /// + /// + public static BitmapImage GetLoginQRCode() + { + try + { + string loginUrl = GetLoginUrl().Data.Url; + return GetLoginQRCode(loginUrl); + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("GetLoginQRCode()发生异常: {0}", e); + LogManager.Error("LoginQR", e); return null; } } + /// + /// 根据输入url生成二维码 + /// + /// + /// + public static BitmapImage GetLoginQRCode(string url) + { + // 设置的参数影响app能否成功扫码 + Bitmap qrCode = Utils.QRCode.EncodeQRCode(url, 10, 10, null, 0, 0, false); + + MemoryStream ms = new MemoryStream(); + qrCode.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); + byte[] bytes = ms.GetBuffer(); + ms.Close(); + + BitmapImage image = new BitmapImage(); + image.BeginInit(); + image.StreamSource = new MemoryStream(bytes); + image.EndInit(); + return image; + } + } } diff --git a/src/Core/entity2/login/LoginStatus.cs b/src/DownKyi.Core/BiliApi/Login/Models/LoginStatus.cs similarity index 78% rename from src/Core/entity2/login/LoginStatus.cs rename to src/DownKyi.Core/BiliApi/Login/Models/LoginStatus.cs index 4274f0a..2d6a599 100644 --- a/src/Core/entity2/login/LoginStatus.cs +++ b/src/DownKyi.Core/BiliApi/Login/Models/LoginStatus.cs @@ -1,10 +1,11 @@ -using Newtonsoft.Json; +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; -namespace Core.entity2.login +namespace DownKyi.Core.BiliApi.Login.Models { // https://passport.bilibili.com/qrcode/getLoginInfo [JsonObject] - public class LoginStatus : BaseEntity + public class LoginStatus : BaseModel { [JsonProperty("code")] public int Code { get; set; } @@ -17,7 +18,7 @@ namespace Core.entity2.login } [JsonObject] - public class LoginStatusScanning : BaseEntity + public class LoginStatusScanning : BaseModel { [JsonProperty("status")] public bool Status { get; set; } @@ -28,7 +29,7 @@ namespace Core.entity2.login } [JsonObject] - public class LoginStatusReady : BaseEntity + public class LoginStatusReady : BaseModel { [JsonProperty("code")] public int Code { get; set; } @@ -40,10 +41,9 @@ namespace Core.entity2.login } [JsonObject] - public class LoginStatusData : BaseEntity + public class LoginStatusData : BaseModel { [JsonProperty("url")] public string Url { get; set; } } - } diff --git a/src/Core/entity2/login/LoginUrl.cs b/src/DownKyi.Core/BiliApi/Login/Models/LoginUrl.cs similarity index 72% rename from src/Core/entity2/login/LoginUrl.cs rename to src/DownKyi.Core/BiliApi/Login/Models/LoginUrl.cs index 2f8ac90..f494a78 100644 --- a/src/Core/entity2/login/LoginUrl.cs +++ b/src/DownKyi.Core/BiliApi/Login/Models/LoginUrl.cs @@ -1,10 +1,11 @@ -using Newtonsoft.Json; +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; -namespace Core.entity2.login +namespace DownKyi.Core.BiliApi.Login.Models { // https://passport.bilibili.com/qrcode/getLoginUrl [JsonObject] - public class LoginUrlOrigin : BaseEntity + public class LoginUrlOrigin : BaseModel { //public int code { get; set; } [JsonProperty("data")] @@ -15,12 +16,11 @@ namespace Core.entity2.login } [JsonObject] - public class LoginUrl : BaseEntity + public class LoginUrl : BaseModel { [JsonProperty("oauthKey")] public string OauthKey { get; set; } [JsonProperty("url")] public string Url { get; set; } } - } diff --git a/src/Core/entity2/login/UserInfoForNavigation.cs b/src/DownKyi.Core/BiliApi/Login/Models/UserInfoForNavigation.cs similarity index 92% rename from src/Core/entity2/login/UserInfoForNavigation.cs rename to src/DownKyi.Core/BiliApi/Login/Models/UserInfoForNavigation.cs index 1cb9347..42eedf5 100644 --- a/src/Core/entity2/login/UserInfoForNavigation.cs +++ b/src/DownKyi.Core/BiliApi/Login/Models/UserInfoForNavigation.cs @@ -1,10 +1,11 @@ -using Newtonsoft.Json; +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; -namespace Core.entity2.login +namespace DownKyi.Core.BiliApi.Login.Models { // https://api.bilibili.com/x/web-interface/nav [JsonObject] - public class UserInfoForNavigationOrigin : BaseEntity + public class UserInfoForNavigationOrigin : BaseModel { //[JsonProperty("code")] //public int Code { get; set; } @@ -17,7 +18,7 @@ namespace Core.entity2.login } [JsonObject] - public class UserInfoForNavigation : BaseEntity + public class UserInfoForNavigation : BaseModel { //public int allowance_count { get; set; } //public int answer_status { get; set; } @@ -93,7 +94,7 @@ namespace Core.entity2.login //} [JsonObject] - public class UserInfoWallet : BaseEntity + public class UserInfoWallet : BaseModel { [JsonProperty("bcoin_balance")] public float BcoinBalance { get; set; } @@ -104,5 +105,4 @@ namespace Core.entity2.login [JsonProperty("mid")] public long Mid { get; set; } } - } diff --git a/src/Core/entity2/BaseEntity.cs b/src/DownKyi.Core/BiliApi/Models/BaseModel.cs similarity index 92% rename from src/Core/entity2/BaseEntity.cs rename to src/DownKyi.Core/BiliApi/Models/BaseModel.cs index 1c55986..c0d4152 100644 --- a/src/Core/entity2/BaseEntity.cs +++ b/src/DownKyi.Core/BiliApi/Models/BaseModel.cs @@ -1,14 +1,14 @@ using Newtonsoft.Json; -namespace Core.entity2 +namespace DownKyi.Core.BiliApi.Models { - public abstract class BaseEntity + public abstract class BaseModel { public string ToString(string format = "") { // 设置为去掉null var jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; - + switch (format) { case "": diff --git a/src/DownKyi.Core/BiliApi/Models/Dimension.cs b/src/DownKyi.Core/BiliApi/Models/Dimension.cs new file mode 100644 index 0000000..41ea536 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Models/Dimension.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Models +{ + public class Dimension : BaseModel + { + [JsonProperty("width")] + public int Width { get; set; } + [JsonProperty("height")] + public int Height { get; set; } + [JsonProperty("rotate")] + public int Rotate { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Models/VideoOwner.cs b/src/DownKyi.Core/BiliApi/Models/VideoOwner.cs new file mode 100644 index 0000000..eaeb6d3 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Models/VideoOwner.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Models +{ + public class VideoOwner : BaseModel + { + [JsonProperty("mid")] + public long Mid { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("face")] + public string Face { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Dynamic.cs b/src/DownKyi.Core/BiliApi/Video/Dynamic.cs new file mode 100644 index 0000000..330b8c8 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Dynamic.cs @@ -0,0 +1,40 @@ +using DownKyi.Core.BiliApi.Video.Models; +using DownKyi.Core.Logging; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Video +{ + public static class Dynamic + { + + /// + /// 获取分区最新视频列表 + /// + /// 目标分区tid + /// 页码 + /// 每页项数(最大50) + /// + public static List RegionDynamicList(int rid, int pn = 1, int ps = 5) + { + string url = $"https://api.bilibili.com/x/web-interface/dynamic/region?rid={rid}&pn={pn}&ps={ps}"; + string referer = "https://www.bilibili.com"; + string response = WebClient.RequestWeb(url, referer); + + try + { + var dynamic = JsonConvert.DeserializeObject(response); + if (dynamic != null && dynamic.Data != null) { return dynamic.Data.Archives; } + else { return null; } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("RegionDynamicList()发生异常: {0}", e); + LogManager.Error("Dynamic", e); + return null; + } + } + + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/DynamicVideoView.cs b/src/DownKyi.Core/BiliApi/Video/Models/DynamicVideoView.cs new file mode 100644 index 0000000..1c59504 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/DynamicVideoView.cs @@ -0,0 +1,55 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + public class DynamicVideoView : BaseModel + { + [JsonProperty("aid")] + public long Aid { get; set; } + [JsonProperty("videos")] + public int Videos { get; set; } + [JsonProperty("tid")] + public int Tid { get; set; } + [JsonProperty("tname")] + public string Tname { get; set; } + [JsonProperty("copyright")] + public int Copyright { get; set; } + [JsonProperty("pic")] + public string Pic { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("pubdate")] + public long Pubdate { get; set; } + [JsonProperty("ctime")] + public long Ctime { get; set; } + [JsonProperty("desc")] + public string Desc { get; set; } + [JsonProperty("state")] + public int State { get; set; } + [JsonProperty("duration")] + public long Duration { get; set; } + [JsonProperty("owner")] + public VideoOwner Owner { get; set; } + [JsonProperty("stat")] + public VideoStat Stat { get; set; } + [JsonProperty("dynamic")] + public string Dynamic { get; set; } + [JsonProperty("cid")] + public long Cid { get; set; } + [JsonProperty("dimension")] + public Dimension Dimension { get; set; } + [JsonProperty("short_link")] + public string ShortLink { get; set; } + [JsonProperty("short_link_v2")] + public string ShortLinkV2 { get; set; } + [JsonProperty("first_frame")] + public string FirstFrame { get; set; } + [JsonProperty("bvid")] + public string Bvid { get; set; } + [JsonProperty("season_type")] + public int SeasonType { get; set; } + [JsonProperty("is_ogv")] + public bool IsOgv { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/RankingVideoView.cs b/src/DownKyi.Core/BiliApi/Video/Models/RankingVideoView.cs new file mode 100644 index 0000000..87bc072 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/RankingVideoView.cs @@ -0,0 +1,47 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + public class RankingVideoView : BaseModel + { + [JsonProperty("aid")] + public long Aid { get; set; } + [JsonProperty("bvid")] + public string Bvid { get; set; } + [JsonProperty("typename")] + public string TypeName { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("subtitle")] + public string Subtitle { get; set; } + [JsonProperty("play")] + public long Play { get; set; } + [JsonProperty("review")] + public long Review { get; set; } + [JsonProperty("video_review")] + public long VideoReview { get; set; } + [JsonProperty("favorites")] + public long Favorites { get; set; } + [JsonProperty("mid")] + public long Mid { get; set; } + [JsonProperty("author")] + public string Author { get; set; } + [JsonProperty("description")] + public string Description { get; set; } + [JsonProperty("create")] + public string Create { get; set; } + [JsonProperty("pic")] + public string Pic { get; set; } + [JsonProperty("coins")] + public long Coins { get; set; } + [JsonProperty("duration")] + public string Duration { get; set; } + [JsonProperty("badgepay")] + public bool Badgepay { get; set; } + [JsonProperty("pts")] + public long Pts { get; set; } + [JsonProperty("redirect_url")] + public string RedirectUrl { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/RegionDynamic.cs b/src/DownKyi.Core/BiliApi/Video/Models/RegionDynamic.cs new file mode 100644 index 0000000..ffbb66d --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/RegionDynamic.cs @@ -0,0 +1,27 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + // https://api.bilibili.com/x/web-interface/dynamic/region + public class RegionDynamicOrigin : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + //[JsonProperty("ttl")] + //public int Ttl { get; set; } + [JsonProperty("data")] + public RegionDynamic Data { get; set; } + } + + public class RegionDynamic : BaseModel + { + [JsonProperty("archives")] + public List Archives { get; set; } + // page + } + +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/RegionRanking.cs b/src/DownKyi.Core/BiliApi/Video/Models/RegionRanking.cs new file mode 100644 index 0000000..d0f7340 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/RegionRanking.cs @@ -0,0 +1,20 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + // https://api.bilibili.com/x/web-interface/ranking/region + public class RegionRanking : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + //[JsonProperty("ttl")] + //public int Ttl { get; set; } + [JsonProperty("data")] + public List Data { get; set; } + } + +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/UgcArc.cs b/src/DownKyi.Core/BiliApi/Video/Models/UgcArc.cs new file mode 100644 index 0000000..301d44f --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/UgcArc.cs @@ -0,0 +1,43 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + public class UgcArc : BaseModel + { + [JsonProperty("aid")] + public long Aid { get; set; } + [JsonProperty("videos")] + public int Videos { get; set; } + [JsonProperty("type_id")] + public int TypeId { get; set; } + [JsonProperty("type_name")] + public string TypeName { get; set; } + [JsonProperty("copyright")] + public int Copyright { get; set; } + [JsonProperty("pic")] + public string Pic { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("pubdate")] + public long Pubdate { get; set; } + [JsonProperty("ctime")] + public long Ctime { get; set; } + [JsonProperty("desc")] + public string Desc { get; set; } + [JsonProperty("state")] + public int State { get; set; } + [JsonProperty("duration")] + public long Duration { get; set; } + //[JsonProperty("rights")] + //public VideoRights Rights { get; set; } + [JsonProperty("author")] + public VideoOwner Author { get; set; } + [JsonProperty("stat")] + public VideoStat Stat { get; set; } + [JsonProperty("dynamic")] + public string Dynamic { get; set; } + [JsonProperty("dimension")] + public Dimension Dimension { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/UgcEpisode.cs b/src/DownKyi.Core/BiliApi/Video/Models/UgcEpisode.cs new file mode 100644 index 0000000..0a7a5e9 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/UgcEpisode.cs @@ -0,0 +1,29 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + public class UgcEpisode : BaseModel + { + [JsonProperty("season_id")] + public long SeasonId { get; set; } + [JsonProperty("section_id")] + public long SectionId { get; set; } + [JsonProperty("id")] + public long Id { get; set; } + [JsonProperty("aid")] + public long Aid { get; set; } + [JsonProperty("cid")] + public long Cid { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("attribute")] + public int Attribute { get; set; } + [JsonProperty("arc")] + public UgcArc Arc { get; set; } + [JsonProperty("page")] + public VideoPage Page { get; set; } + [JsonProperty("bvid")] + public string Bvid { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/UgcSeason.cs b/src/DownKyi.Core/BiliApi/Video/Models/UgcSeason.cs new file mode 100644 index 0000000..cf92b20 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/UgcSeason.cs @@ -0,0 +1,32 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + public class UgcSeason : BaseModel + { + [JsonProperty("id")] + public long Id { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("cover")] + public string Cover { get; set; } + [JsonProperty("mid")] + public long Mid { get; set; } + [JsonProperty("intro")] + public string Intro { get; set; } + [JsonProperty("sign_state")] + public int SignState { get; set; } + [JsonProperty("attribute")] + public int Attribute { get; set; } + [JsonProperty("sections")] + public List Sections { get; set; } + [JsonProperty("stat")] + public UgcStat Stat { get; set; } + [JsonProperty("ep_count")] + public int EpCount { get; set; } + [JsonProperty("season_type")] + public int SeasonType { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/UgcSection.cs b/src/DownKyi.Core/BiliApi/Video/Models/UgcSection.cs new file mode 100644 index 0000000..e3eccd8 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/UgcSection.cs @@ -0,0 +1,20 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + public class UgcSection : BaseModel + { + [JsonProperty("season_id")] + public long SeasonId { get; set; } + [JsonProperty("id")] + public long Id { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("type")] + public int Type { get; set; } + [JsonProperty("episodes")] + public List Episodes { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/UgcStat.cs b/src/DownKyi.Core/BiliApi/Video/Models/UgcStat.cs new file mode 100644 index 0000000..325eb16 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/UgcStat.cs @@ -0,0 +1,29 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + public class UgcStat : BaseModel + { + [JsonProperty("season_id")] + public long SeasonId { get; set; } + [JsonProperty("view")] + public long View { get; set; } + [JsonProperty("danmaku")] + public long Danmaku { get; set; } + [JsonProperty("reply")] + public long Reply { get; set; } + [JsonProperty("fav")] + public long Favorite { get; set; } + [JsonProperty("coin")] + public long Coin { get; set; } + [JsonProperty("share")] + public long Share { get; set; } + [JsonProperty("now_rank")] + public long NowRank { get; set; } + [JsonProperty("his_rank")] + public long HisRank { get; set; } + [JsonProperty("like")] + public long Like { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/VideoDescription.cs b/src/DownKyi.Core/BiliApi/Video/Models/VideoDescription.cs new file mode 100644 index 0000000..c03379c --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/VideoDescription.cs @@ -0,0 +1,18 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + // https://api.bilibili.com/x/web-interface/archive/desc + public class VideoDescription : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + //[JsonProperty("ttl")] + //public int Ttl { get; set; } + [JsonProperty("data")] + public string Data { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/VideoPage.cs b/src/DownKyi.Core/BiliApi/Video/Models/VideoPage.cs new file mode 100644 index 0000000..bcde7ba --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/VideoPage.cs @@ -0,0 +1,25 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + public class VideoPage : BaseModel + { + [JsonProperty("cid")] + public long Cid { get; set; } + [JsonProperty("page")] + public int Page { get; set; } + [JsonProperty("from")] + public string From { get; set; } + [JsonProperty("part")] + public string Part { get; set; } + [JsonProperty("duration")] + public long Duration { get; set; } + [JsonProperty("vid")] + public string Vid { get; set; } + [JsonProperty("weblink")] + public string Weblink { get; set; } + [JsonProperty("dimension")] + public Dimension Dimension { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/VideoPagelist.cs b/src/DownKyi.Core/BiliApi/Video/Models/VideoPagelist.cs new file mode 100644 index 0000000..f958b50 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/VideoPagelist.cs @@ -0,0 +1,19 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + // https://api.bilibili.com/x/player/pagelist + public class VideoPagelist : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + //[JsonProperty("ttl")] + //public int Ttl { get; set; } + [JsonProperty("data")] + public List Data { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/VideoStat.cs b/src/DownKyi.Core/BiliApi/Video/Models/VideoStat.cs new file mode 100644 index 0000000..d76d56d --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/VideoStat.cs @@ -0,0 +1,35 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + public class VideoStat : BaseModel + { + [JsonProperty("aid")] + public long Aid { get; set; } + [JsonProperty("view")] + public long View { get; set; } + [JsonProperty("danmaku")] + public long Danmaku { get; set; } + [JsonProperty("reply")] + public long Reply { get; set; } + [JsonProperty("favorite")] + public long Favorite { get; set; } + [JsonProperty("coin")] + public long Coin { get; set; } + [JsonProperty("share")] + public long Share { get; set; } + [JsonProperty("now_rank")] + public long NowRank { get; set; } + [JsonProperty("his_rank")] + public long HisRank { get; set; } + [JsonProperty("like")] + public long Like { get; set; } + [JsonProperty("dislike")] + public long Dislike { get; set; } + [JsonProperty("evaluation")] + public string Evaluation { get; set; } + [JsonProperty("argue_msg")] + public string ArgueMsg { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/VideoSubtitle.cs b/src/DownKyi.Core/BiliApi/Video/Models/VideoSubtitle.cs new file mode 100644 index 0000000..0d88d8e --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/VideoSubtitle.cs @@ -0,0 +1,55 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + public class VideoSubtitle : BaseModel + { + [JsonProperty("allow_submit")] + public bool AllowSubmit { get; set; } + [JsonProperty("list")] + public List List { get; set; } + } + + public class Subtitle : BaseModel + { + [JsonProperty("id")] + public long Id { get; set; } + [JsonProperty("lan")] + public string Lan { get; set; } + [JsonProperty("lan_doc")] + public string LanDoc { get; set; } + [JsonProperty("is_lock")] + public bool IsLock { get; set; } + [JsonProperty("author_mid")] + public long AuthorMid { get; set; } + [JsonProperty("subtitle_url")] + public string SubtitleUrl { get; set; } + [JsonProperty("author")] + public SubtitleAuthor Author { get; set; } + } + + public class SubtitleAuthor : BaseModel + { + [JsonProperty("mid")] + public long Mid { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("sex")] + public string Sex { get; set; } + [JsonProperty("face")] + public string Face { get; set; } + [JsonProperty("sign")] + public string Sign { get; set; } + //[JsonProperty("rank")] + //public int Rank { get; set; } + //[JsonProperty("birthday")] + //public int Birthday { get; set; } + //[JsonProperty("is_fake_account")] + //public int IsFakeAccount { get; set; } + //[JsonProperty("is_deleted")] + //public int IsDeleted { get; set; } + } + +} diff --git a/src/DownKyi.Core/BiliApi/Video/Models/VideoView.cs b/src/DownKyi.Core/BiliApi/Video/Models/VideoView.cs new file mode 100644 index 0000000..42a24cf --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Models/VideoView.cs @@ -0,0 +1,81 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Video.Models +{ + // https://api.bilibili.com/x/web-interface/view + public class VideoViewOrigin : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + //[JsonProperty("ttl")] + //public int Ttl { get; set; } + [JsonProperty("data")] + public VideoView Data { get; set; } + } + + public class VideoView : BaseModel + { + [JsonProperty("bvid")] + public string Bvid { get; set; } + [JsonProperty("aid")] + public long Aid { get; set; } + [JsonProperty("videos")] + public int Videos { get; set; } + [JsonProperty("tid")] + public int Tid { get; set; } + [JsonProperty("tname")] + public string Tname { get; set; } + [JsonProperty("copyright")] + public int Copyright { get; set; } + [JsonProperty("pic")] + public string Pic { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("pubdate")] + public long Pubdate { get; set; } + [JsonProperty("ctime")] + public long Ctime { get; set; } + [JsonProperty("desc")] + public string Desc { get; set; } + [JsonProperty("state")] + public int State { get; set; } + [JsonProperty("duration")] + public long Duration { get; set; } + [JsonProperty("redirect_url")] + public string RedirectUrl { get; set; } + [JsonProperty("mission_id")] + public long MissionId { get; set; } + //[JsonProperty("rights")] + //public VideoRights Rights { get; set; } + [JsonProperty("owner")] + public VideoOwner Owner { get; set; } + [JsonProperty("stat")] + public VideoStat Stat { get; set; } + [JsonProperty("dynamic")] + public string Dynamic { get; set; } + [JsonProperty("cid")] + public long Cid { get; set; } + [JsonProperty("dimension")] + public Dimension Dimension { get; set; } + [JsonProperty("season_id")] + public long SeasonId { get; set; } + [JsonProperty("festival_jump_url")] + public string FestivalJumpUrl { get; set; } + //[JsonProperty("no_cache")] + //public bool no_cache { get; set; } + [JsonProperty("pages")] + public List Pages { get; set; } + [JsonProperty("subtitle")] + public VideoSubtitle Subtitle { get; set; } + [JsonProperty("ugc_season")] + public UgcSeason UgcSeason { get; set; } + //[JsonProperty("staff")] + //public List staff { get; set; } + //[JsonProperty("user_garb")] + //public user_garb user_garb { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/Ranking.cs b/src/DownKyi.Core/BiliApi/Video/Ranking.cs new file mode 100644 index 0000000..16ac56d --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/Ranking.cs @@ -0,0 +1,40 @@ +using DownKyi.Core.BiliApi.Video.Models; +using DownKyi.Core.Logging; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Video +{ + public static class Ranking + { + + /// + /// 获取分区视频排行榜列表 + /// + /// 目标分区tid + /// 3日榜或周榜(3/7) + /// + /// + public static List RegionRankingList(int rid, int day = 3, int original = 0) + { + string url = $"https://api.bilibili.com/x/web-interface/ranking/region?rid={rid}&day={day}&ps={original}"; + string referer = "https://www.bilibili.com"; + string response = WebClient.RequestWeb(url, referer); + + try + { + var ranking = JsonConvert.DeserializeObject(response); + if (ranking != null) { return ranking.Data; } + else { return null; } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("RegionRankingList()发生异常: {0}", e); + LogManager.Error("Ranking", e); + return null; + } + } + + } +} diff --git a/src/DownKyi.Core/BiliApi/Video/VideoInfo.cs b/src/DownKyi.Core/BiliApi/Video/VideoInfo.cs new file mode 100644 index 0000000..aa0764d --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Video/VideoInfo.cs @@ -0,0 +1,105 @@ +using DownKyi.Core.BiliApi.Video.Models; +using DownKyi.Core.Logging; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.Video +{ + public static class VideoInfo + { + /// + /// 获取视频详细信息(web端) + /// + /// + /// + /// + public static VideoView VideoViewInfo(string bvid = null, long aid = -1) + { + string baseUrl = "https://api.bilibili.com/x/web-interface/view"; + string referer = "https://www.bilibili.com"; + string url; + if (bvid != null) { url = $"{baseUrl}?bvid={bvid}"; } + else if (aid > -1) { url = $"{baseUrl}?aid={aid}"; } + else { return null; } + + string response = WebClient.RequestWeb(url, referer); + + try + { + var videoView = JsonConvert.DeserializeObject(response); + if (videoView != null) { return videoView.Data; } + else { return null; } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("VideoInfo()发生异常: {0}", e); + LogManager.Error("VideoInfo", e); + return null; + } + } + + /// + /// 获取视频简介 + /// + /// + /// + /// + public static string VideoDescription(string bvid = null, long aid = -1) + { + string baseUrl = "https://api.bilibili.com/x/web-interface/archive/desc"; + string referer = "https://www.bilibili.com"; + string url; + if (bvid != null) { url = $"{baseUrl}?bvid={bvid}"; } + else if (aid >= -1) { url = $"{baseUrl}?aid={aid}"; } + else { return null; } + + string response = WebClient.RequestWeb(url, referer); + + try + { + var desc = JsonConvert.DeserializeObject(response); + if (desc != null) { return desc.Data; } + else { return null; } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("VideoDescription()发生异常: {0}", e); + LogManager.Error("VideoInfo", e); + return null; + } + } + + /// + /// 查询视频分P列表 (avid/bvid转cid) + /// + /// + /// + /// + public static List VideoPagelist(string bvid = null, long aid = -1) + { + string baseUrl = "https://api.bilibili.com/x/player/pagelist"; + string referer = "https://www.bilibili.com"; + string url; + if (bvid != null) { url = $"{baseUrl}?bvid={bvid}"; } + else if (aid > -1) { url = $"{baseUrl}?aid={aid}"; } + else { return null; } + + string response = WebClient.RequestWeb(url, referer); + + try + { + var pagelist = JsonConvert.DeserializeObject(response); + if (pagelist != null) { return pagelist.Data; } + else { return null; } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("VideoPagelist()发生异常: {0}", e); + LogManager.Error("VideoInfo", e); + return null; + } + } + + } +} diff --git a/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrl.cs b/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrl.cs new file mode 100644 index 0000000..2457223 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrl.cs @@ -0,0 +1,46 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.VideoStream.Models +{ + public class PlayUrlOrigin : BaseModel + { + //[JsonProperty("code")] + //public int Code { get; set; } + //[JsonProperty("message")] + //public string Message { get; set; } + //[JsonProperty("ttl")] + //public int Ttl { get; set; } + [JsonProperty("data")] + public PlayUrl Data { get; set; } + [JsonProperty("result")] + public PlayUrl Result { get; set; } + } + + public class PlayUrl : BaseModel + { + // from + // result + // message + // quality + // format + // timelength + // accept_format + [JsonProperty("accept_description")] + public List AcceptDescription { get; set; } + [JsonProperty("accept_quality")] + public List AcceptQuality { get; set; } + // video_codecid + // seek_param + // seek_type + [JsonProperty("durl")] + public List Durl { get; set; } + [JsonProperty("dash")] + public PlayUrlDash Dash { get; set; } + [JsonProperty("support_formats")] + public List SupportFormats { get; set; } + // high_format + } + +} diff --git a/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDash.cs b/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDash.cs new file mode 100644 index 0000000..7b65a05 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDash.cs @@ -0,0 +1,20 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.VideoStream.Models +{ + public class PlayUrlDash : BaseModel + { + [JsonProperty("duration")] + public long Duration { get; set; } + //[JsonProperty("minBufferTime")] + //public float minBufferTime { get; set; } + //[JsonProperty("min_buffer_time")] + //public float min_buffer_time { get; set; } + [JsonProperty("video")] + public List Video { get; set; } + [JsonProperty("audio")] + public List Audio { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDashVideo.cs b/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDashVideo.cs new file mode 100644 index 0000000..9c5cf20 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDashVideo.cs @@ -0,0 +1,35 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.VideoStream.Models +{ + public class PlayUrlDashVideo : BaseModel + { + [JsonProperty("id")] + public int Id { get; set; } + [JsonProperty("baseUrl")] + public string BaseUrl { get; set; } + [JsonProperty("backupUrl")] + public List BackupUrl { get; set; } + // bandwidth + [JsonProperty("mimeType")] + public string MimeType { get; set; } + // mime_type + [JsonProperty("codecs")] + public string Codecs { get; set; } + [JsonProperty("width")] + public int Width { get; set; } + [JsonProperty("height")] + public int Height { get; set; } + [JsonProperty("frameRate")] + public string FrameRate { get; set; } + // frame_rate + // sar + // startWithSap + // start_with_sap + // SegmentBase + // segment_base + // codecid + } +} diff --git a/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDurl.cs b/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDurl.cs new file mode 100644 index 0000000..a61f0ec --- /dev/null +++ b/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlDurl.cs @@ -0,0 +1,22 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace DownKyi.Core.BiliApi.VideoStream.Models +{ + public class PlayUrlDurl : BaseModel + { + [JsonProperty("order")] + public int Order { get; set; } + [JsonProperty("length")] + public long Length { get; set; } + [JsonProperty("size")] + public long Size { get; set; } + // ahead + // vhead + [JsonProperty("url")] + public string Url { get; set; } + [JsonProperty("backup_url")] + public List BackupUrl { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlSupportFormat.cs b/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlSupportFormat.cs new file mode 100644 index 0000000..f7187ad --- /dev/null +++ b/src/DownKyi.Core/BiliApi/VideoStream/Models/PlayUrlSupportFormat.cs @@ -0,0 +1,19 @@ +using DownKyi.Core.BiliApi.Models; +using Newtonsoft.Json; + +namespace DownKyi.Core.BiliApi.VideoStream.Models +{ + public class PlayUrlSupportFormat : BaseModel + { + [JsonProperty("quality")] + public int Quality { get; set; } + [JsonProperty("format")] + public string Format { get; set; } + [JsonProperty("new_description")] + public string NewDescription { get; set; } + [JsonProperty("display_desc")] + public string DisplayDesc { get; set; } + [JsonProperty("superscript")] + public string Superscript { get; set; } + } +} diff --git a/src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs b/src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs new file mode 100644 index 0000000..e84cacc --- /dev/null +++ b/src/DownKyi.Core/BiliApi/VideoStream/VideoStream.cs @@ -0,0 +1,101 @@ +using DownKyi.Core.BiliApi.VideoStream.Models; +using DownKyi.Core.Logging; +using Newtonsoft.Json; +using System; + +namespace DownKyi.Core.BiliApi.VideoStream +{ + public static class VideoStream + { + + /// + /// 获取普通视频的视频流 + /// + /// + /// + /// + /// + /// + public static PlayUrl GetVideoPlayUrl(long avid, string bvid, long cid, int quality = 125) + { + string baseUrl = $"https://api.bilibili.com/x/player/playurl?cid={cid}&qn={quality}&fourk=1&fnver=0&fnval=80"; + string url; + if (bvid != null) { url = $"{baseUrl}&bvid={bvid}"; } + else if (avid > -1) { url = $"{baseUrl}&aid={avid}"; } + else { return null; } + + return GetPlayUrl(url); + } + + /// + /// 获取番剧的视频流 + /// + /// + /// + /// + /// + /// + public static PlayUrl GetBangumiPlayUrl(long avid, string bvid, long cid, int quality = 125) + { + string baseUrl = $"https://api.bilibili.com/pgc/player/web/playurl?cid={cid}&qn={quality}&fourk=1&fnver=0&fnval=80"; + string url; + if (bvid != null) { url = $"{baseUrl}&bvid={bvid}"; } + else if (avid > -1) { url = $"{baseUrl}&aid={avid}"; } + else { return null; } + + return GetPlayUrl(url); + } + + /// + /// 获取课程的视频流 + /// + /// + /// + /// + /// + /// + public static PlayUrl GetCheesePlayUrl(long avid, string bvid, long cid, long episodeId, int quality = 125) + { + string baseUrl = $"https://api.bilibili.com/pugv/player/web/playurl?cid={cid}&qn={quality}&fourk=1&fnver=0&fnval=80"; + string url; + if (bvid != null) { url = $"{baseUrl}&bvid={bvid}"; } + else if (avid > -1) { url = $"{baseUrl}&aid={avid}"; } + else { return null; } + + // 必须有episodeId,否则会返回请求错误 + if (episodeId != 0) + { + url += $"&ep_id={episodeId}"; + } + + return GetPlayUrl(url); + } + + /// + /// 获取视频流 + /// + /// + /// + private static PlayUrl GetPlayUrl(string url) + { + string referer = "https://www.bilibili.com"; + string response = WebClient.RequestWeb(url, referer); + + try + { + var playUrl = JsonConvert.DeserializeObject(response); + if (playUrl == null) { return null; } + else if (playUrl.Data != null) { return playUrl.Data; } + else if (playUrl.Result != null) { return playUrl.Result; } + else { return null; } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("GetPlayUrl()发生异常: {0}", e); + LogManager.Error("GetPlayUrl", e); + return null; + } + } + + } +} diff --git a/src/DownKyi.Core/BiliApi/WebClient.cs b/src/DownKyi.Core/BiliApi/WebClient.cs new file mode 100644 index 0000000..2fa1c28 --- /dev/null +++ b/src/DownKyi.Core/BiliApi/WebClient.cs @@ -0,0 +1,142 @@ +using Brotli; +using DownKyi.Core.BiliApi.Login; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Net; +using System.Text; + +namespace DownKyi.Core.BiliApi +{ + internal static class WebClient + { + + /// + /// 发送get或post请求 + /// + /// + /// + /// + /// + /// + public static string RequestWeb(string url, string referer = null, string method = "GET", Dictionary parameters = null, int retry = 3) + { + // 重试次数 + if (retry <= 0) { return ""; } + + // post请求,发送参数 + if (method == "POST" && parameters != null) + { + StringBuilder builder = new StringBuilder(); + int i = 0; + foreach (var item in parameters) + { + if (i > 0) + { + builder.Append("&"); + } + + builder.AppendFormat("{0}={1}", item.Key, item.Value); + i++; + } + + url += "?" + builder.ToString(); + } + + try + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + request.Method = method; + request.Timeout = 30 * 1000; + request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36"; + //request.ContentType = "application/json,text/html,application/xhtml+xml,application/xml;charset=UTF-8"; + request.Headers["accept-language"] = "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"; + request.Headers["accept-encoding"] = "gzip, deflate, br"; + + // referer + if (referer != null) + { + request.Referer = referer; + } + + // 构造cookie + if (!url.Contains("getLogin")) + { + request.Headers["origin"] = "https://www.bilibili.com"; + + CookieContainer cookies = LoginHelper.GetLoginInfoCookies(); + if (cookies != null) + { + request.CookieContainer = cookies; + } + } + + string html = string.Empty; + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) + { + if (response.ContentEncoding.ToLower().Contains("gzip")) + { + using (GZipStream stream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress)) + { + using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) + { + html = reader.ReadToEnd(); + } + } + } + else if (response.ContentEncoding.ToLower().Contains("deflate")) + { + using (DeflateStream stream = new DeflateStream(response.GetResponseStream(), CompressionMode.Decompress)) + { + using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) + { + html = reader.ReadToEnd(); + } + } + } + else if (response.ContentEncoding.ToLower().Contains("br")) + { + using (BrotliStream stream = new BrotliStream(response.GetResponseStream(), CompressionMode.Decompress)) + { + using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) + { + html = reader.ReadToEnd(); + } + } + } + else + { + using (Stream stream = response.GetResponseStream()) + { + using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) + { + html = reader.ReadToEnd(); + } + } + } + } + + return html; + } + catch (WebException e) + { + Console.WriteLine("RequestWeb()发生Web异常: {0}", e); + Logging.LogManager.Error(e); + return RequestWeb(url, referer, method, parameters, retry - 1); + } + catch (IOException e) + { + Console.WriteLine("RequestWeb()发生IO异常: {0}", e); + Logging.LogManager.Error(e); + return RequestWeb(url, referer, method, parameters, retry - 1); + } + catch (Exception e) + { + Console.WriteLine("RequestWeb()发生其他异常: {0}", e); + Logging.LogManager.Error(e); + return RequestWeb(url, referer, method, parameters, retry - 1); + } + } + } +} diff --git a/src/Core/VideoZone.cs b/src/DownKyi.Core/BiliApi/Zone/VideoZone.cs similarity index 97% rename from src/Core/VideoZone.cs rename to src/DownKyi.Core/BiliApi/Zone/VideoZone.cs index 3a7a16d..741a918 100644 --- a/src/Core/VideoZone.cs +++ b/src/DownKyi.Core/BiliApi/Zone/VideoZone.cs @@ -1,7 +1,8 @@ using System.Collections.Generic; -namespace Core +namespace DownKyi.Core.BiliApi.Zone { + public class VideoZone { private static VideoZone that; @@ -188,22 +189,4 @@ namespace Core } } - - public class ZoneAttr - { - public int Id { get; } - public string Type { get; } - public string Name { get; } - public int ParentId { get; } - - public ZoneAttr(int id, string type, string name, int parentId = 0) - { - Id = id; - Type = type; - Name = name; - ParentId = parentId; - } - - } - } diff --git a/src/DownKyi.Core/BiliApi/Zone/ZoneAttr.cs b/src/DownKyi.Core/BiliApi/Zone/ZoneAttr.cs new file mode 100644 index 0000000..ff3876a --- /dev/null +++ b/src/DownKyi.Core/BiliApi/Zone/ZoneAttr.cs @@ -0,0 +1,19 @@ +namespace DownKyi.Core.BiliApi.Zone +{ + public class ZoneAttr + { + public int Id { get; } + public string Type { get; } + public string Name { get; } + public int ParentId { get; } + + public ZoneAttr(int id, string type, string name, int parentId = 0) + { + Id = id; + Type = type; + Name = name; + ParentId = parentId; + } + + } +} diff --git a/src/DownKyi.Core/DownKyi.Core.csproj b/src/DownKyi.Core/DownKyi.Core.csproj new file mode 100644 index 0000000..f17fa6f --- /dev/null +++ b/src/DownKyi.Core/DownKyi.Core.csproj @@ -0,0 +1,226 @@ + + + + + Debug + AnyCPU + {4FDE0364-F65B-4812-BFE8-34E886624FBD} + Library + Properties + DownKyi.Core + DownKyi.Core + v4.7.2 + 512 + true + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Brotli.NET.2.1.1\lib\net45\Brotli.Core.dll + + + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll + + + + + ..\packages\QRCoder.1.4.1\lib\net40\QRCoder.dll + + + + + ..\packages\System.Data.SQLite.Core.1.0.112.2\lib\net40\System.Data.SQLite.dll + + + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + + \ No newline at end of file diff --git a/src/DownKyi.Core/Logging/LogInfo.cs b/src/DownKyi.Core/Logging/LogInfo.cs new file mode 100644 index 0000000..192afe7 --- /dev/null +++ b/src/DownKyi.Core/Logging/LogInfo.cs @@ -0,0 +1,55 @@ +using System; + +namespace DownKyi.Core.Logging +{ + /// + /// 日志信息 + /// + public class LogInfo + { + /// + /// 时间 + /// + public DateTime Time { get; set; } + + /// + /// 线程id + /// + public int ThreadId { get; set; } + + /// + /// 日志级别 + /// + public LogLevel LogLevel { get; set; } + + /// + /// 异常源 + /// + public string Source { get; set; } + + /// + /// 异常信息 + /// + public string Message { get; set; } + + /// + /// 异常对象 + /// + public Exception Exception { get; set; } + + /// + /// 日志类型 + /// + public string ExceptionType { get; set; } + + /// + /// 请求路径 + /// + public string RequestUrl { get; set; } + + /// + /// 客户端代理 + /// + public string UserAgent { get; set; } + } +} \ No newline at end of file diff --git a/src/DownKyi.Core/Logging/LogLevel.cs b/src/DownKyi.Core/Logging/LogLevel.cs new file mode 100644 index 0000000..bf7108e --- /dev/null +++ b/src/DownKyi.Core/Logging/LogLevel.cs @@ -0,0 +1,28 @@ +namespace DownKyi.Core.Logging +{ + /// + /// 日志级别 + /// + public enum LogLevel + { + /// + /// 信息级别 + /// + Info, + + /// + /// debug级别 + /// + Debug, + + /// + /// 错误级别 + /// + Error, + + /// + /// 致命级别 + /// + Fatal + } +} \ No newline at end of file diff --git a/src/DownKyi.Core/Logging/LogManager.cs b/src/DownKyi.Core/Logging/LogManager.cs new file mode 100644 index 0000000..f91abc5 --- /dev/null +++ b/src/DownKyi.Core/Logging/LogManager.cs @@ -0,0 +1,450 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using static System.DateTime; + +namespace DownKyi.Core.Logging +{ + /// + /// 日志组件 + /// + public class LogManager + { + static readonly ConcurrentQueue> LogQueue = new ConcurrentQueue>(); + + /// + /// 自定义事件 + /// + public static event Action Event; + + static LogManager() + { + var writeTask = new Task(obj => + { + while (true) + { + Pause.WaitOne(1000, true); + List temp = new List(); + foreach (var logItem in LogQueue) + { + string logPath = logItem.Item1; + string logMergeContent = string.Concat(logItem.Item2, Environment.NewLine, "----------------------------------------------------------------------------------------------------------------------", Environment.NewLine); + string[] logArr = temp.FirstOrDefault(d => d[0].Equals(logPath)); + if (logArr != null) + { + logArr[1] = string.Concat(logArr[1], logMergeContent); + } + else + { + logArr = new[] + { + logPath, + logMergeContent + }; + temp.Add(logArr); + } + + LogQueue.TryDequeue(out Tuple _); + } + + foreach (var item in temp) + { + WriteText(item[0], item[1]); + } + } + }, null, TaskCreationOptions.LongRunning); + writeTask.Start(); + } + + private static AutoResetEvent Pause => new AutoResetEvent(false); + + /// + /// 日志存放目录,默认日志放在当前应用程序运行目录下的logs文件夹中 + /// + public static string LogDirectory + { + get => Storage.Constant.Logs; // Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs"); + set + { + } + } + + /// + /// 写入Info级别的日志 + /// + /// + public static void Info(string info) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(info).ToUpper()} {info}")); + var log = new LogInfo() + { + LogLevel = LogLevel.Info, + Message = info, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId + }; + Event?.Invoke(log); + } + + /// + /// 写入Info级别的日志 + /// + /// + /// + public static void Info(string source, string info) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(info).ToUpper()} {source} {info}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Info, + Message = info, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source + }; + Event?.Invoke(log); + } + + /// + /// 写入Info级别的日志 + /// + /// + /// + public static void Info(Type source, string info) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(info).ToUpper()} {source.FullName} {info}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Info, + Message = info, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source.FullName + }; + Event?.Invoke(log); + } + + /// + /// 写入debug级别日志 + /// + /// 异常对象 + public static void Debug(string debug) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(debug).ToUpper()} {debug}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Debug, + Message = debug, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId + }; + Event?.Invoke(log); + } + + /// + /// 写入debug级别日志 + /// + /// 异常源的类型 + /// 异常对象 + public static void Debug(string source, string debug) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(debug).ToUpper()} {source} {debug}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Debug, + Message = debug, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source + }; + Event?.Invoke(log); + } + + /// + /// 写入debug级别日志 + /// + /// 异常源的类型 + /// 异常对象 + public static void Debug(Type source, string debug) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(debug).ToUpper()} {source.FullName} {debug}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Debug, + Message = debug, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source.FullName + }; + Event?.Invoke(log); + } + + /// + /// 写入error级别日志 + /// + /// 异常对象 + public static void Error(Exception error) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(error).ToUpper()} {error.Source} {error.Message}{Environment.NewLine}{error.StackTrace}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Error, + Message = error.Message, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = error.Source, + Exception = error, + ExceptionType = error.GetType().Name + }; + Event?.Invoke(log); + } + + /// + /// 写入error级别日志 + /// + /// 异常源的类型 + /// 异常对象 + public static void Error(Type source, Exception error) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(error).ToUpper()} {source.FullName} {error.Message}{Environment.NewLine}{error.StackTrace}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Error, + Message = error.Message, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source.FullName, + Exception = error, + ExceptionType = error.GetType().Name + }; + Event?.Invoke(log); + } + + /// + /// 写入error级别日志 + /// + /// 异常源的类型 + /// 异常信息 + public static void Error(Type source, string error) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(error).ToUpper()} {source.FullName} {error}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Error, + Message = error, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source.FullName, + //Exception = error, + ExceptionType = error.GetType().Name + }; + Event?.Invoke(log); + } + + /// + /// 写入error级别日志 + /// + /// 异常源的类型 + /// 异常对象 + public static void Error(string source, Exception error) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(error).ToUpper()} {source} {error.Message}{Environment.NewLine}{error.StackTrace}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Error, + Message = error.Message, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source, + Exception = error, + ExceptionType = error.GetType().Name + }; + Event?.Invoke(log); + } + + /// + /// 写入error级别日志 + /// + /// 异常源的类型 + /// 异常信息 + public static void Error(string source, string error) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(error).ToUpper()} {source} {error}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Error, + Message = error, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source, + //Exception = error, + ExceptionType = error.GetType().Name + }; + Event?.Invoke(log); + } + + /// + /// 写入fatal级别日志 + /// + /// 异常对象 + public static void Fatal(Exception fatal) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(fatal).ToUpper()} {fatal.Source} {fatal.Message}{Environment.NewLine}{fatal.StackTrace}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Fatal, + Message = fatal.Message, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = fatal.Source, + Exception = fatal, + ExceptionType = fatal.GetType().Name + }; + Event?.Invoke(log); + } + + /// + /// 写入fatal级别日志 + /// + /// 异常源的类型 + /// 异常对象 + public static void Fatal(Type source, Exception fatal) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(fatal).ToUpper()} {source.FullName} {fatal.Message}{Environment.NewLine}{fatal.StackTrace}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Fatal, + Message = fatal.Message, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source.FullName, + Exception = fatal, + ExceptionType = fatal.GetType().Name + }; + Event?.Invoke(log); + } + + /// + /// 写入fatal级别日志 + /// + /// 异常源的类型 + /// 异常对象 + public static void Fatal(Type source, string fatal) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(fatal).ToUpper()} {source.FullName} {fatal}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Fatal, + Message = fatal, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source.FullName, + //Exception = fatal, + ExceptionType = fatal.GetType().Name + }; + Event?.Invoke(log); + } + + /// + /// 写入fatal级别日志 + /// + /// 异常源的类型 + /// 异常对象 + public static void Fatal(string source, Exception fatal) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(fatal).ToUpper()} {source} {fatal.Message}{Environment.NewLine}{fatal.StackTrace}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Fatal, + Message = fatal.Message, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source, + Exception = fatal, + ExceptionType = fatal.GetType().Name + }; + Event?.Invoke(log); + } + + /// + /// 写入fatal级别日志 + /// + /// 异常源的类型 + /// 异常对象 + public static void Fatal(string source, string fatal) + { + LogQueue.Enqueue(new Tuple(GetLogPath(), $"{Now} [{Thread.CurrentThread.ManagedThreadId}] {nameof(fatal).ToUpper()} {source} {fatal}")); + LogInfo log = new LogInfo() + { + LogLevel = LogLevel.Fatal, + Message = fatal, + Time = Now, + ThreadId = Thread.CurrentThread.ManagedThreadId, + Source = source, + ExceptionType = fatal.GetType().Name + }; + Event?.Invoke(log); + } + + private static string GetLogPath() + { + string newFilePath; + var logDir = string.IsNullOrEmpty(LogDirectory) ? Path.Combine(Environment.CurrentDirectory, "logs") : LogDirectory; + Directory.CreateDirectory(logDir); + string extension = ".log"; + string fileNameNotExt = Now.ToString("yyyyMMdd"); + string fileNamePattern = string.Concat(fileNameNotExt, "(*)", extension); + List filePaths = Directory.GetFiles(logDir, fileNamePattern, SearchOption.TopDirectoryOnly).ToList(); + + if (filePaths.Count > 0) + { + int fileMaxLen = filePaths.Max(d => d.Length); + string lastFilePath = filePaths.Where(d => d.Length == fileMaxLen).OrderByDescending(d => d).FirstOrDefault(); + if (new FileInfo(lastFilePath).Length > 1 * 1024 * 1024) + { + var no = new Regex(@"(?is)(?<=\()(.*)(?=\))").Match(Path.GetFileName(lastFilePath)).Value; + var parse = int.TryParse(no, out int tempno); + var formatno = $"({(parse ? (tempno + 1) : tempno)})"; + var newFileName = String.Concat(fileNameNotExt, formatno, extension); + newFilePath = Path.Combine(logDir, newFileName); + } + else + { + newFilePath = lastFilePath; + } + } + else + { + var newFileName = string.Concat(fileNameNotExt, $"({0})", extension); + newFilePath = Path.Combine(logDir, newFileName); + } + + return newFilePath; + } + + private static void WriteText(string logPath, string logContent) + { + try + { + if (!File.Exists(logPath)) + { + File.CreateText(logPath).Close(); + } + + using (var sw = File.AppendText(logPath)) + { + sw.Write(logContent); + } + } + catch (Exception) + { + // ignored + } + } + } +} \ No newline at end of file diff --git a/src/DownKyi.Core/Properties/AssemblyInfo.cs b/src/DownKyi.Core/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e3405cb --- /dev/null +++ b/src/DownKyi.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("DownKyi.Core")] +[assembly: AssemblyDescription("DownKyi.Core")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("DownKyi")] +[assembly: AssemblyProduct("DownKyi.Core")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("4fde0364-f65b-4812-bfe8-34e886624fbd")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("2.0.0.0")] +[assembly: AssemblyFileVersion("2.0.0.0")] diff --git a/src/DownKyi.Core/Settings/AfterDownloadOperation.cs b/src/DownKyi.Core/Settings/AfterDownloadOperation.cs new file mode 100644 index 0000000..99ac8a1 --- /dev/null +++ b/src/DownKyi.Core/Settings/AfterDownloadOperation.cs @@ -0,0 +1,10 @@ +namespace DownKyi.Core.Settings +{ + public enum AfterDownloadOperation + { + NONE = 1, + OPEN_FOLDER, + CLOSE_APP, + CLOSE_SYSTEM + } +} diff --git a/src/DownKyi.Core/Settings/AllowStatus.cs b/src/DownKyi.Core/Settings/AllowStatus.cs new file mode 100644 index 0000000..9473713 --- /dev/null +++ b/src/DownKyi.Core/Settings/AllowStatus.cs @@ -0,0 +1,9 @@ +namespace DownKyi.Core.Settings +{ + public enum AllowStatus + { + NONE = 0, + NO, + YES + } +} diff --git a/src/DownKyi.Core/Settings/DanmakuLayoutAlgorithm.cs b/src/DownKyi.Core/Settings/DanmakuLayoutAlgorithm.cs new file mode 100644 index 0000000..ed188f6 --- /dev/null +++ b/src/DownKyi.Core/Settings/DanmakuLayoutAlgorithm.cs @@ -0,0 +1,9 @@ +namespace DownKyi.Core.Settings +{ + public enum DanmakuLayoutAlgorithm + { + NONE = 0, + ASYNC, + SYNC + } +} diff --git a/src/DownKyi.Core/Settings/DownloadFinishedSort.cs b/src/DownKyi.Core/Settings/DownloadFinishedSort.cs new file mode 100644 index 0000000..6676737 --- /dev/null +++ b/src/DownKyi.Core/Settings/DownloadFinishedSort.cs @@ -0,0 +1,8 @@ +namespace DownKyi.Core.Settings +{ + public enum DownloadFinishedSort + { + DOWNLOAD = 0, + NUMBER + } +} diff --git a/src/DownKyi.Core/Settings/Models/AboutSettings.cs b/src/DownKyi.Core/Settings/Models/AboutSettings.cs new file mode 100644 index 0000000..7b6a1db --- /dev/null +++ b/src/DownKyi.Core/Settings/Models/AboutSettings.cs @@ -0,0 +1,11 @@ +namespace DownKyi.Core.Settings.Models +{ + /// + /// 关于 + /// + public class AboutSettings + { + public AllowStatus IsReceiveBetaVersion { get; set; } + public AllowStatus AutoUpdateWhenLaunch { get; set; } + } +} diff --git a/src/DownKyi.Core/Settings/Models/AppSettings.cs b/src/DownKyi.Core/Settings/Models/AppSettings.cs new file mode 100644 index 0000000..6285a91 --- /dev/null +++ b/src/DownKyi.Core/Settings/Models/AppSettings.cs @@ -0,0 +1,12 @@ +namespace DownKyi.Core.Settings.Models +{ + public class AppSettings + { + public BasicSettings Basic { get; set; } = new BasicSettings(); + public NetworkSettings Network { get; set; } = new NetworkSettings(); + public VideoSettings Video { get; set; } = new VideoSettings(); + public DanmakuSettings Danmaku { get; set; } = new DanmakuSettings(); + public AboutSettings About { get; set; } = new AboutSettings(); + public UserInfoSettings UserInfo { get; set; } + } +} diff --git a/src/DownKyi.Core/Settings/Models/BasicSettings.cs b/src/DownKyi.Core/Settings/Models/BasicSettings.cs new file mode 100644 index 0000000..46a53e0 --- /dev/null +++ b/src/DownKyi.Core/Settings/Models/BasicSettings.cs @@ -0,0 +1,14 @@ +namespace DownKyi.Core.Settings.Models +{ + /// + /// 基本 + /// + public class BasicSettings + { + public AfterDownloadOperation AfterDownload { get; set; } + public AllowStatus IsListenClipboard { get; set; } + public AllowStatus IsAutoParseVideo { get; set; } + public ParseScope ParseScope { get; set; } + public DownloadFinishedSort DownloadFinishedSort { get; set; } + } +} diff --git a/src/DownKyi.Core/Settings/Models/DanmakuSettings.cs b/src/DownKyi.Core/Settings/Models/DanmakuSettings.cs new file mode 100644 index 0000000..64bc828 --- /dev/null +++ b/src/DownKyi.Core/Settings/Models/DanmakuSettings.cs @@ -0,0 +1,19 @@ +namespace DownKyi.Core.Settings.Models +{ + /// + /// 弹幕 + /// + public class DanmakuSettings + { + public AllowStatus DanmakuTopFilter { get; set; } + public AllowStatus DanmakuBottomFilter { get; set; } + public AllowStatus DanmakuScrollFilter { get; set; } + public AllowStatus IsCustomDanmakuResolution { get; set; } + public int DanmakuScreenWidth { get; set; } + public int DanmakuScreenHeight { get; set; } + public string DanmakuFontName { get; set; } + public int DanmakuFontSize { get; set; } + public int DanmakuLineCount { get; set; } + public DanmakuLayoutAlgorithm DanmakuLayoutAlgorithm { get; set; } + } +} diff --git a/src/DownKyi.Core/Settings/Models/NetworkSettings.cs b/src/DownKyi.Core/Settings/Models/NetworkSettings.cs new file mode 100644 index 0000000..cdfcb5f --- /dev/null +++ b/src/DownKyi.Core/Settings/Models/NetworkSettings.cs @@ -0,0 +1,23 @@ +using DownKyi.Core.Aria2cNet.Server; + +namespace DownKyi.Core.Settings.Models +{ + /// + /// 网络 + /// + public class NetworkSettings + { + public AllowStatus IsLiftingOfRegion { get; set; } + public int AriaListenPort { get; set; } + public AriaConfigLogLevel AriaLogLevel { get; set; } + public int AriaMaxConcurrentDownloads { get; set; } + public int AriaSplit { get; set; } + public int AriaMaxOverallDownloadLimit { get; set; } + public int AriaMaxDownloadLimit { get; set; } + public AriaConfigFileAllocation AriaFileAllocation { get; set; } + + public AllowStatus IsAriaHttpProxy { get; set; } + public string AriaHttpProxy { get; set; } + public int AriaHttpProxyListenPort { get; set; } + } +} diff --git a/src/DownKyi.Core/Settings/Models/UserInfoSettings.cs b/src/DownKyi.Core/Settings/Models/UserInfoSettings.cs new file mode 100644 index 0000000..774b7ec --- /dev/null +++ b/src/DownKyi.Core/Settings/Models/UserInfoSettings.cs @@ -0,0 +1,10 @@ +namespace DownKyi.Core.Settings.Models +{ + public class UserInfoSettings + { + public long Mid { get; set; } + public string Name { get; set; } + public bool IsLogin { get; set; } // 是否登录 + public bool IsVip { get; set; } // 是否为大会员,未登录时为false + } +} diff --git a/src/DownKyi.Core/Settings/Models/VideoSettings.cs b/src/DownKyi.Core/Settings/Models/VideoSettings.cs new file mode 100644 index 0000000..0863423 --- /dev/null +++ b/src/DownKyi.Core/Settings/Models/VideoSettings.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace DownKyi.Core.Settings.Models +{ + /// + /// 视频 + /// + public class VideoSettings + { + public VideoCodecs VideoCodecs { get; set; } + public int Quality { get; set; } + public int AudioQuality { get; set; } + public AllowStatus IsAddOrder { get; set; } + public AllowStatus IsTranscodingFlvToMp4 { get; set; } + public string SaveVideoRootPath { get; set; } + public List HistoryVideoRootPaths { get; set; } + public AllowStatus IsUseSaveVideoRootPath { get; set; } + public AllowStatus IsCreateFolderForMedia { get; set; } + public AllowStatus IsDownloadDanmaku { get; set; } + public AllowStatus IsDownloadCover { get; set; } + } +} diff --git a/src/DownKyi.Core/Settings/ParseScope.cs b/src/DownKyi.Core/Settings/ParseScope.cs new file mode 100644 index 0000000..b028eac --- /dev/null +++ b/src/DownKyi.Core/Settings/ParseScope.cs @@ -0,0 +1,10 @@ +namespace DownKyi.Core.Settings +{ + public enum ParseScope + { + NONE = 1, + SELECTED_ITEM, + CURRENT_SECTION, + ALL + } +} diff --git a/src/Core/settings/Settings.about.cs b/src/DownKyi.Core/Settings/SettingsManager.About.cs similarity index 53% rename from src/Core/settings/Settings.about.cs rename to src/DownKyi.Core/Settings/SettingsManager.About.cs index abc3707..b4a2f75 100644 --- a/src/Core/settings/Settings.about.cs +++ b/src/DownKyi.Core/Settings/SettingsManager.About.cs @@ -1,27 +1,27 @@ -namespace Core.settings +namespace DownKyi.Core.Settings { - public partial class Settings + public partial class SettingsManager { // 是否接收测试版更新 - private readonly ALLOW_STATUS isReceiveBetaVersion = ALLOW_STATUS.NO; + private readonly AllowStatus isReceiveBetaVersion = AllowStatus.NO; // 是否在启动时自动检查更新 - private readonly ALLOW_STATUS autoUpdateWhenLaunch = ALLOW_STATUS.YES; - + private readonly AllowStatus autoUpdateWhenLaunch = AllowStatus.YES; /// /// 获取是否接收测试版更新 /// /// - public ALLOW_STATUS IsReceiveBetaVersion() + public AllowStatus IsReceiveBetaVersion() { - if (settingsEntity.IsReceiveBetaVersion == 0) + appSettings = GetSettings(); + if (appSettings.About.IsReceiveBetaVersion == 0) { // 第一次获取,先设置默认值 IsReceiveBetaVersion(isReceiveBetaVersion); return isReceiveBetaVersion; } - return settingsEntity.IsReceiveBetaVersion; + return appSettings.About.IsReceiveBetaVersion; } /// @@ -29,25 +29,26 @@ /// /// /// - public bool IsReceiveBetaVersion(ALLOW_STATUS isReceiveBetaVersion) + public bool IsReceiveBetaVersion(AllowStatus isReceiveBetaVersion) { - settingsEntity.IsReceiveBetaVersion = isReceiveBetaVersion; - return SetEntity(); + appSettings.About.IsReceiveBetaVersion = isReceiveBetaVersion; + return SetSettings(); } /// /// 获取是否允许启动时检查更新 /// /// - public ALLOW_STATUS GetAutoUpdateWhenLaunch() + public AllowStatus GetAutoUpdateWhenLaunch() { - if (settingsEntity.AutoUpdateWhenLaunch == 0) + appSettings = GetSettings(); + if (appSettings.About.AutoUpdateWhenLaunch == 0) { // 第一次获取,先设置默认值 SetAutoUpdateWhenLaunch(autoUpdateWhenLaunch); return autoUpdateWhenLaunch; } - return settingsEntity.AutoUpdateWhenLaunch; + return appSettings.About.AutoUpdateWhenLaunch; } /// @@ -55,10 +56,10 @@ /// /// /// - public bool SetAutoUpdateWhenLaunch(ALLOW_STATUS autoUpdateWhenLaunch) + public bool SetAutoUpdateWhenLaunch(AllowStatus autoUpdateWhenLaunch) { - settingsEntity.AutoUpdateWhenLaunch = autoUpdateWhenLaunch; - return SetEntity(); + appSettings.About.AutoUpdateWhenLaunch = autoUpdateWhenLaunch; + return SetSettings(); } } diff --git a/src/Core/settings/Settings.base.cs b/src/DownKyi.Core/Settings/SettingsManager.Basic.cs similarity index 53% rename from src/Core/settings/Settings.base.cs rename to src/DownKyi.Core/Settings/SettingsManager.Basic.cs index 211a093..d5f93e7 100644 --- a/src/Core/settings/Settings.base.cs +++ b/src/DownKyi.Core/Settings/SettingsManager.Basic.cs @@ -1,33 +1,36 @@ -namespace Core.settings +namespace DownKyi.Core.Settings { - public partial class Settings + public partial class SettingsManager { // 默认下载完成后的操作 private readonly AfterDownloadOperation afterDownload = AfterDownloadOperation.NONE; // 是否监听剪贴板 - private readonly ALLOW_STATUS isListenClipboard = ALLOW_STATUS.YES; + private readonly AllowStatus isListenClipboard = AllowStatus.YES; // 视频详情页面是否自动解析 - private readonly ALLOW_STATUS isAutoParseVideo = ALLOW_STATUS.NO; + private readonly AllowStatus isAutoParseVideo = AllowStatus.NO; + + // 默认的视频解析项 + private readonly ParseScope parseScope = ParseScope.NONE; // 下载完成列表排序 private readonly DownloadFinishedSort finishedSort = DownloadFinishedSort.DOWNLOAD; - /// /// 获取下载完成后的操作 /// /// public AfterDownloadOperation GetAfterDownloadOperation() { - if (settingsEntity.AfterDownload == 0) + appSettings = GetSettings(); + if (appSettings.Basic.AfterDownload == 0) { // 第一次获取,先设置默认值 SetAfterDownloadOperation(afterDownload); return afterDownload; } - return settingsEntity.AfterDownload; + return appSettings.Basic.AfterDownload; } /// @@ -37,23 +40,24 @@ /// public bool SetAfterDownloadOperation(AfterDownloadOperation afterDownload) { - settingsEntity.AfterDownload = afterDownload; - return SetEntity(); + appSettings.Basic.AfterDownload = afterDownload; + return SetSettings(); } /// /// 是否监听剪贴板 /// /// - public ALLOW_STATUS IsListenClipboard() + public AllowStatus IsListenClipboard() { - if (settingsEntity.IsListenClipboard == 0) + appSettings = GetSettings(); + if (appSettings.Basic.IsListenClipboard == 0) { // 第一次获取,先设置默认值 IsListenClipboard(isListenClipboard); return isListenClipboard; } - return settingsEntity.IsListenClipboard; + return appSettings.Basic.IsListenClipboard; } /// @@ -61,25 +65,26 @@ /// /// /// - public bool IsListenClipboard(ALLOW_STATUS isListen) + public bool IsListenClipboard(AllowStatus isListen) { - settingsEntity.IsListenClipboard = isListen; - return SetEntity(); + appSettings.Basic.IsListenClipboard = isListen; + return SetSettings(); } /// /// 视频详情页面是否自动解析 /// /// - public ALLOW_STATUS IsAutoParseVideo() + public AllowStatus IsAutoParseVideo() { - if (settingsEntity.IsAutoParseVideo == 0) + appSettings = GetSettings(); + if (appSettings.Basic.IsAutoParseVideo == 0) { // 第一次获取,先设置默认值 IsAutoParseVideo(isAutoParseVideo); return isAutoParseVideo; } - return settingsEntity.IsAutoParseVideo; + return appSettings.Basic.IsAutoParseVideo; } /// @@ -87,10 +92,37 @@ /// /// /// - public bool IsAutoParseVideo(ALLOW_STATUS IsAuto) + public bool IsAutoParseVideo(AllowStatus IsAuto) + { + appSettings.Basic.IsAutoParseVideo = IsAuto; + return SetSettings(); + } + + /// + /// 获取视频解析项 + /// + /// + public ParseScope GetParseScope() + { + appSettings = GetSettings(); + if (appSettings.Basic.ParseScope == 0) + { + // 第一次获取,先设置默认值 + SetParseScope(parseScope); + return parseScope; + } + return appSettings.Basic.ParseScope; + } + + /// + /// 设置视频解析项 + /// + /// + /// + public bool SetParseScope(ParseScope parseScope) { - settingsEntity.IsAutoParseVideo = IsAuto; - return SetEntity(); + appSettings.Basic.ParseScope = parseScope; + return SetSettings(); } /// @@ -99,13 +131,14 @@ /// public DownloadFinishedSort GetDownloadFinishedSort() { - if (settingsEntity.DownloadFinishedSort == 0) + appSettings = GetSettings(); + if (appSettings.Basic.DownloadFinishedSort == 0) { // 第一次获取,先设置默认值 SetDownloadFinishedSort(finishedSort); return finishedSort; } - return settingsEntity.DownloadFinishedSort; + return appSettings.Basic.DownloadFinishedSort; } /// @@ -115,8 +148,8 @@ /// public bool SetDownloadFinishedSort(DownloadFinishedSort finishedSort) { - settingsEntity.DownloadFinishedSort = finishedSort; - return SetEntity(); + appSettings.Basic.DownloadFinishedSort = finishedSort; + return SetSettings(); } } diff --git a/src/Core/settings/Settings.danmaku.cs b/src/DownKyi.Core/Settings/SettingsManager.Danmaku.cs similarity index 64% rename from src/Core/settings/Settings.danmaku.cs rename to src/DownKyi.Core/Settings/SettingsManager.Danmaku.cs index 0adff0e..34f2b95 100644 --- a/src/Core/settings/Settings.danmaku.cs +++ b/src/DownKyi.Core/Settings/SettingsManager.Danmaku.cs @@ -1,18 +1,18 @@ -namespace Core.settings +namespace DownKyi.Core.Settings { - public partial class Settings + public partial class SettingsManager { // 是否屏蔽顶部弹幕 - private readonly ALLOW_STATUS danmakuTopFilter = ALLOW_STATUS.NO; + private readonly AllowStatus danmakuTopFilter = AllowStatus.NO; // 是否屏蔽底部弹幕 - private readonly ALLOW_STATUS danmakuBottomFilter = ALLOW_STATUS.NO; + private readonly AllowStatus danmakuBottomFilter = AllowStatus.NO; // 是否屏蔽滚动弹幕 - private readonly ALLOW_STATUS danmakuScrollFilter = ALLOW_STATUS.NO; + private readonly AllowStatus danmakuScrollFilter = AllowStatus.NO; // 是否自定义分辨率 - private readonly ALLOW_STATUS isCustomDanmakuResolution = ALLOW_STATUS.NO; + private readonly AllowStatus isCustomDanmakuResolution = AllowStatus.NO; // 分辨率-宽 private readonly int danmakuScreenWidth = 1920; @@ -37,15 +37,16 @@ /// 获取是否屏蔽顶部弹幕 /// /// - public ALLOW_STATUS GetDanmakuTopFilter() + public AllowStatus GetDanmakuTopFilter() { - if (settingsEntity.DanmakuTopFilter == 0) + appSettings = GetSettings(); + if (appSettings.Danmaku.DanmakuTopFilter == 0) { // 第一次获取,先设置默认值 SetDanmakuTopFilter(danmakuTopFilter); return danmakuTopFilter; } - return settingsEntity.DanmakuTopFilter; + return appSettings.Danmaku.DanmakuTopFilter; } /// @@ -53,25 +54,26 @@ /// /// /// - public bool SetDanmakuTopFilter(ALLOW_STATUS danmakuFilter) + public bool SetDanmakuTopFilter(AllowStatus danmakuFilter) { - settingsEntity.DanmakuTopFilter = danmakuFilter; - return SetEntity(); + appSettings.Danmaku.DanmakuTopFilter = danmakuFilter; + return SetSettings(); } /// /// 获取是否屏蔽底部弹幕 /// /// - public ALLOW_STATUS GetDanmakuBottomFilter() + public AllowStatus GetDanmakuBottomFilter() { - if (settingsEntity.DanmakuBottomFilter == 0) + appSettings = GetSettings(); + if (appSettings.Danmaku.DanmakuBottomFilter == 0) { // 第一次获取,先设置默认值 SetDanmakuBottomFilter(danmakuBottomFilter); return danmakuBottomFilter; } - return settingsEntity.DanmakuBottomFilter; + return appSettings.Danmaku.DanmakuBottomFilter; } /// @@ -79,25 +81,26 @@ /// /// /// - public bool SetDanmakuBottomFilter(ALLOW_STATUS danmakuFilter) + public bool SetDanmakuBottomFilter(AllowStatus danmakuFilter) { - settingsEntity.DanmakuBottomFilter = danmakuFilter; - return SetEntity(); + appSettings.Danmaku.DanmakuBottomFilter = danmakuFilter; + return SetSettings(); } /// /// 获取是否屏蔽滚动弹幕 /// /// - public ALLOW_STATUS GetDanmakuScrollFilter() + public AllowStatus GetDanmakuScrollFilter() { - if (settingsEntity.DanmakuScrollFilter == 0) + appSettings = GetSettings(); + if (appSettings.Danmaku.DanmakuScrollFilter == 0) { // 第一次获取,先设置默认值 SetDanmakuScrollFilter(danmakuScrollFilter); return danmakuScrollFilter; } - return settingsEntity.DanmakuScrollFilter; + return appSettings.Danmaku.DanmakuScrollFilter; } /// @@ -105,25 +108,26 @@ /// /// /// - public bool SetDanmakuScrollFilter(ALLOW_STATUS danmakuFilter) + public bool SetDanmakuScrollFilter(AllowStatus danmakuFilter) { - settingsEntity.DanmakuScrollFilter = danmakuFilter; - return SetEntity(); + appSettings.Danmaku.DanmakuScrollFilter = danmakuFilter; + return SetSettings(); } /// /// 获取是否自定义分辨率 /// /// - public ALLOW_STATUS IsCustomDanmakuResolution() + public AllowStatus IsCustomDanmakuResolution() { - if (settingsEntity.IsCustomDanmakuResolution == 0) + appSettings = GetSettings(); + if (appSettings.Danmaku.IsCustomDanmakuResolution == 0) { // 第一次获取,先设置默认值 IsCustomDanmakuResolution(isCustomDanmakuResolution); return isCustomDanmakuResolution; } - return settingsEntity.IsCustomDanmakuResolution; + return appSettings.Danmaku.IsCustomDanmakuResolution; } /// @@ -131,10 +135,10 @@ /// /// /// - public bool IsCustomDanmakuResolution(ALLOW_STATUS isCustomResolution) + public bool IsCustomDanmakuResolution(AllowStatus isCustomResolution) { - settingsEntity.IsCustomDanmakuResolution = isCustomResolution; - return SetEntity(); + appSettings.Danmaku.IsCustomDanmakuResolution = isCustomResolution; + return SetSettings(); } /// @@ -143,13 +147,14 @@ /// public int GetDanmakuScreenWidth() { - if (settingsEntity.DanmakuScreenWidth == 0) + appSettings = GetSettings(); + if (appSettings.Danmaku.DanmakuScreenWidth == 0) { // 第一次获取,先设置默认值 SetDanmakuScreenWidth(danmakuScreenWidth); return danmakuScreenWidth; } - return settingsEntity.DanmakuScreenWidth; + return appSettings.Danmaku.DanmakuScreenWidth; } /// @@ -159,8 +164,8 @@ /// public bool SetDanmakuScreenWidth(int screenWidth) { - settingsEntity.DanmakuScreenWidth = screenWidth; - return SetEntity(); + appSettings.Danmaku.DanmakuScreenWidth = screenWidth; + return SetSettings(); } /// @@ -169,13 +174,14 @@ /// public int GetDanmakuScreenHeight() { - if (settingsEntity.DanmakuScreenHeight == 0) + appSettings = GetSettings(); + if (appSettings.Danmaku.DanmakuScreenHeight == 0) { // 第一次获取,先设置默认值 SetDanmakuScreenHeight(danmakuScreenHeight); return danmakuScreenHeight; } - return settingsEntity.DanmakuScreenHeight; + return appSettings.Danmaku.DanmakuScreenHeight; } /// @@ -185,8 +191,8 @@ /// public bool SetDanmakuScreenHeight(int screenHeight) { - settingsEntity.DanmakuScreenHeight = screenHeight; - return SetEntity(); + appSettings.Danmaku.DanmakuScreenHeight = screenHeight; + return SetSettings(); } /// @@ -195,13 +201,14 @@ /// public string GetDanmakuFontName() { - if (settingsEntity.DanmakuFontName == null) + appSettings = GetSettings(); + if (appSettings.Danmaku.DanmakuFontName == null) { // 第一次获取,先设置默认值 SetDanmakuFontName(danmakuFontName); return danmakuFontName; } - return settingsEntity.DanmakuFontName; + return appSettings.Danmaku.DanmakuFontName; } /// @@ -211,8 +218,8 @@ /// public bool SetDanmakuFontName(string danmakuFontName) { - settingsEntity.DanmakuFontName = danmakuFontName; - return SetEntity(); + appSettings.Danmaku.DanmakuFontName = danmakuFontName; + return SetSettings(); } /// @@ -221,13 +228,14 @@ /// public int GetDanmakuFontSize() { - if (settingsEntity.DanmakuFontSize == 0) + appSettings = GetSettings(); + if (appSettings.Danmaku.DanmakuFontSize == 0) { // 第一次获取,先设置默认值 SetDanmakuFontSize(danmakuFontSize); return danmakuFontSize; } - return settingsEntity.DanmakuFontSize; + return appSettings.Danmaku.DanmakuFontSize; } /// @@ -237,8 +245,8 @@ /// public bool SetDanmakuFontSize(int danmakuFontSize) { - settingsEntity.DanmakuFontSize = danmakuFontSize; - return SetEntity(); + appSettings.Danmaku.DanmakuFontSize = danmakuFontSize; + return SetSettings(); } /// @@ -247,13 +255,14 @@ /// public int GetDanmakuLineCount() { - if (settingsEntity.DanmakuLineCount == 0) + appSettings = GetSettings(); + if (appSettings.Danmaku.DanmakuLineCount == 0) { // 第一次获取,先设置默认值 SetDanmakuLineCount(danmakuLineCount); return danmakuLineCount; } - return settingsEntity.DanmakuLineCount; + return appSettings.Danmaku.DanmakuLineCount; } /// @@ -263,8 +272,8 @@ /// public bool SetDanmakuLineCount(int danmakuLineCount) { - settingsEntity.DanmakuLineCount = danmakuLineCount; - return SetEntity(); + appSettings.Danmaku.DanmakuLineCount = danmakuLineCount; + return SetSettings(); } /// @@ -273,13 +282,14 @@ /// public DanmakuLayoutAlgorithm GetDanmakuLayoutAlgorithm() { - if (settingsEntity.DanmakuLayoutAlgorithm == 0) + appSettings = GetSettings(); + if (appSettings.Danmaku.DanmakuLayoutAlgorithm == 0) { // 第一次获取,先设置默认值 SetDanmakuLayoutAlgorithm(danmakuLayoutAlgorithm); return danmakuLayoutAlgorithm; } - return settingsEntity.DanmakuLayoutAlgorithm; + return appSettings.Danmaku.DanmakuLayoutAlgorithm; } /// @@ -289,10 +299,9 @@ /// public bool SetDanmakuLayoutAlgorithm(DanmakuLayoutAlgorithm danmakuLayoutAlgorithm) { - settingsEntity.DanmakuLayoutAlgorithm = danmakuLayoutAlgorithm; - return SetEntity(); + appSettings.Danmaku.DanmakuLayoutAlgorithm = danmakuLayoutAlgorithm; + return SetSettings(); } - } } diff --git a/src/Core/settings/Settings.network.cs b/src/DownKyi.Core/Settings/SettingsManager.Network.cs similarity index 69% rename from src/Core/settings/Settings.network.cs rename to src/DownKyi.Core/Settings/SettingsManager.Network.cs index 34a44d7..95675e2 100644 --- a/src/Core/settings/Settings.network.cs +++ b/src/DownKyi.Core/Settings/SettingsManager.Network.cs @@ -1,11 +1,11 @@ -using Core.aria2cNet.server; +using DownKyi.Core.Aria2cNet.Server; -namespace Core.settings +namespace DownKyi.Core.Settings { - public partial class Settings + public partial class SettingsManager { // 是否开启解除地区限制 - private readonly ALLOW_STATUS isLiftingOfRegion = ALLOW_STATUS.YES; + private readonly AllowStatus isLiftingOfRegion = AllowStatus.YES; // Aria服务器端口号 private readonly int ariaListenPort = 6800; @@ -29,24 +29,24 @@ namespace Core.settings private readonly AriaConfigFileAllocation ariaFileAllocation = AriaConfigFileAllocation.PREALLOC; // Aria HttpProxy代理 - private readonly ALLOW_STATUS isAriaHttpProxy = ALLOW_STATUS.NO; + private readonly AllowStatus isAriaHttpProxy = AllowStatus.NO; private readonly string ariaHttpProxy = ""; private readonly int ariaHttpProxyListenPort = 0; - /// /// 获取是否解除地区限制 /// /// - public ALLOW_STATUS IsLiftingOfRegion() + public AllowStatus IsLiftingOfRegion() { - if (settingsEntity.IsLiftingOfRegion == 0) + appSettings = GetSettings(); + if (appSettings.Network.IsLiftingOfRegion == 0) { // 第一次获取,先设置默认值 IsLiftingOfRegion(isLiftingOfRegion); return isLiftingOfRegion; } - return settingsEntity.IsLiftingOfRegion; + return appSettings.Network.IsLiftingOfRegion; } /// @@ -54,10 +54,10 @@ namespace Core.settings /// /// /// - public bool IsLiftingOfRegion(ALLOW_STATUS isLiftingOfRegion) + public bool IsLiftingOfRegion(AllowStatus isLiftingOfRegion) { - settingsEntity.IsLiftingOfRegion = isLiftingOfRegion; - return SetEntity(); + appSettings.Network.IsLiftingOfRegion = isLiftingOfRegion; + return SetSettings(); } /// @@ -66,13 +66,14 @@ namespace Core.settings /// public int GetAriaListenPort() { - if (settingsEntity.AriaListenPort == 0) + appSettings = GetSettings(); + if (appSettings.Network.AriaListenPort == 0) { // 第一次获取,先设置默认值 SetAriaListenPort(ariaListenPort); return ariaListenPort; } - return settingsEntity.AriaListenPort; + return appSettings.Network.AriaListenPort; } /// @@ -82,8 +83,8 @@ namespace Core.settings /// public bool SetAriaListenPort(int ariaListenPort) { - settingsEntity.AriaListenPort = ariaListenPort; - return SetEntity(); + appSettings.Network.AriaListenPort = ariaListenPort; + return SetSettings(); } /// @@ -92,13 +93,14 @@ namespace Core.settings /// public AriaConfigLogLevel GetAriaLogLevel() { - if (settingsEntity.AriaLogLevel == 0) + appSettings = GetSettings(); + if (appSettings.Network.AriaLogLevel == 0) { // 第一次获取,先设置默认值 SetAriaLogLevel(ariaLogLevel); return ariaLogLevel; } - return settingsEntity.AriaLogLevel; + return appSettings.Network.AriaLogLevel; } /// @@ -108,8 +110,8 @@ namespace Core.settings /// public bool SetAriaLogLevel(AriaConfigLogLevel ariaLogLevel) { - settingsEntity.AriaLogLevel = ariaLogLevel; - return SetEntity(); + appSettings.Network.AriaLogLevel = ariaLogLevel; + return SetSettings(); } /// @@ -118,13 +120,14 @@ namespace Core.settings /// public int GetAriaMaxConcurrentDownloads() { - if (settingsEntity.AriaMaxConcurrentDownloads == 0) + appSettings = GetSettings(); + if (appSettings.Network.AriaMaxConcurrentDownloads == 0) { // 第一次获取,先设置默认值 SetAriaMaxConcurrentDownloads(ariaMaxConcurrentDownloads); return ariaMaxConcurrentDownloads; } - return settingsEntity.AriaMaxConcurrentDownloads; + return appSettings.Network.AriaMaxConcurrentDownloads; } /// @@ -134,8 +137,8 @@ namespace Core.settings /// public bool SetAriaMaxConcurrentDownloads(int ariaMaxConcurrentDownloads) { - settingsEntity.AriaMaxConcurrentDownloads = ariaMaxConcurrentDownloads; - return SetEntity(); + appSettings.Network.AriaMaxConcurrentDownloads = ariaMaxConcurrentDownloads; + return SetSettings(); } /// @@ -144,13 +147,14 @@ namespace Core.settings /// public int GetAriaSplit() { - if (settingsEntity.AriaSplit == 0) + appSettings = GetSettings(); + if (appSettings.Network.AriaSplit == 0) { // 第一次获取,先设置默认值 SetAriaSplit(ariaSplit); return ariaSplit; } - return settingsEntity.AriaSplit; + return appSettings.Network.AriaSplit; } /// @@ -160,8 +164,8 @@ namespace Core.settings /// public bool SetAriaSplit(int ariaSplit) { - settingsEntity.AriaSplit = ariaSplit; - return SetEntity(); + appSettings.Network.AriaSplit = ariaSplit; + return SetSettings(); } /// @@ -170,13 +174,14 @@ namespace Core.settings /// public int GetAriaMaxOverallDownloadLimit() { - if (settingsEntity.AriaMaxOverallDownloadLimit == 0) + appSettings = GetSettings(); + if (appSettings.Network.AriaMaxOverallDownloadLimit == 0) { // 第一次获取,先设置默认值 SetAriaMaxOverallDownloadLimit(ariaMaxOverallDownloadLimit); return ariaMaxOverallDownloadLimit; } - return settingsEntity.AriaMaxOverallDownloadLimit; + return appSettings.Network.AriaMaxOverallDownloadLimit; } /// @@ -186,8 +191,8 @@ namespace Core.settings /// public bool SetAriaMaxOverallDownloadLimit(int ariaMaxOverallDownloadLimit) { - settingsEntity.AriaMaxOverallDownloadLimit = ariaMaxOverallDownloadLimit; - return SetEntity(); + appSettings.Network.AriaMaxOverallDownloadLimit = ariaMaxOverallDownloadLimit; + return SetSettings(); } /// @@ -196,13 +201,14 @@ namespace Core.settings /// public int GetAriaMaxDownloadLimit() { - if (settingsEntity.AriaMaxDownloadLimit == 0) + appSettings = GetSettings(); + if (appSettings.Network.AriaMaxDownloadLimit == 0) { // 第一次获取,先设置默认值 SetAriaMaxDownloadLimit(ariaMaxDownloadLimit); return ariaMaxDownloadLimit; } - return settingsEntity.AriaMaxDownloadLimit; + return appSettings.Network.AriaMaxDownloadLimit; } /// @@ -212,8 +218,8 @@ namespace Core.settings /// public bool SetAriaMaxDownloadLimit(int ariaMaxDownloadLimit) { - settingsEntity.AriaMaxDownloadLimit = ariaMaxDownloadLimit; - return SetEntity(); + appSettings.Network.AriaMaxDownloadLimit = ariaMaxDownloadLimit; + return SetSettings(); } /// @@ -222,13 +228,14 @@ namespace Core.settings /// public AriaConfigFileAllocation GetAriaFileAllocation() { - if (settingsEntity.AriaFileAllocation == 0) + appSettings = GetSettings(); + if (appSettings.Network.AriaFileAllocation == 0) { // 第一次获取,先设置默认值 SetAriaFileAllocation(ariaFileAllocation); return ariaFileAllocation; } - return settingsEntity.AriaFileAllocation; + return appSettings.Network.AriaFileAllocation; } /// @@ -238,23 +245,24 @@ namespace Core.settings /// public bool SetAriaFileAllocation(AriaConfigFileAllocation ariaFileAllocation) { - settingsEntity.AriaFileAllocation = ariaFileAllocation; - return SetEntity(); + appSettings.Network.AriaFileAllocation = ariaFileAllocation; + return SetSettings(); } /// /// 获取是否开启Aria http代理 /// /// - public ALLOW_STATUS IsAriaHttpProxy() + public AllowStatus IsAriaHttpProxy() { - if (settingsEntity.IsAriaHttpProxy == 0) + appSettings = GetSettings(); + if (appSettings.Network.IsAriaHttpProxy == 0) { // 第一次获取,先设置默认值 IsAriaHttpProxy(isAriaHttpProxy); return isAriaHttpProxy; } - return settingsEntity.IsAriaHttpProxy; + return appSettings.Network.IsAriaHttpProxy; } /// @@ -262,10 +270,10 @@ namespace Core.settings /// /// /// - public bool IsAriaHttpProxy(ALLOW_STATUS isAriaHttpProxy) + public bool IsAriaHttpProxy(AllowStatus isAriaHttpProxy) { - settingsEntity.IsAriaHttpProxy = isAriaHttpProxy; - return SetEntity(); + appSettings.Network.IsAriaHttpProxy = isAriaHttpProxy; + return SetSettings(); } /// @@ -274,13 +282,14 @@ namespace Core.settings /// public string GetAriaHttpProxy() { - if (settingsEntity.AriaHttpProxy == null) + appSettings = GetSettings(); + if (appSettings.Network.AriaHttpProxy == null) { // 第一次获取,先设置默认值 SetAriaHttpProxy(ariaHttpProxy); return ariaHttpProxy; } - return settingsEntity.AriaHttpProxy; + return appSettings.Network.AriaHttpProxy; } /// @@ -290,8 +299,8 @@ namespace Core.settings /// public bool SetAriaHttpProxy(string ariaHttpProxy) { - settingsEntity.AriaHttpProxy = ariaHttpProxy; - return SetEntity(); + appSettings.Network.AriaHttpProxy = ariaHttpProxy; + return SetSettings(); } /// @@ -300,13 +309,14 @@ namespace Core.settings /// public int GetAriaHttpProxyListenPort() { - if (settingsEntity.AriaHttpProxyListenPort == 0) + appSettings = GetSettings(); + if (appSettings.Network.AriaHttpProxyListenPort == 0) { // 第一次获取,先设置默认值 SetAriaHttpProxyListenPort(ariaHttpProxyListenPort); return ariaHttpProxyListenPort; } - return settingsEntity.AriaHttpProxyListenPort; + return appSettings.Network.AriaHttpProxyListenPort; } /// @@ -316,8 +326,8 @@ namespace Core.settings /// public bool SetAriaHttpProxyListenPort(int ariaHttpProxyListenPort) { - settingsEntity.AriaHttpProxyListenPort = ariaHttpProxyListenPort; - return SetEntity(); + appSettings.Network.AriaHttpProxyListenPort = ariaHttpProxyListenPort; + return SetSettings(); } } diff --git a/src/DownKyi.Core/Settings/SettingsManager.UserInfo.cs b/src/DownKyi.Core/Settings/SettingsManager.UserInfo.cs new file mode 100644 index 0000000..fda9352 --- /dev/null +++ b/src/DownKyi.Core/Settings/SettingsManager.UserInfo.cs @@ -0,0 +1,44 @@ +using DownKyi.Core.Settings.Models; + +namespace DownKyi.Core.Settings +{ + public partial class SettingsManager + { + // 登录用户的mid + private readonly UserInfoSettings userInfo = new UserInfoSettings + { + Mid = -1, + Name = "", + IsLogin = false, + IsVip = false + }; + + /// + /// 获取登录用户信息 + /// + /// + public UserInfoSettings GetUserInfo() + { + appSettings = GetSettings(); + if (appSettings.UserInfo == null) + { + // 第一次获取,先设置默认值 + SetUserInfo(userInfo); + return userInfo; + } + return appSettings.UserInfo; + } + + /// + /// 设置中保存登录用户的信息,在index刷新用户状态时使用 + /// + /// + /// + public bool SetUserInfo(UserInfoSettings userInfo) + { + appSettings.UserInfo = userInfo; + return SetSettings(); + } + + } +} diff --git a/src/Core/settings/Settings.video.cs b/src/DownKyi.Core/Settings/SettingsManager.Video.cs similarity index 50% rename from src/Core/settings/Settings.video.cs rename to src/DownKyi.Core/Settings/SettingsManager.Video.cs index 63e537b..1b6700c 100644 --- a/src/Core/settings/Settings.video.cs +++ b/src/DownKyi.Core/Settings/SettingsManager.Video.cs @@ -1,6 +1,10 @@ -namespace Core.settings +using System; +using System.Collections.Generic; +using System.IO; + +namespace DownKyi.Core.Settings { - public partial class Settings + public partial class SettingsManager { // 设置优先下载的视频编码 private readonly VideoCodecs videoCodecs = VideoCodecs.AVC; @@ -8,27 +12,32 @@ // 设置优先下载画质 private readonly int quality = 120; + // 设置优先下载音质 + private readonly int audioQuality = 30280; + // 是否在下载的视频前增加序号 - private readonly ALLOW_STATUS isAddOrder = ALLOW_STATUS.NO; + private readonly AllowStatus isAddOrder = AllowStatus.NO; // 是否下载flv视频后转码为mp4 - private readonly ALLOW_STATUS isTranscodingFlvToMp4 = ALLOW_STATUS.YES; + private readonly AllowStatus isTranscodingFlvToMp4 = AllowStatus.YES; // 默认下载目录 - private readonly string saveVideoRootPath = "./Media"; + private readonly string saveVideoRootPath = Path.Combine(Environment.CurrentDirectory, "Media"); + + // 历史下载目录 + private readonly List historyVideoRootPaths = new List(); // 是否使用默认下载目录,如果是,则每次点击下载选中项时不再询问下载目录 - private readonly ALLOW_STATUS isUseSaveVideoRootPath = ALLOW_STATUS.NO; + private readonly AllowStatus isUseSaveVideoRootPath = AllowStatus.NO; // 是否为不同视频分别创建文件夹 - private readonly ALLOW_STATUS isCreateFolderForMedia = ALLOW_STATUS.YES; + private readonly AllowStatus isCreateFolderForMedia = AllowStatus.YES; // 是否在下载视频的同时下载弹幕 - private readonly ALLOW_STATUS isDownloadDanmaku = ALLOW_STATUS.YES; + private readonly AllowStatus isDownloadDanmaku = AllowStatus.YES; // 是否在下载视频的同时下载封面 - private readonly ALLOW_STATUS isDownloadCover = ALLOW_STATUS.YES; - + private readonly AllowStatus isDownloadCover = AllowStatus.YES; /// /// 获取优先下载的视频编码 @@ -36,13 +45,14 @@ /// public VideoCodecs GetVideoCodecs() { - if (settingsEntity.VideoCodecs == 0) + appSettings = GetSettings(); + if (appSettings.Video.VideoCodecs == 0) { // 第一次获取,先设置默认值 SetVideoCodecs(videoCodecs); return videoCodecs; } - return settingsEntity.VideoCodecs; + return appSettings.Video.VideoCodecs; } /// @@ -52,8 +62,8 @@ /// public bool SetVideoCodecs(VideoCodecs videoCodecs) { - settingsEntity.VideoCodecs = videoCodecs; - return SetEntity(); + appSettings.Video.VideoCodecs = videoCodecs; + return SetSettings(); } /// @@ -62,13 +72,14 @@ /// public int GetQuality() { - if (settingsEntity.Quality == 0) + appSettings = GetSettings(); + if (appSettings.Video.Quality == 0) { // 第一次获取,先设置默认值 SetQuality(quality); return quality; } - return settingsEntity.Quality; + return appSettings.Video.Quality; } /// @@ -78,23 +89,51 @@ /// public bool SetQuality(int quality) { - settingsEntity.Quality = quality; - return SetEntity(); + appSettings.Video.Quality = quality; + return SetSettings(); + } + + /// + /// 获取优先下载音质 + /// + /// + public int GetAudioQuality() + { + appSettings = GetSettings(); + if (appSettings.Video.AudioQuality == 0) + { + // 第一次获取,先设置默认值 + SetAudioQuality(audioQuality); + return audioQuality; + } + return appSettings.Video.AudioQuality; + } + + /// + /// 设置优先下载音质 + /// + /// + /// + public bool SetAudioQuality(int quality) + { + appSettings.Video.AudioQuality = quality; + return SetSettings(); } /// /// 获取是否给视频增加序号 /// /// - public ALLOW_STATUS IsAddOrder() + public AllowStatus IsAddOrder() { - if (settingsEntity.IsAddOrder == 0) + appSettings = GetSettings(); + if (appSettings.Video.IsAddOrder == 0) { // 第一次获取,先设置默认值 IsAddOrder(isAddOrder); return isAddOrder; } - return settingsEntity.IsAddOrder; + return appSettings.Video.IsAddOrder; } /// @@ -102,25 +141,26 @@ /// /// /// - public bool IsAddOrder(ALLOW_STATUS isAddOrder) + public bool IsAddOrder(AllowStatus isAddOrder) { - settingsEntity.IsAddOrder = isAddOrder; - return SetEntity(); + appSettings.Video.IsAddOrder = isAddOrder; + return SetSettings(); } /// /// 获取是否下载flv视频后转码为mp4 /// /// - public ALLOW_STATUS IsTranscodingFlvToMp4() + public AllowStatus IsTranscodingFlvToMp4() { - if (settingsEntity.IsTranscodingFlvToMp4 == 0) + appSettings = GetSettings(); + if (appSettings.Video.IsTranscodingFlvToMp4 == 0) { // 第一次获取,先设置默认值 IsTranscodingFlvToMp4(isTranscodingFlvToMp4); return isTranscodingFlvToMp4; } - return settingsEntity.IsTranscodingFlvToMp4; + return appSettings.Video.IsTranscodingFlvToMp4; } /// @@ -128,10 +168,10 @@ /// /// /// - public bool IsTranscodingFlvToMp4(ALLOW_STATUS isTranscodingFlvToMp4) + public bool IsTranscodingFlvToMp4(AllowStatus isTranscodingFlvToMp4) { - settingsEntity.IsTranscodingFlvToMp4 = isTranscodingFlvToMp4; - return SetEntity(); + appSettings.Video.IsTranscodingFlvToMp4 = isTranscodingFlvToMp4; + return SetSettings(); } /// @@ -140,13 +180,14 @@ /// public string GetSaveVideoRootPath() { - if (settingsEntity.SaveVideoRootPath == null) + appSettings = GetSettings(); + if (appSettings.Video.SaveVideoRootPath == null) { // 第一次获取,先设置默认值 SetSaveVideoRootPath(saveVideoRootPath); return saveVideoRootPath; } - return settingsEntity.SaveVideoRootPath; + return appSettings.Video.SaveVideoRootPath; } /// @@ -156,23 +197,51 @@ /// public bool SetSaveVideoRootPath(string path) { - settingsEntity.SaveVideoRootPath = path; - return SetEntity(); + appSettings.Video.SaveVideoRootPath = path; + return SetSettings(); + } + + /// + /// 获取历史下载目录 + /// + /// + public List GetHistoryVideoRootPaths() + { + appSettings = GetSettings(); + if (appSettings.Video.HistoryVideoRootPaths == null) + { + // 第一次获取,先设置默认值 + SetHistoryVideoRootPaths(historyVideoRootPaths); + return historyVideoRootPaths; + } + return appSettings.Video.HistoryVideoRootPaths; + } + + /// + /// 设置历史下载目录 + /// + /// + /// + public bool SetHistoryVideoRootPaths(List historyPaths) + { + appSettings.Video.HistoryVideoRootPaths = historyPaths; + return SetSettings(); } /// /// 获取是否使用默认下载目录 /// /// - public ALLOW_STATUS IsUseSaveVideoRootPath() + public AllowStatus IsUseSaveVideoRootPath() { - if (settingsEntity.IsUseSaveVideoRootPath == 0) + appSettings = GetSettings(); + if (appSettings.Video.IsUseSaveVideoRootPath == 0) { // 第一次获取,先设置默认值 IsUseSaveVideoRootPath(isUseSaveVideoRootPath); return isUseSaveVideoRootPath; } - return settingsEntity.IsUseSaveVideoRootPath; + return appSettings.Video.IsUseSaveVideoRootPath; } /// @@ -180,25 +249,26 @@ /// /// /// - public bool IsUseSaveVideoRootPath(ALLOW_STATUS isUseSaveVideoRootPath) + public bool IsUseSaveVideoRootPath(AllowStatus isUseSaveVideoRootPath) { - settingsEntity.IsUseSaveVideoRootPath = isUseSaveVideoRootPath; - return SetEntity(); + appSettings.Video.IsUseSaveVideoRootPath = isUseSaveVideoRootPath; + return SetSettings(); } /// /// 获取是否为不同视频分别创建文件夹 /// /// - public ALLOW_STATUS IsCreateFolderForMedia() + public AllowStatus IsCreateFolderForMedia() { - if (settingsEntity.IsCreateFolderForMedia == 0) + appSettings = GetSettings(); + if (appSettings.Video.IsCreateFolderForMedia == 0) { // 第一次获取,先设置默认值 IsCreateFolderForMedia(isCreateFolderForMedia); return isCreateFolderForMedia; } - return settingsEntity.IsCreateFolderForMedia; + return appSettings.Video.IsCreateFolderForMedia; } /// @@ -206,25 +276,26 @@ /// /// /// - public bool IsCreateFolderForMedia(ALLOW_STATUS isCreateFolderForMedia) + public bool IsCreateFolderForMedia(AllowStatus isCreateFolderForMedia) { - settingsEntity.IsCreateFolderForMedia = isCreateFolderForMedia; - return SetEntity(); + appSettings.Video.IsCreateFolderForMedia = isCreateFolderForMedia; + return SetSettings(); } /// /// 获取是否在下载视频的同时下载弹幕 /// /// - public ALLOW_STATUS IsDownloadDanmaku() + public AllowStatus IsDownloadDanmaku() { - if (settingsEntity.IsDownloadDanmaku == 0) + appSettings = GetSettings(); + if (appSettings.Video.IsDownloadDanmaku == 0) { // 第一次获取,先设置默认值 IsDownloadDanmaku(isDownloadDanmaku); return isDownloadDanmaku; } - return settingsEntity.IsDownloadDanmaku; + return appSettings.Video.IsDownloadDanmaku; } /// @@ -232,25 +303,26 @@ /// /// /// - public bool IsDownloadDanmaku(ALLOW_STATUS isDownloadDanmaku) + public bool IsDownloadDanmaku(AllowStatus isDownloadDanmaku) { - settingsEntity.IsDownloadDanmaku = isDownloadDanmaku; - return SetEntity(); + appSettings.Video.IsDownloadDanmaku = isDownloadDanmaku; + return SetSettings(); } /// /// 获取是否在下载视频的同时下载封面 /// /// - public ALLOW_STATUS IsDownloadCover() + public AllowStatus IsDownloadCover() { - if (settingsEntity.IsDownloadCover == 0) + appSettings = GetSettings(); + if (appSettings.Video.IsDownloadCover == 0) { // 第一次获取,先设置默认值 IsDownloadCover(isDownloadCover); return isDownloadCover; } - return settingsEntity.IsDownloadCover; + return appSettings.Video.IsDownloadCover; } /// @@ -258,16 +330,11 @@ /// /// /// - public bool IsDownloadCover(ALLOW_STATUS isDownloadCover) + public bool IsDownloadCover(AllowStatus isDownloadCover) { - settingsEntity.IsDownloadCover = isDownloadCover; - return SetEntity(); + appSettings.Video.IsDownloadCover = isDownloadCover; + return SetSettings(); } - - - - - } } diff --git a/src/DownKyi.Core/Settings/SettingsManager.cs b/src/DownKyi.Core/Settings/SettingsManager.cs new file mode 100644 index 0000000..b511e84 --- /dev/null +++ b/src/DownKyi.Core/Settings/SettingsManager.cs @@ -0,0 +1,81 @@ +using DownKyi.Core.Settings.Models; +using Newtonsoft.Json; +using System; +using System.IO; + +namespace DownKyi.Core.Settings +{ + public partial class SettingsManager + { + private static SettingsManager instance; + + /// + /// 获取SettingsManager实例 + /// + /// + public static SettingsManager GetInstance() + { + if (instance == null) + { + instance = new SettingsManager(); + } + return instance; + } + + /// + /// 隐藏Settings()方法,必须使用单例模式 + /// + private SettingsManager() + { + appSettings = GetSettings(); + } + + // 内存中保存一份配置 + private AppSettings appSettings; + + // 设置的配置文件 + private readonly string settingsName = Storage.StorageManager.GetSettings(); + + /// + /// 获取AppSettingsModel + /// + /// + private AppSettings GetSettings() + { + try + { + StreamReader streamReader = File.OpenText(settingsName); + string jsonWordTemplate = streamReader.ReadToEnd(); + streamReader.Close(); + + return JsonConvert.DeserializeObject(jsonWordTemplate); + } + catch (Exception e) + { + Logging.LogManager.Error(e); + return new AppSettings(); + } + } + + /// + /// 设置AppSettingsModel + /// + /// + private bool SetSettings() + { + string json = JsonConvert.SerializeObject(appSettings, Formatting.Indented); + + try + { + File.WriteAllText(settingsName, json); + return true; + } + catch (Exception e) + { + Logging.LogManager.Error(e); + return false; + } + } + + } +} diff --git a/src/DownKyi.Core/Settings/VideoCodecs.cs b/src/DownKyi.Core/Settings/VideoCodecs.cs new file mode 100644 index 0000000..4694aa0 --- /dev/null +++ b/src/DownKyi.Core/Settings/VideoCodecs.cs @@ -0,0 +1,9 @@ +namespace DownKyi.Core.Settings +{ + public enum VideoCodecs + { + NONE = 0, + AVC, + HEVC + } +} diff --git a/src/DownKyi.Core/Storage/Constant.cs b/src/DownKyi.Core/Storage/Constant.cs new file mode 100644 index 0000000..2fe9aa4 --- /dev/null +++ b/src/DownKyi.Core/Storage/Constant.cs @@ -0,0 +1,65 @@ +using System; + +namespace DownKyi.Core.Storage +{ + /// + /// 存储到本地时使用的一些常量 + /// + internal static class Constant + { + // 根目录 + private static string Root { get; } = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/Downkyi"; + + // 日志 + public static string Logs { get; } = $"{Root}/Logs"; + + // 数据库 + public static string Database { get; } = $"{Root}/Storage"; + + // 历史(搜索、下载) (加密) + public static string History { get; } = $"{Database}/History.db"; + + // 配置 + public static string Config { get; } = $"{Root}/Config"; + + // 设置 + public static string Settings { get; } = $"{Config}/Settings.json"; + + // 登录cookies + public static string Login { get; } = $"{Config}/Login"; + + // Bilibili + private static string Bilibili { get; } = $"{Root}/Bilibili"; + + // 弹幕 + public static string Danmaku { get; } = $"{Bilibili}/Danmakus"; + + // 字幕 + public static string Subtitle { get; } = $"{Bilibili}/Subtitle"; + + // 评论 + // TODO + + // 头图 + public static string Toutu { get; } = $"{Bilibili}/Toutu"; + + // 封面 + public static string Cover { get; } = $"{Bilibili}/Cover"; + + // 封面文件索引 + public static string CoverIndex { get; } = $"{Cover}/Index.db"; + + // 视频快照 + public static string Snapshot { get; } = $"{Bilibili}/Snapshot"; + + // 视频快照文件索引 + public static string SnapshotIndex { get; } = $"{Cover}/Index.db"; + + // 用户头像 + public static string Header { get; } = $"{Bilibili}/Header"; + + // 用户头像文件索引 + public static string HeaderIndex { get; } = $"{Header}/Index.db"; + + } +} diff --git a/src/DownKyi.Core/Storage/Database/Cover.cs b/src/DownKyi.Core/Storage/Database/Cover.cs new file mode 100644 index 0000000..47c6da7 --- /dev/null +++ b/src/DownKyi.Core/Storage/Database/Cover.cs @@ -0,0 +1,11 @@ +namespace DownKyi.Core.Storage.Database +{ + public class Cover + { + public long Avid { get; set; } + public string Bvid { get; set; } + public long Cid { get; set; } + public string Url { get; set; } + public string Md5 { get; set; } + } +} diff --git a/src/DownKyi.Core/Storage/Database/CoverDb.cs b/src/DownKyi.Core/Storage/Database/CoverDb.cs new file mode 100644 index 0000000..bcaea92 --- /dev/null +++ b/src/DownKyi.Core/Storage/Database/CoverDb.cs @@ -0,0 +1,130 @@ +using System.Collections.Generic; + +namespace DownKyi.Core.Storage.Database +{ + public class CoverDb + { + private const string key = "b5018ecc-09d1-4da2-aa49-4625e41e623e"; + private readonly DbHelper dbHelper = new DbHelper(StorageManager.GetCoverIndex(), key); + + public CoverDb() + { + CreateTable(); + } + + /// + /// 关闭数据库连接 + /// + public void Close() + { + dbHelper.Close(); + } + + /// + /// 插入新的数据 + /// + /// + public void Insert(Cover cover) + { + string sql = $"insert into cover values ({cover.Avid}, '{cover.Bvid}', {cover.Cid}, '{cover.Url}', '{cover.Md5}')"; + dbHelper.ExecuteNonQuery(sql); + } + + /// + /// 更新数据,以url检索 + /// + /// + public void Update(Cover cover) + { + string sql = $"update cover set avid={cover.Avid}, bvid='{cover.Bvid}', cid={cover.Cid}, md5='{cover.Md5}' where url glob '{cover.Url}'"; + dbHelper.ExecuteNonQuery(sql); + } + + /// + /// 查询所有数据 + /// + /// + public List QueryAll() + { + string sql = $"select * from cover"; + return Query(sql); + } + + /// + /// 查询url对应的数据 + /// + /// + /// + public Cover QueryByUrl(string url) + { + string sql = $"select * from cover where url glob '{url}'"; + var query = Query(sql); + + if (query.Count > 0) + { + return query[0]; + } + else + { + return null; + } + } + + /// + /// 查询md5对应的数据 + /// + /// + /// + public Cover QueryByMd5(string md5) + { + string sql = $"select * from cover where md5 glob '{md5}'"; + var query = Query(sql); + + if (query.Count > 0) + { + return query[0]; + } + else + { + return null; + } + } + + /// + /// 查询数据 + /// + /// + /// + private List Query(string sql) + { + List covers = new List(); + + dbHelper.ExecuteQuery(sql, reader => + { + while (reader.Read()) + { + Cover cover = new Cover + { + Avid = (long)reader["avid"], + Bvid = (string)reader["bvid"], + Cid = (long)reader["cid"], + Url = (string)reader["url"], + Md5 = (string)reader["md5"] + }; + covers.Add(cover); + } + }); + return covers; + } + + /// + /// 如果表不存在则创建表 + /// + private void CreateTable() + { + string sql = "create table if not exists cover (avid unsigned big int, bvid varchar(20), cid unsigned big int, url varchar(255) unique, md5 varchar(32) unique)"; + dbHelper.ExecuteNonQuery(sql); + } + + } +} diff --git a/src/DownKyi.Core/Storage/Database/DbHelper.cs b/src/DownKyi.Core/Storage/Database/DbHelper.cs new file mode 100644 index 0000000..d2c67af --- /dev/null +++ b/src/DownKyi.Core/Storage/Database/DbHelper.cs @@ -0,0 +1,104 @@ +using System; +using System.Data.SQLite; + +namespace DownKyi.Core.Storage.Database +{ + public class DbHelper + { + private readonly SQLiteConnection conn; + + /// + /// 创建一个数据库 + /// + /// + public DbHelper(string dbPath) + { + string connStr = $"Data Source={dbPath};Version=3;"; + conn = new SQLiteConnection(connStr); + } + + /// + /// 创建一个带密码的数据库 + /// + /// + /// + public DbHelper(string dbPath, string secretKey) + { + string connStr = $"Data Source={dbPath};Version=3;"; + conn = new SQLiteConnection(connStr); + conn.SetPassword(secretKey); + } + + /// + /// 连接是否开启 + /// + /// + public bool IsOpen() + { + return conn.State == System.Data.ConnectionState.Open; + } + + /// + /// 开启连接 + /// + public void Open() + { + if (!IsOpen()) + { + conn.Open(); + } + } + + /// + /// 关闭数据库 + /// + public void Close() + { + if (IsOpen()) + { + conn.Close(); + } + } + + /// + /// 执行一条SQL语句 + /// + /// + public void ExecuteNonQuery(string sql) + { + lock (conn) + { + Open(); + using (var tr = conn.BeginTransaction()) + { + using (var command = conn.CreateCommand()) + { + command.CommandText = sql; + command.ExecuteNonQuery(); + } + tr.Commit(); + } + } + } + + /// + /// 执行一条SQL语句,并执行提供的操作,一般用于查询 + /// + /// + /// + public void ExecuteQuery(string sql, Action action) + { + lock (conn) + { + Open(); + using (var command = conn.CreateCommand()) + { + command.CommandText = sql; + var reader = command.ExecuteReader(); + action(reader); + } + } + } + + } +} diff --git a/src/DownKyi.Core/Storage/Database/Header.cs b/src/DownKyi.Core/Storage/Database/Header.cs new file mode 100644 index 0000000..bcabba0 --- /dev/null +++ b/src/DownKyi.Core/Storage/Database/Header.cs @@ -0,0 +1,10 @@ +namespace DownKyi.Core.Storage.Database +{ + public class Header + { + public long Mid { get; set; } + public string Name { get; set; } + public string Url { get; set; } + public string Md5 { get; set; } + } +} diff --git a/src/DownKyi.Core/Storage/Database/HeaderDb.cs b/src/DownKyi.Core/Storage/Database/HeaderDb.cs new file mode 100644 index 0000000..6cb4500 --- /dev/null +++ b/src/DownKyi.Core/Storage/Database/HeaderDb.cs @@ -0,0 +1,110 @@ +using System.Collections.Generic; + +namespace DownKyi.Core.Storage.Database +{ + public class HeaderDb + { + private const string key = "7c1f1f40-7cdf-4d11-ad28-f0137a3c5308"; + private readonly DbHelper dbHelper = new DbHelper(StorageManager.GetHeaderIndex(), key); + + public HeaderDb() + { + CreateTable(); + } + + /// + /// 关闭数据库连接 + /// + public void Close() + { + dbHelper.Close(); + } + + /// + /// 插入新的数据 + /// + /// + public void Insert(Header header) + { + string sql = $"insert into header values ({header.Mid}, '{header.Name}', '{header.Url}', '{header.Md5}')"; + dbHelper.ExecuteNonQuery(sql); + } + + /// + /// 更新数据 + /// + /// + public void Update(Header header) + { + string sql = $"update header set name='{header.Name}', url='{header.Url}', md5='{header.Md5}' where mid={header.Mid}"; + dbHelper.ExecuteNonQuery(sql); + } + + /// + /// 查询所有数据 + /// + /// + public List
QueryAll() + { + string sql = $"select * from header"; + return Query(sql); + } + + /// + /// 查询mid对应的数据 + /// + /// + /// + public Header QueryByMid(long mid) + { + string sql = $"select * from header where mid={mid}"; + var query = Query(sql); + + if (query.Count > 0) + { + return query[0]; + } + else + { + return null; + } + } + + + /// + /// 查询数据 + /// + /// + /// + private List
Query(string sql) + { + List
headers = new List
(); + + dbHelper.ExecuteQuery(sql, reader => + { + while (reader.Read()) + { + Header header = new Header + { + Mid = (long)reader["mid"], + Name = (string)reader["name"], + Url = (string)reader["url"], + Md5=(string)reader["md5"] + }; + headers.Add(header); + } + }); + return headers; + } + + /// + /// 如果表不存在则创建表 + /// + private void CreateTable() + { + string sql = "create table if not exists header (mid unsigned big int unique, name varchar(255), url varchar(255), md5 varchar(32))"; + dbHelper.ExecuteNonQuery(sql); + } + + } +} diff --git a/src/DownKyi.Core/Storage/StorageCover.cs b/src/DownKyi.Core/Storage/StorageCover.cs new file mode 100644 index 0000000..ae58849 --- /dev/null +++ b/src/DownKyi.Core/Storage/StorageCover.cs @@ -0,0 +1,208 @@ +using DownKyi.Core.Logging; +using DownKyi.Core.Storage.Database; +using DownKyi.Core.Utils.Encryptor; +using System; +using System.Drawing; +using System.IO; +using System.Windows.Media.Imaging; + +namespace DownKyi.Core.Storage +{ + public class StorageCover + { + // 先判断本地有没有 + // 如果有 + // 则返回本地的图片路径 + // 如果没有 + // 则下载图片并返回本地的图片路径 + + /// + /// 获取封面缩略图 + /// + /// + /// + /// + /// + /// + /// + /// + public BitmapImage GetCoverThumbnail(long avid, string bvid, long cid, string url, int width, int height) + { + string header = GetCover(avid, bvid, cid, url); + + return GetGetCoverThumbnail(header, width, height); + } + + /// + /// 获取封面缩略图 + /// + /// + /// + /// + /// + public BitmapImage GetGetCoverThumbnail(string cover, int width, int height) + { + var bitmap = new Bitmap(cover); + var thumbnail = bitmap.GetThumbnailImage(width, height, null, IntPtr.Zero); + + return StorageUtils.BitmapToBitmapImage(new Bitmap(thumbnail)); + } + + /// + /// 获取封面 + /// + /// + /// + public string GetCover(string url) + { + return GetCover(0, "", 0, url); + } + + /// + /// 获取封面 + /// + /// + /// + /// + /// + /// + public string GetCover(long avid, string bvid, long cid, string url) + { + CoverDb coverDb = new CoverDb(); + var cover = coverDb.QueryByUrl(url); + + // 如果存在,直接返回 + // 如果不存在,则先下载 + if (cover != null) + { + string coverPath = $"{StorageManager.GetCover()}/{cover.Md5}"; + if (File.Exists(coverPath)) + { + Cover newCover = new Cover + { + Avid = avid, + Bvid = bvid, + Cid = cid, + Url = url, + Md5 = cover.Md5 + }; + coverDb.Update(newCover); + + coverDb.Close(); + return $"{StorageManager.GetCover()}/{cover.Md5}"; + } + else + { + string md5 = DownloadImage(url); + if (md5 != null) + { + Cover newCover = new Cover + { + Avid = avid, + Bvid = bvid, + Cid = cid, + Url = url, + Md5 = md5 + }; + coverDb.Update(newCover); + + coverDb.Close(); + return $"{StorageManager.GetCover()}/{md5}"; + } + else + { + coverDb.Close(); + return null; + } + } + } + else + { + string md5 = DownloadImage(url); + if (md5 != null) + { + Cover newCover = new Cover + { + Avid = avid, + Bvid = bvid, + Cid = cid, + Url = url, + Md5 = md5 + }; + coverDb.Insert(newCover); + + coverDb.Close(); + return $"{StorageManager.GetCover()}/{md5}"; + } + else + { + coverDb.Close(); + return null; + } + } + } + + /// + /// 下载图片 + /// + /// + /// + private string DownloadImage(string url) + { + string localFile = Path.GetTempPath() + Guid.NewGuid().ToString("N"); + + // 下载 + bool isSuccessed = StorageUtils.DownloadImage(url, localFile); + if (isSuccessed) + { + try + { + string md5 = Hash.GetMD5HashFromFile(localFile); + + if (File.Exists(localFile)) + { + File.Move(localFile, $"{StorageManager.GetCover()}/{md5}"); + + return md5; + } + else + { + return null; + } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("DownloadImage()发生异常: {0}", e); + LogManager.Error("StorageCover", e); + return null; + } + } + + return null; + } + + /// + /// 本地是否存在 + /// + /// + /// + public bool IsLocal(CoverDb coverDb, string url) + { + var cover = coverDb.QueryByUrl(url); + return cover != null; + } + + /// + /// 返回图片md5值 + /// + /// + /// + /// + public string LocalCover(CoverDb coverDb, string url) + { + var cover = coverDb.QueryByUrl(url); + return cover.Md5; + } + + } +} diff --git a/src/DownKyi.Core/Storage/StorageHeader.cs b/src/DownKyi.Core/Storage/StorageHeader.cs new file mode 100644 index 0000000..d80e438 --- /dev/null +++ b/src/DownKyi.Core/Storage/StorageHeader.cs @@ -0,0 +1,164 @@ +using DownKyi.Core.Logging; +using DownKyi.Core.Storage.Database; +using DownKyi.Core.Utils.Encryptor; +using System; +using System.Drawing; +using System.IO; +using System.Windows.Media.Imaging; + +namespace DownKyi.Core.Storage +{ + public class StorageHeader + { + // 先判断本地有没有 + // 如果有 + // 则返回本地的图片路径 + // 如果没有 + // 则下载图片并返回本地的图片路径 + + /// + /// 获取用户头像缩略图 + /// + /// + /// + /// + /// + /// + /// + public BitmapImage GetHeaderThumbnail(long mid, string name, string url, int width, int height) + { + string header = GetHeader(mid, name, url); + + return GetHeaderThumbnail(header, width, height); + } + + /// + /// 获取用户头像缩略图 + /// + /// + /// + /// + /// + public BitmapImage GetHeaderThumbnail(string header, int width, int height) + { + var bitmap = new Bitmap(header); + var thumbnail = bitmap.GetThumbnailImage(width, height, null, IntPtr.Zero); + + return StorageUtils.BitmapToBitmapImage(new Bitmap(thumbnail)); + } + + /// + /// 获取用户头像 + /// + /// + /// + public string GetHeader(long mid, string name, string url) + { + HeaderDb headerDb = new HeaderDb(); + var header = headerDb.QueryByMid(mid); + + if (header != null) + { + string headerPath = $"{StorageManager.GetHeader()}/{header.Md5}"; + if (File.Exists(headerPath)) + { + Header newHeader = new Header + { + Mid = mid, + Name = name, + Url = url, + Md5 = header.Md5 + }; + headerDb.Update(newHeader); + headerDb.Close(); + return $"{StorageManager.GetHeader()}/{header.Md5}"; + } + else + { + string md5 = DownloadImage(url); + if (md5 != null) + { + Header newHeader = new Header + { + Mid = mid, + Name = name, + Url = url, + Md5 = md5 + }; + headerDb.Insert(newHeader); + headerDb.Close(); + return $"{StorageManager.GetHeader()}/{md5}"; + } + else + { + headerDb.Close(); + return null; + } + } + } + else + { + string md5 = DownloadImage(url); + if (md5 != null) + { + Header newHeader = new Header + { + Mid = mid, + Name = name, + Url = url, + Md5 = md5 + }; + headerDb.Insert(newHeader); + headerDb.Close(); + return $"{StorageManager.GetHeader()}/{md5}"; + } + else + { + headerDb.Close(); + return null; + } + } + } + + + /// + /// 下载图片 + /// + /// + /// + private string DownloadImage(string url) + { + string localFile = Path.GetTempPath() + Guid.NewGuid().ToString("N"); + + // 下载 + bool isSuccessed = StorageUtils.DownloadImage(url, localFile); + if (isSuccessed) + { + try + { + string md5 = Hash.GetMD5HashFromFile(localFile); + + if (File.Exists(localFile)) + { + File.Move(localFile, $"{StorageManager.GetHeader()}/{md5}"); + + return md5; + } + else + { + return null; + } + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("DownloadImage()发生异常: {0}", e); + LogManager.Error("StorageHeader", e); + return null; + } + } + + return null; + } + + } +} diff --git a/src/DownKyi.Core/Storage/StorageManager.cs b/src/DownKyi.Core/Storage/StorageManager.cs new file mode 100644 index 0000000..7531ef3 --- /dev/null +++ b/src/DownKyi.Core/Storage/StorageManager.cs @@ -0,0 +1,136 @@ +using System.IO; + +namespace DownKyi.Core.Storage +{ + public static class StorageManager + { + /// + /// 获取历史记录的文件路径 + /// + /// + public static string GetHistory() + { + CreateDirectory(Constant.Database); + return Constant.History; + } + + /// + /// 获取设置的文件路径 + /// + /// + public static string GetSettings() + { + CreateDirectory(Constant.Config); + return Constant.Settings; + } + + /// + /// 获取登录cookies的文件路径 + /// + /// + public static string GetLogin() + { + CreateDirectory(Constant.Config); + return Constant.Login; + } + + /// + /// 获取弹幕的文件夹路径 + /// + /// + public static string GetDanmaku() + { + return CreateDirectory(Constant.Danmaku); + } + + /// + /// 获取字幕的文件夹路径 + /// + /// + public static string GetSubtitle() + { + return CreateDirectory(Constant.Subtitle); + } + + /// + /// 获取头图的文件夹路径 + /// + /// + public static string GetToutu() + { + return CreateDirectory(Constant.Toutu); + } + + /// + /// 获取封面的文件夹路径 + /// + /// + public static string GetCover() + { + return CreateDirectory(Constant.Cover); + } + + /// + /// 获取封面索引的文件路径 + /// + /// + public static string GetCoverIndex() + { + CreateDirectory(Constant.Cover); + return Constant.CoverIndex; + } + + /// + /// 获取视频快照的文件夹路径 + /// + /// + public static string GetSnapshot() + { + return CreateDirectory(Constant.Snapshot); + } + + /// + /// 获取视频快照索引的文件路径 + /// + /// + public static string GetSnapshotIndex() + { + CreateDirectory(Constant.Snapshot); + return Constant.SnapshotIndex; + } + + /// + /// 获取用户头像的文件夹路径 + /// + /// + public static string GetHeader() + { + return CreateDirectory(Constant.Header); + } + + /// + /// 获取用户头像索引的文件路径 + /// + /// + public static string GetHeaderIndex() + { + CreateDirectory(Constant.Header); + return Constant.HeaderIndex; + } + + + /// + /// 若文件夹不存在,则创建文件夹 + /// + /// + /// + private static string CreateDirectory(string directory) + { + if (!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + return directory; + } + } +} diff --git a/src/DownKyi.Core/Storage/StorageUtils.cs b/src/DownKyi.Core/Storage/StorageUtils.cs new file mode 100644 index 0000000..0b4ab9e --- /dev/null +++ b/src/DownKyi.Core/Storage/StorageUtils.cs @@ -0,0 +1,58 @@ +using DownKyi.Core.Logging; +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Net; +using System.Windows.Media.Imaging; + +namespace DownKyi.Core.Storage +{ + internal static class StorageUtils + { + /// + /// 下载图片 + /// + /// + /// + /// + public static bool DownloadImage(string url, string localFile) + { + try + { + WebClient mywebclient = new WebClient(); + mywebclient.DownloadFile(url, localFile); + } + catch (Exception e) + { + Utils.Debug.Console.PrintLine("DownloadImage()发生异常: {0}", e); + LogManager.Error("StorageUtils", e); + return false; + } + return true; + } + + /// + /// Bitmap转BitmapImage + /// + /// + /// + public static BitmapImage BitmapToBitmapImage(Bitmap bitmap) + { + BitmapImage result = new BitmapImage(); + using (MemoryStream stream = new MemoryStream()) + { + bitmap.Save(stream, ImageFormat.Bmp); + stream.Position = 0; + result.BeginInit(); + result.CacheOption = BitmapCacheOption.OnLoad; + result.StreamSource = stream; + result.EndInit(); + result.Freeze(); + } + return result; + } + + } + +} diff --git a/src/DownKyi.Core/Utils/Debug/Console.cs b/src/DownKyi.Core/Utils/Debug/Console.cs new file mode 100644 index 0000000..2a1a165 --- /dev/null +++ b/src/DownKyi.Core/Utils/Debug/Console.cs @@ -0,0 +1,139 @@ +namespace DownKyi.Core.Utils.Debug +{ + public static class Console + { + public static void PrintLine() + { +#if DEBUG + System.Console.WriteLine(); +#endif + } + + public static void PrintLine(float value) + { +#if DEBUG + System.Console.WriteLine(value); +#endif + } + + public static void PrintLine(int value) + { +#if DEBUG + System.Console.WriteLine(value); +#endif + } + + public static void PrintLine(uint value) + { +#if DEBUG + System.Console.WriteLine(value); +#endif + } + + public static void PrintLine(long value) + { +#if DEBUG + System.Console.WriteLine(value); +#endif + } + + public static void PrintLine(ulong value) + { +#if DEBUG + System.Console.WriteLine(value); +#endif + } + + public static void PrintLine(object value) + { +#if DEBUG + System.Console.WriteLine(value); +#endif + } + + public static void PrintLine(string value) + { +#if DEBUG + System.Console.WriteLine(value); +#endif + } + + public static void PrintLine(string format, object arg0) + { +#if DEBUG + System.Console.WriteLine(format, arg0); +#endif + } + + public static void PrintLine(string format, object arg0, object arg1) + { +#if DEBUG + System.Console.WriteLine(format, arg0, arg1); +#endif + } + + public static void PrintLine(string format, object arg0, object arg1, object arg2) + { +#if DEBUG + System.Console.WriteLine(format, arg0, arg1, arg2); +#endif + } + + public static void PrintLine(string format, object arg0, object arg1, object arg2, object arg3) + { +#if DEBUG + System.Console.WriteLine(format, arg0, arg1, arg2); +#endif + } + + public static void PrintLine(string format, params object[] arg) + { +#if DEBUG + System.Console.WriteLine(format, arg); +#endif + } + + public static void PrintLine(char[] buffer, int index, int count) + { +#if DEBUG + System.Console.WriteLine(buffer, index, count); +#endif + } + + public static void PrintLine(decimal value) + { +#if DEBUG + System.Console.WriteLine(value); +#endif + } + + public static void PrintLine(char[] buffer) + { +#if DEBUG + System.Console.WriteLine(buffer); +#endif + } + + public static void PrintLine(char value) + { +#if DEBUG + System.Console.WriteLine(value); +#endif + } + + public static void PrintLine(bool value) + { +#if DEBUG + System.Console.WriteLine(value); +#endif + } + + public static void PrintLine(double value) + { +#if DEBUG + System.Console.WriteLine(value); +#endif + } + + } +} diff --git a/src/Core/Encryptor.cs b/src/DownKyi.Core/Utils/Encryptor/Encryptor.File.cs similarity index 67% rename from src/Core/Encryptor.cs rename to src/DownKyi.Core/Utils/Encryptor/Encryptor.File.cs index 7083606..1a9b9a5 100644 --- a/src/Core/Encryptor.cs +++ b/src/DownKyi.Core/Utils/Encryptor/Encryptor.File.cs @@ -1,11 +1,10 @@ using System; using System.IO; using System.Security.Cryptography; -using System.Text; -namespace Core +namespace DownKyi.Core.Utils.Encryptor { - public static class Encryptor + public static partial class Encryptor { private const ulong FC_TAG = 0xFC010203040506CF; private const int BUFFER_SIZE = 128 * 1024; @@ -215,94 +214,6 @@ namespace Core return bytes; } - - /// - /// DES加密字符串 - /// - /// 待加密的字符串 - /// 加密密钥,要求为8位 - /// 加密成功返回加密后的字符串,失败返回源串 - public static string EncryptString(string encryptString, string encryptKey) - { - try - { - byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));//转换为字节 - byte[] rgbIV = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8)); - byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString); - DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();//实例化数据加密标准 - MemoryStream mStream = new MemoryStream();//实例化内存流 - //将数据流链接到加密转换的流 - CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write); - cStream.Write(inputByteArray, 0, inputByteArray.Length); - cStream.FlushFinalBlock(); - // 转base64 - return Convert.ToBase64String(mStream.ToArray()); - } - catch (Exception e) - { - Console.WriteLine("EncryptString()发生异常: {0}", e); - return encryptString; - } - } - - /// - /// DES解密字符串 - /// - /// 待解密的字符串 - /// 解密密钥,要求为8位,和加密密钥相同 - /// 解密成功返回解密后的字符串,失败返源串 - public static string DecryptString(string decryptString, string decryptKey) - { - try - { - byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey); - byte[] rgbIV = Encoding.UTF8.GetBytes(decryptKey); - byte[] inputByteArray = Convert.FromBase64String(decryptString); - DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider(); - MemoryStream mStream = new MemoryStream(); - CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write); - cStream.Write(inputByteArray, 0, inputByteArray.Length); - cStream.FlushFinalBlock(); - return Encoding.UTF8.GetString(mStream.ToArray()); - } - catch (Exception e) - { - Console.WriteLine("DecryptString()发生异常: {0}", e); - return decryptString; - } - } - - /// - /// 计算字符串MD5值 - /// - /// - /// - public static string GetMd5Hash(string input) - { - if (input == null) - { - return null; - } - - MD5 md5Hash = MD5.Create(); - - // 将输入字符串转换为字节数组并计算哈希数据 - byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); - - // 创建一个 Stringbuilder 来收集字节并创建字符串 - StringBuilder sBuilder = new StringBuilder(); - - // 循环遍历哈希数据的每一个字节并格式化为十六进制字符串 - for (int i = 0; i < data.Length; i++) - { - sBuilder.Append(data[i].ToString("x2")); - } - - // 返回十六进制字符串 - return sBuilder.ToString(); - } - - } /// diff --git a/src/DownKyi.Core/Utils/Encryptor/Encryptor.String.cs b/src/DownKyi.Core/Utils/Encryptor/Encryptor.String.cs new file mode 100644 index 0000000..87493f1 --- /dev/null +++ b/src/DownKyi.Core/Utils/Encryptor/Encryptor.String.cs @@ -0,0 +1,70 @@ +using DownKyi.Core.Logging; +using System; +using System.IO; +using System.Security.Cryptography; +using System.Text; + +namespace DownKyi.Core.Utils.Encryptor +{ + public static partial class Encryptor + { + /// + /// DES加密字符串 + /// + /// 待加密的字符串 + /// 加密密钥,要求为8位 + /// 加密成功返回加密后的字符串,失败返回源串 + public static string EncryptString(string encryptString, string encryptKey) + { + try + { + byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));//转换为字节 + byte[] rgbIV = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8)); + byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString); + DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();//实例化数据加密标准 + MemoryStream mStream = new MemoryStream();//实例化内存流 + //将数据流链接到加密转换的流 + CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write); + cStream.Write(inputByteArray, 0, inputByteArray.Length); + cStream.FlushFinalBlock(); + // 转base64 + return Convert.ToBase64String(mStream.ToArray()); + } + catch (Exception e) + { + Debug.Console.PrintLine("EncryptString()发生异常: {0}", e); + LogManager.Error("Encryptor", e); + return encryptString; + } + } + + /// + /// DES解密字符串 + /// + /// 待解密的字符串 + /// 解密密钥,要求为8位,和加密密钥相同 + /// 解密成功返回解密后的字符串,失败返源串 + public static string DecryptString(string decryptString, string decryptKey) + { + try + { + byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey); + byte[] rgbIV = Encoding.UTF8.GetBytes(decryptKey); + byte[] inputByteArray = Convert.FromBase64String(decryptString); + DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider(); + MemoryStream mStream = new MemoryStream(); + CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write); + cStream.Write(inputByteArray, 0, inputByteArray.Length); + cStream.FlushFinalBlock(); + return Encoding.UTF8.GetString(mStream.ToArray()); + } + catch (Exception e) + { + Debug.Console.PrintLine("DecryptString()发生异常: {0}", e); + LogManager.Error("Encryptor", e); + return decryptString; + } + } + + } +} diff --git a/src/DownKyi.Core/Utils/Encryptor/Hash.cs b/src/DownKyi.Core/Utils/Encryptor/Hash.cs new file mode 100644 index 0000000..a170ccb --- /dev/null +++ b/src/DownKyi.Core/Utils/Encryptor/Hash.cs @@ -0,0 +1,68 @@ +using System; +using System.IO; +using System.Security.Cryptography; +using System.Text; + +namespace DownKyi.Core.Utils.Encryptor +{ + public static class Hash + { + /// + /// 计算字符串MD5值 + /// + /// + /// + public static string GetMd5Hash(string input) + { + if (input == null) + { + return null; + } + + MD5 md5Hash = MD5.Create(); + + // 将输入字符串转换为字节数组并计算哈希数据 + byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); + + // 创建一个 Stringbuilder 来收集字节并创建字符串 + StringBuilder sBuilder = new StringBuilder(); + + // 循环遍历哈希数据的每一个字节并格式化为十六进制字符串 + for (int i = 0; i < data.Length; i++) + { + sBuilder.Append(data[i].ToString("x2")); + } + + // 返回十六进制字符串 + return sBuilder.ToString(); + } + + /// + /// 计算文件MD5值 + /// + /// + /// + public static string GetMD5HashFromFile(string fileName) + { + try + { + FileStream file = new FileStream(fileName, FileMode.Open); + MD5 md5 = new MD5CryptoServiceProvider(); + byte[] retVal = md5.ComputeHash(file); + file.Close(); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < retVal.Length; i++) + { + sb.Append(retVal[i].ToString("x2")); + } + return sb.ToString(); + } + catch (Exception e) + { + throw new Exception("GetMD5HashFromFile()发生异常: {0}" + e.Message); + } + } + + } +} diff --git a/src/DownKyi.Core/Utils/Format.cs b/src/DownKyi.Core/Utils/Format.cs new file mode 100644 index 0000000..d8f08c8 --- /dev/null +++ b/src/DownKyi.Core/Utils/Format.cs @@ -0,0 +1,168 @@ +namespace DownKyi.Core.Utils +{ + public static class Format + { + + /// + /// 格式化Duration时间 + /// + /// + /// + public static string FormatDuration(long duration) + { + string formatDuration; + if (duration / 60 > 0) + { + long dur = duration / 60; + if (dur / 60 > 0) + { + formatDuration = $"{dur / 60}h{dur % 60}m{duration % 60}s"; + } + else + { + formatDuration = $"{duration / 60}m{duration % 60}s"; + } + } + else + { + formatDuration = $"{duration}s"; + } + return formatDuration; + } + + /// + /// 格式化Duration时间,格式为00:00:00 + /// + /// + /// + public static string FormatDuration2(long duration) + { + string formatDuration; + if (duration / 60 > 0) + { + long dur = duration / 60; + if (dur / 60 > 0) + { + formatDuration = string.Format("{0:D2}", dur / 60) + ":" + string.Format("{0:D2}", dur % 60) + ":" + string.Format("{0:D2}", duration % 60); + } + else + { + formatDuration = "00:" + string.Format("{0:D2}", duration / 60) + ":" + string.Format("{0:D2}", duration % 60); + } + } + else + { + formatDuration = "00:00:" + string.Format("{0:D2}", duration); + } + return formatDuration; + } + + /// + /// 格式化Duration时间,格式为00:00 + /// + /// + /// + public static string FormatDuration3(long duration) + { + string formatDuration; + if (duration / 60 > 0) + { + long dur = duration / 60; + if (dur / 60 > 0) + { + formatDuration = string.Format("{0:D2}", dur / 60) + ":" + string.Format("{0:D2}", dur % 60) + ":" + string.Format("{0:D2}", duration % 60); + } + else + { + formatDuration = string.Format("{0:D2}", duration / 60) + ":" + string.Format("{0:D2}", duration % 60); + } + } + else + { + formatDuration = "00:" + string.Format("{0:D2}", duration); + } + return formatDuration; + } + + /// + /// 格式化数字,超过10000的数字将单位改为万,超过100000000的数字将单位改为亿,并保留1位小数 + /// + /// + /// + public static string FormatNumber(long number) + { + if (number > 99999999) + { + return (number / 100000000.0f).ToString("F1") + "亿"; + } + + if (number > 9999) + { + return (number / 10000.0f).ToString("F1") + "万"; + } + else + { + return number.ToString(); + } + } + + /// + /// 格式化网速 + /// + /// + /// + public static string FormatSpeed(float speed) + { + string formatSpeed; + if (speed <= 0) + { + formatSpeed = "0B/s"; + } + else if (speed < 1024) + { + formatSpeed = speed.ToString("#.##") + "B/s"; + } + else if (speed < 1024 * 1024) + { + formatSpeed = (speed / 1024).ToString("#.##") + "KB/s"; + } + else + { + formatSpeed = (speed / 1024 / 1024).ToString("#.##") + "MB/s"; + } + return formatSpeed; + } + + /// + /// 格式化字节大小,可用于文件大小的显示 + /// + /// + /// + public static string FormatFileSize(long fileSize) + { + string formatFileSize; + if (fileSize <= 0) + { + formatFileSize = "0B"; + } + else if (fileSize < 1024) + { + formatFileSize = fileSize.ToString() + "B"; + } + else if (fileSize < 1024 * 1024) + { + formatFileSize = (fileSize / 1024.0).ToString("#.##") + "KB"; + } + else if (fileSize < 1024 * 1024 * 1024) + { + formatFileSize = (fileSize / 1024.0 / 1024.0).ToString("#.##") + "MB"; + } + else + { + formatFileSize = (fileSize / 1024.0 / 1024.0 / 1024.0).ToString("#.##") + "GB"; + } + return formatFileSize; + } + + } +} diff --git a/src/DownKyi.Core/Utils/HardDisk.cs b/src/DownKyi.Core/Utils/HardDisk.cs new file mode 100644 index 0000000..046384d --- /dev/null +++ b/src/DownKyi.Core/Utils/HardDisk.cs @@ -0,0 +1,52 @@ +using System.IO; + +namespace DownKyi.Core.Utils +{ + public static class HardDisk + { + /// + /// 获取指定驱动器的空间总大小 + /// + /// 只需输入代表驱动器的字母即可 + /// + public static long GetHardDiskSpace(string hardDiskName) + { + long totalSize = new long(); + hardDiskName = $"{hardDiskName}:\\"; + DriveInfo[] drives = DriveInfo.GetDrives(); + + foreach (DriveInfo drive in drives) + { + if (drive.Name == hardDiskName) + { + totalSize = drive.TotalSize; + } + } + + return totalSize; + } + + /// + /// 获取指定驱动器的剩余空间总大小 + /// + /// 只需输入代表驱动器的字母即可 + /// + public static long GetHardDiskFreeSpace(string hardDiskName) + { + long freeSpace = new long(); + hardDiskName = $"{hardDiskName}:\\"; + DriveInfo[] drives = DriveInfo.GetDrives(); + + foreach (DriveInfo drive in drives) + { + if (drive.Name == hardDiskName) + { + freeSpace = drive.TotalFreeSpace; + } + } + + return freeSpace; + } + + } +} diff --git a/src/DownKyi.Core/Utils/ListHelper.cs b/src/DownKyi.Core/Utils/ListHelper.cs new file mode 100644 index 0000000..bee195d --- /dev/null +++ b/src/DownKyi.Core/Utils/ListHelper.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; + +namespace DownKyi.Core.Utils +{ + public static class ListHelper + { + + /// + /// 判断List中是否存在,不存在则添加 + /// + /// + /// + public static void AddUnique(List list, T item) + { + if (!list.Exists(t => t.Equals(item))) + { + list.Add(item); + } + } + + /// + /// 判断List中是否存在,不存在则添加 + /// + /// + /// + /// + /// + public static void InsertUnique(List list, T item, int index) + { + if (!list.Exists(t => t.Equals(item))) + { + list.Insert(index, item); + } + else + { + list.Remove(item); + list.Insert(index, item); + } + } + + } +} diff --git a/src/Core/MachineCode.cs b/src/DownKyi.Core/Utils/MachineCode.cs similarity index 96% rename from src/Core/MachineCode.cs rename to src/DownKyi.Core/Utils/MachineCode.cs index e265cfc..5c13cb2 100644 --- a/src/Core/MachineCode.cs +++ b/src/DownKyi.Core/Utils/MachineCode.cs @@ -1,7 +1,7 @@ using System; using System.Management; -namespace Core +namespace DownKyi.Core.Utils { public class MachineCode { @@ -125,8 +125,11 @@ namespace Core ManagementObjectCollection moc2 = mc.GetInstances(); foreach (ManagementObject mo in moc2) { - if ((bool)mo["IPEnabled"] == true) + if ((bool)mo["IPEnabled"]) + { MoAddress = mo["MacAddress"].ToString(); + } + mo.Dispose(); } } diff --git a/src/DownKyi.Core/Utils/ObjectHelper.cs b/src/DownKyi.Core/Utils/ObjectHelper.cs new file mode 100644 index 0000000..13d7632 --- /dev/null +++ b/src/DownKyi.Core/Utils/ObjectHelper.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Runtime.Serialization.Formatters.Binary; + +namespace DownKyi.Core.Utils +{ + public static class ObjectHelper + { + + /// + /// 解析二维码登录返回的url,用于设置cookie + /// + /// + /// + public static CookieContainer ParseCookie(string url) + { + CookieContainer cookieContainer = new CookieContainer(); + + if (url == null || url == "") { return cookieContainer; } + + string[] strList = url.Split('?'); + if (strList.Count() < 2) { return cookieContainer; } + + string[] strList2 = strList[1].Split('&'); + if (strList2.Count() == 0) { return cookieContainer; } + + // 获取expires + string expires = strList2.FirstOrDefault(it => it.Contains("Expires")).Split('=')[1]; + DateTime dateTime = DateTime.Now; + dateTime = dateTime.AddSeconds(int.Parse(expires)); + + foreach (var item in strList2) + { + string[] strList3 = item.Split('='); + if (strList3.Count() < 2) { continue; } + + string name = strList3[0]; + string value = strList3[1]; + + // 不需要 + if (name == "Expires" || name == "gourl") { continue; } + + // 添加cookie + cookieContainer.Add(new Cookie(name, value, "/", ".bilibili.com") { Expires = dateTime }); + Debug.Console.PrintLine(name + ": " + value + "\t" + cookieContainer.Count); + } + + return cookieContainer; + } + + /// + /// 将CookieContainer中的所有的Cookie读出来 + /// + /// + /// + public static List GetAllCookies(CookieContainer cc) + { + List lstCookies = new List(); + + Hashtable table = (Hashtable)cc.GetType().InvokeMember("m_domainTable", + System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | + System.Reflection.BindingFlags.Instance, null, cc, new object[] { }); + + foreach (object pathList in table.Values) + { + SortedList lstCookieCol = (SortedList)pathList.GetType().InvokeMember("m_list", + System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField + | System.Reflection.BindingFlags.Instance, null, pathList, new object[] { }); + foreach (CookieCollection colCookies in lstCookieCol.Values) + { + foreach (Cookie c in colCookies) + { + lstCookies.Add(c); + } + } + } + + return lstCookies; + } + + /// + /// 写入cookies到磁盘 + /// + /// + /// + /// + public static bool WriteCookiesToDisk(string file, CookieContainer cookieJar) + { + return WriteObjectToDisk(file, cookieJar); + } + + /// + /// 从磁盘读取cookie + /// + /// + /// + public static CookieContainer ReadCookiesFromDisk(string file) + { + return (CookieContainer)ReadObjectFromDisk(file); + } + + /// + /// 写入序列化对象到磁盘 + /// + /// + /// + /// + public static bool WriteObjectToDisk(string file, object obj) + { + try + { + using (Stream stream = File.Create(file)) + { + Debug.Console.PrintLine("Writing object to disk... "); + + BinaryFormatter formatter = new BinaryFormatter(); + formatter.Serialize(stream, obj); + + Debug.Console.PrintLine("Done."); + return true; + } + } + catch (IOException e) + { + Debug.Console.PrintLine("WriteObjectToDisk()发生IO异常: {0}", e); + Logging.LogManager.Error(e); + return false; + } + catch (Exception e) + { + Debug.Console.PrintLine("WriteObjectToDisk()发生异常: {0}", e); + Logging.LogManager.Error(e); + return false; + } + } + + /// + /// 从磁盘读取序列化对象 + /// + /// + /// + public static object ReadObjectFromDisk(string file) + { + try + { + using (Stream stream = File.Open(file, FileMode.Open)) + { + Debug.Console.PrintLine("Reading object from disk... "); + BinaryFormatter formatter = new BinaryFormatter(); + Debug.Console.PrintLine("Done."); + return formatter.Deserialize(stream); + } + } + catch (IOException e) + { + Debug.Console.PrintLine("ReadObjectFromDisk()发生IO异常: {0}", e); + Logging.LogManager.Error(e); + return null; + } + catch (Exception e) + { + Debug.Console.PrintLine("ReadObjectFromDisk()发生异常: {0}", e); + Logging.LogManager.Error(e); + return null; + } + } + } +} diff --git a/src/DownKyi.Core/Utils/QRCode.cs b/src/DownKyi.Core/Utils/QRCode.cs new file mode 100644 index 0000000..d7e703f --- /dev/null +++ b/src/DownKyi.Core/Utils/QRCode.cs @@ -0,0 +1,41 @@ +using System.Drawing; + +namespace DownKyi.Core.Utils +{ + public static class QRCode + { + /// + /// 生成二维码 + /// + /// 信息 + /// 版本 1 ~ 40 + /// 像素点大小 + /// 图标路径 + /// 图标尺寸 + /// 图标边框厚度 + /// 二维码白边 + /// 位图 + public static Bitmap EncodeQRCode(string msg, int version, int pixel, string icon_path, int icon_size, int icon_border, bool white_edge) + { + QRCoder.QRCodeGenerator code_generator = new QRCoder.QRCodeGenerator(); + + QRCoder.QRCodeData code_data = code_generator.CreateQrCode(msg, QRCoder.QRCodeGenerator.ECCLevel.H/* 这里设置容错率的一个级别 */, true, false, QRCoder.QRCodeGenerator.EciMode.Utf8, version); + + QRCoder.QRCode code = new QRCoder.QRCode(code_data); + + Bitmap icon; + if (icon_path == null || icon_path == "") + { + icon = null; + } + else + { + icon = new Bitmap(icon_path); + } + + Bitmap bmp = code.GetGraphic(pixel, Color.Black, Color.White, icon, icon_size, icon_border, white_edge); + return bmp; + } + + } +} diff --git a/src/DownKyi.Core/Utils/StringLogicalComparer.cs b/src/DownKyi.Core/Utils/StringLogicalComparer.cs new file mode 100644 index 0000000..d56c1af --- /dev/null +++ b/src/DownKyi.Core/Utils/StringLogicalComparer.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; + +namespace DownKyi.Core.Utils +{ + public class StringLogicalComparer : IComparer + { + /// + /// 比较两个字符串,如果含用数字,则数字按数字的大小来比较。 + /// + /// + /// + /// + public int Compare(T x, T y) + { + if (x == null || y == null) + { + throw new ArgumentException("Parameters can't be null"); + } + + string fileA = x as string; + string fileB = y as string; + char[] arr1 = fileA.ToCharArray(); + char[] arr2 = fileB.ToCharArray(); + int i = 0, j = 0; + while (i < arr1.Length && j < arr2.Length) + { + if (char.IsDigit(arr1[i]) && char.IsDigit(arr2[j])) + { + string s1 = "", s2 = ""; + while (i < arr1.Length && char.IsDigit(arr1[i])) + { + s1 += arr1[i]; + i++; + } + while (j < arr2.Length && char.IsDigit(arr2[j])) + { + s2 += arr2[j]; + j++; + } + if (int.Parse(s1) > int.Parse(s2)) + { + return 1; + } + if (int.Parse(s1) < int.Parse(s2)) + { + return -1; + } + } + else + { + if (arr1[i] > arr2[j]) + { + return 1; + } + if (arr1[i] < arr2[j]) + { + return -1; + } + i++; + j++; + } + } + if (arr1.Length == arr2.Length) + { + return 0; + } + else + { + return arr1.Length > arr2.Length ? 1 : -1; + } + } + + } +} diff --git a/src/DownKyi.Core/Utils/Validator/Number.cs b/src/DownKyi.Core/Utils/Validator/Number.cs new file mode 100644 index 0000000..899ecdf --- /dev/null +++ b/src/DownKyi.Core/Utils/Validator/Number.cs @@ -0,0 +1,29 @@ +using System.Text.RegularExpressions; + +namespace DownKyi.Core.Utils.Validator +{ + public static class Number + { + + /// + /// 字符串转数字(长整型) + /// + /// + /// + public static long GetInt(string value) + { + return IsInt(value) ? long.Parse(value) : -1; + } + + /// + /// 是否为数字 + /// + /// + /// + public static bool IsInt(string value) + { + return Regex.IsMatch(value, @"^\d+$"); + } + + } +} diff --git a/src/DownKyi.Core/Utils/Web.cs b/src/DownKyi.Core/Utils/Web.cs new file mode 100644 index 0000000..7342460 --- /dev/null +++ b/src/DownKyi.Core/Utils/Web.cs @@ -0,0 +1,8 @@ +namespace DownKyi.Core.Utils +{ + public static class Web + { + // TODO 这里的代码只是为了测试Brotli.Core,不是最终的,需要修改 + + } +} diff --git a/src/DownKyi.Core/packages.config b/src/DownKyi.Core/packages.config new file mode 100644 index 0000000..a2b21fd --- /dev/null +++ b/src/DownKyi.Core/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file