aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.ci/azure-pipelines.yml192
-rw-r--r--.drone.yml81
-rw-r--r--.github/ISSUE_TEMPLATE/bug_report.md1
-rw-r--r--.gitignore3
-rw-r--r--.gitmodules1
-rw-r--r--BDInfo/Properties/AssemblyInfo.cs4
-rw-r--r--CONTRIBUTORS.md5
-rw-r--r--Dockerfile21
-rw-r--r--Dockerfile.arm19
-rw-r--r--Dockerfile.arm6419
-rw-r--r--Doxyfile2565
-rw-r--r--DvdLib/Ifo/AudioAttributes.cs36
-rw-r--r--DvdLib/Ifo/Dvd.cs16
-rw-r--r--DvdLib/Ifo/PgcCommandTable.cs17
-rw-r--r--DvdLib/Ifo/ProgramChain.cs4
-rw-r--r--DvdLib/Ifo/VideoAttributes.cs46
-rw-r--r--DvdLib/Properties/AssemblyInfo.cs4
-rw-r--r--Emby.Dlna/Api/DlnaServerService.cs10
-rw-r--r--Emby.Dlna/Configuration/DlnaOptions.cs2
-rw-r--r--Emby.Dlna/ConnectionManager/ConnectionManager.cs10
-rw-r--r--Emby.Dlna/ConnectionManager/ControlHandler.cs4
-rw-r--r--Emby.Dlna/ContentDirectory/ContentDirectory.cs13
-rw-r--r--Emby.Dlna/ContentDirectory/ControlHandler.cs23
-rw-r--r--Emby.Dlna/ControlRequest.cs6
-rw-r--r--Emby.Dlna/Didl/DidlBuilder.cs3
-rw-r--r--Emby.Dlna/DlnaManager.cs38
-rw-r--r--Emby.Dlna/Emby.Dlna.csproj5
-rw-r--r--Emby.Dlna/IUpnpService.cs5
-rw-r--r--Emby.Dlna/Main/DlnaEntryPoint.cs38
-rw-r--r--Emby.Dlna/MediaReceiverRegistrar/ControlHandler.cs5
-rw-r--r--Emby.Dlna/MediaReceiverRegistrar/MediaReceiverRegistrar.cs10
-rw-r--r--Emby.Dlna/PlayTo/CurrentIdEventArgs.cs9
-rw-r--r--Emby.Dlna/PlayTo/Device.cs72
-rw-r--r--Emby.Dlna/PlayTo/PlayToController.cs78
-rw-r--r--Emby.Dlna/PlayTo/PlaylistItemFactory.cs2
-rw-r--r--Emby.Dlna/PlayTo/TransportCommands.cs19
-rw-r--r--Emby.Dlna/PlayTo/TransportStateEventArgs.cs9
-rw-r--r--Emby.Dlna/PlayTo/uParser.cs47
-rw-r--r--Emby.Dlna/PlayTo/uParserObject.cs9
-rw-r--r--Emby.Dlna/Properties/AssemblyInfo.cs4
-rw-r--r--Emby.Dlna/Service/BaseControlHandler.cs17
-rw-r--r--Emby.Drawing/ImageProcessor.cs8
-rw-r--r--Emby.Drawing/Properties/AssemblyInfo.cs4
-rw-r--r--Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs10
-rw-r--r--Emby.IsoMounting/IsoMounter/Properties/AssemblyInfo.cs4
-rw-r--r--Emby.Naming/Properties/AssemblyInfo.cs4
-rw-r--r--Emby.Naming/TV/EpisodePathParser.cs32
-rw-r--r--Emby.Naming/Video/VideoListResolver.cs45
-rw-r--r--Emby.Notifications/CoreNotificationTypes.cs32
-rw-r--r--Emby.Notifications/Notifications.cs32
-rw-r--r--Emby.Notifications/Properties/AssemblyInfo.cs4
-rw-r--r--Emby.Photos/Properties/AssemblyInfo.cs4
-rw-r--r--Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs181
-rw-r--r--Emby.Server.Implementations/Activity/ActivityManager.cs7
-rw-r--r--Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs16
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs629
-rw-r--r--Emby.Server.Implementations/Channels/ChannelManager.cs11
-rw-r--r--Emby.Server.Implementations/Channels/ChannelPostScanTask.cs48
-rw-r--r--Emby.Server.Implementations/Collections/CollectionImageProvider.cs4
-rw-r--r--Emby.Server.Implementations/ConfigurationOptions.cs3
-rw-r--r--Emby.Server.Implementations/Cryptography/CryptographyProvider.cs128
-rw-r--r--Emby.Server.Implementations/Data/BaseSqliteRepository.cs27
-rw-r--r--Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs3
-rw-r--r--Emby.Server.Implementations/Data/SqliteItemRepository.cs301
-rw-r--r--Emby.Server.Implementations/Data/SqliteUserDataRepository.cs4
-rw-r--r--Emby.Server.Implementations/Data/SqliteUserRepository.cs34
-rw-r--r--Emby.Server.Implementations/Data/TypeMapper.cs9
-rw-r--r--Emby.Server.Implementations/Diagnostics/CommonProcess.cs72
-rw-r--r--Emby.Server.Implementations/Dto/DtoService.cs15
-rw-r--r--Emby.Server.Implementations/Emby.Server.Implementations.csproj25
-rw-r--r--Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs4
-rw-r--r--Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs36
-rw-r--r--Emby.Server.Implementations/FFMpeg/FFMpegInfo.cs24
-rw-r--r--Emby.Server.Implementations/FFMpeg/FFMpegInstallInfo.cs17
-rw-r--r--Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs132
-rw-r--r--Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs23
-rw-r--r--Emby.Server.Implementations/HttpServer/FileWriter.cs46
-rw-r--r--Emby.Server.Implementations/HttpServer/HttpListenerHost.cs169
-rw-r--r--Emby.Server.Implementations/HttpServer/HttpResultFactory.cs106
-rw-r--r--Emby.Server.Implementations/HttpServer/IHttpListener.cs17
-rw-r--r--Emby.Server.Implementations/HttpServer/LoggerUtils.cs55
-rw-r--r--Emby.Server.Implementations/HttpServer/RangeRequestWriter.cs9
-rw-r--r--Emby.Server.Implementations/HttpServer/ResponseFilter.cs10
-rw-r--r--Emby.Server.Implementations/HttpServer/Security/AuthService.cs4
-rw-r--r--Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs3
-rw-r--r--Emby.Server.Implementations/HttpServer/StreamWriter.cs25
-rw-r--r--Emby.Server.Implementations/HttpServer/WebSocketConnection.cs39
-rw-r--r--Emby.Server.Implementations/IO/LibraryMonitor.cs15
-rw-r--r--Emby.Server.Implementations/IO/ManagedFileSystem.cs23
-rw-r--r--Emby.Server.Implementations/IO/StreamHelper.cs226
-rw-r--r--Emby.Server.Implementations/IStartupOptions.cs5
-rw-r--r--Emby.Server.Implementations/Images/BaseDynamicImageProvider.cs58
-rw-r--r--Emby.Server.Implementations/Library/DefaultAuthenticationProvider.cs141
-rw-r--r--Emby.Server.Implementations/Library/LibraryManager.cs372
-rw-r--r--Emby.Server.Implementations/Library/UserManager.cs53
-rw-r--r--Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs12
-rw-r--r--Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs25
-rw-r--r--Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs5
-rw-r--r--Emby.Server.Implementations/LiveTv/LiveTvManager.cs6
-rw-r--r--Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs3
-rw-r--r--Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs58
-rw-r--r--Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs17
-rw-r--r--Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs20
-rw-r--r--Emby.Server.Implementations/Localization/Core/es-AR.json184
-rw-r--r--Emby.Server.Implementations/Localization/Core/fr-CA.json170
-rw-r--r--Emby.Server.Implementations/Localization/Core/fr.json4
-rw-r--r--Emby.Server.Implementations/Localization/Core/he.json6
-rw-r--r--Emby.Server.Implementations/Localization/Core/it.json12
-rw-r--r--Emby.Server.Implementations/Localization/Core/kk.json10
-rw-r--r--Emby.Server.Implementations/Localization/Core/pt-BR.json16
-rw-r--r--Emby.Server.Implementations/Localization/Core/sl-SI.json112
-rw-r--r--Emby.Server.Implementations/Localization/Core/tr.json36
-rw-r--r--Emby.Server.Implementations/Localization/Core/zh-CN.json6
-rw-r--r--Emby.Server.Implementations/Localization/LocalizationManager.cs185
-rw-r--r--Emby.Server.Implementations/Localization/Ratings/au.csv8
-rw-r--r--Emby.Server.Implementations/Localization/Ratings/be.csv6
-rw-r--r--Emby.Server.Implementations/Localization/Ratings/de.csv10
-rw-r--r--Emby.Server.Implementations/Localization/Ratings/kz.csv13
-rw-r--r--Emby.Server.Implementations/Localization/Ratings/ru.csv5
-rw-r--r--Emby.Server.Implementations/MediaEncoder/EncodingManager.cs4
-rw-r--r--Emby.Server.Implementations/Middleware/WebSocketMiddleware.cs39
-rw-r--r--Emby.Server.Implementations/Net/DisposableManagedObjectBase.cs66
-rw-r--r--Emby.Server.Implementations/Net/IWebSocket.cs5
-rw-r--r--Emby.Server.Implementations/Net/SocketFactory.cs134
-rw-r--r--Emby.Server.Implementations/Net/UdpSocket.cs72
-rw-r--r--Emby.Server.Implementations/Net/WebSocketConnectEventArgs.cs4
-rw-r--r--Emby.Server.Implementations/Networking/NetworkManager.cs80
-rw-r--r--Emby.Server.Implementations/Playlists/PlaylistImageProvider.cs13
-rw-r--r--Emby.Server.Implementations/Properties/AssemblyInfo.cs2
-rw-r--r--Emby.Server.Implementations/Reflection/AssemblyInfo.cs25
-rw-r--r--Emby.Server.Implementations/ScheduledTasks/Triggers/DailyTrigger.cs2
-rw-r--r--Emby.Server.Implementations/Security/EncryptionManager.cs57
-rw-r--r--Emby.Server.Implementations/Serialization/JsonSerializer.cs21
-rw-r--r--Emby.Server.Implementations/ServerApplicationPaths.cs6
-rw-r--r--Emby.Server.Implementations/Services/HttpResult.cs7
-rw-r--r--Emby.Server.Implementations/Services/ResponseHelper.cs7
-rw-r--r--Emby.Server.Implementations/Services/ServiceExec.cs2
-rw-r--r--Emby.Server.Implementations/Services/ServiceHandler.cs2
-rw-r--r--Emby.Server.Implementations/Services/ServicePath.cs161
-rw-r--r--Emby.Server.Implementations/Services/StringMapTypeDeserializer.cs52
-rw-r--r--Emby.Server.Implementations/Session/SessionManager.cs246
-rw-r--r--Emby.Server.Implementations/Session/SessionWebSocketListener.cs3
-rw-r--r--Emby.Server.Implementations/SocketSharp/HttpFile.cs (renamed from Jellyfin.Server/SocketSharp/HttpFile.cs)6
-rw-r--r--Emby.Server.Implementations/SocketSharp/HttpPostedFile.cs204
-rw-r--r--Emby.Server.Implementations/SocketSharp/RequestMono.cs (renamed from Jellyfin.Server/SocketSharp/RequestMono.cs)295
-rw-r--r--Emby.Server.Implementations/SocketSharp/SharpWebSocket.cs (renamed from Jellyfin.Server/SocketSharp/SharpWebSocket.cs)75
-rw-r--r--Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs136
-rw-r--r--Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs (renamed from Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs)263
-rw-r--r--Emby.Server.Implementations/SocketSharp/WebSocketSharpResponse.cs98
-rw-r--r--Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs2
-rw-r--r--Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs14
-rw-r--r--Emby.Server.Implementations/Updates/InstallationManager.cs32
-rw-r--r--Emby.Server.Implementations/UserViews/CollectionFolderImageProvider.cs9
-rw-r--r--Emby.Server.Implementations/UserViews/DynamicImageProvider.cs13
-rw-r--r--Emby.Server.Implementations/UserViews/FolderImageProvider.cs4
-rw-r--r--Emby.Server.Implementations/WebSockets/WebSocketHandler.cs10
-rw-r--r--Emby.Server.Implementations/WebSockets/WebSocketManager.cs102
-rw-r--r--Emby.Server.Implementations/Xml/XmlReaderSettingsFactory.cs20
-rw-r--r--Emby.XmlTv/Emby.XmlTv/Classes/XmlTvReader.cs27
-rw-r--r--Emby.XmlTv/Emby.XmlTv/Properties/AssemblyInfo.cs4
-rw-r--r--Jellyfin.Drawing.Skia/PercentPlayedDrawer.cs2
-rw-r--r--Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs2
-rw-r--r--Jellyfin.Drawing.Skia/Properties/AssemblyInfo.cs4
-rw-r--r--Jellyfin.Drawing.Skia/StripCollageBuilder.cs54
-rw-r--r--Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs2
-rw-r--r--Jellyfin.Server/CoreAppHost.cs18
-rw-r--r--Jellyfin.Server/Jellyfin.Server.csproj7
-rw-r--r--Jellyfin.Server/Program.cs98
-rw-r--r--Jellyfin.Server/Properties/AssemblyInfo.cs4
-rw-r--r--Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs273
-rw-r--r--Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs181
-rw-r--r--Jellyfin.Server/StartupOptions.cs8
-rw-r--r--MediaBrowser.Api/ApiEntryPoint.cs7
-rw-r--r--MediaBrowser.Api/BaseApiService.cs60
-rw-r--r--MediaBrowser.Api/FilterService.cs3
-rw-r--r--MediaBrowser.Api/Images/ImageService.cs92
-rw-r--r--MediaBrowser.Api/Library/LibraryService.cs3
-rw-r--r--MediaBrowser.Api/LiveTv/LiveTvService.cs53
-rw-r--r--MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs45
-rw-r--r--MediaBrowser.Api/Playback/BaseStreamingService.cs6
-rw-r--r--MediaBrowser.Api/Playback/Progressive/AudioService.cs8
-rw-r--r--MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs93
-rw-r--r--MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs10
-rw-r--r--MediaBrowser.Api/Playback/Progressive/VideoService.cs9
-rw-r--r--MediaBrowser.Api/Playback/UniversalAudioService.cs7
-rw-r--r--MediaBrowser.Api/Properties/AssemblyInfo.cs4
-rw-r--r--MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs16
-rw-r--r--MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs3
-rw-r--r--MediaBrowser.Api/Session/SessionInfoWebSocketListener.cs3
-rw-r--r--MediaBrowser.Api/System/ActivityLogWebSocketListener.cs3
-rw-r--r--MediaBrowser.Api/UserLibrary/ArtistsService.cs12
-rw-r--r--MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs4
-rw-r--r--MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs8
-rw-r--r--MediaBrowser.Api/UserLibrary/GenresService.cs2
-rw-r--r--MediaBrowser.Api/UserLibrary/ItemsService.cs55
-rw-r--r--MediaBrowser.Api/UserLibrary/MusicGenresService.cs2
-rw-r--r--MediaBrowser.Api/UserLibrary/PersonsService.cs6
-rw-r--r--MediaBrowser.Api/UserLibrary/StudiosService.cs2
-rw-r--r--MediaBrowser.Common/Configuration/IApplicationPaths.cs12
-rw-r--r--MediaBrowser.Common/Extensions/BaseExtensions.cs10
-rw-r--r--MediaBrowser.Common/Extensions/CollectionExtensions.cs14
-rw-r--r--MediaBrowser.Common/IApplicationHost.cs15
-rw-r--r--MediaBrowser.Common/MediaBrowser.Common.csproj3
-rw-r--r--MediaBrowser.Common/Net/HttpRequestOptions.cs9
-rw-r--r--MediaBrowser.Common/Net/INetworkManager.cs5
-rw-r--r--MediaBrowser.Common/Properties/AssemblyInfo.cs4
-rw-r--r--MediaBrowser.Common/Providers/SubtitleConfigurationFactory.cs18
-rw-r--r--MediaBrowser.Common/System/OperatingSystem.cs72
-rw-r--r--MediaBrowser.Controller/Dlna/IDlnaManager.cs5
-rw-r--r--MediaBrowser.Controller/Dto/DtoOptions.cs14
-rw-r--r--MediaBrowser.Controller/Dto/IDtoService.cs4
-rw-r--r--MediaBrowser.Controller/Entities/BaseItem.cs111
-rw-r--r--MediaBrowser.Controller/Entities/Folder.cs26
-rw-r--r--MediaBrowser.Controller/Entities/ItemImageInfo.cs16
-rw-r--r--MediaBrowser.Controller/Entities/Movies/BoxSet.cs2
-rw-r--r--MediaBrowser.Controller/Entities/Movies/Movie.cs8
-rw-r--r--MediaBrowser.Controller/Entities/TV/Episode.cs2
-rw-r--r--MediaBrowser.Controller/Entities/TV/Series.cs3
-rw-r--r--MediaBrowser.Controller/Entities/Video.cs2
-rw-r--r--MediaBrowser.Controller/IServerApplicationHost.cs2
-rw-r--r--MediaBrowser.Controller/Library/ILibraryManager.cs14
-rw-r--r--MediaBrowser.Controller/Library/TVUtils.cs38
-rw-r--r--MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs2
-rw-r--r--MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs7
-rw-r--r--MediaBrowser.Controller/MediaEncoding/JobLogger.cs22
-rw-r--r--MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs86
-rw-r--r--MediaBrowser.Controller/Net/IHttpServer.cs24
-rw-r--r--MediaBrowser.Controller/Net/IWebSocketConnection.cs3
-rw-r--r--MediaBrowser.Controller/Net/WebSocketConnectEventArgs.cs39
-rw-r--r--MediaBrowser.Controller/Persistence/IItemRepository.cs14
-rw-r--r--MediaBrowser.Controller/Properties/AssemblyInfo.cs4
-rw-r--r--MediaBrowser.Controller/Security/IEncryptionManager.cs19
-rw-r--r--MediaBrowser.LocalMetadata/Images/InternalMetadataFolderImageProvider.cs16
-rw-r--r--MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs7
-rw-r--r--MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs53
-rw-r--r--MediaBrowser.LocalMetadata/Parsers/BoxSetXmlParser.cs5
-rw-r--r--MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs5
-rw-r--r--MediaBrowser.LocalMetadata/Properties/AssemblyInfo.cs4
-rw-r--r--MediaBrowser.LocalMetadata/Providers/BoxSetXmlProvider.cs7
-rw-r--r--MediaBrowser.LocalMetadata/Providers/PlaylistXmlProvider.cs7
-rw-r--r--MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs7
-rw-r--r--MediaBrowser.LocalMetadata/Savers/BoxSetXmlSaver.cs4
-rw-r--r--MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs4
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs113
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs6
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs449
-rw-r--r--MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj1
-rw-r--r--MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs77
-rw-r--r--MediaBrowser.MediaEncoding/Properties/AssemblyInfo.cs4
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/ConfigurationExtension.cs29
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs346
-rw-r--r--MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs15
-rw-r--r--MediaBrowser.Model/Configuration/EncodingOptions.cs7
-rw-r--r--MediaBrowser.Model/Configuration/ServerConfiguration.cs2
-rw-r--r--MediaBrowser.Model/Cryptography/ICryptoProvider.cs9
-rw-r--r--MediaBrowser.Model/Cryptography/PasswordHash.cs153
-rw-r--r--MediaBrowser.Model/Entities/MediaStream.cs50
-rw-r--r--MediaBrowser.Model/IO/IFileSystem.cs3
-rw-r--r--MediaBrowser.Model/MediaBrowser.Model.csproj1
-rw-r--r--MediaBrowser.Model/Net/HttpResponse.cs64
-rw-r--r--MediaBrowser.Model/Net/IAcceptSocket.cs15
-rw-r--r--MediaBrowser.Model/Net/IpAddressInfo.cs1
-rw-r--r--MediaBrowser.Model/Properties/AssemblyInfo.cs4
-rw-r--r--MediaBrowser.Model/Reflection/IAssemblyInfo.cs14
-rw-r--r--MediaBrowser.Model/Serialization/IJsonSerializer.cs8
-rw-r--r--MediaBrowser.Model/Services/HttpUtility.cs691
-rw-r--r--MediaBrowser.Model/Services/IHttpRequest.cs5
-rw-r--r--MediaBrowser.Model/Services/IHttpResponse.cs20
-rw-r--r--MediaBrowser.Model/Services/IRequest.cs47
-rw-r--r--MediaBrowser.Model/Services/QueryParamCollection.cs57
-rw-r--r--MediaBrowser.Model/System/IEnvironmentInfo.cs21
-rw-r--r--MediaBrowser.Model/System/OperatingSystemId.cs10
-rw-r--r--MediaBrowser.Model/System/SystemInfo.cs29
-rw-r--r--MediaBrowser.Model/Users/UserPolicy.cs5
-rw-r--r--MediaBrowser.Model/Xml/IXmlReaderSettingsFactory.cs9
-rw-r--r--MediaBrowser.Providers/Manager/GenericPriorityQueue.cs402
-rw-r--r--MediaBrowser.Providers/Manager/GenericPriorityQueueNode.cs22
-rw-r--r--MediaBrowser.Providers/Manager/IFixedSizePriorityQueue.cs24
-rw-r--r--MediaBrowser.Providers/Manager/IPriorityQueue.cs56
-rw-r--r--MediaBrowser.Providers/Manager/MetadataService.cs5
-rw-r--r--MediaBrowser.Providers/Manager/ProviderManager.cs39
-rw-r--r--MediaBrowser.Providers/Manager/SimplePriorityQueue.cs247
-rw-r--r--MediaBrowser.Providers/MediaBrowser.Providers.csproj6
-rw-r--r--MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs13
-rw-r--r--MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs317
-rw-r--r--MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs43
-rw-r--r--MediaBrowser.Providers/People/TvdbPersonImageProvider.cs173
-rw-r--r--MediaBrowser.Providers/Properties/AssemblyInfo.cs4
-rw-r--r--MediaBrowser.Providers/TV/MissingEpisodeProvider.cs373
-rw-r--r--MediaBrowser.Providers/TV/SeriesMetadataService.cs21
-rw-r--r--MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs244
-rw-r--r--MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs146
-rw-r--r--MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs851
-rw-r--r--MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs398
-rw-r--r--MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs304
-rw-r--r--MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs321
-rw-r--r--MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs1592
-rw-r--r--MediaBrowser.Providers/TV/TheTVDB/TvdbUtils.cs36
-rw-r--r--MediaBrowser.Providers/TV/TvExternalIds.cs4
-rw-r--r--MediaBrowser.Tests/Properties/AssemblyInfo.cs2
-rw-r--r--MediaBrowser.WebDashboard/Api/DashboardService.cs17
-rw-r--r--MediaBrowser.WebDashboard/Properties/AssemblyInfo.cs4
m---------MediaBrowser.WebDashboard/jellyfin-web0
-rw-r--r--MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs181
-rw-r--r--MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs68
-rw-r--r--MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs14
-rw-r--r--MediaBrowser.XbmcMetadata/Parsers/SeasonNfoParser.cs5
-rw-r--r--MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs5
-rw-r--r--MediaBrowser.XbmcMetadata/Properties/AssemblyInfo.cs4
-rw-r--r--MediaBrowser.XbmcMetadata/Providers/AlbumNfoProvider.cs7
-rw-r--r--MediaBrowser.XbmcMetadata/Providers/ArtistNfoProvider.cs7
-rw-r--r--MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs7
-rw-r--r--MediaBrowser.XbmcMetadata/Providers/EpisodeNfoProvider.cs7
-rw-r--r--MediaBrowser.XbmcMetadata/Providers/MovieNfoProvider.cs10
-rw-r--r--MediaBrowser.XbmcMetadata/Providers/SeasonNfoProvider.cs11
-rw-r--r--MediaBrowser.XbmcMetadata/Providers/SeriesNfoProvider.cs13
-rw-r--r--MediaBrowser.XbmcMetadata/Savers/AlbumNfoSaver.cs4
-rw-r--r--MediaBrowser.XbmcMetadata/Savers/ArtistNfoSaver.cs4
-rw-r--r--MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs80
-rw-r--r--MediaBrowser.XbmcMetadata/Savers/EpisodeNfoSaver.cs4
-rw-r--r--MediaBrowser.XbmcMetadata/Savers/MovieNfoSaver.cs4
-rw-r--r--MediaBrowser.XbmcMetadata/Savers/SeasonNfoSaver.cs6
-rw-r--r--MediaBrowser.XbmcMetadata/Savers/SeriesNfoSaver.cs4
-rw-r--r--MediaBrowser.sln15
-rw-r--r--Mono.Nat/Properties/AssemblyInfo.cs4
-rw-r--r--OpenSubtitlesHandler/Console/OSHConsole.cs92
-rw-r--r--OpenSubtitlesHandler/Interfaces/IMethodResponse.cs71
-rw-r--r--OpenSubtitlesHandler/Interfaces/MethodResponseAttr.cs40
-rw-r--r--OpenSubtitlesHandler/Languages/DetectLanguageResult.cs31
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseAddComment.cs32
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseAddRequest.cs35
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseAutoUpdate.cs59
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash.cs37
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash2.cs37
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseCheckSubHash.cs38
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseDetectLanguage.cs37
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseError.cs36
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseGetAvailableTranslations.cs37
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseGetComments.cs39
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseGetSubLanguages.cs39
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseGetTranslation.cs36
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovie.cs36
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovieHash.cs38
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseLogIn.cs39
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseMovieDetails.cs73
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseMovieSearch.cs43
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseNoOperation.cs52
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongImdbMovie.cs33
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongMovieHash.cs33
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseSearchToMail.cs32
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseServerInfo.cs131
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleDownload.cs44
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleSearch.cs46
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitlesVote.cs43
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseTryUploadSubtitles.cs40
-rw-r--r--OpenSubtitlesHandler/MethodResponses/MethodResponseUploadSubtitles.cs38
-rw-r--r--OpenSubtitlesHandler/Methods Implemeted.txt39
-rw-r--r--OpenSubtitlesHandler/MovieHasher.cs48
-rw-r--r--OpenSubtitlesHandler/Movies/CheckMovieHash2Data.cs42
-rw-r--r--OpenSubtitlesHandler/Movies/CheckMovieHash2Result.cs37
-rw-r--r--OpenSubtitlesHandler/Movies/CheckMovieHashResult.cs41
-rw-r--r--OpenSubtitlesHandler/Movies/InsertMovieHashParameters.cs38
-rw-r--r--OpenSubtitlesHandler/Movies/MovieSearchResult.cs40
-rw-r--r--OpenSubtitlesHandler/Movies/SearchToMailMovieParameter.cs30
-rw-r--r--OpenSubtitlesHandler/OpenSubtitles.cs2744
-rw-r--r--OpenSubtitlesHandler/OpenSubtitlesHandler.csproj13
-rw-r--r--OpenSubtitlesHandler/OtherTypes/GetAvailableTranslationsResult.cs39
-rw-r--r--OpenSubtitlesHandler/OtherTypes/GetCommentsResult.cs36
-rw-r--r--OpenSubtitlesHandler/Properties/AssemblyInfo.cs24
-rw-r--r--OpenSubtitlesHandler/Readme.txt20
-rw-r--r--OpenSubtitlesHandler/SubtitleTypes/CheckSubHashResult.cs30
-rw-r--r--OpenSubtitlesHandler/SubtitleTypes/SubtitleDownloadResult.cs43
-rw-r--r--OpenSubtitlesHandler/SubtitleTypes/SubtitleLanguage.cs39
-rw-r--r--OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs82
-rw-r--r--OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchResult.cs136
-rw-r--r--OpenSubtitlesHandler/SubtitleTypes/TryUploadSubtitlesParameters.cs47
-rw-r--r--OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleInfoParameter.cs46
-rw-r--r--OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleParameters.cs52
-rw-r--r--OpenSubtitlesHandler/Utilities.cs174
-rw-r--r--OpenSubtitlesHandler/XML-RPC/Docs/XML-RPC.txt225
-rw-r--r--OpenSubtitlesHandler/XML-RPC/Enums/XmlRpcValueType.cs25
-rw-r--r--OpenSubtitlesHandler/XML-RPC/Types/XmlRpcMethodCall.cs63
-rw-r--r--OpenSubtitlesHandler/XML-RPC/Values/IXmlRpcValue.cs36
-rw-r--r--OpenSubtitlesHandler/XML-RPC/Values/XmlRpcStructMember.cs43
-rw-r--r--OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueArray.cs121
-rw-r--r--OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueBasic.cs99
-rw-r--r--OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueStruct.cs43
-rw-r--r--OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs350
-rw-r--r--README.md2
-rw-r--r--RSSDP/ISsdpCommunicationsServer.cs6
-rw-r--r--RSSDP/Properties/AssemblyInfo.cs4
-rw-r--r--RSSDP/RSSDP.csproj1
-rw-r--r--RSSDP/SsdpCommunicationsServer.cs23
-rw-r--r--RSSDP/SsdpDeviceLocator.cs2
-rw-r--r--RSSDP/SsdpDevicePublisher.cs19
-rw-r--r--RSSDP/SsdpRootDevice.cs10
-rw-r--r--SharedVersion.cs4
-rw-r--r--SocketHttpListener/ByteOrder.cs17
-rw-r--r--SocketHttpListener/CloseEventArgs.cs79
-rw-r--r--SocketHttpListener/CloseStatusCode.cs94
-rw-r--r--SocketHttpListener/CompressionMethod.cs23
-rw-r--r--SocketHttpListener/ErrorEventArgs.cs42
-rw-r--r--SocketHttpListener/Ext.cs960
-rw-r--r--SocketHttpListener/Fin.cs8
-rw-r--r--SocketHttpListener/HttpBase.cs70
-rw-r--r--SocketHttpListener/HttpResponse.cs123
-rw-r--r--SocketHttpListener/Mask.cs8
-rw-r--r--SocketHttpListener/MessageEventArgs.cs84
-rw-r--r--SocketHttpListener/Net/AuthenticationSchemeSelector.cs6
-rw-r--r--SocketHttpListener/Net/AuthenticationTypes.cs9
-rw-r--r--SocketHttpListener/Net/BoundaryType.cs11
-rw-r--r--SocketHttpListener/Net/ChunkStream.cs385
-rw-r--r--SocketHttpListener/Net/ChunkedInputStream.cs178
-rw-r--r--SocketHttpListener/Net/CookieHelper.cs141
-rw-r--r--SocketHttpListener/Net/EntitySendFormat.cs8
-rw-r--r--SocketHttpListener/Net/HttpConnection.cs528
-rw-r--r--SocketHttpListener/Net/HttpEndPointListener.cs526
-rw-r--r--SocketHttpListener/Net/HttpEndPointManager.cs192
-rw-r--r--SocketHttpListener/Net/HttpKnownHeaderNames.cs91
-rw-r--r--SocketHttpListener/Net/HttpListener.cs277
-rw-r--r--SocketHttpListener/Net/HttpListenerBasicIdentity.cs49
-rw-r--r--SocketHttpListener/Net/HttpListenerContext.Managed.cs99
-rw-r--r--SocketHttpListener/Net/HttpListenerContext.cs74
-rw-r--r--SocketHttpListener/Net/HttpListenerPrefixCollection.cs88
-rw-r--r--SocketHttpListener/Net/HttpListenerRequest.Managed.cs325
-rw-r--r--SocketHttpListener/Net/HttpListenerRequest.cs537
-rw-r--r--SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs443
-rw-r--r--SocketHttpListener/Net/HttpListenerResponse.Managed.cs333
-rw-r--r--SocketHttpListener/Net/HttpListenerResponse.cs294
-rw-r--r--SocketHttpListener/Net/HttpRequestStream.Managed.cs210
-rw-r--r--SocketHttpListener/Net/HttpRequestStream.cs129
-rw-r--r--SocketHttpListener/Net/HttpResponseStream.Managed.cs329
-rw-r--r--SocketHttpListener/Net/HttpResponseStream.cs124
-rw-r--r--SocketHttpListener/Net/HttpStatusCode.cs321
-rw-r--r--SocketHttpListener/Net/HttpStatusDescription.cs69
-rw-r--r--SocketHttpListener/Net/HttpStreamAsyncResult.cs79
-rw-r--r--SocketHttpListener/Net/HttpVersion.cs16
-rw-r--r--SocketHttpListener/Net/ListenerPrefix.cs89
-rw-r--r--SocketHttpListener/Net/UriScheme.cs20
-rw-r--r--SocketHttpListener/Net/WebHeaderCollection.cs360
-rw-r--r--SocketHttpListener/Net/WebHeaderEncoding.cs84
-rw-r--r--SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs92
-rw-r--r--SocketHttpListener/Net/WebSockets/HttpWebSocket.Managed.cs81
-rw-r--r--SocketHttpListener/Net/WebSockets/HttpWebSocket.cs159
-rw-r--r--SocketHttpListener/Net/WebSockets/WebSocketCloseStatus.cs27
-rw-r--r--SocketHttpListener/Net/WebSockets/WebSocketContext.cs24
-rw-r--r--SocketHttpListener/Net/WebSockets/WebSocketValidate.cs141
-rw-r--r--SocketHttpListener/Opcode.cs43
-rw-r--r--SocketHttpListener/PayloadData.cs130
-rw-r--r--SocketHttpListener/Properties/AssemblyInfo.cs21
-rw-r--r--SocketHttpListener/Rsv.cs8
-rw-r--r--SocketHttpListener/SocketHttpListener.csproj18
-rw-r--r--SocketHttpListener/SocketStream.cs74
-rw-r--r--SocketHttpListener/WebSocket.cs776
-rw-r--r--SocketHttpListener/WebSocketException.cs61
-rw-r--r--SocketHttpListener/WebSocketFrame.cs433
-rwxr-xr-xbuild60
-rw-r--r--build.yaml15
-rwxr-xr-xdeployment/common.build.sh7
-rw-r--r--deployment/debian-package-armhf/Dockerfile.amd6442
-rw-r--r--deployment/debian-package-armhf/Dockerfile.armhf34
-rwxr-xr-xdeployment/debian-package-armhf/clean.sh29
-rw-r--r--deployment/debian-package-armhf/dependencies.txt1
-rwxr-xr-xdeployment/debian-package-armhf/docker-build.sh20
-rwxr-xr-xdeployment/debian-package-armhf/package.sh42
l---------deployment/debian-package-armhf/pkg-src1
-rw-r--r--deployment/debian-package-x64/pkg-src/changelog33
-rw-r--r--deployment/debian-package-x64/pkg-src/conf/jellyfin15
-rw-r--r--deployment/debian-package-x64/pkg-src/control2
-rw-r--r--deployment/debian-package-x64/pkg-src/jellyfin.init62
-rw-r--r--deployment/debian-package-x64/pkg-src/jellyfin.service2
-rw-r--r--deployment/debian-package-x64/pkg-src/rules21
-rwxr-xr-xdeployment/debian-x64/build.sh7
-rw-r--r--deployment/fedora-package-x64/Dockerfile2
-rw-r--r--deployment/fedora-package-x64/pkg-src/jellyfin.env9
-rw-r--r--deployment/fedora-package-x64/pkg-src/jellyfin.service2
-rw-r--r--deployment/fedora-package-x64/pkg-src/jellyfin.spec35
-rwxr-xr-xdeployment/macos/build.sh (renamed from deployment/osx-x64/build.sh)0
-rwxr-xr-xdeployment/macos/clean.sh (renamed from deployment/debian-x64/clean.sh)0
-rw-r--r--deployment/macos/dependencies.txt (renamed from deployment/debian-x64/dependencies.txt)0
-rwxr-xr-xdeployment/macos/package.sh (renamed from deployment/debian-x64/package.sh)0
-rwxr-xr-xdeployment/osx-x64/clean.sh7
-rwxr-xr-xdeployment/osx-x64/package.sh7
-rwxr-xr-xdeployment/portable/build.sh (renamed from deployment/framework/build.sh)0
-rwxr-xr-xdeployment/portable/clean.sh (renamed from deployment/framework/clean.sh)0
-rwxr-xr-xdeployment/portable/package.sh (renamed from deployment/framework/package.sh)0
-rwxr-xr-xdeployment/ubuntu-x64/build.sh7
-rwxr-xr-xdeployment/ubuntu-x64/clean.sh7
-rw-r--r--deployment/ubuntu-x64/dependencies.txt1
-rwxr-xr-xdeployment/ubuntu-x64/package.sh7
-rw-r--r--deployment/win-generic/dependencies.txt1
-rwxr-xr-xdeployment/win-x64/package.sh4
-rwxr-xr-xdeployment/win-x86/package.sh4
-rw-r--r--deployment/windows/build-jellyfin.ps1 (renamed from deployment/win-generic/build-jellyfin.ps1)4
-rw-r--r--deployment/windows/dependencies.txt (renamed from deployment/osx-x64/dependencies.txt)0
-rw-r--r--deployment/windows/install-jellyfin.ps1 (renamed from deployment/win-generic/install-jellyfin.ps1)0
-rw-r--r--deployment/windows/install.bat (renamed from deployment/win-generic/install.bat)0
-rw-r--r--jellyfin.ruleset8
-rw-r--r--new-file-header.txt22
499 files changed, 9149 insertions, 28067 deletions
diff --git a/.ci/azure-pipelines.yml b/.ci/azure-pipelines.yml
new file mode 100644
index 000000000..7a92d4088
--- /dev/null
+++ b/.ci/azure-pipelines.yml
@@ -0,0 +1,192 @@
+name: $(Date:yyyyMMdd)$(Rev:.r)
+
+variables:
+ - name: TestProjects
+ value: 'Jellyfin.Server.Tests/Jellyfin.Server.Tests.csproj'
+ - name: RestoreBuildProjects
+ value: 'Jellyfin.Server/Jellyfin.Server.csproj'
+
+pr:
+ autoCancel: true
+
+trigger:
+ batch: true
+
+jobs:
+ - job: main_build
+ displayName: Main Build
+ pool:
+ vmImage: ubuntu-16.04
+ strategy:
+ matrix:
+ release:
+ BuildConfiguration: Release
+ debug:
+ BuildConfiguration: Debug
+ maxParallel: 2
+ steps:
+ - checkout: self
+ clean: true
+ submodules: true
+ persistCredentials: false
+
+ - task: DotNetCoreCLI@2
+ displayName: Restore
+ inputs:
+ command: restore
+ projects: '$(RestoreBuildProjects)'
+
+ - task: DotNetCoreCLI@2
+ displayName: Build
+ inputs:
+ projects: '$(RestoreBuildProjects)'
+ arguments: '--configuration $(BuildConfiguration)'
+
+ - task: DotNetCoreCLI@2
+ displayName: Test
+ inputs:
+ command: test
+ projects: '$(RestoreBuildProjects)'
+ arguments: '--configuration $(BuildConfiguration)'
+ enabled: false
+
+ - task: DotNetCoreCLI@2
+ displayName: Publish
+ inputs:
+ command: publish
+ publishWebProjects: false
+ projects: '$(RestoreBuildProjects)'
+ arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
+ zipAfterPublish: false
+
+ # - task: PublishBuildArtifacts@1
+ # displayName: 'Publish Artifact'
+ # inputs:
+ # PathtoPublish: '$(build.artifactstagingdirectory)'
+ # artifactName: 'jellyfin-build-$(BuildConfiguration)'
+ # zipAfterPublish: true
+
+ - task: PublishBuildArtifacts@1
+ displayName: 'Publish Artifact Naming'
+ condition: and(eq(variables['BuildConfiguration'], 'Release'), succeeded())
+ inputs:
+ PathtoPublish: '$(build.artifactstagingdirectory)/Jellyfin.Server/Emby.Naming.dll'
+ artifactName: 'Jellyfin.Naming'
+
+ - task: PublishBuildArtifacts@1
+ displayName: 'Publish Artifact Controller'
+ condition: and(eq(variables['BuildConfiguration'], 'Release'), succeeded())
+ inputs:
+ PathtoPublish: '$(build.artifactstagingdirectory)/Jellyfin.Server/MediaBrowser.Controller.dll'
+ artifactName: 'Jellyfin.Controller'
+
+ - task: PublishBuildArtifacts@1
+ displayName: 'Publish Artifact Model'
+ condition: and(eq(variables['BuildConfiguration'], 'Release'), succeeded())
+ inputs:
+ PathtoPublish: '$(build.artifactstagingdirectory)/Jellyfin.Server/MediaBrowser.Model.dll'
+ artifactName: 'Jellyfin.Model'
+
+ - task: PublishBuildArtifacts@1
+ displayName: 'Publish Artifact Common'
+ condition: and(eq(variables['BuildConfiguration'], 'Release'), succeeded())
+ inputs:
+ PathtoPublish: '$(build.artifactstagingdirectory)/Jellyfin.Server/MediaBrowser.Common.dll'
+ artifactName: 'Jellyfin.Common'
+
+ - job: dotnet_compat
+ displayName: Compatibility Check
+ pool:
+ vmImage: ubuntu-16.04
+ dependsOn: main_build
+ condition: and(succeeded(), variables['System.PullRequest.PullRequestNumber']) # Only execute if the pullrequest numer is defined. (So not for normal CI builds)
+ strategy:
+ matrix:
+ Naming:
+ NugetPackageName: Jellyfin.Naming
+ AssemblyFileName: Emby.Naming.dll
+ Controller:
+ NugetPackageName: Jellyfin.Controller
+ AssemblyFileName: MediaBrowser.Controller.dll
+ Model:
+ NugetPackageName: Jellyfin.Model
+ AssemblyFileName: MediaBrowser.Model.dll
+ Common:
+ NugetPackageName: Jellyfin.Common
+ AssemblyFileName: MediaBrowser.Common.dll
+ maxParallel: 2
+ steps:
+ - checkout: none
+
+ - task: DownloadBuildArtifacts@0
+ displayName: Download the Reference Assembly Build Artifact
+ inputs:
+ buildType: 'specific' # Options: current, specific
+ project: $(System.TeamProjectId) # Required when buildType == Specific
+ pipeline: $(System.DefinitionId) # Required when buildType == Specific, not sure if this will take a name too
+ #specificBuildWithTriggering: false # Optional
+ buildVersionToDownload: 'latestFromBranch' # Required when buildType == Specific# Options: latest, latestFromBranch, specific
+ allowPartiallySucceededBuilds: false # Optional
+ branchName: '$(System.PullRequest.TargetBranch)' # Required when buildType == Specific && BuildVersionToDownload == LatestFromBranch
+ #buildId: # Required when buildType == Specific && BuildVersionToDownload == Specific
+ #tags: # Optional
+ downloadType: 'single' # Options: single, specific
+ artifactName: '$(NugetPackageName)'# Required when downloadType == Single
+ #itemPattern: '**' # Optional
+ downloadPath: '$(System.ArtifactsDirectory)/current-artifacts'
+ #parallelizationLimit: '8' # Optional
+
+ - task: CopyFiles@2
+ displayName: Copy Nuget Assembly to current-release folder
+ inputs:
+ sourceFolder: $(System.ArtifactsDirectory)/current-artifacts # Optional
+ contents: '**/*.dll'
+ targetFolder: $(System.ArtifactsDirectory)/current-release
+ cleanTargetFolder: true # Optional
+ overWrite: true # Optional
+ flattenFolders: true # Optional
+
+ - task: DownloadBuildArtifacts@0
+ displayName: Download the New Assembly Build Artifact
+ inputs:
+ buildType: 'current' # Options: current, specific
+ allowPartiallySucceededBuilds: false # Optional
+ downloadType: 'single' # Options: single, specific
+ artifactName: '$(NugetPackageName)' # Required when downloadType == Single
+ downloadPath: '$(System.ArtifactsDirectory)/new-artifacts'
+
+ - task: CopyFiles@2
+ displayName: Copy Artifact Assembly to new-release folder
+ inputs:
+ sourceFolder: $(System.ArtifactsDirectory)/new-artifacts # Optional
+ contents: '**/*.dll'
+ targetFolder: $(System.ArtifactsDirectory)/new-release
+ cleanTargetFolder: true # Optional
+ overWrite: true # Optional
+ flattenFolders: true # Optional
+
+ - task: DownloadGitHubRelease@0
+ displayName: Download ABI compatibility check tool from GitHub
+ inputs:
+ connection: Jellyfin GitHub
+ userRepository: EraYaN/dotnet-compatibility
+ defaultVersionType: 'latest' # Options: latest, specificVersion, specificTag
+ #version: # Required when defaultVersionType != Latest
+ itemPattern: '**-ci.zip' # Optional
+ downloadPath: '$(System.ArtifactsDirectory)'
+
+ - task: ExtractFiles@1
+ displayName: Extract ABI compatibility check tool
+ inputs:
+ archiveFilePatterns: '$(System.ArtifactsDirectory)/*-ci.zip'
+ destinationFolder: $(System.ArtifactsDirectory)/tools
+ cleanDestinationFolder: true
+
+ - task: CmdLine@2
+ displayName: Execute ABI compatibility check tool
+ inputs:
+ script: 'dotnet tools/CompatibilityCheckerCoreCLI.dll current-release/$(AssemblyFileName) new-release/$(AssemblyFileName)'
+ workingDirectory: $(System.ArtifactsDirectory) # Optional
+ #failOnStderr: false # Optional
+
+
diff --git a/.drone.yml b/.drone.yml
index 972bf36f3..87c8e414e 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -28,84 +28,3 @@ steps:
commands:
- dotnet publish "Jellyfin.Server" --configuration Release --output "../ci/ci-release"
----
-
-kind: pipeline
-name: check-abi
-
-steps:
-- name: submodules
- image: docker:git
- commands:
- - git submodule update --init --recursive
-
-- name: build
- image: microsoft/dotnet:2-sdk
- commands:
- - dotnet publish "Jellyfin.Server" --configuration Release --output "../ci/ci-release"
-
-- name: clone-dotnet-compat
- image: docker:git
- commands:
- - git clone --depth 1 https://github.com/EraYaN/dotnet-compatibility ci/dotnet-compatibility
-
-- name: build-dotnet-compat
- image: microsoft/dotnet:2-sdk
- commands:
- - dotnet publish "ci/dotnet-compatibility/CompatibilityCheckerCoreCLI" --configuration Release --output "../../ci-tools"
-
-- name: download-last-nuget-release-common
- image: plugins/download
- settings:
- source: https://www.nuget.org/api/v2/package/Jellyfin.Common
- destination: ci/Jellyfin.Common.nupkg
-
-- name: download-last-nuget-release-model
- image: plugins/download
- settings:
- source: https://www.nuget.org/api/v2/package/Jellyfin.Model
- destination: ci/Jellyfin.Model.nupkg
-
-- name: download-last-nuget-release-controller
- image: plugins/download
- settings:
- source: https://www.nuget.org/api/v2/package/Jellyfin.Controller
- destination: ci/Jellyfin.Controller.nupkg
-
-- name: download-last-nuget-release-naming
- image: plugins/download
- settings:
- source: https://www.nuget.org/api/v2/package/Jellyfin.Naming
- destination: ci/Jellyfin.Naming.nupkg
-
-- name: extract-downloaded-nuget-packages
- image: garthk/unzip
- commands:
- - unzip -j ci/Jellyfin.Common.nupkg "*.dll" -d ci/nuget-packages
- - unzip -j ci/Jellyfin.Model.nupkg "*.dll" -d ci/nuget-packages
- - unzip -j ci/Jellyfin.Controller.nupkg "*.dll" -d ci/nuget-packages
- - unzip -j ci/Jellyfin.Naming.nupkg "*.dll" -d ci/nuget-packages
-
-- name: run-dotnet-compat-common
- image: microsoft/dotnet:2-runtime
- err_ignore: true
- commands:
- - dotnet ci/ci-tools/CompatibilityCheckerCoreCLI.dll ci/nuget-packages/Jellyfin.Common.dll ci/ci-release/Jellyfin.Common.dll
-
-- name: run-dotnet-compat-model
- image: microsoft/dotnet:2-runtime
- err_ignore: true
- commands:
- - dotnet ci/ci-tools/CompatibilityCheckerCoreCLI.dll ci/nuget-packages/Jellyfin.Model.dll ci/ci-release/Jellyfin.Model.dll
-
-- name: run-dotnet-compat-controller
- image: microsoft/dotnet:2-runtime
- err_ignore: true
- commands:
- - dotnet ci/ci-tools/CompatibilityCheckerCoreCLI.dll ci/nuget-packages/Jellyfin.Controller.dll ci/ci-release/Jellyfin.Controller.dll
-
-- name: run-dotnet-compat-naming
- image: microsoft/dotnet:2-runtime
- err_ignore: true
- commands:
- - dotnet ci/ci-tools/CompatibilityCheckerCoreCLI.dll ci/nuget-packages/Jellyfin.Naming.dll ci/ci-release/Jellyfin.Naming.dll
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index 137a689e8..ca89c1cb9 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -30,6 +30,7 @@ assignees: ''
- OS: [e.g. Docker, Debian, Windows]
- Browser: [e.g. Firefox, Chrome, Safari]
- Jellyfin Version: [e.g. 10.0.1]
+ - Reverse proxy: [e.g. no, nginx, apache, etc.]
**Additional context**
<!-- Add any other context about the problem here. -->
diff --git a/.gitignore b/.gitignore
index 65e47747e..a1b7ac59c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -266,3 +266,6 @@ deployment/collect-dist/
jellyfin_version.ini
ci/
+
+# Doxygen
+doc/ \ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
index c10f5905c..2b97b1331 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,4 @@
[submodule "MediaBrowser.WebDashboard/jellyfin-web"]
path = MediaBrowser.WebDashboard/jellyfin-web
url = https://github.com/jellyfin/jellyfin-web.git
+ branch = .
diff --git a/BDInfo/Properties/AssemblyInfo.cs b/BDInfo/Properties/AssemblyInfo.cs
index 788cf7366..f65c7036a 100644
--- a/BDInfo/Properties/AssemblyInfo.cs
+++ b/BDInfo/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2016 CinemaSquid. Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2016 CinemaSquid. Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 28690f36f..81857e57c 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -19,6 +19,11 @@
- [LogicalPhallacy](https://github.com/LogicalPhallacy/)
- [RazeLighter777](https://github.com/RazeLighter777)
- [WillWill56](https://github.com/WillWill56)
+ - [Liggy](https://github.com/Liggy)
+ - [fruhnow](https://github.com/fruhnow)
+ - [Lynxy](https://github.com/Lynxy)
+ - [fasheng](https://github.com/fasheng)
+ - [ploughpuff](https://github.com/ploughpuff)
# Emby Contributors
diff --git a/Dockerfile b/Dockerfile
index 6c0d2515f..5794bdde1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,12 +4,10 @@ FROM microsoft/dotnet:${DOTNET_VERSION}-sdk as builder
WORKDIR /repo
COPY . .
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
-RUN dotnet publish \
- --configuration release \
- --output /jellyfin \
- Jellyfin.Server
+RUN bash -c "source deployment/common.build.sh && \
+ build_jellyfin Jellyfin.Server Release linux-x64 /jellyfin"
-FROM jrottenberg/ffmpeg:4.0-vaapi as ffmpeg
+FROM jellyfin/ffmpeg as ffmpeg
FROM microsoft/dotnet:${DOTNET_VERSION}-runtime
# libfontconfig1 is required for Skia
RUN apt-get update \
@@ -17,11 +15,20 @@ RUN apt-get update \
libfontconfig1 \
&& apt-get clean autoclean \
&& apt-get autoremove \
- && rm -rf /var/lib/{apt,dpkg,cache,log} \
+ && rm -rf /var/lib/apt/lists/* \
&& mkdir -p /cache /config /media \
&& chmod 777 /cache /config /media
COPY --from=ffmpeg / /
COPY --from=builder /jellyfin /jellyfin
+
+ARG JELLYFIN_WEB_VERSION=10.2.2
+RUN curl -L https://github.com/jellyfin/jellyfin-web/archive/v${JELLYFIN_WEB_VERSION}.tar.gz | tar zxf - \
+ && rm -rf /jellyfin/jellyfin-web \
+ && mv jellyfin-web-${JELLYFIN_WEB_VERSION} /jellyfin/jellyfin-web
+
EXPOSE 8096
VOLUME /cache /config /media
-ENTRYPOINT dotnet /jellyfin/jellyfin.dll --datadir /config --cachedir /cache
+ENTRYPOINT dotnet /jellyfin/jellyfin.dll \
+ --datadir /config \
+ --cachedir /cache \
+ --ffmpeg /usr/local/bin/ffmpeg
diff --git a/Dockerfile.arm b/Dockerfile.arm
index 9d1c30619..1497da0ef 100644
--- a/Dockerfile.arm
+++ b/Dockerfile.arm
@@ -17,20 +17,27 @@ RUN find . -type f -exec sed -i 's/netcoreapp2.1/netcoreapp3.0/g' {} \;
# Discard objs - may cause failures if exists
RUN find . -type d -name obj | xargs -r rm -r
# Build
-RUN dotnet publish \
- -r linux-arm \
- --configuration release \
- --output /jellyfin \
- Jellyfin.Server
+RUN bash -c "source deployment/common.build.sh && \
+ build_jellyfin Jellyfin.Server Release linux-arm /jellyfin"
FROM microsoft/dotnet:${DOTNET_VERSION}-runtime-stretch-slim-arm32v7
COPY --from=qemu_extract qemu-arm-static /usr/bin
RUN apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y ffmpeg \
+ && rm -rf /var/lib/apt/lists/* \
&& mkdir -p /cache /config /media \
&& chmod 777 /cache /config /media
COPY --from=builder /jellyfin /jellyfin
+
+ARG JELLYFIN_WEB_VERSION=10.2.2
+RUN curl -L https://github.com/jellyfin/jellyfin-web/archive/v${JELLYFIN_WEB_VERSION}.tar.gz | tar zxf - \
+ && rm -rf /jellyfin/jellyfin-web \
+ && mv jellyfin-web-${JELLYFIN_WEB_VERSION} /jellyfin/jellyfin-web
+
EXPOSE 8096
VOLUME /cache /config /media
-ENTRYPOINT dotnet /jellyfin/jellyfin.dll --datadir /config --cachedir /cache
+ENTRYPOINT dotnet /jellyfin/jellyfin.dll \
+ --datadir /config \
+ --cachedir /cache \
+ --ffmpeg /usr/bin/ffmpeg
diff --git a/Dockerfile.arm64 b/Dockerfile.arm64
index e61aaa167..f4658a055 100644
--- a/Dockerfile.arm64
+++ b/Dockerfile.arm64
@@ -18,20 +18,27 @@ RUN find . -type f -exec sed -i 's/netcoreapp2.1/netcoreapp3.0/g' {} \;
# Discard objs - may cause failures if exists
RUN find . -type d -name obj | xargs -r rm -r
# Build
-RUN dotnet publish \
- -r linux-arm64 \
- --configuration release \
- --output /jellyfin \
- Jellyfin.Server
+RUN bash -c "source deployment/common.build.sh && \
+ build_jellyfin Jellyfin.Server Release linux-arm64 /jellyfin"
FROM microsoft/dotnet:${DOTNET_VERSION}-runtime-stretch-slim-arm64v8
COPY --from=qemu_extract qemu-aarch64-static /usr/bin
RUN apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y ffmpeg \
+ && rm -rf /var/lib/apt/lists/* \
&& mkdir -p /cache /config /media \
&& chmod 777 /cache /config /media
COPY --from=builder /jellyfin /jellyfin
+
+ARG JELLYFIN_WEB_VERSION=10.2.2
+RUN curl -L https://github.com/jellyfin/jellyfin-web/archive/v${JELLYFIN_WEB_VERSION}.tar.gz | tar zxf - \
+ && rm -rf /jellyfin/jellyfin-web \
+ && mv jellyfin-web-${JELLYFIN_WEB_VERSION} /jellyfin/jellyfin-web
+
EXPOSE 8096
VOLUME /cache /config /media
-ENTRYPOINT dotnet /jellyfin/jellyfin.dll --datadir /config --cachedir /cache
+ENTRYPOINT dotnet /jellyfin/jellyfin.dll \
+ --datadir /config \
+ --cachedir /cache \
+ --ffmpeg /usr/bin/ffmpeg
diff --git a/Doxyfile b/Doxyfile
new file mode 100644
index 000000000..1628b4bde
--- /dev/null
+++ b/Doxyfile
@@ -0,0 +1,2565 @@
+# Doxyfile 1.8.15
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project.
+#
+# All text after a double hash (##) is considered a comment and is placed in
+# front of the TAG it is preceding.
+#
+# All text after a single hash (#) is considered a comment and will be ignored.
+# The format is:
+# TAG = value [value, ...]
+# For lists, items can also be appended using:
+# TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (\" \").
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the configuration
+# file that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# https://www.gnu.org/software/libiconv/ for the list of possible encodings.
+# The default value is: UTF-8.
+
+DOXYFILE_ENCODING = UTF-8
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by
+# double-quotes, unless you are using Doxywizard) that should identify the
+# project for which the documentation is generated. This name is used in the
+# title of most generated pages and in a few other places.
+# The default value is: My Project.
+
+PROJECT_NAME = Jellyfin
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
+# could be handy for archiving the generated documentation or if some version
+# control system is used.
+
+PROJECT_NUMBER =
+
+# Using the PROJECT_BRIEF tag one can provide an optional one line description
+# for a project that appears at the top of each page and should give viewer a
+# quick idea about the purpose of the project. Keep the description short.
+
+PROJECT_BRIEF = "The Free Software Media System"
+
+# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
+# in the documentation. The maximum height of the logo should not exceed 55
+# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
+# the logo to the output directory.
+
+PROJECT_LOGO =
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
+# into which the generated documentation will be written. If a relative path is
+# entered, it will be relative to the location where doxygen was started. If
+# left blank the current directory will be used.
+
+OUTPUT_DIRECTORY = doc
+
+# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
+# directories (in 2 levels) under the output directory of each output format and
+# will distribute the generated files over these directories. Enabling this
+# option can be useful when feeding doxygen a huge amount of source files, where
+# putting all generated files in the same directory would otherwise causes
+# performance problems for the file system.
+# The default value is: NO.
+
+CREATE_SUBDIRS = NO
+
+# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII
+# characters to appear in the names of generated files. If set to NO, non-ASCII
+# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode
+# U+3044.
+# The default value is: NO.
+
+ALLOW_UNICODE_NAMES = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese,
+# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States),
+# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian,
+# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages),
+# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian,
+# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian,
+# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,
+# Ukrainian and Vietnamese.
+# The default value is: English.
+
+OUTPUT_LANGUAGE = English
+
+# The OUTPUT_TEXT_DIRECTION tag is used to specify the direction in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all generated output in the proper direction.
+# Possible values are: None, LTR, RTL and Context.
+# The default value is: None.
+
+OUTPUT_TEXT_DIRECTION = None
+
+# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member
+# descriptions after the members that are listed in the file and class
+# documentation (similar to Javadoc). Set to NO to disable this.
+# The default value is: YES.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief
+# description of a member or function before the detailed description
+#
+# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+# The default value is: YES.
+
+REPEAT_BRIEF = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator that is
+# used to form the text in various listings. Each string in this list, if found
+# as the leading text of the brief description, will be stripped from the text
+# and the result, after processing the whole list, is used as the annotated
+# text. Otherwise, the brief description is used as-is. If left blank, the
+# following values are used ($name is automatically replaced with the name of
+# the entity):The $name class, The $name widget, The $name file, is, provides,
+# specifies, contains, represents, a, an and the.
+
+ABBREVIATE_BRIEF = "The $name class" \
+ "The $name widget" \
+ "The $name file" \
+ is \
+ provides \
+ specifies \
+ contains \
+ represents \
+ a \
+ an \
+ the
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# doxygen will generate a detailed section even if there is only a brief
+# description.
+# The default value is: NO.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+# The default value is: NO.
+
+INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
+# before files name in the file list and in the header files. If set to NO the
+# shortest path that makes the file name unique will be used
+# The default value is: YES.
+
+FULL_PATH_NAMES = YES
+
+# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
+# Stripping is only done if one of the specified strings matches the left-hand
+# part of the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the path to
+# strip.
+#
+# Note that you can specify absolute paths here, but also relative paths, which
+# will be relative from the directory where doxygen is started.
+# This tag requires that the tag FULL_PATH_NAMES is set to YES.
+
+STRIP_FROM_PATH =
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
+# path mentioned in the documentation of a class, which tells the reader which
+# header file to include in order to use a class. If left blank only the name of
+# the header file containing the class definition is used. Otherwise one should
+# specify the list of include paths that are normally passed to the compiler
+# using the -I flag.
+
+STRIP_FROM_INC_PATH =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
+# less readable) file names. This can be useful is your file systems doesn't
+# support long names like on DOS, Mac, or CD-ROM.
+# The default value is: NO.
+
+SHORT_NAMES = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the
+# first line (until the first dot) of a Javadoc-style comment as the brief
+# description. If set to NO, the Javadoc-style will behave just like regular Qt-
+# style comments (thus requiring an explicit @brief command for a brief
+# description.)
+# The default value is: NO.
+
+JAVADOC_AUTOBRIEF = NO
+
+# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
+# line (until the first dot) of a Qt-style comment as the brief description. If
+# set to NO, the Qt-style will behave just like regular Qt-style comments (thus
+# requiring an explicit \brief command for a brief description.)
+# The default value is: NO.
+
+QT_AUTOBRIEF = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a
+# multi-line C++ special comment block (i.e. a block of //! or /// comments) as
+# a brief description. This used to be the default behavior. The new default is
+# to treat a multi-line C++ comment block as a detailed description. Set this
+# tag to YES if you prefer the old behavior instead.
+#
+# Note that setting this tag to YES also means that rational rose comments are
+# not recognized any more.
+# The default value is: NO.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
+# documentation from any documented member that it re-implements.
+# The default value is: YES.
+
+INHERIT_DOCS = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new
+# page for each member. If set to NO, the documentation of a member will be part
+# of the file/class/namespace that contains it.
+# The default value is: NO.
+
+SEPARATE_MEMBER_PAGES = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen
+# uses this value to replace tabs by spaces in code fragments.
+# Minimum value: 1, maximum value: 16, default value: 4.
+
+TAB_SIZE = 4
+
+# This tag can be used to specify a number of aliases that act as commands in
+# the documentation. An alias has the form:
+# name=value
+# For example adding
+# "sideeffect=@par Side Effects:\n"
+# will allow you to put the command \sideeffect (or @sideeffect) in the
+# documentation, which will result in a user-defined paragraph with heading
+# "Side Effects:". You can put \n's in the value part of an alias to insert
+# newlines (in the resulting output). You can put ^^ in the value part of an
+# alias to insert a newline as if a physical newline was in the original file.
+# When you need a literal { or } or , in the value part of an alias you have to
+# escape them by means of a backslash (\), this can lead to conflicts with the
+# commands \{ and \} for these it is advised to use the version @{ and @} or use
+# a double escape (\\{ and \\})
+
+ALIASES =
+
+# This tag can be used to specify a number of word-keyword mappings (TCL only).
+# A mapping has the form "name=value". For example adding "class=itcl::class"
+# will allow you to use the command class in the itcl::class meaning.
+
+TCL_SUBST =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
+# only. Doxygen will then generate output that is more tailored for C. For
+# instance, some of the names that are used will be different. The list of all
+# members will be omitted, etc.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_FOR_C = NO
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or
+# Python sources only. Doxygen will then generate output that is more tailored
+# for that language. For instance, namespaces will be presented as packages,
+# qualified scopes will look different, etc.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_JAVA = YES
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources. Doxygen will then generate output that is tailored for Fortran.
+# The default value is: NO.
+
+OPTIMIZE_FOR_FORTRAN = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for VHDL.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_VHDL = NO
+
+# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice
+# sources only. Doxygen will then generate output that is more tailored for that
+# language. For instance, namespaces will be presented as modules, types will be
+# separated into more groups, etc.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_SLICE = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it
+# parses. With this tag you can assign which parser to use for a given
+# extension. Doxygen has a built-in mapping, but you can override or extend it
+# using this tag. The format is ext=language, where ext is a file extension, and
+# language is one of the parsers supported by doxygen: IDL, Java, Javascript,
+# Csharp (C#), C, C++, D, PHP, md (Markdown), Objective-C, Python, Slice,
+# Fortran (fixed format Fortran: FortranFixed, free formatted Fortran:
+# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser
+# tries to guess whether the code is fixed or free formatted code, this is the
+# default for Fortran type files), VHDL, tcl. For instance to make doxygen treat
+# .inc files as Fortran files (default is PHP), and .f files as C (default is
+# Fortran), use: inc=Fortran f=C.
+#
+# Note: For files without extension you can use no_extension as a placeholder.
+#
+# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
+# the files are not read by doxygen.
+
+EXTENSION_MAPPING =
+
+# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
+# according to the Markdown format, which allows for more readable
+# documentation. See https://daringfireball.net/projects/markdown/ for details.
+# The output of markdown processing is further processed by doxygen, so you can
+# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in
+# case of backward compatibilities issues.
+# The default value is: YES.
+
+MARKDOWN_SUPPORT = YES
+
+# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up
+# to that level are automatically included in the table of contents, even if
+# they do not have an id attribute.
+# Note: This feature currently applies only to Markdown headings.
+# Minimum value: 0, maximum value: 99, default value: 0.
+# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.
+
+TOC_INCLUDE_HEADINGS = 0
+
+# When enabled doxygen tries to link words that correspond to documented
+# classes, or namespaces to their corresponding documentation. Such a link can
+# be prevented in individual cases by putting a % sign in front of the word or
+# globally by setting AUTOLINK_SUPPORT to NO.
+# The default value is: YES.
+
+AUTOLINK_SUPPORT = YES
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should set this
+# tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string);
+# versus func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+# The default value is: NO.
+
+BUILTIN_STL_SUPPORT = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+# The default value is: NO.
+
+CPP_CLI_SUPPORT = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:
+# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen
+# will parse them like normal C++ but will assume all classes use public instead
+# of private inheritance when no explicit protection keyword is present.
+# The default value is: NO.
+
+SIP_SUPPORT = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate
+# getter and setter methods for a property. Setting this option to YES will make
+# doxygen to replace the get and set methods by a property in the documentation.
+# This will only work if the methods are indeed getting or setting a simple
+# type. If this is not the case, or you want to show the methods anyway, you
+# should set this option to NO.
+# The default value is: YES.
+
+IDL_PROPERTY_SUPPORT = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+# The default value is: NO.
+
+DISTRIBUTE_GROUP_DOC = NO
+
+# If one adds a struct or class to a group and this option is enabled, then also
+# any nested class or struct is added to the same group. By default this option
+# is disabled and one has to add nested compounds explicitly via \ingroup.
+# The default value is: NO.
+
+GROUP_NESTED_COMPOUNDS = NO
+
+# Set the SUBGROUPING tag to YES to allow class member groups of the same type
+# (for instance a group of public functions) to be put as a subgroup of that
+# type (e.g. under the Public Functions section). Set it to NO to prevent
+# subgrouping. Alternatively, this can be done per class using the
+# \nosubgrouping command.
+# The default value is: YES.
+
+SUBGROUPING = YES
+
+# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions
+# are shown inside the group in which they are included (e.g. using \ingroup)
+# instead of on a separate page (for HTML and Man pages) or section (for LaTeX
+# and RTF).
+#
+# Note that this feature does not work in combination with
+# SEPARATE_MEMBER_PAGES.
+# The default value is: NO.
+
+INLINE_GROUPED_CLASSES = NO
+
+# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions
+# with only public data fields or simple typedef fields will be shown inline in
+# the documentation of the scope in which they are defined (i.e. file,
+# namespace, or group documentation), provided this scope is documented. If set
+# to NO, structs, classes, and unions are shown on a separate page (for HTML and
+# Man pages) or section (for LaTeX and RTF).
+# The default value is: NO.
+
+INLINE_SIMPLE_STRUCTS = NO
+
+# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or
+# enum is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically be
+# useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+# The default value is: NO.
+
+TYPEDEF_HIDES_STRUCT = NO
+
+# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This
+# cache is used to resolve symbols given their name and scope. Since this can be
+# an expensive process and often the same symbol appears multiple times in the
+# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small
+# doxygen will become slower. If the cache is too large, memory is wasted. The
+# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range
+# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536
+# symbols. At the end of a run doxygen will report the cache usage and suggest
+# the optimal cache size from a speed point of view.
+# Minimum value: 0, maximum value: 9, default value: 0.
+
+LOOKUP_CACHE_SIZE = 0
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in
+# documentation are documented, even if no documentation was available. Private
+# class members and static file members will be hidden unless the
+# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.
+# Note: This will also disable the warnings about undocumented members that are
+# normally produced when WARNINGS is set to YES.
+# The default value is: NO.
+
+EXTRACT_ALL = YES
+
+# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
+# be included in the documentation.
+# The default value is: NO.
+
+EXTRACT_PRIVATE = NO
+
+# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
+# scope will be included in the documentation.
+# The default value is: NO.
+
+EXTRACT_PACKAGE = NO
+
+# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be
+# included in the documentation.
+# The default value is: NO.
+
+EXTRACT_STATIC = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
+# locally in source files will be included in the documentation. If set to NO,
+# only classes defined in header files are included. Does not have any effect
+# for Java sources.
+# The default value is: YES.
+
+EXTRACT_LOCAL_CLASSES = YES
+
+# This flag is only useful for Objective-C code. If set to YES, local methods,
+# which are defined in the implementation section but not in the interface are
+# included in the documentation. If set to NO, only methods in the interface are
+# included.
+# The default value is: NO.
+
+EXTRACT_LOCAL_METHODS = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base name of
+# the file that contains the anonymous namespace. By default anonymous namespace
+# are hidden.
+# The default value is: NO.
+
+EXTRACT_ANON_NSPACES = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
+# undocumented members inside documented classes or files. If set to NO these
+# members will be included in the various overviews, but no documentation
+# section is generated. This option has no effect if EXTRACT_ALL is enabled.
+# The default value is: NO.
+
+HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy. If set
+# to NO, these classes will be included in the various overviews. This option
+# has no effect if EXTRACT_ALL is enabled.
+# The default value is: NO.
+
+HIDE_UNDOC_CLASSES = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
+# (class|struct|union) declarations. If set to NO, these declarations will be
+# included in the documentation.
+# The default value is: NO.
+
+HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any
+# documentation blocks found inside the body of a function. If set to NO, these
+# blocks will be appended to the function's detailed documentation block.
+# The default value is: NO.
+
+HIDE_IN_BODY_DOCS = NO
+
+# The INTERNAL_DOCS tag determines if documentation that is typed after a
+# \internal command is included. If the tag is set to NO then the documentation
+# will be excluded. Set it to YES to include the internal documentation.
+# The default value is: NO.
+
+INTERNAL_DOCS = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file
+# names in lower-case letters. If set to YES, upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+# The default value is: system dependent.
+
+CASE_SENSE_NAMES = NO
+
+# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with
+# their full class and namespace scopes in the documentation. If set to YES, the
+# scope will be hidden.
+# The default value is: NO.
+
+HIDE_SCOPE_NAMES = NO
+
+# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will
+# append additional text to a page's title, such as Class Reference. If set to
+# YES the compound reference will be hidden.
+# The default value is: NO.
+
+HIDE_COMPOUND_REFERENCE= NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of
+# the files that are included by a file in the documentation of that file.
+# The default value is: YES.
+
+SHOW_INCLUDE_FILES = YES
+
+# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each
+# grouped member an include statement to the documentation, telling the reader
+# which file to include in order to use the member.
+# The default value is: NO.
+
+SHOW_GROUPED_MEMB_INC = NO
+
+# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include
+# files with double quotes in the documentation rather than with sharp brackets.
+# The default value is: NO.
+
+FORCE_LOCAL_INCLUDES = NO
+
+# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
+# documentation for inline members.
+# The default value is: YES.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the
+# (detailed) documentation of file and class members alphabetically by member
+# name. If set to NO, the members will appear in declaration order.
+# The default value is: YES.
+
+SORT_MEMBER_DOCS = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
+# descriptions of file, namespace and class members alphabetically by member
+# name. If set to NO, the members will appear in declaration order. Note that
+# this will also influence the order of the classes in the class list.
+# The default value is: NO.
+
+SORT_BRIEF_DOCS = NO
+
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the
+# (brief and detailed) documentation of class members so that constructors and
+# destructors are listed first. If set to NO the constructors will appear in the
+# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.
+# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief
+# member documentation.
+# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting
+# detailed member documentation.
+# The default value is: NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy
+# of group names into alphabetical order. If set to NO the group names will
+# appear in their defined order.
+# The default value is: NO.
+
+SORT_GROUP_NAMES = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by
+# fully-qualified names, including namespaces. If set to NO, the class list will
+# be sorted only by class name, not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the alphabetical
+# list.
+# The default value is: NO.
+
+SORT_BY_SCOPE_NAME = NO
+
+# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper
+# type resolution of all parameters of a function it will reject a match between
+# the prototype and the implementation of a member function even if there is
+# only one candidate or it is obvious which candidate to choose by doing a
+# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still
+# accept a match between prototype and implementation in such cases.
+# The default value is: NO.
+
+STRICT_PROTO_MATCHING = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo
+# list. This list is created by putting \todo commands in the documentation.
+# The default value is: YES.
+
+GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test
+# list. This list is created by putting \test commands in the documentation.
+# The default value is: YES.
+
+GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug
+# list. This list is created by putting \bug commands in the documentation.
+# The default value is: YES.
+
+GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO)
+# the deprecated list. This list is created by putting \deprecated commands in
+# the documentation.
+# The default value is: YES.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional documentation
+# sections, marked by \if <section_label> ... \endif and \cond <section_label>
+# ... \endcond blocks.
+
+ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the
+# initial value of a variable or macro / define can have for it to appear in the
+# documentation. If the initializer consists of more lines than specified here
+# it will be hidden. Use a value of 0 to hide initializers completely. The
+# appearance of the value of individual variables and macros / defines can be
+# controlled using \showinitializer or \hideinitializer command in the
+# documentation regardless of this setting.
+# Minimum value: 0, maximum value: 10000, default value: 30.
+
+MAX_INITIALIZER_LINES = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at
+# the bottom of the documentation of classes and structs. If set to YES, the
+# list will mention the files that were used to generate the documentation.
+# The default value is: YES.
+
+SHOW_USED_FILES = YES
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This
+# will remove the Files entry from the Quick Index and from the Folder Tree View
+# (if specified).
+# The default value is: YES.
+
+SHOW_FILES = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces
+# page. This will remove the Namespaces entry from the Quick Index and from the
+# Folder Tree View (if specified).
+# The default value is: YES.
+
+SHOW_NAMESPACES = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command command input-file, where command is the value of the
+# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided
+# by doxygen. Whatever the program writes to standard output is used as the file
+# version. For an example see the documentation.
+
+FILE_VERSION_FILTER =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
+# by doxygen. The layout file controls the global structure of the generated
+# output files in an output format independent way. To create the layout file
+# that represents doxygen's defaults, run doxygen with the -l option. You can
+# optionally specify a file name after the option, if omitted DoxygenLayout.xml
+# will be used as the name of the layout file.
+#
+# Note that if you run doxygen from a directory containing a file called
+# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
+# tag is left empty.
+
+LAYOUT_FILE =
+
+# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
+# the reference definitions. This must be a list of .bib files. The .bib
+# extension is automatically appended if omitted. This requires the bibtex tool
+# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info.
+# For LaTeX the style of the bibliography can be controlled using
+# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the
+# search path. See also \cite for info how to create references.
+
+CITE_BIB_FILES =
+
+#---------------------------------------------------------------------------
+# Configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated to
+# standard output by doxygen. If QUIET is set to YES this implies that the
+# messages are off.
+# The default value is: NO.
+
+QUIET = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES
+# this implies that the warnings are on.
+#
+# Tip: Turn warnings on while writing the documentation.
+# The default value is: YES.
+
+WARNINGS = YES
+
+# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate
+# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag
+# will automatically be disabled.
+# The default value is: YES.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some parameters
+# in a documented function, or documenting parameters that don't exist or using
+# markup commands wrongly.
+# The default value is: YES.
+
+WARN_IF_DOC_ERROR = YES
+
+# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that
+# are documented, but have no documentation for their parameters or return
+# value. If set to NO, doxygen will only warn about wrong or incomplete
+# parameter documentation, but not about the absence of documentation. If
+# EXTRACT_ALL is set to YES then this flag will automatically be disabled.
+# The default value is: NO.
+
+WARN_NO_PARAMDOC = NO
+
+# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
+# a warning is encountered.
+# The default value is: NO.
+
+WARN_AS_ERROR = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that doxygen
+# can produce. The string should contain the $file, $line, and $text tags, which
+# will be replaced by the file and line number from which the warning originated
+# and the warning text. Optionally the format may contain $version, which will
+# be replaced by the version of the file (if it could be obtained via
+# FILE_VERSION_FILTER)
+# The default value is: $file:$line: $text.
+
+WARN_FORMAT = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning and error
+# messages should be written. If left blank the output is written to standard
+# error (stderr).
+
+WARN_LOGFILE =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag is used to specify the files and/or directories that contain
+# documented source files. You may enter file names like myfile.cpp or
+# directories like /usr/src/myproject. Separate the files or directories with
+# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
+# Note: If this tag is empty the current directory is searched.
+
+INPUT =
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
+# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
+# documentation (see: https://www.gnu.org/software/libiconv/) for the list of
+# possible encodings.
+# The default value is: UTF-8.
+
+INPUT_ENCODING = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and
+# *.h) to filter out the source-files in the directories.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# read by doxygen.
+#
+# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
+# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
+# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
+# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08,
+# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf, *.qsf and *.ice.
+
+FILE_PATTERNS = *.c \
+ *.cc \
+ *.cxx \
+ *.cpp \
+ *.c++ \
+ *.java \
+ *.ii \
+ *.ixx \
+ *.ipp \
+ *.i++ \
+ *.inl \
+ *.idl \
+ *.ddl \
+ *.odl \
+ *.h \
+ *.hh \
+ *.hxx \
+ *.hpp \
+ *.h++ \
+ *.cs \
+ *.d \
+ *.php \
+ *.php4 \
+ *.php5 \
+ *.phtml \
+ *.inc \
+ *.m \
+ *.markdown \
+ *.md \
+ *.mm \
+ *.dox \
+ *.py \
+ *.pyw \
+ *.f90 \
+ *.f95 \
+ *.f03 \
+ *.f08 \
+ *.f \
+ *.for \
+ *.tcl \
+ *.vhd \
+ *.vhdl \
+ *.ucf \
+ *.qsf \
+ *.ice
+
+# The RECURSIVE tag can be used to specify whether or not subdirectories should
+# be searched for input files as well.
+# The default value is: NO.
+
+RECURSIVE = YES
+
+# The EXCLUDE tag can be used to specify files and/or directories that should be
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+#
+# Note that relative paths are relative to the directory from which doxygen is
+# run.
+
+EXCLUDE =
+
+# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
+# directories that are symbolic links (a Unix file system feature) are excluded
+# from the input.
+# The default value is: NO.
+
+EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories.
+#
+# Note that the wildcards are matched against the file with absolute path, so to
+# exclude all test directories for example use the pattern */test/*
+
+EXCLUDE_PATTERNS =
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+#
+# Note that the wildcards are matched against the file with absolute path, so to
+# exclude all test directories use the pattern */test/*
+
+EXCLUDE_SYMBOLS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or directories
+# that contain example code fragments that are included (see the \include
+# command).
+
+EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
+# *.h) to filter out the source-files in the directories. If left blank all
+# files are included.
+
+EXAMPLE_PATTERNS = *
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude commands
+# irrespective of the value of the RECURSIVE tag.
+# The default value is: NO.
+
+EXAMPLE_RECURSIVE = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or directories
+# that contain images that are to be included in the documentation (see the
+# \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command:
+#
+# <filter> <input-file>
+#
+# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the
+# name of an input file. Doxygen will then use the output that the filter
+# program writes to standard output. If FILTER_PATTERNS is specified, this tag
+# will be ignored.
+#
+# Note that the filter must not add or remove lines; it is applied before the
+# code is scanned, but not when the output code is generated. If lines are added
+# or removed, the anchors will not be placed correctly.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# properly processed by doxygen.
+
+INPUT_FILTER =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis. Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match. The filters are a list of the form: pattern=filter
+# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how
+# filters are used. If the FILTER_PATTERNS tag is empty or if none of the
+# patterns match the file name, INPUT_FILTER is applied.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# properly processed by doxygen.
+
+FILTER_PATTERNS =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will also be used to filter the input files that are used for
+# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).
+# The default value is: NO.
+
+FILTER_SOURCE_FILES = NO
+
+# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
+# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and
+# it is also possible to disable source filtering for a specific pattern using
+# *.ext= (so without naming a filter).
+# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.
+
+FILTER_SOURCE_PATTERNS =
+
+# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that
+# is part of the input, its contents will be placed on the main page
+# (index.html). This can be useful if you have a project on for instance GitHub
+# and want to reuse the introduction page also for the doxygen output.
+
+USE_MDFILE_AS_MAINPAGE = ./README.md
+
+#---------------------------------------------------------------------------
+# Configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will be
+# generated. Documented entities will be cross-referenced with these sources.
+#
+# Note: To get rid of all source code in the generated output, make sure that
+# also VERBATIM_HEADERS is set to NO.
+# The default value is: NO.
+
+SOURCE_BROWSER = YES
+
+# Setting the INLINE_SOURCES tag to YES will include the body of functions,
+# classes and enums directly into the documentation.
+# The default value is: NO.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
+# special comment blocks from generated source code fragments. Normal C, C++ and
+# Fortran comments will always remain visible.
+# The default value is: YES.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES then for each documented
+# entity all documented functions referencing it will be listed.
+# The default value is: NO.
+
+REFERENCED_BY_RELATION = NO
+
+# If the REFERENCES_RELATION tag is set to YES then for each documented function
+# all documented entities called/used by that function will be listed.
+# The default value is: NO.
+
+REFERENCES_RELATION = NO
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set
+# to YES then the hyperlinks from functions in REFERENCES_RELATION and
+# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will
+# link to the documentation.
+# The default value is: YES.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the
+# source code will show a tooltip with additional information such as prototype,
+# brief description and links to the definition and documentation. Since this
+# will make the HTML file larger and loading of large files a bit slower, you
+# can opt to disable this feature.
+# The default value is: YES.
+# This tag requires that the tag SOURCE_BROWSER is set to YES.
+
+SOURCE_TOOLTIPS = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code will
+# point to the HTML generated by the htags(1) tool instead of doxygen built-in
+# source browser. The htags tool is part of GNU's global source tagging system
+# (see https://www.gnu.org/software/global/global.html). You will need version
+# 4.8.6 or higher.
+#
+# To use it do the following:
+# - Install the latest version of global
+# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file
+# - Make sure the INPUT points to the root of the source tree
+# - Run doxygen as normal
+#
+# Doxygen will invoke htags (and that will in turn invoke gtags), so these
+# tools must be available from the command line (i.e. in the search path).
+#
+# The result: instead of the source browser generated by doxygen, the links to
+# source code will now point to the output of htags.
+# The default value is: NO.
+# This tag requires that the tag SOURCE_BROWSER is set to YES.
+
+USE_HTAGS = NO
+
+# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a
+# verbatim copy of the header file for each class for which an include is
+# specified. Set to NO to disable this.
+# See also: Section \class.
+# The default value is: YES.
+
+VERBATIM_HEADERS = YES
+
+# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the
+# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the
+# cost of reduced performance. This can be particularly helpful with template
+# rich C++ code for which doxygen's built-in parser lacks the necessary type
+# information.
+# Note: The availability of this option depends on whether or not doxygen was
+# generated with the -Duse_libclang=ON option for CMake.
+# The default value is: NO.
+
+CLANG_ASSISTED_PARSING = NO
+
+# If clang assisted parsing is enabled you can provide the compiler with command
+# line options that you would normally use when invoking the compiler. Note that
+# the include paths will already be set by doxygen for the files and directories
+# specified with INPUT and INCLUDE_PATH.
+# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.
+
+CLANG_OPTIONS =
+
+# If clang assisted parsing is enabled you can provide the clang parser with the
+# path to the compilation database (see:
+# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) used when the files
+# were built. This is equivalent to specifying the "-p" option to a clang tool,
+# such as clang-check. These options will then be passed to the parser.
+# Note: The availability of this option depends on whether or not doxygen was
+# generated with the -Duse_libclang=ON option for CMake.
+
+CLANG_DATABASE_PATH =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all
+# compounds will be generated. Enable this if the project contains a lot of
+# classes, structs, unions or interfaces.
+# The default value is: YES.
+
+ALPHABETICAL_INDEX = YES
+
+# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in
+# which the alphabetical index list will be split.
+# Minimum value: 1, maximum value: 20, default value: 5.
+# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
+
+COLS_IN_ALPHA_INDEX = 5
+
+# In case all classes in a project start with a common prefix, all classes will
+# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
+# can be used to specify a prefix (or a list of prefixes) that should be ignored
+# while generating the index headers.
+# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output
+# The default value is: YES.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: html.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_OUTPUT = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each
+# generated HTML page (for example: .htm, .php, .asp).
+# The default value is: .html.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a user-defined HTML header file for
+# each generated HTML page. If the tag is left blank doxygen will generate a
+# standard header.
+#
+# To get valid HTML the header file that includes any scripts and style sheets
+# that doxygen needs, which is dependent on the configuration options used (e.g.
+# the setting GENERATE_TREEVIEW). It is highly recommended to start with a
+# default header using
+# doxygen -w html new_header.html new_footer.html new_stylesheet.css
+# YourConfigFile
+# and then modify the file new_header.html. See also section "Doxygen usage"
+# for information on how to generate the default header that doxygen normally
+# uses.
+# Note: The header is subject to change so you typically have to regenerate the
+# default header when upgrading to a newer version of doxygen. For a description
+# of the possible markers and block names see the documentation.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
+# generated HTML page. If the tag is left blank doxygen will generate a standard
+# footer. See HTML_HEADER for more information on how to generate a default
+# footer and what special commands can be used inside the footer. See also
+# section "Doxygen usage" for information on how to generate the default footer
+# that doxygen normally uses.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
+# sheet that is used by each HTML page. It can be used to fine-tune the look of
+# the HTML output. If left blank doxygen will generate a default style sheet.
+# See also section "Doxygen usage" for information on how to generate the style
+# sheet that doxygen normally uses.
+# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as
+# it is more robust and this tag (HTML_STYLESHEET) will in the future become
+# obsolete.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_STYLESHEET =
+
+# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# cascading style sheets that are included after the standard style sheets
+# created by doxygen. Using this option one can overrule certain style aspects.
+# This is preferred over using HTML_STYLESHEET since it does not replace the
+# standard style sheet and is therefore more robust against future updates.
+# Doxygen will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list). For an example see the documentation.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_EXTRA_STYLESHEET =
+
+# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the HTML output directory. Note
+# that these files will be copied to the base HTML output directory. Use the
+# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
+# files. In the HTML_STYLESHEET file, use the file name only. Also note that the
+# files will be copied as-is; there are no commands or markers available.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_EXTRA_FILES =
+
+# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen
+# will adjust the colors in the style sheet and background images according to
+# this color. Hue is specified as an angle on a colorwheel, see
+# https://en.wikipedia.org/wiki/Hue for more information. For instance the value
+# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300
+# purple, and 360 is red again.
+# Minimum value: 0, maximum value: 359, default value: 220.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_HUE = 195
+
+# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors
+# in the HTML output. For a value of 0 the output will use grayscales only. A
+# value of 255 will produce the most vivid colors.
+# Minimum value: 0, maximum value: 255, default value: 100.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_SAT = 100
+
+# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the
+# luminance component of the colors in the HTML output. Values below 100
+# gradually make the output lighter, whereas values above 100 make the output
+# darker. The value divided by 100 is the actual gamma applied, so 80 represents
+# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not
+# change the gamma.
+# Minimum value: 40, maximum value: 240, default value: 80.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_GAMMA = 86
+
+# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
+# page will contain the date and time when the page was generated. Setting this
+# to YES can help to show when doxygen was last run and thus if the
+# documentation is up to date.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_TIMESTAMP = NO
+
+# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML
+# documentation will contain a main index with vertical navigation menus that
+# are dynamically created via Javascript. If disabled, the navigation index will
+# consists of multiple levels of tabs that are statically embedded in every HTML
+# page. Disable this option to support browsers that do not have Javascript,
+# like the Qt help browser.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_DYNAMIC_MENUS = YES
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_DYNAMIC_SECTIONS = NO
+
+# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries
+# shown in the various tree structured indices initially; the user can expand
+# and collapse entries dynamically later on. Doxygen will expand the tree to
+# such a level that at most the specified number of entries are visible (unless
+# a fully collapsed tree already exceeds this amount). So setting the number of
+# entries 1 will produce a full collapsed tree by default. 0 is a special value
+# representing an infinite number of entries and will result in a full expanded
+# tree by default.
+# Minimum value: 0, maximum value: 9999, default value: 100.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_INDEX_NUM_ENTRIES = 100
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files will be
+# generated that can be used as input for Apple's Xcode 3 integrated development
+# environment (see: https://developer.apple.com/xcode/), introduced with OSX
+# 10.5 (Leopard). To create a documentation set, doxygen will generate a
+# Makefile in the HTML output directory. Running make will produce the docset in
+# that directory and running make install will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
+# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy
+# genXcode/_index.html for more information.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_DOCSET = NO
+
+# This tag determines the name of the docset feed. A documentation feed provides
+# an umbrella under which multiple documentation sets from a single provider
+# (such as a company or product suite) can be grouped.
+# The default value is: Doxygen generated docs.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_FEEDNAME = "Doxygen generated docs"
+
+# This tag specifies a string that should uniquely identify the documentation
+# set bundle. This should be a reverse domain-name style string, e.g.
+# com.mycompany.MyDocSet. Doxygen will append .docset to the name.
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_BUNDLE_ID = org.doxygen.Project
+
+# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify
+# the documentation publisher. This should be a reverse domain-name style
+# string, e.g. com.mycompany.MyDocSet.documentation.
+# The default value is: org.doxygen.Publisher.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+
+# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.
+# The default value is: Publisher.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_PUBLISHER_NAME = Publisher
+
+# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
+# additional HTML index files: index.hhp, index.hhc, and index.hhk. The
+# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
+# (see: https://www.microsoft.com/en-us/download/details.aspx?id=21138) on
+# Windows.
+#
+# The HTML Help Workshop contains a compiler that can convert all HTML output
+# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
+# files are now used as the Windows 98 help format, and will replace the old
+# Windows help format (.hlp) on all Windows platforms in the future. Compressed
+# HTML files also contain an index, a table of contents, and you can search for
+# words in the documentation. The HTML workshop also contains a viewer for
+# compressed HTML files.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_HTMLHELP = NO
+
+# The CHM_FILE tag can be used to specify the file name of the resulting .chm
+# file. You can add a path in front of the file if the result should not be
+# written to the html output directory.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+CHM_FILE =
+
+# The HHC_LOCATION tag can be used to specify the location (absolute path
+# including file name) of the HTML help compiler (hhc.exe). If non-empty,
+# doxygen will try to run the HTML help compiler on the generated index.hhp.
+# The file has to be specified with full path.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+HHC_LOCATION =
+
+# The GENERATE_CHI flag controls if a separate .chi index file is generated
+# (YES) or that it should be included in the master .chm file (NO).
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+GENERATE_CHI = NO
+
+# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc)
+# and project file content.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+CHM_INDEX_ENCODING =
+
+# The BINARY_TOC flag controls whether a binary table of contents is generated
+# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it
+# enables the Previous and Next buttons.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+BINARY_TOC = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members to
+# the table of contents of the HTML help documentation and to the tree view.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+TOC_EXPAND = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
+# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that
+# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help
+# (.qch) of the generated HTML documentation.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_QHP = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify
+# the file name of the resulting .qch file. The path specified is relative to
+# the HTML output folder.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QCH_FILE =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
+# Project output. For more information please see Qt Help Project / Namespace
+# (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace).
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_NAMESPACE = org.doxygen.Project
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
+# Help Project output. For more information please see Qt Help Project / Virtual
+# Folders (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-
+# folders).
+# The default value is: doc.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_VIRTUAL_FOLDER = doc
+
+# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
+# filter to add. For more information please see Qt Help Project / Custom
+# Filters (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
+# filters).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_CUST_FILTER_NAME =
+
+# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
+# custom filter to add. For more information please see Qt Help Project / Custom
+# Filters (see: http://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-
+# filters).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_CUST_FILTER_ATTRS =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
+# project's filter section matches. Qt Help Project / Filter Attributes (see:
+# http://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_SECT_FILTER_ATTRS =
+
+# The QHG_LOCATION tag can be used to specify the location of Qt's
+# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the
+# generated .qhp file.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHG_LOCATION =
+
+# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be
+# generated, together with the HTML files, they form an Eclipse help plugin. To
+# install this plugin and make it available under the help contents menu in
+# Eclipse, the contents of the directory containing the HTML and XML files needs
+# to be copied into the plugins directory of eclipse. The name of the directory
+# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.
+# After copying Eclipse needs to be restarted before the help appears.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_ECLIPSEHELP = NO
+
+# A unique identifier for the Eclipse help plugin. When installing the plugin
+# the directory name containing the HTML and XML files should also have this
+# name. Each documentation set should have its own identifier.
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.
+
+ECLIPSE_DOC_ID = org.doxygen.Project
+
+# If you want full control over the layout of the generated HTML pages it might
+# be necessary to disable the index and replace it with your own. The
+# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top
+# of each HTML page. A value of NO enables the index and the value YES disables
+# it. Since the tabs in the index contain the same information as the navigation
+# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+DISABLE_INDEX = NO
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information. If the tag
+# value is set to YES, a side panel will be generated containing a tree-like
+# index structure (just like the one that is generated for HTML Help). For this
+# to work a browser that supports JavaScript, DHTML, CSS and frames is required
+# (i.e. any modern browser). Windows users are probably better off using the
+# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can
+# further fine-tune the look of the index. As an example, the default style
+# sheet generated by doxygen has an example that shows how to put an image at
+# the root of the tree instead of the PROJECT_NAME. Since the tree basically has
+# the same information as the tab index, you could consider setting
+# DISABLE_INDEX to YES when enabling this option.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_TREEVIEW = YES
+
+# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
+# doxygen will group on one line in the generated HTML documentation.
+#
+# Note that a value of 0 will completely suppress the enum values from appearing
+# in the overview section.
+# Minimum value: 0, maximum value: 20, default value: 4.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+ENUM_VALUES_PER_LINE = 4
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used
+# to set the initial width (in pixels) of the frame in which the tree is shown.
+# Minimum value: 0, maximum value: 1500, default value: 250.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+TREEVIEW_WIDTH = 250
+
+# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to
+# external symbols imported via tag files in a separate window.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+EXT_LINKS_IN_WINDOW = NO
+
+# Use this tag to change the font size of LaTeX formulas included as images in
+# the HTML documentation. When you change the font size after a successful
+# doxygen run you need to manually remove any form_*.png images from the HTML
+# output directory to force them to be regenerated.
+# Minimum value: 8, maximum value: 50, default value: 10.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+FORMULA_FONTSIZE = 10
+
+# Use the FORMULA_TRANSPARENT tag to determine whether or not the images
+# generated for formulas are transparent PNGs. Transparent PNGs are not
+# supported properly for IE 6.0, but are supported on all modern browsers.
+#
+# Note that when changing this option you need to delete any form_*.png files in
+# the HTML output directory before the changes have effect.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+FORMULA_TRANSPARENT = YES
+
+# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
+# https://www.mathjax.org) which uses client side Javascript for the rendering
+# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX
+# installed or if you want to formulas look prettier in the HTML output. When
+# enabled you may also need to install MathJax separately and configure the path
+# to it using the MATHJAX_RELPATH option.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+USE_MATHJAX = NO
+
+# When MathJax is enabled you can set the default output format to be used for
+# the MathJax output. See the MathJax site (see:
+# http://docs.mathjax.org/en/latest/output.html) for more details.
+# Possible values are: HTML-CSS (which is slower, but has the best
+# compatibility), NativeMML (i.e. MathML) and SVG.
+# The default value is: HTML-CSS.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_FORMAT = HTML-CSS
+
+# When MathJax is enabled you need to specify the location relative to the HTML
+# output directory using the MATHJAX_RELPATH option. The destination directory
+# should contain the MathJax.js script. For instance, if the mathjax directory
+# is located at the same level as the HTML output directory, then
+# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax
+# Content Delivery Network so you can quickly see the result without installing
+# MathJax. However, it is strongly recommended to install a local copy of
+# MathJax from https://www.mathjax.org before deployment.
+# The default value is: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_RELPATH = https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/
+
+# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax
+# extension names that should be enabled during MathJax rendering. For example
+# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_EXTENSIONS =
+
+# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
+# of code that will be used on startup of the MathJax code. See the MathJax site
+# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an
+# example see the documentation.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_CODEFILE =
+
+# When the SEARCHENGINE tag is enabled doxygen will generate a search box for
+# the HTML output. The underlying search engine uses javascript and DHTML and
+# should work on any modern browser. Note that when using HTML help
+# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)
+# there is already a search function so this one should typically be disabled.
+# For large projects the javascript based search engine can be slow, then
+# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to
+# search using the keyboard; to jump to the search box use <access key> + S
+# (what the <access key> is depends on the OS and browser, but it is typically
+# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down
+# key> to jump into the search results window, the results can be navigated
+# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel
+# the search. The filter options can be selected when the cursor is inside the
+# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>
+# to select a filter and <Enter> or <escape> to activate or cancel the filter
+# option.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+SEARCHENGINE = YES
+
+# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
+# implemented using a web server instead of a web client using Javascript. There
+# are two flavors of web server based searching depending on the EXTERNAL_SEARCH
+# setting. When disabled, doxygen will generate a PHP script for searching and
+# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing
+# and searching needs to be provided by external tools. See the section
+# "External Indexing and Searching" for details.
+# The default value is: NO.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SERVER_BASED_SEARCH = NO
+
+# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP
+# script for searching. Instead the search results are written to an XML file
+# which needs to be processed by an external indexer. Doxygen will invoke an
+# external search engine pointed to by the SEARCHENGINE_URL option to obtain the
+# search results.
+#
+# Doxygen ships with an example indexer (doxyindexer) and search engine
+# (doxysearch.cgi) which are based on the open source search engine library
+# Xapian (see: https://xapian.org/).
+#
+# See the section "External Indexing and Searching" for details.
+# The default value is: NO.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTERNAL_SEARCH = NO
+
+# The SEARCHENGINE_URL should point to a search engine hosted by a web server
+# which will return the search results when EXTERNAL_SEARCH is enabled.
+#
+# Doxygen ships with an example indexer (doxyindexer) and search engine
+# (doxysearch.cgi) which are based on the open source search engine library
+# Xapian (see: https://xapian.org/). See the section "External Indexing and
+# Searching" for details.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SEARCHENGINE_URL =
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed
+# search data is written to a file for indexing by an external tool. With the
+# SEARCHDATA_FILE tag the name of this file can be specified.
+# The default file is: searchdata.xml.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SEARCHDATA_FILE = searchdata.xml
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the
+# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is
+# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple
+# projects and redirect the results back to the right project.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTERNAL_SEARCH_ID =
+
+# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen
+# projects other than the one defined by this configuration file, but that are
+# all added to the same external search index. Each project needs to have a
+# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of
+# to a relative location where the documentation can be found. The format is:
+# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTRA_SEARCH_MAPPINGS =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.
+# The default value is: YES.
+
+GENERATE_LATEX = NO
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: latex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_OUTPUT = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked.
+#
+# Note that when not enabling USE_PDFLATEX the default is latex when enabling
+# USE_PDFLATEX the default is pdflatex and when in the later case latex is
+# chosen this is overwritten by pdflatex. For specific output languages the
+# default can have been set differently, this depends on the implementation of
+# the output language.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_CMD_NAME =
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate
+# index for LaTeX.
+# Note: This tag is used in the Makefile / make.bat.
+# See also: LATEX_MAKEINDEX_CMD for the part in the generated output file
+# (.tex).
+# The default file is: makeindex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+MAKEINDEX_CMD_NAME = makeindex
+
+# The LATEX_MAKEINDEX_CMD tag can be used to specify the command name to
+# generate index for LaTeX.
+# Note: This tag is used in the generated output file (.tex).
+# See also: MAKEINDEX_CMD_NAME for the part in the Makefile / make.bat.
+# The default value is: \makeindex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_MAKEINDEX_CMD = \makeindex
+
+# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX
+# documents. This may be useful for small projects and may help to save some
+# trees in general.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+COMPACT_LATEX = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used by the
+# printer.
+# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x
+# 14 inches) and executive (7.25 x 10.5 inches).
+# The default value is: a4.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+PAPER_TYPE = a4
+
+# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names
+# that should be included in the LaTeX output. The package can be specified just
+# by its name or with the correct syntax as to be used with the LaTeX
+# \usepackage command. To get the times font for instance you can specify :
+# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}
+# To use the option intlimits with the amsmath package you can specify:
+# EXTRA_PACKAGES=[intlimits]{amsmath}
+# If left blank no extra packages will be included.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the
+# generated LaTeX document. The header should contain everything until the first
+# chapter. If it is left blank doxygen will generate a standard header. See
+# section "Doxygen usage" for information on how to let doxygen write the
+# default header to a separate file.
+#
+# Note: Only use a user-defined header if you know what you are doing! The
+# following commands have a special meaning inside the header: $title,
+# $datetime, $date, $doxygenversion, $projectname, $projectnumber,
+# $projectbrief, $projectlogo. Doxygen will replace $title with the empty
+# string, for the replacement values of the other commands the user is referred
+# to HTML_HEADER.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_HEADER =
+
+# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the
+# generated LaTeX document. The footer should contain everything after the last
+# chapter. If it is left blank doxygen will generate a standard footer. See
+# LATEX_HEADER for more information on how to generate a default footer and what
+# special commands can be used inside the footer.
+#
+# Note: Only use a user-defined footer if you know what you are doing!
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_FOOTER =
+
+# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# LaTeX style sheets that are included after the standard style sheets created
+# by doxygen. Using this option one can overrule certain style aspects. Doxygen
+# will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list).
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EXTRA_STYLESHEET =
+
+# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the LATEX_OUTPUT output
+# directory. Note that the files will be copied as-is; there are no commands or
+# markers available.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EXTRA_FILES =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is
+# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will
+# contain links (just like the HTML output) instead of page references. This
+# makes the output suitable for online browsing using a PDF viewer.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+PDF_HYPERLINKS = YES
+
+# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
+# the PDF file directly from the LaTeX files. Set this option to YES, to get a
+# higher quality PDF documentation.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+USE_PDFLATEX = YES
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode
+# command to the generated LaTeX files. This will instruct LaTeX to keep running
+# if errors occur, instead of asking the user for help. This option is also used
+# when generating formulas in HTML.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_BATCHMODE = NO
+
+# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the
+# index chapters (such as File Index, Compound Index, etc.) in the output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_HIDE_INDICES = NO
+
+# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source
+# code with syntax highlighting in the LaTeX output.
+#
+# Note that which sources are shown also depends on other settings such as
+# SOURCE_BROWSER.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_SOURCE_CODE = NO
+
+# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
+# bibliography, e.g. plainnat, or ieeetr. See
+# https://en.wikipedia.org/wiki/BibTeX and \cite for more info.
+# The default value is: plain.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_BIB_STYLE = plain
+
+# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated
+# page will contain the date and time when the page was generated. Setting this
+# to NO can help when comparing the output of multiple runs.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_TIMESTAMP = NO
+
+# The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute)
+# path from which the emoji images will be read. If a relative path is entered,
+# it will be relative to the LATEX_OUTPUT directory. If left blank the
+# LATEX_OUTPUT directory will be used.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EMOJI_DIRECTORY =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The
+# RTF output is optimized for Word 97 and may not look too pretty with other RTF
+# readers/editors.
+# The default value is: NO.
+
+GENERATE_RTF = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: rtf.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF
+# documents. This may be useful for small projects and may help to save some
+# trees in general.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will
+# contain hyperlink fields. The RTF file will contain links (just like the HTML
+# output) instead of page references. This makes the output suitable for online
+# browsing using Word or some other Word compatible readers that support those
+# fields.
+#
+# Note: WordPad (write) and others do not support links.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_HYPERLINKS = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# configuration file, i.e. a series of assignments. You only have to provide
+# replacements, missing definitions are set to their default value.
+#
+# See also section "Doxygen usage" for information on how to generate the
+# default style sheet that doxygen normally uses.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_STYLESHEET_FILE =
+
+# Set optional variables used in the generation of an RTF document. Syntax is
+# similar to doxygen's configuration file. A template extensions file can be
+# generated using doxygen -e rtf extensionFile.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_EXTENSIONS_FILE =
+
+# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code
+# with syntax highlighting in the RTF output.
+#
+# Note that which sources are shown also depends on other settings such as
+# SOURCE_BROWSER.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_SOURCE_CODE = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for
+# classes and files.
+# The default value is: NO.
+
+GENERATE_MAN = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it. A directory man3 will be created inside the directory specified by
+# MAN_OUTPUT.
+# The default directory is: man.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to the generated
+# man pages. In case the manual section does not start with a number, the number
+# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is
+# optional.
+# The default value is: .3.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_EXTENSION = .3
+
+# The MAN_SUBDIR tag determines the name of the directory created within
+# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by
+# MAN_EXTENSION with the initial . removed.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_SUBDIR =
+
+# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it
+# will generate one additional man file for each entity documented in the real
+# man page(s). These additional files only source the real man page, but without
+# them the man command would be unable to find the correct page.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_LINKS = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that
+# captures the structure of the code including all documentation.
+# The default value is: NO.
+
+GENERATE_XML = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: xml.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
+XML_OUTPUT = xml
+
+# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program
+# listings (including syntax highlighting and cross-referencing information) to
+# the XML output. Note that enabling this will significantly increase the size
+# of the XML output.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
+XML_PROGRAMLISTING = YES
+
+# If the XML_NS_MEMB_FILE_SCOPE tag is set to YES, doxygen will include
+# namespace members in file scope as well, matching the HTML output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
+XML_NS_MEMB_FILE_SCOPE = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the DOCBOOK output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files
+# that can be used to generate PDF.
+# The default value is: NO.
+
+GENERATE_DOCBOOK = NO
+
+# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in
+# front of it.
+# The default directory is: docbook.
+# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
+
+DOCBOOK_OUTPUT = docbook
+
+# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the
+# program listings (including syntax highlighting and cross-referencing
+# information) to the DOCBOOK output. Note that enabling this will significantly
+# increase the size of the DOCBOOK output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
+
+DOCBOOK_PROGRAMLISTING = NO
+
+#---------------------------------------------------------------------------
+# Configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an
+# AutoGen Definitions (see http://autogen.sourceforge.net/) file that captures
+# the structure of the code including all documentation. Note that this feature
+# is still experimental and incomplete at the moment.
+# The default value is: NO.
+
+GENERATE_AUTOGEN_DEF = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module
+# file that captures the structure of the code including all documentation.
+#
+# Note that this feature is still experimental and incomplete at the moment.
+# The default value is: NO.
+
+GENERATE_PERLMOD = NO
+
+# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary
+# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI
+# output from the Perl module output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_LATEX = NO
+
+# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely
+# formatted so it can be parsed by a human reader. This is useful if you want to
+# understand what is going on. On the other hand, if this tag is set to NO, the
+# size of the Perl module output will be much smaller and Perl will parse it
+# just the same.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_PRETTY = YES
+
+# The names of the make variables in the generated doxyrules.make file are
+# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful
+# so different doxyrules.make files included by the same Makefile don't
+# overwrite each other's variables.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all
+# C-preprocessor directives found in the sources and include files.
+# The default value is: YES.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
+# in the source code. If set to NO, only conditional compilation will be
+# performed. Macro expansion can be done in a controlled way by setting
+# EXPAND_ONLY_PREDEF to YES.
+# The default value is: NO.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+MACRO_EXPANSION = NO
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
+# the macro expansion is limited to the macros specified with the PREDEFINED and
+# EXPAND_AS_DEFINED tags.
+# The default value is: NO.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+EXPAND_ONLY_PREDEF = NO
+
+# If the SEARCH_INCLUDES tag is set to YES, the include files in the
+# INCLUDE_PATH will be searched if a #include is found.
+# The default value is: YES.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by the
+# preprocessor.
+# This tag requires that the tag SEARCH_INCLUDES is set to YES.
+
+INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will be
+# used.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+INCLUDE_FILE_PATTERNS =
+
+# The PREDEFINED tag can be used to specify one or more macro names that are
+# defined before the preprocessor is started (similar to the -D option of e.g.
+# gcc). The argument of the tag is a list of macros of the form: name or
+# name=definition (no spaces). If the definition and the "=" are omitted, "=1"
+# is assumed. To prevent a macro definition from being undefined via #undef or
+# recursively expanded use the := operator instead of the = operator.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+PREDEFINED =
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
+# tag can be used to specify a list of macro names that should be expanded. The
+# macro definition that is found in the sources will be used. Use the PREDEFINED
+# tag if you want to use a different macro definition that overrules the
+# definition found in the source code.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+EXPAND_AS_DEFINED =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
+# remove all references to function-like macros that are alone on a line, have
+# an all uppercase name, and do not end with a semicolon. Such function macros
+# are typically used for boiler-plate code, and will confuse the parser if not
+# removed.
+# The default value is: YES.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+SKIP_FUNCTION_MACROS = YES
+
+#---------------------------------------------------------------------------
+# Configuration options related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES tag can be used to specify one or more tag files. For each tag
+# file the location of the external documentation should be added. The format of
+# a tag file without this location is as follows:
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where loc1 and loc2 can be relative or absolute paths or URLs. See the
+# section "Linking to external documentation" for more information about the use
+# of tag files.
+# Note: Each tag file must have a unique name (where the name does NOT include
+# the path). If a tag file is not located in the directory in which doxygen is
+# run, you must also specify the path to the tagfile here.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create a
+# tag file that is based on the input files it reads. See section "Linking to
+# external documentation" for more information about the usage of tag files.
+
+GENERATE_TAGFILE =
+
+# If the ALLEXTERNALS tag is set to YES, all external class will be listed in
+# the class index. If set to NO, only the inherited external classes will be
+# listed.
+# The default value is: NO.
+
+ALLEXTERNALS = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will be
+# listed.
+# The default value is: YES.
+
+EXTERNAL_GROUPS = YES
+
+# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in
+# the related pages index. If set to NO, only the current project's pages will
+# be listed.
+# The default value is: YES.
+
+EXTERNAL_PAGES = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of 'which perl').
+# The default file (with absolute path) is: /usr/bin/perl.
+
+PERL_PATH = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram
+# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to
+# NO turns the diagrams off. Note that this option also works with HAVE_DOT
+# disabled, but it is recommended to install and use dot, since it yields more
+# powerful graphs.
+# The default value is: YES.
+
+CLASS_DIAGRAMS = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see:
+# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH =
+
+# You can include diagrams made with dia in doxygen documentation. Doxygen will
+# then run dia to produce the diagram and insert it in the documentation. The
+# DIA_PATH tag allows you to specify the directory where the dia binary resides.
+# If left empty dia is assumed to be found in the default search path.
+
+DIA_PATH =
+
+# If set to YES the inheritance and collaboration graphs will hide inheritance
+# and usage relations if the target is undocumented or is not a class.
+# The default value is: YES.
+
+HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz (see:
+# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent
+# Bell Labs. The other options in this section have no effect if this option is
+# set to NO
+# The default value is: NO.
+
+HAVE_DOT = NO
+
+# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
+# to run in parallel. When set to 0 doxygen will base this on the number of
+# processors available in the system. You can set it explicitly to a value
+# larger than 0 to get control over the balance between CPU load and processing
+# speed.
+# Minimum value: 0, maximum value: 32, default value: 0.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_NUM_THREADS = 0
+
+# When you want a differently looking font in the dot files that doxygen
+# generates you can specify the font name using DOT_FONTNAME. You need to make
+# sure dot is able to find the font, which can be done by putting it in a
+# standard location or by setting the DOTFONTPATH environment variable or by
+# setting DOT_FONTPATH to the directory containing the font.
+# The default value is: Helvetica.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTNAME = Helvetica
+
+# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of
+# dot graphs.
+# Minimum value: 4, maximum value: 24, default value: 10.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTSIZE = 10
+
+# By default doxygen will tell dot to use the default font as specified with
+# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set
+# the path where dot can find it using this tag.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTPATH =
+
+# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for
+# each documented class showing the direct and indirect inheritance relations.
+# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
+# graph for each documented class showing the direct and indirect implementation
+# dependencies (inheritance, containment, and class references variables) of the
+# class with other documented classes.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+COLLABORATION_GRAPH = YES
+
+# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for
+# groups, showing the direct groups dependencies.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GROUP_GRAPHS = YES
+
+# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+UML_LOOK = NO
+
+# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
+# class node. If there are many fields or methods and many nodes the graph may
+# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the
+# number of items for each type to make the size more manageable. Set this to 0
+# for no limit. Note that the threshold may be exceeded by 50% before the limit
+# is enforced. So when you set the threshold to 10, up to 15 fields may appear,
+# but if the number exceeds 15, the total amount of fields shown is limited to
+# 10.
+# Minimum value: 0, maximum value: 100, default value: 10.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+UML_LIMIT_NUM_FIELDS = 10
+
+# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
+# collaboration graphs will show the relations between templates and their
+# instances.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+TEMPLATE_RELATIONS = NO
+
+# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
+# YES then doxygen will generate a graph for each documented file showing the
+# direct and indirect include dependencies of the file with other documented
+# files.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INCLUDE_GRAPH = YES
+
+# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are
+# set to YES then doxygen will generate a graph for each documented file showing
+# the direct and indirect include dependencies of the file with other documented
+# files.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INCLUDED_BY_GRAPH = YES
+
+# If the CALL_GRAPH tag is set to YES then doxygen will generate a call
+# dependency graph for every global function or class method.
+#
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable call graphs for selected
+# functions only using the \callgraph command. Disabling a call graph can be
+# accomplished by means of the command \hidecallgraph.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CALL_GRAPH = NO
+
+# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
+# dependency graph for every global function or class method.
+#
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable caller graphs for selected
+# functions only using the \callergraph command. Disabling a caller graph can be
+# accomplished by means of the command \hidecallergraph.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CALLER_GRAPH = NO
+
+# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
+# hierarchy of all classes instead of a textual one.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GRAPHICAL_HIERARCHY = YES
+
+# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the
+# dependencies a directory has on other directories in a graphical way. The
+# dependency relations are determined by the #include relations between the
+# files in the directories.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DIRECTORY_GRAPH = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. For an explanation of the image formats see the section
+# output formats in the documentation of the dot tool (Graphviz (see:
+# http://www.graphviz.org/)).
+# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order
+# to make the SVG files visible in IE 9+ (other browsers do not have this
+# requirement).
+# Possible values are: png, jpg, gif, svg, png:gd, png:gd:gd, png:cairo,
+# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and
+# png:gdiplus:gdiplus.
+# The default value is: png.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_IMAGE_FORMAT = png
+
+# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
+# enable generation of interactive SVG images that allow zooming and panning.
+#
+# Note that this requires a modern browser other than Internet Explorer. Tested
+# and working are Firefox, Chrome, Safari, and Opera.
+# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make
+# the SVG files visible. Older versions of IE do not have SVG support.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INTERACTIVE_SVG = NO
+
+# The DOT_PATH tag can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_PATH =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the \dotfile
+# command).
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOTFILE_DIRS =
+
+# The MSCFILE_DIRS tag can be used to specify one or more directories that
+# contain msc files that are included in the documentation (see the \mscfile
+# command).
+
+MSCFILE_DIRS =
+
+# The DIAFILE_DIRS tag can be used to specify one or more directories that
+# contain dia files that are included in the documentation (see the \diafile
+# command).
+
+DIAFILE_DIRS =
+
+# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the
+# path where java can find the plantuml.jar file. If left blank, it is assumed
+# PlantUML is not used or called during a preprocessing step. Doxygen will
+# generate a warning when it encounters a \startuml command in this case and
+# will not generate output for the diagram.
+
+PLANTUML_JAR_PATH =
+
+# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a
+# configuration file for plantuml.
+
+PLANTUML_CFG_FILE =
+
+# When using plantuml, the specified paths are searched for files specified by
+# the !include statement in a plantuml block.
+
+PLANTUML_INCLUDE_PATH =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes
+# that will be shown in the graph. If the number of nodes in a graph becomes
+# larger than this value, doxygen will truncate the graph, which is visualized
+# by representing a node as a red box. Note that doxygen if the number of direct
+# children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that
+# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+# Minimum value: 0, maximum value: 10000, default value: 50.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_GRAPH_MAX_NODES = 50
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
+# generated by dot. A depth value of 3 means that only nodes reachable from the
+# root by following a path via at most 3 edges will be shown. Nodes that lay
+# further from the root node will be omitted. Note that setting this option to 1
+# or 2 may greatly reduce the computation time needed for large code bases. Also
+# note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+# Minimum value: 0, maximum value: 1000, default value: 0.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+MAX_DOT_GRAPH_DEPTH = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not seem
+# to support this out of the box.
+#
+# Warning: Depending on the platform used, enabling this option may lead to
+# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
+# read).
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_TRANSPARENT = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10) support
+# this, this feature is disabled by default.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_MULTI_TARGETS = NO
+
+# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page
+# explaining the meaning of the various boxes and arrows in the dot generated
+# graphs.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot
+# files that are used to generate the various graphs.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_CLEANUP = YES
diff --git a/DvdLib/Ifo/AudioAttributes.cs b/DvdLib/Ifo/AudioAttributes.cs
deleted file mode 100644
index b76f9fc05..000000000
--- a/DvdLib/Ifo/AudioAttributes.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-namespace DvdLib.Ifo
-{
- public enum AudioCodec
- {
- AC3 = 0,
- MPEG1 = 2,
- MPEG2ext = 3,
- LPCM = 4,
- DTS = 6,
- }
-
- public enum ApplicationMode
- {
- Unspecified = 0,
- Karaoke = 1,
- Surround = 2,
- }
-
- public class AudioAttributes
- {
- public readonly AudioCodec Codec;
- public readonly bool MultichannelExtensionPresent;
- public readonly ApplicationMode Mode;
- public readonly byte QuantDRC;
- public readonly byte SampleRate;
- public readonly byte Channels;
- public readonly ushort LanguageCode;
- public readonly byte LanguageExtension;
- public readonly byte CodeExtension;
- }
-
- public class MultiChannelExtension
- {
-
- }
-}
diff --git a/DvdLib/Ifo/Dvd.cs b/DvdLib/Ifo/Dvd.cs
index f784be83e..90125fa3e 100644
--- a/DvdLib/Ifo/Dvd.cs
+++ b/DvdLib/Ifo/Dvd.cs
@@ -26,17 +26,17 @@ namespace DvdLib.Ifo
if (vmgPath == null)
{
- var allIfos = allFiles.Where(i => string.Equals(i.Extension, ".ifo", StringComparison.OrdinalIgnoreCase));
-
- foreach (var ifo in allIfos)
+ foreach (var ifo in allFiles)
{
- var num = ifo.Name.Split('_').ElementAtOrDefault(1);
- var numbersRead = new List<ushort>();
+ if (!string.Equals(ifo.Extension, ".ifo", StringComparison.OrdinalIgnoreCase))
+ {
+ continue;
+ }
- if (!string.IsNullOrEmpty(num) && ushort.TryParse(num, out var ifoNumber) && !numbersRead.Contains(ifoNumber))
+ var nums = ifo.Name.Split(new [] { '_' }, StringSplitOptions.RemoveEmptyEntries);
+ if (nums.Length >= 2 && ushort.TryParse(nums[1], out var ifoNumber))
{
ReadVTS(ifoNumber, ifo.FullName);
- numbersRead.Add(ifoNumber);
}
}
}
@@ -76,7 +76,7 @@ namespace DvdLib.Ifo
}
}
- private void ReadVTS(ushort vtsNum, List<FileSystemMetadata> allFiles)
+ private void ReadVTS(ushort vtsNum, IEnumerable<FileSystemMetadata> allFiles)
{
var filename = string.Format("VTS_{0:00}_0.IFO", vtsNum);
diff --git a/DvdLib/Ifo/PgcCommandTable.cs b/DvdLib/Ifo/PgcCommandTable.cs
deleted file mode 100644
index d329fcba2..000000000
--- a/DvdLib/Ifo/PgcCommandTable.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System.Collections.Generic;
-
-namespace DvdLib.Ifo
-{
- public class ProgramChainCommandTable
- {
- public readonly ushort LastByteAddress;
- public readonly List<VirtualMachineCommand> PreCommands;
- public readonly List<VirtualMachineCommand> PostCommands;
- public readonly List<VirtualMachineCommand> CellCommands;
- }
-
- public class VirtualMachineCommand
- {
- public readonly byte[] Command;
- }
-}
diff --git a/DvdLib/Ifo/ProgramChain.cs b/DvdLib/Ifo/ProgramChain.cs
index 80889738f..7b003005b 100644
--- a/DvdLib/Ifo/ProgramChain.cs
+++ b/DvdLib/Ifo/ProgramChain.cs
@@ -25,13 +25,10 @@ namespace DvdLib.Ifo
public byte[] SubpictureStreamControl { get; private set; } // 32*4 entries
private ushort _nextProgramNumber;
- public readonly ProgramChain Next;
private ushort _prevProgramNumber;
- public readonly ProgramChain Previous;
private ushort _goupProgramNumber;
- public readonly ProgramChain Goup; // ?? maybe Group
public ProgramPlaybackMode PlaybackMode { get; private set; }
public uint ProgramCount { get; private set; }
@@ -40,7 +37,6 @@ namespace DvdLib.Ifo
public byte[] Palette { get; private set; } // 16*4 entries
private ushort _commandTableOffset;
- public readonly ProgramChainCommandTable CommandTable;
private ushort _programMapOffset;
private ushort _cellPlaybackOffset;
diff --git a/DvdLib/Ifo/VideoAttributes.cs b/DvdLib/Ifo/VideoAttributes.cs
deleted file mode 100644
index 8b3996715..000000000
--- a/DvdLib/Ifo/VideoAttributes.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-namespace DvdLib.Ifo
-{
- public enum VideoCodec
- {
- MPEG1 = 0,
- MPEG2 = 1,
- }
-
- public enum VideoFormat
- {
- NTSC = 0,
- PAL = 1,
- }
-
- public enum AspectRatio
- {
- ar4to3 = 0,
- ar16to9 = 3
- }
-
- public enum FilmMode
- {
- None = -1,
- Camera = 0,
- Film = 1,
- }
-
- public class VideoAttributes
- {
- public readonly VideoCodec Codec;
- public readonly VideoFormat Format;
- public readonly AspectRatio Aspect;
- public readonly bool AutomaticPanScan;
- public readonly bool AutomaticLetterBox;
- public readonly bool Line21CCField1;
- public readonly bool Line21CCField2;
- public readonly int Width;
- public readonly int Height;
- public readonly bool Letterboxed;
- public readonly FilmMode FilmMode;
-
- public VideoAttributes()
- {
- }
- }
-}
diff --git a/DvdLib/Properties/AssemblyInfo.cs b/DvdLib/Properties/AssemblyInfo.cs
index 5fc055d1f..6acd571d6 100644
--- a/DvdLib/Properties/AssemblyInfo.cs
+++ b/DvdLib/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/Emby.Dlna/Api/DlnaServerService.cs b/Emby.Dlna/Api/DlnaServerService.cs
index 68bf80163..8bf3797f8 100644
--- a/Emby.Dlna/Api/DlnaServerService.cs
+++ b/Emby.Dlna/Api/DlnaServerService.cs
@@ -136,7 +136,7 @@ namespace Emby.Dlna.Api
{
var url = Request.AbsoluteUri;
var serverAddress = url.Substring(0, url.IndexOf("/dlna/", StringComparison.OrdinalIgnoreCase));
- var xml = _dlnaManager.GetServerDescriptionXml(Request.Headers.ToDictionary(), request.UuId, serverAddress);
+ var xml = _dlnaManager.GetServerDescriptionXml(Request.Headers, request.UuId, serverAddress);
var cacheLength = TimeSpan.FromDays(1);
var cacheKey = Request.RawUrl.GetMD5();
@@ -147,21 +147,21 @@ namespace Emby.Dlna.Api
public object Get(GetContentDirectory request)
{
- var xml = ContentDirectory.GetServiceXml(Request.Headers.ToDictionary());
+ var xml = ContentDirectory.GetServiceXml();
return _resultFactory.GetResult(Request, xml, XMLContentType);
}
public object Get(GetMediaReceiverRegistrar request)
{
- var xml = MediaReceiverRegistrar.GetServiceXml(Request.Headers.ToDictionary());
+ var xml = MediaReceiverRegistrar.GetServiceXml();
return _resultFactory.GetResult(Request, xml, XMLContentType);
}
public object Get(GetConnnectionManager request)
{
- var xml = ConnectionManager.GetServiceXml(Request.Headers.ToDictionary());
+ var xml = ConnectionManager.GetServiceXml();
return _resultFactory.GetResult(Request, xml, XMLContentType);
}
@@ -193,7 +193,7 @@ namespace Emby.Dlna.Api
return service.ProcessControlRequest(new ControlRequest
{
- Headers = Request.Headers.ToDictionary(),
+ Headers = Request.Headers,
InputXml = requestStream,
TargetServerUuId = id,
RequestedUrl = Request.AbsoluteUri
diff --git a/Emby.Dlna/Configuration/DlnaOptions.cs b/Emby.Dlna/Configuration/DlnaOptions.cs
index 0ebb490a1..c7cb364a8 100644
--- a/Emby.Dlna/Configuration/DlnaOptions.cs
+++ b/Emby.Dlna/Configuration/DlnaOptions.cs
@@ -7,6 +7,7 @@ namespace Emby.Dlna.Configuration
public bool EnableServer { get; set; }
public bool EnableDebugLog { get; set; }
public bool BlastAliveMessages { get; set; }
+ public bool SendOnlyMatchedHost { get; set; }
public int ClientDiscoveryIntervalSeconds { get; set; }
public int BlastAliveMessageIntervalSeconds { get; set; }
public string DefaultUserId { get; set; }
@@ -16,6 +17,7 @@ namespace Emby.Dlna.Configuration
EnablePlayTo = true;
EnableServer = true;
BlastAliveMessages = true;
+ SendOnlyMatchedHost = true;
ClientDiscoveryIntervalSeconds = 60;
BlastAliveMessageIntervalSeconds = 1800;
}
diff --git a/Emby.Dlna/ConnectionManager/ConnectionManager.cs b/Emby.Dlna/ConnectionManager/ConnectionManager.cs
index cc427f2a1..83011fbab 100644
--- a/Emby.Dlna/ConnectionManager/ConnectionManager.cs
+++ b/Emby.Dlna/ConnectionManager/ConnectionManager.cs
@@ -1,9 +1,7 @@
-using System.Collections.Generic;
using Emby.Dlna.Service;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dlna;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace Emby.Dlna.ConnectionManager
@@ -13,18 +11,16 @@ namespace Emby.Dlna.ConnectionManager
private readonly IDlnaManager _dlna;
private readonly ILogger _logger;
private readonly IServerConfigurationManager _config;
- protected readonly IXmlReaderSettingsFactory XmlReaderSettingsFactory;
- public ConnectionManager(IDlnaManager dlna, IServerConfigurationManager config, ILogger logger, IHttpClient httpClient, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public ConnectionManager(IDlnaManager dlna, IServerConfigurationManager config, ILogger logger, IHttpClient httpClient)
: base(logger, httpClient)
{
_dlna = dlna;
_config = config;
_logger = logger;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
- public string GetServiceXml(IDictionary<string, string> headers)
+ public string GetServiceXml()
{
return new ConnectionManagerXmlBuilder().GetXml();
}
@@ -34,7 +30,7 @@ namespace Emby.Dlna.ConnectionManager
var profile = _dlna.GetProfile(request.Headers) ??
_dlna.GetDefaultProfile();
- return new ControlHandler(_config, _logger, XmlReaderSettingsFactory, profile).ProcessControlRequest(request);
+ return new ControlHandler(_config, _logger, profile).ProcessControlRequest(request);
}
}
}
diff --git a/Emby.Dlna/ConnectionManager/ControlHandler.cs b/Emby.Dlna/ConnectionManager/ControlHandler.cs
index 16211c61f..2e1104748 100644
--- a/Emby.Dlna/ConnectionManager/ControlHandler.cs
+++ b/Emby.Dlna/ConnectionManager/ControlHandler.cs
@@ -4,7 +4,6 @@ using Emby.Dlna.Service;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Model.Dlna;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace Emby.Dlna.ConnectionManager
@@ -32,7 +31,8 @@ namespace Emby.Dlna.ConnectionManager
};
}
- public ControlHandler(IServerConfigurationManager config, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory, DeviceProfile profile) : base(config, logger, xmlReaderSettingsFactory)
+ public ControlHandler(IServerConfigurationManager config, ILogger logger, DeviceProfile profile)
+ : base(config, logger)
{
_profile = profile;
}
diff --git a/Emby.Dlna/ContentDirectory/ContentDirectory.cs b/Emby.Dlna/ContentDirectory/ContentDirectory.cs
index b0fec90e6..5175898ab 100644
--- a/Emby.Dlna/ContentDirectory/ContentDirectory.cs
+++ b/Emby.Dlna/ContentDirectory/ContentDirectory.cs
@@ -11,7 +11,6 @@ using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.TV;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Globalization;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace Emby.Dlna.ContentDirectory
@@ -28,7 +27,6 @@ namespace Emby.Dlna.ContentDirectory
private readonly IMediaSourceManager _mediaSourceManager;
private readonly IUserViewManager _userViewManager;
private readonly IMediaEncoder _mediaEncoder;
- protected readonly IXmlReaderSettingsFactory XmlReaderSettingsFactory;
private readonly ITVSeriesManager _tvSeriesManager;
public ContentDirectory(IDlnaManager dlna,
@@ -38,7 +36,12 @@ namespace Emby.Dlna.ContentDirectory
IServerConfigurationManager config,
IUserManager userManager,
ILogger logger,
- IHttpClient httpClient, ILocalizationManager localization, IMediaSourceManager mediaSourceManager, IUserViewManager userViewManager, IMediaEncoder mediaEncoder, IXmlReaderSettingsFactory xmlReaderSettingsFactory, ITVSeriesManager tvSeriesManager)
+ IHttpClient httpClient,
+ ILocalizationManager localization,
+ IMediaSourceManager mediaSourceManager,
+ IUserViewManager userViewManager,
+ IMediaEncoder mediaEncoder,
+ ITVSeriesManager tvSeriesManager)
: base(logger, httpClient)
{
_dlna = dlna;
@@ -51,7 +54,6 @@ namespace Emby.Dlna.ContentDirectory
_mediaSourceManager = mediaSourceManager;
_userViewManager = userViewManager;
_mediaEncoder = mediaEncoder;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
_tvSeriesManager = tvSeriesManager;
}
@@ -65,7 +67,7 @@ namespace Emby.Dlna.ContentDirectory
}
}
- public string GetServiceXml(IDictionary<string, string> headers)
+ public string GetServiceXml()
{
return new ContentDirectoryXmlBuilder().GetXml();
}
@@ -94,7 +96,6 @@ namespace Emby.Dlna.ContentDirectory
_mediaSourceManager,
_userViewManager,
_mediaEncoder,
- XmlReaderSettingsFactory,
_tvSeriesManager)
.ProcessControlRequest(request);
}
diff --git a/Emby.Dlna/ContentDirectory/ControlHandler.cs b/Emby.Dlna/ContentDirectory/ControlHandler.cs
index 1150afdba..4f8c89e48 100644
--- a/Emby.Dlna/ContentDirectory/ControlHandler.cs
+++ b/Emby.Dlna/ContentDirectory/ControlHandler.cs
@@ -25,7 +25,6 @@ using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Querying;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace Emby.Dlna.ContentDirectory
@@ -51,8 +50,22 @@ namespace Emby.Dlna.ContentDirectory
private readonly DeviceProfile _profile;
- public ControlHandler(ILogger logger, ILibraryManager libraryManager, DeviceProfile profile, string serverAddress, string accessToken, IImageProcessor imageProcessor, IUserDataManager userDataManager, User user, int systemUpdateId, IServerConfigurationManager config, ILocalizationManager localization, IMediaSourceManager mediaSourceManager, IUserViewManager userViewManager, IMediaEncoder mediaEncoder, IXmlReaderSettingsFactory xmlReaderSettingsFactory, ITVSeriesManager tvSeriesManager)
- : base(config, logger, xmlReaderSettingsFactory)
+ public ControlHandler(
+ ILogger logger,
+ ILibraryManager libraryManager,
+ DeviceProfile profile,
+ string serverAddress,
+ string accessToken,
+ IImageProcessor imageProcessor,
+ IUserDataManager userDataManager,
+ User user, int systemUpdateId,
+ IServerConfigurationManager config,
+ ILocalizationManager localization,
+ IMediaSourceManager mediaSourceManager,
+ IUserViewManager userViewManager,
+ IMediaEncoder mediaEncoder,
+ ITVSeriesManager tvSeriesManager)
+ : base(config, logger)
{
_libraryManager = libraryManager;
_userDataManager = userDataManager;
@@ -260,7 +273,7 @@ namespace Emby.Dlna.ContentDirectory
if (item.IsDisplayedAsFolder || serverItem.StubType.HasValue)
{
- var childrenResult = (GetUserItems(item, serverItem.StubType, user, sortCriteria, start, requestedCount));
+ var childrenResult = GetUserItems(item, serverItem.StubType, user, sortCriteria, start, requestedCount);
_didlBuilder.WriteFolderElement(writer, item, serverItem.StubType, null, childrenResult.TotalRecordCount, filter, id);
}
@@ -273,7 +286,7 @@ namespace Emby.Dlna.ContentDirectory
}
else
{
- var childrenResult = (GetUserItems(item, serverItem.StubType, user, sortCriteria, start, requestedCount));
+ var childrenResult = GetUserItems(item, serverItem.StubType, user, sortCriteria, start, requestedCount);
totalCount = childrenResult.TotalRecordCount;
provided = childrenResult.Items.Length;
diff --git a/Emby.Dlna/ControlRequest.cs b/Emby.Dlna/ControlRequest.cs
index afd9a0b87..8c227159c 100644
--- a/Emby.Dlna/ControlRequest.cs
+++ b/Emby.Dlna/ControlRequest.cs
@@ -1,11 +1,11 @@
-using System.Collections.Generic;
using System.IO;
+using Microsoft.AspNetCore.Http;
namespace Emby.Dlna
{
public class ControlRequest
{
- public IDictionary<string, string> Headers { get; set; }
+ public IHeaderDictionary Headers { get; set; }
public Stream InputXml { get; set; }
@@ -15,7 +15,7 @@ namespace Emby.Dlna
public ControlRequest()
{
- Headers = new Dictionary<string, string>();
+ Headers = new HeaderDictionary();
}
}
}
diff --git a/Emby.Dlna/Didl/DidlBuilder.cs b/Emby.Dlna/Didl/DidlBuilder.cs
index 605f4f37b..1268f3d5c 100644
--- a/Emby.Dlna/Didl/DidlBuilder.cs
+++ b/Emby.Dlna/Didl/DidlBuilder.cs
@@ -818,10 +818,9 @@ namespace Emby.Dlna.Didl
{
AddCommonFields(item, itemStubType, context, writer, filter);
- var hasArtists = item as IHasArtist;
var hasAlbumArtists = item as IHasAlbumArtist;
- if (hasArtists != null)
+ if (item is IHasArtist hasArtists)
{
foreach (var artist in hasArtists.Artists)
{
diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.cs
index f53d27451..2b76d2702 100644
--- a/Emby.Dlna/DlnaManager.cs
+++ b/Emby.Dlna/DlnaManager.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
@@ -15,9 +16,10 @@ using MediaBrowser.Controller.Drawing;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Reflection;
using MediaBrowser.Model.Serialization;
+using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Primitives;
namespace Emby.Dlna
{
@@ -29,7 +31,7 @@ namespace Emby.Dlna
private readonly ILogger _logger;
private readonly IJsonSerializer _jsonSerializer;
private readonly IServerApplicationHost _appHost;
- private readonly IAssemblyInfo _assemblyInfo;
+ private static readonly Assembly _assembly = typeof(DlnaManager).Assembly;
private readonly Dictionary<string, Tuple<InternalProfileInfo, DeviceProfile>> _profiles = new Dictionary<string, Tuple<InternalProfileInfo, DeviceProfile>>(StringComparer.Ordinal);
@@ -39,8 +41,7 @@ namespace Emby.Dlna
IApplicationPaths appPaths,
ILoggerFactory loggerFactory,
IJsonSerializer jsonSerializer,
- IServerApplicationHost appHost,
- IAssemblyInfo assemblyInfo)
+ IServerApplicationHost appHost)
{
_xmlSerializer = xmlSerializer;
_fileSystem = fileSystem;
@@ -48,7 +49,6 @@ namespace Emby.Dlna
_logger = loggerFactory.CreateLogger("Dlna");
_jsonSerializer = jsonSerializer;
_appHost = appHost;
- _assemblyInfo = assemblyInfo;
}
public async Task InitProfilesAsync()
@@ -205,16 +205,13 @@ namespace Emby.Dlna
}
}
- public DeviceProfile GetProfile(IDictionary<string, string> headers)
+ public DeviceProfile GetProfile(IHeaderDictionary headers)
{
if (headers == null)
{
throw new ArgumentNullException(nameof(headers));
}
- // Convert to case insensitive
- headers = new Dictionary<string, string>(headers, StringComparer.OrdinalIgnoreCase);
-
var profile = GetProfiles().FirstOrDefault(i => i.Identification != null && IsMatch(headers, i.Identification));
if (profile != null)
@@ -230,12 +227,12 @@ namespace Emby.Dlna
return profile;
}
- private bool IsMatch(IDictionary<string, string> headers, DeviceIdentification profileInfo)
+ private bool IsMatch(IHeaderDictionary headers, DeviceIdentification profileInfo)
{
return profileInfo.Headers.Any(i => IsMatch(headers, i));
}
- private bool IsMatch(IDictionary<string, string> headers, HttpHeaderInfo header)
+ private bool IsMatch(IHeaderDictionary headers, HttpHeaderInfo header)
{
// Handle invalid user setup
if (string.IsNullOrEmpty(header.Name))
@@ -243,14 +240,14 @@ namespace Emby.Dlna
return false;
}
- if (headers.TryGetValue(header.Name, out string value))
+ if (headers.TryGetValue(header.Name, out StringValues value))
{
switch (header.Match)
{
case HeaderMatchType.Equals:
return string.Equals(value, header.Value, StringComparison.OrdinalIgnoreCase);
case HeaderMatchType.Substring:
- var isMatch = value.IndexOf(header.Value, StringComparison.OrdinalIgnoreCase) != -1;
+ var isMatch = value.ToString().IndexOf(header.Value, StringComparison.OrdinalIgnoreCase) != -1;
//_logger.LogDebug("IsMatch-Substring value: {0} testValue: {1} isMatch: {2}", value, header.Value, isMatch);
return isMatch;
case HeaderMatchType.Regex:
@@ -368,15 +365,18 @@ namespace Emby.Dlna
var systemProfilesPath = SystemProfilesPath;
- foreach (var name in _assemblyInfo.GetManifestResourceNames(GetType())
- .Where(i => i.StartsWith(namespaceName))
- .ToList())
+ foreach (var name in _assembly.GetManifestResourceNames())
{
+ if (!name.StartsWith(namespaceName))
+ {
+ continue;
+ }
+
var filename = Path.GetFileName(name).Substring(namespaceName.Length);
var path = Path.Combine(systemProfilesPath, filename);
- using (var stream = _assemblyInfo.GetManifestResourceStream(GetType(), name))
+ using (var stream = _assembly.GetManifestResourceStream(name))
{
var fileInfo = _fileSystem.GetFileInfo(path);
@@ -493,7 +493,7 @@ namespace Emby.Dlna
internal string Path { get; set; }
}
- public string GetServerDescriptionXml(IDictionary<string, string> headers, string serverUuId, string serverAddress)
+ public string GetServerDescriptionXml(IHeaderDictionary headers, string serverUuId, string serverAddress)
{
var profile = GetProfile(headers) ??
GetDefaultProfile();
@@ -514,7 +514,7 @@ namespace Emby.Dlna
return new ImageStream
{
Format = format,
- Stream = _assemblyInfo.GetManifestResourceStream(GetType(), resource)
+ Stream = _assembly.GetManifestResourceStream(resource)
};
}
}
diff --git a/Emby.Dlna/Emby.Dlna.csproj b/Emby.Dlna/Emby.Dlna.csproj
index 71ded2337..4c07087c5 100644
--- a/Emby.Dlna/Emby.Dlna.csproj
+++ b/Emby.Dlna/Emby.Dlna.csproj
@@ -58,4 +58,9 @@
<EmbeddedResource Include="Profiles\Xml\Xbox One.xml" />
</ItemGroup>
+ <ItemGroup>
+ <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
+ <PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
+ </ItemGroup>
+
</Project>
diff --git a/Emby.Dlna/IUpnpService.cs b/Emby.Dlna/IUpnpService.cs
index ab8aa4619..ae90e95c7 100644
--- a/Emby.Dlna/IUpnpService.cs
+++ b/Emby.Dlna/IUpnpService.cs
@@ -1,5 +1,3 @@
-using System.Collections.Generic;
-
namespace Emby.Dlna
{
public interface IUpnpService
@@ -7,9 +5,8 @@ namespace Emby.Dlna
/// <summary>
/// Gets the content directory XML.
/// </summary>
- /// <param name="headers">The headers.</param>
/// <returns>System.String.</returns>
- string GetServiceXml(IDictionary<string, string> headers);
+ string GetServiceXml();
/// <summary>
/// Processes the control request.
diff --git a/Emby.Dlna/Main/DlnaEntryPoint.cs b/Emby.Dlna/Main/DlnaEntryPoint.cs
index a20006578..5fbe70ded 100644
--- a/Emby.Dlna/Main/DlnaEntryPoint.cs
+++ b/Emby.Dlna/Main/DlnaEntryPoint.cs
@@ -1,5 +1,4 @@
using System;
-using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Emby.Dlna.PlayTo;
@@ -20,10 +19,10 @@ using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.System;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
using Rssdp;
using Rssdp.Infrastructure;
+using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace Emby.Dlna.Main
{
@@ -48,9 +47,8 @@ namespace Emby.Dlna.Main
private readonly IDeviceDiscovery _deviceDiscovery;
private SsdpDevicePublisher _Publisher;
-
+
private readonly ISocketFactory _socketFactory;
- private readonly IEnvironmentInfo _environmentInfo;
private readonly INetworkManager _networkManager;
private ISsdpCommunicationsServer _communicationsServer;
@@ -76,10 +74,8 @@ namespace Emby.Dlna.Main
IDeviceDiscovery deviceDiscovery,
IMediaEncoder mediaEncoder,
ISocketFactory socketFactory,
- IEnvironmentInfo environmentInfo,
INetworkManager networkManager,
IUserViewManager userViewManager,
- IXmlReaderSettingsFactory xmlReaderSettingsFactory,
ITVSeriesManager tvSeriesManager)
{
_config = config;
@@ -96,11 +92,11 @@ namespace Emby.Dlna.Main
_deviceDiscovery = deviceDiscovery;
_mediaEncoder = mediaEncoder;
_socketFactory = socketFactory;
- _environmentInfo = environmentInfo;
_networkManager = networkManager;
_logger = loggerFactory.CreateLogger("Dlna");
- ContentDirectory = new ContentDirectory.ContentDirectory(dlnaManager,
+ ContentDirectory = new ContentDirectory.ContentDirectory(
+ dlnaManager,
userDataManager,
imageProcessor,
libraryManager,
@@ -112,12 +108,11 @@ namespace Emby.Dlna.Main
mediaSourceManager,
userViewManager,
mediaEncoder,
- xmlReaderSettingsFactory,
tvSeriesManager);
- ConnectionManager = new ConnectionManager.ConnectionManager(dlnaManager, config, _logger, httpClient, xmlReaderSettingsFactory);
+ ConnectionManager = new ConnectionManager.ConnectionManager(dlnaManager, config, _logger, httpClient);
- MediaReceiverRegistrar = new MediaReceiverRegistrar.MediaReceiverRegistrar(_logger, httpClient, config, xmlReaderSettingsFactory);
+ MediaReceiverRegistrar = new MediaReceiverRegistrar.MediaReceiverRegistrar(_logger, httpClient, config);
Current = this;
}
@@ -169,9 +164,10 @@ namespace Emby.Dlna.Main
{
if (_communicationsServer == null)
{
- var enableMultiSocketBinding = _environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows;
+ var enableMultiSocketBinding = OperatingSystem.Id == OperatingSystemId.Windows ||
+ OperatingSystem.Id == OperatingSystemId.Linux;
- _communicationsServer = new SsdpCommunicationsServer(_socketFactory, _networkManager, _logger, enableMultiSocketBinding)
+ _communicationsServer = new SsdpCommunicationsServer(_config, _socketFactory, _networkManager, _logger, enableMultiSocketBinding)
{
IsShared = true
};
@@ -229,7 +225,7 @@ namespace Emby.Dlna.Main
try
{
- _Publisher = new SsdpDevicePublisher(_communicationsServer, _environmentInfo.OperatingSystemName, _environmentInfo.OperatingSystemVersion);
+ _Publisher = new SsdpDevicePublisher(_communicationsServer, _networkManager, OperatingSystem.Name, Environment.OSVersion.VersionString, _config.GetDlnaConfiguration().SendOnlyMatchedHost);
_Publisher.LogFunction = LogMessage;
_Publisher.SupportPnpRootDevice = false;
@@ -245,17 +241,17 @@ namespace Emby.Dlna.Main
private async Task RegisterServerEndpoints()
{
- var addresses = (await _appHost.GetLocalIpAddresses(CancellationToken.None).ConfigureAwait(false)).ToList();
+ var addresses = await _appHost.GetLocalIpAddresses(CancellationToken.None).ConfigureAwait(false);
var udn = CreateUuid(_appHost.SystemId);
foreach (var address in addresses)
{
- // TODO: Remove this condition on platforms that support it
- //if (address.AddressFamily == IpAddressFamily.InterNetworkV6)
- //{
- // continue;
- //}
+ if (address.AddressFamily == IpAddressFamily.InterNetworkV6)
+ {
+ // Not support IPv6 right now
+ continue;
+ }
var fullService = "urn:schemas-upnp-org:device:MediaServer:1";
@@ -268,6 +264,8 @@ namespace Emby.Dlna.Main
{
CacheLifetime = TimeSpan.FromSeconds(1800), //How long SSDP clients can cache this info.
Location = uri, // Must point to the URL that serves your devices UPnP description document.
+ Address = address,
+ SubnetMask = _networkManager.GetLocalIpSubnetMask(address),
FriendlyName = "Jellyfin",
Manufacturer = "Jellyfin",
ModelName = "Jellyfin Server",
diff --git a/Emby.Dlna/MediaReceiverRegistrar/ControlHandler.cs b/Emby.Dlna/MediaReceiverRegistrar/ControlHandler.cs
index ae8175f4a..7381e5258 100644
--- a/Emby.Dlna/MediaReceiverRegistrar/ControlHandler.cs
+++ b/Emby.Dlna/MediaReceiverRegistrar/ControlHandler.cs
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using Emby.Dlna.Service;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace Emby.Dlna.MediaReceiverRegistrar
@@ -36,8 +35,8 @@ namespace Emby.Dlna.MediaReceiverRegistrar
};
}
- public ControlHandler(IServerConfigurationManager config, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
- : base(config, logger, xmlReaderSettingsFactory)
+ public ControlHandler(IServerConfigurationManager config, ILogger logger)
+ : base(config, logger)
{
}
}
diff --git a/Emby.Dlna/MediaReceiverRegistrar/MediaReceiverRegistrar.cs b/Emby.Dlna/MediaReceiverRegistrar/MediaReceiverRegistrar.cs
index 2b84528ea..b565cb631 100644
--- a/Emby.Dlna/MediaReceiverRegistrar/MediaReceiverRegistrar.cs
+++ b/Emby.Dlna/MediaReceiverRegistrar/MediaReceiverRegistrar.cs
@@ -1,8 +1,6 @@
-using System.Collections.Generic;
using Emby.Dlna.Service;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace Emby.Dlna.MediaReceiverRegistrar
@@ -10,16 +8,14 @@ namespace Emby.Dlna.MediaReceiverRegistrar
public class MediaReceiverRegistrar : BaseService, IMediaReceiverRegistrar
{
private readonly IServerConfigurationManager _config;
- protected readonly IXmlReaderSettingsFactory XmlReaderSettingsFactory;
- public MediaReceiverRegistrar(ILogger logger, IHttpClient httpClient, IServerConfigurationManager config, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public MediaReceiverRegistrar(ILogger logger, IHttpClient httpClient, IServerConfigurationManager config)
: base(logger, httpClient)
{
_config = config;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
- public string GetServiceXml(IDictionary<string, string> headers)
+ public string GetServiceXml()
{
return new MediaReceiverRegistrarXmlBuilder().GetXml();
}
@@ -28,7 +24,7 @@ namespace Emby.Dlna.MediaReceiverRegistrar
{
return new ControlHandler(
_config,
- Logger, XmlReaderSettingsFactory)
+ Logger)
.ProcessControlRequest(request);
}
}
diff --git a/Emby.Dlna/PlayTo/CurrentIdEventArgs.cs b/Emby.Dlna/PlayTo/CurrentIdEventArgs.cs
deleted file mode 100644
index fdf435bcf..000000000
--- a/Emby.Dlna/PlayTo/CurrentIdEventArgs.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System;
-
-namespace Emby.Dlna.PlayTo
-{
- public class CurrentIdEventArgs : EventArgs
- {
- public string Id { get; set; }
- }
-}
diff --git a/Emby.Dlna/PlayTo/Device.cs b/Emby.Dlna/PlayTo/Device.cs
index 037cdd8aa..0c5ddee65 100644
--- a/Emby.Dlna/PlayTo/Device.cs
+++ b/Emby.Dlna/PlayTo/Device.cs
@@ -4,6 +4,7 @@ using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using System.Xml;
using System.Xml.Linq;
using Emby.Dlna.Common;
using Emby.Dlna.Server;
@@ -733,26 +734,21 @@ namespace Emby.Dlna.PlayTo
return (true, null);
}
- XElement uPnpResponse;
+ XElement uPnpResponse = null;
- // Handle different variations sent back by devices
try
{
- uPnpResponse = XElement.Parse(trackString);
+ uPnpResponse = ParseResponse(trackString);
}
- catch (Exception)
+ catch (Exception ex)
{
- // first try to add a root node with a dlna namesapce
- try
- {
- uPnpResponse = XElement.Parse("<data xmlns:dlna=\"urn:schemas-dlna-org:device-1-0\">" + trackString + "</data>");
- uPnpResponse = uPnpResponse.Descendants().First();
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Unable to parse xml {0}", trackString);
- return (true, null);
- }
+ _logger.LogError(ex, "Uncaught exception while parsing xml");
+ }
+
+ if (uPnpResponse == null)
+ {
+ _logger.LogError("Failed to parse xml: \n {Xml}", trackString);
+ return (true, null);
}
var e = uPnpResponse.Element(uPnpNamespaces.items);
@@ -762,6 +758,43 @@ namespace Emby.Dlna.PlayTo
return (true, uTrack);
}
+ private XElement ParseResponse(string xml)
+ {
+ // Handle different variations sent back by devices
+ try
+ {
+ return XElement.Parse(xml);
+ }
+ catch (XmlException)
+ {
+
+ }
+
+ // first try to add a root node with a dlna namesapce
+ try
+ {
+ return XElement.Parse("<data xmlns:dlna=\"urn:schemas-dlna-org:device-1-0\">" + xml + "</data>")
+ .Descendants()
+ .First();
+ }
+ catch (XmlException)
+ {
+
+ }
+
+ // some devices send back invalid xml
+ try
+ {
+ return XElement.Parse(xml.Replace("&", "&amp;"));
+ }
+ catch (XmlException)
+ {
+
+ }
+
+ return null;
+ }
+
private static uBaseObject CreateUBaseObject(XElement container, string trackUri)
{
if (container == null)
@@ -1093,6 +1126,11 @@ namespace Emby.Dlna.PlayTo
private void OnPlaybackStart(uBaseObject mediaInfo)
{
+ if (string.IsNullOrWhiteSpace(mediaInfo.Url))
+ {
+ return;
+ }
+
PlaybackStart?.Invoke(this, new PlaybackStartEventArgs
{
MediaInfo = mediaInfo
@@ -1101,8 +1139,7 @@ namespace Emby.Dlna.PlayTo
private void OnPlaybackProgress(uBaseObject mediaInfo)
{
- var mediaUrl = mediaInfo.Url;
- if (string.IsNullOrWhiteSpace(mediaUrl))
+ if (string.IsNullOrWhiteSpace(mediaInfo.Url))
{
return;
}
@@ -1115,7 +1152,6 @@ namespace Emby.Dlna.PlayTo
private void OnPlaybackStop(uBaseObject mediaInfo)
{
-
PlaybackStopped?.Invoke(this, new PlaybackStoppedEventArgs
{
MediaInfo = mediaInfo
diff --git a/Emby.Dlna/PlayTo/PlayToController.cs b/Emby.Dlna/PlayTo/PlayToController.cs
index be86dde16..c58f16438 100644
--- a/Emby.Dlna/PlayTo/PlayToController.cs
+++ b/Emby.Dlna/PlayTo/PlayToController.cs
@@ -6,6 +6,7 @@ using System.Threading;
using System.Threading.Tasks;
using Emby.Dlna.Didl;
using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
@@ -17,8 +18,8 @@ using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Globalization;
-using MediaBrowser.Model.Services;
using MediaBrowser.Model.Session;
+using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging;
namespace Emby.Dlna.PlayTo
@@ -101,9 +102,10 @@ namespace Emby.Dlna.PlayTo
{
_sessionManager.ReportSessionEnded(_session.Id);
}
- catch
+ catch (Exception ex)
{
// Could throw if the session is already gone
+ _logger.LogError(ex, "Error reporting the end of session {Id}", _session.Id);
}
}
@@ -111,20 +113,14 @@ namespace Emby.Dlna.PlayTo
{
var info = e.Argument;
- info.Headers.TryGetValue("NTS", out string nts);
-
- if (!info.Headers.TryGetValue("USN", out string usn)) usn = string.Empty;
-
- if (!info.Headers.TryGetValue("NT", out string nt)) nt = string.Empty;
-
- if (usn.IndexOf(_device.Properties.UUID, StringComparison.OrdinalIgnoreCase) != -1 &&
- !_disposed)
+ if (!_disposed
+ && info.Headers.TryGetValue("USN", out string usn)
+ && usn.IndexOf(_device.Properties.UUID, StringComparison.OrdinalIgnoreCase) != -1
+ && (usn.IndexOf("MediaRenderer:", StringComparison.OrdinalIgnoreCase) != -1
+ || (info.Headers.TryGetValue("NT", out string nt)
+ && nt.IndexOf("MediaRenderer:", StringComparison.OrdinalIgnoreCase) != -1)))
{
- if (usn.IndexOf("MediaRenderer:", StringComparison.OrdinalIgnoreCase) != -1 ||
- nt.IndexOf("MediaRenderer:", StringComparison.OrdinalIgnoreCase) != -1)
- {
- OnDeviceUnavailable();
- }
+ OnDeviceUnavailable();
}
}
@@ -611,22 +607,34 @@ namespace Emby.Dlna.PlayTo
public void Dispose()
{
- if (!_disposed)
- {
- _disposed = true;
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
- _device.PlaybackStart -= _device_PlaybackStart;
- _device.PlaybackProgress -= _device_PlaybackProgress;
- _device.PlaybackStopped -= _device_PlaybackStopped;
- _device.MediaChanged -= _device_MediaChanged;
- //_deviceDiscovery.DeviceLeft -= _deviceDiscovery_DeviceLeft;
- _device.OnDeviceUnavailable = null;
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+ if (disposing)
+ {
_device.Dispose();
}
+
+ _device.PlaybackStart -= _device_PlaybackStart;
+ _device.PlaybackProgress -= _device_PlaybackProgress;
+ _device.PlaybackStopped -= _device_PlaybackStopped;
+ _device.MediaChanged -= _device_MediaChanged;
+ _deviceDiscovery.DeviceLeft -= _deviceDiscovery_DeviceLeft;
+ _device.OnDeviceUnavailable = null;
+ _device = null;
+
+ _disposed = true;
}
- private readonly CultureInfo _usCulture = new CultureInfo("en-US");
+ private static readonly CultureInfo _usCulture = CultureInfo.ReadOnly(new CultureInfo("en-US"));
private Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken)
{
@@ -847,13 +855,13 @@ namespace Emby.Dlna.PlayTo
if (index == -1) return request;
var query = url.Substring(index + 1);
- QueryParamCollection values = MyHttpUtility.ParseQueryString(query);
+ Dictionary<string, string> values = QueryHelpers.ParseQuery(query).ToDictionary(kv => kv.Key, kv => kv.Value.ToString());
- request.DeviceProfileId = values.Get("DeviceProfileId");
- request.DeviceId = values.Get("DeviceId");
- request.MediaSourceId = values.Get("MediaSourceId");
- request.LiveStreamId = values.Get("LiveStreamId");
- request.IsDirectStream = string.Equals("true", values.Get("Static"), StringComparison.OrdinalIgnoreCase);
+ request.DeviceProfileId = values.GetValueOrDefault("DeviceProfileId");
+ request.DeviceId = values.GetValueOrDefault("DeviceId");
+ request.MediaSourceId = values.GetValueOrDefault("MediaSourceId");
+ request.LiveStreamId = values.GetValueOrDefault("LiveStreamId");
+ request.IsDirectStream = string.Equals("true", values.GetValueOrDefault("Static"), StringComparison.OrdinalIgnoreCase);
request.AudioStreamIndex = GetIntValue(values, "AudioStreamIndex");
request.SubtitleStreamIndex = GetIntValue(values, "SubtitleStreamIndex");
@@ -867,9 +875,9 @@ namespace Emby.Dlna.PlayTo
}
}
- private static int? GetIntValue(QueryParamCollection values, string name)
+ private static int? GetIntValue(IReadOnlyDictionary<string, string> values, string name)
{
- var value = values.Get(name);
+ var value = values.GetValueOrDefault(name);
if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
{
@@ -879,9 +887,9 @@ namespace Emby.Dlna.PlayTo
return null;
}
- private static long GetLongValue(QueryParamCollection values, string name)
+ private static long GetLongValue(IReadOnlyDictionary<string, string> values, string name)
{
- var value = values.Get(name);
+ var value = values.GetValueOrDefault(name);
if (long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
{
diff --git a/Emby.Dlna/PlayTo/PlaylistItemFactory.cs b/Emby.Dlna/PlayTo/PlaylistItemFactory.cs
index aceb634e3..446d8e1e6 100644
--- a/Emby.Dlna/PlayTo/PlaylistItemFactory.cs
+++ b/Emby.Dlna/PlayTo/PlaylistItemFactory.cs
@@ -9,8 +9,6 @@ namespace Emby.Dlna.PlayTo
{
public class PlaylistItemFactory
{
- private readonly CultureInfo _usCulture = new CultureInfo("en-US");
-
public PlaylistItem Create(Photo item, DeviceProfile profile)
{
var playlistItem = new PlaylistItem
diff --git a/Emby.Dlna/PlayTo/TransportCommands.cs b/Emby.Dlna/PlayTo/TransportCommands.cs
index b96fa43e5..4f9e398e9 100644
--- a/Emby.Dlna/PlayTo/TransportCommands.cs
+++ b/Emby.Dlna/PlayTo/TransportCommands.cs
@@ -107,12 +107,18 @@ namespace Emby.Dlna.PlayTo
foreach (var arg in action.ArgumentList)
{
if (arg.Direction == "out")
+ {
continue;
+ }
if (arg.Name == "InstanceID")
+ {
stateString += BuildArgumentXml(arg, "0");
+ }
else
+ {
stateString += BuildArgumentXml(arg, null);
+ }
}
return string.Format(CommandBase, action.Name, xmlNamespace, stateString);
@@ -125,11 +131,18 @@ namespace Emby.Dlna.PlayTo
foreach (var arg in action.ArgumentList)
{
if (arg.Direction == "out")
+ {
continue;
+ }
+
if (arg.Name == "InstanceID")
+ {
stateString += BuildArgumentXml(arg, "0");
+ }
else
+ {
stateString += BuildArgumentXml(arg, value.ToString(), commandParameter);
+ }
}
return string.Format(CommandBase, action.Name, xmlNamesapce, stateString);
@@ -142,11 +155,17 @@ namespace Emby.Dlna.PlayTo
foreach (var arg in action.ArgumentList)
{
if (arg.Name == "InstanceID")
+ {
stateString += BuildArgumentXml(arg, "0");
+ }
else if (dictionary.ContainsKey(arg.Name))
+ {
stateString += BuildArgumentXml(arg, dictionary[arg.Name]);
+ }
else
+ {
stateString += BuildArgumentXml(arg, value.ToString());
+ }
}
return string.Format(CommandBase, action.Name, xmlNamesapce, stateString);
diff --git a/Emby.Dlna/PlayTo/TransportStateEventArgs.cs b/Emby.Dlna/PlayTo/TransportStateEventArgs.cs
deleted file mode 100644
index 7dcd39e10..000000000
--- a/Emby.Dlna/PlayTo/TransportStateEventArgs.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System;
-
-namespace Emby.Dlna.PlayTo
-{
- public class TransportStateEventArgs : EventArgs
- {
- public TRANSPORTSTATE State { get; set; }
- }
-}
diff --git a/Emby.Dlna/PlayTo/uParser.cs b/Emby.Dlna/PlayTo/uParser.cs
deleted file mode 100644
index 3a0ffffd4..000000000
--- a/Emby.Dlna/PlayTo/uParser.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Xml.Linq;
-
-namespace Emby.Dlna.PlayTo
-{
- public class uParser
- {
- public static IList<uBaseObject> ParseBrowseXml(XDocument doc)
- {
- if (doc == null)
- {
- throw new ArgumentException("doc");
- }
-
- var list = new List<uBaseObject>();
-
- var document = doc.Document;
-
- if (document == null)
- return list;
-
- var item = (from result in document.Descendants("Result") select result).FirstOrDefault();
-
- if (item == null)
- return list;
-
- var uPnpResponse = XElement.Parse((string)item);
-
- var uObjects = from container in uPnpResponse.Elements(uPnpNamespaces.containers)
- select new uParserObject { Element = container };
-
- var uObjects2 = from container in uPnpResponse.Elements(uPnpNamespaces.items)
- select new uParserObject { Element = container };
-
- list.AddRange(uObjects.Concat(uObjects2).Select(CreateObjectFromXML).Where(uObject => uObject != null));
-
- return list;
- }
-
- public static uBaseObject CreateObjectFromXML(uParserObject uItem)
- {
- return UpnpContainer.Create(uItem.Element);
- }
- }
-}
diff --git a/Emby.Dlna/PlayTo/uParserObject.cs b/Emby.Dlna/PlayTo/uParserObject.cs
deleted file mode 100644
index 87a7f69c6..000000000
--- a/Emby.Dlna/PlayTo/uParserObject.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System.Xml.Linq;
-
-namespace Emby.Dlna.PlayTo
-{
- public class uParserObject
- {
- public XElement Element { get; set; }
- }
-}
diff --git a/Emby.Dlna/Properties/AssemblyInfo.cs b/Emby.Dlna/Properties/AssemblyInfo.cs
index 9d3a22c97..a2c1e0db8 100644
--- a/Emby.Dlna/Properties/AssemblyInfo.cs
+++ b/Emby.Dlna/Properties/AssemblyInfo.cs
@@ -8,8 +8,8 @@ using System.Resources;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/Emby.Dlna/Service/BaseControlHandler.cs b/Emby.Dlna/Service/BaseControlHandler.cs
index 5f78674b8..067d5fa43 100644
--- a/Emby.Dlna/Service/BaseControlHandler.cs
+++ b/Emby.Dlna/Service/BaseControlHandler.cs
@@ -7,7 +7,6 @@ using System.Xml;
using Emby.Dlna.Didl;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Extensions;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace Emby.Dlna.Service
@@ -18,13 +17,11 @@ namespace Emby.Dlna.Service
protected readonly IServerConfigurationManager Config;
protected readonly ILogger _logger;
- protected readonly IXmlReaderSettingsFactory XmlReaderSettingsFactory;
- protected BaseControlHandler(IServerConfigurationManager config, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ protected BaseControlHandler(IServerConfigurationManager config, ILogger logger)
{
Config = config;
_logger = logger;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
public ControlResponse ProcessControlRequest(ControlRequest request)
@@ -61,11 +58,13 @@ namespace Emby.Dlna.Service
using (var streamReader = new StreamReader(request.InputXml))
{
- var readerSettings = XmlReaderSettingsFactory.Create(false);
-
- readerSettings.CheckCharacters = false;
- readerSettings.IgnoreProcessingInstructions = true;
- readerSettings.IgnoreComments = true;
+ var readerSettings = new XmlReaderSettings()
+ {
+ ValidationType = ValidationType.None,
+ CheckCharacters = false,
+ IgnoreProcessingInstructions = true,
+ IgnoreComments = true
+ };
using (var reader = XmlReader.Create(streamReader, readerSettings))
{
diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs
index faaeb5af8..6d209d8d0 100644
--- a/Emby.Drawing/ImageProcessor.cs
+++ b/Emby.Drawing/ImageProcessor.cs
@@ -180,6 +180,12 @@ namespace Emby.Drawing
var supportedImageInfo = await GetSupportedImage(originalImagePath, dateModified).ConfigureAwait(false);
originalImagePath = supportedImageInfo.path;
+
+ if (!File.Exists(originalImagePath))
+ {
+ return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified);
+ }
+
dateModified = supportedImageInfo.dateModified;
bool requiresTransparency = TransparentImageTypes.Contains(Path.GetExtension(originalImagePath));
@@ -265,8 +271,6 @@ namespace Emby.Drawing
{
// If it fails for whatever reason, return the original image
_logger.LogError(ex, "Error encoding image");
-
- // Just spit out the original file if all the options are default
return (originalImagePath, MimeTypes.GetMimeType(originalImagePath), dateModified);
}
finally
diff --git a/Emby.Drawing/Properties/AssemblyInfo.cs b/Emby.Drawing/Properties/AssemblyInfo.cs
index 8dfefe0af..281008e37 100644
--- a/Emby.Drawing/Properties/AssemblyInfo.cs
+++ b/Emby.Drawing/Properties/AssemblyInfo.cs
@@ -8,8 +8,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
diff --git a/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs b/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs
index 943caa3e6..2f0003be8 100644
--- a/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs
+++ b/Emby.IsoMounting/IsoMounter/LinuxIsoManager.cs
@@ -7,6 +7,7 @@ using MediaBrowser.Model.Diagnostics;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
+using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace IsoMounter
{
@@ -17,7 +18,6 @@ namespace IsoMounter
#region Private Fields
- private readonly IEnvironmentInfo EnvironmentInfo;
private readonly bool ExecutablesAvailable;
private readonly ILogger _logger;
private readonly string MountCommand;
@@ -30,10 +30,8 @@ namespace IsoMounter
#region Constructor(s)
- public LinuxIsoManager(ILogger logger, IEnvironmentInfo environment, IProcessFactory processFactory)
+ public LinuxIsoManager(ILogger logger, IProcessFactory processFactory)
{
-
- EnvironmentInfo = environment;
_logger = logger;
ProcessFactory = processFactory;
@@ -109,7 +107,7 @@ namespace IsoMounter
public bool CanMount(string path)
{
- if (EnvironmentInfo.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Linux)
+ if (OperatingSystem.Id != OperatingSystemId.Linux)
{
return false;
}
@@ -118,7 +116,7 @@ namespace IsoMounter
Name,
path,
Path.GetExtension(path),
- EnvironmentInfo.OperatingSystem,
+ OperatingSystem.Name,
ExecutablesAvailable
);
diff --git a/Emby.IsoMounting/IsoMounter/Properties/AssemblyInfo.cs b/Emby.IsoMounting/IsoMounter/Properties/AssemblyInfo.cs
index d60eccc2e..5956fc3b3 100644
--- a/Emby.IsoMounting/IsoMounter/Properties/AssemblyInfo.cs
+++ b/Emby.IsoMounting/IsoMounter/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/Emby.Naming/Properties/AssemblyInfo.cs b/Emby.Naming/Properties/AssemblyInfo.cs
index 15311570b..f26e0ba79 100644
--- a/Emby.Naming/Properties/AssemblyInfo.cs
+++ b/Emby.Naming/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/Emby.Naming/TV/EpisodePathParser.cs b/Emby.Naming/TV/EpisodePathParser.cs
index 9485d697b..a8f81a3b8 100644
--- a/Emby.Naming/TV/EpisodePathParser.cs
+++ b/Emby.Naming/TV/EpisodePathParser.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
-using System.Text.RegularExpressions;
using Emby.Naming.Common;
namespace Emby.Naming.TV
@@ -22,7 +21,9 @@ namespace Emby.Naming.TV
// There were no failed tests without this block, but to be safe, we can keep it until
// the regex which require file extensions are modified so that they don't need them.
if (IsDirectory)
+ {
path += ".mp4";
+ }
EpisodePathParserResult result = null;
@@ -35,6 +36,7 @@ namespace Emby.Naming.TV
continue;
}
}
+
if (isNamed.HasValue)
{
if (expression.IsNamed != isNamed.Value)
@@ -42,6 +44,7 @@ namespace Emby.Naming.TV
continue;
}
}
+
if (isOptimistic.HasValue)
{
if (expression.IsOptimistic != isOptimistic.Value)
@@ -191,13 +194,20 @@ namespace Emby.Naming.TV
private void FillAdditional(string path, EpisodePathParserResult info, IEnumerable<EpisodeExpression> expressions)
{
- var results = expressions
- .Where(i => i.IsNamed)
- .Select(i => Parse(path, i))
- .Where(i => i.Success);
-
- foreach (var result in results)
+ foreach (var i in expressions)
{
+ if (!i.IsNamed)
+ {
+ continue;
+ }
+
+ var result = Parse(path, i);
+
+ if (!result.Success)
+ {
+ continue;
+ }
+
if (string.IsNullOrEmpty(info.SeriesName))
{
info.SeriesName = result.SeriesName;
@@ -208,12 +218,10 @@ namespace Emby.Naming.TV
info.EndingEpsiodeNumber = result.EndingEpsiodeNumber;
}
- if (!string.IsNullOrEmpty(info.SeriesName))
+ if (!string.IsNullOrEmpty(info.SeriesName)
+ && (!info.EpisodeNumber.HasValue || info.EndingEpsiodeNumber.HasValue))
{
- if (!info.EpisodeNumber.HasValue || info.EndingEpsiodeNumber.HasValue)
- {
- break;
- }
+ break;
}
}
}
diff --git a/Emby.Naming/Video/VideoListResolver.cs b/Emby.Naming/Video/VideoListResolver.cs
index ef97b8739..afedc30ef 100644
--- a/Emby.Naming/Video/VideoListResolver.cs
+++ b/Emby.Naming/Video/VideoListResolver.cs
@@ -175,25 +175,52 @@ namespace Emby.Naming.Video
return videos;
}
+ var list = new List<VideoInfo>();
+
var folderName = Path.GetFileName(Path.GetDirectoryName(videos[0].Files[0].Path));
if (!string.IsNullOrEmpty(folderName) && folderName.Length > 1)
{
- var ordered = videos.OrderBy(i => i.Name);
-
- return ordered.GroupBy(v => new {v.Name, v.Year}).Select(group => new VideoInfo
+ if (videos.All(i => i.Files.Count == 1 && IsEligibleForMultiVersion(folderName, i.Files[0].Path)))
{
- Name = folderName,
- Year = group.First().Year,
- Files = group.First().Files,
- AlternateVersions = group.Skip(1).Select(i => i.Files[0]).ToList(),
- Extras = group.First().Extras.Concat(group.Skip(1).SelectMany(i => i.Extras)).ToList()
- });
+ if (HaveSameYear(videos))
+ {
+ var ordered = videos.OrderBy(i => i.Name).ToList();
+
+ list.Add(ordered[0]);
+
+ list[0].AlternateVersions = ordered.Skip(1).Select(i => i.Files[0]).ToList();
+ list[0].Name = folderName;
+ list[0].Extras.AddRange(ordered.Skip(1).SelectMany(i => i.Extras));
+
+ return list;
+ }
+ }
}
return videos;
}
+ private bool HaveSameYear(List<VideoInfo> videos)
+ {
+ return videos.Select(i => i.Year ?? -1).Distinct().Count() < 2;
+ }
+
+ private bool IsEligibleForMultiVersion(string folderName, string testFilename)
+ {
+ testFilename = Path.GetFileNameWithoutExtension(testFilename) ?? string.Empty;
+
+ if (testFilename.StartsWith(folderName, StringComparison.OrdinalIgnoreCase))
+ {
+ testFilename = testFilename.Substring(folderName.Length).Trim();
+ return string.IsNullOrEmpty(testFilename) ||
+ testFilename.StartsWith("-") ||
+ string.IsNullOrWhiteSpace(Regex.Replace(testFilename, @"\[([^]]*)\]", string.Empty)) ;
+ }
+
+ return false;
+ }
+
private List<VideoFileInfo> GetExtras(IEnumerable<VideoFileInfo> remainingFiles, List<string> baseNames)
{
foreach (var name in baseNames.ToList())
diff --git a/Emby.Notifications/CoreNotificationTypes.cs b/Emby.Notifications/CoreNotificationTypes.cs
index 8cc14fa01..0f9fc08d9 100644
--- a/Emby.Notifications/CoreNotificationTypes.cs
+++ b/Emby.Notifications/CoreNotificationTypes.cs
@@ -11,101 +11,81 @@ namespace Emby.Notifications
public class CoreNotificationTypes : INotificationTypeFactory
{
private readonly ILocalizationManager _localization;
- private readonly IServerApplicationHost _appHost;
- public CoreNotificationTypes(ILocalizationManager localization, IServerApplicationHost appHost)
+ public CoreNotificationTypes(ILocalizationManager localization)
{
_localization = localization;
- _appHost = appHost;
}
public IEnumerable<NotificationTypeInfo> GetNotificationTypes()
{
- var knownTypes = new List<NotificationTypeInfo>
+ var knownTypes = new NotificationTypeInfo[]
{
new NotificationTypeInfo
{
Type = NotificationType.ApplicationUpdateInstalled.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.InstallationFailed.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.PluginInstalled.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.PluginError.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.PluginUninstalled.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.PluginUpdateInstalled.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.ServerRestartRequired.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.TaskFailed.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.NewLibraryContent.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.AudioPlayback.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.VideoPlayback.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.AudioPlaybackStopped.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.VideoPlaybackStopped.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.CameraImageUploaded.ToString()
},
-
new NotificationTypeInfo
{
Type = NotificationType.UserLockedOut.ToString()
- }
- };
-
- if (!_appHost.CanSelfUpdate)
- {
- knownTypes.Add(new NotificationTypeInfo
+ },
+ new NotificationTypeInfo
{
Type = NotificationType.ApplicationUpdateAvailable.ToString()
- });
- }
+ }
+ };
foreach (var type in knownTypes)
{
diff --git a/Emby.Notifications/Notifications.cs b/Emby.Notifications/Notifications.cs
index d3290479f..ec08fd193 100644
--- a/Emby.Notifications/Notifications.cs
+++ b/Emby.Notifications/Notifications.cs
@@ -5,21 +5,17 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
-using MediaBrowser.Common.Updates;
using MediaBrowser.Controller;
-using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Notifications;
using MediaBrowser.Controller.Plugins;
-using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Notifications;
-using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
namespace Emby.Notifications
@@ -29,43 +25,40 @@ namespace Emby.Notifications
/// </summary>
public class Notifications : IServerEntryPoint
{
- private readonly IInstallationManager _installationManager;
- private readonly IUserManager _userManager;
private readonly ILogger _logger;
- private readonly ITaskManager _taskManager;
private readonly INotificationManager _notificationManager;
private readonly ILibraryManager _libraryManager;
- private readonly ISessionManager _sessionManager;
private readonly IServerApplicationHost _appHost;
private Timer LibraryUpdateTimer { get; set; }
private readonly object _libraryChangedSyncLock = new object();
private readonly IConfigurationManager _config;
- private readonly IDeviceManager _deviceManager;
private readonly ILocalizationManager _localization;
private readonly IActivityManager _activityManager;
private string[] _coreNotificationTypes;
- public Notifications(IInstallationManager installationManager, IActivityManager activityManager, ILocalizationManager localization, IUserManager userManager, ILogger logger, ITaskManager taskManager, INotificationManager notificationManager, ILibraryManager libraryManager, ISessionManager sessionManager, IServerApplicationHost appHost, IConfigurationManager config, IDeviceManager deviceManager)
+ public Notifications(
+ IActivityManager activityManager,
+ ILocalizationManager localization,
+ ILogger logger,
+ INotificationManager notificationManager,
+ ILibraryManager libraryManager,
+ IServerApplicationHost appHost,
+ IConfigurationManager config)
{
- _installationManager = installationManager;
- _userManager = userManager;
_logger = logger;
- _taskManager = taskManager;
_notificationManager = notificationManager;
_libraryManager = libraryManager;
- _sessionManager = sessionManager;
_appHost = appHost;
_config = config;
- _deviceManager = deviceManager;
_localization = localization;
_activityManager = activityManager;
- _coreNotificationTypes = new CoreNotificationTypes(localization, appHost).GetNotificationTypes().Select(i => i.Type).ToArray();
+ _coreNotificationTypes = new CoreNotificationTypes(localization).GetNotificationTypes().Select(i => i.Type).ToArray();
}
public Task RunAsync()
@@ -124,10 +117,9 @@ namespace Emby.Notifications
return _config.GetConfiguration<NotificationOptions>("notifications");
}
- async void _appHost_HasUpdateAvailableChanged(object sender, EventArgs e)
+ private async void _appHost_HasUpdateAvailableChanged(object sender, EventArgs e)
{
- // This notification is for users who can't auto-update (aka running as service)
- if (!_appHost.HasUpdateAvailable || _appHost.CanSelfUpdate)
+ if (!_appHost.HasUpdateAvailable)
{
return;
}
@@ -145,7 +137,7 @@ namespace Emby.Notifications
}
private readonly List<BaseItem> _itemsAdded = new List<BaseItem>();
- void _libraryManager_ItemAdded(object sender, ItemChangeEventArgs e)
+ private void _libraryManager_ItemAdded(object sender, ItemChangeEventArgs e)
{
if (!FilterItem(e.Item))
{
diff --git a/Emby.Notifications/Properties/AssemblyInfo.cs b/Emby.Notifications/Properties/AssemblyInfo.cs
index fd7037551..5c82c90c4 100644
--- a/Emby.Notifications/Properties/AssemblyInfo.cs
+++ b/Emby.Notifications/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/Emby.Photos/Properties/AssemblyInfo.cs b/Emby.Photos/Properties/AssemblyInfo.cs
index 262125d38..a3bb4362a 100644
--- a/Emby.Photos/Properties/AssemblyInfo.cs
+++ b/Emby.Photos/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs
index 739f68767..98cd97c31 100644
--- a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs
+++ b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs
@@ -30,13 +30,10 @@ namespace Emby.Server.Implementations.Activity
public class ActivityLogEntryPoint : IServerEntryPoint
{
private readonly IInstallationManager _installationManager;
-
- //private readonly ILogger _logger;
private readonly ISessionManager _sessionManager;
private readonly ITaskManager _taskManager;
private readonly IActivityManager _activityManager;
private readonly ILocalizationManager _localization;
-
private readonly ILibraryManager _libraryManager;
private readonly ISubtitleManager _subManager;
private readonly IUserManager _userManager;
@@ -61,41 +58,37 @@ namespace Emby.Server.Implementations.Activity
public Task RunAsync()
{
- _taskManager.TaskCompleted += _taskManager_TaskCompleted;
-
- _installationManager.PluginInstalled += _installationManager_PluginInstalled;
- _installationManager.PluginUninstalled += _installationManager_PluginUninstalled;
- _installationManager.PluginUpdated += _installationManager_PluginUpdated;
- _installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed;
+ _taskManager.TaskCompleted += OnTaskCompleted;
- _sessionManager.SessionStarted += _sessionManager_SessionStarted;
- _sessionManager.AuthenticationFailed += _sessionManager_AuthenticationFailed;
- _sessionManager.AuthenticationSucceeded += _sessionManager_AuthenticationSucceeded;
- _sessionManager.SessionEnded += _sessionManager_SessionEnded;
+ _installationManager.PluginInstalled += OnPluginInstalled;
+ _installationManager.PluginUninstalled += OnPluginUninstalled;
+ _installationManager.PluginUpdated += OnPluginUpdated;
+ _installationManager.PackageInstallationFailed += OnPackageInstallationFailed;
- _sessionManager.PlaybackStart += _sessionManager_PlaybackStart;
- _sessionManager.PlaybackStopped += _sessionManager_PlaybackStopped;
+ _sessionManager.SessionStarted += OnSessionStarted;
+ _sessionManager.AuthenticationFailed += OnAuthenticationFailed;
+ _sessionManager.AuthenticationSucceeded += OnAuthenticationSucceeded;
+ _sessionManager.SessionEnded += OnSessionEnded;
- //_subManager.SubtitlesDownloaded += _subManager_SubtitlesDownloaded;
- _subManager.SubtitleDownloadFailure += _subManager_SubtitleDownloadFailure;
+ _sessionManager.PlaybackStart += OnPlaybackStart;
+ _sessionManager.PlaybackStopped += OnPlaybackStopped;
- _userManager.UserCreated += _userManager_UserCreated;
- _userManager.UserPasswordChanged += _userManager_UserPasswordChanged;
- _userManager.UserDeleted += _userManager_UserDeleted;
- _userManager.UserPolicyUpdated += _userManager_UserPolicyUpdated;
- _userManager.UserLockedOut += _userManager_UserLockedOut;
+ _subManager.SubtitleDownloadFailure += OnSubtitleDownloadFailure;
- //_config.ConfigurationUpdated += _config_ConfigurationUpdated;
- //_config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated;
+ _userManager.UserCreated += OnUserCreated;
+ _userManager.UserPasswordChanged += OnUserPasswordChanged;
+ _userManager.UserDeleted += OnUserDeleted;
+ _userManager.UserPolicyUpdated += OnUserPolicyUpdated;
+ _userManager.UserLockedOut += OnUserLockedOut;
- _deviceManager.CameraImageUploaded += _deviceManager_CameraImageUploaded;
+ _deviceManager.CameraImageUploaded += OnCameraImageUploaded;
- _appHost.ApplicationUpdated += _appHost_ApplicationUpdated;
+ _appHost.ApplicationUpdated += OnApplicationUpdated;
return Task.CompletedTask;
}
- void _deviceManager_CameraImageUploaded(object sender, GenericEventArgs<CameraImageUploadInfo> e)
+ private void OnCameraImageUploaded(object sender, GenericEventArgs<CameraImageUploadInfo> e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -104,7 +97,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _userManager_UserLockedOut(object sender, GenericEventArgs<User> e)
+ private void OnUserLockedOut(object sender, GenericEventArgs<User> e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -114,7 +107,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _subManager_SubtitleDownloadFailure(object sender, SubtitleDownloadFailureEventArgs e)
+ private void OnSubtitleDownloadFailure(object sender, SubtitleDownloadFailureEventArgs e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -125,7 +118,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _sessionManager_PlaybackStopped(object sender, PlaybackStopEventArgs e)
+ private void OnPlaybackStopped(object sender, PlaybackStopEventArgs e)
{
var item = e.MediaInfo;
@@ -146,7 +139,7 @@ namespace Emby.Server.Implementations.Activity
return;
}
- var user = e.Users.First();
+ var user = e.Users[0];
CreateLogEntry(new ActivityLogEntry
{
@@ -156,7 +149,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _sessionManager_PlaybackStart(object sender, PlaybackProgressEventArgs e)
+ private void OnPlaybackStart(object sender, PlaybackProgressEventArgs e)
{
var item = e.MediaInfo;
@@ -232,7 +225,7 @@ namespace Emby.Server.Implementations.Activity
return null;
}
- void _sessionManager_SessionEnded(object sender, SessionEventArgs e)
+ private void OnSessionEnded(object sender, SessionEventArgs e)
{
string name;
var session = e.SessionInfo;
@@ -258,7 +251,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _sessionManager_AuthenticationSucceeded(object sender, GenericEventArgs<AuthenticationResult> e)
+ private void OnAuthenticationSucceeded(object sender, GenericEventArgs<AuthenticationResult> e)
{
var user = e.Argument.User;
@@ -271,7 +264,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _sessionManager_AuthenticationFailed(object sender, GenericEventArgs<AuthenticationRequest> e)
+ private void OnAuthenticationFailed(object sender, GenericEventArgs<AuthenticationRequest> e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -282,7 +275,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _appHost_ApplicationUpdated(object sender, GenericEventArgs<PackageVersionInfo> e)
+ private void OnApplicationUpdated(object sender, GenericEventArgs<PackageVersionInfo> e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -292,25 +285,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _config_NamedConfigurationUpdated(object sender, ConfigurationUpdateEventArgs e)
- {
- CreateLogEntry(new ActivityLogEntry
- {
- Name = string.Format(_localization.GetLocalizedString("MessageNamedServerConfigurationUpdatedWithValue"), e.Key),
- Type = "NamedConfigurationUpdated"
- });
- }
-
- void _config_ConfigurationUpdated(object sender, EventArgs e)
- {
- CreateLogEntry(new ActivityLogEntry
- {
- Name = _localization.GetLocalizedString("MessageServerConfigurationUpdated"),
- Type = "ServerConfigurationUpdated"
- });
- }
-
- void _userManager_UserPolicyUpdated(object sender, GenericEventArgs<User> e)
+ private void OnUserPolicyUpdated(object sender, GenericEventArgs<User> e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -320,7 +295,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _userManager_UserDeleted(object sender, GenericEventArgs<User> e)
+ private void OnUserDeleted(object sender, GenericEventArgs<User> e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -329,7 +304,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _userManager_UserPasswordChanged(object sender, GenericEventArgs<User> e)
+ private void OnUserPasswordChanged(object sender, GenericEventArgs<User> e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -339,7 +314,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _userManager_UserCreated(object sender, GenericEventArgs<User> e)
+ private void OnUserCreated(object sender, GenericEventArgs<User> e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -349,18 +324,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _subManager_SubtitlesDownloaded(object sender, SubtitleDownloadEventArgs e)
- {
- CreateLogEntry(new ActivityLogEntry
- {
- Name = string.Format(_localization.GetLocalizedString("SubtitlesDownloadedForItem"), Notifications.Notifications.GetItemName(e.Item)),
- Type = "SubtitlesDownloaded",
- ItemId = e.Item.Id.ToString("N"),
- ShortOverview = string.Format(_localization.GetLocalizedString("ProviderValue"), e.Provider)
- });
- }
-
- void _sessionManager_SessionStarted(object sender, SessionEventArgs e)
+ private void OnSessionStarted(object sender, SessionEventArgs e)
{
string name;
var session = e.SessionInfo;
@@ -386,7 +350,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _installationManager_PluginUpdated(object sender, GenericEventArgs<Tuple<IPlugin, PackageVersionInfo>> e)
+ private void OnPluginUpdated(object sender, GenericEventArgs<Tuple<IPlugin, PackageVersionInfo>> e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -397,7 +361,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _installationManager_PluginUninstalled(object sender, GenericEventArgs<IPlugin> e)
+ private void OnPluginUninstalled(object sender, GenericEventArgs<IPlugin> e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -406,7 +370,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _installationManager_PluginInstalled(object sender, GenericEventArgs<PackageVersionInfo> e)
+ private void OnPluginInstalled(object sender, GenericEventArgs<PackageVersionInfo> e)
{
CreateLogEntry(new ActivityLogEntry
{
@@ -416,7 +380,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _installationManager_PackageInstallationFailed(object sender, InstallationFailedEventArgs e)
+ private void OnPackageInstallationFailed(object sender, InstallationFailedEventArgs e)
{
var installationInfo = e.InstallationInfo;
@@ -429,7 +393,7 @@ namespace Emby.Server.Implementations.Activity
});
}
- void _taskManager_TaskCompleted(object sender, TaskCompletionEventArgs e)
+ private void OnTaskCompleted(object sender, TaskCompletionEventArgs e)
{
var result = e.Result;
var task = e.Task;
@@ -468,48 +432,36 @@ namespace Emby.Server.Implementations.Activity
}
private void CreateLogEntry(ActivityLogEntry entry)
- {
- try
- {
- _activityManager.Create(entry);
- }
- catch
- {
- // Logged at lower levels
- }
- }
+ => _activityManager.Create(entry);
public void Dispose()
{
- _taskManager.TaskCompleted -= _taskManager_TaskCompleted;
+ _taskManager.TaskCompleted -= OnTaskCompleted;
- _installationManager.PluginInstalled -= _installationManager_PluginInstalled;
- _installationManager.PluginUninstalled -= _installationManager_PluginUninstalled;
- _installationManager.PluginUpdated -= _installationManager_PluginUpdated;
- _installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed;
+ _installationManager.PluginInstalled -= OnPluginInstalled;
+ _installationManager.PluginUninstalled -= OnPluginUninstalled;
+ _installationManager.PluginUpdated -= OnPluginUpdated;
+ _installationManager.PackageInstallationFailed -= OnPackageInstallationFailed;
- _sessionManager.SessionStarted -= _sessionManager_SessionStarted;
- _sessionManager.AuthenticationFailed -= _sessionManager_AuthenticationFailed;
- _sessionManager.AuthenticationSucceeded -= _sessionManager_AuthenticationSucceeded;
- _sessionManager.SessionEnded -= _sessionManager_SessionEnded;
+ _sessionManager.SessionStarted -= OnSessionStarted;
+ _sessionManager.AuthenticationFailed -= OnAuthenticationFailed;
+ _sessionManager.AuthenticationSucceeded -= OnAuthenticationSucceeded;
+ _sessionManager.SessionEnded -= OnSessionEnded;
- _sessionManager.PlaybackStart -= _sessionManager_PlaybackStart;
- _sessionManager.PlaybackStopped -= _sessionManager_PlaybackStopped;
+ _sessionManager.PlaybackStart -= OnPlaybackStart;
+ _sessionManager.PlaybackStopped -= OnPlaybackStopped;
- _subManager.SubtitleDownloadFailure -= _subManager_SubtitleDownloadFailure;
+ _subManager.SubtitleDownloadFailure -= OnSubtitleDownloadFailure;
- _userManager.UserCreated -= _userManager_UserCreated;
- _userManager.UserPasswordChanged -= _userManager_UserPasswordChanged;
- _userManager.UserDeleted -= _userManager_UserDeleted;
- _userManager.UserPolicyUpdated -= _userManager_UserPolicyUpdated;
- _userManager.UserLockedOut -= _userManager_UserLockedOut;
+ _userManager.UserCreated -= OnUserCreated;
+ _userManager.UserPasswordChanged -= OnUserPasswordChanged;
+ _userManager.UserDeleted -= OnUserDeleted;
+ _userManager.UserPolicyUpdated -= OnUserPolicyUpdated;
+ _userManager.UserLockedOut -= OnUserLockedOut;
- _config.ConfigurationUpdated -= _config_ConfigurationUpdated;
- _config.NamedConfigurationUpdated -= _config_NamedConfigurationUpdated;
+ _deviceManager.CameraImageUploaded -= OnCameraImageUploaded;
- _deviceManager.CameraImageUploaded -= _deviceManager_CameraImageUploaded;
-
- _appHost.ApplicationUpdated -= _appHost_ApplicationUpdated;
+ _appHost.ApplicationUpdated -= OnApplicationUpdated;
}
/// <summary>
@@ -531,6 +483,7 @@ namespace Emby.Server.Implementations.Activity
values.Add(CreateValueString(years, "year"));
days = days % DaysInYear;
}
+
// Number of months
if (days >= DaysInMonth)
{
@@ -538,25 +491,39 @@ namespace Emby.Server.Implementations.Activity
values.Add(CreateValueString(months, "month"));
days = days % DaysInMonth;
}
+
// Number of days
if (days >= 1)
+ {
values.Add(CreateValueString(days, "day"));
+ }
+
// Number of hours
if (span.Hours >= 1)
+ {
values.Add(CreateValueString(span.Hours, "hour"));
+ }
// Number of minutes
if (span.Minutes >= 1)
+ {
values.Add(CreateValueString(span.Minutes, "minute"));
+ }
+
// Number of seconds (include when 0 if no other components included)
if (span.Seconds >= 1 || values.Count == 0)
+ {
values.Add(CreateValueString(span.Seconds, "second"));
+ }
// Combine values into string
var builder = new StringBuilder();
for (int i = 0; i < values.Count; i++)
{
if (builder.Length > 0)
+ {
builder.Append(i == values.Count - 1 ? " and " : ", ");
+ }
+
builder.Append(values[i]);
}
// Return result
diff --git a/Emby.Server.Implementations/Activity/ActivityManager.cs b/Emby.Server.Implementations/Activity/ActivityManager.cs
index 6febcc2f7..0c513ea12 100644
--- a/Emby.Server.Implementations/Activity/ActivityManager.cs
+++ b/Emby.Server.Implementations/Activity/ActivityManager.cs
@@ -39,8 +39,13 @@ namespace Emby.Server.Implementations.Activity
{
var result = _repo.GetActivityLogEntries(minDate, hasUserId, startIndex, limit);
- foreach (var item in result.Items.Where(i => !i.UserId.Equals(Guid.Empty)))
+ foreach (var item in result.Items)
{
+ if (item.UserId == Guid.Empty)
+ {
+ continue;
+ }
+
var user = _userManager.GetUserById(item.UserId);
if (user != null)
diff --git a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs
index f26cc4f62..00cfa0c9a 100644
--- a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs
+++ b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs
@@ -17,12 +17,14 @@ namespace Emby.Server.Implementations.AppBase
string programDataPath,
string logDirectoryPath,
string configurationDirectoryPath,
- string cacheDirectoryPath)
+ string cacheDirectoryPath,
+ string webDirectoryPath)
{
ProgramDataPath = programDataPath;
LogDirectoryPath = logDirectoryPath;
ConfigurationDirectoryPath = configurationDirectoryPath;
CachePath = cacheDirectoryPath;
+ WebPath = webDirectoryPath;
DataPath = Path.Combine(ProgramDataPath, "data");
}
@@ -34,6 +36,12 @@ namespace Emby.Server.Implementations.AppBase
public string ProgramDataPath { get; private set; }
/// <summary>
+ /// Gets the path to the web UI resources folder
+ /// </summary>
+ /// <value>The web UI resources path.</value>
+ public string WebPath { get; set; }
+
+ /// <summary>
/// Gets the path to the system folder
/// </summary>
public string ProgramSystemPath { get; } = AppContext.BaseDirectory;
@@ -73,12 +81,6 @@ namespace Emby.Server.Implementations.AppBase
public string PluginConfigurationsPath => Path.Combine(PluginsPath, "configurations");
/// <summary>
- /// Gets the path to where temporary update files will be stored
- /// </summary>
- /// <value>The plugin configurations path.</value>
- public string TempUpdatePath => Path.Combine(ProgramDataPath, "updates");
-
- /// <summary>
/// Gets the path to the log directory
/// </summary>
/// <value>The log directory path.</value>
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 1b88fae0e..1c9a4776a 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -28,7 +28,6 @@ using Emby.Server.Implementations.Data;
using Emby.Server.Implementations.Devices;
using Emby.Server.Implementations.Diagnostics;
using Emby.Server.Implementations.Dto;
-using Emby.Server.Implementations.FFMpeg;
using Emby.Server.Implementations.HttpServer;
using Emby.Server.Implementations.HttpServer.Security;
using Emby.Server.Implementations.IO;
@@ -37,14 +36,13 @@ using Emby.Server.Implementations.LiveTv;
using Emby.Server.Implementations.Localization;
using Emby.Server.Implementations.Net;
using Emby.Server.Implementations.Playlists;
-using Emby.Server.Implementations.Reflection;
using Emby.Server.Implementations.ScheduledTasks;
using Emby.Server.Implementations.Security;
using Emby.Server.Implementations.Serialization;
using Emby.Server.Implementations.Session;
+using Emby.Server.Implementations.SocketSharp;
using Emby.Server.Implementations.TV;
using Emby.Server.Implementations.Updates;
-using Emby.Server.Implementations.Xml;
using MediaBrowser.Api;
using MediaBrowser.Common;
using MediaBrowser.Common.Configuration;
@@ -92,23 +90,27 @@ using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Net;
-using MediaBrowser.Model.Reflection;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Tasks;
using MediaBrowser.Model.Updates;
-using MediaBrowser.Model.Xml;
using MediaBrowser.Providers.Chapters;
using MediaBrowser.Providers.Manager;
using MediaBrowser.Providers.Subtitles;
+using MediaBrowser.Providers.TV.TheTVDB;
using MediaBrowser.WebDashboard.Api;
using MediaBrowser.XbmcMetadata.Providers;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
using ServiceStack;
-using X509Certificate = System.Security.Cryptography.X509Certificates.X509Certificate;
+using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace Emby.Server.Implementations
{
@@ -123,12 +125,6 @@ namespace Emby.Server.Implementations
/// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value>
public abstract bool CanSelfRestart { get; }
- /// <summary>
- /// Gets or sets a value indicating whether this instance can self update.
- /// </summary>
- /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
- public virtual bool CanSelfUpdate => false;
-
public virtual bool CanLaunchWebBrowser
{
get
@@ -143,12 +139,8 @@ namespace Emby.Server.Implementations
return false;
}
- if (EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows)
- {
- return true;
- }
-
- if (EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.OSX)
+ if (OperatingSystem.Id == OperatingSystemId.Windows
+ || OperatingSystem.Id == OperatingSystemId.Darwin)
{
return true;
}
@@ -168,7 +160,7 @@ namespace Emby.Server.Implementations
public event EventHandler<GenericEventArgs<PackageVersionInfo>> ApplicationUpdated;
/// <summary>
- /// Gets or sets a value indicating whether this instance has changes that require the entire application to restart.
+ /// Gets a value indicating whether this instance has changes that require the entire application to restart.
/// </summary>
/// <value><c>true</c> if this instance has pending application restart; otherwise, <c>false</c>.</value>
public bool HasPendingRestart { get; private set; }
@@ -184,7 +176,7 @@ namespace Emby.Server.Implementations
private IPlugin[] _plugins;
/// <summary>
- /// Gets or sets the plugins.
+ /// Gets the plugins.
/// </summary>
/// <value>The plugins.</value>
public IPlugin[] Plugins
@@ -200,13 +192,13 @@ namespace Emby.Server.Implementations
public ILoggerFactory LoggerFactory { get; protected set; }
/// <summary>
- /// Gets the application paths.
+ /// Gets or sets the application paths.
/// </summary>
/// <value>The application paths.</value>
protected ServerApplicationPaths ApplicationPaths { get; set; }
/// <summary>
- /// Gets all concrete types.
+ /// Gets or sets all concrete types.
/// </summary>
/// <value>All concrete types.</value>
public Type[] AllConcreteTypes { get; protected set; }
@@ -214,7 +206,7 @@ namespace Emby.Server.Implementations
/// <summary>
/// The disposable parts
/// </summary>
- protected readonly List<IDisposable> DisposableParts = new List<IDisposable>();
+ private readonly List<IDisposable> _disposableParts = new List<IDisposable>();
/// <summary>
/// Gets the configuration manager.
@@ -224,16 +216,15 @@ namespace Emby.Server.Implementations
public IFileSystem FileSystemManager { get; set; }
- protected IEnvironmentInfo EnvironmentInfo { get; set; }
-
public PackageVersionClass SystemUpdateLevel
{
get
{
#if BETA
return PackageVersionClass.Beta;
-#endif
+#else
return PackageVersionClass.Release;
+#endif
}
}
@@ -245,15 +236,6 @@ namespace Emby.Server.Implementations
/// <value>The server configuration manager.</value>
public IServerConfigurationManager ServerConfigurationManager => (IServerConfigurationManager)ConfigurationManager;
- /// <summary>
- /// Gets the configuration manager.
- /// </summary>
- /// <returns>IConfigurationManager.</returns>
- protected IConfigurationManager GetConfigurationManager()
- {
- return new ServerConfigurationManager(ApplicationPaths, LoggerFactory, XmlSerializer, FileSystemManager);
- }
-
protected virtual IResourceFileManager CreateResourceFileManager()
{
return new ResourceFileManager(HttpResultFactory, LoggerFactory, FileSystemManager);
@@ -264,27 +246,33 @@ namespace Emby.Server.Implementations
/// </summary>
/// <value>The user manager.</value>
public IUserManager UserManager { get; set; }
+
/// <summary>
/// Gets or sets the library manager.
/// </summary>
/// <value>The library manager.</value>
internal ILibraryManager LibraryManager { get; set; }
+
/// <summary>
/// Gets or sets the directory watchers.
/// </summary>
/// <value>The directory watchers.</value>
private ILibraryMonitor LibraryMonitor { get; set; }
+
/// <summary>
/// Gets or sets the provider manager.
/// </summary>
/// <value>The provider manager.</value>
private IProviderManager ProviderManager { get; set; }
+
/// <summary>
/// Gets or sets the HTTP server.
/// </summary>
/// <value>The HTTP server.</value>
private IHttpServer HttpServer { get; set; }
+
private IDtoService DtoService { get; set; }
+
public IImageProcessor ImageProcessor { get; set; }
/// <summary>
@@ -292,6 +280,7 @@ namespace Emby.Server.Implementations
/// </summary>
/// <value>The media encoder.</value>
private IMediaEncoder MediaEncoder { get; set; }
+
private ISubtitleEncoder SubtitleEncoder { get; set; }
private ISessionManager SessionManager { get; set; }
@@ -301,6 +290,7 @@ namespace Emby.Server.Implementations
public LocalizationManager LocalizationManager { get; set; }
private IEncodingManager EncodingManager { get; set; }
+
private IChannelManager ChannelManager { get; set; }
/// <summary>
@@ -308,20 +298,29 @@ namespace Emby.Server.Implementations
/// </summary>
/// <value>The user data repository.</value>
private IUserDataManager UserDataManager { get; set; }
+
private IUserRepository UserRepository { get; set; }
+
internal SqliteItemRepository ItemRepository { get; set; }
private INotificationManager NotificationManager { get; set; }
+
private ISubtitleManager SubtitleManager { get; set; }
+
private IChapterManager ChapterManager { get; set; }
+
private IDeviceManager DeviceManager { get; set; }
internal IUserViewManager UserViewManager { get; set; }
private IAuthenticationRepository AuthenticationRepository { get; set; }
+
private ITVSeriesManager TVSeriesManager { get; set; }
+
private ICollectionManager CollectionManager { get; set; }
+
private IMediaSourceManager MediaSourceManager { get; set; }
+
private IPlaylistManager PlaylistManager { get; set; }
private readonly IConfiguration _configuration;
@@ -337,52 +336,55 @@ namespace Emby.Server.Implementations
/// </summary>
/// <value>The zip client.</value>
protected IZipClient ZipClient { get; private set; }
+
protected IHttpResultFactory HttpResultFactory { get; private set; }
+
protected IAuthService AuthService { get; private set; }
- public IStartupOptions StartupOptions { get; private set; }
+ public IStartupOptions StartupOptions { get; }
internal IImageEncoder ImageEncoder { get; private set; }
protected IProcessFactory ProcessFactory { get; private set; }
- protected ICryptoProvider CryptographyProvider = new CryptographyProvider();
+
protected readonly IXmlSerializer XmlSerializer;
protected ISocketFactory SocketFactory { get; private set; }
+
protected ITaskManager TaskManager { get; private set; }
+
public IHttpClient HttpClient { get; private set; }
+
protected INetworkManager NetworkManager { get; set; }
+
public IJsonSerializer JsonSerializer { get; private set; }
+
protected IIsoManager IsoManager { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="ApplicationHost" /> class.
/// </summary>
- public ApplicationHost(ServerApplicationPaths applicationPaths,
+ public ApplicationHost(
+ ServerApplicationPaths applicationPaths,
ILoggerFactory loggerFactory,
IStartupOptions options,
IFileSystem fileSystem,
- IEnvironmentInfo environmentInfo,
IImageEncoder imageEncoder,
INetworkManager networkManager,
IConfiguration configuration)
{
_configuration = configuration;
- // hack alert, until common can target .net core
- BaseExtensions.CryptographyProvider = CryptographyProvider;
-
XmlSerializer = new MyXmlSerializer(fileSystem, loggerFactory);
NetworkManager = networkManager;
networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets;
- EnvironmentInfo = environmentInfo;
ApplicationPaths = applicationPaths;
LoggerFactory = loggerFactory;
FileSystemManager = fileSystem;
- ConfigurationManager = GetConfigurationManager();
+ ConfigurationManager = new ServerConfigurationManager(ApplicationPaths, LoggerFactory, XmlSerializer, FileSystemManager);
Logger = LoggerFactory.CreateLogger("App");
@@ -421,7 +423,7 @@ namespace Emby.Server.Implementations
_validAddressResults.Clear();
}
- public string ApplicationVersion => typeof(ApplicationHost).Assembly.GetName().Version.ToString(3);
+ public string ApplicationVersion { get; } = typeof(ApplicationHost).Assembly.GetName().Version.ToString(3);
/// <summary>
/// Gets the current application user agent
@@ -429,14 +431,23 @@ namespace Emby.Server.Implementations
/// <value>The application user agent.</value>
public string ApplicationUserAgent => Name.Replace(' ','-') + "/" + ApplicationVersion;
+ /// <summary>
+ /// Gets the email address for use within a comment section of a user agent field.
+ /// Presently used to provide contact information to MusicBrainz service.
+ /// </summary>
+ public string ApplicationUserAgentAddress { get; } = "team@jellyfin.org";
+
private string _productName;
+
/// <summary>
/// Gets the current application name
/// </summary>
/// <value>The application name.</value>
- public string ApplicationProductName => _productName ?? (_productName = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).ProductName);
+ public string ApplicationProductName
+ => _productName ?? (_productName = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).ProductName);
private DeviceId _deviceId;
+
public string SystemId
{
get
@@ -467,15 +478,15 @@ namespace Emby.Server.Implementations
/// <summary>
/// Creates an instance of type and resolves all constructor dependencies
/// </summary>
- /// <param name="type">The type.</param>
- /// <returns>System.Object.</returns>
+ /// /// <typeparam name="T">The type</typeparam>
+ /// <returns>T</returns>
public T CreateInstance<T>()
=> ActivatorUtilities.CreateInstance<T>(_serviceProvider);
/// <summary>
/// Creates the instance safe.
/// </summary>
- /// <param name="typeInfo">The type information.</param>
+ /// <param name="type">The type.</param>
/// <returns>System.Object.</returns>
protected object CreateInstanceSafe(Type type)
{
@@ -494,14 +505,14 @@ namespace Emby.Server.Implementations
/// <summary>
/// Resolves this instance.
/// </summary>
- /// <typeparam name="T"></typeparam>
+ /// <typeparam name="T">The type</typeparam>
/// <returns>``0.</returns>
public T Resolve<T>() => _serviceProvider.GetService<T>();
/// <summary>
/// Gets the export types.
/// </summary>
- /// <typeparam name="T"></typeparam>
+ /// <typeparam name="T">The type</typeparam>
/// <returns>IEnumerable{Type}.</returns>
public IEnumerable<Type> GetExportTypes<T>()
{
@@ -513,22 +524,22 @@ namespace Emby.Server.Implementations
/// <summary>
/// Gets the exports.
/// </summary>
- /// <typeparam name="T"></typeparam>
+ /// <typeparam name="T">The type</typeparam>
/// <param name="manageLifetime">if set to <c>true</c> [manage lifetime].</param>
/// <returns>IEnumerable{``0}.</returns>
public IEnumerable<T> GetExports<T>(bool manageLifetime = true)
{
var parts = GetExportTypes<T>()
- .Select(x => CreateInstanceSafe(x))
+ .Select(CreateInstanceSafe)
.Where(i => i != null)
.Cast<T>()
.ToList(); // Convert to list so this isn't executed for each iteration
if (manageLifetime)
{
- lock (DisposableParts)
+ lock (_disposableParts)
{
- DisposableParts.AddRange(parts.OfType<IDisposable>());
+ _disposableParts.AddRange(parts.OfType<IDisposable>());
}
}
@@ -538,7 +549,7 @@ namespace Emby.Server.Implementations
/// <summary>
/// Runs the startup tasks.
/// </summary>
- public async Task RunStartupTasks()
+ public async Task RunStartupTasksAsync()
{
Logger.LogInformation("Running startup tasks");
@@ -546,31 +557,24 @@ namespace Emby.Server.Implementations
ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated;
- MediaEncoder.Init();
-
- //if (string.IsNullOrWhiteSpace(MediaEncoder.EncoderPath))
- //{
- // if (ServerConfigurationManager.Configuration.IsStartupWizardCompleted)
- // {
- // ServerConfigurationManager.Configuration.IsStartupWizardCompleted = false;
- // ServerConfigurationManager.SaveConfiguration();
- // }
- //}
+ MediaEncoder.SetFFmpegPath();
Logger.LogInformation("ServerId: {0}", SystemId);
- var entryPoints = GetExports<IServerEntryPoint>();
+ var entryPoints = GetExports<IServerEntryPoint>().ToList();
- var now = DateTime.UtcNow;
- await Task.WhenAll(StartEntryPoints(entryPoints, true));
- Logger.LogInformation("Executed all pre-startup entry points in {Elapsed:fff} ms", DateTime.Now - now);
+ var stopWatch = new Stopwatch();
+ stopWatch.Start();
+ await Task.WhenAll(StartEntryPoints(entryPoints, true)).ConfigureAwait(false);
+ Logger.LogInformation("Executed all pre-startup entry points in {Elapsed:g}", stopWatch.Elapsed);
Logger.LogInformation("Core startup complete");
HttpServer.GlobalResponse = null;
- now = DateTime.UtcNow;
- await Task.WhenAll(StartEntryPoints(entryPoints, false));
- Logger.LogInformation("Executed all post-startup entry points in {Elapsed:fff} ms", DateTime.Now - now);
+ stopWatch.Restart();
+ await Task.WhenAll(StartEntryPoints(entryPoints, false)).ConfigureAwait(false);
+ Logger.LogInformation("Executed all post-startup entry points in {Elapsed:g}", stopWatch.Elapsed);
+ stopWatch.Stop();
}
private IEnumerable<Task> StartEntryPoints(IEnumerable<IServerEntryPoint> entryPoints, bool isBeforeStartup)
@@ -588,7 +592,7 @@ namespace Emby.Server.Implementations
}
}
- public async Task Init(IServiceCollection serviceCollection)
+ public async Task InitAsync(IServiceCollection serviceCollection)
{
HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber;
HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber;
@@ -618,9 +622,71 @@ namespace Emby.Server.Implementations
SetHttpLimit();
- await RegisterResources(serviceCollection);
+ await RegisterResources(serviceCollection).ConfigureAwait(false);
FindParts();
+
+ string contentRoot = ServerConfigurationManager.Configuration.DashboardSourcePath;
+ if (string.IsNullOrEmpty(contentRoot))
+ {
+ contentRoot = ServerConfigurationManager.ApplicationPaths.WebPath;
+ }
+
+ var host = new WebHostBuilder()
+ .UseKestrel(options =>
+ {
+ options.ListenAnyIP(HttpPort);
+
+ if (EnableHttps && Certificate != null)
+ {
+ options.ListenAnyIP(HttpsPort, listenOptions => { listenOptions.UseHttps(Certificate); });
+ }
+ })
+ .UseContentRoot(contentRoot)
+ .ConfigureServices(services =>
+ {
+ services.AddResponseCompression();
+ services.AddHttpContextAccessor();
+ })
+ .Configure(app =>
+ {
+ app.UseWebSockets();
+
+ app.UseResponseCompression();
+ // TODO app.UseMiddleware<WebSocketMiddleware>();
+ app.Use(ExecuteWebsocketHandlerAsync);
+ app.Use(ExecuteHttpHandlerAsync);
+ })
+ .Build();
+
+ await host.StartAsync().ConfigureAwait(false);
+ }
+
+ private async Task ExecuteWebsocketHandlerAsync(HttpContext context, Func<Task> next)
+ {
+ if (!context.WebSockets.IsWebSocketRequest)
+ {
+ await next().ConfigureAwait(false);
+ return;
+ }
+
+ await HttpServer.ProcessWebSocketRequest(context).ConfigureAwait(false);
+ }
+
+ private async Task ExecuteHttpHandlerAsync(HttpContext context, Func<Task> next)
+ {
+ if (context.WebSockets.IsWebSocketRequest)
+ {
+ await next().ConfigureAwait(false);
+ return;
+ }
+
+ var request = context.Request;
+ var response = context.Response;
+ var localPath = context.Request.Path.ToString();
+
+ var req = new WebSocketSharpRequest(request, response, request.Path, Logger);
+ await HttpServer.RequestHandler(req, request.GetDisplayUrl(), request.Host.ToString(), localPath, CancellationToken.None).ConfigureAwait(false);
}
protected virtual IHttpClient CreateHttpClient()
@@ -635,11 +701,14 @@ namespace Emby.Server.Implementations
/// </summary>
protected async Task RegisterResources(IServiceCollection serviceCollection)
{
+ serviceCollection.AddMemoryCache();
+
serviceCollection.AddSingleton(ConfigurationManager);
serviceCollection.AddSingleton<IApplicationHost>(this);
serviceCollection.AddSingleton<IApplicationPaths>(ApplicationPaths);
+ serviceCollection.AddSingleton<IConfiguration>(_configuration);
serviceCollection.AddSingleton(JsonSerializer);
@@ -647,9 +716,8 @@ namespace Emby.Server.Implementations
serviceCollection.AddLogging();
serviceCollection.AddSingleton(Logger);
- serviceCollection.AddSingleton(EnvironmentInfo);
-
serviceCollection.AddSingleton(FileSystemManager);
+ serviceCollection.AddSingleton<TvDbClientManager>();
HttpClient = CreateHttpClient();
serviceCollection.AddSingleton(HttpClient);
@@ -670,18 +738,17 @@ namespace Emby.Server.Implementations
ApplicationHost.StreamHelper = new StreamHelper();
serviceCollection.AddSingleton(StreamHelper);
- serviceCollection.AddSingleton(CryptographyProvider);
+ serviceCollection.AddSingleton(typeof(ICryptoProvider), typeof(CryptographyProvider));
SocketFactory = new SocketFactory();
serviceCollection.AddSingleton(SocketFactory);
- InstallationManager = new InstallationManager(LoggerFactory, this, ApplicationPaths, HttpClient, JsonSerializer, ServerConfigurationManager, FileSystemManager, CryptographyProvider, ZipClient, PackageRuntime);
- serviceCollection.AddSingleton(InstallationManager);
+ serviceCollection.AddSingleton(typeof(IInstallationManager), typeof(InstallationManager));
ZipClient = new ZipClient();
serviceCollection.AddSingleton(ZipClient);
- HttpResultFactory = new HttpResultFactory(LoggerFactory, FileSystemManager, JsonSerializer, CreateBrotliCompressor());
+ HttpResultFactory = new HttpResultFactory(LoggerFactory, FileSystemManager, JsonSerializer, StreamHelper);
serviceCollection.AddSingleton(HttpResultFactory);
serviceCollection.AddSingleton<IServerApplicationHost>(this);
@@ -689,17 +756,12 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton(ServerConfigurationManager);
- var assemblyInfo = new AssemblyInfo();
- serviceCollection.AddSingleton<IAssemblyInfo>(assemblyInfo);
-
- LocalizationManager = new LocalizationManager(ServerConfigurationManager, FileSystemManager, JsonSerializer, LoggerFactory);
- await LocalizationManager.LoadAll();
+ LocalizationManager = new LocalizationManager(ServerConfigurationManager, JsonSerializer, LoggerFactory);
+ await LocalizationManager.LoadAll().ConfigureAwait(false);
serviceCollection.AddSingleton<ILocalizationManager>(LocalizationManager);
serviceCollection.AddSingleton<IBlurayExaminer>(new BdInfoExaminer(FileSystemManager));
- serviceCollection.AddSingleton<IXmlReaderSettingsFactory>(new XmlReaderSettingsFactory());
-
UserDataManager = new UserDataManager(LoggerFactory, ServerConfigurationManager, () => UserManager);
serviceCollection.AddSingleton(UserDataManager);
@@ -710,7 +772,7 @@ namespace Emby.Server.Implementations
var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LoggerFactory, JsonSerializer, ApplicationPaths, FileSystemManager);
serviceCollection.AddSingleton<IDisplayPreferencesRepository>(displayPreferencesRepo);
- ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LoggerFactory, assemblyInfo);
+ ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, JsonSerializer, LoggerFactory, LocalizationManager);
serviceCollection.AddSingleton<IItemRepository>(ItemRepository);
AuthenticationRepository = GetAuthenticationRepository();
@@ -726,7 +788,7 @@ namespace Emby.Server.Implementations
var musicManager = new MusicManager(LibraryManager);
serviceCollection.AddSingleton<IMusicManager>(new MusicManager(LibraryManager));
- LibraryMonitor = new LibraryMonitor(LoggerFactory, LibraryManager, ServerConfigurationManager, FileSystemManager, EnvironmentInfo);
+ LibraryMonitor = new LibraryMonitor(LoggerFactory, LibraryManager, ServerConfigurationManager, FileSystemManager);
serviceCollection.AddSingleton(LibraryMonitor);
serviceCollection.AddSingleton<ISearchEngine>(new SearchEngine(LoggerFactory, LibraryManager, UserManager));
@@ -734,15 +796,19 @@ namespace Emby.Server.Implementations
CertificateInfo = GetCertificateInfo(true);
Certificate = GetCertificate(CertificateInfo);
- HttpServer = new HttpListenerHost(this,
+ HttpServer = new HttpListenerHost(
+ this,
LoggerFactory,
ServerConfigurationManager,
_configuration,
NetworkManager,
JsonSerializer,
- XmlSerializer);
+ XmlSerializer,
+ CreateHttpListener())
+ {
+ GlobalResponse = LocalizationManager.GetLocalizedString("StartupEmbyServerIsLoading")
+ };
- HttpServer.GlobalResponse = LocalizationManager.GetLocalizedString("StartupEmbyServerIsLoading");
serviceCollection.AddSingleton(HttpServer);
ImageProcessor = GetImageProcessor();
@@ -751,10 +817,8 @@ namespace Emby.Server.Implementations
TVSeriesManager = new TVSeriesManager(UserManager, UserDataManager, LibraryManager, ServerConfigurationManager);
serviceCollection.AddSingleton(TVSeriesManager);
- var encryptionManager = new EncryptionManager();
- serviceCollection.AddSingleton<IEncryptionManager>(encryptionManager);
-
DeviceManager = new DeviceManager(AuthenticationRepository, JsonSerializer, LibraryManager, LocalizationManager, UserManager, FileSystemManager, LibraryMonitor, ServerConfigurationManager);
+
serviceCollection.AddSingleton(DeviceManager);
MediaSourceManager = new MediaSourceManager(ItemRepository, ApplicationPaths, LocalizationManager, UserManager, LibraryManager, LoggerFactory, JsonSerializer, FileSystemManager, UserDataManager, () => MediaEncoder);
@@ -776,7 +840,7 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton(SessionManager);
serviceCollection.AddSingleton<IDlnaManager>(
- new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, LoggerFactory, JsonSerializer, this, assemblyInfo));
+ new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, LoggerFactory, JsonSerializer, this));
CollectionManager = new CollectionManager(LibraryManager, ApplicationPaths, LocalizationManager, FileSystemManager, LibraryMonitor, LoggerFactory, ProviderManager);
serviceCollection.AddSingleton(CollectionManager);
@@ -799,7 +863,18 @@ namespace Emby.Server.Implementations
ChapterManager = new ChapterManager(LibraryManager, LoggerFactory, ServerConfigurationManager, ItemRepository);
serviceCollection.AddSingleton(ChapterManager);
- RegisterMediaEncoder(serviceCollection);
+ MediaEncoder = new MediaBrowser.MediaEncoding.Encoder.MediaEncoder(
+ LoggerFactory,
+ JsonSerializer,
+ StartupOptions.FFmpegPath,
+ ServerConfigurationManager,
+ FileSystemManager,
+ () => SubtitleEncoder,
+ () => MediaSourceManager,
+ ProcessFactory,
+ 5000,
+ LocalizationManager);
+ serviceCollection.AddSingleton(MediaEncoder);
EncodingManager = new MediaEncoder.EncodingManager(FileSystemManager, LoggerFactory, MediaEncoder, ChapterManager, LibraryManager);
serviceCollection.AddSingleton(EncodingManager);
@@ -835,14 +910,7 @@ namespace Emby.Server.Implementations
_serviceProvider = serviceCollection.BuildServiceProvider();
}
- protected virtual IBrotliCompressor CreateBrotliCompressor()
- {
- return null;
- }
-
- public virtual string PackageRuntime => "netcore";
-
- public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths, EnvironmentInfo.EnvironmentInfo environmentInfo)
+ public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths)
{
// Distinct these to prevent users from reporting problems that aren't actually problems
var commandLineArgs = Environment
@@ -850,12 +918,14 @@ namespace Emby.Server.Implementations
.Distinct();
logger.LogInformation("Arguments: {Args}", commandLineArgs);
- logger.LogInformation("Operating system: {OS} {OSVersion}", environmentInfo.OperatingSystemName, environmentInfo.OperatingSystemVersion);
- logger.LogInformation("Architecture: {Architecture}", environmentInfo.SystemArchitecture);
+ // FIXME: @bond this logs the kernel version, not the OS version
+ logger.LogInformation("Operating system: {OS} {OSVersion}", OperatingSystem.Name, Environment.OSVersion.Version);
+ logger.LogInformation("Architecture: {Architecture}", RuntimeInformation.OSArchitecture);
logger.LogInformation("64-Bit Process: {Is64Bit}", Environment.Is64BitProcess);
logger.LogInformation("User Interactive: {IsUserInteractive}", Environment.UserInteractive);
logger.LogInformation("Processor count: {ProcessorCount}", Environment.ProcessorCount);
logger.LogInformation("Program data path: {ProgramDataPath}", appPaths.ProgramDataPath);
+ logger.LogInformation("Web resources path: {WebPath}", appPaths.WebPath);
logger.LogInformation("Application directory: {ApplicationPath}", appPaths.ProgramSystemPath);
}
@@ -872,11 +942,9 @@ namespace Emby.Server.Implementations
}
}
- protected virtual bool SupportsDualModeSockets => true;
-
- private X509Certificate GetCertificate(CertificateInfo info)
+ private X509Certificate2 GetCertificate(CertificateInfo info)
{
- var certificateLocation = info == null ? null : info.Path;
+ var certificateLocation = info?.Path;
if (string.IsNullOrWhiteSpace(certificateLocation))
{
@@ -894,7 +962,7 @@ namespace Emby.Server.Implementations
var password = string.IsNullOrWhiteSpace(info.Password) ? null : info.Password;
var localCert = new X509Certificate2(certificateLocation, password);
- //localCert.PrivateKey = PrivateKey.CreateFromFile(pvk_file).RSA;
+ // localCert.PrivateKey = PrivateKey.CreateFromFile(pvk_file).RSA;
if (!localCert.HasPrivateKey)
{
Logger.LogError("No private key included in SSL cert {CertificateLocation}.", certificateLocation);
@@ -915,85 +983,6 @@ namespace Emby.Server.Implementations
return new ImageProcessor(LoggerFactory, ServerConfigurationManager.ApplicationPaths, FileSystemManager, ImageEncoder, () => LibraryManager, () => MediaEncoder);
}
- protected virtual FFMpegInstallInfo GetFfmpegInstallInfo()
- {
- var info = new FFMpegInstallInfo();
-
- // Windows builds: http://ffmpeg.zeranoe.com/builds/
- // Linux builds: http://johnvansickle.com/ffmpeg/
- // OS X builds: http://ffmpegmac.net/
- // OS X x64: http://www.evermeet.cx/ffmpeg/
-
- if (EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Linux)
- {
- info.FFMpegFilename = "ffmpeg";
- info.FFProbeFilename = "ffprobe";
- info.ArchiveType = "7z";
- info.Version = "20170308";
- }
- else if (EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows)
- {
- info.FFMpegFilename = "ffmpeg.exe";
- info.FFProbeFilename = "ffprobe.exe";
- info.Version = "20170308";
- info.ArchiveType = "7z";
- }
- else if (EnvironmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.OSX)
- {
- info.FFMpegFilename = "ffmpeg";
- info.FFProbeFilename = "ffprobe";
- info.ArchiveType = "7z";
- info.Version = "20170308";
- }
-
- return info;
- }
-
- protected virtual FFMpegInfo GetFFMpegInfo()
- {
- return new FFMpegLoader(ApplicationPaths, FileSystemManager, GetFfmpegInstallInfo())
- .GetFFMpegInfo(StartupOptions);
- }
-
- /// <summary>
- /// Registers the media encoder.
- /// </summary>
- /// <returns>Task.</returns>
- private void RegisterMediaEncoder(IServiceCollection serviceCollection)
- {
- string encoderPath = null;
- string probePath = null;
-
- var info = GetFFMpegInfo();
-
- encoderPath = info.EncoderPath;
- probePath = info.ProbePath;
- var hasExternalEncoder = string.Equals(info.Version, "external", StringComparison.OrdinalIgnoreCase);
-
- var mediaEncoder = new MediaBrowser.MediaEncoding.Encoder.MediaEncoder(
- LoggerFactory,
- JsonSerializer,
- encoderPath,
- probePath,
- hasExternalEncoder,
- ServerConfigurationManager,
- FileSystemManager,
- LiveTvManager,
- IsoManager,
- LibraryManager,
- ChannelManager,
- SessionManager,
- () => SubtitleEncoder,
- () => MediaSourceManager,
- HttpClient,
- ZipClient,
- ProcessFactory,
- 5000);
-
- MediaEncoder = mediaEncoder;
- serviceCollection.AddSingleton(MediaEncoder);
- }
-
/// <summary>
/// Gets the user repository.
/// </summary>
@@ -1030,7 +1019,7 @@ namespace Emby.Server.Implementations
/// </summary>
private void SetStaticProperties()
{
- ((SqliteItemRepository)ItemRepository).ImageProcessor = ImageProcessor;
+ ItemRepository.ImageProcessor = ImageProcessor;
// For now there's no real way to inject these properly
BaseItem.Logger = LoggerFactory.CreateLogger("BaseItem");
@@ -1095,6 +1084,8 @@ namespace Emby.Server.Implementations
/// </summary>
protected void FindParts()
{
+ InstallationManager = _serviceProvider.GetService<IInstallationManager>();
+
if (!ServerConfigurationManager.Configuration.IsPortAuthorized)
{
ServerConfigurationManager.Configuration.IsPortAuthorized = true;
@@ -1107,17 +1098,17 @@ namespace Emby.Server.Implementations
.Where(i => i != null)
.ToArray();
- HttpServer.Init(GetExports<IService>(false), GetExports<IWebSocketListener>());
-
- StartServer();
+ HttpServer.Init(GetExports<IService>(false), GetExports<IWebSocketListener>(), GetUrlPrefixes());
- LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(),
+ LibraryManager.AddParts(
+ GetExports<IResolverIgnoreRule>(),
GetExports<IItemResolver>(),
GetExports<IIntroProvider>(),
GetExports<IBaseItemComparer>(),
GetExports<ILibraryPostScanTask>());
- ProviderManager.AddParts(GetExports<IImageProvider>(),
+ ProviderManager.AddParts(
+ GetExports<IImageProvider>(),
GetExports<IMetadataService>(),
GetExports<IMetadataProvider>(),
GetExports<IMetadataSaver>(),
@@ -1193,15 +1184,13 @@ namespace Emby.Server.Implementations
AllConcreteTypes = GetComposablePartAssemblies()
.SelectMany(x => x.ExportedTypes)
- .Where(type =>
- {
- return type.IsClass && !type.IsAbstract && !type.IsInterface && !type.IsGenericType;
- })
+ .Where(type => type.IsClass && !type.IsAbstract && !type.IsInterface && !type.IsGenericType)
.ToArray();
}
private CertificateInfo CertificateInfo { get; set; }
- protected X509Certificate Certificate { get; private set; }
+
+ protected X509Certificate2 Certificate { get; private set; }
private IEnumerable<string> GetUrlPrefixes()
{
@@ -1211,7 +1200,7 @@ namespace Emby.Server.Implementations
{
var prefixes = new List<string>
{
- "http://"+i+":" + HttpPort + "/"
+ "http://" + i + ":" + HttpPort + "/"
};
if (CertificateInfo != null)
@@ -1223,45 +1212,7 @@ namespace Emby.Server.Implementations
});
}
- protected abstract IHttpListener CreateHttpListener();
-
- /// <summary>
- /// Starts the server.
- /// </summary>
- private void StartServer()
- {
- try
- {
- ((HttpListenerHost)HttpServer).StartServer(GetUrlPrefixes().ToArray(), CreateHttpListener());
- return;
- }
- catch (Exception ex)
- {
- var msg = string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase)
- ? "The http server is unable to start due to a Socket error. This can occasionally happen when the operating system takes longer than usual to release the IP bindings from the previous session. This can take up to five minutes. Please try waiting or rebooting the system."
- : "Error starting Http Server";
-
- Logger.LogError(ex, msg);
-
- if (HttpPort == ServerConfiguration.DefaultHttpPort)
- {
- throw;
- }
- }
-
- HttpPort = ServerConfiguration.DefaultHttpPort;
-
- try
- {
- ((HttpListenerHost)HttpServer).StartServer(GetUrlPrefixes().ToArray(), CreateHttpListener());
- }
- catch (Exception ex)
- {
- Logger.LogError(ex, "Error starting http server");
-
- throw;
- }
- }
+ protected IHttpListener CreateHttpListener() => new WebSocketSharpListener(Logger);
private CertificateInfo GetCertificateInfo(bool generateCertificate)
{
@@ -1278,30 +1229,12 @@ namespace Emby.Server.Implementations
// Generate self-signed cert
var certHost = GetHostnameFromExternalDns(ServerConfigurationManager.Configuration.WanDdns);
var certPath = Path.Combine(ServerConfigurationManager.ApplicationPaths.ProgramDataPath, "ssl", "cert_" + (certHost + "2").GetMD5().ToString("N") + ".pfx");
- var password = "embycert";
-
- //if (generateCertificate)
- //{
- // if (!File.Exists(certPath))
- // {
- // FileSystemManager.CreateDirectory(FileSystemManager.GetDirectoryName(certPath));
-
- // try
- // {
- // CertificateGenerator.CreateSelfSignCertificatePfx(certPath, certHost, password, Logger);
- // }
- // catch (Exception ex)
- // {
- // Logger.LogError(ex, "Error creating ssl cert");
- // return null;
- // }
- // }
- //}
+ const string Password = "embycert";
return new CertificateInfo
{
Path = certPath,
- Password = password
+ Password = Password
};
}
@@ -1336,9 +1269,9 @@ namespace Emby.Server.Implementations
requiresRestart = true;
}
- var currentCertPath = CertificateInfo == null ? null : CertificateInfo.Path;
+ var currentCertPath = CertificateInfo?.Path;
var newCertInfo = GetCertificateInfo(false);
- var newCertPath = newCertInfo == null ? null : newCertInfo.Path;
+ var newCertPath = newCertInfo?.Path;
if (!string.Equals(currentCertPath, newCertPath, StringComparison.OrdinalIgnoreCase))
{
@@ -1471,11 +1404,22 @@ namespace Emby.Server.Implementations
/// <summary>
/// Gets the system status.
/// </summary>
+ /// <param name="cancellationToken">The cancellation token</param>
/// <returns>SystemInfo.</returns>
public async Task<SystemInfo> GetSystemInfo(CancellationToken cancellationToken)
{
var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false);
- var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false);
+
+ string wanAddress;
+
+ if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns))
+ {
+ wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false);
+ }
+ else
+ {
+ wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns);
+ }
return new SystemInfo
{
@@ -1487,6 +1431,7 @@ namespace Emby.Server.Implementations
CompletedInstallations = InstallationManager.CompletedInstallations.ToArray(),
Id = SystemId,
ProgramDataPath = ApplicationPaths.ProgramDataPath,
+ WebPath = ApplicationPaths.WebPath,
LogPath = ApplicationPaths.LogDirectoryPath,
ItemsByNamePath = ApplicationPaths.InternalMetadataPath,
InternalMetadataPath = ApplicationPaths.InternalMetadataPath,
@@ -1494,10 +1439,9 @@ namespace Emby.Server.Implementations
HttpServerPortNumber = HttpPort,
SupportsHttps = SupportsHttps,
HttpsPortNumber = HttpsPort,
- OperatingSystem = EnvironmentInfo.OperatingSystem.ToString(),
- OperatingSystemDisplayName = EnvironmentInfo.OperatingSystemName,
+ OperatingSystem = OperatingSystem.Id.ToString(),
+ OperatingSystemDisplayName = OperatingSystem.Name,
CanSelfRestart = CanSelfRestart,
- CanSelfUpdate = CanSelfUpdate,
CanLaunchWebBrowser = CanLaunchWebBrowser,
WanAddress = wanAddress,
HasUpdateAvailable = HasUpdateAvailable,
@@ -1505,8 +1449,8 @@ namespace Emby.Server.Implementations
ServerName = FriendlyName,
LocalAddress = localAddress,
SupportsLibraryMonitor = true,
- EncoderLocationType = MediaEncoder.EncoderLocationType,
- SystemArchitecture = EnvironmentInfo.SystemArchitecture,
+ EncoderLocation = MediaEncoder.EncoderLocation,
+ SystemArchitecture = RuntimeInformation.OSArchitecture,
SystemUpdateLevel = SystemUpdateLevel,
PackageName = StartupOptions.PackageName
};
@@ -1524,13 +1468,23 @@ namespace Emby.Server.Implementations
public async Task<PublicSystemInfo> GetPublicSystemInfo(CancellationToken cancellationToken)
{
- var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false);
- var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false);
+ var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false);
+
+ string wanAddress;
+
+ if (string.IsNullOrEmpty(ServerConfigurationManager.Configuration.WanDdns))
+ {
+ wanAddress = await GetWanApiUrlFromExternal(cancellationToken).ConfigureAwait(false);
+ }
+ else
+ {
+ wanAddress = GetWanApiUrl(ServerConfigurationManager.Configuration.WanDdns);
+ }
return new PublicSystemInfo
{
Version = ApplicationVersion,
Id = SystemId,
- OperatingSystem = EnvironmentInfo.OperatingSystem.ToString(),
+ OperatingSystem = OperatingSystem.Id.ToString(),
WanAddress = wanAddress,
ServerName = FriendlyName,
LocalAddress = localAddress
@@ -1563,23 +1517,23 @@ namespace Emby.Server.Implementations
return null;
}
- public async Task<string> GetWanApiUrl(CancellationToken cancellationToken)
+ public async Task<string> GetWanApiUrlFromExternal(CancellationToken cancellationToken)
{
- const string url = "http://ipv4.icanhazip.com";
+ const string Url = "http://ipv4.icanhazip.com";
try
{
using (var response = await HttpClient.Get(new HttpRequestOptions
{
- Url = url,
+ Url = Url,
LogErrorResponseBody = false,
LogErrors = false,
LogRequest = false,
TimeoutMs = 10000,
BufferContent = false,
CancellationToken = cancellationToken
- }))
+ }).ConfigureAwait(false))
{
- return GetLocalApiUrl(response.ReadToEnd().Trim());
+ return GetWanApiUrl(response.ReadToEnd().Trim());
}
}
catch (Exception ex)
@@ -1601,11 +1555,40 @@ namespace Emby.Server.Implementations
public string GetLocalApiUrl(string host)
{
+ if (EnableHttps)
+ {
+ return string.Format("https://{0}:{1}",
+ host,
+ HttpsPort.ToString(CultureInfo.InvariantCulture));
+ }
return string.Format("http://{0}:{1}",
- host,
- HttpPort.ToString(CultureInfo.InvariantCulture));
+ host,
+ HttpPort.ToString(CultureInfo.InvariantCulture));
+ }
+
+ public string GetWanApiUrl(IpAddressInfo ipAddress)
+ {
+ if (ipAddress.AddressFamily == IpAddressFamily.InterNetworkV6)
+ {
+ return GetWanApiUrl("[" + ipAddress.Address + "]");
+ }
+
+ return GetWanApiUrl(ipAddress.Address);
}
+ public string GetWanApiUrl(string host)
+ {
+ if (EnableHttps)
+ {
+ return string.Format("https://{0}:{1}",
+ host,
+ ServerConfigurationManager.Configuration.PublicHttpsPort.ToString(CultureInfo.InvariantCulture));
+ }
+ return string.Format("http://{0}:{1}",
+ host,
+ ServerConfigurationManager.Configuration.PublicPort.ToString(CultureInfo.InvariantCulture));
+ }
+
public Task<List<IpAddressInfo>> GetLocalIpAddresses(CancellationToken cancellationToken)
{
return GetLocalIpAddressesInternal(true, 0, cancellationToken);
@@ -1622,7 +1605,7 @@ namespace Emby.Server.Implementations
if (addresses.Count == 0)
{
- addresses.AddRange(NetworkManager.GetLocalIpAddresses());
+ addresses.AddRange(NetworkManager.GetLocalIpAddresses(ServerConfigurationManager.Configuration.IgnoreVirtualInterfaces));
}
var resultList = new List<IpAddressInfo>();
@@ -1665,10 +1648,12 @@ namespace Emby.Server.Implementations
{
return result;
}
+
return null;
}
private readonly ConcurrentDictionary<string, bool> _validAddressResults = new ConcurrentDictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
+
private async Task<bool> IsIpAddressValidAsync(IpAddressInfo address, CancellationToken cancellationToken)
{
if (address.Equals(IpAddressInfo.Loopback) ||
@@ -1685,26 +1670,26 @@ namespace Emby.Server.Implementations
return cachedResult;
}
- var logPing = false;
-
#if DEBUG
- logPing = true;
+ const bool LogPing = true;
+#else
+ const bool LogPing = false;
#endif
try
{
- using (var response = await HttpClient.SendAsync(new HttpRequestOptions
- {
- Url = apiUrl,
- LogErrorResponseBody = false,
- LogErrors = logPing,
- LogRequest = logPing,
- TimeoutMs = 30000,
- BufferContent = false,
-
- CancellationToken = cancellationToken
-
- }, "POST").ConfigureAwait(false))
+ using (var response = await HttpClient.SendAsync(
+ new HttpRequestOptions
+ {
+ Url = apiUrl,
+ LogErrorResponseBody = false,
+ LogErrors = LogPing,
+ LogRequest = LogPing,
+ TimeoutMs = 5000,
+ BufferContent = false,
+
+ CancellationToken = cancellationToken
+ }, "POST").ConfigureAwait(false))
{
using (var reader = new StreamReader(response.Content))
{
@@ -1769,6 +1754,7 @@ namespace Emby.Server.Implementations
public event EventHandler HasUpdateAvailableChanged;
private bool _hasUpdateAvailable;
+
public bool HasUpdateAvailable
{
get => _hasUpdateAvailable;
@@ -1797,21 +1783,6 @@ namespace Emby.Server.Implementations
}
/// <summary>
- /// Updates the application.
- /// </summary>
- /// <param name="package">The package that contains the update</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <param name="progress">The progress.</param>
- public async Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress)
- {
- await InstallationManager.InstallPackage(package, false, progress, cancellationToken).ConfigureAwait(false);
-
- HasUpdateAvailable = false;
-
- OnApplicationUpdated(package);
- }
-
- /// <summary>
/// This returns localhost in the case of no external dns, and the hostname if the
/// dns is prefixed with a valid Uri prefix.
/// </summary>
@@ -1844,7 +1815,7 @@ namespace Emby.Server.Implementations
var process = ProcessFactory.Create(new ProcessOptions
{
FileName = url,
- //EnableRaisingEvents = true,
+ EnableRaisingEvents = true,
UseShellExecute = true,
ErrorDialog = false
});
@@ -1879,26 +1850,25 @@ namespace Emby.Server.Implementations
{
Logger.LogInformation("Application has been updated to version {0}", package.versionStr);
- ApplicationUpdated?.Invoke(this, new GenericEventArgs<PackageVersionInfo>
- {
- Argument = package
- });
+ ApplicationUpdated?.Invoke(
+ this,
+ new GenericEventArgs<PackageVersionInfo>()
+ {
+ Argument = package
+ });
NotifyPendingRestart();
}
- private bool _disposed;
+ private bool _disposed = false;
+
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
- if (!_disposed)
- {
- _disposed = true;
-
- Dispose(true);
- }
+ Dispose(true);
+ GC.SuppressFinalize(this);
}
/// <summary>
@@ -1907,14 +1877,19 @@ namespace Emby.Server.Implementations
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool dispose)
{
+ if (_disposed)
+ {
+ return;
+ }
+
if (dispose)
{
var type = GetType();
Logger.LogInformation("Disposing {Type}", type.Name);
- var parts = DisposableParts.Distinct().Where(i => i.GetType() != type).ToList();
- DisposableParts.Clear();
+ var parts = _disposableParts.Distinct().Where(i => i.GetType() != type).ToList();
+ _disposableParts.Clear();
foreach (var part in parts)
{
@@ -1930,6 +1905,8 @@ namespace Emby.Server.Implementations
}
}
}
+
+ _disposed = true;
}
}
diff --git a/Emby.Server.Implementations/Channels/ChannelManager.cs b/Emby.Server.Implementations/Channels/ChannelManager.cs
index 949b89226..7e50650d7 100644
--- a/Emby.Server.Implementations/Channels/ChannelManager.cs
+++ b/Emby.Server.Implementations/Channels/ChannelManager.cs
@@ -243,8 +243,7 @@ namespace Emby.Server.Implementations.Channels
{
foreach (var item in returnItems)
{
- var task = RefreshLatestChannelItems(GetChannelProvider(item), CancellationToken.None);
- Task.WaitAll(task);
+ RefreshLatestChannelItems(GetChannelProvider(item), CancellationToken.None).GetAwaiter().GetResult();
}
}
@@ -303,9 +302,7 @@ namespace Emby.Server.Implementations.Channels
}
numComplete++;
- double percent = numComplete;
- percent /= allChannelsList.Count;
-
+ double percent = (double)numComplete / allChannelsList.Count;
progress.Report(100 * percent);
}
@@ -658,9 +655,7 @@ namespace Emby.Server.Implementations.Channels
foreach (var item in result.Items)
{
- var folder = item as Folder;
-
- if (folder != null)
+ if (item is Folder folder)
{
await GetChannelItemsInternal(new InternalItemsQuery
{
diff --git a/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs b/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs
index ad6c537ef..3c7cbb115 100644
--- a/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs
+++ b/Emby.Server.Implementations/Channels/ChannelPostScanTask.cs
@@ -35,64 +35,52 @@ namespace Emby.Server.Implementations.Channels
public static string GetUserDistinctValue(User user)
{
var channels = user.Policy.EnabledChannels
- .OrderBy(i => i)
- .ToList();
+ .OrderBy(i => i);
- return string.Join("|", channels.ToArray());
+ return string.Join("|", channels);
}
private void CleanDatabase(CancellationToken cancellationToken)
{
var installedChannelIds = ((ChannelManager)_channelManager).GetInstalledChannelIds();
- var databaseIds = _libraryManager.GetItemIds(new InternalItemsQuery
+ var uninstalledChannels = _libraryManager.GetItemList(new InternalItemsQuery
{
- IncludeItemTypes = new[] { typeof(Channel).Name }
+ IncludeItemTypes = new[] { typeof(Channel).Name },
+ ExcludeItemIds = installedChannelIds.ToArray()
});
- var invalidIds = databaseIds
- .Except(installedChannelIds)
- .ToList();
-
- foreach (var id in invalidIds)
+ foreach (var channel in uninstalledChannels)
{
cancellationToken.ThrowIfCancellationRequested();
- CleanChannel(id, cancellationToken);
+ CleanChannel((Channel)channel, cancellationToken);
}
}
- private void CleanChannel(Guid id, CancellationToken cancellationToken)
+ private void CleanChannel(Channel channel, CancellationToken cancellationToken)
{
- _logger.LogInformation("Cleaning channel {0} from database", id);
+ _logger.LogInformation("Cleaning channel {0} from database", channel.Id);
// Delete all channel items
- var allIds = _libraryManager.GetItemIds(new InternalItemsQuery
+ var items = _libraryManager.GetItemList(new InternalItemsQuery
{
- ChannelIds = new[] { id }
+ ChannelIds = new[] { channel.Id }
});
- foreach (var deleteId in allIds)
+ foreach (var item in items)
{
cancellationToken.ThrowIfCancellationRequested();
- DeleteItem(deleteId);
- }
-
- // Finally, delete the channel itself
- DeleteItem(id);
- }
+ _libraryManager.DeleteItem(item, new DeleteOptions
+ {
+ DeleteFileLocation = false
- private void DeleteItem(Guid id)
- {
- var item = _libraryManager.GetItemById(id);
-
- if (item == null)
- {
- return;
+ }, false);
}
- _libraryManager.DeleteItem(item, new DeleteOptions
+ // Finally, delete the channel itself
+ _libraryManager.DeleteItem(channel, new DeleteOptions
{
DeleteFileLocation = false
diff --git a/Emby.Server.Implementations/Collections/CollectionImageProvider.cs b/Emby.Server.Implementations/Collections/CollectionImageProvider.cs
index cdfb5cadf..0244c4a68 100644
--- a/Emby.Server.Implementations/Collections/CollectionImageProvider.cs
+++ b/Emby.Server.Implementations/Collections/CollectionImageProvider.cs
@@ -36,7 +36,7 @@ namespace Emby.Server.Implementations.Collections
return base.Supports(item);
}
- protected override List<BaseItem> GetItemsWithImages(BaseItem item)
+ protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{
var playlist = (BoxSet)item;
@@ -80,7 +80,7 @@ namespace Emby.Server.Implementations.Collections
.ToList();
}
- protected override string CreateImage(BaseItem item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
+ protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
{
return CreateSingleImage(itemsWithImages, outputPathWithoutExtension, ImageType.Primary);
}
diff --git a/Emby.Server.Implementations/ConfigurationOptions.cs b/Emby.Server.Implementations/ConfigurationOptions.cs
index 30bfd8749..9bc60972a 100644
--- a/Emby.Server.Implementations/ConfigurationOptions.cs
+++ b/Emby.Server.Implementations/ConfigurationOptions.cs
@@ -6,7 +6,8 @@ namespace Emby.Server.Implementations
{
public static readonly Dictionary<string, string> Configuration = new Dictionary<string, string>
{
- {"HttpListenerHost:DefaultRedirectPath", "web/index.html"}
+ {"HttpListenerHost:DefaultRedirectPath", "web/index.html"},
+ {"MusicBrainz:BaseUrl", "https://www.musicbrainz.org"}
};
}
}
diff --git a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs b/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs
index 09fdbc856..6d7193ce2 100644
--- a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs
+++ b/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs
@@ -1,4 +1,6 @@
using System;
+using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Security.Cryptography;
using System.Text;
@@ -8,6 +10,39 @@ namespace Emby.Server.Implementations.Cryptography
{
public class CryptographyProvider : ICryptoProvider
{
+ private static readonly HashSet<string> _supportedHashMethods = new HashSet<string>()
+ {
+ "MD5",
+ "System.Security.Cryptography.MD5",
+ "SHA",
+ "SHA1",
+ "System.Security.Cryptography.SHA1",
+ "SHA256",
+ "SHA-256",
+ "System.Security.Cryptography.SHA256",
+ "SHA384",
+ "SHA-384",
+ "System.Security.Cryptography.SHA384",
+ "SHA512",
+ "SHA-512",
+ "System.Security.Cryptography.SHA512"
+ };
+
+ public string DefaultHashMethod => "PBKDF2";
+
+ private RandomNumberGenerator _randomNumberGenerator;
+
+ private const int _defaultIterations = 1000;
+
+ public CryptographyProvider()
+ {
+ //FIXME: When we get DotNet Standard 2.1 we need to revisit how we do the crypto
+ //Currently supported hash methods from https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.cryptoconfig?view=netcore-2.1
+ //there might be a better way to autogenerate this list as dotnet updates, but I couldn't find one
+ //Please note the default method of PBKDF2 is not included, it cannot be used to generate hashes cleanly as it is actually a pbkdf with sha1
+ _randomNumberGenerator = RandomNumberGenerator.Create();
+ }
+
public Guid GetMD5(string str)
{
return new Guid(ComputeMD5(Encoding.Unicode.GetBytes(str)));
@@ -36,5 +71,98 @@ namespace Emby.Server.Implementations.Cryptography
return provider.ComputeHash(bytes);
}
}
+
+ public IEnumerable<string> GetSupportedHashMethods()
+ {
+ return _supportedHashMethods;
+ }
+
+ private byte[] PBKDF2(string method, byte[] bytes, byte[] salt, int iterations)
+ {
+ //downgrading for now as we need this library to be dotnetstandard compliant
+ //with this downgrade we'll add a check to make sure we're on the downgrade method at the moment
+ if (method == DefaultHashMethod)
+ {
+ using (var r = new Rfc2898DeriveBytes(bytes, salt, iterations))
+ {
+ return r.GetBytes(32);
+ }
+ }
+
+ throw new CryptographicException($"Cannot currently use PBKDF2 with requested hash method: {method}");
+ }
+
+ public byte[] ComputeHash(string hashMethod, byte[] bytes)
+ {
+ return ComputeHash(hashMethod, bytes, Array.Empty<byte>());
+ }
+
+ public byte[] ComputeHashWithDefaultMethod(byte[] bytes)
+ {
+ return ComputeHash(DefaultHashMethod, bytes);
+ }
+
+ public byte[] ComputeHash(string hashMethod, byte[] bytes, byte[] salt)
+ {
+ if (hashMethod == DefaultHashMethod)
+ {
+ return PBKDF2(hashMethod, bytes, salt, _defaultIterations);
+ }
+ else if (_supportedHashMethods.Contains(hashMethod))
+ {
+ using (var h = HashAlgorithm.Create(hashMethod))
+ {
+ if (salt.Length == 0)
+ {
+ return h.ComputeHash(bytes);
+ }
+ else
+ {
+ byte[] salted = new byte[bytes.Length + salt.Length];
+ Array.Copy(bytes, salted, bytes.Length);
+ Array.Copy(salt, 0, salted, bytes.Length, salt.Length);
+ return h.ComputeHash(salted);
+ }
+ }
+ }
+ else
+ {
+ throw new CryptographicException($"Requested hash method is not supported: {hashMethod}");
+ }
+ }
+
+ public byte[] ComputeHashWithDefaultMethod(byte[] bytes, byte[] salt)
+ {
+ return PBKDF2(DefaultHashMethod, bytes, salt, _defaultIterations);
+ }
+
+ public byte[] ComputeHash(PasswordHash hash)
+ {
+ int iterations = _defaultIterations;
+ if (!hash.Parameters.ContainsKey("iterations"))
+ {
+ hash.Parameters.Add("iterations", _defaultIterations.ToString(CultureInfo.InvariantCulture));
+ }
+ else
+ {
+ try
+ {
+ iterations = int.Parse(hash.Parameters["iterations"]);
+ }
+ catch (Exception e)
+ {
+ throw new InvalidDataException($"Couldn't successfully parse iterations value from string: {hash.Parameters["iterations"]}", e);
+ }
+ }
+
+ return PBKDF2(hash.Id, hash.HashBytes, hash.SaltBytes, iterations);
+ }
+
+ public byte[] GenerateSalt()
+ {
+ byte[] salt = new byte[64];
+ _randomNumberGenerator.GetBytes(salt);
+ return salt;
+ }
}
}
diff --git a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs
index 0f432c36c..fba81306b 100644
--- a/Emby.Server.Implementations/Data/BaseSqliteRepository.cs
+++ b/Emby.Server.Implementations/Data/BaseSqliteRepository.cs
@@ -224,7 +224,7 @@ namespace Emby.Server.Implementations.Data
});
}
- db.ExecuteAll(string.Join(";", queries.ToArray()));
+ db.ExecuteAll(string.Join(";", queries));
Logger.LogInformation("PRAGMA synchronous=" + db.Query("PRAGMA synchronous").SelectScalarString().First());
}
@@ -232,23 +232,6 @@ namespace Emby.Server.Implementations.Data
protected virtual int? CacheSize => null;
- internal static void CheckOk(int rc)
- {
- string msg = "";
-
- if (raw.SQLITE_OK != rc)
- {
- throw CreateException((ErrorCode)rc, msg);
- }
- }
-
- internal static Exception CreateException(ErrorCode rc, string msg)
- {
- var exp = new Exception(msg);
-
- return exp;
- }
-
private bool _disposed;
protected void CheckDisposed()
{
@@ -375,13 +358,6 @@ namespace Emby.Server.Implementations.Data
}
}
- public class DummyToken : IDisposable
- {
- public void Dispose()
- {
- }
- }
-
public static IDisposable Read(this ReaderWriterLockSlim obj)
{
//if (BaseSqliteRepository.ThreadSafeMode > 0)
@@ -390,6 +366,7 @@ namespace Emby.Server.Implementations.Data
//}
return new WriteLockToken(obj);
}
+
public static IDisposable Write(this ReaderWriterLockSlim obj)
{
//if (BaseSqliteRepository.ThreadSafeMode > 0)
diff --git a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs
index 3d60925da..47552806d 100644
--- a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs
@@ -90,9 +90,10 @@ namespace Emby.Server.Implementations.Data
{
throw new ArgumentNullException(nameof(displayPreferences));
}
+
if (string.IsNullOrEmpty(displayPreferences.Id))
{
- throw new ArgumentNullException(nameof(displayPreferences.Id));
+ throw new ArgumentException("Display preferences has an invalid Id", nameof(displayPreferences));
}
cancellationToken.ThrowIfCancellationRequested();
diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
index 3014e482d..088a6694b 100644
--- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs
@@ -22,9 +22,9 @@ using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Playlists;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Querying;
-using MediaBrowser.Model.Reflection;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
using SQLitePCL.pretty;
@@ -56,6 +56,8 @@ namespace Emby.Server.Implementations.Data
private readonly IServerConfigurationManager _config;
private IServerApplicationHost _appHost;
+ private readonly ILocalizationManager _localization;
+
public IImageProcessor ImageProcessor { get; set; }
/// <summary>
@@ -66,7 +68,7 @@ namespace Emby.Server.Implementations.Data
IServerApplicationHost appHost,
IJsonSerializer jsonSerializer,
ILoggerFactory loggerFactory,
- IAssemblyInfo assemblyInfo)
+ ILocalizationManager localization)
: base(loggerFactory.CreateLogger(nameof(SqliteItemRepository)))
{
if (config == null)
@@ -82,7 +84,8 @@ namespace Emby.Server.Implementations.Data
_appHost = appHost;
_config = config;
_jsonSerializer = jsonSerializer;
- _typeMapper = new TypeMapper(assemblyInfo);
+ _typeMapper = new TypeMapper();
+ _localization = localization;
DbFilePath = Path.Combine(_config.ApplicationPaths.DataPath, "library.db");
}
@@ -536,7 +539,7 @@ namespace Emby.Server.Implementations.Data
throw new ArgumentNullException(nameof(item));
}
- SaveItems(new List<BaseItem> { item }, cancellationToken);
+ SaveItems(new [] { item }, cancellationToken);
}
public void SaveImages(BaseItem item)
@@ -576,7 +579,7 @@ namespace Emby.Server.Implementations.Data
/// or
/// cancellationToken
/// </exception>
- public void SaveItems(List<BaseItem> items, CancellationToken cancellationToken)
+ public void SaveItems(IEnumerable<BaseItem> items, CancellationToken cancellationToken)
{
if (items == null)
{
@@ -587,7 +590,7 @@ namespace Emby.Server.Implementations.Data
CheckDisposed();
- var tuples = new List<Tuple<BaseItem, List<Guid>, BaseItem, string, List<string>>>();
+ var tuples = new List<(BaseItem, List<Guid>, BaseItem, string, List<string>)>();
foreach (var item in items)
{
var ancestorIds = item.SupportsAncestors ?
@@ -599,7 +602,7 @@ namespace Emby.Server.Implementations.Data
var userdataKey = item.GetUserDataKeys().FirstOrDefault();
var inheritedTags = item.GetInheritedTags();
- tuples.Add(new Tuple<BaseItem, List<Guid>, BaseItem, string, List<string>>(item, ancestorIds, topParent, userdataKey, inheritedTags));
+ tuples.Add((item, ancestorIds, topParent, userdataKey, inheritedTags));
}
using (WriteLock.Write())
@@ -615,7 +618,7 @@ namespace Emby.Server.Implementations.Data
}
}
- private void SaveItemsInTranscation(IDatabaseConnection db, List<Tuple<BaseItem, List<Guid>, BaseItem, string, List<string>>> tuples)
+ private void SaveItemsInTranscation(IDatabaseConnection db, IEnumerable<(BaseItem, List<Guid>, BaseItem, string, List<string>)> tuples)
{
var statements = PrepareAllSafe(db, new string[]
{
@@ -966,7 +969,7 @@ namespace Emby.Server.Implementations.Data
if (item.ExtraIds.Length > 0)
{
- saveItemStatement.TryBind("@ExtraIds", string.Join("|", item.ExtraIds.ToArray()));
+ saveItemStatement.TryBind("@ExtraIds", string.Join("|", item.ExtraIds));
}
else
{
@@ -1183,9 +1186,9 @@ namespace Emby.Server.Implementations.Data
/// <exception cref="ArgumentException"></exception>
public BaseItem RetrieveItem(Guid id)
{
- if (id.Equals(Guid.Empty))
+ if (id == Guid.Empty)
{
- throw new ArgumentNullException(nameof(id));
+ throw new ArgumentException(nameof(id), "Guid can't be empty");
}
CheckDisposed();
@@ -2079,14 +2082,14 @@ namespace Emby.Server.Implementations.Data
return false;
}
- var sortingFields = query.OrderBy.Select(i => i.Item1);
+ var sortingFields = new HashSet<string>(query.OrderBy.Select(i => i.Item1), StringComparer.OrdinalIgnoreCase);
- return sortingFields.Contains(ItemSortBy.IsFavoriteOrLiked, StringComparer.OrdinalIgnoreCase)
- || sortingFields.Contains(ItemSortBy.IsPlayed, StringComparer.OrdinalIgnoreCase)
- || sortingFields.Contains(ItemSortBy.IsUnplayed, StringComparer.OrdinalIgnoreCase)
- || sortingFields.Contains(ItemSortBy.PlayCount, StringComparer.OrdinalIgnoreCase)
- || sortingFields.Contains(ItemSortBy.DatePlayed, StringComparer.OrdinalIgnoreCase)
- || sortingFields.Contains(ItemSortBy.SeriesDatePlayed, StringComparer.OrdinalIgnoreCase)
+ return sortingFields.Contains(ItemSortBy.IsFavoriteOrLiked)
+ || sortingFields.Contains(ItemSortBy.IsPlayed)
+ || sortingFields.Contains(ItemSortBy.IsUnplayed)
+ || sortingFields.Contains(ItemSortBy.PlayCount)
+ || sortingFields.Contains(ItemSortBy.DatePlayed)
+ || sortingFields.Contains(ItemSortBy.SeriesDatePlayed)
|| query.IsFavoriteOrLiked.HasValue
|| query.IsFavorite.HasValue
|| query.IsResumable.HasValue
@@ -2094,9 +2097,9 @@ namespace Emby.Server.Implementations.Data
|| query.IsLiked.HasValue;
}
- private readonly List<ItemFields> allFields = Enum.GetNames(typeof(ItemFields))
+ private readonly ItemFields[] _allFields = Enum.GetNames(typeof(ItemFields))
.Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
- .ToList();
+ .ToArray();
private string[] GetColumnNamesFromField(ItemFields field)
{
@@ -2151,18 +2154,26 @@ namespace Emby.Server.Implementations.Data
}
}
- private bool HasProgramAttributes(InternalItemsQuery query)
+ private static readonly HashSet<string> _programExcludeParentTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
- var excludeParentTypes = new string[]
- {
- "Series",
- "Season",
- "MusicAlbum",
- "MusicArtist",
- "PhotoAlbum"
- };
+ "Series",
+ "Season",
+ "MusicAlbum",
+ "MusicArtist",
+ "PhotoAlbum"
+ };
- if (excludeParentTypes.Contains(query.ParentType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
+ private static readonly HashSet<string> _programTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
+ {
+ "Program",
+ "TvChannel",
+ "LiveTvProgram",
+ "LiveTvTvChannel"
+ };
+
+ private bool HasProgramAttributes(InternalItemsQuery query)
+ {
+ if (_programExcludeParentTypes.Contains(query.ParentType))
{
return false;
}
@@ -2172,29 +2183,18 @@ namespace Emby.Server.Implementations.Data
return true;
}
- var types = new string[]
- {
- "Program",
- "TvChannel",
- "LiveTvProgram",
- "LiveTvTvChannel"
- };
-
- return types.Any(i => query.IncludeItemTypes.Contains(i, StringComparer.OrdinalIgnoreCase));
+ return query.IncludeItemTypes.Any(x => _programTypes.Contains(x));
}
- private bool HasServiceName(InternalItemsQuery query)
+ private static readonly HashSet<string> _serviceTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
- var excludeParentTypes = new string[]
- {
- "Series",
- "Season",
- "MusicAlbum",
- "MusicArtist",
- "PhotoAlbum"
- };
+ "TvChannel",
+ "LiveTvTvChannel"
+ };
- if (excludeParentTypes.Contains(query.ParentType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
+ private bool HasServiceName(InternalItemsQuery query)
+ {
+ if (_programExcludeParentTypes.Contains(query.ParentType))
{
return false;
}
@@ -2204,27 +2204,18 @@ namespace Emby.Server.Implementations.Data
return true;
}
- var types = new string[]
- {
- "TvChannel",
- "LiveTvTvChannel"
- };
-
- return types.Any(i => query.IncludeItemTypes.Contains(i, StringComparer.OrdinalIgnoreCase));
+ return query.IncludeItemTypes.Any(x => _serviceTypes.Contains(x));
}
- private bool HasStartDate(InternalItemsQuery query)
+ private static readonly HashSet<string> _startDateTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
- var excludeParentTypes = new string[]
- {
- "Series",
- "Season",
- "MusicAlbum",
- "MusicArtist",
- "PhotoAlbum"
- };
+ "Program",
+ "LiveTvProgram"
+ };
- if (excludeParentTypes.Contains(query.ParentType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
+ private bool HasStartDate(InternalItemsQuery query)
+ {
+ if (_programExcludeParentTypes.Contains(query.ParentType))
{
return false;
}
@@ -2234,13 +2225,7 @@ namespace Emby.Server.Implementations.Data
return true;
}
- var types = new string[]
- {
- "Program",
- "LiveTvProgram"
- };
-
- return types.Any(i => query.IncludeItemTypes.Contains(i, StringComparer.OrdinalIgnoreCase));
+ return query.IncludeItemTypes.Any(x => _startDateTypes.Contains(x));
}
private bool HasEpisodeAttributes(InternalItemsQuery query)
@@ -2263,16 +2248,26 @@ namespace Emby.Server.Implementations.Data
return query.IncludeItemTypes.Contains("Trailer", StringComparer.OrdinalIgnoreCase);
}
- private bool HasArtistFields(InternalItemsQuery query)
+
+ private static readonly HashSet<string> _artistExcludeParentTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
- var excludeParentTypes = new string[]
- {
- "Series",
- "Season",
- "PhotoAlbum"
- };
+ "Series",
+ "Season",
+ "PhotoAlbum"
+ };
+
+ private static readonly HashSet<string> _artistsTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
+ {
+ "Audio",
+ "MusicAlbum",
+ "MusicVideo",
+ "AudioBook",
+ "AudioPodcast"
+ };
- if (excludeParentTypes.Contains(query.ParentType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
+ private bool HasArtistFields(InternalItemsQuery query)
+ {
+ if (_artistExcludeParentTypes.Contains(query.ParentType))
{
return false;
}
@@ -2282,18 +2277,17 @@ namespace Emby.Server.Implementations.Data
return true;
}
- var types = new string[]
- {
- "Audio",
- "MusicAlbum",
- "MusicVideo",
- "AudioBook",
- "AudioPodcast"
- };
-
- return types.Any(i => query.IncludeItemTypes.Contains(i, StringComparer.OrdinalIgnoreCase));
+ return query.IncludeItemTypes.Any(x => _artistsTypes.Contains(x));
}
+ private static readonly HashSet<string> _seriesTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
+ {
+ "Book",
+ "AudioBook",
+ "Episode",
+ "Season"
+ };
+
private bool HasSeriesFields(InternalItemsQuery query)
{
if (string.Equals(query.ParentType, "PhotoAlbum", StringComparison.OrdinalIgnoreCase))
@@ -2306,26 +2300,18 @@ namespace Emby.Server.Implementations.Data
return true;
}
- var types = new string[]
- {
- "Book",
- "AudioBook",
- "Episode",
- "Season"
- };
-
- return types.Any(i => query.IncludeItemTypes.Contains(i, StringComparer.OrdinalIgnoreCase));
+ return query.IncludeItemTypes.Any(x => _seriesTypes.Contains(x));
}
- private string[] GetFinalColumnsToSelect(InternalItemsQuery query, string[] startColumns)
+ private List<string> GetFinalColumnsToSelect(InternalItemsQuery query, IEnumerable<string> startColumns)
{
var list = startColumns.ToList();
- foreach (var field in allFields)
+ foreach (var field in _allFields)
{
if (!HasField(query, field))
{
- foreach (var fieldToRemove in GetColumnNamesFromField(field).ToList())
+ foreach (var fieldToRemove in GetColumnNamesFromField(field))
{
list.Remove(fieldToRemove);
}
@@ -2419,11 +2405,14 @@ namespace Emby.Server.Implementations.Data
list.Add(builder.ToString());
- var excludeIds = query.ExcludeItemIds.ToList();
- excludeIds.Add(item.Id);
- excludeIds.AddRange(item.ExtraIds);
+ var oldLen = query.ExcludeItemIds.Length;
+ var newLen = oldLen + item.ExtraIds.Length + 1;
+ var excludeIds = new Guid[newLen];
+ query.ExcludeItemIds.CopyTo(excludeIds, 0);
+ excludeIds[oldLen] = item.Id;
+ item.ExtraIds.CopyTo(excludeIds, oldLen + 1);
- query.ExcludeItemIds = excludeIds.ToArray();
+ query.ExcludeItemIds = excludeIds;
query.ExcludeProviderIds = item.ProviderIds;
}
@@ -2444,7 +2433,7 @@ namespace Emby.Server.Implementations.Data
list.Add(builder.ToString());
}
- return list.ToArray();
+ return list;
}
private void BindSearchParams(InternalItemsQuery query, IStatement statement)
@@ -2723,18 +2712,17 @@ namespace Emby.Server.Implementations.Data
private void AddItem(List<BaseItem> items, BaseItem newItem)
{
- var providerIds = newItem.ProviderIds.ToList();
-
for (var i = 0; i < items.Count; i++)
{
var item = items[i];
- foreach (var providerId in providerIds)
+ foreach (var providerId in newItem.ProviderIds)
{
if (providerId.Key == MetadataProviders.TmdbCollection.ToString())
{
continue;
}
+
if (item.GetProviderId(providerId.Key) == providerId.Value)
{
if (newItem.SourceType == SourceType.Library)
@@ -2753,15 +2741,15 @@ namespace Emby.Server.Implementations.Data
{
var elapsed = (DateTime.UtcNow - startDate).TotalMilliseconds;
- int slowThreshold = 1000;
+ int slowThreshold = 100;
#if DEBUG
- slowThreshold = 250;
+ slowThreshold = 10;
#endif
if (elapsed >= slowThreshold)
{
- Logger.LogWarning("{0} query time (slow): {1}ms. Query: {2}",
+ Logger.LogWarning("{0} query time (slow): {1:g}. Query: {2}",
methodName,
elapsed,
commandText);
@@ -2806,7 +2794,7 @@ namespace Emby.Server.Implementations.Data
var whereText = whereClauses.Count == 0 ?
string.Empty :
- " where " + string.Join(" AND ", whereClauses.ToArray());
+ " where " + string.Join(" AND ", whereClauses);
commandText += whereText
+ GetGroupBy(query)
@@ -2930,25 +2918,31 @@ namespace Emby.Server.Implementations.Data
private string GetOrderByText(InternalItemsQuery query)
{
- var orderBy = query.OrderBy.ToList();
- var enableOrderInversion = false;
-
- if (query.SimilarTo != null && orderBy.Count == 0)
+ if (string.IsNullOrEmpty(query.SearchTerm))
{
- orderBy.Add(new ValueTuple<string, SortOrder>("SimilarityScore", SortOrder.Descending));
- orderBy.Add(new ValueTuple<string, SortOrder>(ItemSortBy.Random, SortOrder.Ascending));
- }
+ int oldLen = query.OrderBy.Length;
- if (!string.IsNullOrEmpty(query.SearchTerm))
+ if (query.SimilarTo != null && oldLen == 0)
+ {
+ var arr = new (string, SortOrder)[oldLen + 2];
+ query.OrderBy.CopyTo(arr, 0);
+ arr[oldLen] = ("SimilarityScore", SortOrder.Descending);
+ arr[oldLen + 1] = (ItemSortBy.Random, SortOrder.Ascending);
+ query.OrderBy = arr;
+ }
+ }
+ else
{
- orderBy = new List<(string, SortOrder)>();
- orderBy.Add(new ValueTuple<string, SortOrder>("SearchScore", SortOrder.Descending));
- orderBy.Add(new ValueTuple<string, SortOrder>(ItemSortBy.SortName, SortOrder.Ascending));
+ query.OrderBy = new []
+ {
+ ("SearchScore", SortOrder.Descending),
+ (ItemSortBy.SortName, SortOrder.Ascending)
+ };
}
- query.OrderBy = orderBy.ToArray();
+ var orderBy = query.OrderBy;
- if (orderBy.Count == 0)
+ if (orderBy.Length == 0)
{
return string.Empty;
}
@@ -2957,6 +2951,7 @@ namespace Emby.Server.Implementations.Data
{
var columnMap = MapOrderByField(i.Item1, query);
var columnAscending = i.Item2 == SortOrder.Ascending;
+ const bool enableOrderInversion = false;
if (columnMap.Item2 && enableOrderInversion)
{
columnAscending = !columnAscending;
@@ -2968,7 +2963,7 @@ namespace Emby.Server.Implementations.Data
}));
}
- private ValueTuple<string, bool> MapOrderByField(string name, InternalItemsQuery query)
+ private (string, bool) MapOrderByField(string name, InternalItemsQuery query)
{
if (string.Equals(name, ItemSortBy.AirTime, StringComparison.OrdinalIgnoreCase))
{
@@ -3218,7 +3213,7 @@ namespace Emby.Server.Implementations.Data
var whereText = whereClauses.Count == 0 ?
string.Empty :
- " where " + string.Join(" AND ", whereClauses.ToArray());
+ " where " + string.Join(" AND ", whereClauses);
commandText += whereText
+ GetGroupBy(query)
@@ -4378,7 +4373,7 @@ namespace Emby.Server.Implementations.Data
}
else if (query.Years.Length > 1)
{
- var val = string.Join(",", query.Years.ToArray());
+ var val = string.Join(",", query.Years);
whereClauses.Add("ProductionYear in (" + val + ")");
}
@@ -4952,7 +4947,12 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
return result;
}
- return new[] { value }.Where(IsValidType);
+ if (IsValidType(value))
+ {
+ return new[] { value };
+ }
+
+ return Array.Empty<string>();
}
public void DeleteItem(Guid id, CancellationToken cancellationToken)
@@ -5215,32 +5215,32 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
}
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetAllArtists(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetAllArtists(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 0, 1 }, typeof(MusicArtist).FullName);
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetArtists(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetArtists(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 0 }, typeof(MusicArtist).FullName);
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetAlbumArtists(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetAlbumArtists(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 1 }, typeof(MusicArtist).FullName);
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetStudios(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetStudios(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 3 }, typeof(Studio).FullName);
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetGenres(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetGenres(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 2 }, typeof(Genre).FullName);
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetMusicGenres(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetMusicGenres(InternalItemsQuery query)
{
return GetItemValues(query, new[] { 2 }, typeof(MusicGenre).FullName);
}
@@ -5317,7 +5317,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
}
}
- private QueryResult<Tuple<BaseItem, ItemCounts>> GetItemValues(InternalItemsQuery query, int[] itemValueTypes, string returnType)
+ private QueryResult<(BaseItem, ItemCounts)> GetItemValues(InternalItemsQuery query, int[] itemValueTypes, string returnType)
{
if (query == null)
{
@@ -5335,7 +5335,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
var typeClause = itemValueTypes.Length == 1 ?
("Type=" + itemValueTypes[0].ToString(CultureInfo.InvariantCulture)) :
- ("Type in (" + string.Join(",", itemValueTypes.Select(i => i.ToString(CultureInfo.InvariantCulture)).ToArray()) + ")");
+ ("Type in (" + string.Join(",", itemValueTypes.Select(i => i.ToString(CultureInfo.InvariantCulture))) + ")");
InternalItemsQuery typeSubQuery = null;
@@ -5363,11 +5363,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
whereClauses.Add("guid in (select ItemId from ItemValues where ItemValues.CleanValue=A.CleanName AND " + typeClause + ")");
- var typeWhereText = whereClauses.Count == 0 ?
- string.Empty :
- " where " + string.Join(" AND ", whereClauses);
-
- itemCountColumnQuery += typeWhereText;
+ itemCountColumnQuery += " where " + string.Join(" AND ", whereClauses);
itemCountColumns = new Dictionary<string, string>()
{
@@ -5400,7 +5396,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
IsSeries = query.IsSeries
};
- columns = GetFinalColumnsToSelect(query, columns.ToArray()).ToList();
+ columns = GetFinalColumnsToSelect(query, columns);
var commandText = "select "
+ string.Join(",", columns)
@@ -5492,8 +5488,8 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
{
return connection.RunInTransaction(db =>
{
- var list = new List<Tuple<BaseItem, ItemCounts>>();
- var result = new QueryResult<Tuple<BaseItem, ItemCounts>>();
+ var list = new List<(BaseItem, ItemCounts)>();
+ var result = new QueryResult<(BaseItem, ItemCounts)>();
var statements = PrepareAllSafe(db, statementTexts);
@@ -5531,7 +5527,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
{
var countStartColumn = columns.Count - 1;
- list.Add(new Tuple<BaseItem, ItemCounts>(item, GetItemCounts(row, countStartColumn, typesToCount)));
+ list.Add((item, GetItemCounts(row, countStartColumn, typesToCount)));
}
}
@@ -6196,8 +6192,13 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
item.ColorTransfer = reader[34].ToString();
}
+ if (item.Type == MediaStreamType.Subtitle){
+ item.localizedUndefined = _localization.GetLocalizedString("Undefined");
+ item.localizedDefault = _localization.GetLocalizedString("Default");
+ item.localizedForced = _localization.GetLocalizedString("Forced");
+ }
+
return item;
}
-
}
}
diff --git a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
index 7a9b72244..4109b7ad1 100644
--- a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs
@@ -119,9 +119,9 @@ namespace Emby.Server.Implementations.Data
{
list.Add(row[0].ReadGuidFromBlob());
}
- catch
+ catch (Exception ex)
{
-
+ Logger.LogError(ex, "Error while getting user");
}
}
}
diff --git a/Emby.Server.Implementations/Data/SqliteUserRepository.cs b/Emby.Server.Implementations/Data/SqliteUserRepository.cs
index db359d7dd..182df0edc 100644
--- a/Emby.Server.Implementations/Data/SqliteUserRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteUserRepository.cs
@@ -55,6 +55,8 @@ namespace Emby.Server.Implementations.Data
{
TryMigrateToLocalUsersTable(connection);
}
+
+ RemoveEmptyPasswordHashes();
}
}
@@ -73,6 +75,38 @@ namespace Emby.Server.Implementations.Data
}
}
+ private void RemoveEmptyPasswordHashes()
+ {
+ foreach (var user in RetrieveAllUsers())
+ {
+ // If the user password is the sha1 hash of the empty string, remove it
+ if (!string.Equals(user.Password, "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", StringComparison.Ordinal)
+ || !string.Equals(user.Password, "$SHA1$DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", StringComparison.Ordinal))
+ {
+ continue;
+ }
+
+ user.Password = null;
+ var serialized = _jsonSerializer.SerializeToBytes(user);
+
+ using (WriteLock.Write())
+ using (var connection = CreateConnection())
+ {
+ connection.RunInTransaction(db =>
+ {
+ using (var statement = db.PrepareStatement("update LocalUsersv2 set data=@data where Id=@InternalId"))
+ {
+ statement.TryBind("@InternalId", user.InternalId);
+ statement.TryBind("@data", serialized);
+ statement.MoveNext();
+ }
+
+ }, TransactionMode);
+ }
+ }
+
+ }
+
/// <summary>
/// Save a user in the repo
/// </summary>
diff --git a/Emby.Server.Implementations/Data/TypeMapper.cs b/Emby.Server.Implementations/Data/TypeMapper.cs
index 37c952e88..0e67affbf 100644
--- a/Emby.Server.Implementations/Data/TypeMapper.cs
+++ b/Emby.Server.Implementations/Data/TypeMapper.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Linq;
-using MediaBrowser.Model.Reflection;
namespace Emby.Server.Implementations.Data
{
@@ -10,16 +9,13 @@ namespace Emby.Server.Implementations.Data
/// </summary>
public class TypeMapper
{
- private readonly IAssemblyInfo _assemblyInfo;
-
/// <summary>
/// This holds all the types in the running assemblies so that we can de-serialize properly when we don't have strong types
/// </summary>
private readonly ConcurrentDictionary<string, Type> _typeMap = new ConcurrentDictionary<string, Type>();
- public TypeMapper(IAssemblyInfo assemblyInfo)
+ public TypeMapper()
{
- _assemblyInfo = assemblyInfo;
}
/// <summary>
@@ -45,8 +41,7 @@ namespace Emby.Server.Implementations.Data
/// <returns>Type.</returns>
private Type LookupType(string typeName)
{
- return _assemblyInfo
- .GetCurrentAssemblies()
+ return AppDomain.CurrentDomain.GetAssemblies()
.Select(a => a.GetType(typeName))
.FirstOrDefault(t => t != null);
}
diff --git a/Emby.Server.Implementations/Diagnostics/CommonProcess.cs b/Emby.Server.Implementations/Diagnostics/CommonProcess.cs
index 78b22bda3..175a8f3ce 100644
--- a/Emby.Server.Implementations/Diagnostics/CommonProcess.cs
+++ b/Emby.Server.Implementations/Diagnostics/CommonProcess.cs
@@ -9,14 +9,14 @@ namespace Emby.Server.Implementations.Diagnostics
{
public class CommonProcess : IProcess
{
- public event EventHandler Exited;
-
- private readonly ProcessOptions _options;
private readonly Process _process;
+ private bool _disposed = false;
+ private bool _hasExited;
+
public CommonProcess(ProcessOptions options)
{
- _options = options;
+ StartInfo = options;
var startInfo = new ProcessStartInfo
{
@@ -27,10 +27,10 @@ namespace Emby.Server.Implementations.Diagnostics
CreateNoWindow = options.CreateNoWindow,
RedirectStandardError = options.RedirectStandardError,
RedirectStandardInput = options.RedirectStandardInput,
- RedirectStandardOutput = options.RedirectStandardOutput
+ RedirectStandardOutput = options.RedirectStandardOutput,
+ ErrorDialog = options.ErrorDialog
};
- startInfo.ErrorDialog = options.ErrorDialog;
if (options.IsHidden)
{
@@ -45,11 +45,22 @@ namespace Emby.Server.Implementations.Diagnostics
if (options.EnableRaisingEvents)
{
_process.EnableRaisingEvents = true;
- _process.Exited += _process_Exited;
+ _process.Exited += OnProcessExited;
}
}
- private bool _hasExited;
+ public event EventHandler Exited;
+
+ public ProcessOptions StartInfo { get; }
+
+ public StreamWriter StandardInput => _process.StandardInput;
+
+ public StreamReader StandardError => _process.StandardError;
+
+ public StreamReader StandardOutput => _process.StandardOutput;
+
+ public int ExitCode => _process.ExitCode;
+
private bool HasExited
{
get
@@ -72,25 +83,6 @@ namespace Emby.Server.Implementations.Diagnostics
}
}
- private void _process_Exited(object sender, EventArgs e)
- {
- _hasExited = true;
- if (Exited != null)
- {
- Exited(this, e);
- }
- }
-
- public ProcessOptions StartInfo => _options;
-
- public StreamWriter StandardInput => _process.StandardInput;
-
- public StreamReader StandardError => _process.StandardError;
-
- public StreamReader StandardOutput => _process.StandardOutput;
-
- public int ExitCode => _process.ExitCode;
-
public void Start()
{
_process.Start();
@@ -108,7 +100,7 @@ namespace Emby.Server.Implementations.Diagnostics
public Task<bool> WaitForExitAsync(int timeMs)
{
- //Note: For this function to work correctly, the option EnableRisingEvents needs to be set to true.
+ // Note: For this function to work correctly, the option EnableRisingEvents needs to be set to true.
if (HasExited)
{
@@ -130,7 +122,29 @@ namespace Emby.Server.Implementations.Diagnostics
public void Dispose()
{
- _process.Dispose();
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ if (disposing)
+ {
+ _process?.Dispose();
+ }
+
+ _disposed = true;
+ }
+
+ private void OnProcessExited(object sender, EventArgs e)
+ {
+ _hasExited = true;
+ Exited?.Invoke(this, e);
}
}
}
diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs
index 2233d3d40..7b28a22a8 100644
--- a/Emby.Server.Implementations/Dto/DtoService.cs
+++ b/Emby.Server.Implementations/Dto/DtoService.cs
@@ -5,8 +5,6 @@ using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Common;
using MediaBrowser.Controller.Channels;
-using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
@@ -21,8 +19,6 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Extensions;
-using MediaBrowser.Model.IO;
using MediaBrowser.Model.Querying;
using Microsoft.Extensions.Logging;
@@ -83,15 +79,8 @@ namespace Emby.Server.Implementations.Dto
return GetBaseItemDto(item, options, user, owner);
}
- public BaseItemDto[] GetBaseItemDtos(List<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null)
- {
- return GetBaseItemDtos(items, items.Count, options, user, owner);
- }
-
- public BaseItemDto[] GetBaseItemDtos(BaseItem[] items, DtoOptions options, User user = null, BaseItem owner = null)
- {
- return GetBaseItemDtos(items, items.Length, options, user, owner);
- }
+ public BaseItemDto[] GetBaseItemDtos(IReadOnlyList<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null)
+ => GetBaseItemDtos(items, items.Count, options, user, owner);
public BaseItemDto[] GetBaseItemDtos(IEnumerable<BaseItem> items, int itemCount, DtoOptions options, User user = null, BaseItem owner = null)
{
diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj
index bbf165d62..2c7962452 100644
--- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj
+++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj
@@ -9,12 +9,10 @@
<ProjectReference Include="..\MediaBrowser.Providers\MediaBrowser.Providers.csproj" />
<ProjectReference Include="..\MediaBrowser.WebDashboard\MediaBrowser.WebDashboard.csproj" />
<ProjectReference Include="..\MediaBrowser.XbmcMetadata\MediaBrowser.XbmcMetadata.csproj" />
- <ProjectReference Include="..\SocketHttpListener\SocketHttpListener.csproj" />
<ProjectReference Include="..\Emby.Dlna\Emby.Dlna.csproj" />
<ProjectReference Include="..\Mono.Nat\Mono.Nat.csproj" />
<ProjectReference Include="..\MediaBrowser.Api\MediaBrowser.Api.csproj" />
<ProjectReference Include="..\MediaBrowser.LocalMetadata\MediaBrowser.LocalMetadata.csproj" />
- <ProjectReference Include="..\OpenSubtitlesHandler\OpenSubtitlesHandler.csproj" />
<ProjectReference Include="..\Emby.Photos\Emby.Photos.csproj" />
<ProjectReference Include="..\Emby.Drawing\Emby.Drawing.csproj" />
<ProjectReference Include="..\Emby.XmlTv\Emby.XmlTv\Emby.XmlTv.csproj" />
@@ -22,6 +20,14 @@
</ItemGroup>
<ItemGroup>
+ <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.0" />
+ <PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
+ <PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="2.2.0" />
+ <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
+ <PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
+ <PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" />
+ <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
+ <PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />
@@ -40,6 +46,21 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ </PropertyGroup>
+
+ <!-- Code analysers-->
+ <ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.3" />
+ <PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
+ <PackageReference Include="SerilogAnalyzer" Version="0.15.0" />
+ </ItemGroup>
+
+ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
+ </PropertyGroup>
+
<ItemGroup>
<EmbeddedResource Include="Localization\iso6392.txt" />
<EmbeddedResource Include="Localization\countries.json" />
diff --git a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs
index 038965647..8369f4f59 100644
--- a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs
+++ b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs
@@ -388,7 +388,7 @@ namespace Emby.Server.Implementations.EntryPoints
FoldersRemovedFrom = foldersRemovedFrom.SelectMany(i => TranslatePhysicalItemToUserLibrary(i, user)).Select(i => i.Id.ToString("N")).Distinct().ToArray(),
- CollectionFolders = GetTopParentIds(newAndRemoved, user, allUserRootChildren).ToArray()
+ CollectionFolders = GetTopParentIds(newAndRemoved, allUserRootChildren).ToArray()
};
}
@@ -407,7 +407,7 @@ namespace Emby.Server.Implementations.EntryPoints
return item.SourceType == SourceType.Library;
}
- private IEnumerable<string> GetTopParentIds(List<BaseItem> items, User user, List<Folder> allUserRootChildren)
+ private IEnumerable<string> GetTopParentIds(List<BaseItem> items, List<Folder> allUserRootChildren)
{
var list = new List<string>();
diff --git a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs
deleted file mode 100644
index c8104150d..000000000
--- a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-using MediaBrowser.Model.System;
-
-namespace Emby.Server.Implementations.EnvironmentInfo
-{
- public class EnvironmentInfo : IEnvironmentInfo
- {
- public EnvironmentInfo(MediaBrowser.Model.System.OperatingSystem operatingSystem)
- {
- OperatingSystem = operatingSystem;
- }
-
- public MediaBrowser.Model.System.OperatingSystem OperatingSystem { get; private set; }
-
- public string OperatingSystemName
- {
- get
- {
- switch (OperatingSystem)
- {
- case MediaBrowser.Model.System.OperatingSystem.Android: return "Android";
- case MediaBrowser.Model.System.OperatingSystem.BSD: return "BSD";
- case MediaBrowser.Model.System.OperatingSystem.Linux: return "Linux";
- case MediaBrowser.Model.System.OperatingSystem.OSX: return "macOS";
- case MediaBrowser.Model.System.OperatingSystem.Windows: return "Windows";
- default: throw new Exception($"Unknown OS {OperatingSystem}");
- }
- }
- }
-
- public string OperatingSystemVersion => Environment.OSVersion.Version.ToString() + " " + Environment.OSVersion.ServicePack.ToString();
-
- public Architecture SystemArchitecture => RuntimeInformation.OSArchitecture;
- }
-}
diff --git a/Emby.Server.Implementations/FFMpeg/FFMpegInfo.cs b/Emby.Server.Implementations/FFMpeg/FFMpegInfo.cs
deleted file mode 100644
index 60cd7b3d7..000000000
--- a/Emby.Server.Implementations/FFMpeg/FFMpegInfo.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-namespace Emby.Server.Implementations.FFMpeg
-{
- /// <summary>
- /// Class FFMpegInfo
- /// </summary>
- public class FFMpegInfo
- {
- /// <summary>
- /// Gets or sets the path.
- /// </summary>
- /// <value>The path.</value>
- public string EncoderPath { get; set; }
- /// <summary>
- /// Gets or sets the probe path.
- /// </summary>
- /// <value>The probe path.</value>
- public string ProbePath { get; set; }
- /// <summary>
- /// Gets or sets the version.
- /// </summary>
- /// <value>The version.</value>
- public string Version { get; set; }
- }
-}
diff --git a/Emby.Server.Implementations/FFMpeg/FFMpegInstallInfo.cs b/Emby.Server.Implementations/FFMpeg/FFMpegInstallInfo.cs
deleted file mode 100644
index fa9cb5e01..000000000
--- a/Emby.Server.Implementations/FFMpeg/FFMpegInstallInfo.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace Emby.Server.Implementations.FFMpeg
-{
- public class FFMpegInstallInfo
- {
- public string Version { get; set; }
- public string FFMpegFilename { get; set; }
- public string FFProbeFilename { get; set; }
- public string ArchiveType { get; set; }
-
- public FFMpegInstallInfo()
- {
- Version = "Path";
- FFMpegFilename = "ffmpeg";
- FFProbeFilename = "ffprobe";
- }
- }
-}
diff --git a/Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs b/Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs
deleted file mode 100644
index bbf51dd24..000000000
--- a/Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs
+++ /dev/null
@@ -1,132 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using MediaBrowser.Common.Configuration;
-using MediaBrowser.Model.IO;
-
-namespace Emby.Server.Implementations.FFMpeg
-{
- public class FFMpegLoader
- {
- private readonly IApplicationPaths _appPaths;
- private readonly IFileSystem _fileSystem;
- private readonly FFMpegInstallInfo _ffmpegInstallInfo;
-
- public FFMpegLoader(IApplicationPaths appPaths, IFileSystem fileSystem, FFMpegInstallInfo ffmpegInstallInfo)
- {
- _appPaths = appPaths;
- _fileSystem = fileSystem;
- _ffmpegInstallInfo = ffmpegInstallInfo;
- }
-
- public FFMpegInfo GetFFMpegInfo(IStartupOptions options)
- {
- var customffMpegPath = options.FFmpegPath;
- var customffProbePath = options.FFprobePath;
-
- if (!string.IsNullOrWhiteSpace(customffMpegPath) && !string.IsNullOrWhiteSpace(customffProbePath))
- {
- return new FFMpegInfo
- {
- ProbePath = customffProbePath,
- EncoderPath = customffMpegPath,
- Version = "external"
- };
- }
-
- var downloadInfo = _ffmpegInstallInfo;
-
- var prebuiltFolder = _appPaths.ProgramSystemPath;
- var prebuiltffmpeg = Path.Combine(prebuiltFolder, downloadInfo.FFMpegFilename);
- var prebuiltffprobe = Path.Combine(prebuiltFolder, downloadInfo.FFProbeFilename);
- if (File.Exists(prebuiltffmpeg) && File.Exists(prebuiltffprobe))
- {
- return new FFMpegInfo
- {
- ProbePath = prebuiltffprobe,
- EncoderPath = prebuiltffmpeg,
- Version = "external"
- };
- }
-
- var version = downloadInfo.Version;
-
- if (string.Equals(version, "0", StringComparison.OrdinalIgnoreCase))
- {
- return new FFMpegInfo();
- }
-
- var rootEncoderPath = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg");
- var versionedDirectoryPath = Path.Combine(rootEncoderPath, version);
-
- var info = new FFMpegInfo
- {
- ProbePath = Path.Combine(versionedDirectoryPath, downloadInfo.FFProbeFilename),
- EncoderPath = Path.Combine(versionedDirectoryPath, downloadInfo.FFMpegFilename),
- Version = version
- };
-
- Directory.CreateDirectory(versionedDirectoryPath);
-
- var excludeFromDeletions = new List<string> { versionedDirectoryPath };
-
- if (!File.Exists(info.ProbePath) || !File.Exists(info.EncoderPath))
- {
- // ffmpeg not present. See if there's an older version we can start with
- var existingVersion = GetExistingVersion(info, rootEncoderPath);
-
- // No older version. Need to download and block until complete
- if (existingVersion == null)
- {
- return new FFMpegInfo();
- }
- else
- {
- info = existingVersion;
- versionedDirectoryPath = Path.GetDirectoryName(info.EncoderPath);
- excludeFromDeletions.Add(versionedDirectoryPath);
- }
- }
-
- // Allow just one of these to be overridden, if desired.
- if (!string.IsNullOrWhiteSpace(customffMpegPath))
- {
- info.EncoderPath = customffMpegPath;
- }
- if (!string.IsNullOrWhiteSpace(customffProbePath))
- {
- info.ProbePath = customffProbePath;
- }
-
- return info;
- }
-
- private FFMpegInfo GetExistingVersion(FFMpegInfo info, string rootEncoderPath)
- {
- var encoderFilename = Path.GetFileName(info.EncoderPath);
- var probeFilename = Path.GetFileName(info.ProbePath);
-
- foreach (var directory in _fileSystem.GetDirectoryPaths(rootEncoderPath))
- {
- var allFiles = _fileSystem.GetFilePaths(directory, true).ToList();
-
- var encoder = allFiles.FirstOrDefault(i => string.Equals(Path.GetFileName(i), encoderFilename, StringComparison.OrdinalIgnoreCase));
- var probe = allFiles.FirstOrDefault(i => string.Equals(Path.GetFileName(i), probeFilename, StringComparison.OrdinalIgnoreCase));
-
- if (!string.IsNullOrWhiteSpace(encoder) &&
- !string.IsNullOrWhiteSpace(probe))
- {
- return new FFMpegInfo
- {
- EncoderPath = encoder,
- ProbePath = probe,
- Version = Path.GetFileName(Path.GetDirectoryName(probe))
- };
- }
- }
-
- return null;
- }
- }
-}
diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
index 2232b3eeb..1bebdd163 100644
--- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
@@ -15,6 +15,7 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using Microsoft.Extensions.Logging;
+using Microsoft.Net.Http.Headers;
namespace Emby.Server.Implementations.HttpClientManager
{
@@ -179,11 +180,11 @@ namespace Emby.Server.Implementations.HttpClientManager
foreach (var header in options.RequestHeaders)
{
- if (string.Equals(header.Key, "Accept", StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(header.Key, HeaderNames.Accept, StringComparison.OrdinalIgnoreCase))
{
request.Accept = header.Value;
}
- else if (string.Equals(header.Key, "User-Agent", StringComparison.OrdinalIgnoreCase))
+ else if (string.Equals(header.Key, HeaderNames.UserAgent, StringComparison.OrdinalIgnoreCase))
{
SetUserAgent(request, header.Value);
hasUserAgent = true;
@@ -327,7 +328,6 @@ namespace Emby.Server.Implementations.HttpClientManager
}
httpWebRequest.ContentType = contentType;
- httpWebRequest.ContentLength = bytes.Length;
(await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false)).Write(bytes, 0, bytes.Length);
}
catch (Exception ex)
@@ -539,21 +539,10 @@ namespace Emby.Server.Implementations.HttpClientManager
var contentLength = GetContentLength(httpResponse);
- if (contentLength.HasValue)
- {
- using (var fs = _fileSystem.GetFileStream(tempFile, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
- {
- await httpResponse.GetResponseStream().CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
- }
- }
- else
+ using (var stream = httpResponse.GetResponseStream())
+ using (var fs = _fileSystem.GetFileStream(tempFile, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
{
- // We're not able to track progress
- using (var stream = httpResponse.GetResponseStream())
- using (var fs = _fileSystem.GetFileStream(tempFile, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
- {
- await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
- }
+ await stream.CopyToAsync(fs, StreamDefaults.DefaultCopyToBufferSize, options.CancellationToken).ConfigureAwait(false);
}
options.Progress.Report(100);
diff --git a/Emby.Server.Implementations/HttpServer/FileWriter.cs b/Emby.Server.Implementations/HttpServer/FileWriter.cs
index 7aedba9b3..c4d2a70e2 100644
--- a/Emby.Server.Implementations/HttpServer/FileWriter.cs
+++ b/Emby.Server.Implementations/HttpServer/FileWriter.cs
@@ -5,15 +5,19 @@ using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
+using Emby.Server.Implementations.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
+using Microsoft.Net.Http.Headers;
namespace Emby.Server.Implementations.HttpServer
{
public class FileWriter : IHttpResult
{
+ private readonly IStreamHelper _streamHelper;
private ILogger Logger { get; set; }
+ private readonly IFileSystem _fileSystem;
private string RangeHeader { get; set; }
private bool IsHeadRequest { get; set; }
@@ -42,25 +46,27 @@ namespace Emby.Server.Implementations.HttpServer
public string Path { get; set; }
- public FileWriter(string path, string contentType, string rangeHeader, ILogger logger, IFileSystem fileSystem)
+ public FileWriter(string path, string contentType, string rangeHeader, ILogger logger, IFileSystem fileSystem, IStreamHelper streamHelper)
{
if (string.IsNullOrEmpty(contentType))
{
throw new ArgumentNullException(nameof(contentType));
}
+ _streamHelper = streamHelper;
+ _fileSystem = fileSystem;
+
Path = path;
Logger = logger;
RangeHeader = rangeHeader;
- Headers["Content-Type"] = contentType;
+ Headers[HeaderNames.ContentType] = contentType;
TotalContentLength = fileSystem.GetFileInfo(path).Length;
- Headers["Accept-Ranges"] = "bytes";
+ Headers[HeaderNames.AcceptRanges] = "bytes";
if (string.IsNullOrWhiteSpace(rangeHeader))
{
- Headers["Content-Length"] = TotalContentLength.ToString(UsCulture);
StatusCode = HttpStatusCode.OK;
}
else
@@ -93,13 +99,10 @@ namespace Emby.Server.Implementations.HttpServer
RangeStart = requestedRange.Key;
RangeLength = 1 + RangeEnd - RangeStart;
- // Content-Length is the length of what we're serving, not the original content
- var lengthString = RangeLength.ToString(UsCulture);
- Headers["Content-Length"] = lengthString;
- var rangeString = string.Format("bytes {0}-{1}/{2}", RangeStart, RangeEnd, TotalContentLength);
- Headers["Content-Range"] = rangeString;
+ var rangeString = $"bytes {RangeStart}-{RangeEnd}/{TotalContentLength}";
+ Headers[HeaderNames.ContentRange] = rangeString;
- Logger.LogInformation("Setting range response values for {0}. RangeRequest: {1} Content-Length: {2}, Content-Range: {3}", Path, RangeHeader, lengthString, rangeString);
+ Logger.LogInformation("Setting range response values for {0}. RangeRequest: {1} Content-Range: {2}", Path, RangeHeader, rangeString);
}
/// <summary>
@@ -145,8 +148,7 @@ namespace Emby.Server.Implementations.HttpServer
}
}
- private string[] SkipLogExtensions = new string[]
- {
+ private static readonly string[] SkipLogExtensions = {
".js",
".html",
".css"
@@ -163,8 +165,10 @@ namespace Emby.Server.Implementations.HttpServer
}
var path = Path;
+ var offset = RangeStart;
+ var count = RangeLength;
- if (string.IsNullOrWhiteSpace(RangeHeader) || (RangeStart <= 0 && RangeEnd >= TotalContentLength - 1))
+ if (string.IsNullOrWhiteSpace(RangeHeader) || RangeStart <= 0 && RangeEnd >= TotalContentLength - 1)
{
var extension = System.IO.Path.GetExtension(path);
@@ -173,20 +177,15 @@ namespace Emby.Server.Implementations.HttpServer
Logger.LogDebug("Transmit file {0}", path);
}
- //var count = FileShare == FileShareMode.ReadWrite ? TotalContentLength : 0;
-
- await response.TransmitFile(path, 0, 0, FileShare, cancellationToken).ConfigureAwait(false);
- return;
+ offset = 0;
+ count = 0;
}
- await response.TransmitFile(path, RangeStart, RangeLength, FileShare, cancellationToken).ConfigureAwait(false);
+ await response.TransmitFile(path, offset, count, FileShare, _fileSystem, _streamHelper, cancellationToken).ConfigureAwait(false);
}
finally
{
- if (OnComplete != null)
- {
- OnComplete();
- }
+ OnComplete?.Invoke();
}
}
@@ -203,8 +202,5 @@ namespace Emby.Server.Implementations.HttpServer
get => (HttpStatusCode)Status;
set => Status = (int)value;
}
-
- public string StatusDescription { get; set; }
-
}
}
diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
index d78891ac7..e8d47cad5 100644
--- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
+++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
@@ -10,6 +11,7 @@ using System.Threading;
using System.Threading.Tasks;
using Emby.Server.Implementations.Net;
using Emby.Server.Implementations.Services;
+using Emby.Server.Implementations.SocketSharp;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
@@ -19,6 +21,9 @@ using MediaBrowser.Model.Events;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Internal;
+using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using ServiceStack.Text.Jsv;
@@ -28,12 +33,8 @@ namespace Emby.Server.Implementations.HttpServer
public class HttpListenerHost : IHttpServer, IDisposable
{
private string DefaultRedirectPath { get; set; }
-
- private readonly ILogger _logger;
public string[] UrlPrefixes { get; private set; }
- private IHttpListener _listener;
-
public event EventHandler<GenericEventArgs<IWebSocketConnection>> WebSocketConnected;
private readonly IServerConfigurationManager _config;
@@ -41,6 +42,7 @@ namespace Emby.Server.Implementations.HttpServer
private readonly IServerApplicationHost _appHost;
private readonly IJsonSerializer _jsonSerializer;
private readonly IXmlSerializer _xmlSerializer;
+ private readonly IHttpListener _socketListener;
private readonly Func<Type, Func<string, object>> _funcParseFn;
public Action<IRequest, IResponse, object>[] ResponseFilters { get; set; }
@@ -58,16 +60,19 @@ namespace Emby.Server.Implementations.HttpServer
IConfiguration configuration,
INetworkManager networkManager,
IJsonSerializer jsonSerializer,
- IXmlSerializer xmlSerializer)
+ IXmlSerializer xmlSerializer,
+ IHttpListener socketListener)
{
_appHost = applicationHost;
- _logger = loggerFactory.CreateLogger("HttpServer");
+ Logger = loggerFactory.CreateLogger("HttpServer");
_config = config;
DefaultRedirectPath = configuration["HttpListenerHost:DefaultRedirectPath"];
_networkManager = networkManager;
_jsonSerializer = jsonSerializer;
_xmlSerializer = xmlSerializer;
-
+ _socketListener = socketListener;
+ _socketListener.WebSocketConnected = OnWebSocketConnected;
+
_funcParseFn = t => s => JsvReader.GetParseFn(t)(s);
Instance = this;
@@ -76,7 +81,7 @@ namespace Emby.Server.Implementations.HttpServer
public string GlobalResponse { get; set; }
- protected ILogger Logger => _logger;
+ protected ILogger Logger { get; }
public object CreateInstance(Type type)
{
@@ -142,11 +147,11 @@ namespace Emby.Server.Implementations.HttpServer
return;
}
- var connection = new WebSocketConnection(e.WebSocket, e.Endpoint, _jsonSerializer, _logger)
+ var connection = new WebSocketConnection(e.WebSocket, e.Endpoint, _jsonSerializer, Logger)
{
OnReceive = ProcessWebSocketMessageReceived,
Url = e.Url,
- QueryString = e.QueryString ?? new QueryParamCollection()
+ QueryString = e.QueryString ?? new QueryCollection()
};
connection.Closed += Connection_Closed;
@@ -211,16 +216,16 @@ namespace Emby.Server.Implementations.HttpServer
if (logExceptionStackTrace)
{
- _logger.LogError(ex, "Error processing request");
+ Logger.LogError(ex, "Error processing request");
}
else if (logExceptionMessage)
{
- _logger.LogError(ex.Message);
+ Logger.LogError(ex.Message);
}
var httpRes = httpReq.Response;
- if (httpRes.IsClosed)
+ if (httpRes.OriginalResponse.HasStarted)
{
return;
}
@@ -233,7 +238,7 @@ namespace Emby.Server.Implementations.HttpServer
}
catch (Exception errorEx)
{
- _logger.LogError(errorEx, "Error this.ProcessRequest(context)(Exception while writing error to the response)");
+ Logger.LogError(errorEx, "Error this.ProcessRequest(context)(Exception while writing error to the response)");
}
}
@@ -276,39 +281,6 @@ namespace Emby.Server.Implementations.HttpServer
}
}
-
- if (_listener != null)
- {
- _logger.LogInformation("Stopping HttpListener...");
- var task = _listener.Stop();
- Task.WaitAll(task);
- _logger.LogInformation("HttpListener stopped");
- }
- }
-
- private static readonly string[] _skipLogExtensions =
- {
- ".js",
- ".css",
- ".woff",
- ".woff2",
- ".ttf",
- ".html"
- };
-
- private bool EnableLogging(string url, string localPath)
- {
- var extension = GetExtension(url);
-
- return ((string.IsNullOrEmpty(extension) || !_skipLogExtensions.Contains(extension))
- && (string.IsNullOrEmpty(localPath) || localPath.IndexOf("system/ping", StringComparison.OrdinalIgnoreCase) == -1));
- }
-
- private static string GetExtension(string url)
- {
- var parts = url.Split(new[] { '?' }, 2);
-
- return Path.GetExtension(parts[0]);
}
public static string RemoveQueryStringByKey(string url, string key)
@@ -316,7 +288,7 @@ namespace Emby.Server.Implementations.HttpServer
var uri = new Uri(url);
// this gets all the query string key value pairs as a collection
- var newQueryString = MyHttpUtility.ParseQueryString(uri.Query);
+ var newQueryString = QueryHelpers.ParseQuery(uri.Query);
var originalCount = newQueryString.Count;
@@ -337,7 +309,7 @@ namespace Emby.Server.Implementations.HttpServer
string pagePathWithoutQueryString = url.Split(new[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0];
return newQueryString.Count > 0
- ? string.Format("{0}?{1}", pagePathWithoutQueryString, newQueryString)
+ ? QueryHelpers.AddQueryString(pagePathWithoutQueryString, newQueryString.ToDictionary(kv => kv.Key, kv => kv.Value.ToString()))
: pagePathWithoutQueryString;
}
@@ -446,12 +418,11 @@ namespace Emby.Server.Implementations.HttpServer
/// <summary>
/// Overridable method that can be used to implement a custom hnandler
/// </summary>
- protected async Task RequestHandler(IHttpRequest httpReq, string urlString, string host, string localPath, CancellationToken cancellationToken)
+ public async Task RequestHandler(IHttpRequest httpReq, string urlString, string host, string localPath, CancellationToken cancellationToken)
{
- var date = DateTime.Now;
+ var stopWatch = new Stopwatch();
+ stopWatch.Start();
var httpRes = httpReq.Response;
- bool enableLog = false;
- bool logHeaders = false;
string urlToLog = null;
string remoteIp = httpReq.RemoteIp;
@@ -498,18 +469,8 @@ namespace Emby.Server.Implementations.HttpServer
return;
}
- var operationName = httpReq.OperationName;
-
- enableLog = EnableLogging(urlString, localPath);
- urlToLog = urlString;
- logHeaders = enableLog && urlToLog.IndexOf("/videos/", StringComparison.OrdinalIgnoreCase) != -1;
-
- if (enableLog)
- {
- urlToLog = GetUrlToLog(urlString);
-
- LoggerUtils.LogRequest(_logger, urlToLog, httpReq.HttpMethod, httpReq.UserAgent, logHeaders ? httpReq.Headers : null);
- }
+ urlToLog = GetUrlToLog(urlString);
+ Logger.LogDebug("HTTP {HttpMethod} {Url} UserAgent: {UserAgent} \nHeaders: {@Headers}", urlToLog, httpReq.UserAgent ?? string.Empty, httpReq.HttpMethod, httpReq.Headers);
if (string.Equals(localPath, "/emby/", StringComparison.OrdinalIgnoreCase) ||
string.Equals(localPath, "/mediabrowser/", StringComparison.OrdinalIgnoreCase))
@@ -517,6 +478,7 @@ namespace Emby.Server.Implementations.HttpServer
RedirectToUrl(httpRes, DefaultRedirectPath);
return;
}
+
if (string.Equals(localPath, "/emby", StringComparison.OrdinalIgnoreCase) ||
string.Equals(localPath, "/mediabrowser", StringComparison.OrdinalIgnoreCase))
{
@@ -562,16 +524,19 @@ namespace Emby.Server.Implementations.HttpServer
RedirectToUrl(httpRes, DefaultRedirectPath);
return;
}
+
if (string.Equals(localPath, "/web/", StringComparison.OrdinalIgnoreCase))
{
RedirectToUrl(httpRes, "../" + DefaultRedirectPath);
return;
}
+
if (string.Equals(localPath, "/", StringComparison.OrdinalIgnoreCase))
{
RedirectToUrl(httpRes, DefaultRedirectPath);
return;
}
+
if (string.IsNullOrEmpty(localPath))
{
RedirectToUrl(httpRes, "/" + DefaultRedirectPath);
@@ -607,33 +572,21 @@ namespace Emby.Server.Implementations.HttpServer
if (handler != null)
{
- await handler.ProcessRequestAsync(this, httpReq, httpRes, Logger, operationName, cancellationToken).ConfigureAwait(false);
+ await handler.ProcessRequestAsync(this, httpReq, httpRes, Logger, httpReq.OperationName, cancellationToken).ConfigureAwait(false);
}
else
{
await ErrorHandler(new FileNotFoundException(), httpReq, false, false).ConfigureAwait(false);
}
}
- catch (OperationCanceledException ex)
+ catch (Exception ex) when (ex is SocketException || ex is IOException || ex is OperationCanceledException)
{
await ErrorHandler(ex, httpReq, false, false).ConfigureAwait(false);
}
-
- catch (IOException ex)
- {
- await ErrorHandler(ex, httpReq, false, false).ConfigureAwait(false);
- }
-
- catch (SocketException ex)
- {
- await ErrorHandler(ex, httpReq, false, false).ConfigureAwait(false);
- }
-
catch (SecurityException ex)
{
await ErrorHandler(ex, httpReq, false, true).ConfigureAwait(false);
}
-
catch (Exception ex)
{
var logException = !string.Equals(ex.GetType().Name, "SocketException", StringComparison.OrdinalIgnoreCase);
@@ -642,15 +595,15 @@ namespace Emby.Server.Implementations.HttpServer
}
finally
{
- httpRes.Close();
-
- if (enableLog)
+ stopWatch.Stop();
+ var elapsed = stopWatch.Elapsed;
+ if (elapsed.TotalMilliseconds > 500)
{
- var statusCode = httpRes.StatusCode;
-
- var duration = DateTime.Now - date;
-
- LoggerUtils.LogResponse(_logger, statusCode, urlToLog, remoteIp, duration, logHeaders ? httpRes.Headers : null);
+ Logger.LogWarning("HTTP Response {StatusCode} to {RemoteIp}. Time (slow): {Elapsed:g}. {Url}", httpRes.StatusCode, remoteIp, elapsed, urlToLog);
+ }
+ else
+ {
+ Logger.LogDebug("HTTP Response {StatusCode} to {RemoteIp}. Time: {Elapsed:g}. {Url}", httpRes.StatusCode, remoteIp, elapsed, urlToLog);
}
}
}
@@ -663,12 +616,11 @@ namespace Emby.Server.Implementations.HttpServer
var pathParts = pathInfo.TrimStart('/').Split('/');
if (pathParts.Length == 0)
{
- _logger.LogError("Path parts empty for PathInfo: {pathInfo}, Url: {RawUrl}", pathInfo, httpReq.RawUrl);
+ Logger.LogError("Path parts empty for PathInfo: {PathInfo}, Url: {RawUrl}", pathInfo, httpReq.RawUrl);
return null;
}
var restPath = ServiceHandler.FindMatchingRestPath(httpReq.HttpMethod, pathInfo, out string contentType);
-
if (restPath != null)
{
return new ServiceHandler
@@ -678,15 +630,13 @@ namespace Emby.Server.Implementations.HttpServer
};
}
- _logger.LogError("Could not find handler for {PathInfo}", pathInfo);
+ Logger.LogError("Could not find handler for {PathInfo}", pathInfo);
return null;
}
private static Task Write(IResponse response, string text)
{
var bOutput = Encoding.UTF8.GetBytes(text);
- response.SetContentLength(bOutput.Length);
-
return response.OutputStream.WriteAsync(bOutput, 0, bOutput.Length);
}
@@ -705,6 +655,7 @@ namespace Emby.Server.Implementations.HttpServer
}
else
{
+ // TODO what is this?
var httpsUrl = url
.Replace("http://", "https://", StringComparison.OrdinalIgnoreCase)
.Replace(":" + _config.Configuration.PublicPort.ToString(CultureInfo.InvariantCulture), ":" + _config.Configuration.PublicHttpsPort.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase);
@@ -725,13 +676,15 @@ namespace Emby.Server.Implementations.HttpServer
/// Adds the rest handlers.
/// </summary>
/// <param name="services">The services.</param>
- public void Init(IEnumerable<IService> services, IEnumerable<IWebSocketListener> listeners)
+ /// <param name="listeners"></param>
+ /// <param name="urlPrefixes"></param>
+ public void Init(IEnumerable<IService> services, IEnumerable<IWebSocketListener> listeners, IEnumerable<string> urlPrefixes)
{
_webSocketListeners = listeners.ToArray();
-
+ UrlPrefixes = urlPrefixes.ToArray();
ServiceController = new ServiceController();
- _logger.LogInformation("Calling ServiceStack AppHost.Init");
+ Logger.LogInformation("Calling ServiceStack AppHost.Init");
var types = services.Select(r => r.GetType()).ToArray();
@@ -739,7 +692,7 @@ namespace Emby.Server.Implementations.HttpServer
ResponseFilters = new Action<IRequest, IResponse, object>[]
{
- new ResponseFilter(_logger).FilterResponse
+ new ResponseFilter(Logger).FilterResponse
};
}
@@ -801,8 +754,12 @@ namespace Emby.Server.Implementations.HttpServer
return _jsonSerializer.DeserializeFromStreamAsync(stream, type);
}
- //TODO Add Jellyfin Route Path Normalizer
+ public Task ProcessWebSocketRequest(HttpContext context)
+ {
+ return _socketListener.ProcessWebSocketRequest(context);
+ }
+ //TODO Add Jellyfin Route Path Normalizer
private static string NormalizeEmbyRoutePath(string path)
{
if (path.StartsWith("/", StringComparison.OrdinalIgnoreCase))
@@ -835,6 +792,7 @@ namespace Emby.Server.Implementations.HttpServer
private bool _disposed;
private readonly object _disposeLock = new object();
+
protected virtual void Dispose(bool disposing)
{
if (_disposed) return;
@@ -863,7 +821,7 @@ namespace Emby.Server.Implementations.HttpServer
return Task.CompletedTask;
}
- _logger.LogDebug("Websocket message received: {0}", result.MessageType);
+ Logger.LogDebug("Websocket message received: {0}", result.MessageType);
var tasks = _webSocketListeners.Select(i => Task.Run(async () =>
{
@@ -873,7 +831,7 @@ namespace Emby.Server.Implementations.HttpServer
}
catch (Exception ex)
{
- _logger.LogError(ex, "{0} failed processing WebSocket message {1}", i.GetType().Name, result.MessageType ?? string.Empty);
+ Logger.LogError(ex, "{0} failed processing WebSocket message {1}", i.GetType().Name, result.MessageType ?? string.Empty);
}
}));
@@ -884,18 +842,5 @@ namespace Emby.Server.Implementations.HttpServer
{
Dispose(true);
}
-
- public void StartServer(string[] urlPrefixes, IHttpListener httpListener)
- {
- UrlPrefixes = urlPrefixes;
-
- _listener = httpListener;
-
- _listener.WebSocketConnected = OnWebSocketConnected;
- _listener.ErrorHandler = ErrorHandler;
- _listener.RequestHandler = RequestHandler;
-
- _listener.Start(UrlPrefixes);
- }
}
}
diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
index 75ca57ebb..134f3c841 100644
--- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
+++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
@@ -16,6 +16,8 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Primitives;
+using Microsoft.Net.Http.Headers;
using IRequest = MediaBrowser.Model.Services.IRequest;
using MimeTypes = MediaBrowser.Model.Net.MimeTypes;
@@ -32,17 +34,16 @@ namespace Emby.Server.Implementations.HttpServer
private readonly ILogger _logger;
private readonly IFileSystem _fileSystem;
private readonly IJsonSerializer _jsonSerializer;
-
- private IBrotliCompressor _brotliCompressor;
+ private readonly IStreamHelper _streamHelper;
/// <summary>
/// Initializes a new instance of the <see cref="HttpResultFactory" /> class.
/// </summary>
- public HttpResultFactory(ILoggerFactory loggerfactory, IFileSystem fileSystem, IJsonSerializer jsonSerializer, IBrotliCompressor brotliCompressor)
+ public HttpResultFactory(ILoggerFactory loggerfactory, IFileSystem fileSystem, IJsonSerializer jsonSerializer, IStreamHelper streamHelper)
{
_fileSystem = fileSystem;
_jsonSerializer = jsonSerializer;
- _brotliCompressor = brotliCompressor;
+ _streamHelper = streamHelper;
_logger = loggerfactory.CreateLogger("HttpResultFactory");
}
@@ -76,7 +77,7 @@ namespace Emby.Server.Implementations.HttpServer
public object GetRedirectResult(string url)
{
var responseHeaders = new Dictionary<string, string>();
- responseHeaders["Location"] = url;
+ responseHeaders[HeaderNames.Location] = url;
var result = new HttpResult(Array.Empty<byte>(), "text/plain", HttpStatusCode.Redirect);
@@ -90,16 +91,16 @@ namespace Emby.Server.Implementations.HttpServer
/// </summary>
private IHasHeaders GetHttpResult(IRequest requestContext, Stream content, string contentType, bool addCachePrevention, IDictionary<string, string> responseHeaders = null)
{
- var result = new StreamWriter(content, contentType, _logger);
+ var result = new StreamWriter(content, contentType);
if (responseHeaders == null)
{
responseHeaders = new Dictionary<string, string>();
}
- if (addCachePrevention && !responseHeaders.TryGetValue("Expires", out string expires))
+ if (addCachePrevention && !responseHeaders.TryGetValue(HeaderNames.Expires, out string expires))
{
- responseHeaders["Expires"] = "-1";
+ responseHeaders[HeaderNames.Expires] = "0";
}
AddResponseHeaders(result, responseHeaders);
@@ -131,7 +132,7 @@ namespace Emby.Server.Implementations.HttpServer
content = Array.Empty<byte>();
}
- result = new StreamWriter(content, contentType, contentLength, _logger);
+ result = new StreamWriter(content, contentType);
}
else
{
@@ -143,9 +144,9 @@ namespace Emby.Server.Implementations.HttpServer
responseHeaders = new Dictionary<string, string>();
}
- if (addCachePrevention && !responseHeaders.TryGetValue("Expires", out string expires))
+ if (addCachePrevention && !responseHeaders.TryGetValue(HeaderNames.Expires, out string _))
{
- responseHeaders["Expires"] = "-1";
+ responseHeaders[HeaderNames.Expires] = "0";
}
AddResponseHeaders(result, responseHeaders);
@@ -175,7 +176,7 @@ namespace Emby.Server.Implementations.HttpServer
bytes = Array.Empty<byte>();
}
- result = new StreamWriter(bytes, contentType, contentLength, _logger);
+ result = new StreamWriter(bytes, contentType);
}
else
{
@@ -187,9 +188,9 @@ namespace Emby.Server.Implementations.HttpServer
responseHeaders = new Dictionary<string, string>();
}
- if (addCachePrevention && !responseHeaders.TryGetValue("Expires", out string expires))
+ if (addCachePrevention && !responseHeaders.TryGetValue(HeaderNames.Expires, out string _))
{
- responseHeaders["Expires"] = "-1";
+ responseHeaders[HeaderNames.Expires] = "0";
}
AddResponseHeaders(result, responseHeaders);
@@ -214,7 +215,7 @@ namespace Emby.Server.Implementations.HttpServer
responseHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
- responseHeaders["Expires"] = "-1";
+ responseHeaders[HeaderNames.Expires] = "0";
return ToOptimizedResultInternal(requestContext, result, responseHeaders);
}
@@ -246,9 +247,9 @@ namespace Emby.Server.Implementations.HttpServer
private static string GetCompressionType(IRequest request)
{
- var acceptEncoding = request.Headers["Accept-Encoding"];
+ var acceptEncoding = request.Headers[HeaderNames.AcceptEncoding].ToString();
- if (acceptEncoding != null)
+ if (string.IsNullOrEmpty(acceptEncoding))
{
//if (_brotliCompressor != null && acceptEncoding.IndexOf("br", StringComparison.OrdinalIgnoreCase) != -1)
// return "br";
@@ -277,9 +278,10 @@ namespace Emby.Server.Implementations.HttpServer
private object ToOptimizedResultInternal<T>(IRequest request, T dto, IDictionary<string, string> responseHeaders = null)
{
- var contentType = request.ResponseContentType;
+ // TODO: @bond use Span and .Equals
+ var contentType = request.ResponseContentType?.Split(';')[0].Trim().ToLowerInvariant();
- switch (GetRealContentType(contentType))
+ switch (contentType)
{
case "application/xml":
case "text/xml":
@@ -325,21 +327,21 @@ namespace Emby.Server.Implementations.HttpServer
}
content = Compress(content, requestedCompressionType);
- responseHeaders["Content-Encoding"] = requestedCompressionType;
+ responseHeaders[HeaderNames.ContentEncoding] = requestedCompressionType;
- responseHeaders["Vary"] = "Accept-Encoding";
+ responseHeaders[HeaderNames.Vary] = HeaderNames.AcceptEncoding;
var contentLength = content.Length;
if (isHeadRequest)
{
- var result = new StreamWriter(Array.Empty<byte>(), contentType, contentLength, _logger);
+ var result = new StreamWriter(Array.Empty<byte>(), contentType);
AddResponseHeaders(result, responseHeaders);
return result;
}
else
{
- var result = new StreamWriter(content, contentType, contentLength, _logger);
+ var result = new StreamWriter(content, contentType);
AddResponseHeaders(result, responseHeaders);
return result;
}
@@ -347,23 +349,19 @@ namespace Emby.Server.Implementations.HttpServer
private byte[] Compress(byte[] bytes, string compressionType)
{
- if (string.Equals(compressionType, "br", StringComparison.OrdinalIgnoreCase))
- return CompressBrotli(bytes);
-
if (string.Equals(compressionType, "deflate", StringComparison.OrdinalIgnoreCase))
+ {
return Deflate(bytes);
+ }
if (string.Equals(compressionType, "gzip", StringComparison.OrdinalIgnoreCase))
+ {
return GZip(bytes);
+ }
throw new NotSupportedException(compressionType);
}
- private byte[] CompressBrotli(byte[] bytes)
- {
- return _brotliCompressor.Compress(bytes);
- }
-
private static byte[] Deflate(byte[] bytes)
{
// In .NET FX incompat-ville, you can't access compressed bytes without closing DeflateStream
@@ -390,13 +388,6 @@ namespace Emby.Server.Implementations.HttpServer
}
}
- public static string GetRealContentType(string contentType)
- {
- return contentType == null
- ? null
- : contentType.Split(';')[0].ToLowerInvariant().Trim();
- }
-
private static string SerializeToXmlString(object from)
{
using (var ms = new MemoryStream())
@@ -424,12 +415,12 @@ namespace Emby.Server.Implementations.HttpServer
/// </summary>
private object GetCachedResult(IRequest requestContext, IDictionary<string, string> responseHeaders, StaticResultOptions options)
{
- bool noCache = (requestContext.Headers.Get("Cache-Control") ?? string.Empty).IndexOf("no-cache", StringComparison.OrdinalIgnoreCase) != -1;
+ bool noCache = (requestContext.Headers[HeaderNames.CacheControl].ToString()).IndexOf("no-cache", StringComparison.OrdinalIgnoreCase) != -1;
AddCachingHeaders(responseHeaders, options.CacheDuration, noCache, options.DateLastModified);
if (!noCache)
{
- DateTime.TryParse(requestContext.Headers.Get("If-Modified-Since"), out var ifModifiedSinceHeader);
+ DateTime.TryParse(requestContext.Headers[HeaderNames.IfModifiedSince], out var ifModifiedSinceHeader);
if (IsNotModified(ifModifiedSinceHeader, options.CacheDuration, options.DateLastModified))
{
@@ -530,7 +521,7 @@ namespace Emby.Server.Implementations.HttpServer
options.ResponseHeaders = options.ResponseHeaders ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var contentType = options.ContentType;
- if (!string.IsNullOrEmpty(requestContext.Headers.Get("If-Modified-Since")))
+ if (!StringValues.IsNullOrEmpty(requestContext.Headers[HeaderNames.IfModifiedSince]))
{
// See if the result is already cached in the browser
var result = GetCachedResult(requestContext, options.ResponseHeaders, options);
@@ -548,11 +539,11 @@ namespace Emby.Server.Implementations.HttpServer
AddCachingHeaders(responseHeaders, options.CacheDuration, false, options.DateLastModified);
AddAgeHeader(responseHeaders, options.DateLastModified);
- var rangeHeader = requestContext.Headers.Get("Range");
+ var rangeHeader = requestContext.Headers[HeaderNames.Range];
if (!isHeadRequest && !string.IsNullOrEmpty(options.Path))
{
- var hasHeaders = new FileWriter(options.Path, contentType, rangeHeader, _logger, _fileSystem)
+ var hasHeaders = new FileWriter(options.Path, contentType, rangeHeader, _logger, _fileSystem, _streamHelper)
{
OnComplete = options.OnComplete,
OnError = options.OnError,
@@ -590,11 +581,6 @@ namespace Emby.Server.Implementations.HttpServer
}
else
{
- if (totalContentLength.HasValue)
- {
- responseHeaders["Content-Length"] = totalContentLength.Value.ToString(UsCulture);
- }
-
if (isHeadRequest)
{
using (stream)
@@ -603,7 +589,7 @@ namespace Emby.Server.Implementations.HttpServer
}
}
- var hasHeaders = new StreamWriter(stream, contentType, _logger)
+ var hasHeaders = new StreamWriter(stream, contentType)
{
OnComplete = options.OnComplete,
OnError = options.OnError
@@ -615,11 +601,6 @@ namespace Emby.Server.Implementations.HttpServer
}
/// <summary>
- /// The us culture
- /// </summary>
- private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
-
- /// <summary>
/// Adds the caching responseHeaders.
/// </summary>
private void AddCachingHeaders(IDictionary<string, string> responseHeaders, TimeSpan? cacheDuration,
@@ -627,23 +608,23 @@ namespace Emby.Server.Implementations.HttpServer
{
if (noCache)
{
- responseHeaders["Cache-Control"] = "no-cache, no-store, must-revalidate";
- responseHeaders["pragma"] = "no-cache, no-store, must-revalidate";
+ responseHeaders[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate";
+ responseHeaders[HeaderNames.Pragma] = "no-cache, no-store, must-revalidate";
return;
}
if (cacheDuration.HasValue)
{
- responseHeaders["Cache-Control"] = "public, max-age=" + cacheDuration.Value.TotalSeconds;
+ responseHeaders[HeaderNames.CacheControl] = "public, max-age=" + cacheDuration.Value.TotalSeconds;
}
else
{
- responseHeaders["Cache-Control"] = "public";
+ responseHeaders[HeaderNames.CacheControl] = "public";
}
if (lastModifiedDate.HasValue)
{
- responseHeaders["Last-Modified"] = lastModifiedDate.ToString();
+ responseHeaders[HeaderNames.LastModified] = lastModifiedDate.ToString();
}
}
@@ -656,7 +637,7 @@ namespace Emby.Server.Implementations.HttpServer
{
if (lastDateModified.HasValue)
{
- responseHeaders["Age"] = Convert.ToInt64((DateTime.UtcNow - lastDateModified.Value).TotalSeconds).ToString(CultureInfo.InvariantCulture);
+ responseHeaders[HeaderNames.Age] = Convert.ToInt64((DateTime.UtcNow - lastDateModified.Value).TotalSeconds).ToString(CultureInfo.InvariantCulture);
}
}
@@ -714,9 +695,4 @@ namespace Emby.Server.Implementations.HttpServer
}
}
}
-
- public interface IBrotliCompressor
- {
- byte[] Compress(byte[] content);
- }
}
diff --git a/Emby.Server.Implementations/HttpServer/IHttpListener.cs b/Emby.Server.Implementations/HttpServer/IHttpListener.cs
index 835091361..005656d2c 100644
--- a/Emby.Server.Implementations/HttpServer/IHttpListener.cs
+++ b/Emby.Server.Implementations/HttpServer/IHttpListener.cs
@@ -1,10 +1,9 @@
using System;
-using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Emby.Server.Implementations.Net;
-using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
namespace Emby.Server.Implementations.HttpServer
{
@@ -29,20 +28,10 @@ namespace Emby.Server.Implementations.HttpServer
Action<WebSocketConnectEventArgs> WebSocketConnected { get; set; }
/// <summary>
- /// Gets or sets the web socket connecting.
- /// </summary>
- /// <value>The web socket connecting.</value>
- Action<WebSocketConnectingEventArgs> WebSocketConnecting { get; set; }
-
- /// <summary>
- /// Starts this instance.
- /// </summary>
- /// <param name="urlPrefixes">The URL prefixes.</param>
- void Start(IEnumerable<string> urlPrefixes);
-
- /// <summary>
/// Stops this instance.
/// </summary>
Task Stop();
+
+ Task ProcessWebSocketRequest(HttpContext ctx);
}
}
diff --git a/Emby.Server.Implementations/HttpServer/LoggerUtils.cs b/Emby.Server.Implementations/HttpServer/LoggerUtils.cs
deleted file mode 100644
index d22d9db26..000000000
--- a/Emby.Server.Implementations/HttpServer/LoggerUtils.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using System;
-using System.Globalization;
-using MediaBrowser.Model.Services;
-using Microsoft.Extensions.Logging;
-
-namespace Emby.Server.Implementations.HttpServer
-{
- public static class LoggerUtils
- {
- public static void LogRequest(ILogger logger, string url, string method, string userAgent, QueryParamCollection headers)
- {
- if (headers == null)
- {
- logger.LogInformation("{0} {1}. UserAgent: {2}", "HTTP " + method, url, userAgent ?? string.Empty);
- }
- else
- {
- var headerText = string.Empty;
- var index = 0;
-
- foreach (var i in headers)
- {
- if (index > 0)
- {
- headerText += ", ";
- }
-
- headerText += i.Name + "=" + i.Value;
-
- index++;
- }
-
- logger.LogInformation("HTTP {0} {1}. {2}", method, url, headerText);
- }
- }
-
- /// <summary>
- /// Logs the response.
- /// </summary>
- /// <param name="logger">The logger.</param>
- /// <param name="statusCode">The status code.</param>
- /// <param name="url">The URL.</param>
- /// <param name="endPoint">The end point.</param>
- /// <param name="duration">The duration.</param>
- public static void LogResponse(ILogger logger, int statusCode, string url, string endPoint, TimeSpan duration, QueryParamCollection headers)
- {
- var durationMs = duration.TotalMilliseconds;
- var logSuffix = durationMs >= 1000 && durationMs < 60000 ? "ms (slow)" : "ms";
-
- //var headerText = headers == null ? string.Empty : "Headers: " + string.Join(", ", headers.Where(i => i.Name.IndexOf("Access-", StringComparison.OrdinalIgnoreCase) == -1).Select(i => i.Name + "=" + i.Value).ToArray());
- var headerText = string.Empty;
- logger.LogInformation("HTTP Response {0} to {1}. Time: {2}{3}. {4} {5}", statusCode, endPoint, Convert.ToInt32(durationMs).ToString(CultureInfo.InvariantCulture), logSuffix, url, headerText);
- }
- }
-}
diff --git a/Emby.Server.Implementations/HttpServer/RangeRequestWriter.cs b/Emby.Server.Implementations/HttpServer/RangeRequestWriter.cs
index 891a76ec2..449159834 100644
--- a/Emby.Server.Implementations/HttpServer/RangeRequestWriter.cs
+++ b/Emby.Server.Implementations/HttpServer/RangeRequestWriter.cs
@@ -7,6 +7,7 @@ using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
+using Microsoft.Net.Http.Headers;
namespace Emby.Server.Implementations.HttpServer
{
@@ -66,8 +67,8 @@ namespace Emby.Server.Implementations.HttpServer
this._logger = logger;
ContentType = contentType;
- Headers["Content-Type"] = contentType;
- Headers["Accept-Ranges"] = "bytes";
+ Headers[HeaderNames.ContentType] = contentType;
+ Headers[HeaderNames.AcceptRanges] = "bytes";
StatusCode = HttpStatusCode.PartialContent;
SetRangeValues(contentLength);
@@ -95,9 +96,7 @@ namespace Emby.Server.Implementations.HttpServer
RangeStart = requestedRange.Key;
RangeLength = 1 + RangeEnd - RangeStart;
- // Content-Length is the length of what we're serving, not the original content
- Headers["Content-Length"] = RangeLength.ToString(UsCulture);
- Headers["Content-Range"] = string.Format("bytes {0}-{1}/{2}", RangeStart, RangeEnd, TotalContentLength);
+ Headers[HeaderNames.ContentRange] = $"bytes {RangeStart}-{RangeEnd}/{TotalContentLength}";
if (RangeStart > 0 && SourceStream.CanSeek)
{
diff --git a/Emby.Server.Implementations/HttpServer/ResponseFilter.cs b/Emby.Server.Implementations/HttpServer/ResponseFilter.cs
index da2bf983a..a53d9bf0b 100644
--- a/Emby.Server.Implementations/HttpServer/ResponseFilter.cs
+++ b/Emby.Server.Implementations/HttpServer/ResponseFilter.cs
@@ -3,6 +3,7 @@ using System.Globalization;
using System.Text;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
+using Microsoft.Net.Http.Headers;
namespace Emby.Server.Implementations.HttpServer
{
@@ -25,7 +26,7 @@ namespace Emby.Server.Implementations.HttpServer
public void FilterResponse(IRequest req, IResponse res, object dto)
{
// Try to prevent compatibility view
- res.AddHeader("Access-Control-Allow-Headers", "Accept, Accept-Language, Authorization, Cache-Control, Content-Disposition, Content-Encoding, Content-Language, Content-Length, Content-MD5, Content-Range, Content-Type, Date, Host, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Origin, OriginToken, Pragma, Range, Slug, Transfer-Encoding, Want-Digest, X-MediaBrowser-Token, X-Emby-Authorization");
+ res.AddHeader("Access-Control-Allow-Headers", "Accept, Accept-Language, Authorization, Cache-Control, Content-Disposition, Content-Encoding, Content-Language, Content-MD5, Content-Range, Content-Type, Date, Host, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Origin, OriginToken, Pragma, Range, Slug, Transfer-Encoding, Want-Digest, X-MediaBrowser-Token, X-Emby-Authorization");
res.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
res.AddHeader("Access-Control-Allow-Origin", "*");
@@ -44,20 +45,19 @@ namespace Emby.Server.Implementations.HttpServer
if (dto is IHasHeaders hasHeaders)
{
- if (!hasHeaders.Headers.ContainsKey("Server"))
+ if (!hasHeaders.Headers.ContainsKey(HeaderNames.Server))
{
- hasHeaders.Headers["Server"] = "Microsoft-NetCore/2.0, UPnP/1.0 DLNADOC/1.50";
+ hasHeaders.Headers[HeaderNames.Server] = "Microsoft-NetCore/2.0, UPnP/1.0 DLNADOC/1.50";
}
// Content length has to be explicitly set on on HttpListenerResponse or it won't be happy
- if (hasHeaders.Headers.TryGetValue("Content-Length", out string contentLength)
+ if (hasHeaders.Headers.TryGetValue(HeaderNames.ContentLength, out string contentLength)
&& !string.IsNullOrEmpty(contentLength))
{
var length = long.Parse(contentLength, UsCulture);
if (length > 0)
{
- res.SetContentLength(length);
res.SendChunked = false;
}
}
diff --git a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs b/Emby.Server.Implementations/HttpServer/Security/AuthService.cs
index 499a334fc..1027883ed 100644
--- a/Emby.Server.Implementations/HttpServer/Security/AuthService.cs
+++ b/Emby.Server.Implementations/HttpServer/Security/AuthService.cs
@@ -45,7 +45,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
// This code is executed before the service
var auth = AuthorizationContext.GetAuthorizationInfo(request);
- if (!IsExemptFromAuthenticationToken(auth, authAttribtues, request))
+ if (!IsExemptFromAuthenticationToken(authAttribtues, request))
{
ValidateSecurityToken(request, auth.Token);
}
@@ -122,7 +122,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
}
}
- private bool IsExemptFromAuthenticationToken(AuthorizationInfo auth, IAuthenticationAttributes authAttribtues, IRequest request)
+ private bool IsExemptFromAuthenticationToken(IAuthenticationAttributes authAttribtues, IRequest request)
{
if (!_config.Configuration.IsStartupWizardCompleted && authAttribtues.AllowBeforeStartupWizard)
{
diff --git a/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs b/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs
index cab41e65b..276312a30 100644
--- a/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs
+++ b/Emby.Server.Implementations/HttpServer/Security/AuthorizationContext.cs
@@ -5,6 +5,7 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Security;
using MediaBrowser.Model.Services;
+using Microsoft.Net.Http.Headers;
namespace Emby.Server.Implementations.HttpServer.Security
{
@@ -176,7 +177,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
if (string.IsNullOrEmpty(auth))
{
- auth = httpReq.Headers["Authorization"];
+ auth = httpReq.Headers[HeaderNames.Authorization];
}
return GetAuthorization(auth);
diff --git a/Emby.Server.Implementations/HttpServer/StreamWriter.cs b/Emby.Server.Implementations/HttpServer/StreamWriter.cs
index 3269d44cf..324f9085e 100644
--- a/Emby.Server.Implementations/HttpServer/StreamWriter.cs
+++ b/Emby.Server.Implementations/HttpServer/StreamWriter.cs
@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Services;
-using Microsoft.Extensions.Logging;
+using Microsoft.Net.Http.Headers;
namespace Emby.Server.Implementations.HttpServer
{
@@ -14,10 +13,6 @@ namespace Emby.Server.Implementations.HttpServer
/// </summary>
public class StreamWriter : IAsyncStreamWriter, IHasHeaders
{
- private ILogger Logger { get; set; }
-
- private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
-
/// <summary>
/// Gets or sets the source stream.
/// </summary>
@@ -45,7 +40,7 @@ namespace Emby.Server.Implementations.HttpServer
/// <param name="source">The source.</param>
/// <param name="contentType">Type of the content.</param>
/// <param name="logger">The logger.</param>
- public StreamWriter(Stream source, string contentType, ILogger logger)
+ public StreamWriter(Stream source, string contentType)
{
if (string.IsNullOrEmpty(contentType))
{
@@ -53,14 +48,8 @@ namespace Emby.Server.Implementations.HttpServer
}
SourceStream = source;
- Logger = logger;
- Headers["Content-Type"] = contentType;
-
- if (source.CanSeek)
- {
- Headers["Content-Length"] = source.Length.ToString(UsCulture);
- }
+ Headers[HeaderNames.ContentType] = contentType;
}
/// <summary>
@@ -68,8 +57,7 @@ namespace Emby.Server.Implementations.HttpServer
/// </summary>
/// <param name="source">The source.</param>
/// <param name="contentType">Type of the content.</param>
- /// <param name="logger">The logger.</param>
- public StreamWriter(byte[] source, string contentType, int contentLength, ILogger logger)
+ public StreamWriter(byte[] source, string contentType)
{
if (string.IsNullOrEmpty(contentType))
{
@@ -77,11 +65,8 @@ namespace Emby.Server.Implementations.HttpServer
}
SourceBytes = source;
- Logger = logger;
-
- Headers["Content-Type"] = contentType;
- Headers["Content-Length"] = contentLength.ToString(UsCulture);
+ Headers[HeaderNames.ContentType] = contentType;
}
public async Task WriteToAsync(Stream responseStream, CancellationToken cancellationToken)
diff --git a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
index e9d0bac74..54a16040f 100644
--- a/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
+++ b/Emby.Server.Implementations/HttpServer/WebSocketConnection.cs
@@ -8,6 +8,7 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using UtfUnknown;
@@ -67,7 +68,7 @@ namespace Emby.Server.Implementations.HttpServer
/// Gets or sets the query string.
/// </summary>
/// <value>The query string.</value>
- public QueryParamCollection QueryString { get; set; }
+ public IQueryCollection QueryString { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="WebSocketConnection" /> class.
@@ -101,12 +102,6 @@ namespace Emby.Server.Implementations.HttpServer
_socket = socket;
_socket.OnReceiveBytes = OnReceiveInternal;
- var memorySocket = socket as IMemoryWebSocket;
- if (memorySocket != null)
- {
- memorySocket.OnReceiveMemoryBytes = OnReceiveInternal;
- }
-
RemoteEndPoint = remoteEndPoint;
_logger = logger;
@@ -142,34 +137,6 @@ namespace Emby.Server.Implementations.HttpServer
}
}
- /// <summary>
- /// Called when [receive].
- /// </summary>
- /// <param name="memory">The memory block.</param>
- /// <param name="length">The length of the memory block.</param>
- private void OnReceiveInternal(Memory<byte> memory, int length)
- {
- LastActivityDate = DateTime.UtcNow;
-
- if (OnReceive == null)
- {
- return;
- }
-
- var bytes = memory.Slice(0, length).ToArray();
-
- var charset = CharsetDetector.DetectFromBytes(bytes).Detected?.EncodingName;
-
- if (string.Equals(charset, "utf-8", StringComparison.OrdinalIgnoreCase))
- {
- OnReceiveInternal(Encoding.UTF8.GetString(bytes, 0, bytes.Length));
- }
- else
- {
- OnReceiveInternal(Encoding.ASCII.GetString(bytes, 0, bytes.Length));
- }
- }
-
private void OnReceiveInternal(string message)
{
LastActivityDate = DateTime.UtcNow;
@@ -193,7 +160,7 @@ namespace Emby.Server.Implementations.HttpServer
var info = new WebSocketMessageInfo
{
MessageType = stub.MessageType,
- Data = stub.Data == null ? null : stub.Data.ToString(),
+ Data = stub.Data?.ToString(),
Connection = this
};
diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs
index d47342511..df4dc41b9 100644
--- a/Emby.Server.Implementations/IO/LibraryMonitor.cs
+++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs
@@ -10,8 +10,8 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.System;
-using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
+using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace Emby.Server.Implementations.IO
{
@@ -127,7 +127,6 @@ namespace Emby.Server.Implementations.IO
private IServerConfigurationManager ConfigurationManager { get; set; }
private readonly IFileSystem _fileSystem;
- private readonly IEnvironmentInfo _environmentInfo;
/// <summary>
/// Initializes a new instance of the <see cref="LibraryMonitor" /> class.
@@ -136,14 +135,12 @@ namespace Emby.Server.Implementations.IO
ILoggerFactory loggerFactory,
ILibraryManager libraryManager,
IServerConfigurationManager configurationManager,
- IFileSystem fileSystem,
- IEnvironmentInfo environmentInfo)
+ IFileSystem fileSystem)
{
LibraryManager = libraryManager;
Logger = loggerFactory.CreateLogger(GetType().Name);
ConfigurationManager = configurationManager;
_fileSystem = fileSystem;
- _environmentInfo = environmentInfo;
}
private bool IsLibraryMonitorEnabled(BaseItem item)
@@ -267,7 +264,7 @@ namespace Emby.Server.Implementations.IO
return;
}
- if (_environmentInfo.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows)
+ if (OperatingSystem.Id != OperatingSystemId.Windows)
{
if (path.StartsWith("\\\\", StringComparison.OrdinalIgnoreCase) || path.StartsWith("smb://", StringComparison.OrdinalIgnoreCase))
{
@@ -276,12 +273,6 @@ namespace Emby.Server.Implementations.IO
}
}
- if (_environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Android)
- {
- // causing crashing
- return;
- }
-
// Already being watched
if (_fileSystemWatchers.ContainsKey(path))
{
diff --git a/Emby.Server.Implementations/IO/ManagedFileSystem.cs b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
index a64dfb607..47cea7269 100644
--- a/Emby.Server.Implementations/IO/ManagedFileSystem.cs
+++ b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
@@ -7,8 +7,8 @@ using System.Text;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.System;
-using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
+using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace Emby.Server.Implementations.IO
{
@@ -25,22 +25,19 @@ namespace Emby.Server.Implementations.IO
private readonly string _tempPath;
- private readonly IEnvironmentInfo _environmentInfo;
private readonly bool _isEnvironmentCaseInsensitive;
public ManagedFileSystem(
ILoggerFactory loggerFactory,
- IEnvironmentInfo environmentInfo,
IApplicationPaths applicationPaths)
{
Logger = loggerFactory.CreateLogger("FileSystem");
_supportsAsyncFileStreams = true;
_tempPath = applicationPaths.TempDirectory;
- _environmentInfo = environmentInfo;
- SetInvalidFileNameChars(environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows);
+ SetInvalidFileNameChars(OperatingSystem.Id == OperatingSystemId.Windows);
- _isEnvironmentCaseInsensitive = environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows;
+ _isEnvironmentCaseInsensitive = OperatingSystem.Id == OperatingSystemId.Windows;
}
public virtual void AddShortcutHandler(IShortcutHandler handler)
@@ -469,7 +466,7 @@ namespace Emby.Server.Implementations.IO
public virtual void SetHidden(string path, bool isHidden)
{
- if (_environmentInfo.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows)
+ if (OperatingSystem.Id != MediaBrowser.Model.System.OperatingSystemId.Windows)
{
return;
}
@@ -493,7 +490,7 @@ namespace Emby.Server.Implementations.IO
public virtual void SetReadOnly(string path, bool isReadOnly)
{
- if (_environmentInfo.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows)
+ if (OperatingSystem.Id != MediaBrowser.Model.System.OperatingSystemId.Windows)
{
return;
}
@@ -517,7 +514,7 @@ namespace Emby.Server.Implementations.IO
public virtual void SetAttributes(string path, bool isHidden, bool isReadOnly)
{
- if (_environmentInfo.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows)
+ if (OperatingSystem.Id != MediaBrowser.Model.System.OperatingSystemId.Windows)
{
return;
}
@@ -711,20 +708,20 @@ namespace Emby.Server.Implementations.IO
return GetFiles(path, null, false, recursive);
}
- public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
+ public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string> extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
{
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
// On linux and osx the search pattern is case sensitive
// If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
- if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions != null && extensions.Length == 1)
+ if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions != null && extensions.Count == 1)
{
return ToMetadata(new DirectoryInfo(path).EnumerateFiles("*" + extensions[0], searchOption));
}
var files = new DirectoryInfo(path).EnumerateFiles("*", searchOption);
- if (extensions != null && extensions.Length > 0)
+ if (extensions != null && extensions.Count > 0)
{
files = files.Where(i =>
{
@@ -802,7 +799,7 @@ namespace Emby.Server.Implementations.IO
public virtual void SetExecutable(string path)
{
- if (_environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.OSX)
+ if (OperatingSystem.Id == MediaBrowser.Model.System.OperatingSystemId.Darwin)
{
RunProcess("chmod", "+x \"" + path + "\"", Path.GetDirectoryName(path));
}
diff --git a/Emby.Server.Implementations/IO/StreamHelper.cs b/Emby.Server.Implementations/IO/StreamHelper.cs
index 09cf4d4a3..d02cd84a0 100644
--- a/Emby.Server.Implementations/IO/StreamHelper.cs
+++ b/Emby.Server.Implementations/IO/StreamHelper.cs
@@ -1,4 +1,5 @@
using System;
+using System.Buffers;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
@@ -8,168 +9,213 @@ namespace Emby.Server.Implementations.IO
{
public class StreamHelper : IStreamHelper
{
+ private const int StreamCopyToBufferSize = 81920;
+
public async Task CopyToAsync(Stream source, Stream destination, int bufferSize, Action onStarted, CancellationToken cancellationToken)
{
- byte[] buffer = new byte[bufferSize];
- int read;
- while ((read = source.Read(buffer, 0, buffer.Length)) != 0)
+ byte[] buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
+ try
{
- cancellationToken.ThrowIfCancellationRequested();
+ int read;
+ while ((read = await source.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) != 0)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
- await destination.WriteAsync(buffer, 0, read).ConfigureAwait(false);
+ await destination.WriteAsync(buffer, 0, read).ConfigureAwait(false);
- if (onStarted != null)
- {
- onStarted();
- onStarted = null;
+ if (onStarted != null)
+ {
+ onStarted();
+ onStarted = null;
+ }
}
}
+ finally
+ {
+ ArrayPool<byte>.Shared.Return(buffer);
+ }
}
public async Task CopyToAsync(Stream source, Stream destination, int bufferSize, int emptyReadLimit, CancellationToken cancellationToken)
{
- byte[] buffer = new byte[bufferSize];
-
- if (emptyReadLimit <= 0)
+ byte[] buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
+ try
{
- int read;
- while ((read = source.Read(buffer, 0, buffer.Length)) != 0)
+ if (emptyReadLimit <= 0)
{
- cancellationToken.ThrowIfCancellationRequested();
+ int read;
+ while ((read = await source.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) != 0)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
- await destination.WriteAsync(buffer, 0, read).ConfigureAwait(false);
- }
+ await destination.WriteAsync(buffer, 0, read).ConfigureAwait(false);
+ }
- return;
- }
+ return;
+ }
- var eofCount = 0;
+ var eofCount = 0;
- while (eofCount < emptyReadLimit)
- {
- cancellationToken.ThrowIfCancellationRequested();
+ while (eofCount < emptyReadLimit)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
- var bytesRead = source.Read(buffer, 0, buffer.Length);
+ var bytesRead = await source.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
- if (bytesRead == 0)
- {
- eofCount++;
- await Task.Delay(50, cancellationToken).ConfigureAwait(false);
- }
- else
- {
- eofCount = 0;
+ if (bytesRead == 0)
+ {
+ eofCount++;
+ await Task.Delay(50, cancellationToken).ConfigureAwait(false);
+ }
+ else
+ {
+ eofCount = 0;
- await destination.WriteAsync(buffer, 0, bytesRead).ConfigureAwait(false);
+ await destination.WriteAsync(buffer, 0, bytesRead).ConfigureAwait(false);
+ }
}
}
+ finally
+ {
+ ArrayPool<byte>.Shared.Return(buffer);
+ }
}
- const int StreamCopyToBufferSize = 81920;
public async Task<int> CopyToAsync(Stream source, Stream destination, CancellationToken cancellationToken)
{
- var array = new byte[StreamCopyToBufferSize];
- int bytesRead;
- int totalBytesRead = 0;
-
- while ((bytesRead = await source.ReadAsync(array, 0, array.Length, cancellationToken).ConfigureAwait(false)) != 0)
+ byte[] buffer = ArrayPool<byte>.Shared.Rent(StreamCopyToBufferSize);
+ try
{
- var bytesToWrite = bytesRead;
+ int totalBytesRead = 0;
- if (bytesToWrite > 0)
+ int bytesRead;
+ while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0)
{
- await destination.WriteAsync(array, 0, Convert.ToInt32(bytesToWrite), cancellationToken).ConfigureAwait(false);
+ var bytesToWrite = bytesRead;
- totalBytesRead += bytesRead;
+ if (bytesToWrite > 0)
+ {
+ await destination.WriteAsync(buffer, 0, Convert.ToInt32(bytesToWrite), cancellationToken).ConfigureAwait(false);
+
+ totalBytesRead += bytesRead;
+ }
}
- }
- return totalBytesRead;
+ return totalBytesRead;
+ }
+ finally
+ {
+ ArrayPool<byte>.Shared.Return(buffer);
+ }
}
public async Task<int> CopyToAsyncWithSyncRead(Stream source, Stream destination, CancellationToken cancellationToken)
{
- var array = new byte[StreamCopyToBufferSize];
- int bytesRead;
- int totalBytesRead = 0;
-
- while ((bytesRead = source.Read(array, 0, array.Length)) != 0)
+ byte[] buffer = ArrayPool<byte>.Shared.Rent(StreamCopyToBufferSize);
+ try
{
- var bytesToWrite = bytesRead;
+ int bytesRead;
+ int totalBytesRead = 0;
- if (bytesToWrite > 0)
+ while ((bytesRead = source.Read(buffer, 0, buffer.Length)) != 0)
{
- await destination.WriteAsync(array, 0, Convert.ToInt32(bytesToWrite), cancellationToken).ConfigureAwait(false);
+ var bytesToWrite = bytesRead;
- totalBytesRead += bytesRead;
+ if (bytesToWrite > 0)
+ {
+ await destination.WriteAsync(buffer, 0, Convert.ToInt32(bytesToWrite), cancellationToken).ConfigureAwait(false);
+
+ totalBytesRead += bytesRead;
+ }
}
- }
- return totalBytesRead;
+ return totalBytesRead;
+ }
+ finally
+ {
+ ArrayPool<byte>.Shared.Return(buffer);
+ }
}
public async Task CopyToAsyncWithSyncRead(Stream source, Stream destination, long copyLength, CancellationToken cancellationToken)
{
- var array = new byte[StreamCopyToBufferSize];
- int bytesRead;
-
- while ((bytesRead = source.Read(array, 0, array.Length)) != 0)
+ byte[] buffer = ArrayPool<byte>.Shared.Rent(StreamCopyToBufferSize);
+ try
{
- var bytesToWrite = Math.Min(bytesRead, copyLength);
+ int bytesRead;
- if (bytesToWrite > 0)
+ while ((bytesRead = source.Read(buffer, 0, buffer.Length)) != 0)
{
- await destination.WriteAsync(array, 0, Convert.ToInt32(bytesToWrite), cancellationToken).ConfigureAwait(false);
- }
+ var bytesToWrite = Math.Min(bytesRead, copyLength);
- copyLength -= bytesToWrite;
+ if (bytesToWrite > 0)
+ {
+ await destination.WriteAsync(buffer, 0, Convert.ToInt32(bytesToWrite), cancellationToken).ConfigureAwait(false);
+ }
- if (copyLength <= 0)
- {
- break;
+ copyLength -= bytesToWrite;
+
+ if (copyLength <= 0)
+ {
+ break;
+ }
}
}
+ finally
+ {
+ ArrayPool<byte>.Shared.Return(buffer);
+ }
}
public async Task CopyToAsync(Stream source, Stream destination, long copyLength, CancellationToken cancellationToken)
{
- var array = new byte[StreamCopyToBufferSize];
- int bytesRead;
-
- while ((bytesRead = await source.ReadAsync(array, 0, array.Length, cancellationToken).ConfigureAwait(false)) != 0)
+ byte[] buffer = ArrayPool<byte>.Shared.Rent(StreamCopyToBufferSize);
+ try
{
- var bytesToWrite = Math.Min(bytesRead, copyLength);
+ int bytesRead;
- if (bytesToWrite > 0)
+ while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0)
{
- await destination.WriteAsync(array, 0, Convert.ToInt32(bytesToWrite), cancellationToken).ConfigureAwait(false);
- }
+ var bytesToWrite = Math.Min(bytesRead, copyLength);
- copyLength -= bytesToWrite;
+ if (bytesToWrite > 0)
+ {
+ await destination.WriteAsync(buffer, 0, Convert.ToInt32(bytesToWrite), cancellationToken).ConfigureAwait(false);
+ }
- if (copyLength <= 0)
- {
- break;
+ copyLength -= bytesToWrite;
+
+ if (copyLength <= 0)
+ {
+ break;
+ }
}
}
+ finally
+ {
+ ArrayPool<byte>.Shared.Return(buffer);
+ }
}
public async Task CopyUntilCancelled(Stream source, Stream target, int bufferSize, CancellationToken cancellationToken)
{
- byte[] buffer = new byte[bufferSize];
-
- while (!cancellationToken.IsCancellationRequested)
+ byte[] buffer = ArrayPool<byte>.Shared.Rent(bufferSize);
+ try
{
- var bytesRead = await CopyToAsyncInternal(source, target, buffer, cancellationToken).ConfigureAwait(false);
-
- //var position = fs.Position;
- //_logger.LogDebug("Streamed {0} bytes to position {1} from file {2}", bytesRead, position, path);
-
- if (bytesRead == 0)
+ while (!cancellationToken.IsCancellationRequested)
{
- await Task.Delay(100).ConfigureAwait(false);
+ var bytesRead = await CopyToAsyncInternal(source, target, buffer, cancellationToken).ConfigureAwait(false);
+
+ if (bytesRead == 0)
+ {
+ await Task.Delay(100).ConfigureAwait(false);
+ }
}
}
+ finally
+ {
+ ArrayPool<byte>.Shared.Return(buffer);
+ }
}
private static async Task<int> CopyToAsyncInternal(Stream source, Stream destination, byte[] buffer, CancellationToken cancellationToken)
diff --git a/Emby.Server.Implementations/IStartupOptions.cs b/Emby.Server.Implementations/IStartupOptions.cs
index 24aaa76c0..6e915de3d 100644
--- a/Emby.Server.Implementations/IStartupOptions.cs
+++ b/Emby.Server.Implementations/IStartupOptions.cs
@@ -8,11 +8,6 @@ namespace Emby.Server.Implementations
string FFmpegPath { get; }
/// <summary>
- /// --ffprobe
- /// </summary>
- string FFprobePath { get; }
-
- /// <summary>
/// --service
/// </summary>
bool IsService { get; }
diff --git a/Emby.Server.Implementations/Images/BaseDynamicImageProvider.cs b/Emby.Server.Implementations/Images/BaseDynamicImageProvider.cs
index 109c21f18..46f209b4b 100644
--- a/Emby.Server.Implementations/Images/BaseDynamicImageProvider.cs
+++ b/Emby.Server.Implementations/Images/BaseDynamicImageProvider.cs
@@ -20,6 +20,9 @@ namespace Emby.Server.Implementations.Images
public abstract class BaseDynamicImageProvider<T> : IHasItemChangeMonitor, IForcedProvider, ICustomMetadataProvider<T>, IHasOrder
where T : BaseItem
{
+ protected virtual IReadOnlyCollection<ImageType> SupportedImages { get; }
+ = new ImageType[] { ImageType.Primary };
+
protected IFileSystem FileSystem { get; private set; }
protected IProviderManager ProviderManager { get; private set; }
protected IApplicationPaths ApplicationPaths { get; private set; }
@@ -33,18 +36,7 @@ namespace Emby.Server.Implementations.Images
ImageProcessor = imageProcessor;
}
- protected virtual bool Supports(BaseItem item)
- {
- return true;
- }
-
- public virtual ImageType[] GetSupportedImages(BaseItem item)
- {
- return new ImageType[]
- {
- ImageType.Primary
- };
- }
+ protected virtual bool Supports(BaseItem _) => true;
public async Task<ItemUpdateType> FetchAsync(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
{
@@ -54,15 +46,14 @@ namespace Emby.Server.Implementations.Images
}
var updateType = ItemUpdateType.None;
- var supportedImages = GetSupportedImages(item);
- if (supportedImages.Contains(ImageType.Primary))
+ if (SupportedImages.Contains(ImageType.Primary))
{
var primaryResult = await FetchAsync(item, ImageType.Primary, options, cancellationToken).ConfigureAwait(false);
updateType = updateType | primaryResult;
}
- if (supportedImages.Contains(ImageType.Thumb))
+ if (SupportedImages.Contains(ImageType.Thumb))
{
var thumbResult = await FetchAsync(item, ImageType.Thumb, options, cancellationToken).ConfigureAwait(false);
updateType = updateType | thumbResult;
@@ -94,7 +85,7 @@ namespace Emby.Server.Implementations.Images
}
protected async Task<ItemUpdateType> FetchToFileInternal(BaseItem item,
- List<BaseItem> itemsWithImages,
+ IReadOnlyList<BaseItem> itemsWithImages,
ImageType imageType,
CancellationToken cancellationToken)
{
@@ -119,9 +110,9 @@ namespace Emby.Server.Implementations.Images
return ItemUpdateType.ImageUpdate;
}
- protected abstract List<BaseItem> GetItemsWithImages(BaseItem item);
+ protected abstract IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item);
- protected string CreateThumbCollage(BaseItem primaryItem, List<BaseItem> items, string outputPath)
+ protected string CreateThumbCollage(BaseItem primaryItem, IEnumerable<BaseItem> items, string outputPath)
{
return CreateCollage(primaryItem, items, outputPath, 640, 360);
}
@@ -132,38 +123,38 @@ namespace Emby.Server.Implementations.Images
.Select(i =>
{
var image = i.GetImageInfo(ImageType.Primary, 0);
-
if (image != null && image.IsLocalFile)
{
return image.Path;
}
- image = i.GetImageInfo(ImageType.Thumb, 0);
+ image = i.GetImageInfo(ImageType.Thumb, 0);
if (image != null && image.IsLocalFile)
{
return image.Path;
}
+
return null;
})
.Where(i => !string.IsNullOrEmpty(i));
}
- protected string CreatePosterCollage(BaseItem primaryItem, List<BaseItem> items, string outputPath)
+ protected string CreatePosterCollage(BaseItem primaryItem, IEnumerable<BaseItem> items, string outputPath)
{
return CreateCollage(primaryItem, items, outputPath, 400, 600);
}
- protected string CreateSquareCollage(BaseItem primaryItem, List<BaseItem> items, string outputPath)
+ protected string CreateSquareCollage(BaseItem primaryItem, IEnumerable<BaseItem> items, string outputPath)
{
return CreateCollage(primaryItem, items, outputPath, 600, 600);
}
- protected string CreateThumbCollage(BaseItem primaryItem, List<BaseItem> items, string outputPath, int width, int height)
+ protected string CreateThumbCollage(BaseItem primaryItem, IEnumerable<BaseItem> items, string outputPath, int width, int height)
{
return CreateCollage(primaryItem, items, outputPath, width, height);
}
- private string CreateCollage(BaseItem primaryItem, List<BaseItem> items, string outputPath, int width, int height)
+ private string CreateCollage(BaseItem primaryItem, IEnumerable<BaseItem> items, string outputPath, int width, int height)
{
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
@@ -192,7 +183,7 @@ namespace Emby.Server.Implementations.Images
public string Name => "Dynamic Image Provider";
protected virtual string CreateImage(BaseItem item,
- List<BaseItem> itemsWithImages,
+ IReadOnlyCollection<BaseItem> itemsWithImages,
string outputPathWithoutExtension,
ImageType imageType,
int imageIndex)
@@ -211,18 +202,15 @@ namespace Emby.Server.Implementations.Images
if (imageType == ImageType.Primary)
{
- if (item is UserView)
- {
- return CreateSquareCollage(item, itemsWithImages, outputPath);
- }
- if (item is Playlist || item is MusicGenre || item is Genre || item is PhotoAlbum)
+ if (item is UserView || item is Playlist || item is MusicGenre || item is Genre || item is PhotoAlbum)
{
return CreateSquareCollage(item, itemsWithImages, outputPath);
}
+
return CreatePosterCollage(item, itemsWithImages, outputPath);
}
- throw new ArgumentException("Unexpected image type");
+ throw new ArgumentException("Unexpected image type", nameof(imageType));
}
protected virtual int MaxImageAgeDays => 7;
@@ -234,13 +222,11 @@ namespace Emby.Server.Implementations.Images
return false;
}
- var supportedImages = GetSupportedImages(item);
-
- if (supportedImages.Contains(ImageType.Primary) && HasChanged(item, ImageType.Primary))
+ if (SupportedImages.Contains(ImageType.Primary) && HasChanged(item, ImageType.Primary))
{
return true;
}
- if (supportedImages.Contains(ImageType.Thumb) && HasChanged(item, ImageType.Thumb))
+ if (SupportedImages.Contains(ImageType.Thumb) && HasChanged(item, ImageType.Thumb))
{
return true;
}
@@ -285,7 +271,7 @@ namespace Emby.Server.Implementations.Images
public int Order => 0;
- protected string CreateSingleImage(List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType)
+ protected string CreateSingleImage(IEnumerable<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType)
{
var image = itemsWithImages
.Where(i => i.HasImage(imageType) && i.GetImageInfo(imageType, 0).IsLocalFile && Path.HasExtension(i.GetImagePath(imageType)))
diff --git a/Emby.Server.Implementations/Library/DefaultAuthenticationProvider.cs b/Emby.Server.Implementations/Library/DefaultAuthenticationProvider.cs
index 4013ac0c8..3d15a8afb 100644
--- a/Emby.Server.Implementations/Library/DefaultAuthenticationProvider.cs
+++ b/Emby.Server.Implementations/Library/DefaultAuthenticationProvider.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MediaBrowser.Controller.Authentication;
@@ -18,20 +19,64 @@ namespace Emby.Server.Implementations.Library
public string Name => "Default";
public bool IsEnabled => true;
-
+
+ // This is dumb and an artifact of the backwards way auth providers were designed.
+ // This version of authenticate was never meant to be called, but needs to be here for interface compat
+ // Only the providers that don't provide local user support use this
public Task<ProviderAuthenticationResult> Authenticate(string username, string password)
{
throw new NotImplementedException();
}
-
+
+ // This is the verson that we need to use for local users. Because reasons.
public Task<ProviderAuthenticationResult> Authenticate(string username, string password, User resolvedUser)
{
+ bool success = false;
if (resolvedUser == null)
{
throw new Exception("Invalid username or password");
}
- var success = string.Equals(GetPasswordHash(resolvedUser), GetHashedString(resolvedUser, password), StringComparison.OrdinalIgnoreCase);
+ // As long as jellyfin supports passwordless users, we need this little block here to accomodate
+ if (IsPasswordEmpty(resolvedUser, password))
+ {
+ return Task.FromResult(new ProviderAuthenticationResult
+ {
+ Username = username
+ });
+ }
+
+ ConvertPasswordFormat(resolvedUser);
+ byte[] passwordbytes = Encoding.UTF8.GetBytes(password);
+
+ PasswordHash readyHash = new PasswordHash(resolvedUser.Password);
+ byte[] calculatedHash;
+ string calculatedHashString;
+ if (_cryptographyProvider.GetSupportedHashMethods().Contains(readyHash.Id) || _cryptographyProvider.DefaultHashMethod == readyHash.Id)
+ {
+ if (string.IsNullOrEmpty(readyHash.Salt))
+ {
+ calculatedHash = _cryptographyProvider.ComputeHash(readyHash.Id, passwordbytes);
+ calculatedHashString = BitConverter.ToString(calculatedHash).Replace("-", string.Empty);
+ }
+ else
+ {
+ calculatedHash = _cryptographyProvider.ComputeHash(readyHash.Id, passwordbytes, readyHash.SaltBytes);
+ calculatedHashString = BitConverter.ToString(calculatedHash).Replace("-", string.Empty);
+ }
+
+ if (calculatedHashString == readyHash.Hash)
+ {
+ success = true;
+ // throw new Exception("Invalid username or password");
+ }
+ }
+ else
+ {
+ throw new Exception(string.Format($"Requested crypto method not available in provider: {readyHash.Id}"));
+ }
+
+ // var success = string.Equals(GetPasswordHash(resolvedUser), GetHashedString(resolvedUser, password), StringComparison.OrdinalIgnoreCase);
if (!success)
{
@@ -44,46 +89,86 @@ namespace Emby.Server.Implementations.Library
});
}
+ // This allows us to move passwords forward to the newformat without breaking. They are still insecure, unsalted, and dumb before a password change
+ // but at least they are in the new format.
+ private void ConvertPasswordFormat(User user)
+ {
+ if (string.IsNullOrEmpty(user.Password))
+ {
+ return;
+ }
+
+ if (!user.Password.Contains("$"))
+ {
+ string hash = user.Password;
+ user.Password = string.Format("$SHA1${0}", hash);
+ }
+
+ if (user.EasyPassword != null && !user.EasyPassword.Contains("$"))
+ {
+ string hash = user.EasyPassword;
+ user.EasyPassword = string.Format("$SHA1${0}", hash);
+ }
+ }
+
public Task<bool> HasPassword(User user)
{
var hasConfiguredPassword = !IsPasswordEmpty(user, GetPasswordHash(user));
return Task.FromResult(hasConfiguredPassword);
}
- private bool IsPasswordEmpty(User user, string passwordHash)
+ private bool IsPasswordEmpty(User user, string password)
{
- return string.Equals(passwordHash, GetEmptyHashedString(user), StringComparison.OrdinalIgnoreCase);
+ return (string.IsNullOrEmpty(user.Password) && string.IsNullOrEmpty(password));
}
public Task ChangePassword(User user, string newPassword)
{
- string newPasswordHash = null;
+ ConvertPasswordFormat(user);
+ // This is needed to support changing a no password user to a password user
+ if (string.IsNullOrEmpty(user.Password))
+ {
+ PasswordHash newPasswordHash = new PasswordHash(_cryptographyProvider);
+ newPasswordHash.SaltBytes = _cryptographyProvider.GenerateSalt();
+ newPasswordHash.Salt = PasswordHash.ConvertToByteString(newPasswordHash.SaltBytes);
+ newPasswordHash.Id = _cryptographyProvider.DefaultHashMethod;
+ newPasswordHash.Hash = GetHashedStringChangeAuth(newPassword, newPasswordHash);
+ user.Password = newPasswordHash.ToString();
+ return Task.CompletedTask;
+ }
- if (newPassword != null)
+ PasswordHash passwordHash = new PasswordHash(user.Password);
+ if (passwordHash.Id == "SHA1" && string.IsNullOrEmpty(passwordHash.Salt))
{
- newPasswordHash = GetHashedString(user, newPassword);
+ passwordHash.SaltBytes = _cryptographyProvider.GenerateSalt();
+ passwordHash.Salt = PasswordHash.ConvertToByteString(passwordHash.SaltBytes);
+ passwordHash.Id = _cryptographyProvider.DefaultHashMethod;
+ passwordHash.Hash = GetHashedStringChangeAuth(newPassword, passwordHash);
+ }
+ else if (newPassword != null)
+ {
+ passwordHash.Hash = GetHashedString(user, newPassword);
}
- if (string.IsNullOrWhiteSpace(newPasswordHash))
+ if (string.IsNullOrWhiteSpace(passwordHash.Hash))
{
- throw new ArgumentNullException(nameof(newPasswordHash));
+ throw new ArgumentNullException(nameof(passwordHash.Hash));
}
- user.Password = newPasswordHash;
+ user.Password = passwordHash.ToString();
return Task.CompletedTask;
}
public string GetPasswordHash(User user)
{
- return string.IsNullOrEmpty(user.Password)
- ? GetEmptyHashedString(user)
- : user.Password;
+ return user.Password;
}
- public string GetEmptyHashedString(User user)
+ public string GetHashedStringChangeAuth(string newPassword, PasswordHash passwordHash)
{
- return GetHashedString(user, string.Empty);
+ passwordHash.HashBytes = Encoding.UTF8.GetBytes(newPassword);
+ return PasswordHash.ConvertToByteString(_cryptographyProvider.ComputeHash(passwordHash));
}
/// <summary>
@@ -91,14 +176,28 @@ namespace Emby.Server.Implementations.Library
/// </summary>
public string GetHashedString(User user, string str)
{
- var salt = user.Salt;
- if (salt != null)
+ PasswordHash passwordHash;
+ if (string.IsNullOrEmpty(user.Password))
+ {
+ passwordHash = new PasswordHash(_cryptographyProvider);
+ }
+ else
{
- // return BCrypt.HashPassword(str, salt);
+ ConvertPasswordFormat(user);
+ passwordHash = new PasswordHash(user.Password);
}
- // legacy
- return BitConverter.ToString(_cryptographyProvider.ComputeSHA1(Encoding.UTF8.GetBytes(str))).Replace("-", string.Empty);
+ if (passwordHash.SaltBytes != null)
+ {
+ // the password is modern format with PBKDF and we should take advantage of that
+ passwordHash.HashBytes = Encoding.UTF8.GetBytes(str);
+ return PasswordHash.ConvertToByteString(_cryptographyProvider.ComputeHash(passwordHash));
+ }
+ else
+ {
+ // the password has no salt and should be called with the older method for safety
+ return PasswordHash.ConvertToByteString(_cryptographyProvider.ComputeHash(passwordHash.Id, Encoding.UTF8.GetBytes(str)));
+ }
}
}
}
diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs
index 87809cae8..1673e3777 100644
--- a/Emby.Server.Implementations/Library/LibraryManager.cs
+++ b/Emby.Server.Implementations/Library/LibraryManager.cs
@@ -58,22 +58,23 @@ namespace Emby.Server.Implementations.Library
private ILibraryPostScanTask[] PostscanTasks { get; set; }
/// <summary>
- /// Gets the intro providers.
+ /// Gets or sets the intro providers.
/// </summary>
/// <value>The intro providers.</value>
private IIntroProvider[] IntroProviders { get; set; }
/// <summary>
- /// Gets the list of entity resolution ignore rules
+ /// Gets or sets the list of entity resolution ignore rules
/// </summary>
/// <value>The entity resolution ignore rules.</value>
private IResolverIgnoreRule[] EntityResolutionIgnoreRules { get; set; }
/// <summary>
- /// Gets the list of currently registered entity resolvers
+ /// Gets or sets the list of currently registered entity resolvers
/// </summary>
/// <value>The entity resolvers enumerable.</value>
private IItemResolver[] EntityResolvers { get; set; }
+
private IMultiItemResolver[] MultiItemResolvers { get; set; }
/// <summary>
@@ -83,7 +84,7 @@ namespace Emby.Server.Implementations.Library
private IBaseItemComparer[] Comparers { get; set; }
/// <summary>
- /// Gets the active item repository
+ /// Gets or sets the active item repository
/// </summary>
/// <value>The item repository.</value>
public IItemRepository ItemRepository { get; set; }
@@ -133,12 +134,14 @@ namespace Emby.Server.Implementations.Library
private readonly Func<IProviderManager> _providerManagerFactory;
private readonly Func<IUserViewManager> _userviewManager;
public bool IsScanRunning { get; private set; }
+
private IServerApplicationHost _appHost;
/// <summary>
/// The _library items cache
/// </summary>
private readonly ConcurrentDictionary<Guid, BaseItem> _libraryItemsCache;
+
/// <summary>
/// Gets the library items cache.
/// </summary>
@@ -150,7 +153,8 @@ namespace Emby.Server.Implementations.Library
/// <summary>
/// Initializes a new instance of the <see cref="LibraryManager" /> class.
/// </summary>
- /// <param name="logger">The logger.</param>
+ /// <param name="appHost">The application host</param>
+ /// <param name="loggerFactory">The logger factory.</param>
/// <param name="taskManager">The task manager.</param>
/// <param name="userManager">The user manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
@@ -167,6 +171,7 @@ namespace Emby.Server.Implementations.Library
Func<IProviderManager> providerManagerFactory,
Func<IUserViewManager> userviewManager)
{
+ _appHost = appHost;
_logger = loggerFactory.CreateLogger(nameof(LibraryManager));
_taskManager = taskManager;
_userManager = userManager;
@@ -176,7 +181,7 @@ namespace Emby.Server.Implementations.Library
_fileSystem = fileSystem;
_providerManagerFactory = providerManagerFactory;
_userviewManager = userviewManager;
- _appHost = appHost;
+
_libraryItemsCache = new ConcurrentDictionary<Guid, BaseItem>();
ConfigurationManager.ConfigurationUpdated += ConfigurationUpdated;
@@ -191,8 +196,9 @@ namespace Emby.Server.Implementations.Library
/// <param name="resolvers">The resolvers.</param>
/// <param name="introProviders">The intro providers.</param>
/// <param name="itemComparers">The item comparers.</param>
- /// <param name="postscanTasks">The postscan tasks.</param>
- public void AddParts(IEnumerable<IResolverIgnoreRule> rules,
+ /// <param name="postscanTasks">The post scan tasks.</param>
+ public void AddParts(
+ IEnumerable<IResolverIgnoreRule> rules,
IEnumerable<IItemResolver> resolvers,
IEnumerable<IIntroProvider> introProviders,
IEnumerable<IBaseItemComparer> itemComparers,
@@ -203,24 +209,19 @@ namespace Emby.Server.Implementations.Library
MultiItemResolvers = EntityResolvers.OfType<IMultiItemResolver>().ToArray();
IntroProviders = introProviders.ToArray();
Comparers = itemComparers.ToArray();
-
- PostscanTasks = postscanTasks.OrderBy(i =>
- {
- var hasOrder = i as IHasOrder;
-
- return hasOrder == null ? 0 : hasOrder.Order;
-
- }).ToArray();
+ PostscanTasks = postscanTasks.ToArray();
}
/// <summary>
/// The _root folder
/// </summary>
private volatile AggregateFolder _rootFolder;
+
/// <summary>
/// The _root folder sync lock
/// </summary>
private readonly object _rootFolderSyncLock = new object();
+
/// <summary>
/// Gets the root folder.
/// </summary>
@@ -239,11 +240,13 @@ namespace Emby.Server.Implementations.Library
}
}
}
+
return _rootFolder;
}
}
private bool _wizardCompleted;
+
/// <summary>
/// Records the configuration values.
/// </summary>
@@ -258,7 +261,7 @@ namespace Emby.Server.Implementations.Library
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
- void ConfigurationUpdated(object sender, EventArgs e)
+ private void ConfigurationUpdated(object sender, EventArgs e)
{
var config = ConfigurationManager.Configuration;
@@ -278,6 +281,7 @@ namespace Emby.Server.Implementations.Library
{
throw new ArgumentNullException(nameof(item));
}
+
if (item is IItemByName)
{
if (!(item is MusicArtist))
@@ -285,18 +289,7 @@ namespace Emby.Server.Implementations.Library
return;
}
}
-
- else if (item.IsFolder)
- {
- //if (!(item is ICollectionFolder) && !(item is UserView) && !(item is Channel) && !(item is AggregateFolder))
- //{
- // if (item.SourceType != SourceType.Library)
- // {
- // return;
- // }
- //}
- }
- else
+ else if (!item.IsFolder)
{
if (!(item is Video) && !(item is LiveTvChannel))
{
@@ -345,12 +338,14 @@ namespace Emby.Server.Implementations.Library
// channel no longer installed
}
}
+
options.DeleteFileLocation = false;
}
if (item is LiveTvProgram)
{
- _logger.LogDebug("Deleting item, Type: {0}, Name: {1}, Path: {2}, Id: {3}",
+ _logger.LogDebug(
+ "Deleting item, Type: {0}, Name: {1}, Path: {2}, Id: {3}",
item.GetType().Name,
item.Name ?? "Unknown name",
item.Path ?? string.Empty,
@@ -358,7 +353,8 @@ namespace Emby.Server.Implementations.Library
}
else
{
- _logger.LogInformation("Deleting item, Type: {0}, Name: {1}, Path: {2}, Id: {3}",
+ _logger.LogInformation(
+ "Deleting item, Type: {0}, Name: {1}, Path: {2}, Id: {3}",
item.GetType().Name,
item.Name ?? "Unknown name",
item.Path ?? string.Empty,
@@ -371,19 +367,20 @@ namespace Emby.Server.Implementations.Library
foreach (var metadataPath in GetMetadataPaths(item, children))
{
- _logger.LogDebug("Deleting path {0}", metadataPath);
+ if (!Directory.Exists(metadataPath))
+ {
+ continue;
+ }
+
+ _logger.LogDebug("Deleting path {MetadataPath}", metadataPath);
try
{
Directory.Delete(metadataPath, true);
}
- catch (IOException)
- {
-
- }
catch (Exception ex)
{
- _logger.LogError(ex, "Error deleting {metadataPath}", metadataPath);
+ _logger.LogError(ex, "Error deleting {MetadataPath}", metadataPath);
}
}
@@ -497,12 +494,13 @@ namespace Emby.Server.Implementations.Library
{
throw new ArgumentNullException(nameof(key));
}
+
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
- if (key.StartsWith(ConfigurationManager.ApplicationPaths.ProgramDataPath))
+ if (key.StartsWith(ConfigurationManager.ApplicationPaths.ProgramDataPath, StringComparison.Ordinal))
{
// Try to normalize paths located underneath program-data in an attempt to make them more portable
key = key.Substring(ConfigurationManager.ApplicationPaths.ProgramDataPath.Length)
@@ -520,13 +518,11 @@ namespace Emby.Server.Implementations.Library
return key.GetMD5();
}
- public BaseItem ResolvePath(FileSystemMetadata fileInfo,
- Folder parent = null)
- {
- return ResolvePath(fileInfo, new DirectoryService(_logger, _fileSystem), null, parent);
- }
+ public BaseItem ResolvePath(FileSystemMetadata fileInfo, Folder parent = null)
+ => ResolvePath(fileInfo, new DirectoryService(_logger, _fileSystem), null, parent);
- private BaseItem ResolvePath(FileSystemMetadata fileInfo,
+ private BaseItem ResolvePath(
+ FileSystemMetadata fileInfo,
IDirectoryService directoryService,
IItemResolver[] resolvers,
Folder parent = null,
@@ -581,7 +577,7 @@ namespace Emby.Server.Implementations.Library
{
_logger.LogError(ex, "Error in GetFilteredFileSystemEntries isPhysicalRoot: {0} IsVf: {1}", isPhysicalRoot, isVf);
- files = new FileSystemMetadata[] { };
+ files = Array.Empty<FileSystemMetadata>();
}
else
{
@@ -609,13 +605,7 @@ namespace Emby.Server.Implementations.Library
}
public bool IgnoreFile(FileSystemMetadata file, BaseItem parent)
- {
- if (EntityResolutionIgnoreRules.Any(r => r.ShouldIgnore(file, parent)))
- {
- return true;
- }
- return false;
- }
+ => EntityResolutionIgnoreRules.Any(r => r.ShouldIgnore(file, parent));
public List<FileSystemMetadata> NormalizeRootPathList(IEnumerable<FileSystemMetadata> paths)
{
@@ -655,7 +645,8 @@ namespace Emby.Server.Implementations.Library
return ResolvePaths(files, directoryService, parent, libraryOptions, collectionType, EntityResolvers);
}
- public IEnumerable<BaseItem> ResolvePaths(IEnumerable<FileSystemMetadata> files,
+ public IEnumerable<BaseItem> ResolvePaths(
+ IEnumerable<FileSystemMetadata> files,
IDirectoryService directoryService,
Folder parent,
LibraryOptions libraryOptions,
@@ -681,6 +672,7 @@ namespace Emby.Server.Implementations.Library
{
ResolverHelper.SetInitialItemValues(item, parent, _fileSystem, this, directoryService);
}
+
items.AddRange(ResolveFileList(result.ExtraFiles, directoryService, parent, collectionType, resolvers, libraryOptions));
return items;
}
@@ -690,7 +682,8 @@ namespace Emby.Server.Implementations.Library
return ResolveFileList(fileList, directoryService, parent, collectionType, resolvers, libraryOptions);
}
- private IEnumerable<BaseItem> ResolveFileList(IEnumerable<FileSystemMetadata> fileList,
+ private IEnumerable<BaseItem> ResolveFileList(
+ IEnumerable<FileSystemMetadata> fileList,
IDirectoryService directoryService,
Folder parent,
string collectionType,
@@ -775,6 +768,7 @@ namespace Emby.Server.Implementations.Library
private volatile UserRootFolder _userRootFolder;
private readonly object _syncLock = new object();
+
public Folder GetUserRootFolder()
{
if (_userRootFolder == null)
@@ -819,8 +813,6 @@ namespace Emby.Server.Implementations.Library
throw new ArgumentNullException(nameof(path));
}
- //_logger.LogInformation("FindByPath {0}", path);
-
var query = new InternalItemsQuery
{
Path = path,
@@ -894,7 +886,6 @@ namespace Emby.Server.Implementations.Library
/// </summary>
/// <param name="value">The value.</param>
/// <returns>Task{Year}.</returns>
- /// <exception cref="ArgumentOutOfRangeException"></exception>
public Year GetYear(int value)
{
if (value <= 0)
@@ -1036,20 +1027,25 @@ namespace Emby.Server.Implementations.Library
private async Task ValidateTopLibraryFolders(CancellationToken cancellationToken)
{
- var rootChildren = RootFolder.Children.ToList();
- rootChildren = GetUserRootFolder().Children.ToList();
-
await RootFolder.RefreshMetadata(cancellationToken).ConfigureAwait(false);
// Start by just validating the children of the root, but go no further
- await RootFolder.ValidateChildren(new SimpleProgress<double>(), cancellationToken, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), recursive: false);
+ await RootFolder.ValidateChildren(
+ new SimpleProgress<double>(),
+ cancellationToken,
+ new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)),
+ recursive: false).ConfigureAwait(false);
await GetUserRootFolder().RefreshMetadata(cancellationToken).ConfigureAwait(false);
- await GetUserRootFolder().ValidateChildren(new SimpleProgress<double>(), cancellationToken, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), recursive: false).ConfigureAwait(false);
+ await GetUserRootFolder().ValidateChildren(
+ new SimpleProgress<double>(),
+ cancellationToken,
+ new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)),
+ recursive: false).ConfigureAwait(false);
// Quickly scan CollectionFolders for changes
- foreach (var folder in GetUserRootFolder().Children.OfType<Folder>().ToList())
+ foreach (var folder in GetUserRootFolder().Children.OfType<Folder>())
{
await folder.RefreshMetadata(cancellationToken).ConfigureAwait(false);
}
@@ -1213,7 +1209,7 @@ namespace Emby.Server.Implementations.Library
private string GetCollectionType(string path)
{
return _fileSystem.GetFilePaths(path, new[] { ".collection" }, true, false)
- .Select(i => Path.GetFileNameWithoutExtension(i))
+ .Select(Path.GetFileNameWithoutExtension)
.FirstOrDefault(i => !string.IsNullOrEmpty(i));
}
@@ -1225,9 +1221,9 @@ namespace Emby.Server.Implementations.Library
/// <exception cref="ArgumentNullException">id</exception>
public BaseItem GetItemById(Guid id)
{
- if (id.Equals(Guid.Empty))
+ if (id == Guid.Empty)
{
- throw new ArgumentNullException(nameof(id));
+ throw new ArgumentException("Guid can't be empty", nameof(id));
}
if (LibraryItemsCache.TryGetValue(id, out BaseItem item))
@@ -1237,8 +1233,6 @@ namespace Emby.Server.Implementations.Library
item = RetrieveItem(id);
- //_logger.LogDebug("GetitemById {0}", id);
-
if (item != null)
{
RegisterItem(item);
@@ -1333,7 +1327,7 @@ namespace Emby.Server.Implementations.Library
return ItemRepository.GetItemIdsList(query);
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetStudios(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetStudios(InternalItemsQuery query)
{
if (query.User != null)
{
@@ -1344,7 +1338,7 @@ namespace Emby.Server.Implementations.Library
return ItemRepository.GetStudios(query);
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetGenres(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetGenres(InternalItemsQuery query)
{
if (query.User != null)
{
@@ -1355,7 +1349,7 @@ namespace Emby.Server.Implementations.Library
return ItemRepository.GetGenres(query);
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetMusicGenres(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetMusicGenres(InternalItemsQuery query)
{
if (query.User != null)
{
@@ -1366,7 +1360,7 @@ namespace Emby.Server.Implementations.Library
return ItemRepository.GetMusicGenres(query);
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetAllArtists(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetAllArtists(InternalItemsQuery query)
{
if (query.User != null)
{
@@ -1377,7 +1371,7 @@ namespace Emby.Server.Implementations.Library
return ItemRepository.GetAllArtists(query);
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetArtists(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetArtists(InternalItemsQuery query)
{
if (query.User != null)
{
@@ -1397,17 +1391,7 @@ namespace Emby.Server.Implementations.Library
var parents = query.AncestorIds.Select(i => GetItemById(i)).ToList();
- if (parents.All(i =>
- {
- if (i is ICollectionFolder || i is UserView)
- {
- return true;
- }
-
- //_logger.LogDebug("Query requires ancestor query due to type: " + i.GetType().Name);
- return false;
-
- }))
+ if (parents.All(i => i is ICollectionFolder || i is UserView))
{
// Optimize by querying against top level views
query.TopParentIds = parents.SelectMany(i => GetTopParentIdsForQuery(i, query.User)).ToArray();
@@ -1421,7 +1405,7 @@ namespace Emby.Server.Implementations.Library
}
}
- public QueryResult<Tuple<BaseItem, ItemCounts>> GetAlbumArtists(InternalItemsQuery query)
+ public QueryResult<(BaseItem, ItemCounts)> GetAlbumArtists(InternalItemsQuery query)
{
if (query.User != null)
{
@@ -1463,17 +1447,7 @@ namespace Emby.Server.Implementations.Library
private void SetTopParentIdsOrAncestors(InternalItemsQuery query, List<BaseItem> parents)
{
- if (parents.All(i =>
- {
- if (i is ICollectionFolder || i is UserView)
- {
- return true;
- }
-
- //_logger.LogDebug("Query requires ancestor query due to type: " + i.GetType().Name);
- return false;
-
- }))
+ if (parents.All(i => i is ICollectionFolder || i is UserView))
{
// Optimize by querying against top level views
query.TopParentIds = parents.SelectMany(i => GetTopParentIdsForQuery(i, query.User)).ToArray();
@@ -1522,11 +1496,9 @@ namespace Emby.Server.Implementations.Library
private IEnumerable<Guid> GetTopParentIdsForQuery(BaseItem item, User user)
{
- var view = item as UserView;
-
- if (view != null)
+ if (item is UserView view)
{
- if (string.Equals(view.ViewType, CollectionType.LiveTv))
+ if (string.Equals(view.ViewType, CollectionType.LiveTv, StringComparison.Ordinal))
{
return new[] { view.Id };
}
@@ -1539,8 +1511,10 @@ namespace Emby.Server.Implementations.Library
{
return GetTopParentIdsForQuery(displayParent, user);
}
+
return Array.Empty<Guid>();
}
+
if (!view.ParentId.Equals(Guid.Empty))
{
var displayParent = GetItemById(view.ParentId);
@@ -1548,6 +1522,7 @@ namespace Emby.Server.Implementations.Library
{
return GetTopParentIdsForQuery(displayParent, user);
}
+
return Array.Empty<Guid>();
}
@@ -1561,11 +1536,11 @@ namespace Emby.Server.Implementations.Library
.Where(i => user.IsFolderGrouped(i.Id))
.SelectMany(i => GetTopParentIdsForQuery(i, user));
}
+
return Array.Empty<Guid>();
}
- var collectionFolder = item as CollectionFolder;
- if (collectionFolder != null)
+ if (item is CollectionFolder collectionFolder)
{
return collectionFolder.PhysicalFolderIds;
}
@@ -1575,6 +1550,7 @@ namespace Emby.Server.Implementations.Library
{
return new[] { topParent.Id };
}
+
return Array.Empty<Guid>();
}
@@ -1771,19 +1747,16 @@ namespace Emby.Server.Implementations.Library
{
var comparer = Comparers.FirstOrDefault(c => string.Equals(name, c.Name, StringComparison.OrdinalIgnoreCase));
- if (comparer != null)
+ // If it requires a user, create a new one, and assign the user
+ if (comparer is IUserBaseItemComparer)
{
- // If it requires a user, create a new one, and assign the user
- if (comparer is IUserBaseItemComparer)
- {
- var userComparer = (IUserBaseItemComparer)Activator.CreateInstance(comparer.GetType());
+ var userComparer = (IUserBaseItemComparer)Activator.CreateInstance(comparer.GetType());
- userComparer.User = user;
- userComparer.UserManager = _userManager;
- userComparer.UserDataRepository = _userDataRepository;
+ userComparer.User = user;
+ userComparer.UserManager = _userManager;
+ userComparer.UserDataRepository = _userDataRepository;
- return userComparer;
- }
+ return userComparer;
}
return comparer;
@@ -1794,7 +1767,6 @@ namespace Emby.Server.Implementations.Library
/// </summary>
/// <param name="item">The item.</param>
/// <param name="parent">The parent item.</param>
- /// <returns>Task.</returns>
public void CreateItem(BaseItem item, BaseItem parent)
{
CreateItems(new[] { item }, parent, CancellationToken.None);
@@ -1804,22 +1776,23 @@ namespace Emby.Server.Implementations.Library
/// Creates the items.
/// </summary>
/// <param name="items">The items.</param>
+ /// <param name="parent">The parent item</param>
/// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task.</returns>
public void CreateItems(IEnumerable<BaseItem> items, BaseItem parent, CancellationToken cancellationToken)
{
- var list = items.ToList();
+ // Don't iterate multiple times
+ var itemsList = items.ToList();
- ItemRepository.SaveItems(list, cancellationToken);
+ ItemRepository.SaveItems(itemsList, cancellationToken);
- foreach (var item in list)
+ foreach (var item in itemsList)
{
RegisterItem(item);
}
if (ItemAdded != null)
{
- foreach (var item in list)
+ foreach (var item in itemsList)
{
// With the live tv guide this just creates too much noise
if (item.SourceType != SourceType.Library)
@@ -1829,11 +1802,13 @@ namespace Emby.Server.Implementations.Library
try
{
- ItemAdded(this, new ItemChangeEventArgs
- {
- Item = item,
- Parent = parent ?? item.GetParent()
- });
+ ItemAdded(
+ this,
+ new ItemChangeEventArgs
+ {
+ Item = item,
+ Parent = parent ?? item.GetParent()
+ });
}
catch (Exception ex)
{
@@ -1853,9 +1828,12 @@ namespace Emby.Server.Implementations.Library
/// <summary>
/// Updates the item.
/// </summary>
- public void UpdateItems(List<BaseItem> items, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
+ public void UpdateItems(IEnumerable<BaseItem> items, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
{
- foreach (var item in items)
+ // Don't iterate multiple times
+ var itemsList = items.ToList();
+
+ foreach (var item in itemsList)
{
if (item.IsFileProtocol)
{
@@ -1867,14 +1845,11 @@ namespace Emby.Server.Implementations.Library
RegisterItem(item);
}
- //var logName = item.LocationType == LocationType.Remote ? item.Name ?? item.Path : item.Path ?? item.Name;
- //_logger.LogDebug("Saving {0} to database.", logName);
-
- ItemRepository.SaveItems(items, cancellationToken);
+ ItemRepository.SaveItems(itemsList, cancellationToken);
if (ItemUpdated != null)
{
- foreach (var item in items)
+ foreach (var item in itemsList)
{
// With the live tv guide this just creates too much noise
if (item.SourceType != SourceType.Library)
@@ -1884,12 +1859,14 @@ namespace Emby.Server.Implementations.Library
try
{
- ItemUpdated(this, new ItemChangeEventArgs
- {
- Item = item,
- Parent = parent,
- UpdateReason = updateReason
- });
+ ItemUpdated(
+ this,
+ new ItemChangeEventArgs
+ {
+ Item = item,
+ Parent = parent,
+ UpdateReason = updateReason
+ });
}
catch (Exception ex)
{
@@ -1903,29 +1880,32 @@ namespace Emby.Server.Implementations.Library
/// Updates the item.
/// </summary>
/// <param name="item">The item.</param>
+ /// <param name="parent">The parent item.</param>
/// <param name="updateReason">The update reason.</param>
/// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task.</returns>
public void UpdateItem(BaseItem item, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken)
{
- UpdateItems(new List<BaseItem> { item }, parent, updateReason, cancellationToken);
+ UpdateItems(new [] { item }, parent, updateReason, cancellationToken);
}
/// <summary>
/// Reports the item removed.
/// </summary>
/// <param name="item">The item.</param>
+ /// <param name="parent">The parent item.</param>
public void ReportItemRemoved(BaseItem item, BaseItem parent)
{
if (ItemRemoved != null)
{
try
{
- ItemRemoved(this, new ItemChangeEventArgs
- {
- Item = item,
- Parent = parent
- });
+ ItemRemoved(
+ this,
+ new ItemChangeEventArgs
+ {
+ Item = item,
+ Parent = parent
+ });
}
catch (Exception ex)
{
@@ -2005,9 +1985,7 @@ namespace Emby.Server.Implementations.Library
.FirstOrDefault();
}
- var options = collectionFolder == null ? new LibraryOptions() : collectionFolder.GetLibraryOptions();
-
- return options;
+ return collectionFolder == null ? new LibraryOptions() : collectionFolder.GetLibraryOptions();
}
public string GetContentType(BaseItem item)
@@ -2017,11 +1995,13 @@ namespace Emby.Server.Implementations.Library
{
return configuredContentType;
}
+
configuredContentType = GetConfiguredContentType(item, true);
if (!string.IsNullOrEmpty(configuredContentType))
{
return configuredContentType;
}
+
return GetInheritedContentType(item);
}
@@ -2051,22 +2031,21 @@ namespace Emby.Server.Implementations.Library
public string GetConfiguredContentType(BaseItem item, bool inheritConfiguredPath)
{
- var collectionFolder = item as ICollectionFolder;
- if (collectionFolder != null)
+ if (item is ICollectionFolder collectionFolder)
{
return collectionFolder.CollectionType;
}
+
return GetContentTypeOverride(item.ContainingFolderPath, inheritConfiguredPath);
}
private string GetContentTypeOverride(string path, bool inherit)
{
- var nameValuePair = ConfigurationManager.Configuration.ContentTypes.FirstOrDefault(i => _fileSystem.AreEqual(i.Name, path) || (inherit && !string.IsNullOrEmpty(i.Name) && _fileSystem.ContainsSubPath(i.Name, path)));
- if (nameValuePair != null)
- {
- return nameValuePair.Value;
- }
- return null;
+ var nameValuePair = ConfigurationManager.Configuration.ContentTypes
+ .FirstOrDefault(i => _fileSystem.AreEqual(i.Name, path)
+ || (inherit && !string.IsNullOrEmpty(i.Name)
+ && _fileSystem.ContainsSubPath(i.Name, path)));
+ return nameValuePair?.Value;
}
private string GetTopFolderContentType(BaseItem item)
@@ -2083,6 +2062,7 @@ namespace Emby.Server.Implementations.Library
{
break;
}
+
item = parent;
}
@@ -2094,9 +2074,9 @@ namespace Emby.Server.Implementations.Library
}
private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromHours(24);
- //private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromMinutes(1);
- public UserView GetNamedView(User user,
+ public UserView GetNamedView(
+ User user,
string name,
string viewType,
string sortName)
@@ -2104,13 +2084,15 @@ namespace Emby.Server.Implementations.Library
return GetNamedView(user, name, Guid.Empty, viewType, sortName);
}
- public UserView GetNamedView(string name,
+ public UserView GetNamedView(
+ string name,
string viewType,
string sortName)
{
- var path = Path.Combine(ConfigurationManager.ApplicationPaths.InternalMetadataPath, "views");
-
- path = Path.Combine(path, _fileSystem.GetValidFilename(viewType));
+ var path = Path.Combine(
+ ConfigurationManager.ApplicationPaths.InternalMetadataPath,
+ "views",
+ _fileSystem.GetValidFilename(viewType));
var id = GetNewItemId(path + "_namedview_" + name, typeof(UserView));
@@ -2146,7 +2128,8 @@ namespace Emby.Server.Implementations.Library
return item;
}
- public UserView GetNamedView(User user,
+ public UserView GetNamedView(
+ User user,
string name,
Guid parentId,
string viewType,
@@ -2175,10 +2158,10 @@ namespace Emby.Server.Implementations.Library
Name = name,
ViewType = viewType,
ForcedSortName = sortName,
- UserId = user.Id
+ UserId = user.Id,
+ DisplayParentId = parentId
};
- item.DisplayParentId = parentId;
CreateItem(item, null);
@@ -2195,20 +2178,24 @@ namespace Emby.Server.Implementations.Library
if (refresh)
{
- _providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
- {
- // Need to force save to increment DateLastSaved
- ForceSave = true
+ _providerManagerFactory().QueueRefresh(
+ item.Id,
+ new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
+ {
+ // Need to force save to increment DateLastSaved
+ ForceSave = true
- }, RefreshPriority.Normal);
+ },
+ RefreshPriority.Normal);
}
return item;
}
- public UserView GetShadowView(BaseItem parent,
- string viewType,
- string sortName)
+ public UserView GetShadowView(
+ BaseItem parent,
+ string viewType,
+ string sortName)
{
if (parent == null)
{
@@ -2259,18 +2246,21 @@ namespace Emby.Server.Implementations.Library
if (refresh)
{
- _providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
- {
- // Need to force save to increment DateLastSaved
- ForceSave = true
-
- }, RefreshPriority.Normal);
+ _providerManagerFactory().QueueRefresh(
+ item.Id,
+ new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
+ {
+ // Need to force save to increment DateLastSaved
+ ForceSave = true
+ },
+ RefreshPriority.Normal);
}
return item;
}
- public UserView GetNamedView(string name,
+ public UserView GetNamedView(
+ string name,
Guid parentId,
string viewType,
string sortName,
@@ -2333,17 +2323,21 @@ namespace Emby.Server.Implementations.Library
if (refresh)
{
- _providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
- {
- // Need to force save to increment DateLastSaved
- ForceSave = true
- }, RefreshPriority.Normal);
+ _providerManagerFactory().QueueRefresh(
+ item.Id,
+ new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
+ {
+ // Need to force save to increment DateLastSaved
+ ForceSave = true
+ },
+ RefreshPriority.Normal);
}
return item;
}
- public void AddExternalSubtitleStreams(List<MediaStream> streams,
+ public void AddExternalSubtitleStreams(
+ List<MediaStream> streams,
string videoPath,
string[] files)
{
@@ -2447,6 +2441,7 @@ namespace Emby.Server.Implementations.Library
{
changed = true;
}
+
episode.IndexNumber = episodeInfo.EpisodeNumber;
}
@@ -2456,6 +2451,7 @@ namespace Emby.Server.Implementations.Library
{
changed = true;
}
+
episode.IndexNumberEnd = episodeInfo.EndingEpsiodeNumber;
}
@@ -2465,6 +2461,7 @@ namespace Emby.Server.Implementations.Library
{
changed = true;
}
+
episode.ParentIndexNumber = episodeInfo.SeasonNumber;
}
}
@@ -2494,6 +2491,7 @@ namespace Emby.Server.Implementations.Library
private NamingOptions _namingOptions;
private string[] _videoFileExtensions;
+
private NamingOptions GetNamingOptionsInternal()
{
if (_namingOptions == null)
@@ -2690,7 +2688,7 @@ namespace Emby.Server.Implementations.Library
var newPath = path.Replace(from, to, StringComparison.OrdinalIgnoreCase);
var changed = false;
- if (!string.Equals(newPath, path))
+ if (!string.Equals(newPath, path, StringComparison.Ordinal))
{
if (to.IndexOf('/') != -1)
{
@@ -2814,6 +2812,7 @@ namespace Emby.Server.Implementations.Library
{
continue;
}
+
throw;
}
}
@@ -2918,6 +2917,7 @@ namespace Emby.Server.Implementations.Library
}
private const string ShortcutFileExtension = ".mblink";
+
public void AddMediaPath(string virtualFolderName, MediaPathInfo pathInfo)
{
AddMediaPathInternal(virtualFolderName, pathInfo, true);
@@ -2934,7 +2934,7 @@ namespace Emby.Server.Implementations.Library
if (string.IsNullOrWhiteSpace(path))
{
- throw new ArgumentNullException(nameof(path));
+ throw new ArgumentException(nameof(path));
}
if (!Directory.Exists(path))
diff --git a/Emby.Server.Implementations/Library/UserManager.cs b/Emby.Server.Implementations/Library/UserManager.cs
index 15cbbdb5a..4cf703add 100644
--- a/Emby.Server.Implementations/Library/UserManager.cs
+++ b/Emby.Server.Implementations/Library/UserManager.cs
@@ -4,6 +4,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Events;
@@ -168,9 +169,9 @@ namespace Emby.Server.Implementations.Library
/// <exception cref="ArgumentNullException"></exception>
public User GetUserById(Guid id)
{
- if (id.Equals(Guid.Empty))
+ if (id == Guid.Empty)
{
- throw new ArgumentNullException(nameof(id));
+ throw new ArgumentException(nameof(id), "Guid can't be empty");
}
return Users.FirstOrDefault(u => u.Id == id);
@@ -213,22 +214,17 @@ namespace Emby.Server.Implementations.Library
}
}
- public bool IsValidUsername(string username)
+ public static bool IsValidUsername(string username)
{
- // Usernames can contain letters (a-z), numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)
- foreach (var currentChar in username)
- {
- if (!IsValidUsernameCharacter(currentChar))
- {
- return false;
- }
- }
- return true;
+ // This is some regex that matches only on unicode "word" characters, as well as -, _ and @
+ // In theory this will cut out most if not all 'control' characters which should help minimize any weirdness
+ // Usernames can contain letters (a-z + whatever else unicode is cool with), numbers (0-9), at-signs (@), dashes (-), underscores (_), apostrophes ('), and periods (.)
+ return Regex.IsMatch(username, @"^[\w\-'._@]*$");
}
private static bool IsValidUsernameCharacter(char i)
{
- return !char.Equals(i, '<') && !char.Equals(i, '>');
+ return IsValidUsername(i.ToString());
}
public string MakeValidUsername(string username)
@@ -452,11 +448,19 @@ namespace Emby.Server.Implementations.Library
user.Policy.InvalidLoginAttemptCount = newValue;
- var maxCount = user.Policy.IsAdministrator ? 3 : 5;
+ // Check for users without a value here and then fill in the default value
+ // also protect from an always lockout if misconfigured
+ if (user.Policy.LoginAttemptsBeforeLockout == null || user.Policy.LoginAttemptsBeforeLockout == 0)
+ {
+ user.Policy.LoginAttemptsBeforeLockout = user.Policy.IsAdministrator ? 5 : 3;
+ }
+
+ var maxCount = user.Policy.LoginAttemptsBeforeLockout;
var fireLockout = false;
- if (newValue >= maxCount)
+ // -1 can be used to specify no lockout value
+ if (maxCount != -1 && newValue >= maxCount)
{
_logger.LogDebug("Disabling user {0} due to {1} unsuccessful login attempts.", user.Name, newValue);
user.Policy.IsDisabled = true;
@@ -475,15 +479,10 @@ namespace Emby.Server.Implementations.Library
private string GetLocalPasswordHash(User user)
{
return string.IsNullOrEmpty(user.EasyPassword)
- ? _defaultAuthenticationProvider.GetEmptyHashedString(user)
+ ? null
: user.EasyPassword;
}
- private bool IsPasswordEmpty(User user, string passwordHash)
- {
- return string.Equals(passwordHash, _defaultAuthenticationProvider.GetEmptyHashedString(user), StringComparison.OrdinalIgnoreCase);
- }
-
/// <summary>
/// Loads the users from the repository
/// </summary>
@@ -526,14 +525,14 @@ namespace Emby.Server.Implementations.Library
throw new ArgumentNullException(nameof(user));
}
- var hasConfiguredPassword = GetAuthenticationProvider(user).HasPassword(user).Result;
- var hasConfiguredEasyPassword = !IsPasswordEmpty(user, GetLocalPasswordHash(user));
+ bool hasConfiguredPassword = GetAuthenticationProvider(user).HasPassword(user).Result;
+ bool hasConfiguredEasyPassword = string.IsNullOrEmpty(GetLocalPasswordHash(user));
- var hasPassword = user.Configuration.EnableLocalPassword && !string.IsNullOrEmpty(remoteEndPoint) && _networkManager.IsInLocalNetwork(remoteEndPoint) ?
+ bool hasPassword = user.Configuration.EnableLocalPassword && !string.IsNullOrEmpty(remoteEndPoint) && _networkManager.IsInLocalNetwork(remoteEndPoint) ?
hasConfiguredEasyPassword :
hasConfiguredPassword;
- var dto = new UserDto
+ UserDto dto = new UserDto
{
Id = user.Id,
Name = user.Name,
@@ -552,7 +551,7 @@ namespace Emby.Server.Implementations.Library
dto.EnableAutoLogin = true;
}
- var image = user.GetImageInfo(ImageType.Primary, 0);
+ ItemImageInfo image = user.GetImageInfo(ImageType.Primary, 0);
if (image != null)
{
@@ -688,7 +687,7 @@ namespace Emby.Server.Implementations.Library
if (!IsValidUsername(name))
{
- throw new ArgumentException("Usernames can contain letters (a-z), numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)");
+ throw new ArgumentException("Usernames can contain unicode symbols, numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.)");
}
if (Users.Any(u => u.Name.Equals(name, StringComparison.OrdinalIgnoreCase)))
diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
index fceb82ba1..7b210d231 100644
--- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
+++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
@@ -33,7 +33,6 @@ using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Querying;
-using MediaBrowser.Model.Reflection;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
@@ -58,7 +57,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
private readonly IProviderManager _providerManager;
private readonly IMediaEncoder _mediaEncoder;
private readonly IProcessFactory _processFactory;
- private readonly IAssemblyInfo _assemblyInfo;
private IMediaSourceManager _mediaSourceManager;
public static EmbyTV Current;
@@ -74,7 +72,6 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
public EmbyTV(IServerApplicationHost appHost,
IStreamHelper streamHelper,
IMediaSourceManager mediaSourceManager,
- IAssemblyInfo assemblyInfo,
ILogger logger,
IJsonSerializer jsonSerializer,
IHttpClient httpClient,
@@ -101,12 +98,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
_processFactory = processFactory;
_liveTvManager = (LiveTvManager)liveTvManager;
_jsonSerializer = jsonSerializer;
- _assemblyInfo = assemblyInfo;
_mediaSourceManager = mediaSourceManager;
_streamHelper = streamHelper;
- _seriesTimerProvider = new SeriesTimerManager(jsonSerializer, _logger, Path.Combine(DataPath, "seriestimers"));
- _timerProvider = new TimerManager(jsonSerializer, _logger, Path.Combine(DataPath, "timers"), _logger);
+ _seriesTimerProvider = new SeriesTimerManager(jsonSerializer, _logger, Path.Combine(DataPath, "seriestimers.json"));
+ _timerProvider = new TimerManager(jsonSerializer, _logger, Path.Combine(DataPath, "timers.json"), _logger);
_timerProvider.TimerFired += _timerProvider_TimerFired;
_config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated;
@@ -265,7 +261,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
public string HomePageUrl => "https://github.com/jellyfin/jellyfin";
- public async Task RefreshSeriesTimers(CancellationToken cancellationToken, IProgress<double> progress)
+ public async Task RefreshSeriesTimers(CancellationToken cancellationToken)
{
var seriesTimers = await GetSeriesTimersAsync(cancellationToken).ConfigureAwait(false);
@@ -275,7 +271,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
}
}
- public async Task RefreshTimers(CancellationToken cancellationToken, IProgress<double> progress)
+ public async Task RefreshTimers(CancellationToken cancellationToken)
{
var timers = await GetTimersAsync(cancellationToken).ConfigureAwait(false);
diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs
index b825ea3b0..9c45ee36a 100644
--- a/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs
+++ b/Emby.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
@@ -32,31 +31,30 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{
if (_items == null)
{
+ if (!File.Exists(_dataPath))
+ {
+ return new List<T>();
+ }
+
Logger.LogInformation("Loading live tv data from {0}", _dataPath);
_items = GetItemsFromFile(_dataPath);
}
+
return _items.ToList();
}
}
private List<T> GetItemsFromFile(string path)
{
- var jsonFile = path + ".json";
-
try
{
- return _jsonSerializer.DeserializeFromFile<List<T>>(jsonFile) ?? new List<T>();
- }
- catch (FileNotFoundException)
- {
- }
- catch (IOException)
- {
+ return _jsonSerializer.DeserializeFromFile<List<T>>(path);
}
catch (Exception ex)
{
- Logger.LogError(ex, "Error deserializing {jsonFile}", jsonFile);
+ Logger.LogError(ex, "Error deserializing {Path}", path);
}
+
return new List<T>();
}
@@ -67,12 +65,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
throw new ArgumentNullException(nameof(newList));
}
- var file = _dataPath + ".json";
- Directory.CreateDirectory(Path.GetDirectoryName(file));
+ Directory.CreateDirectory(Path.GetDirectoryName(_dataPath));
lock (_fileDataLock)
{
- _jsonSerializer.SerializeToFile(newList, file);
+ _jsonSerializer.SerializeToFile(newList, _dataPath);
_items = newList;
}
}
diff --git a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
index 0bbffb824..4137760d0 100644
--- a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
+++ b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
@@ -17,6 +17,7 @@ using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
+using Microsoft.Net.Http.Headers;
namespace Emby.Server.Implementations.LiveTv.Listings
{
@@ -638,7 +639,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
#if NETSTANDARD2_0
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
- options.RequestHeaders["Accept-Encoding"] = "deflate";
+ options.RequestHeaders[HeaderNames.AcceptEncoding] = "deflate";
}
#endif
@@ -676,7 +677,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
#if NETSTANDARD2_0
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
- options.RequestHeaders["Accept-Encoding"] = "deflate";
+ options.RequestHeaders[HeaderNames.AcceptEncoding] = "deflate";
}
#endif
diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs
index a36302876..9093d9740 100644
--- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs
+++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs
@@ -184,7 +184,7 @@ namespace Emby.Server.Implementations.LiveTv
public QueryResult<BaseItem> GetInternalChannels(LiveTvChannelQuery query, DtoOptions dtoOptions, CancellationToken cancellationToken)
{
- var user = query.UserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(query.UserId);
+ var user = query.UserId == Guid.Empty ? null : _userManager.GetUserById(query.UserId);
var topFolder = GetInternalLiveTvFolder(cancellationToken);
@@ -1087,8 +1087,8 @@ namespace Emby.Server.Implementations.LiveTv
if (coreService != null)
{
- await coreService.RefreshSeriesTimers(cancellationToken, new SimpleProgress<double>()).ConfigureAwait(false);
- await coreService.RefreshTimers(cancellationToken, new SimpleProgress<double>()).ConfigureAwait(false);
+ await coreService.RefreshSeriesTimers(cancellationToken).ConfigureAwait(false);
+ await coreService.RefreshTimers(cancellationToken).ConfigureAwait(false);
}
// Load these now which will prefetch metadata
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs
index 8774371d5..7f426ea31 100644
--- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs
+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunUdpStream.cs
@@ -151,7 +151,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
});
}
- private static int RtpHeaderBytes = 12;
+ private const int RtpHeaderBytes = 12;
+
private async Task CopyTo(MediaBrowser.Model.Net.ISocket udpClient, string file, TaskCompletionSource<bool> openTaskCompletionSource, CancellationToken cancellationToken)
{
var bufferSize = 81920;
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs
index 1f8ca276e..ece2cbd54 100644
--- a/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs
+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/LiveStream.cs
@@ -22,7 +22,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
public string OriginalStreamId { get; set; }
public bool EnableStreamSharing { get; set; }
- public string UniqueId { get; private set; }
+ public string UniqueId { get; }
protected readonly IFileSystem FileSystem;
protected readonly IServerApplicationPaths AppPaths;
@@ -31,12 +31,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
protected readonly ILogger Logger;
protected readonly CancellationTokenSource LiveStreamCancellationTokenSource = new CancellationTokenSource();
- public string TunerHostId { get; private set; }
+ public string TunerHostId { get; }
public DateTime DateOpened { get; protected set; }
- public Func<Task> OnClose { get; set; }
-
public LiveStream(MediaSourceInfo mediaSource, TunerHostInfo tuner, IFileSystem fileSystem, ILogger logger, IServerApplicationPaths appPaths)
{
OriginalMediaSource = mediaSource;
@@ -76,26 +74,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
LiveStreamCancellationTokenSource.Cancel();
- if (OnClose != null)
- {
- return CloseWithExternalFn();
- }
-
return Task.CompletedTask;
}
- private async Task CloseWithExternalFn()
- {
- try
- {
- await OnClose().ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- Logger.LogError(ex, "Error closing live stream");
- }
- }
-
protected Stream GetInputStream(string path, bool allowAsyncFileRead)
{
var fileOpenOptions = FileOpenOptions.SequentialScan;
@@ -113,26 +94,25 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
return DeleteTempFiles(GetStreamFilePaths());
}
- protected async Task DeleteTempFiles(List<string> paths, int retryCount = 0)
+ protected async Task DeleteTempFiles(IEnumerable<string> paths, int retryCount = 0)
{
if (retryCount == 0)
{
- Logger.LogInformation("Deleting temp files {0}", string.Join(", ", paths.ToArray()));
+ Logger.LogInformation("Deleting temp files {0}", paths);
}
var failedFiles = new List<string>();
foreach (var path in paths)
{
- try
- {
- FileSystem.DeleteFile(path);
- }
- catch (DirectoryNotFoundException)
+ if (!File.Exists(path))
{
+ continue;
}
- catch (FileNotFoundException)
+
+ try
{
+ FileSystem.DeleteFile(path);
}
catch (Exception ex)
{
@@ -157,8 +137,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{
cancellationToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, LiveStreamCancellationTokenSource.Token).Token;
- var allowAsync = false;
- // use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039
+ // use non-async filestream on windows along with read due to https://github.com/dotnet/corefx/issues/6039
+ var allowAsync = Environment.OSVersion.Platform != PlatformID.Win32NT;
bool seekFile = (DateTime.UtcNow - DateOpened).TotalSeconds > 10;
@@ -181,28 +161,24 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
Logger.LogInformation("Live Stream ended.");
}
- private Tuple<string, bool> GetNextFile(string currentFile)
+ private (string file, bool isLastFile) GetNextFile(string currentFile)
{
var files = GetStreamFilePaths();
- //logger.LogInformation("Live stream files: {0}", string.Join(", ", files.ToArray()));
-
if (string.IsNullOrEmpty(currentFile))
{
- return new Tuple<string, bool>(files.Last(), true);
+ return (files.Last(), true);
}
var nextIndex = files.FindIndex(i => string.Equals(i, currentFile, StringComparison.OrdinalIgnoreCase)) + 1;
var isLastFile = nextIndex == files.Count - 1;
- return new Tuple<string, bool>(files.ElementAtOrDefault(nextIndex), isLastFile);
+ return (files.ElementAtOrDefault(nextIndex), isLastFile);
}
private async Task CopyFile(string path, bool seekFile, int emptyReadLimit, bool allowAsync, Stream stream, CancellationToken cancellationToken)
{
- //logger.LogInformation("Opening live stream file {0}. Empty read limit: {1}", path, emptyReadLimit);
-
using (var inputStream = (FileStream)GetInputStream(path, allowAsync))
{
if (seekFile)
@@ -218,7 +194,11 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
private void TrySeek(FileStream stream, long offset)
{
- //logger.LogInformation("TrySeek live stream");
+ if (!stream.CanSeek)
+ {
+ return;
+ }
+
try
{
stream.Seek(offset, SeekOrigin.End);
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs
index fdaaf0bae..2d9bec53f 100644
--- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs
+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs
@@ -10,15 +10,14 @@ using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
-using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization;
-using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
+using Microsoft.Net.Http.Headers;
namespace Emby.Server.Implementations.LiveTv.TunerHosts
{
@@ -51,9 +50,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{
var channelIdPrefix = GetFullChannelIdPrefix(info);
- var result = await new M3uParser(Logger, _httpClient, _appHost).Parse(info.Url, channelIdPrefix, info.Id, cancellationToken).ConfigureAwait(false);
-
- return result.Cast<ChannelInfo>().ToList();
+ return await new M3uParser(Logger, _httpClient, _appHost).Parse(info.Url, channelIdPrefix, info.Id, cancellationToken).ConfigureAwait(false);
}
public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken)
@@ -72,7 +69,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
return Task.FromResult(list);
}
- private string[] _disallowedSharedStreamExtensions = new string[]
+ private static readonly string[] _disallowedSharedStreamExtensions = new string[]
{
".mkv",
".mp4",
@@ -87,9 +84,9 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
if (tunerCount > 0)
{
var tunerHostId = info.Id;
- var liveStreams = currentLiveStreams.Where(i => string.Equals(i.TunerHostId, tunerHostId, StringComparison.OrdinalIgnoreCase)).ToList();
+ var liveStreams = currentLiveStreams.Where(i => string.Equals(i.TunerHostId, tunerHostId, StringComparison.OrdinalIgnoreCase));
- if (liveStreams.Count >= tunerCount)
+ if (liveStreams.Count() >= tunerCount)
{
throw new LiveTvConflictException("M3U simultaneous stream limit has been reached.");
}
@@ -97,7 +94,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
var sources = await GetChannelStreamMediaSources(info, channelInfo, cancellationToken).ConfigureAwait(false);
- var mediaSource = sources.First();
+ var mediaSource = sources[0];
if (mediaSource.Protocol == MediaProtocol.Http && !mediaSource.RequiresLooping)
{
@@ -145,7 +142,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
if (protocol == MediaProtocol.Http)
{
// Use user-defined user-agent. If there isn't one, make it look like a browser.
- httpHeaders["User-Agent"] = string.IsNullOrWhiteSpace(info.UserAgent) ?
+ httpHeaders[HeaderNames.UserAgent] = string.IsNullOrWhiteSpace(info.UserAgent) ?
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.85 Safari/537.36" :
info.UserAgent;
}
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
index ad124bb0f..814031b12 100644
--- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
@@ -11,7 +11,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.Extensions;
-using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.LiveTv.TunerHosts
@@ -62,12 +61,13 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
return Task.FromResult((Stream)File.OpenRead(url));
}
- const string ExtInfPrefix = "#EXTINF:";
+ private const string ExtInfPrefix = "#EXTINF:";
+
private List<ChannelInfo> GetChannels(TextReader reader, string channelIdPrefix, string tunerHostId)
{
var channels = new List<ChannelInfo>();
string line;
- string extInf = "";
+ string extInf = string.Empty;
while ((line = reader.ReadLine()) != null)
{
@@ -101,7 +101,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
channel.Path = line;
channels.Add(channel);
- extInf = "";
+ extInf = string.Empty;
}
}
@@ -110,8 +110,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
private ChannelInfo GetChannelnfo(string extInf, string tunerHostId, string mediaUrl)
{
- var channel = new ChannelInfo();
- channel.TunerHostId = tunerHostId;
+ var channel = new ChannelInfo()
+ {
+ TunerHostId = tunerHostId
+ };
extInf = extInf.Trim();
@@ -137,13 +139,15 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
{
channelIdValues.Add(channelId);
}
+
if (!string.IsNullOrWhiteSpace(tvgId))
{
channelIdValues.Add(tvgId);
}
+
if (channelIdValues.Count > 0)
{
- channel.Id = string.Join("_", channelIdValues.ToArray());
+ channel.Id = string.Join("_", channelIdValues);
}
return channel;
@@ -152,7 +156,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
private string GetChannelNumber(string extInf, Dictionary<string, string> attributes, string mediaUrl)
{
var nameParts = extInf.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- var nameInExtInf = nameParts.Length > 1 ? nameParts.Last().Trim() : null;
+ var nameInExtInf = nameParts.Length > 1 ? nameParts[nameParts.Length - 1].Trim() : null;
string numberString = null;
string attributeValue;
diff --git a/Emby.Server.Implementations/Localization/Core/es-AR.json b/Emby.Server.Implementations/Localization/Core/es-AR.json
index c01bb0c50..dc73ba6b3 100644
--- a/Emby.Server.Implementations/Localization/Core/es-AR.json
+++ b/Emby.Server.Implementations/Localization/Core/es-AR.json
@@ -1,97 +1,97 @@
{
- "Albums": "Albums",
- "AppDeviceValues": "App: {0}, Device: {1}",
- "Application": "Application",
- "Artists": "Artists",
- "AuthenticationSucceededWithUserName": "{0} successfully authenticated",
- "Books": "Books",
- "CameraImageUploadedFrom": "A new camera image has been uploaded from {0}",
- "Channels": "Channels",
- "ChapterNameValue": "Chapter {0}",
- "Collections": "Collections",
- "DeviceOfflineWithName": "{0} has disconnected",
- "DeviceOnlineWithName": "{0} is connected",
- "FailedLoginAttemptWithUserName": "Failed login attempt from {0}",
- "Favorites": "Favorites",
- "Folders": "Folders",
- "Genres": "Genres",
- "HeaderAlbumArtists": "Album Artists",
- "HeaderCameraUploads": "Camera Uploads",
- "HeaderContinueWatching": "Continue Watching",
- "HeaderFavoriteAlbums": "Favorite Albums",
- "HeaderFavoriteArtists": "Favorite Artists",
- "HeaderFavoriteEpisodes": "Favorite Episodes",
- "HeaderFavoriteShows": "Favorite Shows",
- "HeaderFavoriteSongs": "Favorite Songs",
- "HeaderLiveTV": "Live TV",
- "HeaderNextUp": "Next Up",
- "HeaderRecordingGroups": "Recording Groups",
- "HomeVideos": "Home videos",
- "Inherit": "Inherit",
- "ItemAddedWithName": "{0} was added to the library",
- "ItemRemovedWithName": "{0} was removed from the library",
- "LabelIpAddressValue": "Ip address: {0}",
- "LabelRunningTimeValue": "Running time: {0}",
- "Latest": "Latest",
- "MessageApplicationUpdated": "Jellyfin Server has been updated",
- "MessageApplicationUpdatedTo": "Jellyfin Server has been updated to {0}",
- "MessageNamedServerConfigurationUpdatedWithValue": "Server configuration section {0} has been updated",
- "MessageServerConfigurationUpdated": "Server configuration has been updated",
- "MixedContent": "Mixed content",
- "Movies": "Movies",
- "Music": "Music",
- "MusicVideos": "Music videos",
- "NameInstallFailed": "{0} installation failed",
- "NameSeasonNumber": "Season {0}",
- "NameSeasonUnknown": "Season Unknown",
- "NewVersionIsAvailable": "A new version of Jellyfin Server is available for download.",
- "NotificationOptionApplicationUpdateAvailable": "Application update available",
- "NotificationOptionApplicationUpdateInstalled": "Application update installed",
- "NotificationOptionAudioPlayback": "Audio playback started",
- "NotificationOptionAudioPlaybackStopped": "Audio playback stopped",
- "NotificationOptionCameraImageUploaded": "Camera image uploaded",
- "NotificationOptionInstallationFailed": "Installation failure",
- "NotificationOptionNewLibraryContent": "New content added",
- "NotificationOptionPluginError": "Plugin failure",
- "NotificationOptionPluginInstalled": "Plugin installed",
- "NotificationOptionPluginUninstalled": "Plugin uninstalled",
- "NotificationOptionPluginUpdateInstalled": "Plugin update installed",
- "NotificationOptionServerRestartRequired": "Server restart required",
- "NotificationOptionTaskFailed": "Scheduled task failure",
- "NotificationOptionUserLockedOut": "User locked out",
- "NotificationOptionVideoPlayback": "Video playback started",
- "NotificationOptionVideoPlaybackStopped": "Video playback stopped",
- "Photos": "Photos",
- "Playlists": "Playlists",
+ "Albums": "Álbumes",
+ "AppDeviceValues": "Aplicación: {0}, Dispositivo: {1}",
+ "Application": "Aplicación",
+ "Artists": "Artistas",
+ "AuthenticationSucceededWithUserName": "{0} autenticado correctamente",
+ "Books": "Libros",
+ "CameraImageUploadedFrom": "Se ha subido una nueva imagen de cámara desde {0}",
+ "Channels": "Canales",
+ "ChapterNameValue": "Capítulo {0}",
+ "Collections": "Colecciones",
+ "DeviceOfflineWithName": "{0} se ha desconectado",
+ "DeviceOnlineWithName": "{0} está conectado",
+ "FailedLoginAttemptWithUserName": "Error al intentar iniciar sesión desde {0}",
+ "Favorites": "Favoritos",
+ "Folders": "Carpetas",
+ "Genres": "Géneros",
+ "HeaderAlbumArtists": "Artistas de álbumes",
+ "HeaderCameraUploads": "Subidas de cámara",
+ "HeaderContinueWatching": "Continuar viendo",
+ "HeaderFavoriteAlbums": "Álbumes favoritos",
+ "HeaderFavoriteArtists": "Artistas favoritos",
+ "HeaderFavoriteEpisodes": "Episodios favoritos",
+ "HeaderFavoriteShows": "Programas favoritos",
+ "HeaderFavoriteSongs": "Canciones favoritas",
+ "HeaderLiveTV": "TV en vivo",
+ "HeaderNextUp": "Continuar Viendo",
+ "HeaderRecordingGroups": "Grupos de grabación",
+ "HomeVideos": "Videos caseros",
+ "Inherit": "Heredar",
+ "ItemAddedWithName": "{0} se ha añadido a la biblioteca",
+ "ItemRemovedWithName": "{0} ha sido eliminado de la biblioteca",
+ "LabelIpAddressValue": "Dirección IP: {0}",
+ "LabelRunningTimeValue": "Tiempo de funcionamiento: {0}",
+ "Latest": "Últimos",
+ "MessageApplicationUpdated": "El servidor Jellyfin fue actualizado",
+ "MessageApplicationUpdatedTo": "Se ha actualizado el servidor Jellyfin a la versión {0}",
+ "MessageNamedServerConfigurationUpdatedWithValue": "Fue actualizada la sección {0} de la configuración del servidor",
+ "MessageServerConfigurationUpdated": "Fue actualizada la configuración del servidor",
+ "MixedContent": "Contenido mixto",
+ "Movies": "Películas",
+ "Music": "Música",
+ "MusicVideos": "Videos musicales",
+ "NameInstallFailed": "{0} error de instalación",
+ "NameSeasonNumber": "Temporada {0}",
+ "NameSeasonUnknown": "Temporada desconocida",
+ "NewVersionIsAvailable": "Disponible una nueva versión de Jellyfin para descargar.",
+ "NotificationOptionApplicationUpdateAvailable": "Actualización de la aplicación disponible",
+ "NotificationOptionApplicationUpdateInstalled": "Actualización de la aplicación instalada",
+ "NotificationOptionAudioPlayback": "Se inició la reproducción de audio",
+ "NotificationOptionAudioPlaybackStopped": "Se detuvo la reproducción de audio",
+ "NotificationOptionCameraImageUploaded": "Imagen de la cámara cargada",
+ "NotificationOptionInstallationFailed": "Error de instalación",
+ "NotificationOptionNewLibraryContent": "Nuevo contenido añadido",
+ "NotificationOptionPluginError": "Error en plugin",
+ "NotificationOptionPluginInstalled": "Plugin instalado",
+ "NotificationOptionPluginUninstalled": "Plugin desinstalado",
+ "NotificationOptionPluginUpdateInstalled": "Actualización del complemento instalada",
+ "NotificationOptionServerRestartRequired": "Se requiere reinicio del servidor",
+ "NotificationOptionTaskFailed": "Error de tarea programada",
+ "NotificationOptionUserLockedOut": "Usuario bloqueado",
+ "NotificationOptionVideoPlayback": "Se inició la reproducción de video",
+ "NotificationOptionVideoPlaybackStopped": "Reproducción de video detenida",
+ "Photos": "Fotos",
+ "Playlists": "Listas de reproducción",
"Plugin": "Plugin",
- "PluginInstalledWithName": "{0} was installed",
- "PluginUninstalledWithName": "{0} was uninstalled",
- "PluginUpdatedWithName": "{0} was updated",
- "ProviderValue": "Provider: {0}",
- "ScheduledTaskFailedWithName": "{0} failed",
- "ScheduledTaskStartedWithName": "{0} started",
- "ServerNameNeedsToBeRestarted": "{0} needs to be restarted",
+ "PluginInstalledWithName": "{0} fue instalado",
+ "PluginUninstalledWithName": "{0} fue desinstalado",
+ "PluginUpdatedWithName": "{0} fue actualizado",
+ "ProviderValue": "Proveedor: {0}",
+ "ScheduledTaskFailedWithName": "{0} falló",
+ "ScheduledTaskStartedWithName": "{0} iniciada",
+ "ServerNameNeedsToBeRestarted": "{0} necesita ser reiniciado",
"Shows": "Series",
- "Songs": "Songs",
- "StartupEmbyServerIsLoading": "Jellyfin Server is loading. Please try again shortly.",
+ "Songs": "Canciones",
+ "StartupEmbyServerIsLoading": "Jellyfin Server se está cargando. Vuelve a intentarlo en breve.",
"SubtitleDownloadFailureForItem": "Subtitles failed to download for {0}",
- "SubtitleDownloadFailureFromForItem": "Subtitles failed to download from {0} for {1}",
- "SubtitlesDownloadedForItem": "Subtitles downloaded for {0}",
- "Sync": "Sync",
- "System": "System",
- "TvShows": "TV Shows",
- "User": "User",
- "UserCreatedWithName": "User {0} has been created",
- "UserDeletedWithName": "User {0} has been deleted",
- "UserDownloadingItemWithValues": "{0} is downloading {1}",
- "UserLockedOutWithName": "User {0} has been locked out",
- "UserOfflineFromDevice": "{0} has disconnected from {1}",
- "UserOnlineFromDevice": "{0} is online from {1}",
- "UserPasswordChangedWithName": "Password has been changed for user {0}",
- "UserPolicyUpdatedWithName": "User policy has been updated for {0}",
- "UserStartedPlayingItemWithValues": "{0} is playing {1} on {2}",
- "UserStoppedPlayingItemWithValues": "{0} has finished playing {1} on {2}",
- "ValueHasBeenAddedToLibrary": "{0} has been added to your media library",
- "ValueSpecialEpisodeName": "Special - {0}",
- "VersionNumber": "Version {0}"
+ "SubtitleDownloadFailureFromForItem": "Fallo de descarga de subtítulos desde {0} para {1}",
+ "SubtitlesDownloadedForItem": "Descargar subtítulos para {0}",
+ "Sync": "Sincronizar",
+ "System": "Sistema",
+ "TvShows": "Series de TV",
+ "User": "Usuario",
+ "UserCreatedWithName": "El usuario {0} ha sido creado",
+ "UserDeletedWithName": "El usuario {0} ha sido borrado",
+ "UserDownloadingItemWithValues": "{0} está descargando {1}",
+ "UserLockedOutWithName": "El usuario {0} ha sido bloqueado",
+ "UserOfflineFromDevice": "{0} se ha desconectado de {1}",
+ "UserOnlineFromDevice": "{0} está en línea desde {1}",
+ "UserPasswordChangedWithName": "Se ha cambiado la contraseña para el usuario {0}",
+ "UserPolicyUpdatedWithName": "Actualizada política de usuario para {0}",
+ "UserStartedPlayingItemWithValues": "{0} está reproduciendo {1} en {2}",
+ "UserStoppedPlayingItemWithValues": "{0} ha terminado de reproducir {1} en {2}",
+ "ValueHasBeenAddedToLibrary": "{0} ha sido añadido a tu biblioteca multimedia",
+ "ValueSpecialEpisodeName": "Especial - {0}",
+ "VersionNumber": "Versión {0}"
}
diff --git a/Emby.Server.Implementations/Localization/Core/fr-CA.json b/Emby.Server.Implementations/Localization/Core/fr-CA.json
index 7202be9f5..4b4db39a8 100644
--- a/Emby.Server.Implementations/Localization/Core/fr-CA.json
+++ b/Emby.Server.Implementations/Localization/Core/fr-CA.json
@@ -1,97 +1,97 @@
{
"Albums": "Albums",
- "AppDeviceValues": "App: {0}, Device: {1}",
+ "AppDeviceValues": "Application : {0}, Appareil : {1}",
"Application": "Application",
- "Artists": "Artists",
- "AuthenticationSucceededWithUserName": "{0} successfully authenticated",
- "Books": "Books",
- "CameraImageUploadedFrom": "A new camera image has been uploaded from {0}",
- "Channels": "Channels",
- "ChapterNameValue": "Chapter {0}",
+ "Artists": "Artistes",
+ "AuthenticationSucceededWithUserName": "{0} s'est authentifié avec succès",
+ "Books": "Livres",
+ "CameraImageUploadedFrom": "Une nouvelle image de caméra a été téléchargée depuis {0}",
+ "Channels": "Chaînes",
+ "ChapterNameValue": "Chapitre {0}",
"Collections": "Collections",
- "DeviceOfflineWithName": "{0} has disconnected",
- "DeviceOnlineWithName": "{0} is connected",
- "FailedLoginAttemptWithUserName": "Failed login attempt from {0}",
- "Favorites": "Favorites",
- "Folders": "Folders",
+ "DeviceOfflineWithName": "{0} s'est déconnecté",
+ "DeviceOnlineWithName": "{0} est connecté",
+ "FailedLoginAttemptWithUserName": "Échec d'une tentative de connexion de {0}",
+ "Favorites": "Favoris",
+ "Folders": "Dossiers",
"Genres": "Genres",
- "HeaderAlbumArtists": "Album Artists",
- "HeaderCameraUploads": "Camera Uploads",
+ "HeaderAlbumArtists": "Artistes de l'album",
+ "HeaderCameraUploads": "Photos transférées",
"HeaderContinueWatching": "Continuer à regarder",
- "HeaderFavoriteAlbums": "Favorite Albums",
- "HeaderFavoriteArtists": "Favorite Artists",
- "HeaderFavoriteEpisodes": "Favorite Episodes",
- "HeaderFavoriteShows": "Favorite Shows",
- "HeaderFavoriteSongs": "Favorite Songs",
- "HeaderLiveTV": "Live TV",
+ "HeaderFavoriteAlbums": "Albums favoris",
+ "HeaderFavoriteArtists": "Artistes favoris",
+ "HeaderFavoriteEpisodes": "Épisodes favoris",
+ "HeaderFavoriteShows": "Séries favorites",
+ "HeaderFavoriteSongs": "Chansons favorites",
+ "HeaderLiveTV": "TV en direct",
"HeaderNextUp": "À Suivre",
- "HeaderRecordingGroups": "Recording Groups",
- "HomeVideos": "Home videos",
- "Inherit": "Inherit",
- "ItemAddedWithName": "{0} was added to the library",
- "ItemRemovedWithName": "{0} was removed from the library",
- "LabelIpAddressValue": "Ip address: {0}",
- "LabelRunningTimeValue": "Running time: {0}",
- "Latest": "Latest",
- "MessageApplicationUpdated": "Jellyfin Server has been updated",
- "MessageApplicationUpdatedTo": "Jellyfin Server has been updated to {0}",
- "MessageNamedServerConfigurationUpdatedWithValue": "Server configuration section {0} has been updated",
- "MessageServerConfigurationUpdated": "Server configuration has been updated",
- "MixedContent": "Mixed content",
- "Movies": "Movies",
- "Music": "Music",
- "MusicVideos": "Music videos",
- "NameInstallFailed": "{0} installation failed",
- "NameSeasonNumber": "Season {0}",
- "NameSeasonUnknown": "Season Unknown",
- "NewVersionIsAvailable": "A new version of Jellyfin Server is available for download.",
- "NotificationOptionApplicationUpdateAvailable": "Application update available",
- "NotificationOptionApplicationUpdateInstalled": "Application update installed",
- "NotificationOptionAudioPlayback": "Audio playback started",
- "NotificationOptionAudioPlaybackStopped": "Audio playback stopped",
- "NotificationOptionCameraImageUploaded": "Camera image uploaded",
- "NotificationOptionInstallationFailed": "Installation failure",
- "NotificationOptionNewLibraryContent": "New content added",
- "NotificationOptionPluginError": "Plugin failure",
- "NotificationOptionPluginInstalled": "Plugin installed",
- "NotificationOptionPluginUninstalled": "Plugin uninstalled",
- "NotificationOptionPluginUpdateInstalled": "Plugin update installed",
- "NotificationOptionServerRestartRequired": "Server restart required",
- "NotificationOptionTaskFailed": "Scheduled task failure",
- "NotificationOptionUserLockedOut": "User locked out",
- "NotificationOptionVideoPlayback": "Video playback started",
- "NotificationOptionVideoPlaybackStopped": "Video playback stopped",
+ "HeaderRecordingGroups": "Groupes d'enregistrements",
+ "HomeVideos": "Vidéos personnelles",
+ "Inherit": "Hériter",
+ "ItemAddedWithName": "{0} a été ajouté à la médiathèque",
+ "ItemRemovedWithName": "{0} a été supprimé de la médiathèque",
+ "LabelIpAddressValue": "Adresse IP : {0}",
+ "LabelRunningTimeValue": "Durée : {0}",
+ "Latest": "Derniers",
+ "MessageApplicationUpdated": "Le serveur Jellyfin a été mis à jour",
+ "MessageApplicationUpdatedTo": "Le serveur Jellyfin a été mis à jour vers la version {0}",
+ "MessageNamedServerConfigurationUpdatedWithValue": "La configuration de la section {0} du serveur a été mise à jour",
+ "MessageServerConfigurationUpdated": "La configuration du serveur a été mise à jour",
+ "MixedContent": "Contenu mixte",
+ "Movies": "Films",
+ "Music": "Musique",
+ "MusicVideos": "Vidéos musicales",
+ "NameInstallFailed": "{0} échec d'installation",
+ "NameSeasonNumber": "Saison {0}",
+ "NameSeasonUnknown": "Saison Inconnue",
+ "NewVersionIsAvailable": "Une nouvelle version du serveur Jellyfin est disponible au téléchargement.",
+ "NotificationOptionApplicationUpdateAvailable": "Mise à jour de l'application disponible",
+ "NotificationOptionApplicationUpdateInstalled": "Mise à jour de l'application installée",
+ "NotificationOptionAudioPlayback": "Lecture audio démarrée",
+ "NotificationOptionAudioPlaybackStopped": "Lecture audio arrêtée",
+ "NotificationOptionCameraImageUploaded": "L'image de l'appareil photo a été transférée",
+ "NotificationOptionInstallationFailed": "Échec d'installation",
+ "NotificationOptionNewLibraryContent": "Nouveau contenu ajouté",
+ "NotificationOptionPluginError": "Erreur d'extension",
+ "NotificationOptionPluginInstalled": "Extension installée",
+ "NotificationOptionPluginUninstalled": "Extension désinstallée",
+ "NotificationOptionPluginUpdateInstalled": "Mise à jour d'extension installée",
+ "NotificationOptionServerRestartRequired": "Un redémarrage du serveur est requis",
+ "NotificationOptionTaskFailed": "Échec de tâche planifiée",
+ "NotificationOptionUserLockedOut": "Utilisateur verrouillé",
+ "NotificationOptionVideoPlayback": "Lecture vidéo démarrée",
+ "NotificationOptionVideoPlaybackStopped": "Lecture vidéo arrêtée",
"Photos": "Photos",
- "Playlists": "Playlists",
- "Plugin": "Plugin",
- "PluginInstalledWithName": "{0} was installed",
- "PluginUninstalledWithName": "{0} was uninstalled",
- "PluginUpdatedWithName": "{0} was updated",
- "ProviderValue": "Provider: {0}",
- "ScheduledTaskFailedWithName": "{0} failed",
- "ScheduledTaskStartedWithName": "{0} started",
- "ServerNameNeedsToBeRestarted": "{0} needs to be restarted",
- "Shows": "Series",
- "Songs": "Songs",
- "StartupEmbyServerIsLoading": "Jellyfin Server is loading. Please try again shortly.",
+ "Playlists": "Listes de lecture",
+ "Plugin": "Extension",
+ "PluginInstalledWithName": "{0} a été installé",
+ "PluginUninstalledWithName": "{0} a été désinstallé",
+ "PluginUpdatedWithName": "{0} a été mis à jour",
+ "ProviderValue": "Fournisseur : {0}",
+ "ScheduledTaskFailedWithName": "{0} a échoué",
+ "ScheduledTaskStartedWithName": "{0} a commencé",
+ "ServerNameNeedsToBeRestarted": "{0} doit être redémarré",
+ "Shows": "Émissions",
+ "Songs": "Chansons",
+ "StartupEmbyServerIsLoading": "Le serveur Jellyfin est en cours de chargement. Veuillez réessayer dans quelques instants.",
"SubtitleDownloadFailureForItem": "Subtitles failed to download for {0}",
- "SubtitleDownloadFailureFromForItem": "Subtitles failed to download from {0} for {1}",
- "SubtitlesDownloadedForItem": "Subtitles downloaded for {0}",
- "Sync": "Sync",
- "System": "System",
- "TvShows": "TV Shows",
- "User": "User",
- "UserCreatedWithName": "User {0} has been created",
- "UserDeletedWithName": "User {0} has been deleted",
- "UserDownloadingItemWithValues": "{0} is downloading {1}",
- "UserLockedOutWithName": "User {0} has been locked out",
- "UserOfflineFromDevice": "{0} has disconnected from {1}",
- "UserOnlineFromDevice": "{0} is online from {1}",
- "UserPasswordChangedWithName": "Password has been changed for user {0}",
- "UserPolicyUpdatedWithName": "User policy has been updated for {0}",
- "UserStartedPlayingItemWithValues": "{0} is playing {1} on {2}",
- "UserStoppedPlayingItemWithValues": "{0} has finished playing {1} on {2}",
- "ValueHasBeenAddedToLibrary": "{0} has been added to your media library",
+ "SubtitleDownloadFailureFromForItem": "Échec du téléchargement des sous-titres depuis {0} pour {1}",
+ "SubtitlesDownloadedForItem": "Les sous-titres de {0} ont été téléchargés",
+ "Sync": "Synchroniser",
+ "System": "Système",
+ "TvShows": "Séries Télé",
+ "User": "Utilisateur",
+ "UserCreatedWithName": "L'utilisateur {0} a été créé",
+ "UserDeletedWithName": "L'utilisateur {0} a été supprimé",
+ "UserDownloadingItemWithValues": "{0} est en train de télécharger {1}",
+ "UserLockedOutWithName": "L'utilisateur {0} a été verrouillé",
+ "UserOfflineFromDevice": "{0} s'est déconnecté depuis {1}",
+ "UserOnlineFromDevice": "{0} s'est connecté depuis {1}",
+ "UserPasswordChangedWithName": "Le mot de passe pour l'utilisateur {0} a été modifié",
+ "UserPolicyUpdatedWithName": "La politique de l'utilisateur a été mise à jour pour {0}",
+ "UserStartedPlayingItemWithValues": "{0} est en train de lire {1} sur {2}",
+ "UserStoppedPlayingItemWithValues": "{0} vient d'arrêter la lecture de {1} sur {2}",
+ "ValueHasBeenAddedToLibrary": "{0} a été ajouté à votre médiathèque",
"ValueSpecialEpisodeName": "Spécial - {0}",
"VersionNumber": "Version {0}"
}
diff --git a/Emby.Server.Implementations/Localization/Core/fr.json b/Emby.Server.Implementations/Localization/Core/fr.json
index 52afb4e49..e434b7605 100644
--- a/Emby.Server.Implementations/Localization/Core/fr.json
+++ b/Emby.Server.Implementations/Localization/Core/fr.json
@@ -44,7 +44,7 @@
"NameInstallFailed": "{0} échec d'installation",
"NameSeasonNumber": "Saison {0}",
"NameSeasonUnknown": "Saison Inconnue",
- "NewVersionIsAvailable": "Une nouvelle version d'Jellyfin Serveur est disponible au téléchargement.",
+ "NewVersionIsAvailable": "Une nouvelle version de Jellyfin Serveur est disponible au téléchargement.",
"NotificationOptionApplicationUpdateAvailable": "Mise à jour de l'application disponible",
"NotificationOptionApplicationUpdateInstalled": "Mise à jour de l'application installée",
"NotificationOptionAudioPlayback": "Lecture audio démarrée",
@@ -89,7 +89,7 @@
"UserOnlineFromDevice": "{0} s'est connecté depuis {1}",
"UserPasswordChangedWithName": "Le mot de passe pour l'utilisateur {0} a été modifié",
"UserPolicyUpdatedWithName": "La politique de l'utilisateur a été mise à jour pour {0}",
- "UserStartedPlayingItemWithValues": "{0} est entrain de lire {1} sur {2}",
+ "UserStartedPlayingItemWithValues": "{0} est en train de lire {1} sur {2}",
"UserStoppedPlayingItemWithValues": "{0} vient d'arrêter la lecture de {1} sur {2}",
"ValueHasBeenAddedToLibrary": "{0} a été ajouté à votre librairie",
"ValueSpecialEpisodeName": "Spécial - {0}",
diff --git a/Emby.Server.Implementations/Localization/Core/he.json b/Emby.Server.Implementations/Localization/Core/he.json
index fff1d1f0e..0ed998c4b 100644
--- a/Emby.Server.Implementations/Localization/Core/he.json
+++ b/Emby.Server.Implementations/Localization/Core/he.json
@@ -1,8 +1,8 @@
{
- "Albums": "Albums",
+ "Albums": "אלבומים",
"AppDeviceValues": "App: {0}, Device: {1}",
- "Application": "Application",
- "Artists": "Artists",
+ "Application": "אפליקציה",
+ "Artists": "אמנים",
"AuthenticationSucceededWithUserName": "{0} successfully authenticated",
"Books": "ספרים",
"CameraImageUploadedFrom": "A new camera image has been uploaded from {0}",
diff --git a/Emby.Server.Implementations/Localization/Core/it.json b/Emby.Server.Implementations/Localization/Core/it.json
index a5f1e8f94..357883cd3 100644
--- a/Emby.Server.Implementations/Localization/Core/it.json
+++ b/Emby.Server.Implementations/Localization/Core/it.json
@@ -34,17 +34,17 @@
"LabelRunningTimeValue": "Durata: {0}",
"Latest": "Più recenti",
"MessageApplicationUpdated": "Il Server Jellyfin è stato aggiornato",
- "MessageApplicationUpdatedTo": "Jellyfin Server has been updated to {0}",
+ "MessageApplicationUpdatedTo": "Jellyfin Server è stato aggiornato a {0}",
"MessageNamedServerConfigurationUpdatedWithValue": "La sezione {0} della configurazione server è stata aggiornata",
"MessageServerConfigurationUpdated": "La configurazione del server è stata aggiornata",
"MixedContent": "Contenuto misto",
"Movies": "Film",
"Music": "Musica",
"MusicVideos": "Video musicali",
- "NameInstallFailed": "{0} installation failed",
+ "NameInstallFailed": "{0} installazione fallita",
"NameSeasonNumber": "Stagione {0}",
"NameSeasonUnknown": "Stagione sconosciuto",
- "NewVersionIsAvailable": "A new version of Jellyfin Server is available for download.",
+ "NewVersionIsAvailable": "Una nuova versione di Jellyfin Server è disponibile per il download.",
"NotificationOptionApplicationUpdateAvailable": "Aggiornamento dell'applicazione disponibile",
"NotificationOptionApplicationUpdateInstalled": "Aggiornamento dell'applicazione installato",
"NotificationOptionAudioPlayback": "La riproduzione audio è iniziata",
@@ -70,12 +70,12 @@
"ProviderValue": "Provider: {0}",
"ScheduledTaskFailedWithName": "{0} fallito",
"ScheduledTaskStartedWithName": "{0} avviati",
- "ServerNameNeedsToBeRestarted": "{0} needs to be restarted",
+ "ServerNameNeedsToBeRestarted": "{0} deve essere riavviato",
"Shows": "Programmi",
"Songs": "Canzoni",
"StartupEmbyServerIsLoading": "Jellyfin server si sta avviando. Per favore riprova più tardi.",
"SubtitleDownloadFailureForItem": "Impossibile scaricare i sottotitoli per {0}",
- "SubtitleDownloadFailureFromForItem": "Subtitles failed to download from {0} for {1}",
+ "SubtitleDownloadFailureFromForItem": "Impossibile scaricare i sottotitoli da {0} per {1}",
"SubtitlesDownloadedForItem": "Sottotitoli scaricati per {0}",
"Sync": "Sincronizza",
"System": "Sistema",
@@ -91,7 +91,7 @@
"UserPolicyUpdatedWithName": "La politica dell'utente è stata aggiornata per {0}",
"UserStartedPlayingItemWithValues": "{0} ha avviato la riproduzione di {1}",
"UserStoppedPlayingItemWithValues": "{0} ha interrotto la riproduzione di {1}",
- "ValueHasBeenAddedToLibrary": "{0} has been added to your media library",
+ "ValueHasBeenAddedToLibrary": "{0} è stato aggiunto alla tua libreria multimediale",
"ValueSpecialEpisodeName": "Speciale - {0}",
"VersionNumber": "Versione {0}"
}
diff --git a/Emby.Server.Implementations/Localization/Core/kk.json b/Emby.Server.Implementations/Localization/Core/kk.json
index 658d168e9..23841f37d 100644
--- a/Emby.Server.Implementations/Localization/Core/kk.json
+++ b/Emby.Server.Implementations/Localization/Core/kk.json
@@ -3,15 +3,15 @@
"AppDeviceValues": "Qoldanba: {0}, Qurylǵy: {1}",
"Application": "Qoldanba",
"Artists": "Oryndaýshylar",
- "AuthenticationSucceededWithUserName": "{0} túpnusqalyǵyn rastalýy sátti",
+ "AuthenticationSucceededWithUserName": "{0} túpnusqalyq rastalýy sátti aıaqtaldy",
"Books": "Kitaptar",
- "CameraImageUploadedFrom": "Jańa sýret {0} kamerasynan júktep alyndy",
+ "CameraImageUploadedFrom": "{0} kamerasynan jańa sýret júktep alyndy",
"Channels": "Arnalar",
"ChapterNameValue": "{0}-sahna",
"Collections": "Jıyntyqtar",
"DeviceOfflineWithName": "{0} ajyratylǵan",
"DeviceOnlineWithName": "{0} qosylǵan",
- "FailedLoginAttemptWithUserName": "{0} tarapynan kirý áreketi sátsiz",
+ "FailedLoginAttemptWithUserName": "{0} tarapynan kirý áreketi sátsiz aıaqtaldy",
"Favorites": "Tańdaýlylar",
"Folders": "Qaltalar",
"Genres": "Janrlar",
@@ -28,13 +28,13 @@
"HeaderRecordingGroups": "Jazba toptary",
"HomeVideos": "Úılik beıneler",
"Inherit": "Muraǵa ıelený",
- "ItemAddedWithName": "{0} tasyǵyshhanaǵa ústelindi",
+ "ItemAddedWithName": "{0} tasyǵyshhanaǵa ústeldi",
"ItemRemovedWithName": "{0} tasyǵyshhanadan alastaldy",
"LabelIpAddressValue": "IP-mekenjaıy: {0}",
"LabelRunningTimeValue": "Oınatý ýaqyty: {0}",
"Latest": "Eń keıingi",
"MessageApplicationUpdated": "Jellyfin Serveri jańartyldy",
- "MessageApplicationUpdatedTo": "Jellyfin Serveri {0} deńgeıge jańartyldy",
+ "MessageApplicationUpdatedTo": "Jellyfin Serveri {0} nusqasyna jańartyldy",
"MessageNamedServerConfigurationUpdatedWithValue": "Server teńsheliminiń {0} bólimi jańartyldy",
"MessageServerConfigurationUpdated": "Server teńshelimi jańartyldy",
"MixedContent": "Aralas mazmun",
diff --git a/Emby.Server.Implementations/Localization/Core/pt-BR.json b/Emby.Server.Implementations/Localization/Core/pt-BR.json
index aaedf0850..dbc9c4c4b 100644
--- a/Emby.Server.Implementations/Localization/Core/pt-BR.json
+++ b/Emby.Server.Implementations/Localization/Core/pt-BR.json
@@ -5,7 +5,7 @@
"Artists": "Artistas",
"AuthenticationSucceededWithUserName": "{0} autenticado com sucesso",
"Books": "Livros",
- "CameraImageUploadedFrom": "A new camera image has been uploaded from {0}",
+ "CameraImageUploadedFrom": "Uma nova imagem da câmera foi submetida de {0}",
"Channels": "Canais",
"ChapterNameValue": "Capítulo {0}",
"Collections": "Coletâneas",
@@ -30,21 +30,21 @@
"Inherit": "Herdar",
"ItemAddedWithName": "{0} foi adicionado à biblioteca",
"ItemRemovedWithName": "{0} foi removido da biblioteca",
- "LabelIpAddressValue": "Endereço ip: {0}",
+ "LabelIpAddressValue": "Endereço IP: {0}",
"LabelRunningTimeValue": "Tempo de execução: {0}",
"Latest": "Recente",
"MessageApplicationUpdated": "O servidor Jellyfin foi atualizado",
- "MessageApplicationUpdatedTo": "Jellyfin Server has been updated to {0}",
+ "MessageApplicationUpdatedTo": "O Servidor Jellyfin foi atualizado para {0}",
"MessageNamedServerConfigurationUpdatedWithValue": "A seção {0} da configuração do servidor foi atualizada",
"MessageServerConfigurationUpdated": "A configuração do servidor foi atualizada",
"MixedContent": "Conteúdo misto",
"Movies": "Filmes",
"Music": "Música",
"MusicVideos": "Vídeos musicais",
- "NameInstallFailed": "{0} installation failed",
+ "NameInstallFailed": "A instalação de {0} falhou",
"NameSeasonNumber": "Temporada {0}",
"NameSeasonUnknown": "Temporada Desconhecida",
- "NewVersionIsAvailable": "A new version of Jellyfin Server is available for download.",
+ "NewVersionIsAvailable": "Uma nova versão do servidor Jellyfin está disponível para download.",
"NotificationOptionApplicationUpdateAvailable": "Atualização de aplicativo disponível",
"NotificationOptionApplicationUpdateInstalled": "Atualização de aplicativo instalada",
"NotificationOptionAudioPlayback": "Reprodução de áudio iniciada",
@@ -70,12 +70,12 @@
"ProviderValue": "Provedor: {0}",
"ScheduledTaskFailedWithName": "{0} falhou",
"ScheduledTaskStartedWithName": "{0} iniciada",
- "ServerNameNeedsToBeRestarted": "{0} needs to be restarted",
+ "ServerNameNeedsToBeRestarted": "O servidor {0} precisa ser reiniciado",
"Shows": "Séries",
"Songs": "Músicas",
"StartupEmbyServerIsLoading": "O Servidor Jellyfin está carregando. Por favor tente novamente em breve.",
"SubtitleDownloadFailureForItem": "Download de legendas falhou para {0}",
- "SubtitleDownloadFailureFromForItem": "Subtitles failed to download from {0} for {1}",
+ "SubtitleDownloadFailureFromForItem": "Houve um problema ao baixar as legendas de {0} para {1}",
"SubtitlesDownloadedForItem": "Legendas baixadas para {0}",
"Sync": "Sincronizar",
"System": "Sistema",
@@ -91,7 +91,7 @@
"UserPolicyUpdatedWithName": "A política de usuário foi atualizada para {0}",
"UserStartedPlayingItemWithValues": "{0} iniciou a reprodução de {1}",
"UserStoppedPlayingItemWithValues": "{0} parou de reproduzir {1}",
- "ValueHasBeenAddedToLibrary": "{0} has been added to your media library",
+ "ValueHasBeenAddedToLibrary": "{0} foi adicionado a sua biblioteca",
"ValueSpecialEpisodeName": "Especial - {0}",
"VersionNumber": "Versão {0}"
}
diff --git a/Emby.Server.Implementations/Localization/Core/sl-SI.json b/Emby.Server.Implementations/Localization/Core/sl-SI.json
index e850257d4..b50ff4706 100644
--- a/Emby.Server.Implementations/Localization/Core/sl-SI.json
+++ b/Emby.Server.Implementations/Localization/Core/sl-SI.json
@@ -1,62 +1,62 @@
{
- "Albums": "Albums",
- "AppDeviceValues": "App: {0}, Device: {1}",
- "Application": "Application",
- "Artists": "Artists",
- "AuthenticationSucceededWithUserName": "{0} successfully authenticated",
- "Books": "Books",
- "CameraImageUploadedFrom": "A new camera image has been uploaded from {0}",
- "Channels": "Channels",
- "ChapterNameValue": "Chapter {0}",
- "Collections": "Collections",
+ "Albums": "Albumi",
+ "AppDeviceValues": "Aplikacija: {0}, Naprava: {1}",
+ "Application": "Aplikacija",
+ "Artists": "Izvajalci",
+ "AuthenticationSucceededWithUserName": "{0} preverjanje uspešno",
+ "Books": "Knjige",
+ "CameraImageUploadedFrom": "Nova fotografija je bila naložena z {0}",
+ "Channels": "Kanali",
+ "ChapterNameValue": "Poglavje {0}",
+ "Collections": "Zbirke",
"DeviceOfflineWithName": "{0} has disconnected",
- "DeviceOnlineWithName": "{0} is connected",
- "FailedLoginAttemptWithUserName": "Failed login attempt from {0}",
- "Favorites": "Favorites",
- "Folders": "Folders",
- "Genres": "Genres",
- "HeaderAlbumArtists": "Album Artists",
- "HeaderCameraUploads": "Camera Uploads",
- "HeaderContinueWatching": "Continue Watching",
- "HeaderFavoriteAlbums": "Favorite Albums",
- "HeaderFavoriteArtists": "Favorite Artists",
- "HeaderFavoriteEpisodes": "Favorite Episodes",
- "HeaderFavoriteShows": "Favorite Shows",
- "HeaderFavoriteSongs": "Favorite Songs",
- "HeaderLiveTV": "Live TV",
- "HeaderNextUp": "Next Up",
- "HeaderRecordingGroups": "Recording Groups",
- "HomeVideos": "Home videos",
- "Inherit": "Inherit",
- "ItemAddedWithName": "{0} was added to the library",
- "ItemRemovedWithName": "{0} was removed from the library",
- "LabelIpAddressValue": "Ip address: {0}",
- "LabelRunningTimeValue": "Running time: {0}",
- "Latest": "Latest",
- "MessageApplicationUpdated": "Jellyfin Server has been updated",
- "MessageApplicationUpdatedTo": "Jellyfin Server has been updated to {0}",
+ "DeviceOnlineWithName": "{0} je povezan",
+ "FailedLoginAttemptWithUserName": "Neuspešen poskus prijave z {0}",
+ "Favorites": "Priljubljeni",
+ "Folders": "Mape",
+ "Genres": "Zvrsti",
+ "HeaderAlbumArtists": "Izvajalci albuma",
+ "HeaderCameraUploads": "Posnetki kamere",
+ "HeaderContinueWatching": "Nadaljuj gledanje",
+ "HeaderFavoriteAlbums": "Priljubljeni albumi",
+ "HeaderFavoriteArtists": "Priljubljeni izvajalci",
+ "HeaderFavoriteEpisodes": "Priljubljene epizode",
+ "HeaderFavoriteShows": "Priljubljene serije",
+ "HeaderFavoriteSongs": "Priljubljene pesmi",
+ "HeaderLiveTV": "TV v živo",
+ "HeaderNextUp": "Sledi",
+ "HeaderRecordingGroups": "Zbirke posnetkov",
+ "HomeVideos": "Domači posnetki",
+ "Inherit": "Podeduj",
+ "ItemAddedWithName": "{0} je dodan v knjižnico",
+ "ItemRemovedWithName": "{0} je bil odstranjen iz knjižnice",
+ "LabelIpAddressValue": "IP naslov: {0}",
+ "LabelRunningTimeValue": "Čas trajanja: {0}",
+ "Latest": "Najnovejše",
+ "MessageApplicationUpdated": "Jellyfin strežnik je bil posodobljen",
+ "MessageApplicationUpdatedTo": "Jellyfin strežnik je bil posodobljen na {0}",
"MessageNamedServerConfigurationUpdatedWithValue": "Server configuration section {0} has been updated",
- "MessageServerConfigurationUpdated": "Server configuration has been updated",
- "MixedContent": "Mixed content",
- "Movies": "Movies",
- "Music": "Music",
- "MusicVideos": "Music videos",
- "NameInstallFailed": "{0} installation failed",
- "NameSeasonNumber": "Season {0}",
- "NameSeasonUnknown": "Season Unknown",
- "NewVersionIsAvailable": "A new version of Jellyfin Server is available for download.",
- "NotificationOptionApplicationUpdateAvailable": "Application update available",
- "NotificationOptionApplicationUpdateInstalled": "Application update installed",
- "NotificationOptionAudioPlayback": "Audio playback started",
- "NotificationOptionAudioPlaybackStopped": "Audio playback stopped",
- "NotificationOptionCameraImageUploaded": "Camera image uploaded",
- "NotificationOptionInstallationFailed": "Installation failure",
- "NotificationOptionNewLibraryContent": "New content added",
- "NotificationOptionPluginError": "Plugin failure",
- "NotificationOptionPluginInstalled": "Plugin installed",
- "NotificationOptionPluginUninstalled": "Plugin uninstalled",
- "NotificationOptionPluginUpdateInstalled": "Plugin update installed",
- "NotificationOptionServerRestartRequired": "Server restart required",
+ "MessageServerConfigurationUpdated": "Nastavitve strežnika so bile posodobljene",
+ "MixedContent": "Razne vsebine",
+ "Movies": "Filmi",
+ "Music": "Glasba",
+ "MusicVideos": "Glasbeni posnetki",
+ "NameInstallFailed": "{0} namestitev neuspešna",
+ "NameSeasonNumber": "Sezona {0}",
+ "NameSeasonUnknown": "Season neznana",
+ "NewVersionIsAvailable": "Nova razničica Jellyfin strežnika je na voljo za prenos.",
+ "NotificationOptionApplicationUpdateAvailable": "Posodobitev aplikacije je na voljo",
+ "NotificationOptionApplicationUpdateInstalled": "Posodobitev aplikacije je bila nameščena",
+ "NotificationOptionAudioPlayback": "Predvajanje zvoka začeto",
+ "NotificationOptionAudioPlaybackStopped": "Predvajanje zvoka zaustavljeno",
+ "NotificationOptionCameraImageUploaded": "Posnetek kamere naložen",
+ "NotificationOptionInstallationFailed": "Napaka pri nameščanju",
+ "NotificationOptionNewLibraryContent": "Nove vsebine dodane",
+ "NotificationOptionPluginError": "Napaka dodatka",
+ "NotificationOptionPluginInstalled": "Dodatek nameščen",
+ "NotificationOptionPluginUninstalled": "Dodatek odstranjen",
+ "NotificationOptionPluginUpdateInstalled": "Posodobitev dodatka nameščena",
+ "NotificationOptionServerRestartRequired": "Potreben je ponovni zagon strežnika",
"NotificationOptionTaskFailed": "Scheduled task failure",
"NotificationOptionUserLockedOut": "User locked out",
"NotificationOptionVideoPlayback": "Video playback started",
diff --git a/Emby.Server.Implementations/Localization/Core/tr.json b/Emby.Server.Implementations/Localization/Core/tr.json
index 495f82db6..9e00eba62 100644
--- a/Emby.Server.Implementations/Localization/Core/tr.json
+++ b/Emby.Server.Implementations/Localization/Core/tr.json
@@ -1,12 +1,12 @@
{
- "Albums": "Albums",
- "AppDeviceValues": "App: {0}, Device: {1}",
- "Application": "Application",
- "Artists": "Artists",
- "AuthenticationSucceededWithUserName": "{0} successfully authenticated",
- "Books": "Books",
+ "Albums": "Albümler",
+ "AppDeviceValues": "Uygulama: {0}, Aygıt: {1}",
+ "Application": "Uygulama",
+ "Artists": "Sanatçılar",
+ "AuthenticationSucceededWithUserName": "{0} başarı ile giriş yaptı",
+ "Books": "Kitaplar",
"CameraImageUploadedFrom": "A new camera image has been uploaded from {0}",
- "Channels": "Channels",
+ "Channels": "Kanallar",
"ChapterNameValue": "Chapter {0}",
"Collections": "Collections",
"DeviceOfflineWithName": "{0} has disconnected",
@@ -17,8 +17,8 @@
"Genres": "Genres",
"HeaderAlbumArtists": "Album Artists",
"HeaderCameraUploads": "Camera Uploads",
- "HeaderContinueWatching": "Continue Watching",
- "HeaderFavoriteAlbums": "Favorite Albums",
+ "HeaderContinueWatching": "İzlemeye Devam Et",
+ "HeaderFavoriteAlbums": "Favori Albümler",
"HeaderFavoriteArtists": "Favorite Artists",
"HeaderFavoriteEpisodes": "Favorite Episodes",
"HeaderFavoriteShows": "Favori Showlar",
@@ -30,21 +30,21 @@
"Inherit": "Inherit",
"ItemAddedWithName": "{0} was added to the library",
"ItemRemovedWithName": "{0} was removed from the library",
- "LabelIpAddressValue": "Ip address: {0}",
- "LabelRunningTimeValue": "Running time: {0}",
+ "LabelIpAddressValue": "Ip adresi: {0}",
+ "LabelRunningTimeValue": "Çalışma süresi: {0}",
"Latest": "Latest",
- "MessageApplicationUpdated": "Jellyfin Server has been updated",
+ "MessageApplicationUpdated": "Jellyfin Sunucusu güncellendi",
"MessageApplicationUpdatedTo": "Jellyfin Server has been updated to {0}",
"MessageNamedServerConfigurationUpdatedWithValue": "Server configuration section {0} has been updated",
"MessageServerConfigurationUpdated": "Server configuration has been updated",
"MixedContent": "Mixed content",
"Movies": "Movies",
- "Music": "Music",
- "MusicVideos": "Music videos",
- "NameInstallFailed": "{0} installation failed",
- "NameSeasonNumber": "Season {0}",
- "NameSeasonUnknown": "Season Unknown",
- "NewVersionIsAvailable": "A new version of Jellyfin Server is available for download.",
+ "Music": "Müzik",
+ "MusicVideos": "Müzik videoları",
+ "NameInstallFailed": "{0} kurulum başarısız",
+ "NameSeasonNumber": "Sezon {0}",
+ "NameSeasonUnknown": "Bilinmeyen Sezon",
+ "NewVersionIsAvailable": "Jellyfin Sunucusunun yeni bir versiyonu indirmek için hazır.",
"NotificationOptionApplicationUpdateAvailable": "Application update available",
"NotificationOptionApplicationUpdateInstalled": "Application update installed",
"NotificationOptionAudioPlayback": "Audio playback started",
diff --git a/Emby.Server.Implementations/Localization/Core/zh-CN.json b/Emby.Server.Implementations/Localization/Core/zh-CN.json
index 8910a6bce..6f7d362d3 100644
--- a/Emby.Server.Implementations/Localization/Core/zh-CN.json
+++ b/Emby.Server.Implementations/Localization/Core/zh-CN.json
@@ -34,14 +34,14 @@
"LabelRunningTimeValue": "运行时间:{0}",
"Latest": "最新",
"MessageApplicationUpdated": "Jellyfin 服务器已更新",
- "MessageApplicationUpdatedTo": "Jellyfin Server has been updated to {0}",
+ "MessageApplicationUpdatedTo": "Jellyfin Server 的版本已更新为 {0}",
"MessageNamedServerConfigurationUpdatedWithValue": "服务器配置 {0} 部分已更新",
"MessageServerConfigurationUpdated": "服务器配置已更新",
"MixedContent": "混合内容",
"Movies": "电影",
"Music": "音乐",
"MusicVideos": "音乐视频",
- "NameInstallFailed": "{0} installation failed",
+ "NameInstallFailed": "{0} 安装失败",
"NameSeasonNumber": "季 {0}",
"NameSeasonUnknown": "未知季",
"NewVersionIsAvailable": "A new version of Jellyfin Server is available for download.",
@@ -70,7 +70,7 @@
"ProviderValue": "提供商:{0}",
"ScheduledTaskFailedWithName": "{0} 已失败",
"ScheduledTaskStartedWithName": "{0} 已开始",
- "ServerNameNeedsToBeRestarted": "{0} needs to be restarted",
+ "ServerNameNeedsToBeRestarted": "{0} 需要重新启动",
"Shows": "节目",
"Songs": "歌曲",
"StartupEmbyServerIsLoading": "Jellyfin 服务器加载中。请稍后再试。",
diff --git a/Emby.Server.Implementations/Localization/LocalizationManager.cs b/Emby.Server.Implementations/Localization/LocalizationManager.cs
index 31217730b..8c49b6405 100644
--- a/Emby.Server.Implementations/Localization/LocalizationManager.cs
+++ b/Emby.Server.Implementations/Localization/LocalizationManager.cs
@@ -11,7 +11,6 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Globalization;
-using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
@@ -35,7 +34,6 @@ namespace Emby.Server.Implementations.Localization
private readonly Dictionary<string, Dictionary<string, ParentalRating>> _allParentalRatings =
new Dictionary<string, Dictionary<string, ParentalRating>>(StringComparer.OrdinalIgnoreCase);
- private readonly IFileSystem _fileSystem;
private readonly IJsonSerializer _jsonSerializer;
private readonly ILogger _logger;
private static readonly Assembly _assembly = typeof(LocalizationManager).Assembly;
@@ -44,130 +42,65 @@ namespace Emby.Server.Implementations.Localization
/// Initializes a new instance of the <see cref="LocalizationManager" /> class.
/// </summary>
/// <param name="configurationManager">The configuration manager.</param>
- /// <param name="fileSystem">The file system.</param>
/// <param name="jsonSerializer">The json serializer.</param>
+ /// <param name="loggerFactory">The logger factory</param>
public LocalizationManager(
IServerConfigurationManager configurationManager,
- IFileSystem fileSystem,
IJsonSerializer jsonSerializer,
ILoggerFactory loggerFactory)
{
_configurationManager = configurationManager;
- _fileSystem = fileSystem;
_jsonSerializer = jsonSerializer;
_logger = loggerFactory.CreateLogger(nameof(LocalizationManager));
}
public async Task LoadAll()
{
- const string ratingsResource = "Emby.Server.Implementations.Localization.Ratings.";
-
- Directory.CreateDirectory(LocalizationPath);
-
- var existingFiles = GetRatingsFiles(LocalizationPath).Select(Path.GetFileName);
+ const string RatingsResource = "Emby.Server.Implementations.Localization.Ratings.";
// Extract from the assembly
foreach (var resource in _assembly.GetManifestResourceNames())
{
- if (!resource.StartsWith(ratingsResource))
+ if (!resource.StartsWith(RatingsResource, StringComparison.Ordinal))
{
continue;
}
- string filename = "ratings-" + resource.Substring(ratingsResource.Length);
-
- if (existingFiles.Contains(filename))
- {
- continue;
- }
+ string countryCode = resource.Substring(RatingsResource.Length, 2);
+ var dict = new Dictionary<string, ParentalRating>(StringComparer.OrdinalIgnoreCase);
- using (var stream = _assembly.GetManifestResourceStream(resource))
+ using (var str = _assembly.GetManifestResourceStream(resource))
+ using (var reader = new StreamReader(str))
{
- string target = Path.Combine(LocalizationPath, filename);
- _logger.LogInformation("Extracting ratings to {0}", target);
-
- using (var fs = _fileSystem.GetFileStream(target, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
+ string line;
+ while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
- await stream.CopyToAsync(fs);
+ if (string.IsNullOrWhiteSpace(line))
+ {
+ continue;
+ }
+
+ string[] parts = line.Split(',');
+ if (parts.Length == 2
+ && int.TryParse(parts[1], NumberStyles.Integer, UsCulture, out var value))
+ {
+ dict.Add(parts[0], new ParentalRating { Name = parts[0], Value = value });
+ }
+#if DEBUG
+ else
+ {
+ _logger.LogWarning("Malformed line in ratings file for country {CountryCode}", countryCode);
+ }
+#endif
}
}
- }
- foreach (var file in GetRatingsFiles(LocalizationPath))
- {
- await LoadRatings(file);
+ _allParentalRatings[countryCode] = dict;
}
- LoadAdditionalRatings();
-
- await LoadCultures();
- }
-
- private void LoadAdditionalRatings()
- {
- LoadRatings("au", new[]
- {
- new ParentalRating("AU-G", 1),
- new ParentalRating("AU-PG", 5),
- new ParentalRating("AU-M", 6),
- new ParentalRating("AU-MA15+", 7),
- new ParentalRating("AU-M15+", 8),
- new ParentalRating("AU-R18+", 9),
- new ParentalRating("AU-X18+", 10),
- new ParentalRating("AU-RC", 11)
- });
-
- LoadRatings("be", new[]
- {
- new ParentalRating("BE-AL", 1),
- new ParentalRating("BE-MG6", 2),
- new ParentalRating("BE-6", 3),
- new ParentalRating("BE-9", 5),
- new ParentalRating("BE-12", 6),
- new ParentalRating("BE-16", 8)
- });
-
- LoadRatings("de", new[]
- {
- new ParentalRating("DE-0", 1),
- new ParentalRating("FSK-0", 1),
- new ParentalRating("DE-6", 5),
- new ParentalRating("FSK-6", 5),
- new ParentalRating("DE-12", 7),
- new ParentalRating("FSK-12", 7),
- new ParentalRating("DE-16", 8),
- new ParentalRating("FSK-16", 8),
- new ParentalRating("DE-18", 9),
- new ParentalRating("FSK-18", 9)
- });
-
- LoadRatings("ru", new[]
- {
- new ParentalRating("RU-0+", 1),
- new ParentalRating("RU-6+", 3),
- new ParentalRating("RU-12+", 7),
- new ParentalRating("RU-16+", 9),
- new ParentalRating("RU-18+", 10)
- });
- }
-
- private void LoadRatings(string country, ParentalRating[] ratings)
- {
- _allParentalRatings[country] = ratings.ToDictionary(i => i.Name);
+ await LoadCultures().ConfigureAwait(false);
}
- private IEnumerable<string> GetRatingsFiles(string directory)
- => _fileSystem.GetFilePaths(directory, false)
- .Where(i => string.Equals(Path.GetExtension(i), ".csv", StringComparison.OrdinalIgnoreCase))
- .Where(i => Path.GetFileName(i).StartsWith("ratings-", StringComparison.OrdinalIgnoreCase));
-
- /// <summary>
- /// Gets the localization path.
- /// </summary>
- /// <value>The localization path.</value>
- public string LocalizationPath
- => Path.Combine(_configurationManager.ApplicationPaths.ProgramDataPath, "localization");
-
public string NormalizeFormKD(string text)
=> text.Normalize(NormalizationForm.FormKD);
@@ -184,14 +117,14 @@ namespace Emby.Server.Implementations.Localization
{
List<CultureDto> list = new List<CultureDto>();
- const string path = "Emby.Server.Implementations.Localization.iso6392.txt";
+ const string ResourcePath = "Emby.Server.Implementations.Localization.iso6392.txt";
- using (var stream = _assembly.GetManifestResourceStream(path))
+ using (var stream = _assembly.GetManifestResourceStream(ResourcePath))
using (var reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
- var line = await reader.ReadLineAsync();
+ var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(line))
{
@@ -217,11 +150,11 @@ namespace Emby.Server.Implementations.Localization
string[] threeletterNames;
if (string.IsNullOrWhiteSpace(parts[1]))
{
- threeletterNames = new [] { parts[0] };
+ threeletterNames = new[] { parts[0] };
}
else
{
- threeletterNames = new [] { parts[0], parts[1] };
+ threeletterNames = new[] { parts[0], parts[1] };
}
list.Add(new CultureDto
@@ -281,6 +214,7 @@ namespace Emby.Server.Implementations.Localization
/// Gets the ratings.
/// </summary>
/// <param name="countryCode">The country code.</param>
+ /// <returns>The ratings</returns>
private Dictionary<string, ParentalRating> GetRatings(string countryCode)
{
_allParentalRatings.TryGetValue(countryCode, out var value);
@@ -288,52 +222,14 @@ namespace Emby.Server.Implementations.Localization
return value;
}
- /// <summary>
- /// Loads the ratings.
- /// </summary>
- /// <param name="file">The file.</param>
- /// <returns>Dictionary{System.StringParentalRating}.</returns>
- private async Task LoadRatings(string file)
- {
- Dictionary<string, ParentalRating> dict
- = new Dictionary<string, ParentalRating>(StringComparer.OrdinalIgnoreCase);
-
- using (var str = File.OpenRead(file))
- using (var reader = new StreamReader(str))
- {
- string line;
- while ((line = await reader.ReadLineAsync()) != null)
- {
- if (string.IsNullOrWhiteSpace(line))
- {
- continue;
- }
-
- string[] parts = line.Split(',');
- if (parts.Length == 2
- && int.TryParse(parts[1], NumberStyles.Integer, UsCulture, out var value))
- {
- dict.Add(parts[0], (new ParentalRating { Name = parts[0], Value = value }));
- }
-#if DEBUG
- else
- {
- _logger.LogWarning("Misformed line in {Path}", file);
- }
-#endif
- }
- }
-
- var countryCode = Path.GetFileNameWithoutExtension(file).Split('-')[1];
-
- _allParentalRatings[countryCode] = dict;
- }
-
private static readonly string[] _unratedValues = { "n/a", "unrated", "not rated" };
+ /// <inheritdoc />
/// <summary>
/// Gets the rating level.
/// </summary>
+ /// <param name="rating">Rating field</param>
+ /// <returns>The rating level</returns>&gt;
public int? GetRatingLevel(string rating)
{
if (string.IsNullOrEmpty(rating))
@@ -405,6 +301,7 @@ namespace Emby.Server.Implementations.Localization
{
culture = _configurationManager.Configuration.UICulture;
}
+
if (string.IsNullOrEmpty(culture))
{
culture = DefaultCulture;
@@ -450,8 +347,8 @@ namespace Emby.Server.Implementations.Localization
var namespaceName = GetType().Namespace + "." + prefix;
- await CopyInto(dictionary, namespaceName + "." + baseFilename);
- await CopyInto(dictionary, namespaceName + "." + GetResourceFilename(culture));
+ await CopyInto(dictionary, namespaceName + "." + baseFilename).ConfigureAwait(false);
+ await CopyInto(dictionary, namespaceName + "." + GetResourceFilename(culture)).ConfigureAwait(false);
return dictionary;
}
@@ -463,7 +360,7 @@ namespace Emby.Server.Implementations.Localization
// If a Culture doesn't have a translation the stream will be null and it defaults to en-us further up the chain
if (stream != null)
{
- var dict = await _jsonSerializer.DeserializeFromStreamAsync<Dictionary<string, string>>(stream);
+ var dict = await _jsonSerializer.DeserializeFromStreamAsync<Dictionary<string, string>>(stream).ConfigureAwait(false);
foreach (var key in dict.Keys)
{
diff --git a/Emby.Server.Implementations/Localization/Ratings/au.csv b/Emby.Server.Implementations/Localization/Ratings/au.csv
new file mode 100644
index 000000000..940375e26
--- /dev/null
+++ b/Emby.Server.Implementations/Localization/Ratings/au.csv
@@ -0,0 +1,8 @@
+AU-G,1
+AU-PG,5
+AU-M,6
+AU-MA15+,7
+AU-M15+,8
+AU-R18+,9
+AU-X18+,10
+AU-RC,11
diff --git a/Emby.Server.Implementations/Localization/Ratings/be.csv b/Emby.Server.Implementations/Localization/Ratings/be.csv
new file mode 100644
index 000000000..d3937caf7
--- /dev/null
+++ b/Emby.Server.Implementations/Localization/Ratings/be.csv
@@ -0,0 +1,6 @@
+BE-AL,1
+BE-MG6,2
+BE-6,3
+BE-9,5
+BE-12,6
+BE-16,8
diff --git a/Emby.Server.Implementations/Localization/Ratings/de.csv b/Emby.Server.Implementations/Localization/Ratings/de.csv
new file mode 100644
index 000000000..f944a140d
--- /dev/null
+++ b/Emby.Server.Implementations/Localization/Ratings/de.csv
@@ -0,0 +1,10 @@
+DE-0,1
+FSK-0,1
+DE-6,5
+FSK-6,5
+DE-12,7
+FSK-12,7
+DE-16,8
+FSK-16,8
+DE-18,9
+FSK-18,9
diff --git a/Emby.Server.Implementations/Localization/Ratings/kz.csv b/Emby.Server.Implementations/Localization/Ratings/kz.csv
index 4441c5650..d546bff53 100644
--- a/Emby.Server.Implementations/Localization/Ratings/kz.csv
+++ b/Emby.Server.Implementations/Localization/Ratings/kz.csv
@@ -1,6 +1,7 @@
-KZ-К,1
-KZ-БА,6
-KZ-Б14,7
-KZ-Е16,8
-KZ-Е18,10
-KZ-НА,15
+KZ-6-,0
+KZ-6+,6
+KZ-12+,12
+KZ-14+,14
+KZ-16+,16
+KZ-18+,18
+KZ-21+,21
diff --git a/Emby.Server.Implementations/Localization/Ratings/ru.csv b/Emby.Server.Implementations/Localization/Ratings/ru.csv
new file mode 100644
index 000000000..1bc94affd
--- /dev/null
+++ b/Emby.Server.Implementations/Localization/Ratings/ru.csv
@@ -0,0 +1,5 @@
+RU-0+,1
+RU-6+,3
+RU-12+,7
+RU-16+,9
+RU-18+,10
diff --git a/Emby.Server.Implementations/MediaEncoder/EncodingManager.cs b/Emby.Server.Implementations/MediaEncoder/EncodingManager.cs
index e68046f6d..52d07d784 100644
--- a/Emby.Server.Implementations/MediaEncoder/EncodingManager.cs
+++ b/Emby.Server.Implementations/MediaEncoder/EncodingManager.cs
@@ -202,6 +202,10 @@ namespace Emby.Server.Implementations.MediaEncoder
private static List<string> GetSavedChapterImages(Video video, IDirectoryService directoryService)
{
var path = GetChapterImagesPath(video);
+ if (!Directory.Exists(path))
+ {
+ return new List<string>();
+ }
try
{
diff --git a/Emby.Server.Implementations/Middleware/WebSocketMiddleware.cs b/Emby.Server.Implementations/Middleware/WebSocketMiddleware.cs
new file mode 100644
index 000000000..268bf4042
--- /dev/null
+++ b/Emby.Server.Implementations/Middleware/WebSocketMiddleware.cs
@@ -0,0 +1,39 @@
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Logging;
+using WebSocketManager = Emby.Server.Implementations.WebSockets.WebSocketManager;
+
+namespace Emby.Server.Implementations.Middleware
+{
+ public class WebSocketMiddleware
+ {
+ private readonly RequestDelegate _next;
+ private readonly ILogger<WebSocketMiddleware> _logger;
+ private readonly WebSocketManager _webSocketManager;
+
+ public WebSocketMiddleware(RequestDelegate next, ILogger<WebSocketMiddleware> logger, WebSocketManager webSocketManager)
+ {
+ _next = next;
+ _logger = logger;
+ _webSocketManager = webSocketManager;
+ }
+
+ public async Task Invoke(HttpContext httpContext)
+ {
+ _logger.LogInformation("Handling request: " + httpContext.Request.Path);
+
+ if (httpContext.WebSockets.IsWebSocketRequest)
+ {
+ var webSocketContext = await httpContext.WebSockets.AcceptWebSocketAsync(null).ConfigureAwait(false);
+ if (webSocketContext != null)
+ {
+ await _webSocketManager.OnWebSocketConnected(webSocketContext);
+ }
+ }
+ else
+ {
+ await _next.Invoke(httpContext);
+ }
+ }
+ }
+}
diff --git a/Emby.Server.Implementations/Net/DisposableManagedObjectBase.cs b/Emby.Server.Implementations/Net/DisposableManagedObjectBase.cs
deleted file mode 100644
index 304b44565..000000000
--- a/Emby.Server.Implementations/Net/DisposableManagedObjectBase.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-using System;
-
-namespace Emby.Server.Implementations.Net
-{
- /// <summary>
- /// Correclty implements the <see cref="IDisposable"/> interface and pattern for an object containing only managed resources, and adds a few common niceities not on the interface such as an <see cref="IsDisposed"/> property.
- /// </summary>
- public abstract class DisposableManagedObjectBase : IDisposable
- {
-
- #region Public Methods
-
- /// <summary>
- /// Override this method and dispose any objects you own the lifetime of if disposing is true;
- /// </summary>
- /// <param name="disposing">True if managed objects should be disposed, if false, only unmanaged resources should be released.</param>
- protected abstract void Dispose(bool disposing);
-
-
- //TODO Remove and reimplement using the IsDisposed property directly.
- /// <summary>
- /// Throws an <see cref="ObjectDisposedException"/> if the <see cref="IsDisposed"/> property is true.
- /// </summary>
- /// <seealso cref="IsDisposed"/>
- /// <exception cref="ObjectDisposedException">Thrown if the <see cref="IsDisposed"/> property is true.</exception>
- /// <seealso cref="Dispose()"/>
- protected virtual void ThrowIfDisposed()
- {
- if (IsDisposed) throw new ObjectDisposedException(GetType().Name);
- }
-
- #endregion
-
- #region Public Properties
-
- /// <summary>
- /// Sets or returns a boolean indicating whether or not this instance has been disposed.
- /// </summary>
- /// <seealso cref="Dispose()"/>
- public bool IsDisposed
- {
- get;
- private set;
- }
-
- #endregion
-
- #region IDisposable Members
-
- /// <summary>
- /// Disposes this object instance and all internally managed resources.
- /// </summary>
- /// <remarks>
- /// <para>Sets the <see cref="IsDisposed"/> property to true. Does not explicitly throw an exception if called multiple times, but makes no promises about behaviour of derived classes.</para>
- /// </remarks>
- /// <seealso cref="IsDisposed"/>
- public void Dispose()
- {
- IsDisposed = true;
-
- Dispose(true);
- }
-
- #endregion
- }
-}
diff --git a/Emby.Server.Implementations/Net/IWebSocket.cs b/Emby.Server.Implementations/Net/IWebSocket.cs
index 4671de07c..4d160aa66 100644
--- a/Emby.Server.Implementations/Net/IWebSocket.cs
+++ b/Emby.Server.Implementations/Net/IWebSocket.cs
@@ -45,9 +45,4 @@ namespace Emby.Server.Implementations.Net
/// <returns>Task.</returns>
Task SendAsync(string text, bool endOfMessage, CancellationToken cancellationToken);
}
-
- public interface IMemoryWebSocket
- {
- Action<Memory<byte>, int> OnReceiveMemoryBytes { get; set; }
- }
}
diff --git a/Emby.Server.Implementations/Net/SocketFactory.cs b/Emby.Server.Implementations/Net/SocketFactory.cs
index 6beb14f55..492f48abe 100644
--- a/Emby.Server.Implementations/Net/SocketFactory.cs
+++ b/Emby.Server.Implementations/Net/SocketFactory.cs
@@ -4,7 +4,6 @@ using System.Net;
using System.Net.Sockets;
using Emby.Server.Implementations.Networking;
using MediaBrowser.Model.Net;
-using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Net
{
@@ -19,7 +18,10 @@ namespace Emby.Server.Implementations.Net
public ISocket CreateTcpSocket(IpAddressInfo remoteAddress, int remotePort)
{
- if (remotePort < 0) throw new ArgumentException("remotePort cannot be less than zero.", nameof(remotePort));
+ if (remotePort < 0)
+ {
+ throw new ArgumentException("remotePort cannot be less than zero.", nameof(remotePort));
+ }
var addressFamily = remoteAddress.AddressFamily == IpAddressFamily.InterNetwork
? AddressFamily.InterNetwork
@@ -42,8 +44,7 @@ namespace Emby.Server.Implementations.Net
}
catch
{
- if (retVal != null)
- retVal.Dispose();
+ retVal?.Dispose();
throw;
}
@@ -55,7 +56,10 @@ namespace Emby.Server.Implementations.Net
/// <param name="localPort">An integer specifying the local port to bind the acceptSocket to.</param>
public ISocket CreateUdpSocket(int localPort)
{
- if (localPort < 0) throw new ArgumentException("localPort cannot be less than zero.", nameof(localPort));
+ if (localPort < 0)
+ {
+ throw new ArgumentException("localPort cannot be less than zero.", nameof(localPort));
+ }
var retVal = new Socket(AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);
try
@@ -65,8 +69,7 @@ namespace Emby.Server.Implementations.Net
}
catch
{
- if (retVal != null)
- retVal.Dispose();
+ retVal?.Dispose();
throw;
}
@@ -74,7 +77,10 @@ namespace Emby.Server.Implementations.Net
public ISocket CreateUdpBroadcastSocket(int localPort)
{
- if (localPort < 0) throw new ArgumentException("localPort cannot be less than zero.", nameof(localPort));
+ if (localPort < 0)
+ {
+ throw new ArgumentException("localPort cannot be less than zero.", nameof(localPort));
+ }
var retVal = new Socket(AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);
try
@@ -86,8 +92,7 @@ namespace Emby.Server.Implementations.Net
}
catch
{
- if (retVal != null)
- retVal.Dispose();
+ retVal?.Dispose();
throw;
}
@@ -99,7 +104,10 @@ namespace Emby.Server.Implementations.Net
/// <returns>An implementation of the <see cref="ISocket"/> interface used by RSSDP components to perform acceptSocket operations.</returns>
public ISocket CreateSsdpUdpSocket(IpAddressInfo localIpAddress, int localPort)
{
- if (localPort < 0) throw new ArgumentException("localPort cannot be less than zero.", nameof(localPort));
+ if (localPort < 0)
+ {
+ throw new ArgumentException("localPort cannot be less than zero.", nameof(localPort));
+ }
var retVal = new Socket(AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);
try
@@ -114,8 +122,7 @@ namespace Emby.Server.Implementations.Net
}
catch
{
- if (retVal != null)
- retVal.Dispose();
+ retVal?.Dispose();
throw;
}
@@ -130,10 +137,25 @@ namespace Emby.Server.Implementations.Net
/// <returns></returns>
public ISocket CreateUdpMulticastSocket(string ipAddress, int multicastTimeToLive, int localPort)
{
- if (ipAddress == null) throw new ArgumentNullException(nameof(ipAddress));
- if (ipAddress.Length == 0) throw new ArgumentException("ipAddress cannot be an empty string.", nameof(ipAddress));
- if (multicastTimeToLive <= 0) throw new ArgumentException("multicastTimeToLive cannot be zero or less.", nameof(multicastTimeToLive));
- if (localPort < 0) throw new ArgumentException("localPort cannot be less than zero.", nameof(localPort));
+ if (ipAddress == null)
+ {
+ throw new ArgumentNullException(nameof(ipAddress));
+ }
+
+ if (ipAddress.Length == 0)
+ {
+ throw new ArgumentException("ipAddress cannot be an empty string.", nameof(ipAddress));
+ }
+
+ if (multicastTimeToLive <= 0)
+ {
+ throw new ArgumentException("multicastTimeToLive cannot be zero or less.", nameof(multicastTimeToLive));
+ }
+
+ if (localPort < 0)
+ {
+ throw new ArgumentException("localPort cannot be less than zero.", nameof(localPort));
+ }
var retVal = new Socket(AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);
@@ -172,87 +194,13 @@ namespace Emby.Server.Implementations.Net
}
catch
{
- if (retVal != null)
- retVal.Dispose();
+ retVal?.Dispose();
throw;
}
}
public Stream CreateNetworkStream(ISocket socket, bool ownsSocket)
- {
- var netSocket = (UdpSocket)socket;
-
- return new SocketStream(netSocket.Socket, ownsSocket);
- }
+ => new NetworkStream(((UdpSocket)socket).Socket, ownsSocket);
}
-
- public class SocketStream : Stream
- {
- private readonly Socket _socket;
-
- public SocketStream(Socket socket, bool ownsSocket)
- {
- _socket = socket;
- }
-
- public override void Flush()
- {
- }
-
- public override bool CanRead => true;
-
- public override bool CanSeek => false;
-
- public override bool CanWrite => true;
-
- public override long Length => throw new NotImplementedException();
-
- public override long Position
- {
- get => throw new NotImplementedException();
- set => throw new NotImplementedException();
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- _socket.Send(buffer, offset, count, SocketFlags.None);
- }
-
- public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
- {
- return _socket.BeginSend(buffer, offset, count, SocketFlags.None, callback, state);
- }
-
- public override void EndWrite(IAsyncResult asyncResult)
- {
- _socket.EndSend(asyncResult);
- }
-
- public override void SetLength(long value)
- {
- throw new NotImplementedException();
- }
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotImplementedException();
- }
-
- public override int Read(byte[] buffer, int offset, int count)
- {
- return _socket.Receive(buffer, offset, count, SocketFlags.None);
- }
-
- public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
- {
- return _socket.BeginReceive(buffer, offset, count, SocketFlags.None, callback, state);
- }
-
- public override int EndRead(IAsyncResult asyncResult)
- {
- return _socket.EndReceive(asyncResult);
- }
- }
-
}
diff --git a/Emby.Server.Implementations/Net/UdpSocket.cs b/Emby.Server.Implementations/Net/UdpSocket.cs
index d48855486..6c55085c8 100644
--- a/Emby.Server.Implementations/Net/UdpSocket.cs
+++ b/Emby.Server.Implementations/Net/UdpSocket.cs
@@ -11,12 +11,15 @@ namespace Emby.Server.Implementations.Net
// THIS IS A LINKED FILE - SHARED AMONGST MULTIPLE PLATFORMS
// Be careful to check any changes compile and work for all platform projects it is shared in.
- public sealed class UdpSocket : DisposableManagedObjectBase, ISocket
+ public sealed class UdpSocket : ISocket, IDisposable
{
- private Socket _Socket;
- private int _LocalPort;
+ private Socket _socket;
+ private int _localPort;
+ private bool _disposed = false;
- public Socket Socket => _Socket;
+ public Socket Socket => _socket;
+
+ public IpAddressInfo LocalIPAddress { get; }
private readonly SocketAsyncEventArgs _receiveSocketAsyncEventArgs = new SocketAsyncEventArgs()
{
@@ -35,11 +38,11 @@ namespace Emby.Server.Implementations.Net
{
if (socket == null) throw new ArgumentNullException(nameof(socket));
- _Socket = socket;
- _LocalPort = localPort;
+ _socket = socket;
+ _localPort = localPort;
LocalIPAddress = NetworkManager.ToIpAddressInfo(ip);
- _Socket.Bind(new IPEndPoint(ip, _LocalPort));
+ _socket.Bind(new IPEndPoint(ip, _localPort));
InitReceiveSocketAsyncEventArgs();
}
@@ -101,32 +104,26 @@ namespace Emby.Server.Implementations.Net
{
if (socket == null) throw new ArgumentNullException(nameof(socket));
- _Socket = socket;
- _Socket.Connect(NetworkManager.ToIPEndPoint(endPoint));
+ _socket = socket;
+ _socket.Connect(NetworkManager.ToIPEndPoint(endPoint));
InitReceiveSocketAsyncEventArgs();
}
- public IpAddressInfo LocalIPAddress
- {
- get;
- private set;
- }
-
public IAsyncResult BeginReceive(byte[] buffer, int offset, int count, AsyncCallback callback)
{
ThrowIfDisposed();
EndPoint receivedFromEndPoint = new IPEndPoint(IPAddress.Any, 0);
- return _Socket.BeginReceiveFrom(buffer, offset, count, SocketFlags.None, ref receivedFromEndPoint, callback, buffer);
+ return _socket.BeginReceiveFrom(buffer, offset, count, SocketFlags.None, ref receivedFromEndPoint, callback, buffer);
}
public int Receive(byte[] buffer, int offset, int count)
{
ThrowIfDisposed();
- return _Socket.Receive(buffer, 0, buffer.Length, SocketFlags.None);
+ return _socket.Receive(buffer, 0, buffer.Length, SocketFlags.None);
}
public SocketReceiveResult EndReceive(IAsyncResult result)
@@ -136,7 +133,7 @@ namespace Emby.Server.Implementations.Net
var sender = new IPEndPoint(IPAddress.Any, 0);
var remoteEndPoint = (EndPoint)sender;
- var receivedBytes = _Socket.EndReceiveFrom(result, ref remoteEndPoint);
+ var receivedBytes = _socket.EndReceiveFrom(result, ref remoteEndPoint);
var buffer = (byte[])result.AsyncState;
@@ -236,35 +233,40 @@ namespace Emby.Server.Implementations.Net
var ipEndPoint = NetworkManager.ToIPEndPoint(endPoint);
- return _Socket.BeginSendTo(buffer, offset, size, SocketFlags.None, ipEndPoint, callback, state);
+ return _socket.BeginSendTo(buffer, offset, size, SocketFlags.None, ipEndPoint, callback, state);
}
public int EndSendTo(IAsyncResult result)
{
ThrowIfDisposed();
- return _Socket.EndSendTo(result);
+ return _socket.EndSendTo(result);
}
- protected override void Dispose(bool disposing)
+ private void ThrowIfDisposed()
{
- if (disposing)
+ if (_disposed)
{
- var socket = _Socket;
- if (socket != null)
- socket.Dispose();
+ throw new ObjectDisposedException(nameof(UdpSocket));
+ }
+ }
- var tcs = _currentReceiveTaskCompletionSource;
- if (tcs != null)
- {
- tcs.TrySetCanceled();
- }
- var sendTcs = _currentSendTaskCompletionSource;
- if (sendTcs != null)
- {
- sendTcs.TrySetCanceled();
- }
+ public void Dispose()
+ {
+ if (_disposed)
+ {
+ return;
}
+
+ _socket?.Dispose();
+ _currentReceiveTaskCompletionSource?.TrySetCanceled();
+ _currentSendTaskCompletionSource?.TrySetCanceled();
+
+ _socket = null;
+ _currentReceiveTaskCompletionSource = null;
+ _currentSendTaskCompletionSource = null;
+
+ _disposed = true;
}
private static IpEndPointInfo ToIpEndPointInfo(IPEndPoint endpoint)
diff --git a/Emby.Server.Implementations/Net/WebSocketConnectEventArgs.cs b/Emby.Server.Implementations/Net/WebSocketConnectEventArgs.cs
index 3ab8e854a..e3047d392 100644
--- a/Emby.Server.Implementations/Net/WebSocketConnectEventArgs.cs
+++ b/Emby.Server.Implementations/Net/WebSocketConnectEventArgs.cs
@@ -1,5 +1,7 @@
using System;
+using System.Net.WebSockets;
using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
namespace Emby.Server.Implementations.Net
{
@@ -14,7 +16,7 @@ namespace Emby.Server.Implementations.Net
/// Gets or sets the query string.
/// </summary>
/// <value>The query string.</value>
- public QueryParamCollection QueryString { get; set; }
+ public IQueryCollection QueryString { get; set; }
/// <summary>
/// Gets or sets the web socket.
/// </summary>
diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs
index 60cc9b88e..c102f9eb5 100644
--- a/Emby.Server.Implementations/Networking/NetworkManager.cs
+++ b/Emby.Server.Implementations/Networking/NetworkManager.cs
@@ -7,11 +7,11 @@ using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
-using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
+using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace Emby.Server.Implementations.Networking
{
@@ -22,14 +22,12 @@ namespace Emby.Server.Implementations.Networking
public event EventHandler NetworkChanged;
public Func<string[]> LocalSubnetsFn { get; set; }
- public NetworkManager(
- ILoggerFactory loggerFactory,
- IEnvironmentInfo environment)
+ public NetworkManager(ILoggerFactory loggerFactory)
{
Logger = loggerFactory.CreateLogger(nameof(NetworkManager));
// In FreeBSD these events cause a crash
- if (environment.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.BSD)
+ if (OperatingSystem.Id != OperatingSystemId.BSD)
{
try
{
@@ -79,13 +77,13 @@ namespace Emby.Server.Implementations.Networking
private IpAddressInfo[] _localIpAddresses;
private readonly object _localIpAddressSyncLock = new object();
- public IpAddressInfo[] GetLocalIpAddresses()
+ public IpAddressInfo[] GetLocalIpAddresses(bool ignoreVirtualInterface = true)
{
lock (_localIpAddressSyncLock)
{
if (_localIpAddresses == null)
{
- var addresses = GetLocalIpAddressesInternal().Result.Select(ToIpAddressInfo).ToArray();
+ var addresses = GetLocalIpAddressesInternal(ignoreVirtualInterface).Result.Select(ToIpAddressInfo).ToArray();
_localIpAddresses = addresses;
@@ -95,9 +93,9 @@ namespace Emby.Server.Implementations.Networking
}
}
- private async Task<List<IPAddress>> GetLocalIpAddressesInternal()
+ private async Task<List<IPAddress>> GetLocalIpAddressesInternal(bool ignoreVirtualInterface)
{
- var list = GetIPsDefault()
+ var list = GetIPsDefault(ignoreVirtualInterface)
.ToList();
if (list.Count == 0)
@@ -383,7 +381,7 @@ namespace Emby.Server.Implementations.Networking
return Dns.GetHostAddressesAsync(hostName);
}
- private List<IPAddress> GetIPsDefault()
+ private List<IPAddress> GetIPsDefault(bool ignoreVirtualInterface)
{
NetworkInterface[] interfaces;
@@ -414,7 +412,7 @@ namespace Emby.Server.Implementations.Networking
// Try to exclude virtual adapters
// http://stackoverflow.com/questions/8089685/c-sharp-finding-my-machines-local-ip-address-and-not-the-vms
var addr = ipProperties.GatewayAddresses.FirstOrDefault();
- if (addr == null || string.Equals(addr.Address.ToString(), "0.0.0.0", StringComparison.OrdinalIgnoreCase))
+ if (addr == null || ignoreVirtualInterface && string.Equals(addr.Address.ToString(), "0.0.0.0", StringComparison.OrdinalIgnoreCase))
{
return new List<IPAddress>();
}
@@ -636,6 +634,66 @@ namespace Emby.Server.Implementations.Networking
return false;
}
+ public bool IsInSameSubnet(IpAddressInfo address1, IpAddressInfo address2, IpAddressInfo subnetMask)
+ {
+ IPAddress network1 = GetNetworkAddress(ToIPAddress(address1), ToIPAddress(subnetMask));
+ IPAddress network2 = GetNetworkAddress(ToIPAddress(address2), ToIPAddress(subnetMask));
+ return network1.Equals(network2);
+ }
+
+ private IPAddress GetNetworkAddress(IPAddress address, IPAddress subnetMask)
+ {
+ byte[] ipAdressBytes = address.GetAddressBytes();
+ byte[] subnetMaskBytes = subnetMask.GetAddressBytes();
+
+ if (ipAdressBytes.Length != subnetMaskBytes.Length)
+ {
+ throw new ArgumentException("Lengths of IP address and subnet mask do not match.");
+ }
+
+ byte[] broadcastAddress = new byte[ipAdressBytes.Length];
+ for (int i = 0; i < broadcastAddress.Length; i++)
+ {
+ broadcastAddress[i] = (byte)(ipAdressBytes[i] & (subnetMaskBytes[i]));
+ }
+ return new IPAddress(broadcastAddress);
+ }
+
+ public IpAddressInfo GetLocalIpSubnetMask(IpAddressInfo address)
+ {
+ NetworkInterface[] interfaces;
+ IPAddress ipaddress = ToIPAddress(address);
+
+ try
+ {
+ var validStatuses = new[] { OperationalStatus.Up, OperationalStatus.Unknown };
+
+ interfaces = NetworkInterface.GetAllNetworkInterfaces()
+ .Where(i => validStatuses.Contains(i.OperationalStatus))
+ .ToArray();
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex, "Error in GetAllNetworkInterfaces");
+ return null;
+ }
+
+ foreach (NetworkInterface ni in interfaces)
+ {
+ if (ni.GetIPProperties().GatewayAddresses.FirstOrDefault() != null)
+ {
+ foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
+ {
+ if (ip.Address.Equals(ipaddress) && ip.IPv4Mask != null)
+ {
+ return ToIpAddressInfo(ip.IPv4Mask);
+ }
+ }
+ }
+ }
+ return null;
+ }
+
public static IpEndPointInfo ToIpEndPointInfo(IPEndPoint endpoint)
{
if (endpoint == null)
diff --git a/Emby.Server.Implementations/Playlists/PlaylistImageProvider.cs b/Emby.Server.Implementations/Playlists/PlaylistImageProvider.cs
index 8a7c1492d..cad66a80f 100644
--- a/Emby.Server.Implementations/Playlists/PlaylistImageProvider.cs
+++ b/Emby.Server.Implementations/Playlists/PlaylistImageProvider.cs
@@ -24,7 +24,7 @@ namespace Emby.Server.Implementations.Playlists
{
}
- protected override List<BaseItem> GetItemsWithImages(BaseItem item)
+ protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{
var playlist = (Playlist)item;
@@ -78,7 +78,7 @@ namespace Emby.Server.Implementations.Playlists
_libraryManager = libraryManager;
}
- protected override List<BaseItem> GetItemsWithImages(BaseItem item)
+ protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{
return _libraryManager.GetItemList(new InternalItemsQuery
{
@@ -89,7 +89,6 @@ namespace Emby.Server.Implementations.Playlists
Recursive = true,
ImageTypes = new[] { ImageType.Primary },
DtoOptions = new DtoOptions(false)
-
});
}
}
@@ -103,7 +102,7 @@ namespace Emby.Server.Implementations.Playlists
_libraryManager = libraryManager;
}
- protected override List<BaseItem> GetItemsWithImages(BaseItem item)
+ protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{
return _libraryManager.GetItemList(new InternalItemsQuery
{
@@ -116,11 +115,5 @@ namespace Emby.Server.Implementations.Playlists
DtoOptions = new DtoOptions(false)
});
}
-
- //protected override Task<string> CreateImage(IHasMetadata item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
- //{
- // return CreateSingleImage(itemsWithImages, outputPathWithoutExtension, ImageType.Primary);
- //}
}
-
}
diff --git a/Emby.Server.Implementations/Properties/AssemblyInfo.cs b/Emby.Server.Implementations/Properties/AssemblyInfo.cs
index 79ba9374c..a1933f66e 100644
--- a/Emby.Server.Implementations/Properties/AssemblyInfo.cs
+++ b/Emby.Server.Implementations/Properties/AssemblyInfo.cs
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
[assembly: AssemblyProduct("Jellyfin Server")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/Emby.Server.Implementations/Reflection/AssemblyInfo.cs b/Emby.Server.Implementations/Reflection/AssemblyInfo.cs
deleted file mode 100644
index 9d16fe43f..000000000
--- a/Emby.Server.Implementations/Reflection/AssemblyInfo.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System;
-using System.IO;
-using System.Reflection;
-using MediaBrowser.Model.Reflection;
-
-namespace Emby.Server.Implementations.Reflection
-{
- public class AssemblyInfo : IAssemblyInfo
- {
- public Stream GetManifestResourceStream(Type type, string resource)
- {
- return type.Assembly.GetManifestResourceStream(resource);
- }
-
- public string[] GetManifestResourceNames(Type type)
- {
- return type.Assembly.GetManifestResourceNames();
- }
-
- public Assembly[] GetCurrentAssemblies()
- {
- return AppDomain.CurrentDomain.GetAssemblies();
- }
- }
-}
diff --git a/Emby.Server.Implementations/ScheduledTasks/Triggers/DailyTrigger.cs b/Emby.Server.Implementations/ScheduledTasks/Triggers/DailyTrigger.cs
index 98685cebe..ec9466c4a 100644
--- a/Emby.Server.Implementations/ScheduledTasks/Triggers/DailyTrigger.cs
+++ b/Emby.Server.Implementations/ScheduledTasks/Triggers/DailyTrigger.cs
@@ -44,7 +44,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
var dueTime = triggerDate - now;
- logger.LogInformation("Daily trigger for {0} set to fire at {1}, which is {2} minutes from now.", taskName, triggerDate.ToString(), dueTime.TotalMinutes.ToString(CultureInfo.InvariantCulture));
+ logger.LogInformation("Daily trigger for {Task} set to fire at {TriggerDate:g}, which is {DueTime:g} from now.", taskName, triggerDate, dueTime);
Timer = new Timer(state => OnTriggered(), null, dueTime, TimeSpan.FromMilliseconds(-1));
}
diff --git a/Emby.Server.Implementations/Security/EncryptionManager.cs b/Emby.Server.Implementations/Security/EncryptionManager.cs
deleted file mode 100644
index fa8872ccc..000000000
--- a/Emby.Server.Implementations/Security/EncryptionManager.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-using System;
-using System.Text;
-using MediaBrowser.Controller.Security;
-
-namespace Emby.Server.Implementations.Security
-{
- public class EncryptionManager : IEncryptionManager
- {
- /// <summary>
- /// Encrypts the string.
- /// </summary>
- /// <param name="value">The value.</param>
- /// <returns>System.String.</returns>
- /// <exception cref="ArgumentNullException">value</exception>
- public string EncryptString(string value)
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- return EncryptStringUniversal(value);
- }
-
- /// <summary>
- /// Decrypts the string.
- /// </summary>
- /// <param name="value">The value.</param>
- /// <returns>System.String.</returns>
- /// <exception cref="ArgumentNullException">value</exception>
- public string DecryptString(string value)
- {
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- return DecryptStringUniversal(value);
- }
-
- private static string EncryptStringUniversal(string value)
- {
- // Yes, this isn't good, but ProtectedData in mono is throwing exceptions, so use this for now
-
- var bytes = Encoding.UTF8.GetBytes(value);
- return Convert.ToBase64String(bytes);
- }
-
- private static string DecryptStringUniversal(string value)
- {
- // Yes, this isn't good, but ProtectedData in mono is throwing exceptions, so use this for now
-
- var bytes = Convert.FromBase64String(value);
- return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
- }
- }
-}
diff --git a/Emby.Server.Implementations/Serialization/JsonSerializer.cs b/Emby.Server.Implementations/Serialization/JsonSerializer.cs
index 44898d498..8ae7fd90c 100644
--- a/Emby.Server.Implementations/Serialization/JsonSerializer.cs
+++ b/Emby.Server.Implementations/Serialization/JsonSerializer.cs
@@ -42,6 +42,27 @@ namespace Emby.Server.Implementations.Serialization
}
/// <summary>
+ /// Serializes to stream.
+ /// </summary>
+ /// <param name="obj">The obj.</param>
+ /// <param name="stream">The stream.</param>
+ /// <exception cref="ArgumentNullException">obj</exception>
+ public void SerializeToStream<T>(T obj, Stream stream)
+ {
+ if (obj == null)
+ {
+ throw new ArgumentNullException(nameof(obj));
+ }
+
+ if (stream == null)
+ {
+ throw new ArgumentNullException(nameof(stream));
+ }
+
+ ServiceStack.Text.JsonSerializer.SerializeToStream<T>(obj, stream);
+ }
+
+ /// <summary>
/// Serializes to file.
/// </summary>
/// <param name="obj">The obj.</param>
diff --git a/Emby.Server.Implementations/ServerApplicationPaths.cs b/Emby.Server.Implementations/ServerApplicationPaths.cs
index 05f6469ec..adaf23234 100644
--- a/Emby.Server.Implementations/ServerApplicationPaths.cs
+++ b/Emby.Server.Implementations/ServerApplicationPaths.cs
@@ -17,11 +17,13 @@ namespace Emby.Server.Implementations
string programDataPath,
string logDirectoryPath,
string configurationDirectoryPath,
- string cacheDirectoryPath)
+ string cacheDirectoryPath,
+ string webDirectoryPath)
: base(programDataPath,
logDirectoryPath,
configurationDirectoryPath,
- cacheDirectoryPath)
+ cacheDirectoryPath,
+ webDirectoryPath)
{
}
diff --git a/Emby.Server.Implementations/Services/HttpResult.cs b/Emby.Server.Implementations/Services/HttpResult.cs
index 296da2f7a..b6758486c 100644
--- a/Emby.Server.Implementations/Services/HttpResult.cs
+++ b/Emby.Server.Implementations/Services/HttpResult.cs
@@ -43,14 +43,9 @@ namespace Emby.Server.Implementations.Services
{
var contentLength = bytesResponse.Length;
- if (response != null)
- {
- response.SetContentLength(contentLength);
- }
-
if (contentLength > 0)
{
- await responseStream.WriteAsync(bytesResponse, 0, contentLength).ConfigureAwait(false);
+ await responseStream.WriteAsync(bytesResponse, 0, contentLength, cancellationToken).ConfigureAwait(false);
}
return;
}
diff --git a/Emby.Server.Implementations/Services/ResponseHelper.cs b/Emby.Server.Implementations/Services/ResponseHelper.cs
index dc9975347..0301ff335 100644
--- a/Emby.Server.Implementations/Services/ResponseHelper.cs
+++ b/Emby.Server.Implementations/Services/ResponseHelper.cs
@@ -20,8 +20,6 @@ namespace Emby.Server.Implementations.Services
{
response.StatusCode = (int)HttpStatusCode.NoContent;
}
-
- response.SetContentLength(0);
return Task.CompletedTask;
}
@@ -55,7 +53,6 @@ namespace Emby.Server.Implementations.Services
{
if (string.Equals(responseHeaders.Key, "Content-Length", StringComparison.OrdinalIgnoreCase))
{
- response.SetContentLength(long.Parse(responseHeaders.Value));
continue;
}
@@ -104,7 +101,6 @@ namespace Emby.Server.Implementations.Services
if (bytes != null)
{
response.ContentType = "application/octet-stream";
- response.SetContentLength(bytes.Length);
if (bytes.Length > 0)
{
@@ -117,7 +113,6 @@ namespace Emby.Server.Implementations.Services
if (responseText != null)
{
bytes = Encoding.UTF8.GetBytes(responseText);
- response.SetContentLength(bytes.Length);
if (bytes.Length > 0)
{
return response.OutputStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken);
@@ -149,8 +144,6 @@ namespace Emby.Server.Implementations.Services
var contentLength = ms.Length;
- response.SetContentLength(contentLength);
-
if (contentLength > 0)
{
await ms.CopyToAsync(response.OutputStream).ConfigureAwait(false);
diff --git a/Emby.Server.Implementations/Services/ServiceExec.cs b/Emby.Server.Implementations/Services/ServiceExec.cs
index 79f5c59e6..38952628d 100644
--- a/Emby.Server.Implementations/Services/ServiceExec.cs
+++ b/Emby.Server.Implementations/Services/ServiceExec.cs
@@ -78,7 +78,7 @@ namespace Emby.Server.Implementations.Services
foreach (var requestFilter in actionContext.RequestFilters)
{
requestFilter.RequestFilter(request, request.Response, requestDto);
- if (request.Response.IsClosed)
+ if (request.Response.OriginalResponse.HasStarted)
{
Task.FromResult<object>(null);
}
diff --git a/Emby.Server.Implementations/Services/ServiceHandler.cs b/Emby.Server.Implementations/Services/ServiceHandler.cs
index 7e836e22c..3c8adfc98 100644
--- a/Emby.Server.Implementations/Services/ServiceHandler.cs
+++ b/Emby.Server.Implementations/Services/ServiceHandler.cs
@@ -154,7 +154,7 @@ namespace Emby.Server.Implementations.Services
{
if (name == null) continue; //thank you ASP.NET
- var values = request.QueryString.GetValues(name);
+ var values = request.QueryString[name];
if (values.Count == 1)
{
map[name] = values[0];
diff --git a/Emby.Server.Implementations/Services/ServicePath.cs b/Emby.Server.Implementations/Services/ServicePath.cs
index f575baca3..ccb28e8df 100644
--- a/Emby.Server.Implementations/Services/ServicePath.cs
+++ b/Emby.Server.Implementations/Services/ServicePath.cs
@@ -16,7 +16,7 @@ namespace Emby.Server.Implementations.Services
private const char ComponentSeperator = '.';
private const string VariablePrefix = "{";
- readonly bool[] componentsWithSeparators;
+ private readonly bool[] componentsWithSeparators;
private readonly string restPath;
public bool IsWildCardPath { get; private set; }
@@ -54,10 +54,6 @@ namespace Emby.Server.Implementations.Services
public string Description { get; private set; }
public bool IsHidden { get; private set; }
- public int Priority { get; set; } //passed back to RouteAttribute
-
- public IEnumerable<string> PathVariables => this.variablesNames.Where(e => !string.IsNullOrWhiteSpace(e));
-
public static string[] GetPathPartsForMatching(string pathInfo)
{
return pathInfo.ToLowerInvariant().Split(new[] { PathSeperatorChar }, StringSplitOptions.RemoveEmptyEntries);
@@ -83,9 +79,12 @@ namespace Emby.Server.Implementations.Services
{
list.Add(hashPrefix + part);
- var subParts = part.Split(ComponentSeperator);
- if (subParts.Length == 1) continue;
+ if (part.IndexOf(ComponentSeperator) == -1)
+ {
+ continue;
+ }
+ var subParts = part.Split(ComponentSeperator);
foreach (var subPart in subParts)
{
list.Add(hashPrefix + subPart);
@@ -114,7 +113,7 @@ namespace Emby.Server.Implementations.Services
{
if (string.IsNullOrEmpty(component)) continue;
- if (StringContains(component, VariablePrefix)
+ if (component.IndexOf(VariablePrefix, StringComparison.OrdinalIgnoreCase) != -1
&& component.IndexOf(ComponentSeperator) != -1)
{
hasSeparators.Add(true);
@@ -165,7 +164,11 @@ namespace Emby.Server.Implementations.Services
for (var i = 0; i < components.Length - 1; i++)
{
- if (!this.isWildcard[i]) continue;
+ if (!this.isWildcard[i])
+ {
+ continue;
+ }
+
if (this.literalsToMatch[i + 1] == null)
{
throw new ArgumentException(
@@ -173,7 +176,7 @@ namespace Emby.Server.Implementations.Services
}
}
- this.wildcardCount = this.isWildcard.Count(x => x);
+ this.wildcardCount = this.isWildcard.Length;
this.IsWildCardPath = this.wildcardCount > 0;
this.FirstMatchHashKey = !this.IsWildCardPath
@@ -181,19 +184,14 @@ namespace Emby.Server.Implementations.Services
: WildCardChar + PathSeperator + firstLiteralMatch;
this.typeDeserializer = new StringMapTypeDeserializer(createInstanceFn, getParseFn, this.RequestType);
- RegisterCaseInsenstivePropertyNameMappings();
- }
- private void RegisterCaseInsenstivePropertyNameMappings()
- {
- foreach (var propertyInfo in GetSerializableProperties(RequestType))
- {
- var propertyName = propertyInfo.Name;
- propertyNamesMap.Add(propertyName.ToLowerInvariant(), propertyName);
- }
+ _propertyNamesMap = new HashSet<string>(
+ GetSerializableProperties(RequestType).Select(x => x.Name),
+ StringComparer.OrdinalIgnoreCase);
}
- internal static string[] IgnoreAttributesNamed = new[] {
+ internal static string[] IgnoreAttributesNamed = new[]
+ {
"IgnoreDataMemberAttribute",
"JsonIgnoreAttribute"
};
@@ -201,19 +199,12 @@ namespace Emby.Server.Implementations.Services
private static Type excludeType = typeof(Stream);
- internal static List<PropertyInfo> GetSerializableProperties(Type type)
+ internal static IEnumerable<PropertyInfo> GetSerializableProperties(Type type)
{
- var list = new List<PropertyInfo>();
- var props = GetPublicProperties(type);
-
- foreach (var prop in props)
+ foreach (var prop in GetPublicProperties(type))
{
- if (prop.GetMethod == null)
- {
- continue;
- }
-
- if (excludeType == prop.PropertyType)
+ if (prop.GetMethod == null
+ || excludeType == prop.PropertyType)
{
continue;
}
@@ -230,23 +221,21 @@ namespace Emby.Server.Implementations.Services
if (!ignored)
{
- list.Add(prop);
+ yield return prop;
}
}
-
- // else return those properties that are not decorated with IgnoreDataMember
- return list;
}
- private static List<PropertyInfo> GetPublicProperties(Type type)
+ private static IEnumerable<PropertyInfo> GetPublicProperties(Type type)
{
- if (type.GetTypeInfo().IsInterface)
+ if (type.IsInterface)
{
var propertyInfos = new List<PropertyInfo>();
-
- var considered = new List<Type>();
+ var considered = new List<Type>()
+ {
+ type
+ };
var queue = new Queue<Type>();
- considered.Add(type);
queue.Enqueue(type);
while (queue.Count > 0)
@@ -254,15 +243,16 @@ namespace Emby.Server.Implementations.Services
var subType = queue.Dequeue();
foreach (var subInterface in subType.GetTypeInfo().ImplementedInterfaces)
{
- if (considered.Contains(subInterface)) continue;
+ if (considered.Contains(subInterface))
+ {
+ continue;
+ }
considered.Add(subInterface);
queue.Enqueue(subInterface);
}
- var typeProperties = GetTypesPublicProperties(subType);
-
- var newPropertyInfos = typeProperties
+ var newPropertyInfos = GetTypesPublicProperties(subType)
.Where(x => !propertyInfos.Contains(x));
propertyInfos.InsertRange(0, newPropertyInfos);
@@ -271,28 +261,22 @@ namespace Emby.Server.Implementations.Services
return propertyInfos;
}
- var list = new List<PropertyInfo>();
-
- foreach (var t in GetTypesPublicProperties(type))
- {
- if (t.GetIndexParameters().Length == 0)
- {
- list.Add(t);
- }
- }
- return list;
+ return GetTypesPublicProperties(type)
+ .Where(x => x.GetIndexParameters().Length == 0);
}
- private static PropertyInfo[] GetTypesPublicProperties(Type subType)
+ private static IEnumerable<PropertyInfo> GetTypesPublicProperties(Type subType)
{
- var pis = new List<PropertyInfo>();
foreach (var pi in subType.GetRuntimeProperties())
{
var mi = pi.GetMethod ?? pi.SetMethod;
- if (mi != null && mi.IsStatic) continue;
- pis.Add(pi);
+ if (mi != null && mi.IsStatic)
+ {
+ continue;
+ }
+
+ yield return pi;
}
- return pis.ToArray();
}
/// <summary>
@@ -302,7 +286,7 @@ namespace Emby.Server.Implementations.Services
private readonly StringMapTypeDeserializer typeDeserializer;
- private readonly Dictionary<string, string> propertyNamesMap = new Dictionary<string, string>();
+ private readonly HashSet<string> _propertyNamesMap;
public int MatchScore(string httpMethod, string[] withPathInfoParts)
{
@@ -312,13 +296,10 @@ namespace Emby.Server.Implementations.Services
return -1;
}
- var score = 0;
-
//Routes with least wildcard matches get the highest score
- score += Math.Max((100 - wildcardMatchCount), 1) * 1000;
-
- //Routes with less variable (and more literal) matches
- score += Math.Max((10 - VariableArgsCount), 1) * 100;
+ var score = Math.Max((100 - wildcardMatchCount), 1) * 1000
+ //Routes with less variable (and more literal) matches
+ + Math.Max((10 - VariableArgsCount), 1) * 100;
//Exact verb match is better than ANY
if (Verbs.Length == 1 && string.Equals(httpMethod, Verbs[0], StringComparison.OrdinalIgnoreCase))
@@ -333,11 +314,6 @@ namespace Emby.Server.Implementations.Services
return score;
}
- private bool StringContains(string str1, string str2)
- {
- return str1.IndexOf(str2, StringComparison.OrdinalIgnoreCase) != -1;
- }
-
/// <summary>
/// For performance withPathInfoParts should already be a lower case string
/// to minimize redundant matching operations.
@@ -374,7 +350,8 @@ namespace Emby.Server.Implementations.Services
if (i < this.TotalComponentsCount - 1)
{
// Continue to consume up until a match with the next literal
- while (pathIx < withPathInfoParts.Length && !LiteralsEqual(withPathInfoParts[pathIx], this.literalsToMatch[i + 1]))
+ while (pathIx < withPathInfoParts.Length
+ && !string.Equals(withPathInfoParts[pathIx], this.literalsToMatch[i + 1], StringComparison.InvariantCultureIgnoreCase))
{
pathIx++;
wildcardMatchCount++;
@@ -403,10 +380,12 @@ namespace Emby.Server.Implementations.Services
continue;
}
- if (withPathInfoParts.Length <= pathIx || !LiteralsEqual(withPathInfoParts[pathIx], literalToMatch))
+ if (withPathInfoParts.Length <= pathIx
+ || !string.Equals(withPathInfoParts[pathIx], literalToMatch, StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
+
pathIx++;
}
}
@@ -414,35 +393,26 @@ namespace Emby.Server.Implementations.Services
return pathIx == withPathInfoParts.Length;
}
- private static bool LiteralsEqual(string str1, string str2)
- {
- // Most cases
- if (string.Equals(str1, str2, StringComparison.OrdinalIgnoreCase))
- {
- return true;
- }
-
- // Handle turkish i
- str1 = str1.ToUpperInvariant();
- str2 = str2.ToUpperInvariant();
-
- // Invariant IgnoreCase would probably be better but it's not available in PCL
- return string.Equals(str1, str2, StringComparison.CurrentCultureIgnoreCase);
- }
-
private bool ExplodeComponents(ref string[] withPathInfoParts)
{
var totalComponents = new List<string>();
for (var i = 0; i < withPathInfoParts.Length; i++)
{
var component = withPathInfoParts[i];
- if (string.IsNullOrEmpty(component)) continue;
+ if (string.IsNullOrEmpty(component))
+ {
+ continue;
+ }
if (this.PathComponentsCount != this.TotalComponentsCount
&& this.componentsWithSeparators[i])
{
var subComponents = component.Split(ComponentSeperator);
- if (subComponents.Length < 2) return false;
+ if (subComponents.Length < 2)
+ {
+ return false;
+ }
+
totalComponents.AddRange(subComponents);
}
else
@@ -483,7 +453,7 @@ namespace Emby.Server.Implementations.Services
continue;
}
- if (!this.propertyNamesMap.TryGetValue(variableName.ToLowerInvariant(), out var propertyNameOnRequest))
+ if (!this._propertyNamesMap.Contains(variableName))
{
if (string.Equals("ignore", variableName, StringComparison.OrdinalIgnoreCase))
{
@@ -507,6 +477,7 @@ namespace Emby.Server.Implementations.Services
{
sb.Append(PathSeperatorChar + requestComponents[j]);
}
+
value = sb.ToString();
}
else
@@ -517,13 +488,13 @@ namespace Emby.Server.Implementations.Services
var stopLiteral = i == this.TotalComponentsCount - 1 ? null : this.literalsToMatch[i + 1];
if (!string.Equals(requestComponents[pathIx], stopLiteral, StringComparison.OrdinalIgnoreCase))
{
- var sb = new StringBuilder();
- sb.Append(value);
+ var sb = new StringBuilder(value);
pathIx++;
while (!string.Equals(requestComponents[pathIx], stopLiteral, StringComparison.OrdinalIgnoreCase))
{
sb.Append(PathSeperatorChar + requestComponents[pathIx++]);
}
+
value = sb.ToString();
}
else
@@ -538,7 +509,7 @@ namespace Emby.Server.Implementations.Services
pathIx++;
}
- requestKeyValuesMap[propertyNameOnRequest] = value;
+ requestKeyValuesMap[variableName] = value;
}
if (queryStringAndFormData != null)
diff --git a/Emby.Server.Implementations/Services/StringMapTypeDeserializer.cs b/Emby.Server.Implementations/Services/StringMapTypeDeserializer.cs
index d13935fba..f835aa1b5 100644
--- a/Emby.Server.Implementations/Services/StringMapTypeDeserializer.cs
+++ b/Emby.Server.Implementations/Services/StringMapTypeDeserializer.cs
@@ -11,15 +11,16 @@ namespace Emby.Server.Implementations.Services
{
internal class PropertySerializerEntry
{
- public PropertySerializerEntry(Action<object, object> propertySetFn, Func<string, object> propertyParseStringFn)
+ public PropertySerializerEntry(Action<object, object> propertySetFn, Func<string, object> propertyParseStringFn, Type propertyType)
{
PropertySetFn = propertySetFn;
PropertyParseStringFn = propertyParseStringFn;
+ PropertyType = PropertyType;
}
- public Action<object, object> PropertySetFn;
- public Func<string, object> PropertyParseStringFn;
- public Type PropertyType;
+ public Action<object, object> PropertySetFn { get; private set; }
+ public Func<string, object> PropertyParseStringFn { get; private set; }
+ public Type PropertyType { get; private set; }
}
private readonly Type type;
@@ -29,7 +30,9 @@ namespace Emby.Server.Implementations.Services
public Func<string, object> GetParseFn(Type propertyType)
{
if (propertyType == typeof(string))
+ {
return s => s;
+ }
return _GetParseFn(propertyType);
}
@@ -48,7 +51,7 @@ namespace Emby.Server.Implementations.Services
var propertySetFn = TypeAccessor.GetSetPropertyMethod(type, propertyInfo);
var propertyType = propertyInfo.PropertyType;
var propertyParseStringFn = GetParseFn(propertyType);
- var propertySerializer = new PropertySerializerEntry(propertySetFn, propertyParseStringFn) { PropertyType = propertyType };
+ var propertySerializer = new PropertySerializerEntry(propertySetFn, propertyParseStringFn, propertyType);
propertySetterMap[propertyInfo.Name] = propertySerializer;
}
@@ -56,34 +59,21 @@ namespace Emby.Server.Implementations.Services
public object PopulateFromMap(object instance, IDictionary<string, string> keyValuePairs)
{
- string propertyName = null;
- string propertyTextValue = null;
PropertySerializerEntry propertySerializerEntry = null;
if (instance == null)
+ {
instance = _CreateInstanceFn(type);
+ }
foreach (var pair in keyValuePairs)
{
- propertyName = pair.Key;
- propertyTextValue = pair.Value;
-
- if (string.IsNullOrEmpty(propertyTextValue))
- {
- continue;
- }
+ string propertyName = pair.Key;
+ string propertyTextValue = pair.Value;
- if (!propertySetterMap.TryGetValue(propertyName, out propertySerializerEntry))
- {
- if (propertyName == "v")
- {
- continue;
- }
-
- continue;
- }
-
- if (propertySerializerEntry.PropertySetFn == null)
+ if (string.IsNullOrEmpty(propertyTextValue)
+ || !propertySetterMap.TryGetValue(propertyName, out propertySerializerEntry)
+ || propertySerializerEntry.PropertySetFn == null)
{
continue;
}
@@ -99,6 +89,7 @@ namespace Emby.Server.Implementations.Services
{
continue;
}
+
propertySerializerEntry.PropertySetFn(instance, value);
}
@@ -107,7 +98,11 @@ namespace Emby.Server.Implementations.Services
public static string LeftPart(string strVal, char needle)
{
- if (strVal == null) return null;
+ if (strVal == null)
+ {
+ return null;
+ }
+
var pos = strVal.IndexOf(needle);
return pos == -1
? strVal
@@ -119,7 +114,10 @@ namespace Emby.Server.Implementations.Services
{
public static Action<object, object> GetSetPropertyMethod(Type type, PropertyInfo propertyInfo)
{
- if (!propertyInfo.CanWrite || propertyInfo.GetIndexParameters().Length > 0) return null;
+ if (!propertyInfo.CanWrite || propertyInfo.GetIndexParameters().Length > 0)
+ {
+ return null;
+ }
var setMethodInfo = propertyInfo.SetMethod;
return (instance, value) => setMethodInfo.Invoke(instance, new[] { value });
diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs
index fa0ab62d3..985748caf 100644
--- a/Emby.Server.Implementations/Session/SessionManager.cs
+++ b/Emby.Server.Implementations/Session/SessionManager.cs
@@ -116,14 +116,14 @@ namespace Emby.Server.Implementations.Session
_authRepo = authRepo;
_deviceManager = deviceManager;
_mediaSourceManager = mediaSourceManager;
- _deviceManager.DeviceOptionsUpdated += _deviceManager_DeviceOptionsUpdated;
+ _deviceManager.DeviceOptionsUpdated += OnDeviceManagerDeviceOptionsUpdated;
}
- private void _deviceManager_DeviceOptionsUpdated(object sender, GenericEventArgs<Tuple<string, DeviceOptions>> e)
+ private void OnDeviceManagerDeviceOptionsUpdated(object sender, GenericEventArgs<Tuple<string, DeviceOptions>> e)
{
foreach (var session in Sessions)
{
- if (string.Equals(session.DeviceId, e.Argument.Item1))
+ if (string.Equals(session.DeviceId, e.Argument.Item1, StringComparison.Ordinal))
{
if (!string.IsNullOrWhiteSpace(e.Argument.Item2.CustomName))
{
@@ -138,11 +138,29 @@ namespace Emby.Server.Implementations.Session
}
}
- private bool _disposed;
+ private bool _disposed = false;
+
public void Dispose()
{
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ if (disposing)
+ {
+ // TODO: dispose stuff
+ }
+
+ _deviceManager.DeviceOptionsUpdated -= OnDeviceManagerDeviceOptionsUpdated;
+
_disposed = true;
- _deviceManager.DeviceOptionsUpdated -= _deviceManager_DeviceOptionsUpdated;
}
public void CheckDisposed()
@@ -157,7 +175,7 @@ namespace Emby.Server.Implementations.Session
/// Gets all connections.
/// </summary>
/// <value>All connections.</value>
- public IEnumerable<SessionInfo> Sessions => _activeConnections.Values.OrderByDescending(c => c.LastActivityDate).ToList();
+ public IEnumerable<SessionInfo> Sessions => _activeConnections.Values.OrderByDescending(c => c.LastActivityDate);
private void OnSessionStarted(SessionInfo info)
{
@@ -171,20 +189,27 @@ namespace Emby.Server.Implementations.Session
}
}
- EventHelper.QueueEventIfNotNull(SessionStarted, this, new SessionEventArgs
- {
- SessionInfo = info
-
- }, _logger);
+ EventHelper.QueueEventIfNotNull(
+ SessionStarted,
+ this,
+ new SessionEventArgs
+ {
+ SessionInfo = info
+ },
+ _logger);
}
private void OnSessionEnded(SessionInfo info)
{
- EventHelper.QueueEventIfNotNull(SessionEnded, this, new SessionEventArgs
- {
- SessionInfo = info
+ EventHelper.QueueEventIfNotNull(
+ SessionEnded,
+ this,
+ new SessionEventArgs
+ {
+ SessionInfo = info
- }, _logger);
+ },
+ _logger);
info.Dispose();
}
@@ -192,9 +217,6 @@ namespace Emby.Server.Implementations.Session
public void UpdateDeviceName(string sessionId, string deviceName)
{
var session = GetSession(sessionId);
-
- var key = GetSessionKey(session.Client, session.DeviceId);
-
if (session != null)
{
session.DeviceName = deviceName;
@@ -210,10 +232,10 @@ namespace Emby.Server.Implementations.Session
/// <param name="deviceName">Name of the device.</param>
/// <param name="remoteEndPoint">The remote end point.</param>
/// <param name="user">The user.</param>
- /// <returns>Task.</returns>
+ /// <returns>SessionInfo.</returns>
/// <exception cref="ArgumentNullException">user</exception>
- /// <exception cref="UnauthorizedAccessException"></exception>
- public SessionInfo LogSessionActivity(string appName,
+ public SessionInfo LogSessionActivity(
+ string appName,
string appVersion,
string deviceId,
string deviceName,
@@ -226,10 +248,12 @@ namespace Emby.Server.Implementations.Session
{
throw new ArgumentNullException(nameof(appName));
}
+
if (string.IsNullOrEmpty(appVersion))
{
throw new ArgumentNullException(nameof(appVersion));
}
+
if (string.IsNullOrEmpty(deviceId))
{
throw new ArgumentNullException(nameof(deviceId));
@@ -260,10 +284,12 @@ namespace Emby.Server.Implementations.Session
if ((activityDate - lastActivityDate).TotalSeconds > 10)
{
- SessionActivity?.Invoke(this, new SessionEventArgs
- {
- SessionInfo = session
- });
+ SessionActivity?.Invoke(
+ this,
+ new SessionEventArgs
+ {
+ SessionInfo = session
+ });
}
return session;
@@ -304,6 +330,7 @@ namespace Emby.Server.Implementations.Session
/// <summary>
/// Updates the now playing item id.
/// </summary>
+ /// <returns>Task.</returns>
private async Task UpdateNowPlayingItem(SessionInfo session, PlaybackProgressInfo info, BaseItem libraryItem, bool updateLastCheckInTime)
{
if (string.IsNullOrEmpty(info.MediaSourceId))
@@ -418,7 +445,7 @@ namespace Emby.Server.Implementations.Session
});
sessionInfo.UserId = user == null ? Guid.Empty : user.Id;
- sessionInfo.UserName = user == null ? null : user.Name;
+ sessionInfo.UserName = user?.Name;
sessionInfo.UserPrimaryImageTag = user == null ? null : GetImageCacheTag(user, ImageType.Primary);
sessionInfo.RemoteEndPoint = remoteEndPoint;
sessionInfo.Client = appName;
@@ -432,7 +459,7 @@ namespace Emby.Server.Implementations.Session
if (user == null)
{
- sessionInfo.AdditionalUsers = new SessionUserInfo[] { };
+ sessionInfo.AdditionalUsers = Array.Empty<SessionUserInfo>();
}
return sessionInfo;
@@ -449,9 +476,9 @@ namespace Emby.Server.Implementations.Session
ServerId = _appHost.SystemId
};
- var username = user == null ? null : user.Name;
+ var username = user?.Name;
- sessionInfo.UserId = user == null ? Guid.Empty : user.Id;
+ sessionInfo.UserId = user?.Id ?? Guid.Empty;
sessionInfo.UserName = username;
sessionInfo.UserPrimaryImageTag = user == null ? null : GetImageCacheTag(user, ImageType.Primary);
sessionInfo.RemoteEndPoint = remoteEndPoint;
@@ -508,6 +535,7 @@ namespace Emby.Server.Implementations.Session
_idleTimer = new Timer(CheckForIdlePlayback, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));
}
}
+
private void StopIdleCheckTimer()
{
if (_idleTimer != null)
@@ -539,9 +567,9 @@ namespace Emby.Server.Implementations.Session
Item = session.NowPlayingItem,
ItemId = session.NowPlayingItem == null ? Guid.Empty : session.NowPlayingItem.Id,
SessionId = session.Id,
- MediaSourceId = session.PlayState == null ? null : session.PlayState.MediaSourceId,
- PositionTicks = session.PlayState == null ? null : session.PlayState.PositionTicks
- });
+ MediaSourceId = session.PlayState?.MediaSourceId,
+ PositionTicks = session.PlayState?.PositionTicks
+ }).ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -616,18 +644,22 @@ namespace Emby.Server.Implementations.Session
// Nothing to save here
// Fire events to inform plugins
- EventHelper.QueueEventIfNotNull(PlaybackStart, this, new PlaybackProgressEventArgs
- {
- Item = libraryItem,
- Users = users,
- MediaSourceId = info.MediaSourceId,
- MediaInfo = info.Item,
- DeviceName = session.DeviceName,
- ClientName = session.Client,
- DeviceId = session.DeviceId,
- Session = session
-
- }, _logger);
+ EventHelper.QueueEventIfNotNull(
+ PlaybackStart,
+ this,
+ new PlaybackProgressEventArgs
+ {
+ Item = libraryItem,
+ Users = users,
+ MediaSourceId = info.MediaSourceId,
+ MediaInfo = info.Item,
+ DeviceName = session.DeviceName,
+ ClientName = session.Client,
+ DeviceId = session.DeviceId,
+ Session = session
+
+ },
+ _logger);
StartIdleCheckTimer();
}
@@ -667,6 +699,7 @@ namespace Emby.Server.Implementations.Session
/// <summary>
/// Used to report playback progress for an item
/// </summary>
+ /// <returns>Task.</returns>
public async Task OnPlaybackProgress(PlaybackProgressInfo info, bool isAutomated)
{
CheckDisposed();
@@ -695,21 +728,23 @@ namespace Emby.Server.Implementations.Session
}
}
- PlaybackProgress?.Invoke(this, new PlaybackProgressEventArgs
- {
- Item = libraryItem,
- Users = users,
- PlaybackPositionTicks = session.PlayState.PositionTicks,
- MediaSourceId = session.PlayState.MediaSourceId,
- MediaInfo = info.Item,
- DeviceName = session.DeviceName,
- ClientName = session.Client,
- DeviceId = session.DeviceId,
- IsPaused = info.IsPaused,
- PlaySessionId = info.PlaySessionId,
- IsAutomated = isAutomated,
- Session = session
- });
+ PlaybackProgress?.Invoke(
+ this,
+ new PlaybackProgressEventArgs
+ {
+ Item = libraryItem,
+ Users = users,
+ PlaybackPositionTicks = session.PlayState.PositionTicks,
+ MediaSourceId = session.PlayState.MediaSourceId,
+ MediaInfo = info.Item,
+ DeviceName = session.DeviceName,
+ ClientName = session.Client,
+ DeviceId = session.DeviceId,
+ IsPaused = info.IsPaused,
+ PlaySessionId = info.PlaySessionId,
+ IsAutomated = isAutomated,
+ Session = session
+ });
if (!isAutomated)
{
@@ -830,8 +865,7 @@ namespace Emby.Server.Implementations.Session
{
MediaSourceInfo mediaSource = null;
- var hasMediaSources = libraryItem as IHasMediaSources;
- if (hasMediaSources != null)
+ if (libraryItem is IHasMediaSources hasMediaSources)
{
mediaSource = await GetMediaSource(libraryItem, info.MediaSourceId, info.LiveStreamId).ConfigureAwait(false);
}
@@ -848,7 +882,8 @@ namespace Emby.Server.Implementations.Session
{
var msString = info.PositionTicks.HasValue ? (info.PositionTicks.Value / 10000).ToString(CultureInfo.InvariantCulture) : "unknown";
- _logger.LogInformation("Playback stopped reported by app {0} {1} playing {2}. Stopped at {3} ms",
+ _logger.LogInformation(
+ "Playback stopped reported by app {0} {1} playing {2}. Stopped at {3} ms",
session.Client,
session.ApplicationVersion,
info.Item.Name,
@@ -887,20 +922,24 @@ namespace Emby.Server.Implementations.Session
}
}
- EventHelper.QueueEventIfNotNull(PlaybackStopped, this, new PlaybackStopEventArgs
- {
- Item = libraryItem,
- Users = users,
- PlaybackPositionTicks = info.PositionTicks,
- PlayedToCompletion = playedToCompletion,
- MediaSourceId = info.MediaSourceId,
- MediaInfo = info.Item,
- DeviceName = session.DeviceName,
- ClientName = session.Client,
- DeviceId = session.DeviceId,
- Session = session
+ EventHelper.QueueEventIfNotNull(
+ PlaybackStopped,
+ this,
+ new PlaybackStopEventArgs
+ {
+ Item = libraryItem,
+ Users = users,
+ PlaybackPositionTicks = info.PositionTicks,
+ PlayedToCompletion = playedToCompletion,
+ MediaSourceId = info.MediaSourceId,
+ MediaInfo = info.Item,
+ DeviceName = session.DeviceName,
+ ClientName = session.Client,
+ DeviceId = session.DeviceId,
+ Session = session
- }, _logger);
+ },
+ _logger);
}
private bool OnPlaybackStopped(User user, BaseItem item, long? positionTicks, bool playbackFailed)
@@ -936,11 +975,10 @@ namespace Emby.Server.Implementations.Session
/// <param name="sessionId">The session identifier.</param>
/// <param name="throwOnMissing">if set to <c>true</c> [throw on missing].</param>
/// <returns>SessionInfo.</returns>
- /// <exception cref="ResourceNotFoundException"></exception>
+ /// <exception cref="ResourceNotFoundException">sessionId</exception>
private SessionInfo GetSession(string sessionId, bool throwOnMissing = true)
{
- var session = Sessions.FirstOrDefault(i => string.Equals(i.Id, sessionId));
-
+ var session = Sessions.FirstOrDefault(i => string.Equals(i.Id, sessionId, StringComparison.Ordinal));
if (session == null && throwOnMissing)
{
throw new ResourceNotFoundException(string.Format("Session {0} not found.", sessionId));
@@ -952,7 +990,7 @@ namespace Emby.Server.Implementations.Session
private SessionInfo GetSessionToRemoteControl(string sessionId)
{
// Accept either device id or session id
- var session = Sessions.FirstOrDefault(i => string.Equals(i.Id, sessionId));
+ var session = Sessions.FirstOrDefault(i => string.Equals(i.Id, sessionId, StringComparison.Ordinal));
if (session == null)
{
@@ -1061,10 +1099,12 @@ namespace Emby.Server.Implementations.Session
var series = episode.Series;
if (series != null)
{
- var episodes = series.GetEpisodes(user, new DtoOptions(false)
- {
- EnableImages = false
- })
+ var episodes = series.GetEpisodes(
+ user,
+ new DtoOptions(false)
+ {
+ EnableImages = false
+ })
.Where(i => !i.IsVirtualItem)
.SkipWhile(i => i.Id != episode.Id)
.ToList();
@@ -1090,7 +1130,7 @@ namespace Emby.Server.Implementations.Session
await SendMessageToSession(session, "Play", command, cancellationToken).ConfigureAwait(false);
}
- private IList<BaseItem> TranslateItemForPlayback(Guid id, User user)
+ private IEnumerable<BaseItem> TranslateItemForPlayback(Guid id, User user)
{
var item = _libraryManager.GetItemById(id);
@@ -1100,9 +1140,7 @@ namespace Emby.Server.Implementations.Session
return new List<BaseItem>();
}
- var byName = item as IItemByName;
-
- if (byName != null)
+ if (item is IItemByName byName)
{
return byName.GetTaggedItems(new InternalItemsQuery(user)
{
@@ -1152,7 +1190,7 @@ namespace Emby.Server.Implementations.Session
if (item == null)
{
- _logger.LogError("A non-existant item Id {0} was passed into TranslateItemForInstantMix", id);
+ _logger.LogError("A non-existent item Id {0} was passed into TranslateItemForInstantMix", id);
return new List<BaseItem>();
}
@@ -1163,13 +1201,15 @@ namespace Emby.Server.Implementations.Session
{
var generalCommand = new GeneralCommand
{
- Name = GeneralCommandType.DisplayContent.ToString()
+ Name = GeneralCommandType.DisplayContent.ToString(),
+ Arguments =
+ {
+ ["ItemId"] = command.ItemId,
+ ["ItemName"] = command.ItemName,
+ ["ItemType"] = command.ItemType
+ }
};
- generalCommand.Arguments["ItemId"] = command.ItemId;
- generalCommand.Arguments["ItemName"] = command.ItemName;
- generalCommand.Arguments["ItemType"] = command.ItemType;
-
return SendGeneralCommand(controllingSessionId, sessionId, generalCommand, cancellationToken);
}
@@ -1410,7 +1450,8 @@ namespace Emby.Server.Implementations.Session
var token = GetAuthorizationToken(user, request.DeviceId, request.App, request.AppVersion, request.DeviceName);
- var session = LogSessionActivity(request.App,
+ var session = LogSessionActivity(
+ request.App,
request.AppVersion,
request.DeviceId,
request.DeviceName,
@@ -1454,9 +1495,9 @@ namespace Emby.Server.Implementations.Session
{
Logout(auth);
}
- catch
+ catch (Exception ex)
{
-
+ _logger.LogError(ex, "Error while logging out.");
}
}
}
@@ -1572,7 +1613,8 @@ namespace Emby.Server.Implementations.Session
ReportCapabilities(session, capabilities, true);
}
- private void ReportCapabilities(SessionInfo session,
+ private void ReportCapabilities(
+ SessionInfo session,
ClientCapabilities capabilities,
bool saveCapabilities)
{
@@ -1580,10 +1622,12 @@ namespace Emby.Server.Implementations.Session
if (saveCapabilities)
{
- CapabilitiesChanged?.Invoke(this, new SessionEventArgs
- {
- SessionInfo = session
- });
+ CapabilitiesChanged?.Invoke(
+ this,
+ new SessionEventArgs
+ {
+ SessionInfo = session
+ });
try
{
diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
index 24903f5e8..a551433ed 100644
--- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
+++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
@@ -5,6 +5,7 @@ using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Session
@@ -62,7 +63,7 @@ namespace Emby.Server.Implementations.Session
}
}
- private SessionInfo GetSession(QueryParamCollection queryString, string remoteEndpoint)
+ private SessionInfo GetSession(IQueryCollection queryString, string remoteEndpoint)
{
if (queryString == null)
{
diff --git a/Jellyfin.Server/SocketSharp/HttpFile.cs b/Emby.Server.Implementations/SocketSharp/HttpFile.cs
index 89c75e536..120ac50d9 100644
--- a/Jellyfin.Server/SocketSharp/HttpFile.cs
+++ b/Emby.Server.Implementations/SocketSharp/HttpFile.cs
@@ -1,14 +1,18 @@
using System.IO;
using MediaBrowser.Model.Services;
-namespace Jellyfin.Server.SocketSharp
+namespace Emby.Server.Implementations.SocketSharp
{
public class HttpFile : IHttpFile
{
public string Name { get; set; }
+
public string FileName { get; set; }
+
public long ContentLength { get; set; }
+
public string ContentType { get; set; }
+
public Stream InputStream { get; set; }
}
}
diff --git a/Emby.Server.Implementations/SocketSharp/HttpPostedFile.cs b/Emby.Server.Implementations/SocketSharp/HttpPostedFile.cs
new file mode 100644
index 000000000..95b7912fb
--- /dev/null
+++ b/Emby.Server.Implementations/SocketSharp/HttpPostedFile.cs
@@ -0,0 +1,204 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+using MediaBrowser.Model.Services;
+
+public sealed class HttpPostedFile : IDisposable
+{
+ private string _name;
+ private string _contentType;
+ private Stream _stream;
+ private bool _disposed = false;
+
+ internal HttpPostedFile(string name, string content_type, Stream base_stream, long offset, long length)
+ {
+ _name = name;
+ _contentType = content_type;
+ _stream = new ReadSubStream(base_stream, offset, length);
+ }
+
+ public string ContentType => _contentType;
+
+ public int ContentLength => (int)_stream.Length;
+
+ public string FileName => _name;
+
+ public Stream InputStream => _stream;
+
+ /// <summary>
+ /// Releases the unmanaged resources and disposes of the managed resources used.
+ /// </summary>
+ public void Dispose()
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ _stream.Dispose();
+ _stream = null;
+
+ _name = null;
+ _contentType = null;
+
+ _disposed = true;
+ }
+
+ private class ReadSubStream : Stream
+ {
+ private Stream _stream;
+ private long _offset;
+ private long _end;
+ private long _position;
+
+ public ReadSubStream(Stream s, long offset, long length)
+ {
+ _stream = s;
+ _offset = offset;
+ _end = offset + length;
+ _position = offset;
+ }
+
+ public override bool CanRead => true;
+
+ public override bool CanSeek => true;
+
+ public override bool CanWrite => false;
+
+ public override long Length => _end - _offset;
+
+ public override long Position
+ {
+ get => _position - _offset;
+ set
+ {
+ if (value > Length)
+ {
+ throw new ArgumentOutOfRangeException(nameof(value));
+ }
+
+ _position = Seek(value, SeekOrigin.Begin);
+ }
+ }
+
+ public override void Flush()
+ {
+ }
+
+ public override int Read(byte[] buffer, int dest_offset, int count)
+ {
+ if (buffer == null)
+ {
+ throw new ArgumentNullException(nameof(buffer));
+ }
+
+ if (dest_offset < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(dest_offset), "< 0");
+ }
+
+ if (count < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(count), "< 0");
+ }
+
+ int len = buffer.Length;
+ if (dest_offset > len)
+ {
+ throw new ArgumentException("destination offset is beyond array size", nameof(dest_offset));
+ }
+
+ // reordered to avoid possible integer overflow
+ if (dest_offset > len - count)
+ {
+ throw new ArgumentException("Reading would overrun buffer", nameof(count));
+ }
+
+ if (count > _end - _position)
+ {
+ count = (int)(_end - _position);
+ }
+
+ if (count <= 0)
+ {
+ return 0;
+ }
+
+ _stream.Position = _position;
+ int result = _stream.Read(buffer, dest_offset, count);
+ if (result > 0)
+ {
+ _position += result;
+ }
+ else
+ {
+ _position = _end;
+ }
+
+ return result;
+ }
+
+ public override int ReadByte()
+ {
+ if (_position >= _end)
+ {
+ return -1;
+ }
+
+ _stream.Position = _position;
+ int result = _stream.ReadByte();
+ if (result < 0)
+ {
+ _position = _end;
+ }
+ else
+ {
+ _position++;
+ }
+
+ return result;
+ }
+
+ public override long Seek(long d, SeekOrigin origin)
+ {
+ long real;
+ switch (origin)
+ {
+ case SeekOrigin.Begin:
+ real = _offset + d;
+ break;
+ case SeekOrigin.End:
+ real = _end + d;
+ break;
+ case SeekOrigin.Current:
+ real = _position + d;
+ break;
+ default:
+ throw new ArgumentException("Unknown SeekOrigin value", nameof(origin));
+ }
+
+ long virt = real - _offset;
+ if (virt < 0 || virt > Length)
+ {
+ throw new ArgumentException("Invalid position", nameof(d));
+ }
+
+ _position = _stream.Seek(real, SeekOrigin.Begin);
+ return _position;
+ }
+
+ public override void SetLength(long value)
+ {
+ throw new NotSupportedException();
+ }
+
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ throw new NotSupportedException();
+ }
+ }
+}
diff --git a/Jellyfin.Server/SocketSharp/RequestMono.cs b/Emby.Server.Implementations/SocketSharp/RequestMono.cs
index 24cf994ea..373f6d758 100644
--- a/Jellyfin.Server/SocketSharp/RequestMono.cs
+++ b/Emby.Server.Implementations/SocketSharp/RequestMono.cs
@@ -6,14 +6,16 @@ using System.Net;
using System.Text;
using System.Threading.Tasks;
using MediaBrowser.Model.Services;
+using Microsoft.Extensions.Primitives;
+using Microsoft.Net.Http.Headers;
-namespace Jellyfin.Server.SocketSharp
+namespace Emby.Server.Implementations.SocketSharp
{
public partial class WebSocketSharpRequest : IHttpRequest
{
- internal static string GetParameter(string header, string attr)
+ internal static string GetParameter(ReadOnlySpan<char> header, string attr)
{
- int ap = header.IndexOf(attr, StringComparison.Ordinal);
+ int ap = header.IndexOf(attr.AsSpan(), StringComparison.Ordinal);
if (ap == -1)
{
return null;
@@ -31,18 +33,19 @@ namespace Jellyfin.Server.SocketSharp
ending = ' ';
}
- int end = header.IndexOf(ending, ap + 1);
+ var slice = header.Slice(ap + 1);
+ int end = slice.IndexOf(ending);
if (end == -1)
{
- return ending == '"' ? null : header.Substring(ap);
+ return ending == '"' ? null : header.Slice(ap).ToString();
}
- return header.Substring(ap + 1, end - ap - 1);
+ return slice.Slice(0, end - ap - 1).ToString();
}
private async Task LoadMultiPart(WebROCollection form)
{
- string boundary = GetParameter(ContentType, "; boundary=");
+ string boundary = GetParameter(ContentType.AsSpan(), "; boundary=");
if (boundary == null)
{
return;
@@ -76,7 +79,7 @@ namespace Jellyfin.Server.SocketSharp
byte[] copy = new byte[e.Length];
input.Position = e.Start;
- input.Read(copy, 0, (int)e.Length);
+ await input.ReadAsync(copy, 0, (int)e.Length).ConfigureAwait(false);
form.Add(e.Name, (e.Encoding ?? ContentEncoding).GetString(copy, 0, copy.Length));
}
@@ -95,23 +98,15 @@ namespace Jellyfin.Server.SocketSharp
var form = new WebROCollection();
files = new Dictionary<string, HttpPostedFile>();
- if (IsContentType("multipart/form-data", true))
+ if (IsContentType("multipart/form-data"))
{
await LoadMultiPart(form).ConfigureAwait(false);
}
- else if (IsContentType("application/x-www-form-urlencoded", true))
+ else if (IsContentType("application/x-www-form-urlencoded"))
{
await LoadWwwForm(form).ConfigureAwait(false);
}
-#if NET_4_0
- if (validateRequestNewMode && !checked_form) {
- // Setting this before calling the validator prevents
- // possible endless recursion
- checked_form = true;
- ValidateNameValueCollection("Form", query_string_nvc, RequestValidationSource.Form);
- } else
-#endif
if (validate_form && !checked_form)
{
checked_form = true;
@@ -121,15 +116,11 @@ namespace Jellyfin.Server.SocketSharp
return form;
}
- public string Accept => string.IsNullOrEmpty(request.Headers["Accept"]) ? null : request.Headers["Accept"];
+ public string Accept => StringValues.IsNullOrEmpty(request.Headers[HeaderNames.Accept]) ? null : request.Headers[HeaderNames.Accept].ToString();
- public string Authorization => string.IsNullOrEmpty(request.Headers["Authorization"]) ? null : request.Headers["Authorization"];
+ public string Authorization => StringValues.IsNullOrEmpty(request.Headers[HeaderNames.Authorization]) ? null : request.Headers[HeaderNames.Authorization].ToString();
- protected bool validate_cookies { get; set; }
- protected bool validate_query_string { get; set; }
protected bool validate_form { get; set; }
- protected bool checked_cookies { get; set; }
- protected bool checked_query_string { get; set; }
protected bool checked_form { get; set; }
private static void ThrowValidationException(string name, string key, string value)
@@ -209,26 +200,14 @@ namespace Jellyfin.Server.SocketSharp
return false;
}
- public void ValidateInput()
- {
- validate_cookies = true;
- validate_query_string = true;
- validate_form = true;
- }
-
- private bool IsContentType(string ct, bool starts_with)
+ private bool IsContentType(string ct)
{
- if (ct == null || ContentType == null)
+ if (ContentType == null)
{
return false;
}
- if (starts_with)
- {
- return StrUtils.StartsWith(ContentType, ct, true);
- }
-
- return string.Equals(ContentType, ct, StringComparison.OrdinalIgnoreCase);
+ return ContentType.StartsWith(ct, StringComparison.OrdinalIgnoreCase);
}
private async Task LoadWwwForm(WebROCollection form)
@@ -324,215 +303,6 @@ namespace Jellyfin.Server.SocketSharp
return result.ToString();
}
}
-
- public sealed class HttpPostedFile
- {
- private string name;
- private string content_type;
- private Stream stream;
-
- private class ReadSubStream : Stream
- {
- private Stream s;
- private long offset;
- private long end;
- private long position;
-
- public ReadSubStream(Stream s, long offset, long length)
- {
- this.s = s;
- this.offset = offset;
- this.end = offset + length;
- position = offset;
- }
-
- public override void Flush()
- {
- }
-
- public override int Read(byte[] buffer, int dest_offset, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer));
- }
-
- if (dest_offset < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(dest_offset), "< 0");
- }
-
- if (count < 0)
- {
- throw new ArgumentOutOfRangeException(nameof(count), "< 0");
- }
-
- int len = buffer.Length;
- if (dest_offset > len)
- {
- throw new ArgumentException("destination offset is beyond array size", nameof(dest_offset));
- }
-
- // reordered to avoid possible integer overflow
- if (dest_offset > len - count)
- {
- throw new ArgumentException("Reading would overrun buffer", nameof(count));
- }
-
- if (count > end - position)
- {
- count = (int)(end - position);
- }
-
- if (count <= 0)
- {
- return 0;
- }
-
- s.Position = position;
- int result = s.Read(buffer, dest_offset, count);
- if (result > 0)
- {
- position += result;
- }
- else
- {
- position = end;
- }
-
- return result;
- }
-
- public override int ReadByte()
- {
- if (position >= end)
- {
- return -1;
- }
-
- s.Position = position;
- int result = s.ReadByte();
- if (result < 0)
- {
- position = end;
- }
- else
- {
- position++;
- }
-
- return result;
- }
-
- public override long Seek(long d, SeekOrigin origin)
- {
- long real;
- switch (origin)
- {
- case SeekOrigin.Begin:
- real = offset + d;
- break;
- case SeekOrigin.End:
- real = end + d;
- break;
- case SeekOrigin.Current:
- real = position + d;
- break;
- default:
- throw new ArgumentException("Unknown SeekOrigin value", nameof(origin));
- }
-
- long virt = real - offset;
- if (virt < 0 || virt > Length)
- {
- throw new ArgumentException("Invalid position", nameof(d));
- }
-
- position = s.Seek(real, SeekOrigin.Begin);
- return position;
- }
-
- public override void SetLength(long value)
- {
- throw new NotSupportedException();
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- throw new NotSupportedException();
- }
-
- public override bool CanRead => true;
-
- public override bool CanSeek => true;
-
- public override bool CanWrite => false;
-
- public override long Length => end - offset;
-
- public override long Position
- {
- get => position - offset;
- set
- {
- if (value > Length)
- {
- throw new ArgumentOutOfRangeException(nameof(value));
- }
-
- position = Seek(value, SeekOrigin.Begin);
- }
- }
- }
-
- internal HttpPostedFile(string name, string content_type, Stream base_stream, long offset, long length)
- {
- this.name = name;
- this.content_type = content_type;
- this.stream = new ReadSubStream(base_stream, offset, length);
- }
-
- public string ContentType => content_type;
-
- public int ContentLength => (int)stream.Length;
-
- public string FileName => name;
-
- public Stream InputStream => stream;
- }
-
- internal static class StrUtils
- {
- public static bool StartsWith(string str1, string str2, bool ignore_case)
- {
- if (string.IsNullOrEmpty(str1))
- {
- return false;
- }
-
- var comparison = ignore_case ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
- return str1.IndexOf(str2, comparison) == 0;
- }
-
- public static bool EndsWith(string str1, string str2, bool ignore_case)
- {
- int l2 = str2.Length;
- if (l2 == 0)
- {
- return true;
- }
-
- int l1 = str1.Length;
- if (l2 > l1)
- {
- return false;
- }
-
- var comparison = ignore_case ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
- return str1.IndexOf(str2, comparison) == str1.Length - str2.Length - 1;
- }
- }
-
private class HttpMultipart
{
@@ -603,17 +373,17 @@ namespace Jellyfin.Server.SocketSharp
}
var elem = new Element();
- string header;
- while ((header = ReadHeaders()) != null)
+ ReadOnlySpan<char> header;
+ while ((header = ReadHeaders().AsSpan()) != null)
{
- if (StrUtils.StartsWith(header, "Content-Disposition:", true))
+ if (header.StartsWith("Content-Disposition:".AsSpan(), StringComparison.OrdinalIgnoreCase))
{
elem.Name = GetContentDispositionAttribute(header, "name");
elem.Filename = StripPath(GetContentDispositionAttributeWithEncoding(header, "filename"));
}
- else if (StrUtils.StartsWith(header, "Content-Type:", true))
+ else if (header.StartsWith("Content-Type:".AsSpan(), StringComparison.OrdinalIgnoreCase))
{
- elem.ContentType = header.Substring("Content-Type:".Length).Trim();
+ elem.ContentType = header.Slice("Content-Type:".Length).Trim().ToString();
elem.Encoding = GetEncoding(elem.ContentType);
}
}
@@ -661,16 +431,16 @@ namespace Jellyfin.Server.SocketSharp
return sb.ToString();
}
- private static string GetContentDispositionAttribute(string l, string name)
+ private static string GetContentDispositionAttribute(ReadOnlySpan<char> l, string name)
{
- int idx = l.IndexOf(name + "=\"", StringComparison.Ordinal);
+ int idx = l.IndexOf((name + "=\"").AsSpan(), StringComparison.Ordinal);
if (idx < 0)
{
return null;
}
int begin = idx + name.Length + "=\"".Length;
- int end = l.IndexOf('"', begin);
+ int end = l.Slice(begin).IndexOf('"');
if (end < 0)
{
return null;
@@ -681,19 +451,19 @@ namespace Jellyfin.Server.SocketSharp
return string.Empty;
}
- return l.Substring(begin, end - begin);
+ return l.Slice(begin, end - begin).ToString();
}
- private string GetContentDispositionAttributeWithEncoding(string l, string name)
+ private string GetContentDispositionAttributeWithEncoding(ReadOnlySpan<char> l, string name)
{
- int idx = l.IndexOf(name + "=\"", StringComparison.Ordinal);
+ int idx = l.IndexOf((name + "=\"").AsSpan(), StringComparison.Ordinal);
if (idx < 0)
{
return null;
}
int begin = idx + name.Length + "=\"".Length;
- int end = l.IndexOf('"', begin);
+ int end = l.Slice(begin).IndexOf('"');
if (end < 0)
{
return null;
@@ -704,7 +474,7 @@ namespace Jellyfin.Server.SocketSharp
return string.Empty;
}
- string temp = l.Substring(begin, end - begin);
+ ReadOnlySpan<char> temp = l.Slice(begin, end - begin);
byte[] source = new byte[temp.Length];
for (int i = temp.Length - 1; i >= 0; i--)
{
@@ -730,13 +500,14 @@ namespace Jellyfin.Server.SocketSharp
return false;
}
- if (!StrUtils.EndsWith(line, boundary, false))
+ if (!line.EndsWith(boundary, StringComparison.Ordinal))
{
return true;
}
}
catch
{
+
}
return false;
diff --git a/Jellyfin.Server/SocketSharp/SharpWebSocket.cs b/Emby.Server.Implementations/SocketSharp/SharpWebSocket.cs
index 6eee4cd12..62b16ed8c 100644
--- a/Jellyfin.Server/SocketSharp/SharpWebSocket.cs
+++ b/Emby.Server.Implementations/SocketSharp/SharpWebSocket.cs
@@ -1,11 +1,12 @@
using System;
using System.Net.WebSockets;
+using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Emby.Server.Implementations.Net;
using Microsoft.Extensions.Logging;
-namespace Jellyfin.Server.SocketSharp
+namespace Emby.Server.Implementations.SocketSharp
{
public class SharpWebSocket : IWebSocket
{
@@ -20,66 +21,22 @@ namespace Jellyfin.Server.SocketSharp
/// Gets or sets the web socket.
/// </summary>
/// <value>The web socket.</value>
- private SocketHttpListener.WebSocket WebSocket { get; set; }
+ private readonly WebSocket _webSocket;
- private TaskCompletionSource<bool> _taskCompletionSource = new TaskCompletionSource<bool>();
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
- private bool _disposed = false;
+ private bool _disposed;
- public SharpWebSocket(SocketHttpListener.WebSocket socket, ILogger logger)
+ public SharpWebSocket(WebSocket socket, ILogger logger)
{
- if (socket == null)
- {
- throw new ArgumentNullException(nameof(socket));
- }
-
- if (logger == null)
- {
- throw new ArgumentNullException(nameof(logger));
- }
-
- _logger = logger;
- WebSocket = socket;
-
- socket.OnMessage += OnSocketMessage;
- socket.OnClose += OnSocketClose;
- socket.OnError += OnSocketError;
-
- WebSocket.ConnectAsServer();
- }
-
- public Task StartReceive()
- {
- return _taskCompletionSource.Task;
- }
-
- private void OnSocketError(object sender, SocketHttpListener.ErrorEventArgs e)
- {
- _logger.LogError("Error in SharpWebSocket: {Message}", e.Message ?? string.Empty);
-
- // Closed?.Invoke(this, EventArgs.Empty);
- }
-
- private void OnSocketClose(object sender, SocketHttpListener.CloseEventArgs e)
- {
- _taskCompletionSource.TrySetResult(true);
-
- Closed?.Invoke(this, EventArgs.Empty);
- }
-
- private void OnSocketMessage(object sender, SocketHttpListener.MessageEventArgs e)
- {
- if (OnReceiveBytes != null)
- {
- OnReceiveBytes(e.RawData);
- }
+ _logger = logger ?? throw new ArgumentNullException(nameof(logger));
+ _webSocket = socket ?? throw new ArgumentNullException(nameof(socket));
}
/// <summary>
/// Gets or sets the state.
/// </summary>
/// <value>The state.</value>
- public WebSocketState State => WebSocket.ReadyState;
+ public WebSocketState State => _webSocket.State;
/// <summary>
/// Sends the async.
@@ -90,7 +47,7 @@ namespace Jellyfin.Server.SocketSharp
/// <returns>Task.</returns>
public Task SendAsync(byte[] bytes, bool endOfMessage, CancellationToken cancellationToken)
{
- return WebSocket.SendAsync(bytes);
+ return _webSocket.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Binary, endOfMessage, cancellationToken);
}
/// <summary>
@@ -102,7 +59,7 @@ namespace Jellyfin.Server.SocketSharp
/// <returns>Task.</returns>
public Task SendAsync(string text, bool endOfMessage, CancellationToken cancellationToken)
{
- return WebSocket.SendAsync(text);
+ return _webSocket.SendAsync(new ArraySegment<byte>(Encoding.UTF8.GetBytes(text)), WebSocketMessageType.Text, endOfMessage, cancellationToken);
}
/// <summary>
@@ -127,13 +84,13 @@ namespace Jellyfin.Server.SocketSharp
if (dispose)
{
- WebSocket.OnMessage -= OnSocketMessage;
- WebSocket.OnClose -= OnSocketClose;
- WebSocket.OnError -= OnSocketError;
-
_cancellationTokenSource.Cancel();
-
- WebSocket.Close();
+ if (_webSocket.State == WebSocketState.Open)
+ {
+ _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closed by client",
+ CancellationToken.None);
+ }
+ Closed?.Invoke(this, EventArgs.Empty);
}
_disposed = true;
diff --git a/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs b/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs
new file mode 100644
index 000000000..dd313b336
--- /dev/null
+++ b/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs
@@ -0,0 +1,136 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.WebSockets;
+using System.Threading;
+using System.Threading.Tasks;
+using Emby.Server.Implementations.HttpServer;
+using Emby.Server.Implementations.Net;
+using MediaBrowser.Controller.Net;
+using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
+using Microsoft.Extensions.Logging;
+using Microsoft.Net.Http.Headers;
+
+namespace Emby.Server.Implementations.SocketSharp
+{
+ public class WebSocketSharpListener : IHttpListener
+ {
+ private readonly ILogger _logger;
+
+ private CancellationTokenSource _disposeCancellationTokenSource = new CancellationTokenSource();
+ private CancellationToken _disposeCancellationToken;
+
+ public WebSocketSharpListener(
+ ILogger logger)
+ {
+ _logger = logger;
+
+ _disposeCancellationToken = _disposeCancellationTokenSource.Token;
+ }
+
+ public Func<Exception, IRequest, bool, bool, Task> ErrorHandler { get; set; }
+ public Func<IHttpRequest, string, string, string, CancellationToken, Task> RequestHandler { get; set; }
+
+ public Action<WebSocketConnectEventArgs> WebSocketConnected { get; set; }
+
+ private static void LogRequest(ILogger logger, HttpRequest request)
+ {
+ var url = request.GetDisplayUrl();
+
+ logger.LogInformation("WS {Url}. UserAgent: {UserAgent}", url, request.Headers[HeaderNames.UserAgent].ToString());
+ }
+
+ public async Task ProcessWebSocketRequest(HttpContext ctx)
+ {
+ try
+ {
+ LogRequest(_logger, ctx.Request);
+ var endpoint = ctx.Connection.RemoteIpAddress.ToString();
+ var url = ctx.Request.GetDisplayUrl();
+
+ var webSocketContext = await ctx.WebSockets.AcceptWebSocketAsync(null).ConfigureAwait(false);
+ var socket = new SharpWebSocket(webSocketContext, _logger);
+
+ WebSocketConnected(new WebSocketConnectEventArgs
+ {
+ Url = url,
+ QueryString = ctx.Request.Query,
+ WebSocket = socket,
+ Endpoint = endpoint
+ });
+
+ WebSocketReceiveResult result;
+ var message = new List<byte>();
+
+ do
+ {
+ var buffer = WebSocket.CreateServerBuffer(4096);
+ result = await webSocketContext.ReceiveAsync(buffer, _disposeCancellationToken);
+ message.AddRange(buffer.Array.Take(result.Count));
+
+ if (result.EndOfMessage)
+ {
+ socket.OnReceiveBytes(message.ToArray());
+ message.Clear();
+ }
+ } while (socket.State == WebSocketState.Open && result.MessageType != WebSocketMessageType.Close);
+
+
+ if (webSocketContext.State == WebSocketState.Open)
+ {
+ await webSocketContext.CloseAsync(result.CloseStatus ?? WebSocketCloseStatus.NormalClosure,
+ result.CloseStatusDescription, _disposeCancellationToken);
+ }
+
+ socket.Dispose();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "AcceptWebSocketAsync error");
+ if (!ctx.Response.HasStarted)
+ {
+ ctx.Response.StatusCode = 500;
+ }
+ }
+ }
+
+ public Task Stop()
+ {
+ _disposeCancellationTokenSource.Cancel();
+ return Task.CompletedTask;
+ }
+
+ /// <summary>
+ /// Releases the unmanaged resources and disposes of the managed resources used.
+ /// </summary>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ private bool _disposed;
+
+ /// <summary>
+ /// Releases the unmanaged resources and disposes of the managed resources used.
+ /// </summary>
+ /// <param name="disposing">Whether or not the managed resources should be disposed</param>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ {
+ return;
+ }
+
+ if (disposing)
+ {
+ Stop().GetAwaiter().GetResult();
+ }
+
+ _disposed = true;
+ }
+ }
+}
diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs b/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs
index cbce7d457..e0a0ee286 100644
--- a/Jellyfin.Server/SocketSharp/WebSocketSharpRequest.cs
+++ b/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs
@@ -2,97 +2,87 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
+using System.Net;
using System.Text;
-using Emby.Server.Implementations.HttpServer;
using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Logging;
-using SocketHttpListener.Net;
+using Microsoft.Extensions.Primitives;
+using Microsoft.Net.Http.Headers;
using IHttpFile = MediaBrowser.Model.Services.IHttpFile;
using IHttpRequest = MediaBrowser.Model.Services.IHttpRequest;
-using IHttpResponse = MediaBrowser.Model.Services.IHttpResponse;
using IResponse = MediaBrowser.Model.Services.IResponse;
-namespace Jellyfin.Server.SocketSharp
+namespace Emby.Server.Implementations.SocketSharp
{
public partial class WebSocketSharpRequest : IHttpRequest
{
- private readonly HttpListenerRequest request;
- private readonly IHttpResponse response;
+ private readonly HttpRequest request;
- public WebSocketSharpRequest(HttpListenerContext httpContext, string operationName, ILogger logger)
+ public WebSocketSharpRequest(HttpRequest httpContext, HttpResponse response, string operationName, ILogger logger)
{
this.OperationName = operationName;
- this.request = httpContext.Request;
- this.response = new WebSocketSharpResponse(logger, httpContext.Response, this);
+ this.request = httpContext;
+ this.Response = new WebSocketSharpResponse(logger, response);
// HandlerFactoryPath = GetHandlerPathIfAny(UrlPrefixes[0]);
}
- private static string GetHandlerPathIfAny(string listenerUrl)
- {
- if (listenerUrl == null)
- {
- return null;
- }
+ public HttpRequest HttpRequest => request;
- var pos = listenerUrl.IndexOf("://", StringComparison.OrdinalIgnoreCase);
- if (pos == -1)
- {
- return null;
- }
-
- var startHostUrl = listenerUrl.Substring(pos + "://".Length);
- var endPos = startHostUrl.IndexOf('/', StringComparison.Ordinal);
- if (endPos == -1)
- {
- return null;
- }
-
- var endHostUrl = startHostUrl.Substring(endPos + 1);
- return string.IsNullOrEmpty(endHostUrl) ? null : endHostUrl.TrimEnd('/');
- }
-
- public HttpListenerRequest HttpRequest => request;
-
- public object OriginalRequest => request;
-
- public IResponse Response => response;
-
- public IHttpResponse HttpResponse => response;
+ public IResponse Response { get; }
public string OperationName { get; set; }
public object Dto { get; set; }
- public string RawUrl => request.RawUrl;
+ public string RawUrl => request.GetEncodedPathAndQuery();
- public string AbsoluteUri => request.Url.AbsoluteUri.TrimEnd('/');
-
- public string UserHostAddress => request.UserHostAddress;
+ public string AbsoluteUri => request.GetDisplayUrl().TrimEnd('/');
public string XForwardedFor
- => string.IsNullOrEmpty(request.Headers["X-Forwarded-For"]) ? null : request.Headers["X-Forwarded-For"];
+ => StringValues.IsNullOrEmpty(request.Headers["X-Forwarded-For"]) ? null : request.Headers["X-Forwarded-For"].ToString();
public int? XForwardedPort
- => string.IsNullOrEmpty(request.Headers["X-Forwarded-Port"]) ? (int?)null : int.Parse(request.Headers["X-Forwarded-Port"], CultureInfo.InvariantCulture);
+ => StringValues.IsNullOrEmpty(request.Headers["X-Forwarded-Port"]) ? (int?)null : int.Parse(request.Headers["X-Forwarded-Port"], CultureInfo.InvariantCulture);
- public string XForwardedProtocol => string.IsNullOrEmpty(request.Headers["X-Forwarded-Proto"]) ? null : request.Headers["X-Forwarded-Proto"];
+ public string XForwardedProtocol => StringValues.IsNullOrEmpty(request.Headers["X-Forwarded-Proto"]) ? null : request.Headers["X-Forwarded-Proto"].ToString();
- public string XRealIp => string.IsNullOrEmpty(request.Headers["X-Real-IP"]) ? null : request.Headers["X-Real-IP"];
+ public string XRealIp => StringValues.IsNullOrEmpty(request.Headers["X-Real-IP"]) ? null : request.Headers["X-Real-IP"].ToString();
private string remoteIp;
- public string RemoteIp =>
- remoteIp ??
- (remoteIp = CheckBadChars(XForwardedFor) ??
- NormalizeIp(CheckBadChars(XRealIp) ??
- (request.RemoteEndPoint != null ? NormalizeIp(request.RemoteEndPoint.Address.ToString()) : null)));
+ public string RemoteIp
+ {
+ get
+ {
+ if (remoteIp != null)
+ {
+ return remoteIp;
+ }
+
+ var temp = CheckBadChars(XForwardedFor.AsSpan());
+ if (temp.Length != 0)
+ {
+ return remoteIp = temp.ToString();
+ }
+
+ temp = CheckBadChars(XRealIp.AsSpan());
+ if (temp.Length != 0)
+ {
+ return remoteIp = NormalizeIp(temp).ToString();
+ }
+
+ return remoteIp = NormalizeIp(request.HttpContext.Connection.RemoteIpAddress.ToString().AsSpan()).ToString();
+ }
+ }
private static readonly char[] HttpTrimCharacters = new char[] { (char)0x09, (char)0xA, (char)0xB, (char)0xC, (char)0xD, (char)0x20 };
// CheckBadChars - throws on invalid chars to be not found in header name/value
- internal static string CheckBadChars(string name)
+ internal static ReadOnlySpan<char> CheckBadChars(ReadOnlySpan<char> name)
{
- if (name == null || name.Length == 0)
+ if (name.Length == 0)
{
return name;
}
@@ -102,7 +92,7 @@ namespace Jellyfin.Server.SocketSharp
name = name.Trim(HttpTrimCharacters);
// First, check for correctly formed multi-line value
- // Second, check for absenece of CTL characters
+ // Second, check for absence of CTL characters
int crlf = 0;
for (int i = 0; i < name.Length; ++i)
{
@@ -123,7 +113,7 @@ namespace Jellyfin.Server.SocketSharp
}
else if (c == 127 || (c < ' ' && c != '\t'))
{
- throw new ArgumentException("net_WebHeaderInvalidControlChars");
+ throw new ArgumentException("net_WebHeaderInvalidControlChars", nameof(name));
}
break;
@@ -137,7 +127,7 @@ namespace Jellyfin.Server.SocketSharp
break;
}
- throw new ArgumentException("net_WebHeaderInvalidCRLFChars");
+ throw new ArgumentException("net_WebHeaderInvalidCRLFChars", nameof(name));
}
case 2:
@@ -148,51 +138,36 @@ namespace Jellyfin.Server.SocketSharp
break;
}
- throw new ArgumentException("net_WebHeaderInvalidCRLFChars");
+ throw new ArgumentException("net_WebHeaderInvalidCRLFChars", nameof(name));
}
}
}
if (crlf != 0)
{
- throw new ArgumentException("net_WebHeaderInvalidCRLFChars");
+ throw new ArgumentException("net_WebHeaderInvalidCRLFChars", nameof(name));
}
return name;
}
- internal static bool ContainsNonAsciiChars(string token)
+ private ReadOnlySpan<char> NormalizeIp(ReadOnlySpan<char> ip)
{
- for (int i = 0; i < token.Length; ++i)
- {
- if ((token[i] < 0x20) || (token[i] > 0x7e))
- {
- return true;
- }
- }
-
- return false;
- }
-
- private string NormalizeIp(string ip)
- {
- if (!string.IsNullOrWhiteSpace(ip))
+ if (ip.Length != 0 && !ip.IsWhiteSpace())
{
// Handle ipv4 mapped to ipv6
const string srch = "::ffff:";
- var index = ip.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
+ var index = ip.IndexOf(srch.AsSpan(), StringComparison.OrdinalIgnoreCase);
if (index == 0)
{
- ip = ip.Substring(srch.Length);
+ ip = ip.Slice(srch.Length);
}
}
return ip;
}
- public bool IsSecureConnection => request.IsSecureConnection || XForwardedProtocol == "https";
-
- public string[] AcceptTypes => request.AcceptTypes;
+ public string[] AcceptTypes => request.Headers.GetCommaSeparatedValues(HeaderNames.Accept);
private Dictionary<string, object> items;
public Dictionary<string, object> Items => items ?? (items = new Dictionary<string, object>());
@@ -202,13 +177,13 @@ namespace Jellyfin.Server.SocketSharp
{
get =>
responseContentType
- ?? (responseContentType = GetResponseContentType(this));
+ ?? (responseContentType = GetResponseContentType(HttpRequest));
set => this.responseContentType = value;
}
public const string FormUrlEncoded = "application/x-www-form-urlencoded";
public const string MultiPartFormData = "multipart/form-data";
- public static string GetResponseContentType(IRequest httpReq)
+ public static string GetResponseContentType(HttpRequest httpReq)
{
var specifiedContentType = GetQueryStringContentType(httpReq);
if (!string.IsNullOrEmpty(specifiedContentType))
@@ -218,7 +193,7 @@ namespace Jellyfin.Server.SocketSharp
const string serverDefaultContentType = "application/json";
- var acceptContentTypes = httpReq.AcceptTypes;
+ var acceptContentTypes = httpReq.Headers.GetCommaSeparatedValues(HeaderNames.Accept);
string defaultContentType = null;
if (HasAnyOfContentTypes(httpReq, FormUrlEncoded, MultiPartFormData))
{
@@ -231,8 +206,15 @@ namespace Jellyfin.Server.SocketSharp
{
foreach (var acceptsType in acceptContentTypes)
{
- var contentType = HttpResultFactory.GetRealContentType(acceptsType);
- acceptsAnything = acceptsAnything || contentType == "*/*";
+ // TODO: @bond move to Span when Span.Split lands
+ // https://github.com/dotnet/corefx/issues/26528
+ var contentType = acceptsType?.Split(';')[0].Trim();
+ acceptsAnything = contentType.Equals("*/*", StringComparison.OrdinalIgnoreCase);
+
+ if (acceptsAnything)
+ {
+ break;
+ }
}
if (acceptsAnything)
@@ -241,7 +223,7 @@ namespace Jellyfin.Server.SocketSharp
{
return defaultContentType;
}
- else if (serverDefaultContentType != null)
+ else
{
return serverDefaultContentType;
}
@@ -259,7 +241,7 @@ namespace Jellyfin.Server.SocketSharp
public const string Soap11 = "text/xml; charset=utf-8";
- public static bool HasAnyOfContentTypes(IRequest request, params string[] contentTypes)
+ public static bool HasAnyOfContentTypes(HttpRequest request, params string[] contentTypes)
{
if (contentTypes == null || request.ContentType == null)
{
@@ -277,18 +259,18 @@ namespace Jellyfin.Server.SocketSharp
return false;
}
- public static bool IsContentType(IRequest request, string contentType)
+ public static bool IsContentType(HttpRequest request, string contentType)
{
return request.ContentType.StartsWith(contentType, StringComparison.OrdinalIgnoreCase);
}
- private static string GetQueryStringContentType(IRequest httpReq)
+ private static string GetQueryStringContentType(HttpRequest httpReq)
{
- var format = httpReq.QueryString["format"];
+ ReadOnlySpan<char> format = httpReq.Query["format"].ToString().AsSpan();
if (format == null)
{
const int formatMaxLength = 4;
- var pi = httpReq.PathInfo;
+ ReadOnlySpan<char> pi = httpReq.Path.ToString().AsSpan();
if (pi == null || pi.Length <= formatMaxLength)
{
return null;
@@ -296,7 +278,7 @@ namespace Jellyfin.Server.SocketSharp
if (pi[0] == '/')
{
- pi = pi.Substring(1);
+ pi = pi.Slice(1);
}
format = LeftPart(pi, '/');
@@ -307,11 +289,11 @@ namespace Jellyfin.Server.SocketSharp
}
format = LeftPart(format, '.');
- if (format.Contains("json", StringComparison.OrdinalIgnoreCase))
+ if (format.Contains("json".AsSpan(), StringComparison.OrdinalIgnoreCase))
{
return "application/json";
}
- else if (format.Contains("xml", StringComparison.OrdinalIgnoreCase))
+ else if (format.Contains("xml".AsSpan(), StringComparison.OrdinalIgnoreCase))
{
return "application/xml";
}
@@ -319,15 +301,15 @@ namespace Jellyfin.Server.SocketSharp
return null;
}
- public static string LeftPart(string strVal, char needle)
+ public static ReadOnlySpan<char> LeftPart(ReadOnlySpan<char> strVal, char needle)
{
if (strVal == null)
{
return null;
}
- var pos = strVal.IndexOf(needle, StringComparison.Ordinal);
- return pos == -1 ? strVal : strVal.Substring(0, pos);
+ var pos = strVal.IndexOf(needle);
+ return pos == -1 ? strVal : strVal.Slice(0, pos);
}
public static string HandlerFactoryPath;
@@ -341,10 +323,10 @@ namespace Jellyfin.Server.SocketSharp
{
var mode = HandlerFactoryPath;
- var pos = request.RawUrl.IndexOf("?", StringComparison.Ordinal);
+ var pos = RawUrl.IndexOf("?", StringComparison.Ordinal);
if (pos != -1)
{
- var path = request.RawUrl.Substring(0, pos);
+ var path = RawUrl.Substring(0, pos);
this.pathInfo = GetPathInfo(
path,
mode,
@@ -352,11 +334,11 @@ namespace Jellyfin.Server.SocketSharp
}
else
{
- this.pathInfo = request.RawUrl;
+ this.pathInfo = RawUrl;
}
- this.pathInfo = System.Net.WebUtility.UrlDecode(pathInfo);
- this.pathInfo = NormalizePathInfo(pathInfo, mode);
+ this.pathInfo = WebUtility.UrlDecode(pathInfo);
+ this.pathInfo = NormalizePathInfo(pathInfo, mode).ToString();
}
return this.pathInfo;
@@ -419,59 +401,55 @@ namespace Jellyfin.Server.SocketSharp
return null;
}
- var path = sbPathInfo.ToString();
- return path.Length > 1 ? path.TrimEnd('/') : "/";
- }
-
- private Dictionary<string, System.Net.Cookie> cookies;
- public IDictionary<string, System.Net.Cookie> Cookies
- {
- get
- {
- if (cookies == null)
- {
- cookies = new Dictionary<string, System.Net.Cookie>();
- foreach (var cookie in this.request.Cookies)
- {
- var httpCookie = (System.Net.Cookie)cookie;
- cookies[httpCookie.Name] = new System.Net.Cookie(httpCookie.Name, httpCookie.Value, httpCookie.Path, httpCookie.Domain);
- }
- }
-
- return cookies;
- }
+ return sbPathInfo.Length > 1 ? sbPathInfo.ToString().TrimEnd('/') : "/";
}
- public string UserAgent => request.UserAgent;
+ public string UserAgent => request.Headers[HeaderNames.UserAgent];
- public QueryParamCollection Headers => request.Headers;
+ public IHeaderDictionary Headers => request.Headers;
- private QueryParamCollection queryString;
- public QueryParamCollection QueryString => queryString ?? (queryString = MyHttpUtility.ParseQueryString(request.Url.Query));
+ public IQueryCollection QueryString => request.Query;
- public bool IsLocal => request.IsLocal;
+ public bool IsLocal => string.Equals(request.HttpContext.Connection.LocalIpAddress.ToString(), request.HttpContext.Connection.RemoteIpAddress.ToString());
private string httpMethod;
public string HttpMethod =>
httpMethod
- ?? (httpMethod = request.HttpMethod);
+ ?? (httpMethod = request.Method);
public string Verb => HttpMethod;
public string ContentType => request.ContentType;
- private Encoding contentEncoding;
- public Encoding ContentEncoding
+ private Encoding ContentEncoding
{
- get => contentEncoding ?? request.ContentEncoding;
- set => contentEncoding = value;
+ get
+ {
+ // TODO is this necessary?
+ if (UserAgent != null && CultureInfo.InvariantCulture.CompareInfo.IsPrefix(UserAgent, "UP"))
+ {
+ string postDataCharset = Headers["x-up-devcap-post-charset"];
+ if (!string.IsNullOrEmpty(postDataCharset))
+ {
+ try
+ {
+ return Encoding.GetEncoding(postDataCharset);
+ }
+ catch (ArgumentException)
+ {
+ }
+ }
+ }
+
+ return request.GetTypedHeaders().ContentType.Encoding ?? Encoding.UTF8;
+ }
}
- public Uri UrlReferrer => request.UrlReferrer;
+ public Uri UrlReferrer => request.GetTypedHeaders().Referer;
public static Encoding GetEncoding(string contentTypeHeader)
{
- var param = GetParameter(contentTypeHeader, "charset=");
+ var param = GetParameter(contentTypeHeader.AsSpan(), "charset=");
if (param == null)
{
return null;
@@ -487,9 +465,9 @@ namespace Jellyfin.Server.SocketSharp
}
}
- public Stream InputStream => request.InputStream;
+ public Stream InputStream => request.Body;
- public long ContentLength => request.ContentLength64;
+ public long ContentLength => request.ContentLength ?? 0;
private IHttpFile[] httpFiles;
public IHttpFile[] Files
@@ -523,15 +501,18 @@ namespace Jellyfin.Server.SocketSharp
}
}
- public static string NormalizePathInfo(string pathInfo, string handlerPath)
+ public static ReadOnlySpan<char> NormalizePathInfo(string pathInfo, string handlerPath)
{
- var trimmed = pathInfo.TrimStart('/');
- if (handlerPath != null && trimmed.StartsWith(handlerPath, StringComparison.OrdinalIgnoreCase))
+ if (handlerPath != null)
{
- return trimmed.Substring(handlerPath.Length);
+ var trimmed = pathInfo.AsSpan().TrimStart('/');
+ if (trimmed.StartsWith(handlerPath.AsSpan(), StringComparison.OrdinalIgnoreCase))
+ {
+ return trimmed.Slice(handlerPath.Length).ToString().AsSpan();
+ }
}
- return pathInfo;
+ return pathInfo.AsSpan();
}
}
}
diff --git a/Emby.Server.Implementations/SocketSharp/WebSocketSharpResponse.cs b/Emby.Server.Implementations/SocketSharp/WebSocketSharpResponse.cs
new file mode 100644
index 000000000..0f67eaa62
--- /dev/null
+++ b/Emby.Server.Implementations/SocketSharp/WebSocketSharpResponse.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
+using MediaBrowser.Model.IO;
+using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Logging;
+using IRequest = MediaBrowser.Model.Services.IRequest;
+
+namespace Emby.Server.Implementations.SocketSharp
+{
+ public class WebSocketSharpResponse : IResponse
+ {
+ private readonly ILogger _logger;
+
+ public WebSocketSharpResponse(ILogger logger, HttpResponse response)
+ {
+ _logger = logger;
+ OriginalResponse = response;
+ }
+
+ public HttpResponse OriginalResponse { get; }
+
+ public int StatusCode
+ {
+ get => OriginalResponse.StatusCode;
+ set => OriginalResponse.StatusCode = value;
+ }
+
+ public string StatusDescription { get; set; }
+
+ public string ContentType
+ {
+ get => OriginalResponse.ContentType;
+ set => OriginalResponse.ContentType = value;
+ }
+
+ public void AddHeader(string name, string value)
+ {
+ if (string.Equals(name, "Content-Type", StringComparison.OrdinalIgnoreCase))
+ {
+ ContentType = value;
+ return;
+ }
+
+ OriginalResponse.Headers.Add(name, value);
+ }
+
+ public void Redirect(string url)
+ {
+ OriginalResponse.Redirect(url);
+ }
+
+ public Stream OutputStream => OriginalResponse.Body;
+
+ public bool SendChunked { get; set; }
+
+ const int StreamCopyToBufferSize = 81920;
+ public async Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, IFileSystem fileSystem, IStreamHelper streamHelper, CancellationToken cancellationToken)
+ {
+ var allowAsync = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+
+ //if (count <= 0)
+ //{
+ // allowAsync = true;
+ //}
+
+ var fileOpenOptions = FileOpenOptions.SequentialScan;
+
+ if (allowAsync)
+ {
+ fileOpenOptions |= FileOpenOptions.Asynchronous;
+ }
+
+ // use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039
+
+ using (var fs = fileSystem.GetFileStream(path, FileOpenMode.Open, FileAccessMode.Read, fileShareMode, fileOpenOptions))
+ {
+ if (offset > 0)
+ {
+ fs.Position = offset;
+ }
+
+ if (count > 0)
+ {
+ await streamHelper.CopyToAsync(fs, OutputStream, count, cancellationToken).ConfigureAwait(false);
+ }
+ else
+ {
+ await fs.CopyToAsync(OutputStream, StreamCopyToBufferSize, cancellationToken).ConfigureAwait(false);
+ }
+ }
+ }
+ }
+}
diff --git a/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs b/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs
index 535f123f9..0804b01fc 100644
--- a/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs
+++ b/Emby.Server.Implementations/Sorting/AlbumArtistComparer.cs
@@ -32,7 +32,7 @@ namespace Emby.Server.Implementations.Sorting
{
var audio = x as IHasAlbumArtist;
- return audio != null ? audio.AlbumArtists.FirstOrDefault() : null;
+ return audio?.AlbumArtists.FirstOrDefault();
}
/// <summary>
diff --git a/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs b/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs
index 46e0dd918..504b6d283 100644
--- a/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs
+++ b/Emby.Server.Implementations/Sorting/SeriesSortNameComparer.cs
@@ -18,17 +18,17 @@ namespace Emby.Server.Implementations.Sorting
return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase);
}
- private static string GetValue(BaseItem item)
- {
- var hasSeries = item as IHasSeries;
-
- return hasSeries != null ? hasSeries.FindSeriesSortName() : null;
- }
-
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
public string Name => ItemSortBy.SeriesSortName;
+
+ private static string GetValue(BaseItem item)
+ {
+ var hasSeries = item as IHasSeries;
+
+ return hasSeries?.FindSeriesSortName();
+ }
}
}
diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs
index 301802b8a..7310de55d 100644
--- a/Emby.Server.Implementations/Updates/InstallationManager.cs
+++ b/Emby.Server.Implementations/Updates/InstallationManager.cs
@@ -12,7 +12,6 @@ using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Progress;
using MediaBrowser.Common.Updates;
using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
@@ -39,11 +38,10 @@ namespace Emby.Server.Implementations.Updates
/// <summary>
/// The completed installations
/// </summary>
- private ConcurrentBag<InstallationInfo> CompletedInstallationsInternal { get; set; }
+ private ConcurrentBag<InstallationInfo> _completedInstallationsInternal;
- public IEnumerable<InstallationInfo> CompletedInstallations => CompletedInstallationsInternal;
+ public IEnumerable<InstallationInfo> CompletedInstallations => _completedInstallationsInternal;
- #region PluginUninstalled Event
/// <summary>
/// Occurs when [plugin uninstalled].
/// </summary>
@@ -57,9 +55,7 @@ namespace Emby.Server.Implementations.Updates
{
PluginUninstalled?.Invoke(this, new GenericEventArgs<IPlugin> { Argument = plugin });
}
- #endregion
- #region PluginUpdated Event
/// <summary>
/// Occurs when [plugin updated].
/// </summary>
@@ -77,9 +73,7 @@ namespace Emby.Server.Implementations.Updates
_applicationHost.NotifyPendingRestart();
}
- #endregion
- #region PluginInstalled Event
/// <summary>
/// Occurs when [plugin updated].
/// </summary>
@@ -96,7 +90,6 @@ namespace Emby.Server.Implementations.Updates
_applicationHost.NotifyPendingRestart();
}
- #endregion
/// <summary>
/// The _logger
@@ -115,12 +108,8 @@ namespace Emby.Server.Implementations.Updates
/// <value>The application host.</value>
private readonly IApplicationHost _applicationHost;
- private readonly ICryptoProvider _cryptographyProvider;
private readonly IZipClient _zipClient;
- // netframework or netcore
- private readonly string _packageRuntime;
-
public InstallationManager(
ILoggerFactory loggerFactory,
IApplicationHost appHost,
@@ -129,9 +118,7 @@ namespace Emby.Server.Implementations.Updates
IJsonSerializer jsonSerializer,
IServerConfigurationManager config,
IFileSystem fileSystem,
- ICryptoProvider cryptographyProvider,
- IZipClient zipClient,
- string packageRuntime)
+ IZipClient zipClient)
{
if (loggerFactory == null)
{
@@ -139,18 +126,16 @@ namespace Emby.Server.Implementations.Updates
}
CurrentInstallations = new List<Tuple<InstallationInfo, CancellationTokenSource>>();
- CompletedInstallationsInternal = new ConcurrentBag<InstallationInfo>();
+ _completedInstallationsInternal = new ConcurrentBag<InstallationInfo>();
+ _logger = loggerFactory.CreateLogger(nameof(InstallationManager));
_applicationHost = appHost;
_appPaths = appPaths;
_httpClient = httpClient;
_jsonSerializer = jsonSerializer;
_config = config;
_fileSystem = fileSystem;
- _cryptographyProvider = cryptographyProvider;
_zipClient = zipClient;
- _packageRuntime = packageRuntime;
- _logger = loggerFactory.CreateLogger(nameof(InstallationManager));
}
private static Version GetPackageVersion(PackageVersionInfo version)
@@ -222,11 +207,6 @@ namespace Emby.Server.Implementations.Updates
continue;
}
- if (string.IsNullOrEmpty(version.runtimes) || version.runtimes.IndexOf(_packageRuntime, StringComparison.OrdinalIgnoreCase) == -1)
- {
- continue;
- }
-
versions.Add(version);
}
@@ -448,7 +428,7 @@ namespace Emby.Server.Implementations.Updates
CurrentInstallations.Remove(tuple);
}
- CompletedInstallationsInternal.Add(installationInfo);
+ _completedInstallationsInternal.Add(installationInfo);
PackageInstallationCompleted?.Invoke(this, installationEventArgs);
}
diff --git a/Emby.Server.Implementations/UserViews/CollectionFolderImageProvider.cs b/Emby.Server.Implementations/UserViews/CollectionFolderImageProvider.cs
index ce6c2cd87..a3f3f6cb4 100644
--- a/Emby.Server.Implementations/UserViews/CollectionFolderImageProvider.cs
+++ b/Emby.Server.Implementations/UserViews/CollectionFolderImageProvider.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Linq;
using Emby.Server.Implementations.Images;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Drawing;
@@ -20,7 +19,7 @@ namespace Emby.Server.Implementations.UserViews
{
}
- protected override List<BaseItem> GetItemsWithImages(BaseItem item)
+ protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{
var view = (CollectionFolder)item;
var viewType = view.CollectionType;
@@ -56,7 +55,7 @@ namespace Emby.Server.Implementations.UserViews
includeItemTypes = new string[] { "Video", "Audio", "Photo", "Movie", "Series" };
}
- var recursive = !new[] { CollectionType.Playlists }.Contains(view.CollectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
+ var recursive = !string.Equals(CollectionType.Playlists, viewType, StringComparison.OrdinalIgnoreCase);
return view.GetItemList(new InternalItemsQuery
{
@@ -71,7 +70,7 @@ namespace Emby.Server.Implementations.UserViews
},
IncludeItemTypes = includeItemTypes
- }).ToList();
+ });
}
protected override bool Supports(BaseItem item)
@@ -79,7 +78,7 @@ namespace Emby.Server.Implementations.UserViews
return item is CollectionFolder;
}
- protected override string CreateImage(BaseItem item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
+ protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
{
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ".png");
diff --git a/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs b/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs
index 4ec68e550..f48520443 100644
--- a/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs
+++ b/Emby.Server.Implementations/UserViews/DynamicImageProvider.cs
@@ -28,7 +28,7 @@ namespace Emby.Server.Implementations.UserViews
_libraryManager = libraryManager;
}
- protected override List<BaseItem> GetItemsWithImages(BaseItem item)
+ protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{
var view = (UserView)item;
@@ -46,8 +46,7 @@ namespace Emby.Server.Implementations.UserViews
var items = result.Select(i =>
{
- var episode = i as Episode;
- if (episode != null)
+ if (i is Episode episode)
{
var series = episode.Series;
if (series != null)
@@ -58,8 +57,7 @@ namespace Emby.Server.Implementations.UserViews
return episode;
}
- var season = i as Season;
- if (season != null)
+ if (i is Season season)
{
var series = season.Series;
if (series != null)
@@ -70,8 +68,7 @@ namespace Emby.Server.Implementations.UserViews
return season;
}
- var audio = i as Audio;
- if (audio != null)
+ if (i is Audio audio)
{
var album = audio.AlbumEntity;
if (album != null && album.HasImage(ImageType.Primary))
@@ -122,7 +119,7 @@ namespace Emby.Server.Implementations.UserViews
return collectionStripViewTypes.Contains(view.ViewType ?? string.Empty);
}
- protected override string CreateImage(BaseItem item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
+ protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
{
if (itemsWithImages.Count == 0)
{
diff --git a/Emby.Server.Implementations/UserViews/FolderImageProvider.cs b/Emby.Server.Implementations/UserViews/FolderImageProvider.cs
index c810004ab..4655cd928 100644
--- a/Emby.Server.Implementations/UserViews/FolderImageProvider.cs
+++ b/Emby.Server.Implementations/UserViews/FolderImageProvider.cs
@@ -24,7 +24,7 @@ namespace Emby.Server.Implementations.UserViews
_libraryManager = libraryManager;
}
- protected override List<BaseItem> GetItemsWithImages(BaseItem item)
+ protected override IReadOnlyList<BaseItem> GetItemsWithImages(BaseItem item)
{
return _libraryManager.GetItemList(new InternalItemsQuery
{
@@ -40,7 +40,7 @@ namespace Emby.Server.Implementations.UserViews
});
}
- protected override string CreateImage(BaseItem item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
+ protected override string CreateImage(BaseItem item, IReadOnlyCollection<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
{
return CreateSingleImage(itemsWithImages, outputPathWithoutExtension, ImageType.Primary);
}
diff --git a/Emby.Server.Implementations/WebSockets/WebSocketHandler.cs b/Emby.Server.Implementations/WebSockets/WebSocketHandler.cs
new file mode 100644
index 000000000..eb1877440
--- /dev/null
+++ b/Emby.Server.Implementations/WebSockets/WebSocketHandler.cs
@@ -0,0 +1,10 @@
+using System.Threading.Tasks;
+using MediaBrowser.Model.Net;
+
+namespace Emby.Server.Implementations.WebSockets
+{
+ public interface IWebSocketHandler
+ {
+ Task ProcessMessage(WebSocketMessage<object> message, TaskCompletionSource<bool> taskCompletionSource);
+ }
+}
diff --git a/Emby.Server.Implementations/WebSockets/WebSocketManager.cs b/Emby.Server.Implementations/WebSockets/WebSocketManager.cs
new file mode 100644
index 000000000..04c73ecea
--- /dev/null
+++ b/Emby.Server.Implementations/WebSockets/WebSocketManager.cs
@@ -0,0 +1,102 @@
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.WebSockets;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using MediaBrowser.Controller.Net;
+using MediaBrowser.Model.Net;
+using MediaBrowser.Model.Serialization;
+using Microsoft.Extensions.Logging;
+using UtfUnknown;
+
+namespace Emby.Server.Implementations.WebSockets
+{
+ public class WebSocketManager
+ {
+ private readonly IWebSocketHandler[] _webSocketHandlers;
+ private readonly IJsonSerializer _jsonSerializer;
+ private readonly ILogger<WebSocketManager> _logger;
+ private const int BufferSize = 4096;
+
+ public WebSocketManager(IWebSocketHandler[] webSocketHandlers, IJsonSerializer jsonSerializer, ILogger<WebSocketManager> logger)
+ {
+ _webSocketHandlers = webSocketHandlers;
+ _jsonSerializer = jsonSerializer;
+ _logger = logger;
+ }
+
+ public async Task OnWebSocketConnected(WebSocket webSocket)
+ {
+ var taskCompletionSource = new TaskCompletionSource<bool>();
+ var cancellationToken = new CancellationTokenSource().Token;
+ WebSocketReceiveResult result;
+ var message = new List<byte>();
+
+ // Keep listening for incoming messages, otherwise the socket closes automatically
+ do
+ {
+ var buffer = WebSocket.CreateServerBuffer(BufferSize);
+ result = await webSocket.ReceiveAsync(buffer, cancellationToken);
+ message.AddRange(buffer.Array.Take(result.Count));
+
+ if (result.EndOfMessage)
+ {
+ await ProcessMessage(message.ToArray(), taskCompletionSource);
+ message.Clear();
+ }
+ } while (!taskCompletionSource.Task.IsCompleted &&
+ webSocket.State == WebSocketState.Open &&
+ result.MessageType != WebSocketMessageType.Close);
+
+ if (webSocket.State == WebSocketState.Open)
+ {
+ await webSocket.CloseAsync(result.CloseStatus ?? WebSocketCloseStatus.NormalClosure,
+ result.CloseStatusDescription, cancellationToken);
+ }
+ }
+
+ private async Task ProcessMessage(byte[] messageBytes, TaskCompletionSource<bool> taskCompletionSource)
+ {
+ var charset = CharsetDetector.DetectFromBytes(messageBytes).Detected?.EncodingName;
+ var message = string.Equals(charset, "utf-8", StringComparison.OrdinalIgnoreCase)
+ ? Encoding.UTF8.GetString(messageBytes, 0, messageBytes.Length)
+ : Encoding.ASCII.GetString(messageBytes, 0, messageBytes.Length);
+
+ // All messages are expected to be valid JSON objects
+ if (!message.StartsWith("{", StringComparison.OrdinalIgnoreCase))
+ {
+ _logger.LogDebug("Received web socket message that is not a json structure: {Message}", message);
+ return;
+ }
+
+ try
+ {
+ var info = _jsonSerializer.DeserializeFromString<WebSocketMessage<object>>(message);
+
+ _logger.LogDebug("Websocket message received: {0}", info.MessageType);
+
+ var tasks = _webSocketHandlers.Select(handler => Task.Run(() =>
+ {
+ try
+ {
+ handler.ProcessMessage(info, taskCompletionSource).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "{HandlerType} failed processing WebSocket message {MessageType}",
+ handler.GetType().Name, info.MessageType ?? string.Empty);
+ }
+ }));
+
+ await Task.WhenAll(tasks);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error processing web socket message");
+ }
+ }
+ }
+}
diff --git a/Emby.Server.Implementations/Xml/XmlReaderSettingsFactory.cs b/Emby.Server.Implementations/Xml/XmlReaderSettingsFactory.cs
deleted file mode 100644
index 308922e6d..000000000
--- a/Emby.Server.Implementations/Xml/XmlReaderSettingsFactory.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System.Xml;
-using MediaBrowser.Model.Xml;
-
-namespace Emby.Server.Implementations.Xml
-{
- public class XmlReaderSettingsFactory : IXmlReaderSettingsFactory
- {
- public XmlReaderSettings Create(bool enableValidation)
- {
- var settings = new XmlReaderSettings();
-
- if (!enableValidation)
- {
- settings.ValidationType = ValidationType.None;
- }
-
- return settings;
- }
- }
-}
diff --git a/Emby.XmlTv/Emby.XmlTv/Classes/XmlTvReader.cs b/Emby.XmlTv/Emby.XmlTv/Classes/XmlTvReader.cs
index 52ec7a135..46bf6cc21 100644
--- a/Emby.XmlTv/Emby.XmlTv/Classes/XmlTvReader.cs
+++ b/Emby.XmlTv/Emby.XmlTv/Classes/XmlTvReader.cs
@@ -495,9 +495,7 @@ namespace Emby.XmlTv.Classes
ParseMovieDbSystem(reader, result);
break;
case "SxxExx":
- // TODO
- // <episode-num system="SxxExx">S03E12</episode-num>
- reader.Skip();
+ ParseSxxExxSystem(reader, result);
break;
default: // Handles empty string and nulls
reader.Skip();
@@ -505,6 +503,29 @@ namespace Emby.XmlTv.Classes
}
}
+ public void ParseSxxExxSystem(XmlReader reader, XmlTvProgram result)
+ {
+ // <episode-num system="SxxExx">S012E32</episode-num>
+
+ var value = reader.ReadElementContentAsString();
+ var res = Regex.Match(value, "s([0-9]+)e([0-9]+)", RegexOptions.IgnoreCase);
+
+ if (res.Success)
+ {
+ int parsedInt;
+
+ if (int.TryParse(res.Groups[1].Value, out parsedInt))
+ {
+ result.Episode.Series = parsedInt;
+ }
+
+ if (int.TryParse(res.Groups[2].Value, out parsedInt))
+ {
+ result.Episode.Episode = parsedInt;
+ }
+ }
+ }
+
public void ParseMovieDbSystem(XmlReader reader, XmlTvProgram result)
{
// <episode-num system="thetvdb.com">series/248841</episode-num>
diff --git a/Emby.XmlTv/Emby.XmlTv/Properties/AssemblyInfo.cs b/Emby.XmlTv/Emby.XmlTv/Properties/AssemblyInfo.cs
index ff2efb078..7beec09cb 100644
--- a/Emby.XmlTv/Emby.XmlTv/Properties/AssemblyInfo.cs
+++ b/Emby.XmlTv/Emby.XmlTv/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/Jellyfin.Drawing.Skia/PercentPlayedDrawer.cs b/Jellyfin.Drawing.Skia/PercentPlayedDrawer.cs
index 0d5a1d3c0..c72f295fd 100644
--- a/Jellyfin.Drawing.Skia/PercentPlayedDrawer.cs
+++ b/Jellyfin.Drawing.Skia/PercentPlayedDrawer.cs
@@ -23,7 +23,7 @@ namespace Jellyfin.Drawing.Skia
foregroundWidth *= percent;
foregroundWidth /= 100;
- paint.Color = SKColor.Parse("#FF52B54B");
+ paint.Color = SKColor.Parse("#FF00A4DC");
canvas.DrawRect(SKRect.Create(0, (float)endY - IndicatorHeight, Convert.ToInt32(foregroundWidth), (float)endY), paint);
}
}
diff --git a/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs b/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs
index 62497da27..7f3c18bb2 100644
--- a/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs
+++ b/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs
@@ -13,7 +13,7 @@ namespace Jellyfin.Drawing.Skia
using (var paint = new SKPaint())
{
- paint.Color = SKColor.Parse("#CC52B54B");
+ paint.Color = SKColor.Parse("#CC00A4DC");
paint.Style = SKPaintStyle.Fill;
canvas.DrawCircle((float)x, OffsetFromTopRightCorner, 20, paint);
}
diff --git a/Jellyfin.Drawing.Skia/Properties/AssemblyInfo.cs b/Jellyfin.Drawing.Skia/Properties/AssemblyInfo.cs
index ea1c457f6..e7db09449 100644
--- a/Jellyfin.Drawing.Skia/Properties/AssemblyInfo.cs
+++ b/Jellyfin.Drawing.Skia/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs b/Jellyfin.Drawing.Skia/StripCollageBuilder.cs
index dfdf39871..7d404ce64 100644
--- a/Jellyfin.Drawing.Skia/StripCollageBuilder.cs
+++ b/Jellyfin.Drawing.Skia/StripCollageBuilder.cs
@@ -77,21 +77,18 @@ namespace Jellyfin.Drawing.Skia
{
canvas.Clear(SKColors.Black);
+ // number of images used in the thumbnail
+ var iCount = 3;
+
// determine sizes for each image that will composited into the final image
- var iSlice = Convert.ToInt32(width * 0.23475);
- int iTrans = Convert.ToInt32(height * .25);
- int iHeight = Convert.ToInt32(height * .70);
- var horizontalImagePadding = Convert.ToInt32(width * 0.0125);
- var verticalSpacing = Convert.ToInt32(height * 0.01111111111111111111111111111111);
+ var iSlice = Convert.ToInt32(width / iCount);
+ int iHeight = Convert.ToInt32(height * 1.00);
int imageIndex = 0;
-
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < iCount; i++)
{
-
using (var currentBitmap = GetNextValidImage(paths, imageIndex, out int newIndex))
{
imageIndex = newIndex;
-
if (currentBitmap == null)
{
continue;
@@ -108,44 +105,7 @@ namespace Jellyfin.Drawing.Skia
using (var subset = image.Subset(SKRectI.Create(ix, 0, iSlice, iHeight)))
{
// draw image onto canvas
- canvas.DrawImage(subset ?? image, (horizontalImagePadding * (i + 1)) + (iSlice * i), verticalSpacing);
-
- if (subset == null)
- {
- continue;
- }
- // create reflection of image below the drawn image
- using (var croppedBitmap = SKBitmap.FromImage(subset))
- using (var reflectionBitmap = new SKBitmap(croppedBitmap.Width, croppedBitmap.Height / 2, croppedBitmap.ColorType, croppedBitmap.AlphaType))
- {
- // resize to half height
- currentBitmap.ScalePixels(reflectionBitmap, SKFilterQuality.High);
-
- using (var flippedBitmap = new SKBitmap(reflectionBitmap.Width, reflectionBitmap.Height, reflectionBitmap.ColorType, reflectionBitmap.AlphaType))
- using (var flippedCanvas = new SKCanvas(flippedBitmap))
- {
- // flip image vertically
- var matrix = SKMatrix.MakeScale(1, -1);
- matrix.SetScaleTranslate(1, -1, 0, flippedBitmap.Height);
- flippedCanvas.SetMatrix(matrix);
- flippedCanvas.DrawBitmap(reflectionBitmap, 0, 0);
- flippedCanvas.ResetMatrix();
-
- // create gradient to make image appear as a reflection
- var remainingHeight = height - (iHeight + (2 * verticalSpacing));
- flippedCanvas.ClipRect(SKRect.Create(reflectionBitmap.Width, remainingHeight));
- using (var gradient = new SKPaint())
- {
- gradient.IsAntialias = true;
- gradient.BlendMode = SKBlendMode.SrcOver;
- gradient.Shader = SKShader.CreateLinearGradient(new SKPoint(0, 0), new SKPoint(0, remainingHeight), new[] { new SKColor(0, 0, 0, 128), new SKColor(0, 0, 0, 208), new SKColor(0, 0, 0, 240), new SKColor(0, 0, 0, 255) }, null, SKShaderTileMode.Clamp);
- flippedCanvas.DrawPaint(gradient);
- }
-
- // finally draw reflection onto canvas
- canvas.DrawBitmap(flippedBitmap, (horizontalImagePadding * (i + 1)) + (iSlice * i), iHeight + (2 * verticalSpacing));
- }
- }
+ canvas.DrawImage(subset ?? image, iSlice * i, 0);
}
}
}
diff --git a/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs b/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs
index ba712bff7..dbf935f4e 100644
--- a/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs
+++ b/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs
@@ -15,7 +15,7 @@ namespace Jellyfin.Drawing.Skia
using (var paint = new SKPaint())
{
- paint.Color = SKColor.Parse("#CC52B54B");
+ paint.Color = SKColor.Parse("#CC00A4DC");
paint.Style = SKPaintStyle.Fill;
canvas.DrawCircle((float)x, OffsetFromTopRightCorner, 20, paint);
}
diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs
index 84d78d3fb..8e6ed7a7e 100644
--- a/Jellyfin.Server/CoreAppHost.cs
+++ b/Jellyfin.Server/CoreAppHost.cs
@@ -2,9 +2,7 @@ using System.Collections.Generic;
using System.Reflection;
using Emby.Server.Implementations;
using Emby.Server.Implementations.HttpServer;
-using Jellyfin.Server.SocketSharp;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
@@ -17,7 +15,6 @@ namespace Jellyfin.Server
ILoggerFactory loggerFactory,
StartupOptions options,
IFileSystem fileSystem,
- IEnvironmentInfo environmentInfo,
MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder,
MediaBrowser.Common.Net.INetworkManager networkManager,
IConfiguration configuration)
@@ -26,7 +23,6 @@ namespace Jellyfin.Server
loggerFactory,
options,
fileSystem,
- environmentInfo,
imageEncoder,
networkManager,
configuration)
@@ -35,8 +31,6 @@ namespace Jellyfin.Server
public override bool CanSelfRestart => StartupOptions.RestartPath != null;
- protected override bool SupportsDualModeSockets => true;
-
protected override void RestartInternal() => Program.Restart();
protected override IEnumerable<Assembly> GetAssembliesWithPartsInternal()
@@ -45,17 +39,5 @@ namespace Jellyfin.Server
}
protected override void ShutdownInternal() => Program.Shutdown();
-
- protected override IHttpListener CreateHttpListener()
- => new WebSocketSharpListener(
- Logger,
- Certificate,
- StreamHelper,
- NetworkManager,
- SocketFactory,
- CryptographyProvider,
- SupportsDualModeSockets,
- FileSystemManager,
- EnvironmentInfo);
}
}
diff --git a/Jellyfin.Server/Jellyfin.Server.csproj b/Jellyfin.Server/Jellyfin.Server.csproj
index bd670df52..9346a2d25 100644
--- a/Jellyfin.Server/Jellyfin.Server.csproj
+++ b/Jellyfin.Server/Jellyfin.Server.csproj
@@ -12,7 +12,8 @@
<!-- We need C# 7.1 for async main-->
<LangVersion>latest</LangVersion>
<!-- Disable documentation warnings (for now) -->
- <NoWarn>SA1600;CS1591</NoWarn>
+ <NoWarn>SA1600;SA1601;CS1591</NoWarn>
+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
@@ -23,10 +24,6 @@
<EmbeddedResource Include="Resources/Configuration/*" />
</ItemGroup>
- <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
- <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
- </PropertyGroup>
-
<!-- Code analysers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.3" />
diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs
index 2a2f1dde6..d4b10c8c8 100644
--- a/Jellyfin.Server/Program.cs
+++ b/Jellyfin.Server/Program.cs
@@ -12,7 +12,6 @@ using System.Threading.Tasks;
using CommandLine;
using Emby.Drawing;
using Emby.Server.Implementations;
-using Emby.Server.Implementations.EnvironmentInfo;
using Emby.Server.Implementations.IO;
using Emby.Server.Implementations.Networking;
using Jellyfin.Drawing.Skia;
@@ -45,7 +44,6 @@ namespace Jellyfin.Server
const string pattern = @"^(-[^-\s]{2})"; // Match -xx, not -x, not --xx, not xx
const string substitution = @"-$1"; // Prepend with additional single-hyphen
var regex = new Regex(pattern);
-
for (var i = 0; i < args.Length; i++)
{
args[i] = regex.Replace(args[i], substitution);
@@ -53,9 +51,7 @@ namespace Jellyfin.Server
// Parse the command line arguments and either start the app or exit indicating error
await Parser.Default.ParseArguments<StartupOptions>(args)
- .MapResult(
- options => StartApp(options),
- errs => Task.FromResult(0)).ConfigureAwait(false);
+ .MapResult(StartApp, _ => Task.CompletedTask).ConfigureAwait(false);
}
public static void Shutdown()
@@ -118,33 +114,29 @@ namespace Jellyfin.Server
_logger.LogInformation("Jellyfin version: {Version}", Assembly.GetEntryAssembly().GetName().Version);
- EnvironmentInfo environmentInfo = new EnvironmentInfo(GetOperatingSystem());
- ApplicationHost.LogEnvironmentInfo(_logger, appPaths, environmentInfo);
+ ApplicationHost.LogEnvironmentInfo(_logger, appPaths);
SQLitePCL.Batteries_V2.Init();
// Allow all https requests
- ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; } );
+ ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
- var fileSystem = new ManagedFileSystem(_loggerFactory, environmentInfo, appPaths);
+ var fileSystem = new ManagedFileSystem(_loggerFactory, appPaths);
using (var appHost = new CoreAppHost(
appPaths,
_loggerFactory,
options,
fileSystem,
- environmentInfo,
new NullImageEncoder(),
- new NetworkManager(_loggerFactory, environmentInfo),
+ new NetworkManager(_loggerFactory),
appConfig))
{
- await appHost.Init(new ServiceCollection()).ConfigureAwait(false);
+ await appHost.InitAsync(new ServiceCollection()).ConfigureAwait(false);
appHost.ImageProcessor.ImageEncoder = GetImageEncoder(fileSystem, appPaths, appHost.LocalizationManager);
- await appHost.RunStartupTasks().ConfigureAwait(false);
-
- // TODO: read input for a stop command
+ await appHost.RunStartupTasksAsync().ConfigureAwait(false);
try
{
@@ -175,35 +167,19 @@ namespace Jellyfin.Server
{
// dataDir
// IF --datadir
- // ELSE IF $JELLYFIN_DATA_PATH
+ // ELSE IF $JELLYFIN_DATA_DIR
// ELSE IF windows, use <%APPDATA%>/jellyfin
// ELSE IF $XDG_DATA_HOME then use $XDG_DATA_HOME/jellyfin
// ELSE use $HOME/.local/share/jellyfin
var dataDir = options.DataDir;
-
if (string.IsNullOrEmpty(dataDir))
{
- dataDir = Environment.GetEnvironmentVariable("JELLYFIN_DATA_PATH");
+ dataDir = Environment.GetEnvironmentVariable("JELLYFIN_DATA_DIR");
if (string.IsNullOrEmpty(dataDir))
{
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- dataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- }
- else
- {
- // $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored.
- dataDir = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
-
- // If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.
- if (string.IsNullOrEmpty(dataDir))
- {
- dataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share");
- }
- }
-
- dataDir = Path.Combine(dataDir, "jellyfin");
+ // LocalApplicationData follows the XDG spec on unix machines
+ dataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "jellyfin");
}
}
@@ -216,7 +192,6 @@ namespace Jellyfin.Server
// ELSE IF $XDG_CONFIG_HOME use $XDG_CONFIG_HOME/jellyfin
// ELSE $HOME/.config/jellyfin
var configDir = options.ConfigDir;
-
if (string.IsNullOrEmpty(configDir))
{
configDir = Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR");
@@ -251,7 +226,6 @@ namespace Jellyfin.Server
// ELSE IF XDG_CACHE_HOME, use $XDG_CACHE_HOME/jellyfin
// ELSE HOME/.cache/jellyfin
var cacheDir = options.CacheDir;
-
if (string.IsNullOrEmpty(cacheDir))
{
cacheDir = Environment.GetEnvironmentVariable("JELLYFIN_CACHE_DIR");
@@ -279,13 +253,29 @@ namespace Jellyfin.Server
}
}
+ // webDir
+ // IF --webdir
+ // ELSE IF $JELLYFIN_WEB_DIR
+ // ELSE use <bindir>/jellyfin-web
+ var webDir = options.WebDir;
+
+ if (string.IsNullOrEmpty(webDir))
+ {
+ webDir = Environment.GetEnvironmentVariable("JELLYFIN_WEB_DIR");
+
+ if (string.IsNullOrEmpty(webDir))
+ {
+ // Use default location under ResourcesPath
+ webDir = Path.Combine(AppContext.BaseDirectory, "jellyfin-web", "src");
+ }
+ }
+
// logDir
// IF --logdir
// ELSE IF $JELLYFIN_LOG_DIR
// ELSE IF --datadir, use <datadir>/log (assume portable run)
// ELSE <datadir>/log
var logDir = options.LogDir;
-
if (string.IsNullOrEmpty(logDir))
{
logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR");
@@ -312,7 +302,7 @@ namespace Jellyfin.Server
Environment.Exit(1);
}
- return new ServerApplicationPaths(dataDir, logDir, configDir, cacheDir);
+ return new ServerApplicationPaths(dataDir, logDir, configDir, cacheDir, webDir);
}
private static async Task<IConfiguration> CreateConfiguration(IApplicationPaths appPaths)
@@ -380,36 +370,6 @@ namespace Jellyfin.Server
return new NullImageEncoder();
}
- private static MediaBrowser.Model.System.OperatingSystem GetOperatingSystem()
- {
- switch (Environment.OSVersion.Platform)
- {
- case PlatformID.MacOSX:
- return MediaBrowser.Model.System.OperatingSystem.OSX;
- case PlatformID.Win32NT:
- return MediaBrowser.Model.System.OperatingSystem.Windows;
- case PlatformID.Unix:
- default:
- {
- string osDescription = RuntimeInformation.OSDescription;
- if (osDescription.Contains("linux", StringComparison.OrdinalIgnoreCase))
- {
- return MediaBrowser.Model.System.OperatingSystem.Linux;
- }
- else if (osDescription.Contains("darwin", StringComparison.OrdinalIgnoreCase))
- {
- return MediaBrowser.Model.System.OperatingSystem.OSX;
- }
- else if (osDescription.Contains("bsd", StringComparison.OrdinalIgnoreCase))
- {
- return MediaBrowser.Model.System.OperatingSystem.BSD;
- }
-
- throw new Exception($"Can't resolve OS with description: '{osDescription}'");
- }
- }
- }
-
private static void StartNewInstance(StartupOptions options)
{
_logger.LogInformation("Starting new instance");
diff --git a/Jellyfin.Server/Properties/AssemblyInfo.cs b/Jellyfin.Server/Properties/AssemblyInfo.cs
index 2959cdf1f..5de1e653d 100644
--- a/Jellyfin.Server/Properties/AssemblyInfo.cs
+++ b/Jellyfin.Server/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs
deleted file mode 100644
index 58c4d38a2..000000000
--- a/Jellyfin.Server/SocketSharp/WebSocketSharpListener.cs
+++ /dev/null
@@ -1,273 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Security.Cryptography.X509Certificates;
-using System.Threading;
-using System.Threading.Tasks;
-using Emby.Server.Implementations.HttpServer;
-using Emby.Server.Implementations.Net;
-using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Net;
-using MediaBrowser.Model.Cryptography;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Net;
-using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
-using Microsoft.Extensions.Logging;
-using SocketHttpListener.Net;
-
-namespace Jellyfin.Server.SocketSharp
-{
- public class WebSocketSharpListener : IHttpListener
- {
- private HttpListener _listener;
-
- private readonly ILogger _logger;
- private readonly X509Certificate _certificate;
- private readonly IStreamHelper _streamHelper;
- private readonly INetworkManager _networkManager;
- private readonly ISocketFactory _socketFactory;
- private readonly ICryptoProvider _cryptoProvider;
- private readonly IFileSystem _fileSystem;
- private readonly bool _enableDualMode;
- private readonly IEnvironmentInfo _environment;
-
- private CancellationTokenSource _disposeCancellationTokenSource = new CancellationTokenSource();
- private CancellationToken _disposeCancellationToken;
-
- public WebSocketSharpListener(
- ILogger logger,
- X509Certificate certificate,
- IStreamHelper streamHelper,
- INetworkManager networkManager,
- ISocketFactory socketFactory,
- ICryptoProvider cryptoProvider,
- bool enableDualMode,
- IFileSystem fileSystem,
- IEnvironmentInfo environment)
- {
- _logger = logger;
- _certificate = certificate;
- _streamHelper = streamHelper;
- _networkManager = networkManager;
- _socketFactory = socketFactory;
- _cryptoProvider = cryptoProvider;
- _enableDualMode = enableDualMode;
- _fileSystem = fileSystem;
- _environment = environment;
-
- _disposeCancellationToken = _disposeCancellationTokenSource.Token;
- }
-
- public Func<Exception, IRequest, bool, bool, Task> ErrorHandler { get; set; }
- public Func<IHttpRequest, string, string, string, CancellationToken, Task> RequestHandler { get; set; }
-
- public Action<WebSocketConnectingEventArgs> WebSocketConnecting { get; set; }
-
- public Action<WebSocketConnectEventArgs> WebSocketConnected { get; set; }
-
- public void Start(IEnumerable<string> urlPrefixes)
- {
- if (_listener == null)
- {
- _listener = new HttpListener(_logger, _cryptoProvider, _socketFactory, _networkManager, _streamHelper, _fileSystem, _environment);
- }
-
- _listener.EnableDualMode = _enableDualMode;
-
- if (_certificate != null)
- {
- _listener.LoadCert(_certificate);
- }
-
- foreach (var prefix in urlPrefixes)
- {
- _logger.LogInformation("Adding HttpListener prefix " + prefix);
- _listener.Prefixes.Add(prefix);
- }
-
- _listener.OnContext = ProcessContext;
-
- _listener.Start();
- }
-
- private void ProcessContext(HttpListenerContext context)
- {
- _ = Task.Run(async () => await InitTask(context, _disposeCancellationToken).ConfigureAwait(false));
- }
-
- private static void LogRequest(ILogger logger, HttpListenerRequest request)
- {
- var url = request.Url.ToString();
-
- logger.LogInformation(
- "{0} {1}. UserAgent: {2}",
- request.IsWebSocketRequest ? "WS" : "HTTP " + request.HttpMethod,
- url,
- request.UserAgent ?? string.Empty);
- }
-
- private Task InitTask(HttpListenerContext context, CancellationToken cancellationToken)
- {
- IHttpRequest httpReq = null;
- var request = context.Request;
-
- try
- {
- if (request.IsWebSocketRequest)
- {
- LogRequest(_logger, request);
-
- return ProcessWebSocketRequest(context);
- }
-
- httpReq = GetRequest(context);
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Error processing request");
-
- httpReq = httpReq ?? GetRequest(context);
- return ErrorHandler(ex, httpReq, true, true);
- }
-
- var uri = request.Url;
-
- return RequestHandler(httpReq, uri.OriginalString, uri.Host, uri.LocalPath, cancellationToken);
- }
-
- private async Task ProcessWebSocketRequest(HttpListenerContext ctx)
- {
- try
- {
- var endpoint = ctx.Request.RemoteEndPoint.ToString();
- var url = ctx.Request.RawUrl;
-
- var queryString = ctx.Request.QueryString;
-
- var connectingArgs = new WebSocketConnectingEventArgs
- {
- Url = url,
- QueryString = queryString,
- Endpoint = endpoint
- };
-
- if (WebSocketConnecting != null)
- {
- WebSocketConnecting(connectingArgs);
- }
-
- if (connectingArgs.AllowConnection)
- {
- _logger.LogDebug("Web socket connection allowed");
-
- var webSocketContext = await ctx.AcceptWebSocketAsync(null).ConfigureAwait(false);
-
- if (WebSocketConnected != null)
- {
- var socket = new SharpWebSocket(webSocketContext.WebSocket, _logger);
-
- WebSocketConnected(new WebSocketConnectEventArgs
- {
- Url = url,
- QueryString = queryString,
- WebSocket = socket,
- Endpoint = endpoint
- });
-
- await ReceiveWebSocket(ctx, socket).ConfigureAwait(false);
- }
- }
- else
- {
- _logger.LogWarning("Web socket connection not allowed");
- ctx.Response.StatusCode = 401;
- ctx.Response.Close();
- }
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "AcceptWebSocketAsync error");
- ctx.Response.StatusCode = 500;
- ctx.Response.Close();
- }
- }
-
- private async Task ReceiveWebSocket(HttpListenerContext ctx, SharpWebSocket socket)
- {
- try
- {
- await socket.StartReceive().ConfigureAwait(false);
- }
- finally
- {
- TryClose(ctx, 200);
- }
- }
-
- private void TryClose(HttpListenerContext ctx, int statusCode)
- {
- try
- {
- ctx.Response.StatusCode = statusCode;
- ctx.Response.Close();
- }
- catch (ObjectDisposedException)
- {
- // TODO: Investigate and properly fix.
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Error closing web socket response");
- }
- }
-
- private IHttpRequest GetRequest(HttpListenerContext httpContext)
- {
- var urlSegments = httpContext.Request.Url.Segments;
-
- var operationName = urlSegments[urlSegments.Length - 1];
-
- var req = new WebSocketSharpRequest(httpContext, operationName, _logger);
-
- return req;
- }
-
- public Task Stop()
- {
- _disposeCancellationTokenSource.Cancel();
- _listener?.Close();
-
- return Task.CompletedTask;
- }
-
- /// <summary>
- /// Releases the unmanaged resources and disposes of the managed resources used.
- /// </summary>
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- private bool _disposed;
-
- /// <summary>
- /// Releases the unmanaged resources and disposes of the managed resources used.
- /// </summary>
- /// <param name="disposing">Whether or not the managed resources should be disposed</param>
- protected virtual void Dispose(bool disposing)
- {
- if (_disposed)
- {
- return;
- }
-
- if (disposing)
- {
- Stop().GetAwaiter().GetResult();
- }
-
- _disposed = true;
- }
- }
-}
diff --git a/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs b/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs
deleted file mode 100644
index 56e5c73d6..000000000
--- a/Jellyfin.Server/SocketSharp/WebSocketSharpResponse.cs
+++ /dev/null
@@ -1,181 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Net;
-using System.Net.Sockets;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Services;
-using Microsoft.Extensions.Logging;
-using HttpListenerResponse = SocketHttpListener.Net.HttpListenerResponse;
-using IHttpResponse = MediaBrowser.Model.Services.IHttpResponse;
-using IRequest = MediaBrowser.Model.Services.IRequest;
-
-namespace Jellyfin.Server.SocketSharp
-{
- public class WebSocketSharpResponse : IHttpResponse
- {
- private readonly ILogger _logger;
-
- private readonly HttpListenerResponse _response;
-
- public WebSocketSharpResponse(ILogger logger, HttpListenerResponse response, IRequest request)
- {
- _logger = logger;
- this._response = response;
- Items = new Dictionary<string, object>();
- Request = request;
- }
-
- public IRequest Request { get; private set; }
-
- public Dictionary<string, object> Items { get; private set; }
-
- public object OriginalResponse => _response;
-
- public int StatusCode
- {
- get => this._response.StatusCode;
- set => this._response.StatusCode = value;
- }
-
- public string StatusDescription
- {
- get => this._response.StatusDescription;
- set => this._response.StatusDescription = value;
- }
-
- public string ContentType
- {
- get => _response.ContentType;
- set => _response.ContentType = value;
- }
-
- public QueryParamCollection Headers => _response.Headers;
-
- public void AddHeader(string name, string value)
- {
- if (string.Equals(name, "Content-Type", StringComparison.OrdinalIgnoreCase))
- {
- ContentType = value;
- return;
- }
-
- _response.AddHeader(name, value);
- }
-
- public string GetHeader(string name)
- {
- return _response.Headers[name];
- }
-
- public void Redirect(string url)
- {
- _response.Redirect(url);
- }
-
- public Stream OutputStream => _response.OutputStream;
-
- public void Close()
- {
- if (!this.IsClosed)
- {
- this.IsClosed = true;
-
- try
- {
- var response = this._response;
-
- var outputStream = response.OutputStream;
-
- // This is needed with compression
- outputStream.Flush();
- outputStream.Dispose();
-
- response.Close();
- }
- catch (SocketException)
- {
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Error in HttpListenerResponseWrapper");
- }
- }
- }
-
- public bool IsClosed
- {
- get;
- private set;
- }
-
- public void SetContentLength(long contentLength)
- {
- // you can happily set the Content-Length header in Asp.Net
- // but HttpListener will complain if you do - you have to set ContentLength64 on the response.
- // workaround: HttpListener throws "The parameter is incorrect" exceptions when we try to set the Content-Length header
- _response.ContentLength64 = contentLength;
- }
-
- public void SetCookie(Cookie cookie)
- {
- var cookieStr = AsHeaderValue(cookie);
- _response.Headers.Add("Set-Cookie", cookieStr);
- }
-
- public static string AsHeaderValue(Cookie cookie)
- {
- var defaultExpires = DateTime.MinValue;
-
- var path = cookie.Expires == defaultExpires
- ? "/"
- : cookie.Path ?? "/";
-
- var sb = new StringBuilder();
-
- sb.Append($"{cookie.Name}={cookie.Value};path={path}");
-
- if (cookie.Expires != defaultExpires)
- {
- sb.Append($";expires={cookie.Expires:R}");
- }
-
- if (!string.IsNullOrEmpty(cookie.Domain))
- {
- sb.Append($";domain={cookie.Domain}");
- }
-
- if (cookie.Secure)
- {
- sb.Append(";Secure");
- }
-
- if (cookie.HttpOnly)
- {
- sb.Append(";HttpOnly");
- }
-
- return sb.ToString();
- }
-
- public bool SendChunked
- {
- get => _response.SendChunked;
- set => _response.SendChunked = value;
- }
-
- public bool KeepAlive { get; set; }
-
- public void ClearCookies()
- {
- }
-
- public Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken)
- {
- return _response.TransmitFile(path, offset, count, fileShareMode, cancellationToken);
- }
- }
-}
diff --git a/Jellyfin.Server/StartupOptions.cs b/Jellyfin.Server/StartupOptions.cs
index 5d3f7b171..8296d414e 100644
--- a/Jellyfin.Server/StartupOptions.cs
+++ b/Jellyfin.Server/StartupOptions.cs
@@ -11,6 +11,9 @@ namespace Jellyfin.Server
[Option('d', "datadir", Required = false, HelpText = "Path to use for the data folder (database files, etc.).")]
public string DataDir { get; set; }
+ [Option('w', "webdir", Required = false, HelpText = "Path to the Jellyfin web UI resources.")]
+ public string WebDir { get; set; }
+
[Option('C', "cachedir", Required = false, HelpText = "Path to use for caching.")]
public string CacheDir { get; set; }
@@ -20,12 +23,9 @@ namespace Jellyfin.Server
[Option('l', "logdir", Required = false, HelpText = "Path to use for writing log files.")]
public string LogDir { get; set; }
- [Option("ffmpeg", Required = false, HelpText = "Path to external FFmpeg executable to use in place of default found in PATH. Must be specified along with --ffprobe.")]
+ [Option("ffmpeg", Required = false, HelpText = "Path to external FFmpeg executable to use in place of default found in PATH.")]
public string FFmpegPath { get; set; }
- [Option("ffprobe", Required = false, HelpText = "Path to external FFprobe executable to use in place of default found in PATH. Must be specified along with --ffmpeg.")]
- public string FFprobePath { get; set; }
-
[Option("service", Required = false, HelpText = "Run as headless service.")]
public bool IsService { get; set; }
diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs
index 8dbc26356..700cbb943 100644
--- a/MediaBrowser.Api/ApiEntryPoint.cs
+++ b/MediaBrowser.Api/ApiEntryPoint.cs
@@ -170,7 +170,12 @@ namespace MediaBrowser.Api
/// </summary>
private void DeleteEncodedMediaCache()
{
- var path = _config.ApplicationPaths.TranscodingTempPath;
+ var path = _config.ApplicationPaths.GetTranscodingTempPath();
+
+ if (!Directory.Exists(path))
+ {
+ return;
+ }
foreach (var file in _fileSystem.GetFilePaths(path, true))
{
diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs
index 451ee72dd..49f8c6ace 100644
--- a/MediaBrowser.Api/BaseApiService.cs
+++ b/MediaBrowser.Api/BaseApiService.cs
@@ -9,6 +9,7 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Services;
+using MediaBrowser.Model.Querying;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api
@@ -118,8 +119,7 @@ namespace MediaBrowser.Api
{
var options = new DtoOptions();
- var hasFields = request as IHasItemFields;
- if (hasFields != null)
+ if (request is IHasItemFields hasFields)
{
options.Fields = hasFields.GetItemFields();
}
@@ -133,9 +133,11 @@ namespace MediaBrowser.Api
client.IndexOf("media center", StringComparison.OrdinalIgnoreCase) != -1 ||
client.IndexOf("classic", StringComparison.OrdinalIgnoreCase) != -1)
{
- var list = options.Fields.ToList();
- list.Add(Model.Querying.ItemFields.RecursiveItemCount);
- options.Fields = list.ToArray();
+ int oldLen = options.Fields.Length;
+ var arr = new ItemFields[oldLen + 1];
+ options.Fields.CopyTo(arr, 0);
+ arr[oldLen] = Model.Querying.ItemFields.RecursiveItemCount;
+ options.Fields = arr;
}
if (client.IndexOf("kodi", StringComparison.OrdinalIgnoreCase) != -1 ||
@@ -146,9 +148,12 @@ namespace MediaBrowser.Api
client.IndexOf("samsung", StringComparison.OrdinalIgnoreCase) != -1 ||
client.IndexOf("androidtv", StringComparison.OrdinalIgnoreCase) != -1)
{
- var list = options.Fields.ToList();
- list.Add(Model.Querying.ItemFields.ChildCount);
- options.Fields = list.ToArray();
+
+ int oldLen = options.Fields.Length;
+ var arr = new ItemFields[oldLen + 1];
+ options.Fields.CopyTo(arr, 0);
+ arr[oldLen] = Model.Querying.ItemFields.ChildCount;
+ options.Fields = arr;
}
}
@@ -160,6 +165,7 @@ namespace MediaBrowser.Api
{
options.ImageTypeLimit = hasDtoOptions.ImageTypeLimit.Value;
}
+
if (hasDtoOptions.EnableUserData.HasValue)
{
options.EnableUserData = hasDtoOptions.EnableUserData.Value;
@@ -167,7 +173,9 @@ namespace MediaBrowser.Api
if (!string.IsNullOrWhiteSpace(hasDtoOptions.EnableImageTypes))
{
- options.ImageTypes = (hasDtoOptions.EnableImageTypes ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true)).ToArray();
+ options.ImageTypes = hasDtoOptions.EnableImageTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
+ .Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true))
+ .ToArray();
}
}
@@ -300,7 +308,7 @@ namespace MediaBrowser.Api
return pathInfo[index];
}
- private string[] Parse(string pathUri)
+ private static string[] Parse(string pathUri)
{
var actionParts = pathUri.Split(new[] { "://" }, StringSplitOptions.None);
@@ -322,38 +330,32 @@ namespace MediaBrowser.Api
/// </summary>
protected BaseItem GetItemByName(string name, string type, ILibraryManager libraryManager, DtoOptions dtoOptions)
{
- BaseItem item;
-
- if (type.IndexOf("Person", StringComparison.OrdinalIgnoreCase) == 0)
- {
- item = GetPerson(name, libraryManager, dtoOptions);
- }
- else if (type.IndexOf("Artist", StringComparison.OrdinalIgnoreCase) == 0)
+ if (type.Equals("Person", StringComparison.OrdinalIgnoreCase))
{
- item = GetArtist(name, libraryManager, dtoOptions);
+ return GetPerson(name, libraryManager, dtoOptions);
}
- else if (type.IndexOf("Genre", StringComparison.OrdinalIgnoreCase) == 0)
+ else if (type.Equals("Artist", StringComparison.OrdinalIgnoreCase))
{
- item = GetGenre(name, libraryManager, dtoOptions);
+ return GetArtist(name, libraryManager, dtoOptions);
}
- else if (type.IndexOf("MusicGenre", StringComparison.OrdinalIgnoreCase) == 0)
+ else if (type.Equals("Genre", StringComparison.OrdinalIgnoreCase))
{
- item = GetMusicGenre(name, libraryManager, dtoOptions);
+ return GetGenre(name, libraryManager, dtoOptions);
}
- else if (type.IndexOf("Studio", StringComparison.OrdinalIgnoreCase) == 0)
+ else if (type.Equals("MusicGenre", StringComparison.OrdinalIgnoreCase))
{
- item = GetStudio(name, libraryManager, dtoOptions);
+ return GetMusicGenre(name, libraryManager, dtoOptions);
}
- else if (type.IndexOf("Year", StringComparison.OrdinalIgnoreCase) == 0)
+ else if (type.Equals("Studio", StringComparison.OrdinalIgnoreCase))
{
- item = libraryManager.GetYear(int.Parse(name));
+ return GetStudio(name, libraryManager, dtoOptions);
}
- else
+ else if (type.Equals("Year", StringComparison.OrdinalIgnoreCase))
{
- throw new ArgumentException();
+ return libraryManager.GetYear(int.Parse(name));
}
- return item;
+ throw new ArgumentException("Invalid type", nameof(type));
}
}
}
diff --git a/MediaBrowser.Api/FilterService.cs b/MediaBrowser.Api/FilterService.cs
index 9caf07cea..201efe737 100644
--- a/MediaBrowser.Api/FilterService.cs
+++ b/MediaBrowser.Api/FilterService.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
@@ -180,7 +181,7 @@ namespace MediaBrowser.Api
return ToOptimizedResult(filters);
}
- private QueryFiltersLegacy GetFilters(BaseItem[] items)
+ private QueryFiltersLegacy GetFilters(IReadOnlyCollection<BaseItem> items)
{
var result = new QueryFiltersLegacy();
diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs
index 61db7b8d4..10bbc9e5d 100644
--- a/MediaBrowser.Api/Images/ImageService.cs
+++ b/MediaBrowser.Api/Images/ImageService.cs
@@ -18,6 +18,7 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
+using Microsoft.Net.Http.Headers;
namespace MediaBrowser.Api.Images
{
@@ -311,35 +312,35 @@ namespace MediaBrowser.Api.Images
private ImageInfo GetImageInfo(BaseItem item, ItemImageInfo info, int? imageIndex)
{
+ int? width = null;
+ int? height = null;
+ long length = 0;
+
try
{
- int? width = null;
- int? height = null;
- long length = 0;
-
- try
+ if (info.IsLocalFile)
{
- if (info.IsLocalFile)
- {
- var fileInfo = _fileSystem.GetFileInfo(info.Path);
- length = fileInfo.Length;
+ var fileInfo = _fileSystem.GetFileInfo(info.Path);
+ length = fileInfo.Length;
- ImageDimensions size = _imageProcessor.GetImageDimensions(item, info, true);
- width = size.Width;
- height = size.Height;
-
- if (width <= 0 || height <= 0)
- {
- width = null;
- height = null;
- }
+ ImageDimensions size = _imageProcessor.GetImageDimensions(item, info, true);
+ width = size.Width;
+ height = size.Height;
+ if (width <= 0 || height <= 0)
+ {
+ width = null;
+ height = null;
}
}
- catch
- {
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex, "Error getting image information for {Item}", item.Name);
+ }
- }
+ try
+ {
return new ImageInfo
{
Path = info.Path,
@@ -353,7 +354,7 @@ namespace MediaBrowser.Api.Images
}
catch (Exception ex)
{
- Logger.LogError(ex, "Error getting image information for {path}", info.Path);
+ Logger.LogError(ex, "Error getting image information for {Path}", info.Path);
return null;
}
@@ -518,16 +519,16 @@ namespace MediaBrowser.Api.Images
request.AddPlayedIndicator = true;
}
}
+
if (request.PercentPlayed.HasValue)
{
request.UnplayedCount = null;
}
- if (request.UnplayedCount.HasValue)
+
+ if (request.UnplayedCount.HasValue
+ && request.UnplayedCount.Value <= 0)
{
- if (request.UnplayedCount.Value <= 0)
- {
- request.UnplayedCount = null;
- }
+ request.UnplayedCount = null;
}
if (item == null)
@@ -541,7 +542,6 @@ namespace MediaBrowser.Api.Images
}
var imageInfo = GetImageInfo(request, item);
-
if (imageInfo == null)
{
var displayText = item == null ? itemId.ToString() : item.Name;
@@ -549,7 +549,6 @@ namespace MediaBrowser.Api.Images
}
IImageEnhancer[] supportedImageEnhancers;
-
if (_imageProcessor.ImageEnhancers.Length > 0)
{
if (item == null)
@@ -564,13 +563,15 @@ namespace MediaBrowser.Api.Images
supportedImageEnhancers = Array.Empty<IImageEnhancer>();
}
- var cropwhitespace = request.Type == ImageType.Logo ||
- request.Type == ImageType.Art;
-
+ bool cropwhitespace;
if (request.CropWhitespace.HasValue)
{
cropwhitespace = request.CropWhitespace.Value;
}
+ else
+ {
+ cropwhitespace = request.Type == ImageType.Logo || request.Type == ImageType.Art;
+ }
var outputFormats = GetOutputFormats(request);
@@ -634,7 +635,7 @@ namespace MediaBrowser.Api.Images
var imageResult = await _imageProcessor.ProcessImage(options).ConfigureAwait(false);
- headers["Vary"] = "Accept";
+ headers[HeaderNames.Vary] = HeaderNames.Accept;
return await ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions
{
@@ -652,12 +653,10 @@ namespace MediaBrowser.Api.Images
private ImageFormat[] GetOutputFormats(ImageRequest request)
{
- if (!string.IsNullOrWhiteSpace(request.Format))
+ if (!string.IsNullOrWhiteSpace(request.Format)
+ && Enum.TryParse(request.Format, true, out ImageFormat format))
{
- if (Enum.TryParse(request.Format, true, out ImageFormat format))
- {
- return new ImageFormat[] { format };
- }
+ return new ImageFormat[] { format };
}
return GetClientSupportedFormats();
@@ -665,8 +664,19 @@ namespace MediaBrowser.Api.Images
private ImageFormat[] GetClientSupportedFormats()
{
- //logger.LogDebug("Request types: {0}", string.Join(",", Request.AcceptTypes ?? Array.Empty<string>()));
- var supportedFormats = (Request.AcceptTypes ?? Array.Empty<string>()).Select(i => i.Split(';')[0]).ToArray();
+ var supportedFormats = Request.AcceptTypes ?? Array.Empty<string>();
+ if (supportedFormats.Length > 0)
+ {
+ for (int i = 0; i < supportedFormats.Length; i++)
+ {
+ int index = supportedFormats[i].IndexOf(';');
+ if (index != -1)
+ {
+ supportedFormats[i] = supportedFormats[i].Substring(0, index);
+ }
+ }
+ }
+
var acceptParam = Request.QueryString["accept"];
var supportsWebP = SupportsFormat(supportedFormats, acceptParam, "webp", false);
@@ -699,7 +709,7 @@ namespace MediaBrowser.Api.Images
return formats.ToArray();
}
- private bool SupportsFormat(string[] requestAcceptTypes, string acceptParam, string format, bool acceptAll)
+ private bool SupportsFormat(IEnumerable<string> requestAcceptTypes, string acceptParam, string format, bool acceptAll)
{
var mimeType = "image/" + format;
diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs
index d44b07256..8eefbdf2c 100644
--- a/MediaBrowser.Api/Library/LibraryService.cs
+++ b/MediaBrowser.Api/Library/LibraryService.cs
@@ -29,6 +29,7 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
+using Microsoft.Net.Http.Headers;
namespace MediaBrowser.Api.Library
{
@@ -827,7 +828,7 @@ namespace MediaBrowser.Api.Library
var filename = (Path.GetFileName(path) ?? string.Empty).Replace("\"", string.Empty);
if (!string.IsNullOrWhiteSpace(filename))
{
- headers["Content-Disposition"] = "attachment; filename=\"" + filename + "\"";
+ headers[HeaderNames.ContentDisposition] = "attachment; filename=\"" + filename + "\"";
}
return ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions
diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs
index 8fdd726b7..e41ad540a 100644
--- a/MediaBrowser.Api/LiveTv/LiveTvService.cs
+++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs
@@ -23,7 +23,7 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
+using Microsoft.Net.Http.Headers;
namespace MediaBrowser.Api.LiveTv
{
@@ -694,29 +694,36 @@ namespace MediaBrowser.Api.LiveTv
private readonly IHttpClient _httpClient;
private readonly ILibraryManager _libraryManager;
private readonly IDtoService _dtoService;
- private readonly IFileSystem _fileSystem;
private readonly IAuthorizationContext _authContext;
private readonly ISessionContext _sessionContext;
- private readonly IEnvironmentInfo _environment;
- private ICryptoProvider _cryptographyProvider;
- private IStreamHelper _streamHelper;
- private IMediaSourceManager _mediaSourceManager;
-
- public LiveTvService(ICryptoProvider crypto, IMediaSourceManager mediaSourceManager, IStreamHelper streamHelper, ILiveTvManager liveTvManager, IUserManager userManager, IServerConfigurationManager config, IHttpClient httpClient, ILibraryManager libraryManager, IDtoService dtoService, IFileSystem fileSystem, IAuthorizationContext authContext, ISessionContext sessionContext, IEnvironmentInfo environment)
+ private readonly ICryptoProvider _cryptographyProvider;
+ private readonly IStreamHelper _streamHelper;
+ private readonly IMediaSourceManager _mediaSourceManager;
+
+ public LiveTvService(
+ ICryptoProvider crypto,
+ IMediaSourceManager mediaSourceManager,
+ IStreamHelper streamHelper,
+ ILiveTvManager liveTvManager,
+ IUserManager userManager,
+ IServerConfigurationManager config,
+ IHttpClient httpClient,
+ ILibraryManager libraryManager,
+ IDtoService dtoService,
+ IAuthorizationContext authContext,
+ ISessionContext sessionContext)
{
+ _cryptographyProvider = crypto;
+ _mediaSourceManager = mediaSourceManager;
+ _streamHelper = streamHelper;
_liveTvManager = liveTvManager;
_userManager = userManager;
_config = config;
_httpClient = httpClient;
_libraryManager = libraryManager;
_dtoService = dtoService;
- _fileSystem = fileSystem;
_authContext = authContext;
_sessionContext = sessionContext;
- _environment = environment;
- _cryptographyProvider = crypto;
- _streamHelper = streamHelper;
- _mediaSourceManager = mediaSourceManager;
}
public object Get(GetTunerHostTypes request)
@@ -730,7 +737,7 @@ namespace MediaBrowser.Api.LiveTv
var user = request.UserId.Equals(Guid.Empty) ? null : _userManager.GetUserById(request.UserId);
var folders = _liveTvManager.GetRecordingFolders(user);
- var returnArray = _dtoService.GetBaseItemDtos(folders.ToArray(), new DtoOptions(), user);
+ var returnArray = _dtoService.GetBaseItemDtos(folders, new DtoOptions(), user);
var result = new QueryResult<BaseItemDto>
{
@@ -750,11 +757,12 @@ namespace MediaBrowser.Api.LiveTv
throw new FileNotFoundException();
}
- var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
-
- outputHeaders["Content-Type"] = Model.Net.MimeTypes.GetMimeType(path);
+ var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
+ {
+ [HeaderNames.ContentType] = Model.Net.MimeTypes.GetMimeType(path)
+ };
- return new ProgressiveFileCopier(_fileSystem, _streamHelper, path, outputHeaders, Logger, _environment)
+ return new ProgressiveFileCopier(_streamHelper, path, outputHeaders, Logger)
{
AllowEndOfFile = false
};
@@ -772,11 +780,12 @@ namespace MediaBrowser.Api.LiveTv
var directStreamProvider = liveStreamInfo;
- var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
-
- outputHeaders["Content-Type"] = Model.Net.MimeTypes.GetMimeType("file." + request.Container);
+ var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
+ {
+ [HeaderNames.ContentType] = Model.Net.MimeTypes.GetMimeType("file." + request.Container)
+ };
- return new ProgressiveFileCopier(directStreamProvider, _streamHelper, outputHeaders, Logger, _environment)
+ return new ProgressiveFileCopier(directStreamProvider, _streamHelper, outputHeaders, Logger)
{
AllowEndOfFile = false
};
diff --git a/MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs b/MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs
index 8412bf66b..4c608d9a3 100644
--- a/MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs
+++ b/MediaBrowser.Api/LiveTv/ProgressiveFileCopier.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
@@ -5,60 +6,39 @@ using System.Threading.Tasks;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.LiveTv
{
public class ProgressiveFileCopier : IAsyncStreamWriter, IHasHeaders
{
- private readonly IFileSystem _fileSystem;
private readonly ILogger _logger;
private readonly string _path;
private readonly Dictionary<string, string> _outputHeaders;
- const int StreamCopyToBufferSize = 81920;
-
- public long StartPosition { get; set; }
public bool AllowEndOfFile = true;
private readonly IDirectStreamProvider _directStreamProvider;
- private readonly IEnvironmentInfo _environment;
private IStreamHelper _streamHelper;
- public ProgressiveFileCopier(IFileSystem fileSystem, IStreamHelper streamHelper, string path, Dictionary<string, string> outputHeaders, ILogger logger, IEnvironmentInfo environment)
+ public ProgressiveFileCopier(IStreamHelper streamHelper, string path, Dictionary<string, string> outputHeaders, ILogger logger)
{
- _fileSystem = fileSystem;
_path = path;
_outputHeaders = outputHeaders;
_logger = logger;
- _environment = environment;
_streamHelper = streamHelper;
}
- public ProgressiveFileCopier(IDirectStreamProvider directStreamProvider, IStreamHelper streamHelper, Dictionary<string, string> outputHeaders, ILogger logger, IEnvironmentInfo environment)
+ public ProgressiveFileCopier(IDirectStreamProvider directStreamProvider, IStreamHelper streamHelper, Dictionary<string, string> outputHeaders, ILogger logger)
{
_directStreamProvider = directStreamProvider;
_outputHeaders = outputHeaders;
_logger = logger;
- _environment = environment;
_streamHelper = streamHelper;
}
public IDictionary<string, string> Headers => _outputHeaders;
- private Stream GetInputStream(bool allowAsyncFileRead)
- {
- var fileOpenOptions = FileOpenOptions.SequentialScan;
-
- if (allowAsyncFileRead)
- {
- fileOpenOptions |= FileOpenOptions.Asynchronous;
- }
-
- return _fileSystem.GetFileStream(_path, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.ReadWrite, fileOpenOptions);
- }
-
public async Task WriteToAsync(Stream outputStream, CancellationToken cancellationToken)
{
if (_directStreamProvider != null)
@@ -67,28 +47,23 @@ namespace MediaBrowser.Api.LiveTv
return;
}
- var eofCount = 0;
+ var fileOptions = FileOptions.SequentialScan;
// use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039
- var allowAsyncFileRead = true;
-
- using (var inputStream = GetInputStream(allowAsyncFileRead))
+ if (Environment.OSVersion.Platform != PlatformID.Win32NT)
{
- if (StartPosition > 0)
- {
- inputStream.Position = StartPosition;
- }
+ fileOptions |= FileOptions.Asynchronous;
+ }
+ using (var inputStream = new FileStream(_path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, fileOptions))
+ {
var emptyReadLimit = AllowEndOfFile ? 20 : 100;
-
+ var eofCount = 0;
while (eofCount < emptyReadLimit)
{
int bytesRead;
bytesRead = await _streamHelper.CopyToAsync(inputStream, outputStream, cancellationToken).ConfigureAwait(false);
- //var position = fs.Position;
- //_logger.LogDebug("Streamed {0} bytes to position {1} from file {2}", bytesRead, position, path);
-
if (bytesRead == 0)
{
eofCount++;
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs
index a6be071b8..ae259a4f5 100644
--- a/MediaBrowser.Api/Playback/BaseStreamingService.cs
+++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs
@@ -609,12 +609,12 @@ namespace MediaBrowser.Api.Playback
{
foreach (var param in Request.QueryString)
{
- if (char.IsLower(param.Name[0]))
+ if (char.IsLower(param.Key[0]))
{
// This was probably not parsed initially and should be a StreamOptions
// TODO: This should be incorporated either in the lower framework for parsing requests
// or the generated URL should correctly serialize it
- request.StreamOptions[param.Name] = param.Value;
+ request.StreamOptions[param.Key] = param.Value;
}
}
}
@@ -867,7 +867,7 @@ namespace MediaBrowser.Api.Playback
private void ApplyDeviceProfileSettings(StreamState state)
{
- var headers = Request.Headers.ToDictionary();
+ var headers = Request.Headers;
if (!string.IsNullOrWhiteSpace(state.Request.DeviceProfileId))
{
diff --git a/MediaBrowser.Api/Playback/Progressive/AudioService.cs b/MediaBrowser.Api/Playback/Progressive/AudioService.cs
index 48b4e2f24..dfe4b2b8e 100644
--- a/MediaBrowser.Api/Playback/Progressive/AudioService.cs
+++ b/MediaBrowser.Api/Playback/Progressive/AudioService.cs
@@ -3,7 +3,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna;
-using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
@@ -11,7 +10,6 @@ using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
namespace MediaBrowser.Api.Playback.Progressive
{
@@ -46,8 +44,7 @@ namespace MediaBrowser.Api.Playback.Progressive
IDeviceManager deviceManager,
IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer,
- IAuthorizationContext authorizationContext,
- IEnvironmentInfo environmentInfo)
+ IAuthorizationContext authorizationContext)
: base(httpClient,
serverConfig,
userManager,
@@ -60,8 +57,7 @@ namespace MediaBrowser.Api.Playback.Progressive
deviceManager,
mediaSourceManager,
jsonSerializer,
- authorizationContext,
- environmentInfo)
+ authorizationContext)
{
}
diff --git a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs
index 6a98c5e8a..a2c20e38f 100644
--- a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs
+++ b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
@@ -8,15 +7,13 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna;
-using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization;
-using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
+using Microsoft.Net.Http.Headers;
namespace MediaBrowser.Api.Playback.Progressive
{
@@ -25,7 +22,6 @@ namespace MediaBrowser.Api.Playback.Progressive
/// </summary>
public abstract class BaseProgressiveStreamingService : BaseStreamingService
{
- protected readonly IEnvironmentInfo EnvironmentInfo;
protected IHttpClient HttpClient { get; private set; }
public BaseProgressiveStreamingService(
@@ -41,8 +37,7 @@ namespace MediaBrowser.Api.Playback.Progressive
IDeviceManager deviceManager,
IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer,
- IAuthorizationContext authorizationContext,
- IEnvironmentInfo environmentInfo)
+ IAuthorizationContext authorizationContext)
: base(serverConfig,
userManager,
libraryManager,
@@ -56,7 +51,6 @@ namespace MediaBrowser.Api.Playback.Progressive
jsonSerializer,
authorizationContext)
{
- EnvironmentInfo = environmentInfo;
HttpClient = httpClient;
}
@@ -154,9 +148,9 @@ namespace MediaBrowser.Api.Playback.Progressive
var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
// TODO: Don't hardcode this
- outputHeaders["Content-Type"] = MediaBrowser.Model.Net.MimeTypes.GetMimeType("file.ts");
+ outputHeaders[HeaderNames.ContentType] = Model.Net.MimeTypes.GetMimeType("file.ts");
- return new ProgressiveFileCopier(state.DirectStreamProvider, outputHeaders, null, Logger, EnvironmentInfo, CancellationToken.None)
+ return new ProgressiveFileCopier(state.DirectStreamProvider, outputHeaders, null, Logger, CancellationToken.None)
{
AllowEndOfFile = false
};
@@ -196,11 +190,13 @@ namespace MediaBrowser.Api.Playback.Progressive
{
if (state.MediaSource.IsInfiniteStream)
{
- var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
+ var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
+ {
+ [HeaderNames.ContentType] = contentType
+ };
- outputHeaders["Content-Type"] = contentType;
- return new ProgressiveFileCopier(FileSystem, state.MediaPath, outputHeaders, null, Logger, EnvironmentInfo, CancellationToken.None)
+ return new ProgressiveFileCopier(FileSystem, state.MediaPath, outputHeaders, null, Logger, CancellationToken.None)
{
AllowEndOfFile = false
};
@@ -298,16 +294,16 @@ namespace MediaBrowser.Api.Playback.Progressive
if (trySupportSeek)
{
- if (!string.IsNullOrWhiteSpace(Request.QueryString["Range"]))
+ if (!string.IsNullOrWhiteSpace(Request.QueryString[HeaderNames.Range]))
{
- options.RequestHeaders["Range"] = Request.QueryString["Range"];
+ options.RequestHeaders[HeaderNames.Range] = Request.QueryString[HeaderNames.Range];
}
}
var response = await HttpClient.GetResponse(options).ConfigureAwait(false);
if (trySupportSeek)
{
- foreach (var name in new[] { "Content-Range", "Accept-Ranges" })
+ foreach (var name in new[] { HeaderNames.ContentRange, HeaderNames.AcceptRanges })
{
var val = response.Headers[name];
if (!string.IsNullOrWhiteSpace(val))
@@ -318,13 +314,7 @@ namespace MediaBrowser.Api.Playback.Progressive
}
else
{
- responseHeaders["Accept-Ranges"] = "none";
- }
-
- // Seeing cases of -1 here
- if (response.ContentLength.HasValue && response.ContentLength.Value >= 0)
- {
- responseHeaders["Content-Length"] = response.ContentLength.Value.ToString(UsCulture);
+ responseHeaders[HeaderNames.AcceptRanges] = "none";
}
if (isHeadRequest)
@@ -337,7 +327,7 @@ namespace MediaBrowser.Api.Playback.Progressive
var result = new StaticRemoteStreamWriter(response);
- result.Headers["Content-Type"] = response.ContentType;
+ result.Headers[HeaderNames.ContentType] = response.ContentType;
// Add the response headers to the result object
foreach (var header in responseHeaders)
@@ -361,41 +351,15 @@ namespace MediaBrowser.Api.Playback.Progressive
// Use the command line args with a dummy playlist path
var outputPath = state.OutputFilePath;
- responseHeaders["Accept-Ranges"] = "none";
+ responseHeaders[HeaderNames.AcceptRanges] = "none";
var contentType = state.GetMimeType(outputPath);
// TODO: The isHeadRequest is only here because ServiceStack will add Content-Length=0 to the response
- // What we really want to do is hunt that down and remove that
- var contentLength = state.EstimateContentLength || isHeadRequest ? GetEstimatedContentLength(state) : null;
-
- if (contentLength.HasValue)
- {
- responseHeaders["Content-Length"] = contentLength.Value.ToString(UsCulture);
- }
-
// Headers only
if (isHeadRequest)
{
- var streamResult = ResultFactory.GetResult(null, new byte[] { }, contentType, responseHeaders);
-
- var hasHeaders = streamResult as IHasHeaders;
- if (hasHeaders != null)
- {
- if (contentLength.HasValue)
- {
- hasHeaders.Headers["Content-Length"] = contentLength.Value.ToString(CultureInfo.InvariantCulture);
- }
- else
- {
- if (hasHeaders.Headers.ContainsKey("Content-Length"))
- {
- hasHeaders.Headers.Remove("Content-Length");
- }
- }
- }
-
- return streamResult;
+ return ResultFactory.GetResult(null, Array.Empty<byte>(), contentType, responseHeaders);
}
var transcodingLock = ApiEntryPoint.Instance.GetTranscodingLock(outputPath);
@@ -414,9 +378,11 @@ namespace MediaBrowser.Api.Playback.Progressive
state.Dispose();
}
- var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
+ var outputHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
+ {
+ [HeaderNames.ContentType] = contentType
+ };
- outputHeaders["Content-Type"] = contentType;
// Add the response headers to the result object
foreach (var item in responseHeaders)
@@ -424,29 +390,12 @@ namespace MediaBrowser.Api.Playback.Progressive
outputHeaders[item.Key] = item.Value;
}
- return new ProgressiveFileCopier(FileSystem, outputPath, outputHeaders, job, Logger, EnvironmentInfo, CancellationToken.None);
+ return new ProgressiveFileCopier(FileSystem, outputPath, outputHeaders, job, Logger, CancellationToken.None);
}
finally
{
transcodingLock.Release();
}
}
-
- /// <summary>
- /// Gets the length of the estimated content.
- /// </summary>
- /// <param name="state">The state.</param>
- /// <returns>System.Nullable{System.Int64}.</returns>
- private long? GetEstimatedContentLength(StreamState state)
- {
- var totalBitrate = state.TotalOutputBitrate ?? 0;
-
- if (totalBitrate > 0 && state.RunTimeTicks.HasValue)
- {
- return Convert.ToInt64(totalBitrate * TimeSpan.FromTicks(state.RunTimeTicks.Value).TotalSeconds / 8);
- }
-
- return null;
- }
}
}
diff --git a/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs b/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs
index 3dd9de2a1..660912065 100644
--- a/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs
+++ b/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs
@@ -8,6 +8,7 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
+using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace MediaBrowser.Api.Playback.Progressive
{
@@ -27,9 +28,8 @@ namespace MediaBrowser.Api.Playback.Progressive
public bool AllowEndOfFile = true;
private readonly IDirectStreamProvider _directStreamProvider;
- private readonly IEnvironmentInfo _environment;
- public ProgressiveFileCopier(IFileSystem fileSystem, string path, Dictionary<string, string> outputHeaders, TranscodingJob job, ILogger logger, IEnvironmentInfo environment, CancellationToken cancellationToken)
+ public ProgressiveFileCopier(IFileSystem fileSystem, string path, Dictionary<string, string> outputHeaders, TranscodingJob job, ILogger logger, CancellationToken cancellationToken)
{
_fileSystem = fileSystem;
_path = path;
@@ -37,17 +37,15 @@ namespace MediaBrowser.Api.Playback.Progressive
_job = job;
_logger = logger;
_cancellationToken = cancellationToken;
- _environment = environment;
}
- public ProgressiveFileCopier(IDirectStreamProvider directStreamProvider, Dictionary<string, string> outputHeaders, TranscodingJob job, ILogger logger, IEnvironmentInfo environment, CancellationToken cancellationToken)
+ public ProgressiveFileCopier(IDirectStreamProvider directStreamProvider, Dictionary<string, string> outputHeaders, TranscodingJob job, ILogger logger, CancellationToken cancellationToken)
{
_directStreamProvider = directStreamProvider;
_outputHeaders = outputHeaders;
_job = job;
_logger = logger;
_cancellationToken = cancellationToken;
- _environment = environment;
}
public IDictionary<string, string> Headers => _outputHeaders;
@@ -79,7 +77,7 @@ namespace MediaBrowser.Api.Playback.Progressive
var eofCount = 0;
// use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039
- var allowAsyncFileRead = _environment.OperatingSystem != Model.System.OperatingSystem.Windows;
+ var allowAsyncFileRead = OperatingSystem.Id != OperatingSystemId.Windows;
using (var inputStream = GetInputStream(allowAsyncFileRead))
{
diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs
index 7aeb0e9e8..ab19fdc26 100644
--- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs
+++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs
@@ -3,7 +3,6 @@ using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna;
-using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
@@ -11,7 +10,6 @@ using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
namespace MediaBrowser.Api.Playback.Progressive
{
@@ -37,6 +35,7 @@ namespace MediaBrowser.Api.Playback.Progressive
[Route("/Videos/{Id}/stream.mov", "GET")]
[Route("/Videos/{Id}/stream.iso", "GET")]
[Route("/Videos/{Id}/stream.flv", "GET")]
+ [Route("/Videos/{Id}/stream.rm", "GET")]
[Route("/Videos/{Id}/stream", "GET")]
[Route("/Videos/{Id}/stream.ts", "HEAD")]
[Route("/Videos/{Id}/stream.webm", "HEAD")]
@@ -82,8 +81,7 @@ namespace MediaBrowser.Api.Playback.Progressive
IDeviceManager deviceManager,
IMediaSourceManager mediaSourceManager,
IJsonSerializer jsonSerializer,
- IAuthorizationContext authorizationContext,
- IEnvironmentInfo environmentInfo)
+ IAuthorizationContext authorizationContext)
: base(httpClient,
serverConfig,
userManager,
@@ -96,8 +94,7 @@ namespace MediaBrowser.Api.Playback.Progressive
deviceManager,
mediaSourceManager,
jsonSerializer,
- authorizationContext,
- environmentInfo)
+ authorizationContext)
{
}
diff --git a/MediaBrowser.Api/Playback/UniversalAudioService.cs b/MediaBrowser.Api/Playback/UniversalAudioService.cs
index f97e88e98..b3d8bfe59 100644
--- a/MediaBrowser.Api/Playback/UniversalAudioService.cs
+++ b/MediaBrowser.Api/Playback/UniversalAudioService.cs
@@ -18,7 +18,6 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
-using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.Playback
@@ -93,7 +92,6 @@ namespace MediaBrowser.Api.Playback
IAuthorizationContext authorizationContext,
IImageProcessor imageProcessor,
INetworkManager networkManager,
- IEnvironmentInfo environmentInfo,
ILoggerFactory loggerFactory)
{
HttpClient = httpClient;
@@ -112,7 +110,6 @@ namespace MediaBrowser.Api.Playback
AuthorizationContext = authorizationContext;
ImageProcessor = imageProcessor;
NetworkManager = networkManager;
- EnvironmentInfo = environmentInfo;
_loggerFactory = loggerFactory;
_logger = loggerFactory.CreateLogger(nameof(UniversalAudioService));
}
@@ -133,7 +130,6 @@ namespace MediaBrowser.Api.Playback
protected IAuthorizationContext AuthorizationContext { get; private set; }
protected IImageProcessor ImageProcessor { get; private set; }
protected INetworkManager NetworkManager { get; private set; }
- protected IEnvironmentInfo EnvironmentInfo { get; private set; }
private ILoggerFactory _loggerFactory;
private ILogger _logger;
@@ -338,8 +334,7 @@ namespace MediaBrowser.Api.Playback
DeviceManager,
MediaSourceManager,
JsonSerializer,
- AuthorizationContext,
- EnvironmentInfo)
+ AuthorizationContext)
{
Request = Request
};
diff --git a/MediaBrowser.Api/Properties/AssemblyInfo.cs b/MediaBrowser.Api/Properties/AssemblyInfo.cs
index f86723031..35bcbea5c 100644
--- a/MediaBrowser.Api/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.Api/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs b/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs
index 16b036912..b7e94b73f 100644
--- a/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs
+++ b/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs
@@ -197,16 +197,6 @@ namespace MediaBrowser.Api.ScheduledTasks
throw new ResourceNotFoundException("Task not found");
}
- if (string.Equals(task.ScheduledTask.Key, "SystemUpdateTask", StringComparison.OrdinalIgnoreCase))
- {
- // This is a hack for now just to get the update application function to work when auto-update is disabled
- if (!_config.Configuration.EnableAutoUpdate)
- {
- _config.Configuration.EnableAutoUpdate = true;
- _config.SaveConfiguration();
- }
- }
-
TaskManager.Execute(task, new TaskOptions());
}
@@ -238,16 +228,14 @@ namespace MediaBrowser.Api.ScheduledTasks
// https://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Text/ServiceStack.Text/Controller/PathInfo.cs
var id = GetPathValue(1);
- var task = TaskManager.ScheduledTasks.FirstOrDefault(i => string.Equals(i.Id, id));
+ var task = TaskManager.ScheduledTasks.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.Ordinal));
if (task == null)
{
throw new ResourceNotFoundException("Task not found");
}
- var triggerInfos = request;
-
- task.Triggers = triggerInfos.ToArray();
+ task.Triggers = request.ToArray();
}
}
}
diff --git a/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs b/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs
index b0c4b29c1..d24a18743 100644
--- a/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs
+++ b/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs
@@ -58,9 +58,8 @@ namespace MediaBrowser.Api.ScheduledTasks
/// <summary>
/// Gets the data to send.
/// </summary>
- /// <param name="state">The state.</param>
/// <returns>Task{IEnumerable{TaskInfo}}.</returns>
- protected override Task<IEnumerable<TaskInfo>> GetDataToSend(WebSocketListenerState state, CancellationToken cancellationToken)
+ protected override Task<IEnumerable<TaskInfo>> GetDataToSend()
{
return Task.FromResult(TaskManager.ScheduledTasks
.OrderBy(i => i.Name)
diff --git a/MediaBrowser.Api/Session/SessionInfoWebSocketListener.cs b/MediaBrowser.Api/Session/SessionInfoWebSocketListener.cs
index beb2fb11d..b79e9f84b 100644
--- a/MediaBrowser.Api/Session/SessionInfoWebSocketListener.cs
+++ b/MediaBrowser.Api/Session/SessionInfoWebSocketListener.cs
@@ -79,9 +79,8 @@ namespace MediaBrowser.Api.Session
/// <summary>
/// Gets the data to send.
/// </summary>
- /// <param name="state">The state.</param>
/// <returns>Task{SystemInfo}.</returns>
- protected override Task<IEnumerable<SessionInfo>> GetDataToSend(WebSocketListenerState state, CancellationToken cancellationToken)
+ protected override Task<IEnumerable<SessionInfo>> GetDataToSend()
{
return Task.FromResult(_sessionManager.Sessions);
}
diff --git a/MediaBrowser.Api/System/ActivityLogWebSocketListener.cs b/MediaBrowser.Api/System/ActivityLogWebSocketListener.cs
index 43f3c5a22..a036619b8 100644
--- a/MediaBrowser.Api/System/ActivityLogWebSocketListener.cs
+++ b/MediaBrowser.Api/System/ActivityLogWebSocketListener.cs
@@ -38,9 +38,8 @@ namespace MediaBrowser.Api.System
/// <summary>
/// Gets the data to send.
/// </summary>
- /// <param name="state">The state.</param>
/// <returns>Task{SystemInfo}.</returns>
- protected override Task<List<ActivityLogEntry>> GetDataToSend(WebSocketListenerState state, CancellationToken CancellationToken)
+ protected override Task<List<ActivityLogEntry>> GetDataToSend()
{
return Task.FromResult(new List<ActivityLogEntry>());
}
diff --git a/MediaBrowser.Api/UserLibrary/ArtistsService.cs b/MediaBrowser.Api/UserLibrary/ArtistsService.cs
index 651da1939..a30f8adfe 100644
--- a/MediaBrowser.Api/UserLibrary/ArtistsService.cs
+++ b/MediaBrowser.Api/UserLibrary/ArtistsService.cs
@@ -87,11 +87,6 @@ namespace MediaBrowser.Api.UserLibrary
/// <returns>System.Object.</returns>
public object Get(GetArtists request)
{
- if (string.IsNullOrWhiteSpace(request.IncludeItemTypes))
- {
- //request.IncludeItemTypes = "Audio,MusicVideo";
- }
-
return GetResultSlim(request);
}
@@ -102,17 +97,12 @@ namespace MediaBrowser.Api.UserLibrary
/// <returns>System.Object.</returns>
public object Get(GetAlbumArtists request)
{
- if (string.IsNullOrWhiteSpace(request.IncludeItemTypes))
- {
- //request.IncludeItemTypes = "Audio,MusicVideo";
- }
-
var result = GetResultSlim(request);
return ToOptimizedResult(result);
}
- protected override QueryResult<Tuple<BaseItem, ItemCounts>> GetItems(GetItemsByName request, InternalItemsQuery query)
+ protected override QueryResult<(BaseItem, ItemCounts)> GetItems(GetItemsByName request, InternalItemsQuery query)
{
if (request is GetAlbumArtists)
{
diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
index 471b41127..e3c9ae58e 100644
--- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
+++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
@@ -209,9 +209,9 @@ namespace MediaBrowser.Api.UserLibrary
};
}
- protected virtual QueryResult<Tuple<BaseItem, ItemCounts>> GetItems(GetItemsByName request, InternalItemsQuery query)
+ protected virtual QueryResult<(BaseItem, ItemCounts)> GetItems(GetItemsByName request, InternalItemsQuery query)
{
- return new QueryResult<Tuple<BaseItem, ItemCounts>>();
+ return new QueryResult<(BaseItem, ItemCounts)>();
}
private void SetItemCounts(BaseItemDto dto, ItemCounts counts)
diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs
index 7af50c329..a26f59573 100644
--- a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs
+++ b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs
@@ -396,14 +396,12 @@ namespace MediaBrowser.Api.UserLibrary
public VideoType[] GetVideoTypes()
{
- var val = VideoTypes;
-
- if (string.IsNullOrEmpty(val))
+ if (string.IsNullOrEmpty(VideoTypes))
{
- return new VideoType[] { };
+ return Array.Empty<VideoType>();
}
- return val.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(v => (VideoType)Enum.Parse(typeof(VideoType), v, true)).ToArray();
+ return VideoTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(v => (VideoType)Enum.Parse(typeof(VideoType), v, true)).ToArray();
}
/// <summary>
diff --git a/MediaBrowser.Api/UserLibrary/GenresService.cs b/MediaBrowser.Api/UserLibrary/GenresService.cs
index baf570d50..0c04d02dd 100644
--- a/MediaBrowser.Api/UserLibrary/GenresService.cs
+++ b/MediaBrowser.Api/UserLibrary/GenresService.cs
@@ -92,7 +92,7 @@ namespace MediaBrowser.Api.UserLibrary
return ToOptimizedResult(result);
}
- protected override QueryResult<Tuple<BaseItem, ItemCounts>> GetItems(GetItemsByName request, InternalItemsQuery query)
+ protected override QueryResult<(BaseItem, ItemCounts)> GetItems(GetItemsByName request, InternalItemsQuery query)
{
var viewType = GetParentItemViewType(request);
diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs
index 3ae7da007..3c7ad1d0a 100644
--- a/MediaBrowser.Api/UserLibrary/ItemsService.cs
+++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Globalization;
using System.Linq;
using MediaBrowser.Controller.Dto;
@@ -12,6 +13,7 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services;
+using Microsoft.Extensions.Logging;
namespace MediaBrowser.Api.UserLibrary
{
@@ -90,7 +92,7 @@ namespace MediaBrowser.Api.UserLibrary
var options = GetDtoOptions(_authContext, request);
- var ancestorIds = new List<Guid>();
+ var ancestorIds = Array.Empty<Guid>();
var excludeFolderIds = user.Configuration.LatestItemsExcludes;
if (parentIdGuid.Equals(Guid.Empty) && excludeFolderIds.Length > 0)
@@ -99,12 +101,12 @@ namespace MediaBrowser.Api.UserLibrary
.Where(i => i is Folder)
.Where(i => !excludeFolderIds.Contains(i.Id.ToString("N")))
.Select(i => i.Id)
- .ToList();
+ .ToArray();
}
var itemsResult = _libraryManager.GetItemsResult(new InternalItemsQuery(user)
{
- OrderBy = new[] { ItemSortBy.DatePlayed }.Select(i => new ValueTuple<string, SortOrder>(i, SortOrder.Descending)).ToArray(),
+ OrderBy = new[] { (ItemSortBy.DatePlayed, SortOrder.Descending) },
IsResumable = true,
StartIndex = request.StartIndex,
Limit = request.Limit,
@@ -115,7 +117,7 @@ namespace MediaBrowser.Api.UserLibrary
IsVirtualItem = false,
CollapseBoxSetItems = false,
EnableTotalRecordCount = request.EnableTotalRecordCount,
- AncestorIds = ancestorIds.ToArray(),
+ AncestorIds = ancestorIds,
IncludeItemTypes = request.GetIncludeItemTypes(),
ExcludeItemTypes = request.GetExcludeItemTypes(),
SearchTerm = request.SearchTerm
@@ -155,7 +157,7 @@ namespace MediaBrowser.Api.UserLibrary
/// <param name="request">The request.</param>
private QueryResult<BaseItemDto> GetItems(GetItems request)
{
- var user = !request.UserId.Equals(Guid.Empty) ? _userManager.GetUserById(request.UserId) : null;
+ var user = request.UserId == Guid.Empty ? null : _userManager.GetUserById(request.UserId);
var dtoOptions = GetDtoOptions(_authContext, request);
@@ -190,57 +192,54 @@ namespace MediaBrowser.Api.UserLibrary
/// </summary>
private QueryResult<BaseItem> GetQueryResult(GetItems request, DtoOptions dtoOptions, User user)
{
- if (string.Equals(request.IncludeItemTypes, "Playlist", StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(request.IncludeItemTypes, "Playlist", StringComparison.OrdinalIgnoreCase)
+ || string.Equals(request.IncludeItemTypes, "BoxSet", StringComparison.OrdinalIgnoreCase))
{
request.ParentId = null;
}
- else if (string.Equals(request.IncludeItemTypes, "BoxSet", StringComparison.OrdinalIgnoreCase))
+
+ BaseItem item = null;
+
+ if (!string.IsNullOrEmpty(request.ParentId))
{
- request.ParentId = null;
+ item = _libraryManager.GetItemById(request.ParentId);
}
- var item = string.IsNullOrEmpty(request.ParentId) ?
- null :
- _libraryManager.GetItemById(request.ParentId);
-
if (item == null)
{
- item = string.IsNullOrEmpty(request.ParentId) ?
- user == null ? _libraryManager.RootFolder : _libraryManager.GetUserRootFolder() :
- _libraryManager.GetItemById(request.ParentId);
+ item = _libraryManager.GetUserRootFolder();
}
- // Default list type = children
-
- var folder = item as Folder;
+ Folder folder = item as Folder;
if (folder == null)
{
- folder = user == null ? _libraryManager.RootFolder : _libraryManager.GetUserRootFolder();
+ folder = _libraryManager.GetUserRootFolder();
}
var hasCollectionType = folder as IHasCollectionType;
- var isPlaylistQuery = (hasCollectionType != null && string.Equals(hasCollectionType.CollectionType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase));
-
- if (isPlaylistQuery)
+ if (hasCollectionType != null
+ && string.Equals(hasCollectionType.CollectionType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase))
{
request.Recursive = true;
request.IncludeItemTypes = "Playlist";
}
- if (request.Recursive || !string.IsNullOrEmpty(request.Ids) || user == null)
+ if (!user.Policy.EnableAllFolders && !user.Policy.EnabledFolders.Any(i => new Guid(i) == item.Id))
{
- return folder.GetItems(GetItemsQuery(request, dtoOptions, user));
+ Logger.LogWarning("{UserName} is not permitted to access Library {ItemName}.", user.Name, item.Name);
+ return new QueryResult<BaseItem>
+ {
+ Items = Array.Empty<BaseItem>(),
+ TotalRecordCount = 0
+ };
}
- var userRoot = item as UserRootFolder;
-
- if (userRoot == null)
+ if (request.Recursive || !string.IsNullOrEmpty(request.Ids) || !(item is UserRootFolder))
{
return folder.GetItems(GetItemsQuery(request, dtoOptions, user));
}
var itemsArray = folder.GetChildren(user, true).ToArray();
-
return new QueryResult<BaseItem>
{
Items = itemsArray,
diff --git a/MediaBrowser.Api/UserLibrary/MusicGenresService.cs b/MediaBrowser.Api/UserLibrary/MusicGenresService.cs
index 4fcc3aa53..94f5262b0 100644
--- a/MediaBrowser.Api/UserLibrary/MusicGenresService.cs
+++ b/MediaBrowser.Api/UserLibrary/MusicGenresService.cs
@@ -83,7 +83,7 @@ namespace MediaBrowser.Api.UserLibrary
return ToOptimizedResult(result);
}
- protected override QueryResult<Tuple<BaseItem, ItemCounts>> GetItems(GetItemsByName request, InternalItemsQuery query)
+ protected override QueryResult<(BaseItem, ItemCounts)> GetItems(GetItemsByName request, InternalItemsQuery query)
{
return LibraryManager.GetMusicGenres(query);
}
diff --git a/MediaBrowser.Api/UserLibrary/PersonsService.cs b/MediaBrowser.Api/UserLibrary/PersonsService.cs
index d317f9f38..c26457778 100644
--- a/MediaBrowser.Api/UserLibrary/PersonsService.cs
+++ b/MediaBrowser.Api/UserLibrary/PersonsService.cs
@@ -101,7 +101,7 @@ namespace MediaBrowser.Api.UserLibrary
throw new NotImplementedException();
}
- protected override QueryResult<Tuple<BaseItem, ItemCounts>> GetItems(GetItemsByName request, InternalItemsQuery query)
+ protected override QueryResult<(BaseItem, ItemCounts)> GetItems(GetItemsByName request, InternalItemsQuery query)
{
var items = LibraryManager.GetPeopleItems(new InternalPeopleQuery
{
@@ -109,10 +109,10 @@ namespace MediaBrowser.Api.UserLibrary
NameContains = query.NameContains ?? query.SearchTerm
});
- return new QueryResult<Tuple<BaseItem, ItemCounts>>
+ return new QueryResult<(BaseItem, ItemCounts)>
{
TotalRecordCount = items.Count,
- Items = items.Take(query.Limit ?? int.MaxValue).Select(i => new Tuple<BaseItem, ItemCounts>(i, new ItemCounts())).ToArray()
+ Items = items.Take(query.Limit ?? int.MaxValue).Select(i => (i as BaseItem, new ItemCounts())).ToArray()
};
}
diff --git a/MediaBrowser.Api/UserLibrary/StudiosService.cs b/MediaBrowser.Api/UserLibrary/StudiosService.cs
index 4e2483a56..890acc931 100644
--- a/MediaBrowser.Api/UserLibrary/StudiosService.cs
+++ b/MediaBrowser.Api/UserLibrary/StudiosService.cs
@@ -91,7 +91,7 @@ namespace MediaBrowser.Api.UserLibrary
return ToOptimizedResult(result);
}
- protected override QueryResult<Tuple<BaseItem, ItemCounts>> GetItems(GetItemsByName request, InternalItemsQuery query)
+ protected override QueryResult<(BaseItem, ItemCounts)> GetItems(GetItemsByName request, InternalItemsQuery query)
{
return LibraryManager.GetStudios(query);
}
diff --git a/MediaBrowser.Common/Configuration/IApplicationPaths.cs b/MediaBrowser.Common/Configuration/IApplicationPaths.cs
index 27092c0e1..fd11bf904 100644
--- a/MediaBrowser.Common/Configuration/IApplicationPaths.cs
+++ b/MediaBrowser.Common/Configuration/IApplicationPaths.cs
@@ -12,6 +12,12 @@ namespace MediaBrowser.Common.Configuration
string ProgramDataPath { get; }
/// <summary>
+ /// Gets the path to the web UI resources folder
+ /// </summary>
+ /// <value>The web UI resources path.</value>
+ string WebPath { get; }
+
+ /// <summary>
/// Gets the path to the program system folder
/// </summary>
/// <value>The program data path.</value>
@@ -42,12 +48,6 @@ namespace MediaBrowser.Common.Configuration
string PluginConfigurationsPath { get; }
/// <summary>
- /// Gets the path to where temporary update files will be stored
- /// </summary>
- /// <value>The plugin configurations path.</value>
- string TempUpdatePath { get; }
-
- /// <summary>
/// Gets the path to the log directory
/// </summary>
/// <value>The log directory path.</value>
diff --git a/MediaBrowser.Common/Extensions/BaseExtensions.cs b/MediaBrowser.Common/Extensions/BaseExtensions.cs
index db0514bb1..40c16b957 100644
--- a/MediaBrowser.Common/Extensions/BaseExtensions.cs
+++ b/MediaBrowser.Common/Extensions/BaseExtensions.cs
@@ -1,6 +1,7 @@
using System;
+using System.Text;
using System.Text.RegularExpressions;
-using MediaBrowser.Model.Cryptography;
+using System.Security.Cryptography;
namespace MediaBrowser.Common.Extensions
{
@@ -9,8 +10,6 @@ namespace MediaBrowser.Common.Extensions
/// </summary>
public static class BaseExtensions
{
- public static ICryptoProvider CryptographyProvider { get; set; }
-
/// <summary>
/// Strips the HTML.
/// </summary>
@@ -31,7 +30,10 @@ namespace MediaBrowser.Common.Extensions
/// <returns>Guid.</returns>
public static Guid GetMD5(this string str)
{
- return CryptographyProvider.GetMD5(str);
+ using (var provider = MD5.Create())
+ {
+ return new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(str)));
+ }
}
}
}
diff --git a/MediaBrowser.Common/Extensions/CollectionExtensions.cs b/MediaBrowser.Common/Extensions/CollectionExtensions.cs
new file mode 100644
index 000000000..f7c0e3cf0
--- /dev/null
+++ b/MediaBrowser.Common/Extensions/CollectionExtensions.cs
@@ -0,0 +1,14 @@
+using System.Collections.Generic;
+
+namespace MediaBrowser.Common.Extensions
+{
+ // The MS CollectionExtensions are only available in netcoreapp
+ public static class CollectionExtensions
+ {
+ public static TValue GetValueOrDefault<TKey, TValue> (this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)
+ {
+ dictionary.TryGetValue(key, out var ret);
+ return ret;
+ }
+ }
+}
diff --git a/MediaBrowser.Common/IApplicationHost.cs b/MediaBrowser.Common/IApplicationHost.cs
index 6891152ee..2925a3efd 100644
--- a/MediaBrowser.Common/IApplicationHost.cs
+++ b/MediaBrowser.Common/IApplicationHost.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Events;
@@ -73,10 +72,10 @@ namespace MediaBrowser.Common
string ApplicationUserAgent { get; }
/// <summary>
- /// Gets or sets a value indicating whether this instance can self update.
+ /// Gets the email address for use within a comment section of a user agent field.
+ /// Presently used to provide contact information to MusicBrainz service.
/// </summary>
- /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
- bool CanSelfUpdate { get; }
+ string ApplicationUserAgentAddress { get; }
/// <summary>
/// Gets the exports.
@@ -87,12 +86,6 @@ namespace MediaBrowser.Common
IEnumerable<T> GetExports<T>(bool manageLifetime = true);
/// <summary>
- /// Updates the application.
- /// </summary>
- /// <returns>Task.</returns>
- Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress);
-
- /// <summary>
/// Resolves this instance.
/// </summary>
/// <typeparam name="T"></typeparam>
@@ -119,7 +112,7 @@ namespace MediaBrowser.Common
/// <summary>
/// Inits this instance.
/// </summary>
- Task Init(IServiceCollection serviceCollection);
+ Task InitAsync(IServiceCollection serviceCollection);
/// <summary>
/// Creates the instance.
diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj
index 715f4fccd..05b48a2a1 100644
--- a/MediaBrowser.Common/MediaBrowser.Common.csproj
+++ b/MediaBrowser.Common/MediaBrowser.Common.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Jellyfin Contributors</Authors>
@@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
+ <PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
diff --git a/MediaBrowser.Common/Net/HttpRequestOptions.cs b/MediaBrowser.Common/Net/HttpRequestOptions.cs
index dadac5e03..bea178517 100644
--- a/MediaBrowser.Common/Net/HttpRequestOptions.cs
+++ b/MediaBrowser.Common/Net/HttpRequestOptions.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
+using Microsoft.Net.Http.Headers;
namespace MediaBrowser.Common.Net
{
@@ -24,8 +25,8 @@ namespace MediaBrowser.Common.Net
/// <value>The accept header.</value>
public string AcceptHeader
{
- get => GetHeaderValue("Accept");
- set => RequestHeaders["Accept"] = value;
+ get => GetHeaderValue(HeaderNames.Accept);
+ set => RequestHeaders[HeaderNames.Accept] = value;
}
/// <summary>
/// Gets or sets the cancellation token.
@@ -45,8 +46,8 @@ namespace MediaBrowser.Common.Net
/// <value>The user agent.</value>
public string UserAgent
{
- get => GetHeaderValue("User-Agent");
- set => RequestHeaders["User-Agent"] = value;
+ get => GetHeaderValue(HeaderNames.UserAgent);
+ set => RequestHeaders[HeaderNames.UserAgent] = value;
}
/// <summary>
diff --git a/MediaBrowser.Common/Net/INetworkManager.cs b/MediaBrowser.Common/Net/INetworkManager.cs
index 72fb6e2b8..34c6f5866 100644
--- a/MediaBrowser.Common/Net/INetworkManager.cs
+++ b/MediaBrowser.Common/Net/INetworkManager.cs
@@ -53,7 +53,7 @@ namespace MediaBrowser.Common.Net
/// <returns><c>true</c> if [is in local network] [the specified endpoint]; otherwise, <c>false</c>.</returns>
bool IsInLocalNetwork(string endpoint);
- IpAddressInfo[] GetLocalIpAddresses();
+ IpAddressInfo[] GetLocalIpAddresses(bool ignoreVirtualInterface);
IpAddressInfo ParseIpAddress(string ipAddress);
@@ -62,5 +62,8 @@ namespace MediaBrowser.Common.Net
Task<IpAddressInfo[]> GetHostAddressesAsync(string host);
bool IsAddressInSubnets(string addressString, string[] subnets);
+
+ bool IsInSameSubnet(IpAddressInfo address1, IpAddressInfo address2, IpAddressInfo subnetMask);
+ IpAddressInfo GetLocalIpSubnetMask(IpAddressInfo address);
}
}
diff --git a/MediaBrowser.Common/Properties/AssemblyInfo.cs b/MediaBrowser.Common/Properties/AssemblyInfo.cs
index 1a8fdb618..538e89fd1 100644
--- a/MediaBrowser.Common/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.Common/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/MediaBrowser.Common/Providers/SubtitleConfigurationFactory.cs b/MediaBrowser.Common/Providers/SubtitleConfigurationFactory.cs
new file mode 100644
index 000000000..09d974db6
--- /dev/null
+++ b/MediaBrowser.Common/Providers/SubtitleConfigurationFactory.cs
@@ -0,0 +1,18 @@
+using System.Collections.Generic;
+using MediaBrowser.Common.Configuration;
+using MediaBrowser.Model.Providers;
+
+namespace MediaBrowser.Common.Providers
+{
+ public class SubtitleConfigurationFactory : IConfigurationFactory
+ {
+ public IEnumerable<ConfigurationStore> GetConfigurations()
+ {
+ yield return new ConfigurationStore()
+ {
+ Key = "subtitles",
+ ConfigurationType = typeof(SubtitleOptions)
+ };
+ }
+ }
+}
diff --git a/MediaBrowser.Common/System/OperatingSystem.cs b/MediaBrowser.Common/System/OperatingSystem.cs
new file mode 100644
index 000000000..640821d4d
--- /dev/null
+++ b/MediaBrowser.Common/System/OperatingSystem.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Threading;
+using MediaBrowser.Model.System;
+
+namespace MediaBrowser.Common.System
+{
+ public static class OperatingSystem
+ {
+ // We can't use Interlocked.CompareExchange for enums
+ private static int _id = int.MaxValue;
+
+ public static OperatingSystemId Id
+ {
+ get
+ {
+ if (_id == int.MaxValue)
+ {
+ Interlocked.CompareExchange(ref _id, (int)GetId(), int.MaxValue);
+ }
+
+ return (OperatingSystemId)_id;
+ }
+ }
+
+ public static string Name
+ {
+ get
+ {
+ switch (Id)
+ {
+ case OperatingSystemId.BSD: return "BSD";
+ case OperatingSystemId.Linux: return "Linux";
+ case OperatingSystemId.Darwin: return "macOS";
+ case OperatingSystemId.Windows: return "Windows";
+ default: throw new Exception($"Unknown OS {Id}");
+ }
+ }
+ }
+
+ private static OperatingSystemId GetId()
+ {
+ switch (Environment.OSVersion.Platform)
+ {
+ // On .NET Core `MacOSX` got replaced by `Unix`, this case should never be hit.
+ case PlatformID.MacOSX:
+ return OperatingSystemId.Darwin;
+ case PlatformID.Win32NT:
+ return OperatingSystemId.Windows;
+ case PlatformID.Unix:
+ default:
+ {
+ string osDescription = RuntimeInformation.OSDescription;
+ if (osDescription.IndexOf("linux", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ return OperatingSystemId.Linux;
+ }
+ else if (osDescription.IndexOf("darwin", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ return OperatingSystemId.Darwin;
+ }
+ else if (osDescription.IndexOf("bsd", StringComparison.OrdinalIgnoreCase) != -1)
+ {
+ return OperatingSystemId.BSD;
+ }
+
+ throw new Exception($"Can't resolve OS with description: '{osDescription}'");
+ }
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Controller/Dlna/IDlnaManager.cs b/MediaBrowser.Controller/Dlna/IDlnaManager.cs
index a6ee7c505..41a7686a3 100644
--- a/MediaBrowser.Controller/Dlna/IDlnaManager.cs
+++ b/MediaBrowser.Controller/Dlna/IDlnaManager.cs
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Model.Dlna;
+using Microsoft.AspNetCore.Http;
namespace MediaBrowser.Controller.Dlna
{
@@ -17,7 +18,7 @@ namespace MediaBrowser.Controller.Dlna
/// </summary>
/// <param name="headers">The headers.</param>
/// <returns>DeviceProfile.</returns>
- DeviceProfile GetProfile(IDictionary<string, string> headers);
+ DeviceProfile GetProfile(IHeaderDictionary headers);
/// <summary>
/// Gets the default profile.
@@ -64,7 +65,7 @@ namespace MediaBrowser.Controller.Dlna
/// <param name="serverUuId">The server uu identifier.</param>
/// <param name="serverAddress">The server address.</param>
/// <returns>System.String.</returns>
- string GetServerDescriptionXml(IDictionary<string, string> headers, string serverUuId, string serverAddress);
+ string GetServerDescriptionXml(IHeaderDictionary headers, string serverUuId, string serverAddress);
/// <summary>
/// Gets the icon.
diff --git a/MediaBrowser.Controller/Dto/DtoOptions.cs b/MediaBrowser.Controller/Dto/DtoOptions.cs
index aa99f6b58..cdaf95f5c 100644
--- a/MediaBrowser.Controller/Dto/DtoOptions.cs
+++ b/MediaBrowser.Controller/Dto/DtoOptions.cs
@@ -36,9 +36,7 @@ namespace MediaBrowser.Controller.Dto
.ToArray();
public bool ContainsField(ItemFields field)
- {
- return AllItemFields.Contains(field);
- }
+ => Fields.Contains(field);
public DtoOptions(bool allFields)
{
@@ -47,15 +45,7 @@ namespace MediaBrowser.Controller.Dto
EnableUserData = true;
AddCurrentProgram = true;
- if (allFields)
- {
- Fields = AllItemFields;
- }
- else
- {
- Fields = new ItemFields[] { };
- }
-
+ Fields = allFields ? AllItemFields : Array.Empty<ItemFields>();
ImageTypes = AllImageTypes;
}
diff --git a/MediaBrowser.Controller/Dto/IDtoService.cs b/MediaBrowser.Controller/Dto/IDtoService.cs
index df5ec5dd0..4b6fd58fe 100644
--- a/MediaBrowser.Controller/Dto/IDtoService.cs
+++ b/MediaBrowser.Controller/Dto/IDtoService.cs
@@ -57,9 +57,7 @@ namespace MediaBrowser.Controller.Dto
/// <param name="options">The options.</param>
/// <param name="user">The user.</param>
/// <param name="owner">The owner.</param>
- BaseItemDto[] GetBaseItemDtos(BaseItem[] items, DtoOptions options, User user = null, BaseItem owner = null);
-
- BaseItemDto[] GetBaseItemDtos(List<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null);
+ BaseItemDto[] GetBaseItemDtos(IReadOnlyList<BaseItem> items, DtoOptions options, User user = null, BaseItem owner = null);
/// <summary>
/// Gets the item by name dto.
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index 72c4e3573..e20641c99 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -36,10 +36,26 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public abstract class BaseItem : IHasProviderIds, IHasLookupInfo<ItemLookupInfo>
{
- protected static MetadataFields[] EmptyMetadataFieldsArray = Array.Empty<MetadataFields>();
- protected static MediaUrl[] EmptyMediaUrlArray = Array.Empty<MediaUrl>();
- protected static ItemImageInfo[] EmptyItemImageInfoArray = Array.Empty<ItemImageInfo>();
- public static readonly LinkedChild[] EmptyLinkedChildArray = Array.Empty<LinkedChild>();
+ /// <summary>
+ /// The supported image extensions
+ /// </summary>
+ public static readonly string[] SupportedImageExtensions
+ = new [] { ".png", ".jpg", ".jpeg", ".tbn", ".gif" };
+
+ private static readonly List<string> _supportedExtensions = new List<string>(SupportedImageExtensions)
+ {
+ ".nfo",
+ ".xml",
+ ".srt",
+ ".vtt",
+ ".sub",
+ ".idx",
+ ".txt",
+ ".edl",
+ ".bif",
+ ".smi",
+ ".ttml"
+ };
protected BaseItem()
{
@@ -49,8 +65,8 @@ namespace MediaBrowser.Controller.Entities
Genres = Array.Empty<string>();
Studios = Array.Empty<string>();
ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
- LockedFields = EmptyMetadataFieldsArray;
- ImageInfos = EmptyItemImageInfoArray;
+ LockedFields = Array.Empty<MetadataFields>();
+ ImageInfos = Array.Empty<ItemImageInfo>();
ProductionLocations = Array.Empty<string>();
RemoteTrailers = Array.Empty<MediaUrl>();
ExtraIds = Array.Empty<Guid>();
@@ -60,11 +76,6 @@ namespace MediaBrowser.Controller.Entities
public static char SlugChar = '-';
/// <summary>
- /// The supported image extensions
- /// </summary>
- public static readonly string[] SupportedImageExtensions = { ".png", ".jpg", ".jpeg", ".tbn", ".gif" };
-
- /// <summary>
/// The trailer folder name
/// </summary>
public static string TrailerFolderName = "trailers";
@@ -1283,6 +1294,35 @@ namespace MediaBrowser.Controller.Entities
}).OrderBy(i => i.Path).ToArray();
}
+ protected virtual BaseItem[] LoadExtras(List<FileSystemMetadata> fileSystemChildren, IDirectoryService directoryService)
+ {
+ var files = fileSystemChildren.Where(i => i.IsDirectory)
+ .SelectMany(i => FileSystem.GetFiles(i.FullName));
+
+ return LibraryManager.ResolvePaths(files, directoryService, null, new LibraryOptions())
+ .OfType<Video>()
+ .Select(item =>
+ {
+ // Try to retrieve it from the db. If we don't find it, use the resolved version
+ var dbItem = LibraryManager.GetItemById(item.Id) as Video;
+
+ if (dbItem != null)
+ {
+ item = dbItem;
+ }
+ else
+ {
+ // item is new
+ item.ExtraType = MediaBrowser.Model.Entities.ExtraType.Clip;
+ }
+
+ return item;
+
+ // Sort them so that the list can be easily compared for changes
+ }).OrderBy(i => i.Path).ToArray();
+ }
+
+
public Task RefreshMetadata(CancellationToken cancellationToken)
{
return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem)), cancellationToken);
@@ -1371,6 +1411,8 @@ namespace MediaBrowser.Controller.Entities
var themeVideosChanged = false;
+ var extrasChanged = false;
+
var localTrailersChanged = false;
if (IsFileProtocol && SupportsOwnedItems)
@@ -1382,6 +1424,8 @@ namespace MediaBrowser.Controller.Entities
themeSongsChanged = await RefreshThemeSongs(this, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
themeVideosChanged = await RefreshThemeVideos(this, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
+
+ extrasChanged = await RefreshExtras(this, options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
}
}
@@ -1392,7 +1436,7 @@ namespace MediaBrowser.Controller.Entities
}
}
- return themeSongsChanged || themeVideosChanged || localTrailersChanged;
+ return themeSongsChanged || themeVideosChanged || extrasChanged || localTrailersChanged;
}
protected virtual FileSystemMetadata[] GetFileSystemChildren(IDirectoryService directoryService)
@@ -1435,6 +1479,31 @@ namespace MediaBrowser.Controller.Entities
return itemsChanged;
}
+ private async Task<bool> RefreshExtras(BaseItem item, MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
+ {
+ var newExtras = LoadExtras(fileSystemChildren, options.DirectoryService).Concat(LoadThemeVideos(fileSystemChildren, options.DirectoryService)).Concat(LoadThemeSongs(fileSystemChildren, options.DirectoryService));
+
+ var newExtraIds = newExtras.Select(i => i.Id).ToArray();
+
+ var extrasChanged = !item.ExtraIds.SequenceEqual(newExtraIds);
+
+ if (extrasChanged)
+ {
+ var ownerId = item.Id;
+
+ var tasks = newExtras.Select(i =>
+ {
+ return RefreshMetadataForOwnedItem(i, true, new MetadataRefreshOptions(options), cancellationToken);
+ });
+
+ await Task.WhenAll(tasks).ConfigureAwait(false);
+
+ item.ExtraIds = newExtraIds;
+ }
+
+ return extrasChanged;
+ }
+
private async Task<bool> RefreshThemeVideos(BaseItem item, MetadataRefreshOptions options, IEnumerable<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
{
var newThemeVideos = LoadThemeVideos(fileSystemChildren, options.DirectoryService);
@@ -2394,10 +2463,8 @@ namespace MediaBrowser.Controller.Entities
}
var filename = System.IO.Path.GetFileNameWithoutExtension(Path);
- var extensions = new List<string> { ".nfo", ".xml", ".srt", ".vtt", ".sub", ".idx", ".txt", ".edl", ".bif", ".smi", ".ttml" };
- extensions.AddRange(SupportedImageExtensions);
- return FileSystem.GetFiles(System.IO.Path.GetDirectoryName(Path), extensions.ToArray(), false, false)
+ return FileSystem.GetFiles(System.IO.Path.GetDirectoryName(Path), _supportedExtensions, false, false)
.Where(i => System.IO.Path.GetFileNameWithoutExtension(i.FullName).StartsWith(filename, StringComparison.OrdinalIgnoreCase))
.ToList();
}
@@ -2775,17 +2842,17 @@ namespace MediaBrowser.Controller.Entities
public IEnumerable<BaseItem> GetExtras()
{
- return ThemeVideoIds.Select(LibraryManager.GetItemById).Where(i => i.ExtraType.Equals(Model.Entities.ExtraType.ThemeVideo)).OrderBy(i => i.SortName);
+ return ExtraIds.Select(LibraryManager.GetItemById).Where(i => i != null).OrderBy(i => i.SortName);
}
- public IEnumerable<BaseItem> GetExtras(ExtraType[] unused)
+ public IEnumerable<BaseItem> GetExtras(ExtraType[] extraTypes)
{
- return GetExtras();
+ return ExtraIds.Select(LibraryManager.GetItemById).Where(i => i != null && extraTypes.Contains(i.ExtraType.Value)).OrderBy(i => i.SortName);
}
public IEnumerable<BaseItem> GetDisplayExtras()
{
- return GetExtras();
+ return GetExtras(DisplayExtraTypes);
}
public virtual bool IsHD => Height >= 720;
@@ -2798,8 +2865,10 @@ namespace MediaBrowser.Controller.Entities
{
return RunTimeTicks ?? 0;
}
- // what does this do?
- public static ExtraType[] DisplayExtraTypes = new[] { Model.Entities.ExtraType.ThemeSong, Model.Entities.ExtraType.ThemeVideo };
+
+ // Possible types of extra videos
+ public static ExtraType[] DisplayExtraTypes = new[] { Model.Entities.ExtraType.BehindTheScenes, Model.Entities.ExtraType.Clip, Model.Entities.ExtraType.DeletedScene, Model.Entities.ExtraType.Interview, Model.Entities.ExtraType.Sample, Model.Entities.ExtraType.Scene };
+
public virtual bool SupportsExternalTransfer => false;
}
}
diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs
index 8bfadbee6..c056bc0b4 100644
--- a/MediaBrowser.Controller/Entities/Folder.cs
+++ b/MediaBrowser.Controller/Entities/Folder.cs
@@ -43,7 +43,7 @@ namespace MediaBrowser.Controller.Entities
public Folder()
{
- LinkedChildren = EmptyLinkedChildArray;
+ LinkedChildren = Array.Empty<LinkedChild>();
}
[IgnoreDataMember]
@@ -810,37 +810,19 @@ namespace MediaBrowser.Controller.Entities
{
if (query.ItemIds.Length > 0)
{
- var result = LibraryManager.GetItemsResult(query);
-
- if (query.OrderBy.Length == 0)
- {
- var ids = query.ItemIds.ToList();
-
- // Try to preserve order
- result.Items = result.Items.OrderBy(i => ids.IndexOf(i.Id)).ToArray();
- }
- return result;
+ return LibraryManager.GetItemsResult(query);
}
return GetItemsInternal(query);
}
- public BaseItem[] GetItemList(InternalItemsQuery query)
+ public IReadOnlyList<BaseItem> GetItemList(InternalItemsQuery query)
{
query.EnableTotalRecordCount = false;
if (query.ItemIds.Length > 0)
{
- var result = LibraryManager.GetItemList(query);
-
- if (query.OrderBy.Length == 0)
- {
- var ids = query.ItemIds.ToList();
-
- // Try to preserve order
- return result.OrderBy(i => ids.IndexOf(i.Id)).ToArray();
- }
- return result.ToArray();
+ return LibraryManager.GetItemList(query);
}
return GetItemsInternal(query).Items;
diff --git a/MediaBrowser.Controller/Entities/ItemImageInfo.cs b/MediaBrowser.Controller/Entities/ItemImageInfo.cs
index ff6b13398..848493864 100644
--- a/MediaBrowser.Controller/Entities/ItemImageInfo.cs
+++ b/MediaBrowser.Controller/Entities/ItemImageInfo.cs
@@ -25,22 +25,10 @@ namespace MediaBrowser.Controller.Entities
public DateTime DateModified { get; set; }
public int Width { get; set; }
+
public int Height { get; set; }
[IgnoreDataMember]
- public bool IsLocalFile
- {
- get
- {
- if (Path != null)
- {
- if (Path.StartsWith("http", StringComparison.OrdinalIgnoreCase))
- {
- return false;
- }
- }
- return true;
- }
- }
+ public bool IsLocalFile => Path == null || !Path.StartsWith("http", StringComparison.OrdinalIgnoreCase);
}
}
diff --git a/MediaBrowser.Controller/Entities/Movies/BoxSet.cs b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs
index 124a943ef..a532b5ee9 100644
--- a/MediaBrowser.Controller/Entities/Movies/BoxSet.cs
+++ b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs
@@ -17,7 +17,7 @@ namespace MediaBrowser.Controller.Entities.Movies
{
public BoxSet()
{
- RemoteTrailers = EmptyMediaUrlArray;
+ RemoteTrailers = Array.Empty<MediaUrl>();
LocalTrailerIds = Array.Empty<Guid>();
RemoteTrailerIds = Array.Empty<Guid>();
diff --git a/MediaBrowser.Controller/Entities/Movies/Movie.cs b/MediaBrowser.Controller/Entities/Movies/Movie.cs
index 232d11624..20c5b3521 100644
--- a/MediaBrowser.Controller/Entities/Movies/Movie.cs
+++ b/MediaBrowser.Controller/Entities/Movies/Movie.cs
@@ -21,10 +21,10 @@ namespace MediaBrowser.Controller.Entities.Movies
public Movie()
{
- SpecialFeatureIds = new Guid[] { };
- RemoteTrailers = EmptyMediaUrlArray;
- LocalTrailerIds = new Guid[] { };
- RemoteTrailerIds = new Guid[] { };
+ SpecialFeatureIds = Array.Empty<Guid>();
+ RemoteTrailers = Array.Empty<MediaUrl>();
+ LocalTrailerIds = Array.Empty<Guid>();
+ RemoteTrailerIds = Array.Empty<Guid>();
}
public Guid[] LocalTrailerIds { get; set; }
diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs
index 072b1d89a..fb29c07b0 100644
--- a/MediaBrowser.Controller/Entities/TV/Episode.cs
+++ b/MediaBrowser.Controller/Entities/TV/Episode.cs
@@ -18,7 +18,7 @@ namespace MediaBrowser.Controller.Entities.TV
{
public Episode()
{
- RemoteTrailers = EmptyMediaUrlArray;
+ RemoteTrailers = Array.Empty<MediaUrl>();
LocalTrailerIds = Array.Empty<Guid>();
RemoteTrailerIds = Array.Empty<Guid>();
}
diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs
index 570e9389e..eae834f6f 100644
--- a/MediaBrowser.Controller/Entities/TV/Series.cs
+++ b/MediaBrowser.Controller/Entities/TV/Series.cs
@@ -7,7 +7,6 @@ using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Serialization;
@@ -22,7 +21,7 @@ namespace MediaBrowser.Controller.Entities.TV
{
public Series()
{
- RemoteTrailers = EmptyMediaUrlArray;
+ RemoteTrailers = Array.Empty<MediaUrl>();
LocalTrailerIds = Array.Empty<Guid>();
RemoteTrailerIds = Array.Empty<Guid>();
AirDays = Array.Empty<DayOfWeek>();
diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs
index 31cd42975..8379dcc09 100644
--- a/MediaBrowser.Controller/Entities/Video.cs
+++ b/MediaBrowser.Controller/Entities/Video.cs
@@ -167,7 +167,7 @@ namespace MediaBrowser.Controller.Entities
AdditionalParts = Array.Empty<string>();
LocalAlternateVersions = Array.Empty<string>();
SubtitleFiles = Array.Empty<string>();
- LinkedAlternateVersions = EmptyLinkedChildArray;
+ LinkedAlternateVersions = Array.Empty<LinkedChild>();
}
public override bool CanDownload()
diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.cs
index 22797aa0d..81b9ff0a5 100644
--- a/MediaBrowser.Controller/IServerApplicationHost.cs
+++ b/MediaBrowser.Controller/IServerApplicationHost.cs
@@ -83,8 +83,6 @@ namespace MediaBrowser.Controller
void EnableLoopback(string appName);
- string PackageRuntime { get; }
-
WakeOnLanInfo[] GetWakeOnLanInfo();
string ExpandVirtualPath(string path);
diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs
index 60c183d04..511356aa4 100644
--- a/MediaBrowser.Controller/Library/ILibraryManager.cs
+++ b/MediaBrowser.Controller/Library/ILibraryManager.cs
@@ -193,7 +193,7 @@ namespace MediaBrowser.Controller.Library
/// <summary>
/// Updates the item.
/// </summary>
- void UpdateItems(List<BaseItem> items, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken);
+ void UpdateItems(IEnumerable<BaseItem> items, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken);
void UpdateItem(BaseItem item, BaseItem parent, ItemUpdateType updateReason, CancellationToken cancellationToken);
/// <summary>
@@ -520,12 +520,12 @@ namespace MediaBrowser.Controller.Library
void UpdateMediaPath(string virtualFolderName, MediaPathInfo path);
void RemoveMediaPath(string virtualFolderName, string path);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetGenres(InternalItemsQuery query);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetMusicGenres(InternalItemsQuery query);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetStudios(InternalItemsQuery query);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetArtists(InternalItemsQuery query);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetAlbumArtists(InternalItemsQuery query);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetAllArtists(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetGenres(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetMusicGenres(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetStudios(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetArtists(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetAlbumArtists(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetAllArtists(InternalItemsQuery query);
int GetCount(InternalItemsQuery query);
diff --git a/MediaBrowser.Controller/Library/TVUtils.cs b/MediaBrowser.Controller/Library/TVUtils.cs
index 5b66e7497..fd5fb6748 100644
--- a/MediaBrowser.Controller/Library/TVUtils.cs
+++ b/MediaBrowser.Controller/Library/TVUtils.cs
@@ -8,16 +8,6 @@ namespace MediaBrowser.Controller.Library
public static class TVUtils
{
/// <summary>
- /// The TVDB API key
- /// </summary>
- public static readonly string TvdbApiKey = "72930AE1CB7E2DB3";
- public static readonly string TvdbBaseUrl = "https://www.thetvdb.com/";
- /// <summary>
- /// The banner URL
- /// </summary>
- public static readonly string BannerUrl = TvdbBaseUrl + "banners/";
-
- /// <summary>
/// Gets the air days.
/// </summary>
/// <param name="day">The day.</param>
@@ -28,24 +18,24 @@ namespace MediaBrowser.Controller.Library
{
if (string.Equals(day, "Daily", StringComparison.OrdinalIgnoreCase))
{
- return new DayOfWeek[]
- {
- DayOfWeek.Sunday,
- DayOfWeek.Monday,
- DayOfWeek.Tuesday,
- DayOfWeek.Wednesday,
- DayOfWeek.Thursday,
- DayOfWeek.Friday,
- DayOfWeek.Saturday
- };
+ return new[]
+ {
+ DayOfWeek.Sunday,
+ DayOfWeek.Monday,
+ DayOfWeek.Tuesday,
+ DayOfWeek.Wednesday,
+ DayOfWeek.Thursday,
+ DayOfWeek.Friday,
+ DayOfWeek.Saturday
+ };
}
if (Enum.TryParse(day, true, out DayOfWeek value))
{
- return new DayOfWeek[]
- {
- value
- };
+ return new[]
+ {
+ value
+ };
}
return new DayOfWeek[] { };
diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
index f5f147db1..e378c2b89 100644
--- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
+++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
@@ -1904,7 +1904,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
flags.Add("+ignidx");
}
- if (state.GenPtsInput)
+ if (state.GenPtsInput || string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))
{
flags.Add("+genpts");
}
diff --git a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs
index 057e43910..d032a849e 100644
--- a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs
+++ b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs
@@ -6,6 +6,7 @@ using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
+using MediaBrowser.Model.System;
namespace MediaBrowser.Controller.MediaEncoding
{
@@ -14,7 +15,7 @@ namespace MediaBrowser.Controller.MediaEncoding
/// </summary>
public interface IMediaEncoder : ITranscoderSupport
{
- string EncoderLocationType { get; }
+ FFmpegLocation EncoderLocation { get; }
/// <summary>
/// Gets the encoder path.
@@ -73,7 +74,7 @@ namespace MediaBrowser.Controller.MediaEncoding
/// <param name="inputFiles">The input files.</param>
/// <param name="protocol">The protocol.</param>
/// <returns>System.String.</returns>
- string GetInputArgument(string[] inputFiles, MediaProtocol protocol);
+ string GetInputArgument(IReadOnlyList<string> inputFiles, MediaProtocol protocol);
/// <summary>
/// Gets the time parameter.
@@ -91,7 +92,7 @@ namespace MediaBrowser.Controller.MediaEncoding
/// <returns>System.String.</returns>
string EscapeSubtitleFilterPath(string path);
- void Init();
+ void SetFFmpegPath();
void UpdateEncoderPath(string path, string pathType);
bool SupportsEncoder(string encoder);
diff --git a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs
index b812a8ddc..2755bf581 100644
--- a/MediaBrowser.Controller/MediaEncoding/JobLogger.cs
+++ b/MediaBrowser.Controller/MediaEncoding/JobLogger.cs
@@ -10,7 +10,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
public class JobLogger
{
- private readonly CultureInfo _usCulture = new CultureInfo("en-US");
+ private static readonly CultureInfo _usCulture = CultureInfo.ReadOnly(new CultureInfo("en-US"));
private readonly ILogger _logger;
public JobLogger(ILogger logger)
@@ -24,7 +24,7 @@ namespace MediaBrowser.Controller.MediaEncoding
{
using (var reader = new StreamReader(source))
{
- while (!reader.EndOfStream)
+ while (!reader.EndOfStream && reader.BaseStream.CanRead)
{
var line = await reader.ReadLineAsync().ConfigureAwait(false);
@@ -32,16 +32,24 @@ namespace MediaBrowser.Controller.MediaEncoding
var bytes = Encoding.UTF8.GetBytes(Environment.NewLine + line);
+ // If ffmpeg process is closed, the state is disposed, so don't write to target in that case
+ if (!target.CanWrite)
+ {
+ break;
+ }
+
await target.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
+
+ // Check again, the stream could have been closed
+ if (!target.CanWrite)
+ {
+ break;
+ }
+
await target.FlushAsync().ConfigureAwait(false);
}
}
}
- catch (ObjectDisposedException)
- {
- //TODO Investigate and properly fix.
- // Don't spam the log. This doesn't seem to throw in windows, but sometimes under linux
- }
catch (Exception ex)
{
_logger.LogError(ex, "Error reading ffmpeg log");
diff --git a/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs b/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs
index 4242a00e2..844412546 100644
--- a/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs
+++ b/MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs
@@ -22,8 +22,8 @@ namespace MediaBrowser.Controller.Net
/// <summary>
/// The _active connections
/// </summary>
- protected readonly List<Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType>> ActiveConnections =
- new List<Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType>>();
+ protected readonly List<Tuple<IWebSocketConnection, CancellationTokenSource, TStateType>> ActiveConnections =
+ new List<Tuple<IWebSocketConnection, CancellationTokenSource, TStateType>>();
/// <summary>
/// Gets the name.
@@ -34,9 +34,8 @@ namespace MediaBrowser.Controller.Net
/// <summary>
/// Gets the data to send.
/// </summary>
- /// <param name="state">The state.</param>
/// <returns>Task{`1}.</returns>
- protected abstract Task<TReturnDataType> GetDataToSend(TStateType state, CancellationToken cancellationToken);
+ protected abstract Task<TReturnDataType> GetDataToSend();
/// <summary>
/// The logger
@@ -80,13 +79,6 @@ namespace MediaBrowser.Controller.Net
protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
- protected virtual bool SendOnTimer => false;
-
- protected virtual void ParseMessageParams(string[] values)
- {
-
- }
-
/// <summary>
/// Starts sending messages over a web socket
/// </summary>
@@ -98,19 +90,10 @@ namespace MediaBrowser.Controller.Net
var dueTimeMs = long.Parse(vals[0], UsCulture);
var periodMs = long.Parse(vals[1], UsCulture);
- if (vals.Length > 2)
- {
- ParseMessageParams(vals.Skip(2).ToArray());
- }
-
var cancellationTokenSource = new CancellationTokenSource();
Logger.LogDebug("{1} Begin transmitting over websocket to {0}", message.Connection.RemoteEndPoint, GetType().Name);
- var timer = SendOnTimer ?
- new Timer(TimerCallback, message.Connection, Timeout.Infinite, Timeout.Infinite) :
- null;
-
var state = new TStateType
{
IntervalMs = periodMs,
@@ -119,47 +102,13 @@ namespace MediaBrowser.Controller.Net
lock (ActiveConnections)
{
- ActiveConnections.Add(new Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType>(message.Connection, cancellationTokenSource, timer, state));
- }
-
- if (timer != null)
- {
- timer.Change(TimeSpan.FromMilliseconds(dueTimeMs), TimeSpan.FromMilliseconds(periodMs));
+ ActiveConnections.Add(new Tuple<IWebSocketConnection, CancellationTokenSource, TStateType>(message.Connection, cancellationTokenSource, state));
}
}
- /// <summary>
- /// Timers the callback.
- /// </summary>
- /// <param name="state">The state.</param>
- private void TimerCallback(object state)
- {
- var connection = (IWebSocketConnection)state;
-
- Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType> tuple;
-
- lock (ActiveConnections)
- {
- tuple = ActiveConnections.FirstOrDefault(c => c.Item1 == connection);
- }
-
- if (tuple == null)
- {
- return;
- }
-
- if (connection.State != WebSocketState.Open || tuple.Item2.IsCancellationRequested)
- {
- DisposeConnection(tuple);
- return;
- }
-
- SendData(tuple);
- }
-
protected void SendData(bool force)
{
- Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType>[] tuples;
+ Tuple<IWebSocketConnection, CancellationTokenSource, TStateType>[] tuples;
lock (ActiveConnections)
{
@@ -168,7 +117,7 @@ namespace MediaBrowser.Controller.Net
{
if (c.Item1.State == WebSocketState.Open && !c.Item2.IsCancellationRequested)
{
- var state = c.Item4;
+ var state = c.Item3;
if (force || (DateTime.UtcNow - state.DateLastSendUtc).TotalMilliseconds >= state.IntervalMs)
{
@@ -187,17 +136,17 @@ namespace MediaBrowser.Controller.Net
}
}
- private async void SendData(Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType> tuple)
+ private async void SendData(Tuple<IWebSocketConnection, CancellationTokenSource, TStateType> tuple)
{
var connection = tuple.Item1;
try
{
- var state = tuple.Item4;
+ var state = tuple.Item3;
var cancellationToken = tuple.Item2.Token;
- var data = await GetDataToSend(state, cancellationToken).ConfigureAwait(false);
+ var data = await GetDataToSend().ConfigureAwait(false);
if (data != null)
{
@@ -246,23 +195,12 @@ namespace MediaBrowser.Controller.Net
/// Disposes the connection.
/// </summary>
/// <param name="connection">The connection.</param>
- private void DisposeConnection(Tuple<IWebSocketConnection, CancellationTokenSource, Timer, TStateType> connection)
+ private void DisposeConnection(Tuple<IWebSocketConnection, CancellationTokenSource, TStateType> connection)
{
Logger.LogDebug("{1} stop transmitting over websocket to {0}", connection.Item1.RemoteEndPoint, GetType().Name);
- var timer = connection.Item3;
-
- if (timer != null)
- {
- try
- {
- timer.Dispose();
- }
- catch (ObjectDisposedException)
- {
- //TODO Investigate and properly fix.
- }
- }
+ // TODO disposing the connection seems to break websockets in subtle ways, so what is the purpose of this function really...
+ // connection.Item1.Dispose();
try
{
diff --git a/MediaBrowser.Controller/Net/IHttpServer.cs b/MediaBrowser.Controller/Net/IHttpServer.cs
index f41303007..46933c046 100644
--- a/MediaBrowser.Controller/Net/IHttpServer.cs
+++ b/MediaBrowser.Controller/Net/IHttpServer.cs
@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
namespace MediaBrowser.Controller.Net
{
@@ -29,11 +32,30 @@ namespace MediaBrowser.Controller.Net
/// <summary>
/// Inits this instance.
/// </summary>
- void Init(IEnumerable<IService> services, IEnumerable<IWebSocketListener> listener);
+ void Init(IEnumerable<IService> services, IEnumerable<IWebSocketListener> listener, IEnumerable<string> urlPrefixes);
/// <summary>
/// If set, all requests will respond with this message
/// </summary>
string GlobalResponse { get; set; }
+
+ /// <summary>
+ /// Sends the http context to the socket listener
+ /// </summary>
+ /// <param name="ctx"></param>
+ /// <returns></returns>
+ Task ProcessWebSocketRequest(HttpContext ctx);
+
+ /// <summary>
+ /// The HTTP request handler
+ /// </summary>
+ /// <param name="httpReq"></param>
+ /// <param name="urlString"></param>
+ /// <param name="host"></param>
+ /// <param name="localPath"></param>
+ /// <param name="cancellationToken"></param>
+ /// <returns></returns>
+ Task RequestHandler(IHttpRequest httpReq, string urlString, string host, string localPath,
+ CancellationToken cancellationToken);
}
}
diff --git a/MediaBrowser.Controller/Net/IWebSocketConnection.cs b/MediaBrowser.Controller/Net/IWebSocketConnection.cs
index a09b2f7a2..566897b31 100644
--- a/MediaBrowser.Controller/Net/IWebSocketConnection.cs
+++ b/MediaBrowser.Controller/Net/IWebSocketConnection.cs
@@ -4,6 +4,7 @@ using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Services;
+using Microsoft.AspNetCore.Http;
namespace MediaBrowser.Controller.Net
{
@@ -35,7 +36,7 @@ namespace MediaBrowser.Controller.Net
/// Gets or sets the query string.
/// </summary>
/// <value>The query string.</value>
- QueryParamCollection QueryString { get; set; }
+ IQueryCollection QueryString { get; set; }
/// <summary>
/// Gets or sets the receive action.
diff --git a/MediaBrowser.Controller/Net/WebSocketConnectEventArgs.cs b/MediaBrowser.Controller/Net/WebSocketConnectEventArgs.cs
deleted file mode 100644
index f26b764bb..000000000
--- a/MediaBrowser.Controller/Net/WebSocketConnectEventArgs.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System;
-using MediaBrowser.Model.Services;
-
-namespace MediaBrowser.Controller.Net
-{
- /// <summary>
- /// Class WebSocketConnectEventArgs
- /// </summary>
- public class WebSocketConnectingEventArgs : EventArgs
- {
- /// <summary>
- /// Gets or sets the URL.
- /// </summary>
- /// <value>The URL.</value>
- public string Url { get; set; }
- /// <summary>
- /// Gets or sets the endpoint.
- /// </summary>
- /// <value>The endpoint.</value>
- public string Endpoint { get; set; }
- /// <summary>
- /// Gets or sets the query string.
- /// </summary>
- /// <value>The query string.</value>
- public QueryParamCollection QueryString { get; set; }
- /// <summary>
- /// Gets or sets a value indicating whether [allow connection].
- /// </summary>
- /// <value><c>true</c> if [allow connection]; otherwise, <c>false</c>.</value>
- public bool AllowConnection { get; set; }
-
- public WebSocketConnectingEventArgs()
- {
- QueryString = new QueryParamCollection();
- AllowConnection = true;
- }
- }
-
-}
diff --git a/MediaBrowser.Controller/Persistence/IItemRepository.cs b/MediaBrowser.Controller/Persistence/IItemRepository.cs
index 5156fce11..47e0f3453 100644
--- a/MediaBrowser.Controller/Persistence/IItemRepository.cs
+++ b/MediaBrowser.Controller/Persistence/IItemRepository.cs
@@ -32,7 +32,7 @@ namespace MediaBrowser.Controller.Persistence
/// </summary>
/// <param name="items">The items.</param>
/// <param name="cancellationToken">The cancellation token.</param>
- void SaveItems(List<BaseItem> items, CancellationToken cancellationToken);
+ void SaveItems(IEnumerable<BaseItem> items, CancellationToken cancellationToken);
void SaveImages(BaseItem item);
@@ -141,12 +141,12 @@ namespace MediaBrowser.Controller.Persistence
int GetCount(InternalItemsQuery query);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetGenres(InternalItemsQuery query);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetMusicGenres(InternalItemsQuery query);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetStudios(InternalItemsQuery query);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetArtists(InternalItemsQuery query);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetAlbumArtists(InternalItemsQuery query);
- QueryResult<Tuple<BaseItem, ItemCounts>> GetAllArtists(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetGenres(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetMusicGenres(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetStudios(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetArtists(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetAlbumArtists(InternalItemsQuery query);
+ QueryResult<(BaseItem, ItemCounts)> GetAllArtists(InternalItemsQuery query);
List<string> GetMusicGenreNames();
List<string> GetStudioNames();
diff --git a/MediaBrowser.Controller/Properties/AssemblyInfo.cs b/MediaBrowser.Controller/Properties/AssemblyInfo.cs
index 007a1d739..60e792309 100644
--- a/MediaBrowser.Controller/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.Controller/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/MediaBrowser.Controller/Security/IEncryptionManager.cs b/MediaBrowser.Controller/Security/IEncryptionManager.cs
deleted file mode 100644
index 68680fdf3..000000000
--- a/MediaBrowser.Controller/Security/IEncryptionManager.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-namespace MediaBrowser.Controller.Security
-{
- public interface IEncryptionManager
- {
- /// <summary>
- /// Encrypts the string.
- /// </summary>
- /// <param name="value">The value.</param>
- /// <returns>System.String.</returns>
- string EncryptString(string value);
-
- /// <summary>
- /// Decrypts the string.
- /// </summary>
- /// <param name="value">The value.</param>
- /// <returns>System.String.</returns>
- string DecryptString(string value);
- }
-}
diff --git a/MediaBrowser.LocalMetadata/Images/InternalMetadataFolderImageProvider.cs b/MediaBrowser.LocalMetadata/Images/InternalMetadataFolderImageProvider.cs
index c0706ceeb..25a8ad596 100644
--- a/MediaBrowser.LocalMetadata/Images/InternalMetadataFolderImageProvider.cs
+++ b/MediaBrowser.LocalMetadata/Images/InternalMetadataFolderImageProvider.cs
@@ -5,6 +5,7 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
+using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Images
{
@@ -12,11 +13,16 @@ namespace MediaBrowser.LocalMetadata.Images
{
private readonly IServerConfigurationManager _config;
private readonly IFileSystem _fileSystem;
+ private readonly ILogger _logger;
- public InternalMetadataFolderImageProvider(IServerConfigurationManager config, IFileSystem fileSystem)
+ public InternalMetadataFolderImageProvider(
+ IServerConfigurationManager config,
+ IFileSystem fileSystem,
+ ILogger<InternalMetadataFolderImageProvider> logger)
{
_config = config;
_fileSystem = fileSystem;
+ _logger = logger;
}
public string Name => "Internal Images";
@@ -53,12 +59,18 @@ namespace MediaBrowser.LocalMetadata.Images
{
var path = item.GetInternalMetadataPath();
+ if (!Directory.Exists(path))
+ {
+ return new List<LocalImageInfo>();
+ }
+
try
{
return new LocalImageProvider(_fileSystem).GetImages(item, path, false, directoryService);
}
- catch (IOException)
+ catch (IOException ex)
{
+ _logger.LogError(ex, "Error while getting images for {Library}", item.Name);
return new List<LocalImageInfo>();
}
}
diff --git a/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs b/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs
index 1a7654bfd..7c330ad86 100644
--- a/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs
+++ b/MediaBrowser.LocalMetadata/Images/LocalImageProvider.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.IO;
using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
@@ -65,6 +66,12 @@ namespace MediaBrowser.LocalMetadata.Images
var path = item.ContainingFolderPath;
+ // Exit if the cache dir does not exist, alternative solution is to create it, but that's a lot of empty dirs...
+ if (!Directory.Exists(path))
+ {
+ return Array.Empty<FileSystemMetadata>();
+ }
+
if (includeDirectories)
{
return directoryService.GetFileSystemEntries(path)
diff --git a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs
index 38458e34c..59c8f4da5 100644
--- a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs
+++ b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs
@@ -10,7 +10,6 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Parsers
@@ -30,19 +29,14 @@ namespace MediaBrowser.LocalMetadata.Parsers
private Dictionary<string, string> _validProviderIds;
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
- protected IFileSystem FileSystem { get; private set; }
-
/// <summary>
/// Initializes a new instance of the <see cref="BaseItemXmlParser{T}" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
- public BaseItemXmlParser(ILogger logger, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory, IFileSystem fileSystem)
+ public BaseItemXmlParser(ILogger logger, IProviderManager providerManager)
{
Logger = logger;
ProviderManager = providerManager;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
- FileSystem = fileSystem;
}
/// <summary>
@@ -64,11 +58,13 @@ namespace MediaBrowser.LocalMetadata.Parsers
throw new ArgumentException("The metadata file was empty or null.", nameof(metadataFile));
}
- var settings = XmlReaderSettingsFactory.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
+ var settings = new XmlReaderSettings()
+ {
+ ValidationType = ValidationType.None,
+ CheckCharacters = false,
+ IgnoreProcessingInstructions = true,
+ IgnoreComments = true
+ };
_validProviderIds = _validProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
@@ -103,29 +99,24 @@ namespace MediaBrowser.LocalMetadata.Parsers
item.ResetPeople();
using (var fileStream = File.OpenRead(metadataFile))
+ using (var streamReader = new StreamReader(fileStream, encoding))
+ using (var reader = XmlReader.Create(streamReader, settings))
{
- using (var streamReader = new StreamReader(fileStream, encoding))
+ reader.MoveToContent();
+ reader.Read();
+
+ // Loop through each element
+ while (!reader.EOF && reader.ReadState == ReadState.Interactive)
{
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
+ cancellationToken.ThrowIfCancellationRequested();
+
+ if (reader.NodeType == XmlNodeType.Element)
+ {
+ FetchDataFromXmlNode(reader, item);
+ }
+ else
{
- reader.MoveToContent();
reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- if (reader.NodeType == XmlNodeType.Element)
- {
- FetchDataFromXmlNode(reader, item);
- }
- else
- {
- reader.Read();
- }
- }
}
}
}
diff --git a/MediaBrowser.LocalMetadata/Parsers/BoxSetXmlParser.cs b/MediaBrowser.LocalMetadata/Parsers/BoxSetXmlParser.cs
index e595e9d06..127334625 100644
--- a/MediaBrowser.LocalMetadata/Parsers/BoxSetXmlParser.cs
+++ b/MediaBrowser.LocalMetadata/Parsers/BoxSetXmlParser.cs
@@ -3,8 +3,6 @@ using System.Xml;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Parsers
@@ -87,7 +85,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
item.Item.LinkedChildren = list.ToArray();
}
- public BoxSetXmlParser(ILogger logger, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory, IFileSystem fileSystem) : base(logger, providerManager, xmlReaderSettingsFactory, fileSystem)
+ public BoxSetXmlParser(ILogger logger, IProviderManager providerManager)
+ : base(logger, providerManager)
{
}
}
diff --git a/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs b/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs
index ff69cb023..5608a0be9 100644
--- a/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs
+++ b/MediaBrowser.LocalMetadata/Parsers/PlaylistXmlParser.cs
@@ -3,8 +3,6 @@ using System.Xml;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Playlists;
using MediaBrowser.Controller.Providers;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Parsers
@@ -95,7 +93,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
item.LinkedChildren = list.ToArray();
}
- public PlaylistXmlParser(ILogger logger, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory, IFileSystem fileSystem) : base(logger, providerManager, xmlReaderSettingsFactory, fileSystem)
+ public PlaylistXmlParser(ILogger logger, IProviderManager providerManager)
+ : base(logger, providerManager)
{
}
}
diff --git a/MediaBrowser.LocalMetadata/Properties/AssemblyInfo.cs b/MediaBrowser.LocalMetadata/Properties/AssemblyInfo.cs
index 3eac83708..580cef9da 100644
--- a/MediaBrowser.LocalMetadata/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.LocalMetadata/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/MediaBrowser.LocalMetadata/Providers/BoxSetXmlProvider.cs b/MediaBrowser.LocalMetadata/Providers/BoxSetXmlProvider.cs
index 539f818c6..2e303efab 100644
--- a/MediaBrowser.LocalMetadata/Providers/BoxSetXmlProvider.cs
+++ b/MediaBrowser.LocalMetadata/Providers/BoxSetXmlProvider.cs
@@ -4,7 +4,6 @@ using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.LocalMetadata.Parsers;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Providers
@@ -16,19 +15,17 @@ namespace MediaBrowser.LocalMetadata.Providers
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
- public BoxSetXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public BoxSetXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<BoxSet> result, string path, CancellationToken cancellationToken)
{
- new BoxSetXmlParser(_logger, _providerManager, XmlReaderSettingsFactory, FileSystem).Fetch(result, path, cancellationToken);
+ new BoxSetXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)
diff --git a/MediaBrowser.LocalMetadata/Providers/PlaylistXmlProvider.cs b/MediaBrowser.LocalMetadata/Providers/PlaylistXmlProvider.cs
index 442a18cb9..d111ae9ba 100644
--- a/MediaBrowser.LocalMetadata/Providers/PlaylistXmlProvider.cs
+++ b/MediaBrowser.LocalMetadata/Providers/PlaylistXmlProvider.cs
@@ -4,7 +4,6 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.LocalMetadata.Parsers;
using MediaBrowser.LocalMetadata.Savers;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Providers
@@ -13,19 +12,17 @@ namespace MediaBrowser.LocalMetadata.Providers
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
- public PlaylistXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public PlaylistXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<Playlist> result, string path, CancellationToken cancellationToken)
{
- new PlaylistXmlParser(_logger, _providerManager, XmlReaderSettingsFactory, FileSystem).Fetch(result, path, cancellationToken);
+ new PlaylistXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)
diff --git a/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs
index 438b84252..30a33b729 100644
--- a/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs
+++ b/MediaBrowser.LocalMetadata/Savers/BaseXmlSaver.cs
@@ -14,7 +14,6 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Playlists;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Savers
@@ -23,7 +22,7 @@ namespace MediaBrowser.LocalMetadata.Savers
{
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
- public BaseXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public BaseXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger)
{
FileSystem = fileSystem;
ConfigurationManager = configurationManager;
@@ -31,7 +30,6 @@ namespace MediaBrowser.LocalMetadata.Savers
UserManager = userManager;
UserDataManager = userDataManager;
Logger = logger;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected IFileSystem FileSystem { get; private set; }
@@ -40,9 +38,6 @@ namespace MediaBrowser.LocalMetadata.Savers
protected IUserManager UserManager { get; private set; }
protected IUserDataManager UserDataManager { get; private set; }
protected ILogger Logger { get; private set; }
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
-
- protected ItemUpdateType MinimumUpdateType => ItemUpdateType.MetadataDownload;
public string Name => XmlProviderUtils.Name;
diff --git a/MediaBrowser.LocalMetadata/Savers/BoxSetXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/BoxSetXmlSaver.cs
index b4d5440a5..ea939e33b 100644
--- a/MediaBrowser.LocalMetadata/Savers/BoxSetXmlSaver.cs
+++ b/MediaBrowser.LocalMetadata/Savers/BoxSetXmlSaver.cs
@@ -5,7 +5,6 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Savers
@@ -31,7 +30,8 @@ namespace MediaBrowser.LocalMetadata.Savers
return Path.Combine(item.Path, "collection.xml");
}
- public BoxSetXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
+ public BoxSetXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger)
+ : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
}
diff --git a/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs
index 09bb6d8f7..35a431fa4 100644
--- a/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs
+++ b/MediaBrowser.LocalMetadata/Savers/PlaylistXmlSaver.cs
@@ -5,7 +5,6 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Playlists;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.LocalMetadata.Savers
@@ -49,7 +48,8 @@ namespace MediaBrowser.LocalMetadata.Savers
return Path.Combine(path, "playlist.xml");
}
- public PlaylistXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
+ public PlaylistXmlSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger)
+ : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
}
diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
index 262772959..3eed891cb 100644
--- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
+using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using MediaBrowser.Model.Diagnostics;
@@ -19,7 +19,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
_processFactory = processFactory;
}
- public (IEnumerable<string> decoders, IEnumerable<string> encoders) Validate(string encoderPath)
+ public (IEnumerable<string> decoders, IEnumerable<string> encoders) GetAvailableCoders(string encoderPath)
{
_logger.LogInformation("Validating media encoder at {EncoderPath}", encoderPath);
@@ -48,6 +48,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
if (string.IsNullOrWhiteSpace(output))
{
+ if (logOutput)
+ {
+ _logger.LogError("FFmpeg validation: The process returned no result");
+ }
return false;
}
@@ -55,21 +59,114 @@ namespace MediaBrowser.MediaEncoding.Encoder
if (output.IndexOf("Libav developers", StringComparison.OrdinalIgnoreCase) != -1)
{
+ if (logOutput)
+ {
+ _logger.LogError("FFmpeg validation: avconv instead of ffmpeg is not supported");
+ }
return false;
}
- output = " " + output + " ";
+ // The min and max FFmpeg versions required to run jellyfin successfully
+ var minRequired = new Version(4, 0);
+ var maxRequired = new Version(4, 0);
+
+ // Work out what the version under test is
+ var underTest = GetFFmpegVersion(output);
- for (var i = 2013; i <= 2015; i++)
+ if (logOutput)
{
- var yearString = i.ToString(CultureInfo.InvariantCulture);
- if (output.IndexOf(" " + yearString + " ", StringComparison.OrdinalIgnoreCase) != -1)
+ _logger.LogInformation("FFmpeg validation: Found ffmpeg version {0}", underTest != null ? underTest.ToString() : "unknown");
+
+ if (underTest == null) // Version is unknown
{
- return false;
+ if (minRequired.Equals(maxRequired))
+ {
+ _logger.LogWarning("FFmpeg validation: We recommend ffmpeg version {0}", minRequired.ToString());
+ }
+ else
+ {
+ _logger.LogWarning("FFmpeg validation: We recommend a minimum of {0} and maximum of {1}", minRequired.ToString(), maxRequired.ToString());
+ }
}
+ else if (underTest.CompareTo(minRequired) < 0) // Version is below what we recommend
+ {
+ _logger.LogWarning("FFmpeg validation: The minimum recommended ffmpeg version is {0}", minRequired.ToString());
+ }
+ else if (underTest.CompareTo(maxRequired) > 0) // Version is above what we recommend
+ {
+ _logger.LogWarning("FFmpeg validation: The maximum recommended ffmpeg version is {0}", maxRequired.ToString());
+ }
+ else // Version is ok
+ {
+ _logger.LogInformation("FFmpeg validation: Found suitable ffmpeg version");
+ }
+ }
+
+ // underTest shall be null if versions is unknown
+ return (underTest == null) ? false : (underTest.CompareTo(minRequired) >= 0 && underTest.CompareTo(maxRequired) <= 0);
+ }
+
+ /// <summary>
+ /// Using the output from "ffmpeg -version" work out the FFmpeg version.
+ /// For pre-built binaries the first line should contain a string like "ffmpeg version x.y", which is easy
+ /// to parse. If this is not available, then we try to match known library versions to FFmpeg versions.
+ /// If that fails then we use one of the main libraries to determine if it's new/older than the latest
+ /// we have stored.
+ /// </summary>
+ /// <param name="output"></param>
+ /// <returns></returns>
+ static private Version GetFFmpegVersion(string output)
+ {
+ // For pre-built binaries the FFmpeg version should be mentioned at the very start of the output
+ var match = Regex.Match(output, @"ffmpeg version (\d+\.\d+)");
+
+ if (match.Success)
+ {
+ return new Version(match.Groups[1].Value);
+ }
+ else
+ {
+ // Try and use the individual library versions to determine a FFmpeg version
+ // This lookup table is to be maintained with the following command line:
+ // $ ./ffmpeg.exe -version | perl -ne ' print "$1=$2.$3," if /^(lib\w+)\s+(\d+)\.\s*(\d+)/'
+ var lut = new ReadOnlyDictionary<Version, string>
+ (new Dictionary<Version, string>
+ {
+ { new Version("4.1"), "libavutil=56.22,libavcodec=58.35,libavformat=58.20,libavdevice=58.5,libavfilter=7.40,libswscale=5.3,libswresample=3.3,libpostproc=55.3," },
+ { new Version("4.0"), "libavutil=56.14,libavcodec=58.18,libavformat=58.12,libavdevice=58.3,libavfilter=7.16,libswscale=5.1,libswresample=3.1,libpostproc=55.1," },
+ { new Version("3.4"), "libavutil=55.78,libavcodec=57.107,libavformat=57.83,libavdevice=57.10,libavfilter=6.107,libswscale=4.8,libswresample=2.9,libpostproc=54.7," },
+ { new Version("3.3"), "libavutil=55.58,libavcodec=57.89,libavformat=57.71,libavdevice=57.6,libavfilter=6.82,libswscale=4.6,libswresample=2.7,libpostproc=54.5," },
+ { new Version("3.2"), "libavutil=55.34,libavcodec=57.64,libavformat=57.56,libavdevice=57.1,libavfilter=6.65,libswscale=4.2,libswresample=2.3,libpostproc=54.1," },
+ { new Version("2.8"), "libavutil=54.31,libavcodec=56.60,libavformat=56.40,libavdevice=56.4,libavfilter=5.40,libswscale=3.1,libswresample=1.2,libpostproc=53.3," }
+ });
+
+ // Create a reduced version string and lookup key from dictionary
+ var reducedVersion = GetVersionString(output);
+
+ // Try to lookup the string and return Key, otherwise if not found returns null
+ return lut.FirstOrDefault(x => x.Value == reducedVersion).Key;
+ }
+ }
+
+ /// <summary>
+ /// Grabs the library names and major.minor version numbers from the 'ffmpeg -version' output
+ /// and condenses them on to one line. Output format is "name1=major.minor,name2=major.minor,etc."
+ /// </summary>
+ /// <param name="output"></param>
+ /// <returns></returns>
+ static private string GetVersionString(string output)
+ {
+ string pattern = @"((?<name>lib\w+)\s+(?<major>\d+)\.\s*(?<minor>\d+))";
+ RegexOptions options = RegexOptions.Multiline;
+
+ string rc = null;
+
+ foreach (Match m in Regex.Matches(output, pattern, options))
+ {
+ rc += string.Concat(m.Groups["name"], '=', m.Groups["major"], '.', m.Groups["minor"], ',');
}
- return true;
+ return rc;
}
private static readonly string[] requiredDecoders = new[]
diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs
index 44e62446b..d4aede572 100644
--- a/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/EncodingUtils.cs
@@ -6,11 +6,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
public static class EncodingUtils
{
- public static string GetInputArgument(List<string> inputFiles, MediaProtocol protocol)
+ public static string GetInputArgument(IReadOnlyList<string> inputFiles, MediaProtocol protocol)
{
if (protocol != MediaProtocol.File)
{
- var url = inputFiles.First();
+ var url = inputFiles[0];
return string.Format("\"{0}\"", url);
}
@@ -29,7 +29,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
// If there's more than one we'll need to use the concat command
if (inputFiles.Count > 1)
{
- var files = string.Join("|", inputFiles.Select(NormalizePath).ToArray());
+ var files = string.Join("|", inputFiles.Select(NormalizePath));
return string.Format("concat:\"{0}\"", files);
}
diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
index d922f1068..4867c0f85 100644
--- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
@@ -3,25 +3,24 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
+using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
-using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaEncoding;
-using MediaBrowser.Controller.Session;
using MediaBrowser.MediaEncoding.Probing;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Diagnostics;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization;
+using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.MediaEncoding.Encoder
@@ -32,340 +31,217 @@ namespace MediaBrowser.MediaEncoding.Encoder
public class MediaEncoder : IMediaEncoder, IDisposable
{
/// <summary>
- /// The _logger
- /// </summary>
- private readonly ILogger _logger;
-
- /// <summary>
- /// Gets the json serializer.
+ /// Gets the encoder path.
/// </summary>
- /// <value>The json serializer.</value>
- private readonly IJsonSerializer _jsonSerializer;
+ /// <value>The encoder path.</value>
+ public string EncoderPath => FFmpegPath;
/// <summary>
- /// The _thumbnail resource pool
+ /// The location of the discovered FFmpeg tool.
/// </summary>
- private readonly SemaphoreSlim _thumbnailResourcePool = new SemaphoreSlim(1, 1);
-
- public string FFMpegPath { get; private set; }
-
- public string FFProbePath { get; private set; }
+ public FFmpegLocation EncoderLocation { get; private set; }
+ private readonly ILogger _logger;
+ private readonly IJsonSerializer _jsonSerializer;
+ private string FFmpegPath;
+ private string FFprobePath;
protected readonly IServerConfigurationManager ConfigurationManager;
protected readonly IFileSystem FileSystem;
- protected readonly ILiveTvManager LiveTvManager;
- protected readonly IIsoManager IsoManager;
- protected readonly ILibraryManager LibraryManager;
- protected readonly IChannelManager ChannelManager;
- protected readonly ISessionManager SessionManager;
protected readonly Func<ISubtitleEncoder> SubtitleEncoder;
protected readonly Func<IMediaSourceManager> MediaSourceManager;
- private readonly IHttpClient _httpClient;
- private readonly IZipClient _zipClient;
private readonly IProcessFactory _processFactory;
+ private readonly int DefaultImageExtractionTimeoutMs;
+ private readonly string StartupOptionFFmpegPath;
+ private readonly SemaphoreSlim _thumbnailResourcePool = new SemaphoreSlim(1, 1);
private readonly List<ProcessWrapper> _runningProcesses = new List<ProcessWrapper>();
- private readonly bool _hasExternalEncoder;
- private readonly string _originalFFMpegPath;
- private readonly string _originalFFProbePath;
- private readonly int DefaultImageExtractionTimeoutMs;
+ private readonly ILocalizationManager _localization;
public MediaEncoder(
ILoggerFactory loggerFactory,
IJsonSerializer jsonSerializer,
- string ffMpegPath,
- string ffProbePath,
- bool hasExternalEncoder,
+ string startupOptionsFFmpegPath,
IServerConfigurationManager configurationManager,
IFileSystem fileSystem,
- ILiveTvManager liveTvManager,
- IIsoManager isoManager,
- ILibraryManager libraryManager,
- IChannelManager channelManager,
- ISessionManager sessionManager,
Func<ISubtitleEncoder> subtitleEncoder,
Func<IMediaSourceManager> mediaSourceManager,
- IHttpClient httpClient,
- IZipClient zipClient,
IProcessFactory processFactory,
- int defaultImageExtractionTimeoutMs)
+ int defaultImageExtractionTimeoutMs,
+ ILocalizationManager localization)
{
_logger = loggerFactory.CreateLogger(nameof(MediaEncoder));
_jsonSerializer = jsonSerializer;
+ StartupOptionFFmpegPath = startupOptionsFFmpegPath;
ConfigurationManager = configurationManager;
FileSystem = fileSystem;
- LiveTvManager = liveTvManager;
- IsoManager = isoManager;
- LibraryManager = libraryManager;
- ChannelManager = channelManager;
- SessionManager = sessionManager;
SubtitleEncoder = subtitleEncoder;
- MediaSourceManager = mediaSourceManager;
- _httpClient = httpClient;
- _zipClient = zipClient;
_processFactory = processFactory;
DefaultImageExtractionTimeoutMs = defaultImageExtractionTimeoutMs;
- FFProbePath = ffProbePath;
- FFMpegPath = ffMpegPath;
- _originalFFProbePath = ffProbePath;
- _originalFFMpegPath = ffMpegPath;
- _hasExternalEncoder = hasExternalEncoder;
+ _localization = localization;
}
- public string EncoderLocationType
+ /// <summary>
+ /// Run at startup or if the user removes a Custom path from transcode page.
+ /// Sets global variables FFmpegPath.
+ /// Precedence is: Config > CLI > $PATH
+ /// </summary>
+ public void SetFFmpegPath()
{
- get
+ // 1) Custom path stored in config/encoding xml file under tag <EncoderAppPath> takes precedence
+ if (!ValidatePath(ConfigurationManager.GetConfiguration<EncodingOptions>("encoding").EncoderAppPath, FFmpegLocation.Custom))
{
- if (_hasExternalEncoder)
- {
- return "External";
- }
-
- if (string.IsNullOrWhiteSpace(FFMpegPath))
+ // 2) Check if the --ffmpeg CLI switch has been given
+ if (!ValidatePath(StartupOptionFFmpegPath, FFmpegLocation.SetByArgument))
{
- return null;
- }
-
- if (IsSystemInstalledPath(FFMpegPath))
- {
- return "System";
+ // 3) Search system $PATH environment variable for valid FFmpeg
+ if (!ValidatePath(ExistsOnSystemPath("ffmpeg"), FFmpegLocation.System))
+ {
+ EncoderLocation = FFmpegLocation.NotFound;
+ FFmpegPath = null;
+ }
}
-
- return "Custom";
}
- }
- private bool IsSystemInstalledPath(string path)
- {
- if (path.IndexOf("/", StringComparison.Ordinal) == -1 && path.IndexOf("\\", StringComparison.Ordinal) == -1)
- {
- return true;
- }
-
- return false;
- }
-
- public void Init()
- {
- InitPaths();
+ // Write the FFmpeg path to the config/encoding.xml file as <EncoderAppPathDisplay> so it appears in UI
+ var config = ConfigurationManager.GetConfiguration<EncodingOptions>("encoding");
+ config.EncoderAppPathDisplay = FFmpegPath ?? string.Empty;
+ ConfigurationManager.SaveConfiguration("encoding", config);
- if (!string.IsNullOrWhiteSpace(FFMpegPath))
+ // Only if mpeg path is set, try and set path to probe
+ if (FFmpegPath != null)
{
- var result = new EncoderValidator(_logger, _processFactory).Validate(FFMpegPath);
+ // Determine a probe path from the mpeg path
+ FFprobePath = Regex.Replace(FFmpegPath, @"[^\/\\]+?(\.[^\/\\\n.]+)?$", @"ffprobe$1");
+
+ // Interrogate to understand what coders are supported
+ var result = new EncoderValidator(_logger, _processFactory).GetAvailableCoders(FFmpegPath);
SetAvailableDecoders(result.decoders);
SetAvailableEncoders(result.encoders);
}
- }
-
- private void InitPaths()
- {
- ConfigureEncoderPaths();
-
- if (_hasExternalEncoder)
- {
- LogPaths();
- return;
- }
-
- // If the path was passed in, save it into config now.
- var encodingOptions = GetEncodingOptions();
- var appPath = encodingOptions.EncoderAppPath;
- var valueToSave = FFMpegPath;
-
- if (!string.IsNullOrWhiteSpace(valueToSave))
- {
- // if using system variable, don't save this.
- if (IsSystemInstalledPath(valueToSave) || _hasExternalEncoder)
- {
- valueToSave = null;
- }
- }
-
- if (!string.Equals(valueToSave, appPath, StringComparison.Ordinal))
- {
- encodingOptions.EncoderAppPath = valueToSave;
- ConfigurationManager.SaveConfiguration("encoding", encodingOptions);
- }
+ _logger.LogInformation("FFmpeg: {0}: {1}", EncoderLocation.ToString(), FFmpegPath ?? string.Empty);
}
+ /// <summary>
+ /// Triggered from the Settings > Transcoding UI page when users submits Custom FFmpeg path to use.
+ /// Only write the new path to xml if it exists. Do not perform validation checks on ffmpeg here.
+ /// </summary>
+ /// <param name="path"></param>
+ /// <param name="pathType"></param>
public void UpdateEncoderPath(string path, string pathType)
{
- if (_hasExternalEncoder)
- {
- return;
- }
+ string newPath;
_logger.LogInformation("Attempting to update encoder path to {0}. pathType: {1}", path ?? string.Empty, pathType ?? string.Empty);
- Tuple<string, string> newPaths;
-
- if (string.Equals(pathType, "system", StringComparison.OrdinalIgnoreCase))
- {
- path = "ffmpeg";
-
- newPaths = TestForInstalledVersions();
- }
- else if (string.Equals(pathType, "custom", StringComparison.OrdinalIgnoreCase))
+ if (!string.Equals(pathType, "custom", StringComparison.OrdinalIgnoreCase))
{
- if (string.IsNullOrWhiteSpace(path))
- {
- throw new ArgumentNullException(nameof(path));
- }
-
- if (!File.Exists(path) && !Directory.Exists(path))
- {
- throw new ResourceNotFoundException();
- }
- newPaths = GetEncoderPaths(path);
+ throw new ArgumentException("Unexpected pathType value");
}
- else
+ else if (string.IsNullOrWhiteSpace(path))
{
- throw new ArgumentException("Unexpected pathType value");
+ // User had cleared the custom path in UI
+ newPath = string.Empty;
}
-
- if (string.IsNullOrWhiteSpace(newPaths.Item1))
+ else if (File.Exists(path))
{
- throw new ResourceNotFoundException("ffmpeg not found");
+ newPath = path;
}
- if (string.IsNullOrWhiteSpace(newPaths.Item2))
+ else if (Directory.Exists(path))
{
- throw new ResourceNotFoundException("ffprobe not found");
+ // Given path is directory, so resolve down to filename
+ newPath = GetEncoderPathFromDirectory(path, "ffmpeg");
}
-
- path = newPaths.Item1;
-
- if (!ValidateVersion(path, true))
+ else
{
- throw new ResourceNotFoundException("ffmpeg version 3.0 or greater is required.");
+ throw new ResourceNotFoundException();
}
- var config = GetEncodingOptions();
- config.EncoderAppPath = path;
+ // Write the new ffmpeg path to the xml as <EncoderAppPath>
+ // This ensures its not lost on next startup
+ var config = ConfigurationManager.GetConfiguration<EncodingOptions>("encoding");
+ config.EncoderAppPath = newPath;
ConfigurationManager.SaveConfiguration("encoding", config);
- Init();
+ // Trigger SetFFmpegPath so we validate the new path and setup probe path
+ SetFFmpegPath();
}
- private bool ValidateVersion(string path, bool logOutput)
+ /// <summary>
+ /// Validates the supplied FQPN to ensure it is a ffmpeg utility.
+ /// If checks pass, global variable FFmpegPath and EncoderLocation are updated.
+ /// </summary>
+ /// <param name="path">FQPN to test</param>
+ /// <param name="location">Location (External, Custom, System) of tool</param>
+ /// <returns></returns>
+ private bool ValidatePath(string path, FFmpegLocation location)
{
- return new EncoderValidator(_logger, _processFactory).ValidateVersion(path, logOutput);
- }
+ bool rc = false;
- private void ConfigureEncoderPaths()
- {
- if (_hasExternalEncoder)
+ if (!string.IsNullOrEmpty(path))
{
- return;
- }
-
- var appPath = GetEncodingOptions().EncoderAppPath;
-
- if (string.IsNullOrWhiteSpace(appPath))
- {
- appPath = Path.Combine(ConfigurationManager.ApplicationPaths.ProgramDataPath, "ffmpeg");
- }
-
- var newPaths = GetEncoderPaths(appPath);
- if (string.IsNullOrWhiteSpace(newPaths.Item1) || string.IsNullOrWhiteSpace(newPaths.Item2) || IsSystemInstalledPath(appPath))
- {
- newPaths = TestForInstalledVersions();
- }
-
- if (!string.IsNullOrWhiteSpace(newPaths.Item1) && !string.IsNullOrWhiteSpace(newPaths.Item2))
- {
- FFMpegPath = newPaths.Item1;
- FFProbePath = newPaths.Item2;
- }
+ if (File.Exists(path))
+ {
+ rc = new EncoderValidator(_logger, _processFactory).ValidateVersion(path, true);
- LogPaths();
- }
+ if (!rc)
+ {
+ _logger.LogWarning("FFmpeg: {0}: Failed version check: {1}", location.ToString(), path);
+ }
- private Tuple<string, string> GetEncoderPaths(string configuredPath)
- {
- var appPath = configuredPath;
+ // ToDo - Enable the ffmpeg validator. At the moment any version can be used.
+ rc = true;
- if (!string.IsNullOrWhiteSpace(appPath))
- {
- if (Directory.Exists(appPath))
- {
- return GetPathsFromDirectory(appPath);
+ FFmpegPath = path;
+ EncoderLocation = location;
}
-
- if (File.Exists(appPath))
+ else
{
- return new Tuple<string, string>(appPath, GetProbePathFromEncoderPath(appPath));
+ _logger.LogWarning("FFmpeg: {0}: File not found: {1}", location.ToString(), path);
}
}
- return new Tuple<string, string>(null, null);
+ return rc;
}
- private Tuple<string, string> TestForInstalledVersions()
+ private string GetEncoderPathFromDirectory(string path, string filename)
{
- string encoderPath = null;
- string probePath = null;
-
- if (_hasExternalEncoder && ValidateVersion(_originalFFMpegPath, true))
+ try
{
- encoderPath = _originalFFMpegPath;
- probePath = _originalFFProbePath;
- }
+ var files = FileSystem.GetFilePaths(path);
+
+ var excludeExtensions = new[] { ".c" };
- if (string.IsNullOrWhiteSpace(encoderPath))
+ return files.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), filename, StringComparison.OrdinalIgnoreCase)
+ && !excludeExtensions.Contains(Path.GetExtension(i) ?? string.Empty));
+ }
+ catch (Exception)
{
- if (ValidateVersion("ffmpeg", true) && ValidateVersion("ffprobe", false))
- {
- encoderPath = "ffmpeg";
- probePath = "ffprobe";
- }
+ // Trap all exceptions, like DirNotExists, and return null
+ return null;
}
-
- return new Tuple<string, string>(encoderPath, probePath);
}
- private Tuple<string, string> GetPathsFromDirectory(string path)
+ /// <summary>
+ /// Search the system $PATH environment variable looking for given filename.
+ /// </summary>
+ /// <param name="fileName"></param>
+ /// <returns></returns>
+ private string ExistsOnSystemPath(string filename)
{
- // Since we can't predict the file extension, first try directly within the folder
- // If that doesn't pan out, then do a recursive search
- var files = FileSystem.GetFilePaths(path);
-
- var excludeExtensions = new[] { ".c" };
+ var values = Environment.GetEnvironmentVariable("PATH");
- var ffmpegPath = files.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffmpeg", StringComparison.OrdinalIgnoreCase) && !excludeExtensions.Contains(Path.GetExtension(i) ?? string.Empty));
- var ffprobePath = files.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffprobe", StringComparison.OrdinalIgnoreCase) && !excludeExtensions.Contains(Path.GetExtension(i) ?? string.Empty));
-
- if (string.IsNullOrWhiteSpace(ffmpegPath) || !File.Exists(ffmpegPath))
+ foreach (var path in values.Split(Path.PathSeparator))
{
- files = FileSystem.GetFilePaths(path, true);
-
- ffmpegPath = files.FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffmpeg", StringComparison.OrdinalIgnoreCase) && !excludeExtensions.Contains(Path.GetExtension(i) ?? string.Empty));
+ var candidatePath = GetEncoderPathFromDirectory(path, filename);
- if (!string.IsNullOrWhiteSpace(ffmpegPath))
+ if (!string.IsNullOrEmpty(candidatePath))
{
- ffprobePath = GetProbePathFromEncoderPath(ffmpegPath);
+ return candidatePath;
}
}
-
- return new Tuple<string, string>(ffmpegPath, ffprobePath);
- }
-
- private string GetProbePathFromEncoderPath(string appPath)
- {
- return FileSystem.GetFilePaths(Path.GetDirectoryName(appPath))
- .FirstOrDefault(i => string.Equals(Path.GetFileNameWithoutExtension(i), "ffprobe", StringComparison.OrdinalIgnoreCase));
- }
-
- private void LogPaths()
- {
- _logger.LogInformation("FFMpeg: {0}", FFMpegPath ?? "not found");
- _logger.LogInformation("FFProbe: {0}", FFProbePath ?? "not found");
- }
-
- private EncodingOptions GetEncodingOptions()
- {
- return ConfigurationManager.GetConfiguration<EncodingOptions>("encoding");
+ return null;
}
private List<string> _encoders = new List<string>();
@@ -413,12 +289,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
/// <summary>
- /// Gets the encoder path.
- /// </summary>
- /// <value>The encoder path.</value>
- public string EncoderPath => FFMpegPath;
-
- /// <summary>
/// Gets the media info.
/// </summary>
/// <param name="request">The request.</param>
@@ -459,10 +329,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
/// <param name="protocol">The protocol.</param>
/// <returns>System.String.</returns>
/// <exception cref="ArgumentException">Unrecognized InputType</exception>
- public string GetInputArgument(string[] inputFiles, MediaProtocol protocol)
- {
- return EncodingUtils.GetInputArgument(inputFiles.ToList(), protocol);
- }
+ public string GetInputArgument(IReadOnlyList<string> inputFiles, MediaProtocol protocol)
+ => EncodingUtils.GetInputArgument(inputFiles, protocol);
/// <summary>
/// Gets the media info internal.
@@ -479,8 +347,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
CancellationToken cancellationToken)
{
var args = extractChapters
- ? "{0} -i {1} -threads 0 -v info -print_format json -show_streams -show_chapters -show_format"
- : "{0} -i {1} -threads 0 -v info -print_format json -show_streams -show_format";
+ ? "{0} -i {1} -threads 0 -v warning -print_format json -show_streams -show_chapters -show_format"
+ : "{0} -i {1} -threads 0 -v warning -print_format json -show_streams -show_format";
+ args = string.Format(args, probeSizeArgument, inputPath).Trim();
var process = _processFactory.Create(new ProcessOptions
{
@@ -489,8 +358,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
// Must consume both or ffmpeg may hang due to deadlocks. See comments below.
RedirectStandardOutput = true,
- FileName = FFProbePath,
- Arguments = string.Format(args, probeSizeArgument, inputPath).Trim(),
+
+ FileName = FFprobePath,
+ Arguments = args,
+
IsHidden = true,
ErrorDialog = false,
@@ -508,43 +379,45 @@ namespace MediaBrowser.MediaEncoding.Encoder
using (var processWrapper = new ProcessWrapper(process, this, _logger))
{
+ _logger.LogDebug("Starting ffprobe with args {Args}", args);
StartProcess(processWrapper);
+ InternalMediaInfoResult result;
try
{
- //process.BeginErrorReadLine();
+ result = await _jsonSerializer.DeserializeFromStreamAsync<InternalMediaInfoResult>(
+ process.StandardOutput.BaseStream).ConfigureAwait(false);
+ }
+ catch
+ {
+ StopProcess(processWrapper, 100);
- var result = await _jsonSerializer.DeserializeFromStreamAsync<InternalMediaInfoResult>(process.StandardOutput.BaseStream).ConfigureAwait(false);
+ throw;
+ }
- if (result == null || (result.streams == null && result.format == null))
- {
- throw new Exception("ffprobe failed - streams and format are both null.");
- }
+ if (result == null || (result.streams == null && result.format == null))
+ {
+ throw new Exception("ffprobe failed - streams and format are both null.");
+ }
- if (result.streams != null)
+ if (result.streams != null)
+ {
+ // Normalize aspect ratio if invalid
+ foreach (var stream in result.streams)
{
- // Normalize aspect ratio if invalid
- foreach (var stream in result.streams)
+ if (string.Equals(stream.display_aspect_ratio, "0:1", StringComparison.OrdinalIgnoreCase))
{
- if (string.Equals(stream.display_aspect_ratio, "0:1", StringComparison.OrdinalIgnoreCase))
- {
- stream.display_aspect_ratio = string.Empty;
- }
- if (string.Equals(stream.sample_aspect_ratio, "0:1", StringComparison.OrdinalIgnoreCase))
- {
- stream.sample_aspect_ratio = string.Empty;
- }
+ stream.display_aspect_ratio = string.Empty;
}
- }
- return new ProbeResultNormalizer(_logger, FileSystem).GetMediaInfo(result, videoType, isAudio, primaryPath, protocol);
+ if (string.Equals(stream.sample_aspect_ratio, "0:1", StringComparison.OrdinalIgnoreCase))
+ {
+ stream.sample_aspect_ratio = string.Empty;
+ }
+ }
}
- catch
- {
- StopProcess(processWrapper, 100);
- throw;
- }
+ return new ProbeResultNormalizer(_logger, FileSystem, _localization).GetMediaInfo(result, videoType, isAudio, primaryPath, protocol);
}
}
@@ -691,10 +564,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
CreateNoWindow = true,
UseShellExecute = false,
- FileName = FFMpegPath,
+ FileName = FFmpegPath,
Arguments = args,
IsHidden = true,
- ErrorDialog = false
+ ErrorDialog = false,
+ EnableRaisingEvents = true
});
_logger.LogDebug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
@@ -813,10 +687,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
CreateNoWindow = true,
UseShellExecute = false,
- FileName = FFMpegPath,
+ FileName = FFmpegPath,
Arguments = args,
IsHidden = true,
- ErrorDialog = false
+ ErrorDialog = false,
+ EnableRaisingEvents = true
});
_logger.LogInformation(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj
index 68b8bd4fa..e4757543e 100644
--- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj
+++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj
@@ -14,7 +14,6 @@
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
- <ProjectReference Include="..\OpenSubtitlesHandler\OpenSubtitlesHandler.csproj" />
</ItemGroup>
<ItemGroup>
diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs
index 5099ccb2a..54d02fc9f 100644
--- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs
+++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs
@@ -9,6 +9,7 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
+using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using Microsoft.Extensions.Logging;
@@ -20,11 +21,13 @@ namespace MediaBrowser.MediaEncoding.Probing
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly ILogger _logger;
private readonly IFileSystem _fileSystem;
+ private readonly ILocalizationManager _localization;
- public ProbeResultNormalizer(ILogger logger, IFileSystem fileSystem)
+ public ProbeResultNormalizer(ILogger logger, IFileSystem fileSystem, ILocalizationManager localization)
{
_logger = logger;
_fileSystem = fileSystem;
+ _localization = localization;
}
public MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType? videoType, bool isAudio, string path, MediaProtocol protocol)
@@ -246,52 +249,49 @@ namespace MediaBrowser.MediaEncoding.Probing
// <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>cast</key>\n\t<array>\n\t\t<dict>\n\t\t\t<key>name</key>\n\t\t\t<string>Blender Foundation</string>\n\t\t</dict>\n\t\t<dict>\n\t\t\t<key>name</key>\n\t\t\t<string>Janus Bager Kristensen</string>\n\t\t</dict>\n\t</array>\n\t<key>directors</key>\n\t<array>\n\t\t<dict>\n\t\t\t<key>name</key>\n\t\t\t<string>Sacha Goedegebure</string>\n\t\t</dict>\n\t</array>\n\t<key>studio</key>\n\t<string>Blender Foundation</string>\n</dict>\n</plist>\n
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
+ using (var streamReader = new StreamReader(stream))
{
- using (var streamReader = new StreamReader(stream))
+ try
{
- try
+ using (var reader = XmlReader.Create(streamReader))
{
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader))
- {
- reader.MoveToContent();
- reader.Read();
+ reader.MoveToContent();
+ reader.Read();
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
+ // Loop through each element
+ while (!reader.EOF && reader.ReadState == ReadState.Interactive)
+ {
+ if (reader.NodeType == XmlNodeType.Element)
{
- if (reader.NodeType == XmlNodeType.Element)
+ switch (reader.Name)
{
- switch (reader.Name)
- {
- case "dict":
- if (reader.IsEmptyElement)
- {
- reader.Read();
- continue;
- }
- using (var subtree = reader.ReadSubtree())
- {
- ReadFromDictNode(subtree, info);
- }
- break;
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
+ case "dict":
+ if (reader.IsEmptyElement)
+ {
+ reader.Read();
+ continue;
+ }
+ using (var subtree = reader.ReadSubtree())
+ {
+ ReadFromDictNode(subtree, info);
+ }
+ break;
+ default:
+ reader.Skip();
+ break;
}
}
+ else
+ {
+ reader.Read();
+ }
}
}
- catch (XmlException)
- {
- // I've seen probe examples where the iTunMOVI value is just "<"
- // So we should not allow this to fail the entire probing operation
- }
+ }
+ catch (XmlException)
+ {
+ // I've seen probe examples where the iTunMOVI value is just "<"
+ // So we should not allow this to fail the entire probing operation
}
}
}
@@ -599,6 +599,9 @@ namespace MediaBrowser.MediaEncoding.Probing
{
stream.Type = MediaStreamType.Subtitle;
stream.Codec = NormalizeSubtitleCodec(stream.Codec);
+ stream.localizedUndefined = _localization.GetLocalizedString("Undefined");
+ stream.localizedDefault = _localization.GetLocalizedString("Default");
+ stream.localizedForced = _localization.GetLocalizedString("Forced");
}
else if (string.Equals(streamInfo.codec_type, "video", StringComparison.OrdinalIgnoreCase))
{
diff --git a/MediaBrowser.MediaEncoding/Properties/AssemblyInfo.cs b/MediaBrowser.MediaEncoding/Properties/AssemblyInfo.cs
index 6ecdf89bc..a9491374b 100644
--- a/MediaBrowser.MediaEncoding/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.MediaEncoding/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/MediaBrowser.MediaEncoding/Subtitles/ConfigurationExtension.cs b/MediaBrowser.MediaEncoding/Subtitles/ConfigurationExtension.cs
deleted file mode 100644
index 92544f4f6..000000000
--- a/MediaBrowser.MediaEncoding/Subtitles/ConfigurationExtension.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System.Collections.Generic;
-using MediaBrowser.Common.Configuration;
-using MediaBrowser.Model.Providers;
-
-namespace MediaBrowser.MediaEncoding.Subtitles
-{
- public static class ConfigurationExtension
- {
- public static SubtitleOptions GetSubtitleConfiguration(this IConfigurationManager manager)
- {
- return manager.GetConfiguration<SubtitleOptions>("subtitles");
- }
- }
-
- public class SubtitleConfigurationFactory : IConfigurationFactory
- {
- public IEnumerable<ConfigurationStore> GetConfigurations()
- {
- return new List<ConfigurationStore>
- {
- new ConfigurationStore
- {
- Key = "subtitles",
- ConfigurationType = typeof (SubtitleOptions)
- }
- };
- }
- }
-}
diff --git a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs
deleted file mode 100644
index 6a5162b8d..000000000
--- a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs
+++ /dev/null
@@ -1,346 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using MediaBrowser.Common.Configuration;
-using MediaBrowser.Common.Extensions;
-using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Providers;
-using MediaBrowser.Controller.Security;
-using MediaBrowser.Controller.Subtitles;
-using MediaBrowser.Model.Dto;
-using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Providers;
-using MediaBrowser.Model.Serialization;
-using Microsoft.Extensions.Logging;
-using OpenSubtitlesHandler;
-
-namespace MediaBrowser.MediaEncoding.Subtitles
-{
- public class OpenSubtitleDownloader : ISubtitleProvider, IDisposable
- {
- private readonly ILogger _logger;
- private readonly IHttpClient _httpClient;
- private readonly CultureInfo _usCulture = new CultureInfo("en-US");
-
- private readonly IServerConfigurationManager _config;
- private readonly IEncryptionManager _encryption;
-
- private readonly IJsonSerializer _json;
- private readonly IFileSystem _fileSystem;
-
- public OpenSubtitleDownloader(ILoggerFactory loggerFactory, IHttpClient httpClient, IServerConfigurationManager config, IEncryptionManager encryption, IJsonSerializer json, IFileSystem fileSystem)
- {
- _logger = loggerFactory.CreateLogger(GetType().Name);
- _httpClient = httpClient;
- _config = config;
- _encryption = encryption;
- _json = json;
- _fileSystem = fileSystem;
-
- _config.NamedConfigurationUpdating += _config_NamedConfigurationUpdating;
-
- Utilities.HttpClient = httpClient;
- OpenSubtitles.SetUserAgent("jellyfin");
- }
-
- private const string PasswordHashPrefix = "h:";
- void _config_NamedConfigurationUpdating(object sender, ConfigurationUpdateEventArgs e)
- {
- if (!string.Equals(e.Key, "subtitles", StringComparison.OrdinalIgnoreCase))
- {
- return;
- }
-
- var options = (SubtitleOptions)e.NewConfiguration;
-
- if (options != null &&
- !string.IsNullOrWhiteSpace(options.OpenSubtitlesPasswordHash) &&
- !options.OpenSubtitlesPasswordHash.StartsWith(PasswordHashPrefix, StringComparison.OrdinalIgnoreCase))
- {
- options.OpenSubtitlesPasswordHash = EncryptPassword(options.OpenSubtitlesPasswordHash);
- }
- }
-
- private string EncryptPassword(string password)
- {
- return PasswordHashPrefix + _encryption.EncryptString(password);
- }
-
- private string DecryptPassword(string password)
- {
- if (password == null ||
- !password.StartsWith(PasswordHashPrefix, StringComparison.OrdinalIgnoreCase))
- {
- return string.Empty;
- }
-
- return _encryption.DecryptString(password.Substring(2));
- }
-
- public string Name => "Open Subtitles";
-
- private SubtitleOptions GetOptions()
- {
- return _config.GetSubtitleConfiguration();
- }
-
- public IEnumerable<VideoContentType> SupportedMediaTypes
- {
- get
- {
- var options = GetOptions();
-
- if (string.IsNullOrWhiteSpace(options.OpenSubtitlesUsername) ||
- string.IsNullOrWhiteSpace(options.OpenSubtitlesPasswordHash))
- {
- return new VideoContentType[] { };
- }
-
- return new[] { VideoContentType.Episode, VideoContentType.Movie };
- }
- }
-
- public Task<SubtitleResponse> GetSubtitles(string id, CancellationToken cancellationToken)
- {
- return GetSubtitlesInternal(id, GetOptions(), cancellationToken);
- }
-
- private DateTime _lastRateLimitException;
- private async Task<SubtitleResponse> GetSubtitlesInternal(string id,
- SubtitleOptions options,
- CancellationToken cancellationToken)
- {
- if (string.IsNullOrWhiteSpace(id))
- {
- throw new ArgumentNullException(nameof(id));
- }
-
- var idParts = id.Split(new[] { '-' }, 3);
-
- var format = idParts[0];
- var language = idParts[1];
- var ossId = idParts[2];
-
- var downloadsList = new[] { int.Parse(ossId, _usCulture) };
-
- await Login(cancellationToken).ConfigureAwait(false);
-
- if ((DateTime.UtcNow - _lastRateLimitException).TotalHours < 1)
- {
- throw new RateLimitExceededException("OpenSubtitles rate limit reached");
- }
-
- var resultDownLoad = await OpenSubtitles.DownloadSubtitlesAsync(downloadsList, cancellationToken).ConfigureAwait(false);
-
- if ((resultDownLoad.Status ?? string.Empty).IndexOf("407", StringComparison.OrdinalIgnoreCase) != -1)
- {
- _lastRateLimitException = DateTime.UtcNow;
- throw new RateLimitExceededException("OpenSubtitles rate limit reached");
- }
-
- if (!(resultDownLoad is MethodResponseSubtitleDownload))
- {
- throw new Exception("Invalid response type");
- }
-
- var results = ((MethodResponseSubtitleDownload)resultDownLoad).Results;
-
- _lastRateLimitException = DateTime.MinValue;
-
- if (results.Count == 0)
- {
- var msg = string.Format("Subtitle with Id {0} was not found. Name: {1}. Status: {2}. Message: {3}",
- ossId,
- resultDownLoad.Name ?? string.Empty,
- resultDownLoad.Status ?? string.Empty,
- resultDownLoad.Message ?? string.Empty);
-
- throw new ResourceNotFoundException(msg);
- }
-
- var data = Convert.FromBase64String(results.First().Data);
-
- return new SubtitleResponse
- {
- Format = format,
- Language = language,
-
- Stream = new MemoryStream(Utilities.Decompress(new MemoryStream(data)))
- };
- }
-
- private DateTime _lastLogin;
- private async Task Login(CancellationToken cancellationToken)
- {
- if ((DateTime.UtcNow - _lastLogin).TotalSeconds < 60)
- {
- return;
- }
-
- var options = GetOptions();
-
- var user = options.OpenSubtitlesUsername ?? string.Empty;
- var password = DecryptPassword(options.OpenSubtitlesPasswordHash);
-
- var loginResponse = await OpenSubtitles.LogInAsync(user, password, "en", cancellationToken).ConfigureAwait(false);
-
- if (!(loginResponse is MethodResponseLogIn))
- {
- throw new Exception("Authentication to OpenSubtitles failed.");
- }
-
- _lastLogin = DateTime.UtcNow;
- }
-
- public async Task<IEnumerable<NameIdPair>> GetSupportedLanguages(CancellationToken cancellationToken)
- {
- await Login(cancellationToken).ConfigureAwait(false);
-
- var result = OpenSubtitles.GetSubLanguages("en");
- if (!(result is MethodResponseGetSubLanguages))
- {
- _logger.LogError("Invalid response type");
- return new List<NameIdPair>();
- }
-
- var results = ((MethodResponseGetSubLanguages)result).Languages;
-
- return results.Select(i => new NameIdPair
- {
- Name = i.LanguageName,
- Id = i.SubLanguageID
- });
- }
-
- private string NormalizeLanguage(string language)
- {
- // Problem with Greek subtitle download #1349
- if (string.Equals(language, "gre", StringComparison.OrdinalIgnoreCase))
- {
-
- return "ell";
- }
-
- return language;
- }
-
- public async Task<IEnumerable<RemoteSubtitleInfo>> Search(SubtitleSearchRequest request, CancellationToken cancellationToken)
- {
- var imdbIdText = request.GetProviderId(MetadataProviders.Imdb);
- long imdbId = 0;
-
- switch (request.ContentType)
- {
- case VideoContentType.Episode:
- if (!request.IndexNumber.HasValue || !request.ParentIndexNumber.HasValue || string.IsNullOrEmpty(request.SeriesName))
- {
- _logger.LogDebug("Episode information missing");
- return new List<RemoteSubtitleInfo>();
- }
- break;
- case VideoContentType.Movie:
- if (string.IsNullOrEmpty(request.Name))
- {
- _logger.LogDebug("Movie name missing");
- return new List<RemoteSubtitleInfo>();
- }
- if (string.IsNullOrWhiteSpace(imdbIdText) || !long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId))
- {
- _logger.LogDebug("Imdb id missing");
- return new List<RemoteSubtitleInfo>();
- }
- break;
- }
-
- if (string.IsNullOrEmpty(request.MediaPath))
- {
- _logger.LogDebug("Path Missing");
- return new List<RemoteSubtitleInfo>();
- }
-
- await Login(cancellationToken).ConfigureAwait(false);
-
- var subLanguageId = NormalizeLanguage(request.Language);
- string hash;
-
- using (var fileStream = File.OpenRead(request.MediaPath))
- {
- hash = Utilities.ComputeHash(fileStream);
- }
- var fileInfo = _fileSystem.GetFileInfo(request.MediaPath);
- var movieByteSize = fileInfo.Length;
- var searchImdbId = request.ContentType == VideoContentType.Movie ? imdbId.ToString(_usCulture) : "";
- var subtitleSearchParameters = request.ContentType == VideoContentType.Episode
- ? new List<SubtitleSearchParameters> {
- new SubtitleSearchParameters(subLanguageId,
- query: request.SeriesName,
- season: request.ParentIndexNumber.Value.ToString(_usCulture),
- episode: request.IndexNumber.Value.ToString(_usCulture))
- }
- : new List<SubtitleSearchParameters> {
- new SubtitleSearchParameters(subLanguageId, imdbid: searchImdbId),
- new SubtitleSearchParameters(subLanguageId, query: request.Name, imdbid: searchImdbId)
- };
- var parms = new List<SubtitleSearchParameters> {
- new SubtitleSearchParameters( subLanguageId,
- movieHash: hash,
- movieByteSize: movieByteSize,
- imdbid: searchImdbId ),
- };
- parms.AddRange(subtitleSearchParameters);
- var result = await OpenSubtitles.SearchSubtitlesAsync(parms.ToArray(), cancellationToken).ConfigureAwait(false);
- if (!(result is MethodResponseSubtitleSearch))
- {
- _logger.LogError("Invalid response type");
- return new List<RemoteSubtitleInfo>();
- }
-
- Predicate<SubtitleSearchResult> mediaFilter =
- x =>
- request.ContentType == VideoContentType.Episode
- ? !string.IsNullOrEmpty(x.SeriesSeason) && !string.IsNullOrEmpty(x.SeriesEpisode) &&
- int.Parse(x.SeriesSeason, _usCulture) == request.ParentIndexNumber &&
- int.Parse(x.SeriesEpisode, _usCulture) == request.IndexNumber
- : !string.IsNullOrEmpty(x.IDMovieImdb) && long.Parse(x.IDMovieImdb, _usCulture) == imdbId;
-
- var results = ((MethodResponseSubtitleSearch)result).Results;
-
- // Avoid implicitly captured closure
- var hasCopy = hash;
-
- return results.Where(x => x.SubBad == "0" && mediaFilter(x) && (!request.IsPerfectMatch || string.Equals(x.MovieHash, hash, StringComparison.OrdinalIgnoreCase)))
- .OrderBy(x => (string.Equals(x.MovieHash, hash, StringComparison.OrdinalIgnoreCase) ? 0 : 1))
- .ThenBy(x => Math.Abs(long.Parse(x.MovieByteSize, _usCulture) - movieByteSize))
- .ThenByDescending(x => int.Parse(x.SubDownloadsCnt, _usCulture))
- .ThenByDescending(x => double.Parse(x.SubRating, _usCulture))
- .Select(i => new RemoteSubtitleInfo
- {
- Author = i.UserNickName,
- Comment = i.SubAuthorComment,
- CommunityRating = float.Parse(i.SubRating, _usCulture),
- DownloadCount = int.Parse(i.SubDownloadsCnt, _usCulture),
- Format = i.SubFormat,
- ProviderName = Name,
- ThreeLetterISOLanguageName = i.SubLanguageID,
-
- Id = i.SubFormat + "-" + i.SubLanguageID + "-" + i.IDSubtitleFile,
-
- Name = i.SubFileName,
- DateCreated = DateTime.Parse(i.SubAddDate, _usCulture),
- IsHashMatch = i.MovieHash == hasCopy
-
- }).Where(i => !string.Equals(i.Format, "sub", StringComparison.OrdinalIgnoreCase) && !string.Equals(i.Format, "idx", StringComparison.OrdinalIgnoreCase));
- }
-
- public void Dispose()
- {
- _config.NamedConfigurationUpdating -= _config_NamedConfigurationUpdating;
- }
- }
-}
diff --git a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs
index ce4ef1cfe..6a1a0f090 100644
--- a/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs
+++ b/MediaBrowser.Model/Configuration/BaseApplicationConfiguration.cs
@@ -7,20 +7,6 @@ namespace MediaBrowser.Model.Configuration
/// </summary>
public class BaseApplicationConfiguration
{
- // TODO: @bond Remove?
- /// <summary>
- /// Gets or sets a value indicating whether [enable debug level logging].
- /// </summary>
- /// <value><c>true</c> if [enable debug level logging]; otherwise, <c>false</c>.</value>
- public bool EnableDebugLevelLogging { get; set; }
-
- /// <summary>
- /// Enable automatically and silently updating of the application
- /// </summary>
- /// <value><c>true</c> if [enable auto update]; otherwise, <c>false</c>.</value>
- public bool EnableAutoUpdate { get; set; }
-
- // TODO: @bond Remove?
/// <summary>
/// The number of days we should retain log files
/// </summary>
@@ -44,7 +30,6 @@ namespace MediaBrowser.Model.Configuration
/// </summary>
public BaseApplicationConfiguration()
{
- EnableAutoUpdate = true;
LogFileRetentionDays = 3;
}
}
diff --git a/MediaBrowser.Model/Configuration/EncodingOptions.cs b/MediaBrowser.Model/Configuration/EncodingOptions.cs
index 8584bd3dd..285ff4ba5 100644
--- a/MediaBrowser.Model/Configuration/EncodingOptions.cs
+++ b/MediaBrowser.Model/Configuration/EncodingOptions.cs
@@ -8,7 +8,14 @@ namespace MediaBrowser.Model.Configuration
public bool EnableThrottling { get; set; }
public int ThrottleDelaySeconds { get; set; }
public string HardwareAccelerationType { get; set; }
+ /// <summary>
+ /// FFmpeg path as set by the user via the UI
+ /// </summary>
public string EncoderAppPath { get; set; }
+ /// <summary>
+ /// The current FFmpeg path being used by the system and displayed on the transcode page
+ /// </summary>
+ public string EncoderAppPathDisplay { get; set; }
public string VaapiDevice { get; set; }
public int H264Crf { get; set; }
public string H264Preset { get; set; }
diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
index ed5800329..0ba36b4b9 100644
--- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs
+++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
@@ -178,6 +178,7 @@ namespace MediaBrowser.Model.Configuration
public string[] LocalNetworkSubnets { get; set; }
public string[] LocalNetworkAddresses { get; set; }
public string[] CodecsUsed { get; set; }
+ public bool IgnoreVirtualInterfaces { get; set; }
public bool EnableExternalContentInSuggestions { get; set; }
public bool RequireHttps { get; set; }
public bool IsBehindProxy { get; set; }
@@ -205,6 +206,7 @@ namespace MediaBrowser.Model.Configuration
CodecsUsed = Array.Empty<string>();
ImageExtractionTimeoutMs = 0;
PathSubstitutions = Array.Empty<PathSubstitution>();
+ IgnoreVirtualInterfaces = false;
EnableSimpleArtistDetection = true;
DisplaySpecialsWithinSeasons = true;
diff --git a/MediaBrowser.Model/Cryptography/ICryptoProvider.cs b/MediaBrowser.Model/Cryptography/ICryptoProvider.cs
index b027d2ad0..5988112c2 100644
--- a/MediaBrowser.Model/Cryptography/ICryptoProvider.cs
+++ b/MediaBrowser.Model/Cryptography/ICryptoProvider.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.Collections.Generic;
namespace MediaBrowser.Model.Cryptography
{
@@ -9,5 +10,13 @@ namespace MediaBrowser.Model.Cryptography
byte[] ComputeMD5(Stream str);
byte[] ComputeMD5(byte[] bytes);
byte[] ComputeSHA1(byte[] bytes);
+ IEnumerable<string> GetSupportedHashMethods();
+ byte[] ComputeHash(string HashMethod, byte[] bytes);
+ byte[] ComputeHashWithDefaultMethod(byte[] bytes);
+ byte[] ComputeHash(string HashMethod, byte[] bytes, byte[] salt);
+ byte[] ComputeHashWithDefaultMethod(byte[] bytes, byte[] salt);
+ byte[] ComputeHash(PasswordHash hash);
+ byte[] GenerateSalt();
+ string DefaultHashMethod { get; }
}
}
diff --git a/MediaBrowser.Model/Cryptography/PasswordHash.cs b/MediaBrowser.Model/Cryptography/PasswordHash.cs
new file mode 100644
index 000000000..a9d0f6744
--- /dev/null
+++ b/MediaBrowser.Model/Cryptography/PasswordHash.cs
@@ -0,0 +1,153 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace MediaBrowser.Model.Cryptography
+{
+ public class PasswordHash
+ {
+ // Defined from this hash storage spec
+ // https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md
+ // $<id>[$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]]
+ // with one slight amendment to ease the transition, we're writing out the bytes in hex
+ // rather than making them a BASE64 string with stripped padding
+
+ private string _id;
+
+ private Dictionary<string, string> _parameters = new Dictionary<string, string>();
+
+ private string _salt;
+
+ private byte[] _saltBytes;
+
+ private string _hash;
+
+ private byte[] _hashBytes;
+
+ public string Id { get => _id; set => _id = value; }
+
+ public Dictionary<string, string> Parameters { get => _parameters; set => _parameters = value; }
+
+ public string Salt { get => _salt; set => _salt = value; }
+
+ public byte[] SaltBytes { get => _saltBytes; set => _saltBytes = value; }
+
+ public string Hash { get => _hash; set => _hash = value; }
+
+ public byte[] HashBytes { get => _hashBytes; set => _hashBytes = value; }
+
+ public PasswordHash(string storageString)
+ {
+ string[] splitted = storageString.Split('$');
+ _id = splitted[1];
+ if (splitted[2].Contains("="))
+ {
+ foreach (string paramset in (splitted[2].Split(',')))
+ {
+ if (!string.IsNullOrEmpty(paramset))
+ {
+ string[] fields = paramset.Split('=');
+ if (fields.Length == 2)
+ {
+ _parameters.Add(fields[0], fields[1]);
+ }
+ else
+ {
+ throw new Exception($"Malformed parameter in password hash string {paramset}");
+ }
+ }
+ }
+ if (splitted.Length == 5)
+ {
+ _salt = splitted[3];
+ _saltBytes = ConvertFromByteString(_salt);
+ _hash = splitted[4];
+ _hashBytes = ConvertFromByteString(_hash);
+ }
+ else
+ {
+ _salt = string.Empty;
+ _hash = splitted[3];
+ _hashBytes = ConvertFromByteString(_hash);
+ }
+ }
+ else
+ {
+ if (splitted.Length == 4)
+ {
+ _salt = splitted[2];
+ _saltBytes = ConvertFromByteString(_salt);
+ _hash = splitted[3];
+ _hashBytes = ConvertFromByteString(_hash);
+ }
+ else
+ {
+ _salt = string.Empty;
+ _hash = splitted[2];
+ _hashBytes = ConvertFromByteString(_hash);
+ }
+
+ }
+
+ }
+
+ public PasswordHash(ICryptoProvider cryptoProvider)
+ {
+ _id = cryptoProvider.DefaultHashMethod;
+ _saltBytes = cryptoProvider.GenerateSalt();
+ _salt = ConvertToByteString(SaltBytes);
+ }
+
+ public static byte[] ConvertFromByteString(string byteString)
+ {
+ byte[] bytes = new byte[byteString.Length / 2];
+ for (int i = 0; i < byteString.Length; i += 2)
+ {
+ // TODO: NetStandard2.1 switch this to use a span instead of a substring.
+ bytes[i / 2] = Convert.ToByte(byteString.Substring(i, 2), 16);
+ }
+
+ return bytes;
+ }
+
+ public static string ConvertToByteString(byte[] bytes)
+ {
+ return BitConverter.ToString(bytes).Replace("-", "");
+ }
+
+ private string SerializeParameters()
+ {
+ string returnString = string.Empty;
+ foreach (var KVP in _parameters)
+ {
+ returnString += $",{KVP.Key}={KVP.Value}";
+ }
+
+ if ((!string.IsNullOrEmpty(returnString)) && returnString[0] == ',')
+ {
+ returnString = returnString.Remove(0, 1);
+ }
+
+ return returnString;
+ }
+
+ public override string ToString()
+ {
+ string outString = "$" + _id;
+ string paramstring = SerializeParameters();
+ if (!string.IsNullOrEmpty(paramstring))
+ {
+ outString += $"${paramstring}";
+ }
+
+ if (!string.IsNullOrEmpty(_salt))
+ {
+ outString += $"${_salt}";
+ }
+
+ outString += $"${_hash}";
+ return outString;
+ }
+ }
+
+}
diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs
index fc346df37..5652962da 100644
--- a/MediaBrowser.Model/Entities/MediaStream.cs
+++ b/MediaBrowser.Model/Entities/MediaStream.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.Linq;
+using System.Text;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.MediaInfo;
@@ -65,6 +67,10 @@ namespace MediaBrowser.Model.Entities
}
}
+ public string localizedUndefined { get; set; }
+ public string localizedDefault { get; set; }
+ public string localizedForced { get; set; }
+
public string DisplayTitle
{
get
@@ -128,10 +134,6 @@ namespace MediaBrowser.Model.Entities
if (Type == MediaStreamType.Subtitle)
{
- //if (!string.IsNullOrEmpty(Title))
- //{
- // return AddLanguageIfNeeded(Title);
- //}
var attributes = new List<string>();
@@ -141,22 +143,30 @@ namespace MediaBrowser.Model.Entities
}
else
{
- attributes.Add("Und");
+ attributes.Add(string.IsNullOrEmpty(localizedUndefined) ? "Und" : localizedUndefined);
}
if (IsDefault)
{
- attributes.Add("Default");
+ attributes.Add(string.IsNullOrEmpty(localizedDefault) ? "Default" : localizedDefault);
}
if (IsForced)
{
- attributes.Add("Forced");
+ attributes.Add(string.IsNullOrEmpty(localizedForced) ? "Forced" : localizedForced);
}
- string name = string.Join(" ", attributes.ToArray());
+ if (!string.IsNullOrEmpty(Title))
+ {
+ return attributes.AsEnumerable()
+ // keep Tags that are not already in Title
+ .Where(tag => Title.IndexOf(tag, StringComparison.OrdinalIgnoreCase) == -1)
+ // attributes concatenation, starting with Title
+ .Aggregate(new StringBuilder(Title), (builder, attr) => builder.Append(" - ").Append(attr))
+ .ToString();
+ }
- return name;
+ return string.Join(" - ", attributes.ToArray());
}
if (Type == MediaStreamType.Video)
@@ -220,28 +230,6 @@ namespace MediaBrowser.Model.Entities
return null;
}
- private string AddLanguageIfNeeded(string title)
- {
- if (!string.IsNullOrEmpty(Language) &&
- !string.Equals(Language, "und", StringComparison.OrdinalIgnoreCase) &&
- !IsLanguageInTitle(title, Language))
- {
- title = StringHelper.FirstToUpper(Language) + " " + title;
- }
-
- return title;
- }
-
- private bool IsLanguageInTitle(string title, string language)
- {
- if (title.IndexOf(Language, StringComparison.OrdinalIgnoreCase) != -1)
- {
- return true;
- }
-
- return false;
- }
-
public string NalLengthSize { get; set; }
/// <summary>
diff --git a/MediaBrowser.Model/IO/IFileSystem.cs b/MediaBrowser.Model/IO/IFileSystem.cs
index e0771245f..ca99b28ca 100644
--- a/MediaBrowser.Model/IO/IFileSystem.cs
+++ b/MediaBrowser.Model/IO/IFileSystem.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Text;
namespace MediaBrowser.Model.IO
{
@@ -177,7 +176,7 @@ namespace MediaBrowser.Model.IO
/// </summary>
IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false);
- IEnumerable<FileSystemMetadata> GetFiles(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive);
+ IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string> extensions, bool enableCaseSensitiveExtensions, bool recursive);
/// <summary>
/// Gets the file system entries.
diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj
index f17fd7159..3de2cca2d 100644
--- a/MediaBrowser.Model/MediaBrowser.Model.csproj
+++ b/MediaBrowser.Model/MediaBrowser.Model.csproj
@@ -13,6 +13,7 @@
</PropertyGroup>
<ItemGroup>
+ <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
</ItemGroup>
diff --git a/MediaBrowser.Model/Net/HttpResponse.cs b/MediaBrowser.Model/Net/HttpResponse.cs
deleted file mode 100644
index 286b1c0af..000000000
--- a/MediaBrowser.Model/Net/HttpResponse.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Net;
-
-namespace MediaBrowser.Model.Net
-{
- public class HttpResponse : IDisposable
- {
- /// <summary>
- /// Gets or sets the type of the content.
- /// </summary>
- /// <value>The type of the content.</value>
- public string ContentType { get; set; }
-
- /// <summary>
- /// Gets or sets the response URL.
- /// </summary>
- /// <value>The response URL.</value>
- public string ResponseUrl { get; set; }
-
- /// <summary>
- /// Gets or sets the content.
- /// </summary>
- /// <value>The content.</value>
- public Stream Content { get; set; }
-
- /// <summary>
- /// Gets or sets the status code.
- /// </summary>
- /// <value>The status code.</value>
- public HttpStatusCode StatusCode { get; set; }
-
- /// <summary>
- /// Gets or sets the length of the content.
- /// </summary>
- /// <value>The length of the content.</value>
- public long? ContentLength { get; set; }
-
- /// <summary>
- /// Gets or sets the headers.
- /// </summary>
- /// <value>The headers.</value>
- public Dictionary<string, string> Headers { get; set; }
-
- private readonly IDisposable _disposable;
-
- public HttpResponse(IDisposable disposable)
- {
- _disposable = disposable;
- }
- public HttpResponse()
- {
- }
-
- public void Dispose()
- {
- if (_disposable != null)
- {
- _disposable.Dispose();
- }
- }
- }
-}
diff --git a/MediaBrowser.Model/Net/IAcceptSocket.cs b/MediaBrowser.Model/Net/IAcceptSocket.cs
deleted file mode 100644
index 2b21d3e66..000000000
--- a/MediaBrowser.Model/Net/IAcceptSocket.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-
-namespace MediaBrowser.Model.Net
-{
- public class SocketCreateException : Exception
- {
- public SocketCreateException(string errorCode, Exception originalException)
- : base(errorCode, originalException)
- {
- ErrorCode = errorCode;
- }
-
- public string ErrorCode { get; private set; }
- }
-}
diff --git a/MediaBrowser.Model/Net/IpAddressInfo.cs b/MediaBrowser.Model/Net/IpAddressInfo.cs
index 7a278d4d4..87fa55bca 100644
--- a/MediaBrowser.Model/Net/IpAddressInfo.cs
+++ b/MediaBrowser.Model/Net/IpAddressInfo.cs
@@ -10,6 +10,7 @@ namespace MediaBrowser.Model.Net
public static IpAddressInfo IPv6Loopback = new IpAddressInfo("::1", IpAddressFamily.InterNetworkV6);
public string Address { get; set; }
+ public IpAddressInfo SubnetMask { get; set; }
public IpAddressFamily AddressFamily { get; set; }
public IpAddressInfo(string address, IpAddressFamily addressFamily)
diff --git a/MediaBrowser.Model/Properties/AssemblyInfo.cs b/MediaBrowser.Model/Properties/AssemblyInfo.cs
index e78719e35..f99e9ece9 100644
--- a/MediaBrowser.Model/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.Model/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/MediaBrowser.Model/Reflection/IAssemblyInfo.cs b/MediaBrowser.Model/Reflection/IAssemblyInfo.cs
deleted file mode 100644
index 5c4536c1c..000000000
--- a/MediaBrowser.Model/Reflection/IAssemblyInfo.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-using System.IO;
-using System.Reflection;
-
-namespace MediaBrowser.Model.Reflection
-{
- public interface IAssemblyInfo
- {
- Stream GetManifestResourceStream(Type type, string resource);
- string[] GetManifestResourceNames(Type type);
-
- Assembly[] GetCurrentAssemblies();
- }
-}
diff --git a/MediaBrowser.Model/Serialization/IJsonSerializer.cs b/MediaBrowser.Model/Serialization/IJsonSerializer.cs
index ae0cf6f36..18f51f652 100644
--- a/MediaBrowser.Model/Serialization/IJsonSerializer.cs
+++ b/MediaBrowser.Model/Serialization/IJsonSerializer.cs
@@ -15,6 +15,14 @@ namespace MediaBrowser.Model.Serialization
void SerializeToStream(object obj, Stream stream);
/// <summary>
+ /// Serializes to stream.
+ /// </summary>
+ /// <param name="obj">The obj.</param>
+ /// <param name="stream">The stream.</param>
+ /// <exception cref="ArgumentNullException">obj</exception>
+ void SerializeToStream<T>(T obj, Stream stream);
+
+ /// <summary>
/// Serializes to file.
/// </summary>
/// <param name="obj">The obj.</param>
diff --git a/MediaBrowser.Model/Services/HttpUtility.cs b/MediaBrowser.Model/Services/HttpUtility.cs
deleted file mode 100644
index be180334c..000000000
--- a/MediaBrowser.Model/Services/HttpUtility.cs
+++ /dev/null
@@ -1,691 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Text;
-
-namespace MediaBrowser.Model.Services
-{
- public static class MyHttpUtility
- {
- // Must be sorted
- static readonly long[] entities = new long[] {
- (long)'A' << 56 | (long)'E' << 48 | (long)'l' << 40 | (long)'i' << 32 | (long)'g' << 24,
- (long)'A' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'A' << 56 | (long)'c' << 48 | (long)'i' << 40 | (long)'r' << 32 | (long)'c' << 24,
- (long)'A' << 56 | (long)'g' << 48 | (long)'r' << 40 | (long)'a' << 32 | (long)'v' << 24 | (long)'e' << 16,
- (long)'A' << 56 | (long)'l' << 48 | (long)'p' << 40 | (long)'h' << 32 | (long)'a' << 24,
- (long)'A' << 56 | (long)'r' << 48 | (long)'i' << 40 | (long)'n' << 32 | (long)'g' << 24,
- (long)'A' << 56 | (long)'t' << 48 | (long)'i' << 40 | (long)'l' << 32 | (long)'d' << 24 | (long)'e' << 16,
- (long)'A' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'B' << 56 | (long)'e' << 48 | (long)'t' << 40 | (long)'a' << 32,
- (long)'C' << 56 | (long)'c' << 48 | (long)'e' << 40 | (long)'d' << 32 | (long)'i' << 24 | (long)'l' << 16,
- (long)'C' << 56 | (long)'h' << 48 | (long)'i' << 40,
- (long)'D' << 56 | (long)'a' << 48 | (long)'g' << 40 | (long)'g' << 32 | (long)'e' << 24 | (long)'r' << 16,
- (long)'D' << 56 | (long)'e' << 48 | (long)'l' << 40 | (long)'t' << 32 | (long)'a' << 24,
- (long)'E' << 56 | (long)'T' << 48 | (long)'H' << 40,
- (long)'E' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'E' << 56 | (long)'c' << 48 | (long)'i' << 40 | (long)'r' << 32 | (long)'c' << 24,
- (long)'E' << 56 | (long)'g' << 48 | (long)'r' << 40 | (long)'a' << 32 | (long)'v' << 24 | (long)'e' << 16,
- (long)'E' << 56 | (long)'p' << 48 | (long)'s' << 40 | (long)'i' << 32 | (long)'l' << 24 | (long)'o' << 16 | (long)'n' << 8,
- (long)'E' << 56 | (long)'t' << 48 | (long)'a' << 40,
- (long)'E' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'G' << 56 | (long)'a' << 48 | (long)'m' << 40 | (long)'m' << 32 | (long)'a' << 24,
- (long)'I' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'I' << 56 | (long)'c' << 48 | (long)'i' << 40 | (long)'r' << 32 | (long)'c' << 24,
- (long)'I' << 56 | (long)'g' << 48 | (long)'r' << 40 | (long)'a' << 32 | (long)'v' << 24 | (long)'e' << 16,
- (long)'I' << 56 | (long)'o' << 48 | (long)'t' << 40 | (long)'a' << 32,
- (long)'I' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'K' << 56 | (long)'a' << 48 | (long)'p' << 40 | (long)'p' << 32 | (long)'a' << 24,
- (long)'L' << 56 | (long)'a' << 48 | (long)'m' << 40 | (long)'b' << 32 | (long)'d' << 24 | (long)'a' << 16,
- (long)'M' << 56 | (long)'u' << 48,
- (long)'N' << 56 | (long)'t' << 48 | (long)'i' << 40 | (long)'l' << 32 | (long)'d' << 24 | (long)'e' << 16,
- (long)'N' << 56 | (long)'u' << 48,
- (long)'O' << 56 | (long)'E' << 48 | (long)'l' << 40 | (long)'i' << 32 | (long)'g' << 24,
- (long)'O' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'O' << 56 | (long)'c' << 48 | (long)'i' << 40 | (long)'r' << 32 | (long)'c' << 24,
- (long)'O' << 56 | (long)'g' << 48 | (long)'r' << 40 | (long)'a' << 32 | (long)'v' << 24 | (long)'e' << 16,
- (long)'O' << 56 | (long)'m' << 48 | (long)'e' << 40 | (long)'g' << 32 | (long)'a' << 24,
- (long)'O' << 56 | (long)'m' << 48 | (long)'i' << 40 | (long)'c' << 32 | (long)'r' << 24 | (long)'o' << 16 | (long)'n' << 8,
- (long)'O' << 56 | (long)'s' << 48 | (long)'l' << 40 | (long)'a' << 32 | (long)'s' << 24 | (long)'h' << 16,
- (long)'O' << 56 | (long)'t' << 48 | (long)'i' << 40 | (long)'l' << 32 | (long)'d' << 24 | (long)'e' << 16,
- (long)'O' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'P' << 56 | (long)'h' << 48 | (long)'i' << 40,
- (long)'P' << 56 | (long)'i' << 48,
- (long)'P' << 56 | (long)'r' << 48 | (long)'i' << 40 | (long)'m' << 32 | (long)'e' << 24,
- (long)'P' << 56 | (long)'s' << 48 | (long)'i' << 40,
- (long)'R' << 56 | (long)'h' << 48 | (long)'o' << 40,
- (long)'S' << 56 | (long)'c' << 48 | (long)'a' << 40 | (long)'r' << 32 | (long)'o' << 24 | (long)'n' << 16,
- (long)'S' << 56 | (long)'i' << 48 | (long)'g' << 40 | (long)'m' << 32 | (long)'a' << 24,
- (long)'T' << 56 | (long)'H' << 48 | (long)'O' << 40 | (long)'R' << 32 | (long)'N' << 24,
- (long)'T' << 56 | (long)'a' << 48 | (long)'u' << 40,
- (long)'T' << 56 | (long)'h' << 48 | (long)'e' << 40 | (long)'t' << 32 | (long)'a' << 24,
- (long)'U' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'U' << 56 | (long)'c' << 48 | (long)'i' << 40 | (long)'r' << 32 | (long)'c' << 24,
- (long)'U' << 56 | (long)'g' << 48 | (long)'r' << 40 | (long)'a' << 32 | (long)'v' << 24 | (long)'e' << 16,
- (long)'U' << 56 | (long)'p' << 48 | (long)'s' << 40 | (long)'i' << 32 | (long)'l' << 24 | (long)'o' << 16 | (long)'n' << 8,
- (long)'U' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'X' << 56 | (long)'i' << 48,
- (long)'Y' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'Y' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'Z' << 56 | (long)'e' << 48 | (long)'t' << 40 | (long)'a' << 32,
- (long)'a' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'a' << 56 | (long)'c' << 48 | (long)'i' << 40 | (long)'r' << 32 | (long)'c' << 24,
- (long)'a' << 56 | (long)'c' << 48 | (long)'u' << 40 | (long)'t' << 32 | (long)'e' << 24,
- (long)'a' << 56 | (long)'e' << 48 | (long)'l' << 40 | (long)'i' << 32 | (long)'g' << 24,
- (long)'a' << 56 | (long)'g' << 48 | (long)'r' << 40 | (long)'a' << 32 | (long)'v' << 24 | (long)'e' << 16,
- (long)'a' << 56 | (long)'l' << 48 | (long)'e' << 40 | (long)'f' << 32 | (long)'s' << 24 | (long)'y' << 16 | (long)'m' << 8,
- (long)'a' << 56 | (long)'l' << 48 | (long)'p' << 40 | (long)'h' << 32 | (long)'a' << 24,
- (long)'a' << 56 | (long)'m' << 48 | (long)'p' << 40,
- (long)'a' << 56 | (long)'n' << 48 | (long)'d' << 40,
- (long)'a' << 56 | (long)'n' << 48 | (long)'g' << 40,
- (long)'a' << 56 | (long)'p' << 48 | (long)'o' << 40 | (long)'s' << 32,
- (long)'a' << 56 | (long)'r' << 48 | (long)'i' << 40 | (long)'n' << 32 | (long)'g' << 24,
- (long)'a' << 56 | (long)'s' << 48 | (long)'y' << 40 | (long)'m' << 32 | (long)'p' << 24,
- (long)'a' << 56 | (long)'t' << 48 | (long)'i' << 40 | (long)'l' << 32 | (long)'d' << 24 | (long)'e' << 16,
- (long)'a' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'b' << 56 | (long)'d' << 48 | (long)'q' << 40 | (long)'u' << 32 | (long)'o' << 24,
- (long)'b' << 56 | (long)'e' << 48 | (long)'t' << 40 | (long)'a' << 32,
- (long)'b' << 56 | (long)'r' << 48 | (long)'v' << 40 | (long)'b' << 32 | (long)'a' << 24 | (long)'r' << 16,
- (long)'b' << 56 | (long)'u' << 48 | (long)'l' << 40 | (long)'l' << 32,
- (long)'c' << 56 | (long)'a' << 48 | (long)'p' << 40,
- (long)'c' << 56 | (long)'c' << 48 | (long)'e' << 40 | (long)'d' << 32 | (long)'i' << 24 | (long)'l' << 16,
- (long)'c' << 56 | (long)'e' << 48 | (long)'d' << 40 | (long)'i' << 32 | (long)'l' << 24,
- (long)'c' << 56 | (long)'e' << 48 | (long)'n' << 40 | (long)'t' << 32,
- (long)'c' << 56 | (long)'h' << 48 | (long)'i' << 40,
- (long)'c' << 56 | (long)'i' << 48 | (long)'r' << 40 | (long)'c' << 32,
- (long)'c' << 56 | (long)'l' << 48 | (long)'u' << 40 | (long)'b' << 32 | (long)'s' << 24,
- (long)'c' << 56 | (long)'o' << 48 | (long)'n' << 40 | (long)'g' << 32,
- (long)'c' << 56 | (long)'o' << 48 | (long)'p' << 40 | (long)'y' << 32,
- (long)'c' << 56 | (long)'r' << 48 | (long)'a' << 40 | (long)'r' << 32 | (long)'r' << 24,
- (long)'c' << 56 | (long)'u' << 48 | (long)'p' << 40,
- (long)'c' << 56 | (long)'u' << 48 | (long)'r' << 40 | (long)'r' << 32 | (long)'e' << 24 | (long)'n' << 16,
- (long)'d' << 56 | (long)'A' << 48 | (long)'r' << 40 | (long)'r' << 32,
- (long)'d' << 56 | (long)'a' << 48 | (long)'g' << 40 | (long)'g' << 32 | (long)'e' << 24 | (long)'r' << 16,
- (long)'d' << 56 | (long)'a' << 48 | (long)'r' << 40 | (long)'r' << 32,
- (long)'d' << 56 | (long)'e' << 48 | (long)'g' << 40,
- (long)'d' << 56 | (long)'e' << 48 | (long)'l' << 40 | (long)'t' << 32 | (long)'a' << 24,
- (long)'d' << 56 | (long)'i' << 48 | (long)'a' << 40 | (long)'m' << 32 | (long)'s' << 24,
- (long)'d' << 56 | (long)'i' << 48 | (long)'v' << 40 | (long)'i' << 32 | (long)'d' << 24 | (long)'e' << 16,
- (long)'e' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'e' << 56 | (long)'c' << 48 | (long)'i' << 40 | (long)'r' << 32 | (long)'c' << 24,
- (long)'e' << 56 | (long)'g' << 48 | (long)'r' << 40 | (long)'a' << 32 | (long)'v' << 24 | (long)'e' << 16,
- (long)'e' << 56 | (long)'m' << 48 | (long)'p' << 40 | (long)'t' << 32 | (long)'y' << 24,
- (long)'e' << 56 | (long)'m' << 48 | (long)'s' << 40 | (long)'p' << 32,
- (long)'e' << 56 | (long)'n' << 48 | (long)'s' << 40 | (long)'p' << 32,
- (long)'e' << 56 | (long)'p' << 48 | (long)'s' << 40 | (long)'i' << 32 | (long)'l' << 24 | (long)'o' << 16 | (long)'n' << 8,
- (long)'e' << 56 | (long)'q' << 48 | (long)'u' << 40 | (long)'i' << 32 | (long)'v' << 24,
- (long)'e' << 56 | (long)'t' << 48 | (long)'a' << 40,
- (long)'e' << 56 | (long)'t' << 48 | (long)'h' << 40,
- (long)'e' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'e' << 56 | (long)'u' << 48 | (long)'r' << 40 | (long)'o' << 32,
- (long)'e' << 56 | (long)'x' << 48 | (long)'i' << 40 | (long)'s' << 32 | (long)'t' << 24,
- (long)'f' << 56 | (long)'n' << 48 | (long)'o' << 40 | (long)'f' << 32,
- (long)'f' << 56 | (long)'o' << 48 | (long)'r' << 40 | (long)'a' << 32 | (long)'l' << 24 | (long)'l' << 16,
- (long)'f' << 56 | (long)'r' << 48 | (long)'a' << 40 | (long)'c' << 32 | (long)'1' << 24 | (long)'2' << 16,
- (long)'f' << 56 | (long)'r' << 48 | (long)'a' << 40 | (long)'c' << 32 | (long)'1' << 24 | (long)'4' << 16,
- (long)'f' << 56 | (long)'r' << 48 | (long)'a' << 40 | (long)'c' << 32 | (long)'3' << 24 | (long)'4' << 16,
- (long)'f' << 56 | (long)'r' << 48 | (long)'a' << 40 | (long)'s' << 32 | (long)'l' << 24,
- (long)'g' << 56 | (long)'a' << 48 | (long)'m' << 40 | (long)'m' << 32 | (long)'a' << 24,
- (long)'g' << 56 | (long)'e' << 48,
- (long)'g' << 56 | (long)'t' << 48,
- (long)'h' << 56 | (long)'A' << 48 | (long)'r' << 40 | (long)'r' << 32,
- (long)'h' << 56 | (long)'a' << 48 | (long)'r' << 40 | (long)'r' << 32,
- (long)'h' << 56 | (long)'e' << 48 | (long)'a' << 40 | (long)'r' << 32 | (long)'t' << 24 | (long)'s' << 16,
- (long)'h' << 56 | (long)'e' << 48 | (long)'l' << 40 | (long)'l' << 32 | (long)'i' << 24 | (long)'p' << 16,
- (long)'i' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'i' << 56 | (long)'c' << 48 | (long)'i' << 40 | (long)'r' << 32 | (long)'c' << 24,
- (long)'i' << 56 | (long)'e' << 48 | (long)'x' << 40 | (long)'c' << 32 | (long)'l' << 24,
- (long)'i' << 56 | (long)'g' << 48 | (long)'r' << 40 | (long)'a' << 32 | (long)'v' << 24 | (long)'e' << 16,
- (long)'i' << 56 | (long)'m' << 48 | (long)'a' << 40 | (long)'g' << 32 | (long)'e' << 24,
- (long)'i' << 56 | (long)'n' << 48 | (long)'f' << 40 | (long)'i' << 32 | (long)'n' << 24,
- (long)'i' << 56 | (long)'n' << 48 | (long)'t' << 40,
- (long)'i' << 56 | (long)'o' << 48 | (long)'t' << 40 | (long)'a' << 32,
- (long)'i' << 56 | (long)'q' << 48 | (long)'u' << 40 | (long)'e' << 32 | (long)'s' << 24 | (long)'t' << 16,
- (long)'i' << 56 | (long)'s' << 48 | (long)'i' << 40 | (long)'n' << 32,
- (long)'i' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'k' << 56 | (long)'a' << 48 | (long)'p' << 40 | (long)'p' << 32 | (long)'a' << 24,
- (long)'l' << 56 | (long)'A' << 48 | (long)'r' << 40 | (long)'r' << 32,
- (long)'l' << 56 | (long)'a' << 48 | (long)'m' << 40 | (long)'b' << 32 | (long)'d' << 24 | (long)'a' << 16,
- (long)'l' << 56 | (long)'a' << 48 | (long)'n' << 40 | (long)'g' << 32,
- (long)'l' << 56 | (long)'a' << 48 | (long)'q' << 40 | (long)'u' << 32 | (long)'o' << 24,
- (long)'l' << 56 | (long)'a' << 48 | (long)'r' << 40 | (long)'r' << 32,
- (long)'l' << 56 | (long)'c' << 48 | (long)'e' << 40 | (long)'i' << 32 | (long)'l' << 24,
- (long)'l' << 56 | (long)'d' << 48 | (long)'q' << 40 | (long)'u' << 32 | (long)'o' << 24,
- (long)'l' << 56 | (long)'e' << 48,
- (long)'l' << 56 | (long)'f' << 48 | (long)'l' << 40 | (long)'o' << 32 | (long)'o' << 24 | (long)'r' << 16,
- (long)'l' << 56 | (long)'o' << 48 | (long)'w' << 40 | (long)'a' << 32 | (long)'s' << 24 | (long)'t' << 16,
- (long)'l' << 56 | (long)'o' << 48 | (long)'z' << 40,
- (long)'l' << 56 | (long)'r' << 48 | (long)'m' << 40,
- (long)'l' << 56 | (long)'s' << 48 | (long)'a' << 40 | (long)'q' << 32 | (long)'u' << 24 | (long)'o' << 16,
- (long)'l' << 56 | (long)'s' << 48 | (long)'q' << 40 | (long)'u' << 32 | (long)'o' << 24,
- (long)'l' << 56 | (long)'t' << 48,
- (long)'m' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'r' << 32,
- (long)'m' << 56 | (long)'d' << 48 | (long)'a' << 40 | (long)'s' << 32 | (long)'h' << 24,
- (long)'m' << 56 | (long)'i' << 48 | (long)'c' << 40 | (long)'r' << 32 | (long)'o' << 24,
- (long)'m' << 56 | (long)'i' << 48 | (long)'d' << 40 | (long)'d' << 32 | (long)'o' << 24 | (long)'t' << 16,
- (long)'m' << 56 | (long)'i' << 48 | (long)'n' << 40 | (long)'u' << 32 | (long)'s' << 24,
- (long)'m' << 56 | (long)'u' << 48,
- (long)'n' << 56 | (long)'a' << 48 | (long)'b' << 40 | (long)'l' << 32 | (long)'a' << 24,
- (long)'n' << 56 | (long)'b' << 48 | (long)'s' << 40 | (long)'p' << 32,
- (long)'n' << 56 | (long)'d' << 48 | (long)'a' << 40 | (long)'s' << 32 | (long)'h' << 24,
- (long)'n' << 56 | (long)'e' << 48,
- (long)'n' << 56 | (long)'i' << 48,
- (long)'n' << 56 | (long)'o' << 48 | (long)'t' << 40,
- (long)'n' << 56 | (long)'o' << 48 | (long)'t' << 40 | (long)'i' << 32 | (long)'n' << 24,
- (long)'n' << 56 | (long)'s' << 48 | (long)'u' << 40 | (long)'b' << 32,
- (long)'n' << 56 | (long)'t' << 48 | (long)'i' << 40 | (long)'l' << 32 | (long)'d' << 24 | (long)'e' << 16,
- (long)'n' << 56 | (long)'u' << 48,
- (long)'o' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'o' << 56 | (long)'c' << 48 | (long)'i' << 40 | (long)'r' << 32 | (long)'c' << 24,
- (long)'o' << 56 | (long)'e' << 48 | (long)'l' << 40 | (long)'i' << 32 | (long)'g' << 24,
- (long)'o' << 56 | (long)'g' << 48 | (long)'r' << 40 | (long)'a' << 32 | (long)'v' << 24 | (long)'e' << 16,
- (long)'o' << 56 | (long)'l' << 48 | (long)'i' << 40 | (long)'n' << 32 | (long)'e' << 24,
- (long)'o' << 56 | (long)'m' << 48 | (long)'e' << 40 | (long)'g' << 32 | (long)'a' << 24,
- (long)'o' << 56 | (long)'m' << 48 | (long)'i' << 40 | (long)'c' << 32 | (long)'r' << 24 | (long)'o' << 16 | (long)'n' << 8,
- (long)'o' << 56 | (long)'p' << 48 | (long)'l' << 40 | (long)'u' << 32 | (long)'s' << 24,
- (long)'o' << 56 | (long)'r' << 48,
- (long)'o' << 56 | (long)'r' << 48 | (long)'d' << 40 | (long)'f' << 32,
- (long)'o' << 56 | (long)'r' << 48 | (long)'d' << 40 | (long)'m' << 32,
- (long)'o' << 56 | (long)'s' << 48 | (long)'l' << 40 | (long)'a' << 32 | (long)'s' << 24 | (long)'h' << 16,
- (long)'o' << 56 | (long)'t' << 48 | (long)'i' << 40 | (long)'l' << 32 | (long)'d' << 24 | (long)'e' << 16,
- (long)'o' << 56 | (long)'t' << 48 | (long)'i' << 40 | (long)'m' << 32 | (long)'e' << 24 | (long)'s' << 16,
- (long)'o' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'p' << 56 | (long)'a' << 48 | (long)'r' << 40 | (long)'a' << 32,
- (long)'p' << 56 | (long)'a' << 48 | (long)'r' << 40 | (long)'t' << 32,
- (long)'p' << 56 | (long)'e' << 48 | (long)'r' << 40 | (long)'m' << 32 | (long)'i' << 24 | (long)'l' << 16,
- (long)'p' << 56 | (long)'e' << 48 | (long)'r' << 40 | (long)'p' << 32,
- (long)'p' << 56 | (long)'h' << 48 | (long)'i' << 40,
- (long)'p' << 56 | (long)'i' << 48,
- (long)'p' << 56 | (long)'i' << 48 | (long)'v' << 40,
- (long)'p' << 56 | (long)'l' << 48 | (long)'u' << 40 | (long)'s' << 32 | (long)'m' << 24 | (long)'n' << 16,
- (long)'p' << 56 | (long)'o' << 48 | (long)'u' << 40 | (long)'n' << 32 | (long)'d' << 24,
- (long)'p' << 56 | (long)'r' << 48 | (long)'i' << 40 | (long)'m' << 32 | (long)'e' << 24,
- (long)'p' << 56 | (long)'r' << 48 | (long)'o' << 40 | (long)'d' << 32,
- (long)'p' << 56 | (long)'r' << 48 | (long)'o' << 40 | (long)'p' << 32,
- (long)'p' << 56 | (long)'s' << 48 | (long)'i' << 40,
- (long)'q' << 56 | (long)'u' << 48 | (long)'o' << 40 | (long)'t' << 32,
- (long)'r' << 56 | (long)'A' << 48 | (long)'r' << 40 | (long)'r' << 32,
- (long)'r' << 56 | (long)'a' << 48 | (long)'d' << 40 | (long)'i' << 32 | (long)'c' << 24,
- (long)'r' << 56 | (long)'a' << 48 | (long)'n' << 40 | (long)'g' << 32,
- (long)'r' << 56 | (long)'a' << 48 | (long)'q' << 40 | (long)'u' << 32 | (long)'o' << 24,
- (long)'r' << 56 | (long)'a' << 48 | (long)'r' << 40 | (long)'r' << 32,
- (long)'r' << 56 | (long)'c' << 48 | (long)'e' << 40 | (long)'i' << 32 | (long)'l' << 24,
- (long)'r' << 56 | (long)'d' << 48 | (long)'q' << 40 | (long)'u' << 32 | (long)'o' << 24,
- (long)'r' << 56 | (long)'e' << 48 | (long)'a' << 40 | (long)'l' << 32,
- (long)'r' << 56 | (long)'e' << 48 | (long)'g' << 40,
- (long)'r' << 56 | (long)'f' << 48 | (long)'l' << 40 | (long)'o' << 32 | (long)'o' << 24 | (long)'r' << 16,
- (long)'r' << 56 | (long)'h' << 48 | (long)'o' << 40,
- (long)'r' << 56 | (long)'l' << 48 | (long)'m' << 40,
- (long)'r' << 56 | (long)'s' << 48 | (long)'a' << 40 | (long)'q' << 32 | (long)'u' << 24 | (long)'o' << 16,
- (long)'r' << 56 | (long)'s' << 48 | (long)'q' << 40 | (long)'u' << 32 | (long)'o' << 24,
- (long)'s' << 56 | (long)'b' << 48 | (long)'q' << 40 | (long)'u' << 32 | (long)'o' << 24,
- (long)'s' << 56 | (long)'c' << 48 | (long)'a' << 40 | (long)'r' << 32 | (long)'o' << 24 | (long)'n' << 16,
- (long)'s' << 56 | (long)'d' << 48 | (long)'o' << 40 | (long)'t' << 32,
- (long)'s' << 56 | (long)'e' << 48 | (long)'c' << 40 | (long)'t' << 32,
- (long)'s' << 56 | (long)'h' << 48 | (long)'y' << 40,
- (long)'s' << 56 | (long)'i' << 48 | (long)'g' << 40 | (long)'m' << 32 | (long)'a' << 24,
- (long)'s' << 56 | (long)'i' << 48 | (long)'g' << 40 | (long)'m' << 32 | (long)'a' << 24 | (long)'f' << 16,
- (long)'s' << 56 | (long)'i' << 48 | (long)'m' << 40,
- (long)'s' << 56 | (long)'p' << 48 | (long)'a' << 40 | (long)'d' << 32 | (long)'e' << 24 | (long)'s' << 16,
- (long)'s' << 56 | (long)'u' << 48 | (long)'b' << 40,
- (long)'s' << 56 | (long)'u' << 48 | (long)'b' << 40 | (long)'e' << 32,
- (long)'s' << 56 | (long)'u' << 48 | (long)'m' << 40,
- (long)'s' << 56 | (long)'u' << 48 | (long)'p' << 40,
- (long)'s' << 56 | (long)'u' << 48 | (long)'p' << 40 | (long)'1' << 32,
- (long)'s' << 56 | (long)'u' << 48 | (long)'p' << 40 | (long)'2' << 32,
- (long)'s' << 56 | (long)'u' << 48 | (long)'p' << 40 | (long)'3' << 32,
- (long)'s' << 56 | (long)'u' << 48 | (long)'p' << 40 | (long)'e' << 32,
- (long)'s' << 56 | (long)'z' << 48 | (long)'l' << 40 | (long)'i' << 32 | (long)'g' << 24,
- (long)'t' << 56 | (long)'a' << 48 | (long)'u' << 40,
- (long)'t' << 56 | (long)'h' << 48 | (long)'e' << 40 | (long)'r' << 32 | (long)'e' << 24 | (long)'4' << 16,
- (long)'t' << 56 | (long)'h' << 48 | (long)'e' << 40 | (long)'t' << 32 | (long)'a' << 24,
- (long)'t' << 56 | (long)'h' << 48 | (long)'e' << 40 | (long)'t' << 32 | (long)'a' << 24 | (long)'s' << 16 | (long)'y' << 8 | (long)'m' << 0,
- (long)'t' << 56 | (long)'h' << 48 | (long)'i' << 40 | (long)'n' << 32 | (long)'s' << 24 | (long)'p' << 16,
- (long)'t' << 56 | (long)'h' << 48 | (long)'o' << 40 | (long)'r' << 32 | (long)'n' << 24,
- (long)'t' << 56 | (long)'i' << 48 | (long)'l' << 40 | (long)'d' << 32 | (long)'e' << 24,
- (long)'t' << 56 | (long)'i' << 48 | (long)'m' << 40 | (long)'e' << 32 | (long)'s' << 24,
- (long)'t' << 56 | (long)'r' << 48 | (long)'a' << 40 | (long)'d' << 32 | (long)'e' << 24,
- (long)'u' << 56 | (long)'A' << 48 | (long)'r' << 40 | (long)'r' << 32,
- (long)'u' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'u' << 56 | (long)'a' << 48 | (long)'r' << 40 | (long)'r' << 32,
- (long)'u' << 56 | (long)'c' << 48 | (long)'i' << 40 | (long)'r' << 32 | (long)'c' << 24,
- (long)'u' << 56 | (long)'g' << 48 | (long)'r' << 40 | (long)'a' << 32 | (long)'v' << 24 | (long)'e' << 16,
- (long)'u' << 56 | (long)'m' << 48 | (long)'l' << 40,
- (long)'u' << 56 | (long)'p' << 48 | (long)'s' << 40 | (long)'i' << 32 | (long)'h' << 24,
- (long)'u' << 56 | (long)'p' << 48 | (long)'s' << 40 | (long)'i' << 32 | (long)'l' << 24 | (long)'o' << 16 | (long)'n' << 8,
- (long)'u' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'w' << 56 | (long)'e' << 48 | (long)'i' << 40 | (long)'e' << 32 | (long)'r' << 24 | (long)'p' << 16,
- (long)'x' << 56 | (long)'i' << 48,
- (long)'y' << 56 | (long)'a' << 48 | (long)'c' << 40 | (long)'u' << 32 | (long)'t' << 24 | (long)'e' << 16,
- (long)'y' << 56 | (long)'e' << 48 | (long)'n' << 40,
- (long)'y' << 56 | (long)'u' << 48 | (long)'m' << 40 | (long)'l' << 32,
- (long)'z' << 56 | (long)'e' << 48 | (long)'t' << 40 | (long)'a' << 32,
- (long)'z' << 56 | (long)'w' << 48 | (long)'j' << 40,
- (long)'z' << 56 | (long)'w' << 48 | (long)'n' << 40 | (long)'j' << 32
- };
-
- static readonly char[] entities_values = new char[] {
- '\u00C6', '\u00C1', '\u00C2', '\u00C0', '\u0391', '\u00C5', '\u00C3', '\u00C4', '\u0392', '\u00C7', '\u03A7',
- '\u2021', '\u0394', '\u00D0', '\u00C9', '\u00CA', '\u00C8', '\u0395', '\u0397', '\u00CB', '\u0393', '\u00CD',
- '\u00CE', '\u00CC', '\u0399', '\u00CF', '\u039A', '\u039B', '\u039C', '\u00D1', '\u039D', '\u0152', '\u00D3',
- '\u00D4', '\u00D2', '\u03A9', '\u039F', '\u00D8', '\u00D5', '\u00D6', '\u03A6', '\u03A0', '\u2033', '\u03A8',
- '\u03A1', '\u0160', '\u03A3', '\u00DE', '\u03A4', '\u0398', '\u00DA', '\u00DB', '\u00D9', '\u03A5', '\u00DC',
- '\u039E', '\u00DD', '\u0178', '\u0396', '\u00E1', '\u00E2', '\u00B4', '\u00E6', '\u00E0', '\u2135', '\u03B1',
- '\u0026', '\u2227', '\u2220', '\u0027', '\u00E5', '\u2248', '\u00E3', '\u00E4', '\u201E', '\u03B2', '\u00A6',
- '\u2022', '\u2229', '\u00E7', '\u00B8', '\u00A2', '\u03C7', '\u02C6', '\u2663', '\u2245', '\u00A9', '\u21B5',
- '\u222A', '\u00A4', '\u21D3', '\u2020', '\u2193', '\u00B0', '\u03B4', '\u2666', '\u00F7', '\u00E9', '\u00EA',
- '\u00E8', '\u2205', '\u2003', '\u2002', '\u03B5', '\u2261', '\u03B7', '\u00F0', '\u00EB', '\u20AC', '\u2203',
- '\u0192', '\u2200', '\u00BD', '\u00BC', '\u00BE', '\u2044', '\u03B3', '\u2265', '\u003E', '\u21D4', '\u2194',
- '\u2665', '\u2026', '\u00ED', '\u00EE', '\u00A1', '\u00EC', '\u2111', '\u221E', '\u222B', '\u03B9', '\u00BF',
- '\u2208', '\u00EF', '\u03BA', '\u21D0', '\u03BB', '\u2329', '\u00AB', '\u2190', '\u2308', '\u201C', '\u2264',
- '\u230A', '\u2217', '\u25CA', '\u200E', '\u2039', '\u2018', '\u003C', '\u00AF', '\u2014', '\u00B5', '\u00B7',
- '\u2212', '\u03BC', '\u2207', '\u00A0', '\u2013', '\u2260', '\u220B', '\u00AC', '\u2209', '\u2284', '\u00F1',
- '\u03BD', '\u00F3', '\u00F4', '\u0153', '\u00F2', '\u203E', '\u03C9', '\u03BF', '\u2295', '\u2228', '\u00AA',
- '\u00BA', '\u00F8', '\u00F5', '\u2297', '\u00F6', '\u00B6', '\u2202', '\u2030', '\u22A5', '\u03C6', '\u03C0',
- '\u03D6', '\u00B1', '\u00A3', '\u2032', '\u220F', '\u221D', '\u03C8', '\u0022', '\u21D2', '\u221A', '\u232A',
- '\u00BB', '\u2192', '\u2309', '\u201D', '\u211C', '\u00AE', '\u230B', '\u03C1', '\u200F', '\u203A', '\u2019',
- '\u201A', '\u0161', '\u22C5', '\u00A7', '\u00AD', '\u03C3', '\u03C2', '\u223C', '\u2660', '\u2282', '\u2286',
- '\u2211', '\u2283', '\u00B9', '\u00B2', '\u00B3', '\u2287', '\u00DF', '\u03C4', '\u2234', '\u03B8', '\u03D1',
- '\u2009', '\u00FE', '\u02DC', '\u00D7', '\u2122', '\u21D1', '\u00FA', '\u2191', '\u00FB', '\u00F9', '\u00A8',
- '\u03D2', '\u03C5', '\u00FC', '\u2118', '\u03BE', '\u00FD', '\u00A5', '\u00FF', '\u03B6', '\u200D', '\u200C'
- };
-
- #region Methods
-
- static void WriteCharBytes(IList buf, char ch, Encoding e)
- {
- if (ch > 255)
- {
- foreach (byte b in e.GetBytes(new char[] { ch }))
- buf.Add(b);
- }
- else
- buf.Add((byte)ch);
- }
-
- public static string UrlDecode(string s, Encoding e)
- {
- if (null == s)
- return null;
-
- if (s.IndexOf('%') == -1 && s.IndexOf('+') == -1)
- return s;
-
- if (e == null)
- e = Encoding.UTF8;
-
- long len = s.Length;
- var bytes = new List<byte>();
- int xchar;
- char ch;
-
- for (int i = 0; i < len; i++)
- {
- ch = s[i];
- if (ch == '%' && i + 2 < len && s[i + 1] != '%')
- {
- if (s[i + 1] == 'u' && i + 5 < len)
- {
- // unicode hex sequence
- xchar = GetChar(s, i + 2, 4);
- if (xchar != -1)
- {
- WriteCharBytes(bytes, (char)xchar, e);
- i += 5;
- }
- else
- WriteCharBytes(bytes, '%', e);
- }
- else if ((xchar = GetChar(s, i + 1, 2)) != -1)
- {
- WriteCharBytes(bytes, (char)xchar, e);
- i += 2;
- }
- else
- {
- WriteCharBytes(bytes, '%', e);
- }
- continue;
- }
-
- if (ch == '+')
- WriteCharBytes(bytes, ' ', e);
- else
- WriteCharBytes(bytes, ch, e);
- }
-
- byte[] buf = bytes.ToArray();
- bytes = null;
- return e.GetString(buf, 0, buf.Length);
-
- }
-
- static int GetInt(byte b)
- {
- char c = (char)b;
- if (c >= '0' && c <= '9')
- return c - '0';
-
- if (c >= 'a' && c <= 'f')
- return c - 'a' + 10;
-
- if (c >= 'A' && c <= 'F')
- return c - 'A' + 10;
-
- return -1;
- }
-
- static int GetChar(string str, int offset, int length)
- {
- int val = 0;
- int end = length + offset;
- for (int i = offset; i < end; i++)
- {
- char c = str[i];
- if (c > 127)
- return -1;
-
- int current = GetInt((byte)c);
- if (current == -1)
- return -1;
- val = (val << 4) + current;
- }
-
- return val;
- }
-
- static bool TryConvertKeyToEntity(string key, out char value)
- {
- var token = CalculateKeyValue(key);
- if (token == 0)
- {
- value = '\0';
- return false;
- }
-
- var idx = Array.BinarySearch(entities, token);
- if (idx < 0)
- {
- value = '\0';
- return false;
- }
-
- value = entities_values[idx];
- return true;
- }
-
- static long CalculateKeyValue(string s)
- {
- if (s.Length > 8)
- return 0;
-
- long key = 0;
- for (int i = 0; i < s.Length; ++i)
- {
- long ch = s[i];
- if (ch > 'z' || ch < '0')
- return 0;
-
- key |= ch << ((7 - i) * 8);
- }
-
- return key;
- }
-
- /// <summary>
- /// Decodes an HTML-encoded string and returns the decoded string.
- /// </summary>
- /// <param name="s">The HTML string to decode. </param>
- /// <returns>The decoded text.</returns>
- public static string HtmlDecode(string s)
- {
- if (s == null)
- throw new ArgumentNullException(nameof(s));
-
- if (s.IndexOf('&') == -1)
- return s;
-
- var entity = new StringBuilder();
- var output = new StringBuilder();
- int len = s.Length;
- // 0 -> nothing,
- // 1 -> right after '&'
- // 2 -> between '&' and ';' but no '#'
- // 3 -> '#' found after '&' and getting numbers
- int state = 0;
- int number = 0;
- int digit_start = 0;
- bool hex_number = false;
-
- for (int i = 0; i < len; i++)
- {
- char c = s[i];
- if (state == 0)
- {
- if (c == '&')
- {
- entity.Append(c);
- state = 1;
- }
- else
- {
- output.Append(c);
- }
- continue;
- }
-
- if (c == '&')
- {
- state = 1;
- if (digit_start > 0)
- {
- entity.Append(s, digit_start, i - digit_start);
- digit_start = 0;
- }
-
- output.Append(entity.ToString());
- entity.Length = 0;
- entity.Append('&');
- continue;
- }
-
- switch (state)
- {
- case 1:
- if (c == ';')
- {
- state = 0;
- output.Append(entity.ToString());
- output.Append(c);
- entity.Length = 0;
- break;
- }
-
- number = 0;
- hex_number = false;
- if (c != '#')
- {
- state = 2;
- }
- else
- {
- state = 3;
- }
- entity.Append(c);
-
- break;
- case 2:
- entity.Append(c);
- if (c == ';')
- {
- string key = entity.ToString();
- state = 0;
- entity.Length = 0;
-
- if (key.Length > 1)
- {
- var skey = key.Substring(1, key.Length - 2);
- if (TryConvertKeyToEntity(skey, out c))
- {
- output.Append(c);
- break;
- }
- }
-
- output.Append(key);
- }
-
- break;
- case 3:
- if (c == ';')
- {
- if (number < 0x10000)
- {
- output.Append((char)number);
- }
- else
- {
- output.Append((char)(0xd800 + ((number - 0x10000) >> 10)));
- output.Append((char)(0xdc00 + ((number - 0x10000) & 0x3ff)));
- }
- state = 0;
- entity.Length = 0;
- digit_start = 0;
- break;
- }
-
- if (c == 'x' || c == 'X' && !hex_number)
- {
- digit_start = i;
- hex_number = true;
- break;
- }
-
- if (char.IsDigit(c))
- {
- if (digit_start == 0)
- digit_start = i;
-
- number = number * (hex_number ? 16 : 10) + ((int)c - '0');
- break;
- }
-
- if (hex_number)
- {
- if (c >= 'a' && c <= 'f')
- {
- number = number * 16 + 10 + ((int)c - 'a');
- break;
- }
- if (c >= 'A' && c <= 'F')
- {
- number = number * 16 + 10 + ((int)c - 'A');
- break;
- }
- }
-
- state = 2;
- if (digit_start > 0)
- {
- entity.Append(s, digit_start, i - digit_start);
- digit_start = 0;
- }
-
- entity.Append(c);
- break;
- }
- }
-
- if (entity.Length > 0)
- {
- output.Append(entity);
- }
- else if (digit_start > 0)
- {
- output.Append(s, digit_start, s.Length - digit_start);
- }
- return output.ToString();
- }
-
- public static QueryParamCollection ParseQueryString(string query)
- {
- return ParseQueryString(query, Encoding.UTF8);
- }
-
- public static QueryParamCollection ParseQueryString(string query, Encoding encoding)
- {
- if (query == null)
- throw new ArgumentNullException(nameof(query));
- if (encoding == null)
- throw new ArgumentNullException(nameof(encoding));
- if (query.Length == 0 || (query.Length == 1 && query[0] == '?'))
- return new QueryParamCollection();
- if (query[0] == '?')
- query = query.Substring(1);
-
- var result = new QueryParamCollection();
- ParseQueryString(query, encoding, result);
- return result;
- }
-
- internal static void ParseQueryString(string query, Encoding encoding, QueryParamCollection result)
- {
- if (query.Length == 0)
- return;
-
- string decoded = HtmlDecode(query);
- int decodedLength = decoded.Length;
- int namePos = 0;
- bool first = true;
- while (namePos <= decodedLength)
- {
- int valuePos = -1, valueEnd = -1;
- for (int q = namePos; q < decodedLength; q++)
- {
- if (valuePos == -1 && decoded[q] == '=')
- {
- valuePos = q + 1;
- }
- else if (decoded[q] == '&')
- {
- valueEnd = q;
- break;
- }
- }
-
- if (first)
- {
- first = false;
- if (decoded[namePos] == '?')
- namePos++;
- }
-
- string name, value;
- if (valuePos == -1)
- {
- name = null;
- valuePos = namePos;
- }
- else
- {
- name = UrlDecode(decoded.Substring(namePos, valuePos - namePos - 1), encoding);
- }
- if (valueEnd < 0)
- {
- namePos = -1;
- valueEnd = decoded.Length;
- }
- else
- {
- namePos = valueEnd + 1;
- }
- value = UrlDecode(decoded.Substring(valuePos, valueEnd - valuePos), encoding);
-
- result.Add(name, value);
- if (namePos == -1)
- break;
- }
- }
- #endregion // Methods
- }
-}
diff --git a/MediaBrowser.Model/Services/IHttpRequest.cs b/MediaBrowser.Model/Services/IHttpRequest.cs
index 579f80c96..50c6076f3 100644
--- a/MediaBrowser.Model/Services/IHttpRequest.cs
+++ b/MediaBrowser.Model/Services/IHttpRequest.cs
@@ -3,11 +3,6 @@ namespace MediaBrowser.Model.Services
public interface IHttpRequest : IRequest
{
/// <summary>
- /// The HttpResponse
- /// </summary>
- IHttpResponse HttpResponse { get; }
-
- /// <summary>
/// The HTTP Verb
/// </summary>
string HttpMethod { get; }
diff --git a/MediaBrowser.Model/Services/IHttpResponse.cs b/MediaBrowser.Model/Services/IHttpResponse.cs
deleted file mode 100644
index a8b79f394..000000000
--- a/MediaBrowser.Model/Services/IHttpResponse.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System.Net;
-
-namespace MediaBrowser.Model.Services
-{
- public interface IHttpResponse : IResponse
- {
- //ICookies Cookies { get; }
-
- /// <summary>
- /// Adds a new Set-Cookie instruction to Response
- /// </summary>
- /// <param name="cookie"></param>
- void SetCookie(Cookie cookie);
-
- /// <summary>
- /// Removes all pending Set-Cookie instructions
- /// </summary>
- void ClearCookies();
- }
-}
diff --git a/MediaBrowser.Model/Services/IRequest.cs b/MediaBrowser.Model/Services/IRequest.cs
index ac9b981b9..4f6ddb476 100644
--- a/MediaBrowser.Model/Services/IRequest.cs
+++ b/MediaBrowser.Model/Services/IRequest.cs
@@ -1,20 +1,15 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Net;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.IO;
+using Microsoft.AspNetCore.Http;
namespace MediaBrowser.Model.Services
{
public interface IRequest
{
- /// <summary>
- /// The underlying ASP.NET or HttpListener HttpRequest
- /// </summary>
- object OriginalRequest { get; }
-
IResponse Response { get; }
/// <summary>
@@ -41,8 +36,6 @@ namespace MediaBrowser.Model.Services
string UserAgent { get; }
- IDictionary<string, Cookie> Cookies { get; }
-
/// <summary>
/// The expected Response ContentType for this request
/// </summary>
@@ -53,9 +46,9 @@ namespace MediaBrowser.Model.Services
/// </summary>
Dictionary<string, object> Items { get; }
- QueryParamCollection Headers { get; }
+ IHeaderDictionary Headers { get; }
- QueryParamCollection QueryString { get; }
+ IQueryCollection QueryString { get; }
Task<QueryParamCollection> GetFormData();
@@ -64,11 +57,6 @@ namespace MediaBrowser.Model.Services
string AbsoluteUri { get; }
/// <summary>
- /// The Remote Ip as reported by Request.UserHostAddress
- /// </summary>
- string UserHostAddress { get; }
-
- /// <summary>
/// The Remote Ip as reported by X-Forwarded-For, X-Real-IP or Request.UserHostAddress
/// </summary>
string RemoteIp { get; }
@@ -78,11 +66,6 @@ namespace MediaBrowser.Model.Services
/// </summary>
string Authorization { get; }
- /// <summary>
- /// e.g. is https or not
- /// </summary>
- bool IsSecureConnection { get; }
-
string[] AcceptTypes { get; }
string PathInfo { get; }
@@ -118,7 +101,7 @@ namespace MediaBrowser.Model.Services
public interface IResponse
{
- IRequest Request { get; }
+ HttpResponse OriginalResponse { get; }
int StatusCode { get; set; }
@@ -128,31 +111,11 @@ namespace MediaBrowser.Model.Services
void AddHeader(string name, string value);
- string GetHeader(string name);
-
void Redirect(string url);
Stream OutputStream { get; }
- /// <summary>
- /// Signal that this response has been handled and no more processing should be done.
- /// When used in a request or response filter, no more filters or processing is done on this request.
- /// </summary>
- void Close();
-
- /// <summary>
- /// Gets a value indicating whether this instance is closed.
- /// </summary>
- bool IsClosed { get; }
-
- void SetContentLength(long contentLength);
-
- //Add Metadata to Response
- Dictionary<string, object> Items { get; }
-
- QueryParamCollection Headers { get; }
-
- Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken);
+ Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, IFileSystem fileSystem, IStreamHelper streamHelper, CancellationToken cancellationToken);
bool SendChunked { get; set; }
}
diff --git a/MediaBrowser.Model/Services/QueryParamCollection.cs b/MediaBrowser.Model/Services/QueryParamCollection.cs
index 4297b97c6..7708db00a 100644
--- a/MediaBrowser.Model/Services/QueryParamCollection.cs
+++ b/MediaBrowser.Model/Services/QueryParamCollection.cs
@@ -5,19 +5,11 @@ using MediaBrowser.Model.Dto;
namespace MediaBrowser.Model.Services
{
+ // Remove this garbage class, it's just a bastard copy of NameValueCollection
public class QueryParamCollection : List<NameValuePair>
{
public QueryParamCollection()
{
-
- }
-
- public QueryParamCollection(IDictionary<string, string> headers)
- {
- foreach (var pair in headers)
- {
- Add(pair.Key, pair.Value);
- }
}
private static StringComparison GetStringComparison()
@@ -30,30 +22,15 @@ namespace MediaBrowser.Model.Services
return StringComparer.OrdinalIgnoreCase;
}
- public string GetKey(int index)
- {
- return this[index].Name;
- }
-
- public string Get(int index)
- {
- return this[index].Value;
- }
-
- public virtual string[] GetValues(int index)
- {
- return new[] { Get(index) };
- }
-
/// <summary>
/// Adds a new query parameter.
/// </summary>
- public virtual void Add(string key, string value)
+ public void Add(string key, string value)
{
Add(new NameValuePair(key, value));
}
- public virtual void Set(string key, string value)
+ private void Set(string key, string value)
{
if (string.IsNullOrEmpty(value))
{
@@ -81,17 +58,7 @@ namespace MediaBrowser.Model.Services
Add(key, value);
}
- /// <summary>
- /// Removes all parameters of the given name.
- /// </summary>
- /// <returns>The number of parameters that were removed</returns>
- /// <exception cref="ArgumentNullException"><paramref name="name" /> is null.</exception>
- public virtual int Remove(string name)
- {
- return RemoveAll(p => p.Name == name);
- }
-
- public string Get(string name)
+ private string Get(string name)
{
var stringComparison = GetStringComparison();
@@ -106,7 +73,7 @@ namespace MediaBrowser.Model.Services
return null;
}
- public virtual List<NameValuePair> GetItems(string name)
+ private List<NameValuePair> GetItems(string name)
{
var stringComparison = GetStringComparison();
@@ -140,20 +107,6 @@ namespace MediaBrowser.Model.Services
return list;
}
- public Dictionary<string, string> ToDictionary()
- {
- var stringComparer = GetStringComparer();
-
- var headers = new Dictionary<string, string>(stringComparer);
-
- foreach (var pair in this)
- {
- headers[pair.Name] = pair.Value;
- }
-
- return headers;
- }
-
public IEnumerable<string> Keys
{
get
diff --git a/MediaBrowser.Model/System/IEnvironmentInfo.cs b/MediaBrowser.Model/System/IEnvironmentInfo.cs
deleted file mode 100644
index 3ffcc7de1..000000000
--- a/MediaBrowser.Model/System/IEnvironmentInfo.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System.Runtime.InteropServices;
-
-namespace MediaBrowser.Model.System
-{
- public interface IEnvironmentInfo
- {
- OperatingSystem OperatingSystem { get; }
- string OperatingSystemName { get; }
- string OperatingSystemVersion { get; }
- Architecture SystemArchitecture { get; }
- }
-
- public enum OperatingSystem
- {
- Windows,
- Linux,
- OSX,
- BSD,
- Android
- }
-}
diff --git a/MediaBrowser.Model/System/OperatingSystemId.cs b/MediaBrowser.Model/System/OperatingSystemId.cs
new file mode 100644
index 000000000..e81dd4213
--- /dev/null
+++ b/MediaBrowser.Model/System/OperatingSystemId.cs
@@ -0,0 +1,10 @@
+namespace MediaBrowser.Model.System
+{
+ public enum OperatingSystemId
+ {
+ Windows,
+ Linux,
+ Darwin,
+ BSD
+ }
+}
diff --git a/MediaBrowser.Model/System/SystemInfo.cs b/MediaBrowser.Model/System/SystemInfo.cs
index d9ed68b27..222c10798 100644
--- a/MediaBrowser.Model/System/SystemInfo.cs
+++ b/MediaBrowser.Model/System/SystemInfo.cs
@@ -5,6 +5,21 @@ using MediaBrowser.Model.Updates;
namespace MediaBrowser.Model.System
{
/// <summary>
+ /// Enum describing the location of the FFmpeg tool.
+ /// </summary>
+ public enum FFmpegLocation
+ {
+ /// <summary>No path to FFmpeg found.</summary>
+ NotFound,
+ /// <summary>Path supplied via command line using switch --ffmpeg.</summary>
+ SetByArgument,
+ /// <summary>User has supplied path via Transcoding UI page.</summary>
+ Custom,
+ /// <summary>FFmpeg tool found on system $PATH.</summary>
+ System
+ };
+
+ /// <summary>
/// Class SystemInfo
/// </summary>
public class SystemInfo : PublicSystemInfo
@@ -60,12 +75,6 @@ namespace MediaBrowser.Model.System
/// <value><c>true</c> if this instance can self restart; otherwise, <c>false</c>.</value>
public bool CanSelfRestart { get; set; }
- /// <summary>
- /// Gets or sets a value indicating whether this instance can self update.
- /// </summary>
- /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
- public bool CanSelfUpdate { get; set; }
-
public bool CanLaunchWebBrowser { get; set; }
/// <summary>
@@ -75,6 +84,12 @@ namespace MediaBrowser.Model.System
public string ProgramDataPath { get; set; }
/// <summary>
+ /// Gets or sets the web UI resources path.
+ /// </summary>
+ /// <value>The web UI resources path.</value>
+ public string WebPath { get; set; }
+
+ /// <summary>
/// Gets or sets the items by name path.
/// </summary>
/// <value>The items by name path.</value>
@@ -128,7 +143,7 @@ namespace MediaBrowser.Model.System
/// <value><c>true</c> if this instance has update available; otherwise, <c>false</c>.</value>
public bool HasUpdateAvailable { get; set; }
- public string EncoderLocationType { get; set; }
+ public FFmpegLocation EncoderLocation { get; set; }
public Architecture SystemArchitecture { get; set; }
diff --git a/MediaBrowser.Model/Users/UserPolicy.cs b/MediaBrowser.Model/Users/UserPolicy.cs
index 23805b79f..5415fd5e8 100644
--- a/MediaBrowser.Model/Users/UserPolicy.cs
+++ b/MediaBrowser.Model/Users/UserPolicy.cs
@@ -66,6 +66,7 @@ namespace MediaBrowser.Model.Users
public bool EnableAllFolders { get; set; }
public int InvalidLoginAttemptCount { get; set; }
+ public int? LoginAttemptsBeforeLockout { get; set; }
public bool EnablePublicSharing { get; set; }
@@ -77,7 +78,7 @@ namespace MediaBrowser.Model.Users
public UserPolicy()
{
- EnableContentDeletion = true;
+ EnableContentDeletion = false;
EnableContentDeletionFromFolders = Array.Empty<string>();
EnableSyncTranscoding = true;
@@ -104,6 +105,8 @@ namespace MediaBrowser.Model.Users
AccessSchedules = Array.Empty<AccessSchedule>();
+ LoginAttemptsBeforeLockout = -1;
+
EnableAllChannels = true;
EnabledChannels = Array.Empty<string>();
diff --git a/MediaBrowser.Model/Xml/IXmlReaderSettingsFactory.cs b/MediaBrowser.Model/Xml/IXmlReaderSettingsFactory.cs
deleted file mode 100644
index b39325958..000000000
--- a/MediaBrowser.Model/Xml/IXmlReaderSettingsFactory.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System.Xml;
-
-namespace MediaBrowser.Model.Xml
-{
- public interface IXmlReaderSettingsFactory
- {
- XmlReaderSettings Create(bool enableValidation);
- }
-}
diff --git a/MediaBrowser.Providers/Manager/GenericPriorityQueue.cs b/MediaBrowser.Providers/Manager/GenericPriorityQueue.cs
deleted file mode 100644
index 10ff2515c..000000000
--- a/MediaBrowser.Providers/Manager/GenericPriorityQueue.cs
+++ /dev/null
@@ -1,402 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-
-//TODO Fix namespace or replace
-namespace Priority_Queue
-{
- /// <summary>
- /// Credit: https://github.com/BlueRaja/High-Speed-Priority-Queue-for-C-Sharp
- /// A copy of StablePriorityQueue which also has generic priority-type
- /// </summary>
- /// <typeparam name="TItem">The values in the queue. Must extend the GenericPriorityQueue class</typeparam>
- /// <typeparam name="TPriority">The priority-type. Must extend IComparable&lt;TPriority&gt;</typeparam>
- public sealed class GenericPriorityQueue<TItem, TPriority> : IFixedSizePriorityQueue<TItem, TPriority>
- where TItem : GenericPriorityQueueNode<TPriority>
- where TPriority : IComparable<TPriority>
- {
- private int _numNodes;
- private TItem[] _nodes;
- private long _numNodesEverEnqueued;
-
- /// <summary>
- /// Instantiate a new Priority Queue
- /// </summary>
- /// <param name="maxNodes">The max nodes ever allowed to be enqueued (going over this will cause undefined behavior)</param>
- public GenericPriorityQueue(int maxNodes)
- {
-#if DEBUG
- if (maxNodes <= 0)
- {
- throw new InvalidOperationException("New queue size cannot be smaller than 1");
- }
-#endif
-
- _numNodes = 0;
- _nodes = new TItem[maxNodes + 1];
- _numNodesEverEnqueued = 0;
- }
-
- /// <summary>
- /// Returns the number of nodes in the queue.
- /// O(1)
- /// </summary>
- public int Count => _numNodes;
-
- /// <summary>
- /// Returns the maximum number of items that can be enqueued at once in this queue. Once you hit this number (ie. once Count == MaxSize),
- /// attempting to enqueue another item will cause undefined behavior. O(1)
- /// </summary>
- public int MaxSize => _nodes.Length - 1;
-
- /// <summary>
- /// Removes every node from the queue.
- /// O(n) (So, don't do this often!)
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Clear()
- {
- Array.Clear(_nodes, 1, _numNodes);
- _numNodes = 0;
- }
-
- /// <summary>
- /// Returns (in O(1)!) whether the given node is in the queue. O(1)
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool Contains(TItem node)
- {
-#if DEBUG
- if (node == null)
- {
- throw new ArgumentNullException(nameof(node));
- }
- if (node.QueueIndex < 0 || node.QueueIndex >= _nodes.Length)
- {
- throw new InvalidOperationException("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?");
- }
-#endif
-
- return (_nodes[node.QueueIndex] == node);
- }
-
- /// <summary>
- /// Enqueue a node to the priority queue. Lower values are placed in front. Ties are broken by first-in-first-out.
- /// If the queue is full, the result is undefined.
- /// If the node is already enqueued, the result is undefined.
- /// O(log n)
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void Enqueue(TItem node, TPriority priority)
- {
-#if DEBUG
- if (node == null)
- {
- throw new ArgumentNullException(nameof(node));
- }
- if (_numNodes >= _nodes.Length - 1)
- {
- throw new InvalidOperationException("Queue is full - node cannot be added: " + node);
- }
- if (Contains(node))
- {
- throw new InvalidOperationException("Node is already enqueued: " + node);
- }
-#endif
-
- node.Priority = priority;
- _numNodes++;
- _nodes[_numNodes] = node;
- node.QueueIndex = _numNodes;
- node.InsertionIndex = _numNodesEverEnqueued++;
- CascadeUp(_nodes[_numNodes]);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private void Swap(TItem node1, TItem node2)
- {
- //Swap the nodes
- _nodes[node1.QueueIndex] = node2;
- _nodes[node2.QueueIndex] = node1;
-
- //Swap their indicies
- int temp = node1.QueueIndex;
- node1.QueueIndex = node2.QueueIndex;
- node2.QueueIndex = temp;
- }
-
- //Performance appears to be slightly better when this is NOT inlined o_O
- private void CascadeUp(TItem node)
- {
- //aka Heapify-up
- int parent = node.QueueIndex / 2;
- while (parent >= 1)
- {
- var parentNode = _nodes[parent];
- if (HasHigherPriority(parentNode, node))
- break;
-
- //Node has lower priority value, so move it up the heap
- Swap(node, parentNode); //For some reason, this is faster with Swap() rather than (less..?) individual operations, like in CascadeDown()
-
- parent = node.QueueIndex / 2;
- }
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private void CascadeDown(TItem node)
- {
- //aka Heapify-down
- TItem newParent;
- int finalQueueIndex = node.QueueIndex;
- while (true)
- {
- newParent = node;
- int childLeftIndex = 2 * finalQueueIndex;
-
- //Check if the left-child is higher-priority than the current node
- if (childLeftIndex > _numNodes)
- {
- //This could be placed outside the loop, but then we'd have to check newParent != node twice
- node.QueueIndex = finalQueueIndex;
- _nodes[finalQueueIndex] = node;
- break;
- }
-
- var childLeft = _nodes[childLeftIndex];
- if (HasHigherPriority(childLeft, newParent))
- {
- newParent = childLeft;
- }
-
- //Check if the right-child is higher-priority than either the current node or the left child
- int childRightIndex = childLeftIndex + 1;
- if (childRightIndex <= _numNodes)
- {
- var childRight = _nodes[childRightIndex];
- if (HasHigherPriority(childRight, newParent))
- {
- newParent = childRight;
- }
- }
-
- //If either of the children has higher (smaller) priority, swap and continue cascading
- if (newParent != node)
- {
- //Move new parent to its new index. node will be moved once, at the end
- //Doing it this way is one less assignment operation than calling Swap()
- _nodes[finalQueueIndex] = newParent;
-
- int temp = newParent.QueueIndex;
- newParent.QueueIndex = finalQueueIndex;
- finalQueueIndex = temp;
- }
- else
- {
- //See note above
- node.QueueIndex = finalQueueIndex;
- _nodes[finalQueueIndex] = node;
- break;
- }
- }
- }
-
- /// <summary>
- /// Returns true if 'higher' has higher priority than 'lower', false otherwise.
- /// Note that calling HasHigherPriority(node, node) (ie. both arguments the same node) will return false
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private bool HasHigherPriority(TItem higher, TItem lower)
- {
- var cmp = higher.Priority.CompareTo(lower.Priority);
- return (cmp < 0 || (cmp == 0 && higher.InsertionIndex < lower.InsertionIndex));
- }
-
- /// <summary>
- /// Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it.
- /// If queue is empty, result is undefined
- /// O(log n)
- /// </summary>
- public bool TryDequeue(out TItem item)
- {
- if (_numNodes <= 0)
- {
- item = default(TItem);
- return false;
- }
-
-#if DEBUG
-
- if (!IsValidQueue())
- {
- throw new InvalidOperationException("Queue has been corrupted (Did you update a node priority manually instead of calling UpdatePriority()?" +
- "Or add the same node to two different queues?)");
- }
-#endif
-
- var returnMe = _nodes[1];
- Remove(returnMe);
- item = returnMe;
- return true;
- }
-
- /// <summary>
- /// Resize the queue so it can accept more nodes. All currently enqueued nodes are remain.
- /// Attempting to decrease the queue size to a size too small to hold the existing nodes results in undefined behavior
- /// O(n)
- /// </summary>
- public void Resize(int maxNodes)
- {
-#if DEBUG
- if (maxNodes <= 0)
- {
- throw new InvalidOperationException("Queue size cannot be smaller than 1");
- }
-
- if (maxNodes < _numNodes)
- {
- throw new InvalidOperationException("Called Resize(" + maxNodes + "), but current queue contains " + _numNodes + " nodes");
- }
-#endif
-
- TItem[] newArray = new TItem[maxNodes + 1];
- int highestIndexToCopy = Math.Min(maxNodes, _numNodes);
- for (int i = 1; i <= highestIndexToCopy; i++)
- {
- newArray[i] = _nodes[i];
- }
- _nodes = newArray;
- }
-
- /// <summary>
- /// Returns the head of the queue, without removing it (use Dequeue() for that).
- /// If the queue is empty, behavior is undefined.
- /// O(1)
- /// </summary>
- public TItem First
- {
- get
- {
-#if DEBUG
- if (_numNodes <= 0)
- {
- throw new InvalidOperationException("Cannot call .First on an empty queue");
- }
-#endif
-
- return _nodes[1];
- }
- }
-
- /// <summary>
- /// This method must be called on a node every time its priority changes while it is in the queue.
- /// <b>Forgetting to call this method will result in a corrupted queue!</b>
- /// Calling this method on a node not in the queue results in undefined behavior
- /// O(log n)
- /// </summary>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public void UpdatePriority(TItem node, TPriority priority)
- {
-#if DEBUG
- if (node == null)
- {
- throw new ArgumentNullException(nameof(node));
- }
- if (!Contains(node))
- {
- throw new InvalidOperationException("Cannot call UpdatePriority() on a node which is not enqueued: " + node);
- }
-#endif
-
- node.Priority = priority;
- OnNodeUpdated(node);
- }
-
- private void OnNodeUpdated(TItem node)
- {
- //Bubble the updated node up or down as appropriate
- int parentIndex = node.QueueIndex / 2;
- var parentNode = _nodes[parentIndex];
-
- if (parentIndex > 0 && HasHigherPriority(node, parentNode))
- {
- CascadeUp(node);
- }
- else
- {
- //Note that CascadeDown will be called if parentNode == node (that is, node is the root)
- CascadeDown(node);
- }
- }
-
- /// <summary>
- /// Removes a node from the queue. The node does not need to be the head of the queue.
- /// If the node is not in the queue, the result is undefined. If unsure, check Contains() first
- /// O(log n)
- /// </summary>
- public void Remove(TItem node)
- {
-#if DEBUG
- if (node == null)
- {
- throw new ArgumentNullException(nameof(node));
- }
- if (!Contains(node))
- {
- throw new InvalidOperationException("Cannot call Remove() on a node which is not enqueued: " + node);
- }
-#endif
-
- //If the node is already the last node, we can remove it immediately
- if (node.QueueIndex == _numNodes)
- {
- _nodes[_numNodes] = null;
- _numNodes--;
- return;
- }
-
- //Swap the node with the last node
- var formerLastNode = _nodes[_numNodes];
- Swap(node, formerLastNode);
- _nodes[_numNodes] = null;
- _numNodes--;
-
- //Now bubble formerLastNode (which is no longer the last node) up or down as appropriate
- OnNodeUpdated(formerLastNode);
- }
-
- public IEnumerator<TItem> GetEnumerator()
- {
- for (int i = 1; i <= _numNodes; i++)
- yield return _nodes[i];
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- /// <summary>
- /// <b>Should not be called in production code.</b>
- /// Checks to make sure the queue is still in a valid state. Used for testing/debugging the queue.
- /// </summary>
- public bool IsValidQueue()
- {
- for (int i = 1; i < _nodes.Length; i++)
- {
- if (_nodes[i] != null)
- {
- int childLeftIndex = 2 * i;
- if (childLeftIndex < _nodes.Length && _nodes[childLeftIndex] != null && HasHigherPriority(_nodes[childLeftIndex], _nodes[i]))
- return false;
-
- int childRightIndex = childLeftIndex + 1;
- if (childRightIndex < _nodes.Length && _nodes[childRightIndex] != null && HasHigherPriority(_nodes[childRightIndex], _nodes[i]))
- return false;
- }
- }
- return true;
- }
- }
-}
diff --git a/MediaBrowser.Providers/Manager/GenericPriorityQueueNode.cs b/MediaBrowser.Providers/Manager/GenericPriorityQueueNode.cs
deleted file mode 100644
index b45ae0fd8..000000000
--- a/MediaBrowser.Providers/Manager/GenericPriorityQueueNode.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-namespace Priority_Queue
-{
- /// Credit: https://github.com/BlueRaja/High-Speed-Priority-Queue-for-C-Sharp
- public class GenericPriorityQueueNode<TPriority>
- {
- /// <summary>
- /// The Priority to insert this node at. Must be set BEFORE adding a node to the queue (ideally just once, in the node's constructor).
- /// Should not be manually edited once the node has been enqueued - use queue.UpdatePriority() instead
- /// </summary>
- public TPriority Priority { get; protected internal set; }
-
- /// <summary>
- /// Represents the current position in the queue
- /// </summary>
- public int QueueIndex { get; internal set; }
-
- /// <summary>
- /// Represents the order the node was inserted in
- /// </summary>
- public long InsertionIndex { get; internal set; }
- }
-}
diff --git a/MediaBrowser.Providers/Manager/IFixedSizePriorityQueue.cs b/MediaBrowser.Providers/Manager/IFixedSizePriorityQueue.cs
deleted file mode 100644
index 509d98e42..000000000
--- a/MediaBrowser.Providers/Manager/IFixedSizePriorityQueue.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System;
-
-namespace Priority_Queue
-{
- /// <summary>
- /// Credit: https://github.com/BlueRaja/High-Speed-Priority-Queue-for-C-Sharp
- /// A helper-interface only needed to make writing unit tests a bit easier (hence the 'internal' access modifier)
- /// </summary>
- internal interface IFixedSizePriorityQueue<TItem, in TPriority> : IPriorityQueue<TItem, TPriority>
- where TPriority : IComparable<TPriority>
- {
- /// <summary>
- /// Resize the queue so it can accept more nodes. All currently enqueued nodes are remain.
- /// Attempting to decrease the queue size to a size too small to hold the existing nodes results in undefined behavior
- /// </summary>
- void Resize(int maxNodes);
-
- /// <summary>
- /// Returns the maximum number of items that can be enqueued at once in this queue. Once you hit this number (ie. once Count == MaxSize),
- /// attempting to enqueue another item will cause undefined behavior.
- /// </summary>
- int MaxSize { get; }
- }
-}
diff --git a/MediaBrowser.Providers/Manager/IPriorityQueue.cs b/MediaBrowser.Providers/Manager/IPriorityQueue.cs
deleted file mode 100644
index dc319a7f8..000000000
--- a/MediaBrowser.Providers/Manager/IPriorityQueue.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Priority_Queue
-{
- /// <summary>
- /// Credit: https://github.com/BlueRaja/High-Speed-Priority-Queue-for-C-Sharp
- /// The IPriorityQueue interface. This is mainly here for purists, and in case I decide to add more implementations later.
- /// For speed purposes, it is actually recommended that you *don't* access the priority queue through this interface, since the JIT can
- /// (theoretically?) optimize method calls from concrete-types slightly better.
- /// </summary>
- public interface IPriorityQueue<TItem, in TPriority> : IEnumerable<TItem>
- where TPriority : IComparable<TPriority>
- {
- /// <summary>
- /// Enqueue a node to the priority queue. Lower values are placed in front. Ties are broken by first-in-first-out.
- /// See implementation for how duplicates are handled.
- /// </summary>
- void Enqueue(TItem node, TPriority priority);
-
- /// <summary>
- /// Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it.
- /// </summary>
- bool TryDequeue(out TItem item);
-
- /// <summary>
- /// Removes every node from the queue.
- /// </summary>
- void Clear();
-
- /// <summary>
- /// Returns whether the given node is in the queue.
- /// </summary>
- bool Contains(TItem node);
-
- /// <summary>
- /// Removes a node from the queue. The node does not need to be the head of the queue.
- /// </summary>
- void Remove(TItem node);
-
- /// <summary>
- /// Call this method to change the priority of a node.
- /// </summary>
- void UpdatePriority(TItem node, TPriority priority);
-
- /// <summary>
- /// Returns the head of the queue, without removing it (use Dequeue() for that).
- /// </summary>
- TItem First { get; }
-
- /// <summary>
- /// Returns the number of nodes in the queue.
- /// </summary>
- int Count { get; }
- }
-}
diff --git a/MediaBrowser.Providers/Manager/MetadataService.cs b/MediaBrowser.Providers/Manager/MetadataService.cs
index 77028e526..f0716f201 100644
--- a/MediaBrowser.Providers/Manager/MetadataService.cs
+++ b/MediaBrowser.Providers/Manager/MetadataService.cs
@@ -92,10 +92,7 @@ namespace MediaBrowser.Providers.Manager
catch (Exception ex)
{
localImagesFailed = true;
- if (!(item is IItemByName))
- {
- Logger.LogError(ex, "Error validating images for {0}", item.Path ?? item.Name ?? "Unknown name");
- }
+ Logger.LogError(ex, "Error validating images for {0}", item.Path ?? item.Name ?? "Unknown name");
}
var metadataResult = new MetadataResult<TItemType>
diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs
index f26087fda..860ea13cf 100644
--- a/MediaBrowser.Providers/Manager/ProviderManager.cs
+++ b/MediaBrowser.Providers/Manager/ProviderManager.cs
@@ -942,10 +942,7 @@ namespace MediaBrowser.Providers.Manager
_activeRefreshes[id] = 0;
}
- if (RefreshStarted != null)
- {
- RefreshStarted(this, new GenericEventArgs<BaseItem>(item));
- }
+ RefreshStarted?.Invoke(this, new GenericEventArgs<BaseItem>(item));
}
public void OnRefreshComplete(BaseItem item)
@@ -956,10 +953,7 @@ namespace MediaBrowser.Providers.Manager
_activeRefreshes.Remove(item.Id);
}
- if (RefreshCompleted != null)
- {
- RefreshCompleted(this, new GenericEventArgs<BaseItem>(item));
- }
+ RefreshCompleted?.Invoke(this, new GenericEventArgs<BaseItem>(item));
}
public double? GetRefreshProgress(Guid id)
@@ -986,10 +980,7 @@ namespace MediaBrowser.Providers.Manager
{
_activeRefreshes[id] = progress;
- if (RefreshProgress != null)
- {
- RefreshProgress(this, new GenericEventArgs<Tuple<BaseItem, double>>(new Tuple<BaseItem, double>(item, progress)));
- }
+ RefreshProgress?.Invoke(this, new GenericEventArgs<Tuple<BaseItem, double>>(new Tuple<BaseItem, double>(item, progress)));
}
else
{
@@ -1079,17 +1070,14 @@ namespace MediaBrowser.Providers.Manager
await item.RefreshMetadata(options, cancellationToken).ConfigureAwait(false);
// Collection folders don't validate their children so we'll have to simulate that here
- var collectionFolder = item as CollectionFolder;
- if (collectionFolder != null)
+ if (item is CollectionFolder collectionFolder)
{
await RefreshCollectionFolderChildren(options, collectionFolder, cancellationToken).ConfigureAwait(false);
}
else
{
- var folder = item as Folder;
-
- if (folder != null)
+ if (item is Folder folder)
{
await folder.ValidateChildren(new SimpleProgress<double>(), cancellationToken, options).ConfigureAwait(false);
}
@@ -1098,16 +1086,11 @@ namespace MediaBrowser.Providers.Manager
private async Task RefreshCollectionFolderChildren(MetadataRefreshOptions options, CollectionFolder collectionFolder, CancellationToken cancellationToken)
{
- foreach (var child in collectionFolder.GetPhysicalFolders().ToList())
+ foreach (var child in collectionFolder.GetPhysicalFolders())
{
await child.RefreshMetadata(options, cancellationToken).ConfigureAwait(false);
- if (child.IsFolder)
- {
- var folder = (Folder)child;
-
- await folder.ValidateChildren(new SimpleProgress<double>(), cancellationToken, options, true).ConfigureAwait(false);
- }
+ await child.ValidateChildren(new SimpleProgress<double>(), cancellationToken, options, true).ConfigureAwait(false);
}
}
@@ -1116,20 +1099,18 @@ namespace MediaBrowser.Providers.Manager
var albums = _libraryManagerFactory()
.GetItemList(new InternalItemsQuery
{
- IncludeItemTypes = new[] { typeof(MusicAlbum).Name },
+ IncludeItemTypes = new[] { nameof(MusicAlbum) },
ArtistIds = new[] { item.Id },
DtoOptions = new DtoOptions(false)
{
EnableImages = false
}
})
- .OfType<MusicAlbum>()
- .ToList();
+ .OfType<MusicAlbum>();
var musicArtists = albums
.Select(i => i.MusicArtist)
- .Where(i => i != null)
- .ToList();
+ .Where(i => i != null);
var musicArtistRefreshTasks = musicArtists.Select(i => i.ValidateChildren(new SimpleProgress<double>(), cancellationToken, options, true));
diff --git a/MediaBrowser.Providers/Manager/SimplePriorityQueue.cs b/MediaBrowser.Providers/Manager/SimplePriorityQueue.cs
deleted file mode 100644
index d064312cf..000000000
--- a/MediaBrowser.Providers/Manager/SimplePriorityQueue.cs
+++ /dev/null
@@ -1,247 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-
-namespace Priority_Queue
-{
- /// <summary>
- /// Credit: https://github.com/BlueRaja/High-Speed-Priority-Queue-for-C-Sharp
- /// A simplified priority queue implementation. Is stable, auto-resizes, and thread-safe, at the cost of being slightly slower than
- /// FastPriorityQueue
- /// </summary>
- /// <typeparam name="TItem">The type to enqueue</typeparam>
- /// <typeparam name="TPriority">The priority-type to use for nodes. Must extend IComparable&lt;TPriority&gt;</typeparam>
- public class SimplePriorityQueue<TItem, TPriority> : IPriorityQueue<TItem, TPriority>
- where TPriority : IComparable<TPriority>
- {
- private class SimpleNode : GenericPriorityQueueNode<TPriority>
- {
- public TItem Data { get; private set; }
-
- public SimpleNode(TItem data)
- {
- Data = data;
- }
- }
-
- private const int INITIAL_QUEUE_SIZE = 10;
- private readonly GenericPriorityQueue<SimpleNode, TPriority> _queue;
-
- public SimplePriorityQueue()
- {
- _queue = new GenericPriorityQueue<SimpleNode, TPriority>(INITIAL_QUEUE_SIZE);
- }
-
- /// <summary>
- /// Given an item of type T, returns the exist SimpleNode in the queue
- /// </summary>
- private SimpleNode GetExistingNode(TItem item)
- {
- var comparer = EqualityComparer<TItem>.Default;
- foreach (var node in _queue)
- {
- if (comparer.Equals(node.Data, item))
- {
- return node;
- }
- }
- throw new InvalidOperationException("Item cannot be found in queue: " + item);
- }
-
- /// <summary>
- /// Returns the number of nodes in the queue.
- /// O(1)
- /// </summary>
- public int Count
- {
- get
- {
- lock (_queue)
- {
- return _queue.Count;
- }
- }
- }
-
-
- /// <summary>
- /// Returns the head of the queue, without removing it (use Dequeue() for that).
- /// Throws an exception when the queue is empty.
- /// O(1)
- /// </summary>
- public TItem First
- {
- get
- {
- lock (_queue)
- {
- if (_queue.Count <= 0)
- {
- throw new InvalidOperationException("Cannot call .First on an empty queue");
- }
-
- SimpleNode first = _queue.First;
- return (first != null ? first.Data : default(TItem));
- }
- }
- }
-
- /// <summary>
- /// Removes every node from the queue.
- /// O(n)
- /// </summary>
- public void Clear()
- {
- lock (_queue)
- {
- _queue.Clear();
- }
- }
-
- /// <summary>
- /// Returns whether the given item is in the queue.
- /// O(n)
- /// </summary>
- public bool Contains(TItem item)
- {
- lock (_queue)
- {
- var comparer = EqualityComparer<TItem>.Default;
- foreach (var node in _queue)
- {
- if (comparer.Equals(node.Data, item))
- {
- return true;
- }
- }
- return false;
- }
- }
-
- /// <summary>
- /// Removes the head of the queue (node with minimum priority; ties are broken by order of insertion), and returns it.
- /// If queue is empty, throws an exception
- /// O(log n)
- /// </summary>
- public bool TryDequeue(out TItem item)
- {
- lock (_queue)
- {
- if (_queue.Count <= 0)
- {
- item = default(TItem);
- return false;
- }
-
- if (_queue.TryDequeue(out SimpleNode node))
- {
- item = node.Data;
- return true;
- }
-
- item = default(TItem);
- return false;
- }
- }
-
- /// <summary>
- /// Enqueue a node to the priority queue. Lower values are placed in front. Ties are broken by first-in-first-out.
- /// This queue automatically resizes itself, so there's no concern of the queue becoming 'full'.
- /// Duplicates are allowed.
- /// O(log n)
- /// </summary>
- public void Enqueue(TItem item, TPriority priority)
- {
- lock (_queue)
- {
- var node = new SimpleNode(item);
- if (_queue.Count == _queue.MaxSize)
- {
- _queue.Resize(_queue.MaxSize * 2 + 1);
- }
- _queue.Enqueue(node, priority);
- }
- }
-
- /// <summary>
- /// Removes an item from the queue. The item does not need to be the head of the queue.
- /// If the item is not in the queue, an exception is thrown. If unsure, check Contains() first.
- /// If multiple copies of the item are enqueued, only the first one is removed.
- /// O(n)
- /// </summary>
- public void Remove(TItem item)
- {
- lock (_queue)
- {
- try
- {
- _queue.Remove(GetExistingNode(item));
- }
- catch (InvalidOperationException ex)
- {
- throw new InvalidOperationException("Cannot call Remove() on a node which is not enqueued: " + item, ex);
- }
- }
- }
-
- /// <summary>
- /// Call this method to change the priority of an item.
- /// Calling this method on a item not in the queue will throw an exception.
- /// If the item is enqueued multiple times, only the first one will be updated.
- /// (If your requirements are complex enough that you need to enqueue the same item multiple times <i>and</i> be able
- /// to update all of them, please wrap your items in a wrapper class so they can be distinguished).
- /// O(n)
- /// </summary>
- public void UpdatePriority(TItem item, TPriority priority)
- {
- lock (_queue)
- {
- try
- {
- SimpleNode updateMe = GetExistingNode(item);
- _queue.UpdatePriority(updateMe, priority);
- }
- catch (InvalidOperationException ex)
- {
- throw new InvalidOperationException("Cannot call UpdatePriority() on a node which is not enqueued: " + item, ex);
- }
- }
- }
-
- public IEnumerator<TItem> GetEnumerator()
- {
- var queueData = new List<TItem>();
- lock (_queue)
- {
- //Copy to a separate list because we don't want to 'yield return' inside a lock
- foreach (var node in _queue)
- {
- queueData.Add(node.Data);
- }
- }
-
- return queueData.GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- public bool IsValidQueue()
- {
- lock (_queue)
- {
- return _queue.IsValidQueue();
- }
- }
- }
-
- /// <summary>
- /// A simplified priority queue implementation. Is stable, auto-resizes, and thread-safe, at the cost of being slightly slower than
- /// FastPriorityQueue
- /// This class is kept here for backwards compatibility. It's recommended you use Simple
- /// </summary>
- /// <typeparam name="TItem">The type to enqueue</typeparam>
- public class SimplePriorityQueue<TItem> : SimplePriorityQueue<TItem, float> { }
-}
diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj
index e6ef889c3..cfbb85ea6 100644
--- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj
+++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
@@ -11,7 +11,11 @@
</ItemGroup>
<ItemGroup>
+ <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
+ <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
+ <PackageReference Include="OptimizedPriorityQueue" Version="4.2.0" />
<PackageReference Include="PlaylistsNET" Version="1.0.2" />
+ <PackageReference Include="TvDbSharper" Version="2.0.0" />
</ItemGroup>
<PropertyGroup>
diff --git a/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs b/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs
index cd026b39b..8195591e1 100644
--- a/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs
+++ b/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs
@@ -16,7 +16,7 @@ namespace MediaBrowser.Providers.MediaInfo
private readonly ILocalizationManager _localization;
private readonly IFileSystem _fileSystem;
- private string[] SubtitleExtensions = new[]
+ private static readonly HashSet<string> SubtitleExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
".srt",
".ssa",
@@ -49,9 +49,16 @@ namespace MediaBrowser.Providers.MediaInfo
startIndex += streams.Count;
+ string folder = video.GetInternalMetadataPath();
+
+ if (!Directory.Exists(folder))
+ {
+ return streams;
+ }
+
try
{
- AddExternalSubtitleStreams(streams, video.GetInternalMetadataPath(), video.Path, startIndex, directoryService, clearCache);
+ AddExternalSubtitleStreams(streams, folder, video.Path, startIndex, directoryService, clearCache);
}
catch (IOException)
{
@@ -105,7 +112,7 @@ namespace MediaBrowser.Providers.MediaInfo
{
var extension = Path.GetExtension(fullName);
- if (!SubtitleExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
+ if (!SubtitleExtensions.Contains(extension))
{
continue;
}
diff --git a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs
index e4bb52217..3797f9039 100644
--- a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs
+++ b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
+using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
@@ -15,7 +15,7 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
-using MediaBrowser.Model.Xml;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Music
@@ -28,17 +28,42 @@ namespace MediaBrowser.Providers.Music
private readonly IApplicationHost _appHost;
private readonly ILogger _logger;
private readonly IJsonSerializer _json;
- private readonly IXmlReaderSettingsFactory _xmlSettings;
+ private Stopwatch _stopWatchMusicBrainz = new Stopwatch();
- public static string MusicBrainzBaseUrl = "https://www.musicbrainz.org";
+ public readonly string MusicBrainzBaseUrl;
- public MusicBrainzAlbumProvider(IHttpClient httpClient, IApplicationHost appHost, ILogger logger, IJsonSerializer json, IXmlReaderSettingsFactory xmlSettings)
+ /// <summary>
+ /// The Jellyfin user-agent is unrestricted but source IP must not exceed
+ /// one request per second, therefore we rate limit to avoid throttling.
+ /// Be prudent, use a value slightly above the minimun required.
+ /// https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting
+ /// </summary>
+ private const long MusicBrainzQueryIntervalMs = 1050u;
+
+ /// <summary>
+ /// For each single MB lookup/search, this is the maximum number of
+ /// attempts that shall be made whilst receiving a 503 Server
+ /// Unavailable (indicating throttled) response.
+ /// </summary>
+ private const uint MusicBrainzQueryAttempts = 5u;
+
+ public MusicBrainzAlbumProvider(
+ IHttpClient httpClient,
+ IApplicationHost appHost,
+ ILogger logger,
+ IJsonSerializer json,
+ IConfiguration configuration)
{
_httpClient = httpClient;
_appHost = appHost;
_logger = logger;
_json = json;
- _xmlSettings = xmlSettings;
+
+ MusicBrainzBaseUrl = configuration["MusicBrainz:BaseUrl"];
+
+ // Use a stopwatch to ensure we don't exceed the MusicBrainz rate limit
+ _stopWatchMusicBrainz.Start();
+
Current = this;
}
@@ -47,9 +72,7 @@ namespace MediaBrowser.Providers.Music
var releaseId = searchInfo.GetReleaseId();
var releaseGroupId = searchInfo.GetReleaseGroupId();
- string url = null;
- var isNameSearch = false;
- bool forceMusicBrainzProper = false;
+ string url;
if (!string.IsNullOrEmpty(releaseId))
{
@@ -58,7 +81,6 @@ namespace MediaBrowser.Providers.Music
else if (!string.IsNullOrEmpty(releaseGroupId))
{
url = string.Format("/ws/2/release?release-group={0}", releaseGroupId);
- forceMusicBrainzProper = true;
}
else
{
@@ -72,8 +94,6 @@ namespace MediaBrowser.Providers.Music
}
else
{
- isNameSearch = true;
-
// I'm sure there is a better way but for now it resolves search for 12" Mixes
var queryName = searchInfo.Name.Replace("\"", string.Empty);
@@ -85,7 +105,7 @@ namespace MediaBrowser.Providers.Music
if (!string.IsNullOrWhiteSpace(url))
{
- using (var response = await GetMusicBrainzResponse(url, isNameSearch, forceMusicBrainzProper, cancellationToken).ConfigureAwait(false))
+ using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
{
using (var stream = response.Content)
{
@@ -94,18 +114,20 @@ namespace MediaBrowser.Providers.Music
}
}
- return new List<RemoteSearchResult>();
+ return Enumerable.Empty<RemoteSearchResult>();
}
- private List<RemoteSearchResult> GetResultsFromResponse(Stream stream)
+ private IEnumerable<RemoteSearchResult> GetResultsFromResponse(Stream stream)
{
using (var oReader = new StreamReader(stream, Encoding.UTF8))
{
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
+ var settings = new XmlReaderSettings()
+ {
+ ValidationType = ValidationType.None,
+ CheckCharacters = false,
+ IgnoreProcessingInstructions = true,
+ IgnoreComments = true
+ };
using (var reader = XmlReader.Create(oReader, settings))
{
@@ -141,7 +163,7 @@ namespace MediaBrowser.Providers.Music
return result;
- }).ToList();
+ });
}
}
}
@@ -239,23 +261,21 @@ namespace MediaBrowser.Providers.Music
WebUtility.UrlEncode(albumName),
artistId);
- using (var response = await GetMusicBrainzResponse(url, true, cancellationToken).ConfigureAwait(false))
+ using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
+ using (var stream = response.Content)
+ using (var oReader = new StreamReader(stream, Encoding.UTF8))
{
- using (var stream = response.Content)
+ var settings = new XmlReaderSettings()
{
- using (var oReader = new StreamReader(stream, Encoding.UTF8))
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
+ ValidationType = ValidationType.None,
+ CheckCharacters = false,
+ IgnoreProcessingInstructions = true,
+ IgnoreComments = true
+ };
- using (var reader = XmlReader.Create(oReader, settings))
- {
- return ReleaseResult.Parse(reader).FirstOrDefault();
- }
- }
+ using (var reader = XmlReader.Create(oReader, settings))
+ {
+ return ReleaseResult.Parse(reader).FirstOrDefault();
}
}
}
@@ -266,23 +286,21 @@ namespace MediaBrowser.Providers.Music
WebUtility.UrlEncode(albumName),
WebUtility.UrlEncode(artistName));
- using (var response = await GetMusicBrainzResponse(url, true, cancellationToken).ConfigureAwait(false))
+ using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
+ using (var stream = response.Content)
+ using (var oReader = new StreamReader(stream, Encoding.UTF8))
{
- using (var stream = response.Content)
+ var settings = new XmlReaderSettings()
{
- using (var oReader = new StreamReader(stream, Encoding.UTF8))
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
+ ValidationType = ValidationType.None,
+ CheckCharacters = false,
+ IgnoreProcessingInstructions = true,
+ IgnoreComments = true
+ };
- using (var reader = XmlReader.Create(oReader, settings))
- {
- return ReleaseResult.Parse(reader).FirstOrDefault();
- }
- }
+ using (var reader = XmlReader.Create(oReader, settings))
+ {
+ return ReleaseResult.Parse(reader).FirstOrDefault();
}
}
}
@@ -297,7 +315,7 @@ namespace MediaBrowser.Providers.Music
public List<ValueTuple<string, string>> Artists = new List<ValueTuple<string, string>>();
- public static List<ReleaseResult> Parse(XmlReader reader)
+ public static IEnumerable<ReleaseResult> Parse(XmlReader reader)
{
reader.MoveToContent();
reader.Read();
@@ -334,13 +352,11 @@ namespace MediaBrowser.Providers.Music
}
}
- return new List<ReleaseResult>();
+ return Enumerable.Empty<ReleaseResult>();
}
- private static List<ReleaseResult> ParseReleaseList(XmlReader reader)
+ private static IEnumerable<ReleaseResult> ParseReleaseList(XmlReader reader)
{
- var list = new List<ReleaseResult>();
-
reader.MoveToContent();
reader.Read();
@@ -365,7 +381,7 @@ namespace MediaBrowser.Providers.Music
var release = ParseRelease(subReader, releaseId);
if (release != null)
{
- list.Add(release);
+ yield return release;
}
}
break;
@@ -382,8 +398,6 @@ namespace MediaBrowser.Providers.Music
reader.Read();
}
}
-
- return list;
}
private static ReleaseResult ParseRelease(XmlReader reader, string releaseId)
@@ -548,7 +562,7 @@ namespace MediaBrowser.Providers.Music
return (null, null);
}
- private static ValueTuple<string, string> ParseArtistArtistCredit(XmlReader reader, string artistId)
+ private static (string name, string id) ParseArtistArtistCredit(XmlReader reader, string artistId)
{
reader.MoveToContent();
reader.Read();
@@ -582,34 +596,32 @@ namespace MediaBrowser.Providers.Music
}
}
- return new ValueTuple<string, string>(name, artistId);
+ return (name, artistId);
}
private async Task<string> GetReleaseIdFromReleaseGroupId(string releaseGroupId, CancellationToken cancellationToken)
{
var url = string.Format("/ws/2/release?release-group={0}", releaseGroupId);
- using (var response = await GetMusicBrainzResponse(url, true, true, cancellationToken).ConfigureAwait(false))
+ using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
+ using (var stream = response.Content)
+ using (var oReader = new StreamReader(stream, Encoding.UTF8))
{
- using (var stream = response.Content)
+ var settings = new XmlReaderSettings()
{
- using (var oReader = new StreamReader(stream, Encoding.UTF8))
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
+ ValidationType = ValidationType.None,
+ CheckCharacters = false,
+ IgnoreProcessingInstructions = true,
+ IgnoreComments = true
+ };
- using (var reader = XmlReader.Create(oReader, settings))
- {
- var result = ReleaseResult.Parse(reader).FirstOrDefault();
+ using (var reader = XmlReader.Create(oReader, settings))
+ {
+ var result = ReleaseResult.Parse(reader).FirstOrDefault();
- if (result != null)
- {
- return result.ReleaseId;
- }
- }
+ if (result != null)
+ {
+ return result.ReleaseId;
}
}
}
@@ -627,57 +639,55 @@ namespace MediaBrowser.Providers.Music
{
var url = string.Format("/ws/2/release-group/?query=reid:{0}", releaseEntryId);
- using (var response = await GetMusicBrainzResponse(url, false, cancellationToken).ConfigureAwait(false))
+ using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
+ using (var stream = response.Content)
+ using (var oReader = new StreamReader(stream, Encoding.UTF8))
{
- using (var stream = response.Content)
+ var settings = new XmlReaderSettings()
{
- using (var oReader = new StreamReader(stream, Encoding.UTF8))
- {
- var settings = _xmlSettings.Create(false);
+ ValidationType = ValidationType.None,
+ CheckCharacters = false,
+ IgnoreProcessingInstructions = true,
+ IgnoreComments = true
+ };
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
+ using (var reader = XmlReader.Create(oReader, settings))
+ {
+ reader.MoveToContent();
+ reader.Read();
- using (var reader = XmlReader.Create(oReader, settings))
+ // Loop through each element
+ while (!reader.EOF && reader.ReadState == ReadState.Interactive)
+ {
+ if (reader.NodeType == XmlNodeType.Element)
{
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
+ switch (reader.Name)
{
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
+ case "release-group-list":
{
- case "release-group-list":
- {
- if (reader.IsEmptyElement)
- {
- reader.Read();
- continue;
- }
- using (var subReader = reader.ReadSubtree())
- {
- return GetFirstReleaseGroupId(subReader);
- }
- }
- default:
- {
- reader.Skip();
- break;
- }
+ if (reader.IsEmptyElement)
+ {
+ reader.Read();
+ continue;
+ }
+ using (var subReader = reader.ReadSubtree())
+ {
+ return GetFirstReleaseGroupId(subReader);
+ }
+ }
+ default:
+ {
+ reader.Skip();
+ break;
}
- }
- else
- {
- reader.Read();
- }
}
- return null;
+ }
+ else
+ {
+ reader.Read();
}
}
+ return null;
}
}
}
@@ -714,37 +724,56 @@ namespace MediaBrowser.Providers.Music
return null;
}
- internal Task<HttpResponseInfo> GetMusicBrainzResponse(string url, bool isSearch, CancellationToken cancellationToken)
- {
- return GetMusicBrainzResponse(url, isSearch, false, cancellationToken);
- }
-
/// <summary>
- /// Gets the music brainz response.
+ /// Makes request to MusicBrainz server and awaits a response.
+ /// A 503 Service Unavailable response indicates throttling to maintain a rate limit.
+ /// A number of retries shall be made in order to try and satisfy the request before
+ /// giving up and returning null.
/// </summary>
- internal async Task<HttpResponseInfo> GetMusicBrainzResponse(string url, bool isSearch, bool forceMusicBrainzProper, CancellationToken cancellationToken)
+ internal async Task<HttpResponseInfo> GetMusicBrainzResponse(string url, CancellationToken cancellationToken)
{
- var urlInfo = new MbzUrl(MusicBrainzBaseUrl, 1000);
- var throttleMs = urlInfo.throttleMs;
+ var options = new HttpRequestOptions
+ {
+ Url = MusicBrainzBaseUrl.TrimEnd('/') + url,
+ CancellationToken = cancellationToken,
+ // MusicBrainz request a contact email address is supplied, as comment, in user agent field:
+ // https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting#User-Agent
+ UserAgent = string.Format("{0} ( {1} )", _appHost.ApplicationUserAgent, _appHost.ApplicationUserAgentAddress),
+ BufferContent = false
+ };
+
+ HttpResponseInfo response;
+ var attempts = 0u;
- if (throttleMs > 0)
+ do
{
- // MusicBrainz is extremely adamant about limiting to one request per second
- _logger.LogDebug("Throttling MusicBrainz by {0}ms", throttleMs.ToString(CultureInfo.InvariantCulture));
- await Task.Delay(throttleMs, cancellationToken).ConfigureAwait(false);
- }
+ attempts++;
- url = urlInfo.url.TrimEnd('/') + url;
+ if (_stopWatchMusicBrainz.ElapsedMilliseconds < MusicBrainzQueryIntervalMs)
+ {
+ // MusicBrainz is extremely adamant about limiting to one request per second
+ var delayMs = MusicBrainzQueryIntervalMs - _stopWatchMusicBrainz.ElapsedMilliseconds;
+ await Task.Delay((int)delayMs, cancellationToken).ConfigureAwait(false);
+ }
- var options = new HttpRequestOptions
+ // Write time since last request to debug log as evidence we're meeting rate limit
+ // requirement, before resetting stopwatch back to zero.
+ _logger.LogDebug("GetMusicBrainzResponse: Time since previous request: {0} ms", _stopWatchMusicBrainz.ElapsedMilliseconds);
+ _stopWatchMusicBrainz.Restart();
+
+ response = await _httpClient.SendAsync(options, "GET").ConfigureAwait(false);
+
+ // We retry a finite number of times, and only whilst MB is indcating 503 (throttling)
+ }
+ while (attempts < MusicBrainzQueryAttempts && response.StatusCode == HttpStatusCode.ServiceUnavailable);
+
+ // Log error if unable to query MB database due to throttling
+ if (attempts == MusicBrainzQueryAttempts && response.StatusCode == HttpStatusCode.ServiceUnavailable )
{
- Url = url,
- CancellationToken = cancellationToken,
- UserAgent = _appHost.ApplicationUserAgent,
- BufferContent = throttleMs > 0
- };
+ _logger.LogError("GetMusicBrainzResponse: 503 Service Unavailable (throttled) response received {0} times whilst requesting {1}", attempts, options.Url);
+ }
- return await _httpClient.SendAsync(options, "GET").ConfigureAwait(false);
+ return response;
}
public int Order => 0;
@@ -753,17 +782,5 @@ namespace MediaBrowser.Providers.Music
{
throw new NotImplementedException();
}
-
- internal class MbzUrl
- {
- internal MbzUrl(string url, int throttleMs)
- {
- this.url = url;
- this.throttleMs = throttleMs;
- }
-
- public string url { get; set; }
- public int throttleMs { get; set; }
- }
}
}
diff --git a/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs
index 8d10834c3..59280df89 100644
--- a/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs
+++ b/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs
@@ -13,17 +13,14 @@ using MediaBrowser.Controller.Extensions;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
-using MediaBrowser.Model.Xml;
namespace MediaBrowser.Providers.Music
{
public class MusicBrainzArtistProvider : IRemoteMetadataProvider<MusicArtist, ArtistInfo>
{
- private readonly IXmlReaderSettingsFactory _xmlSettings;
-
- public MusicBrainzArtistProvider(IXmlReaderSettingsFactory xmlSettings)
+ public MusicBrainzArtistProvider()
{
- _xmlSettings = xmlSettings;
+
}
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
@@ -34,7 +31,7 @@ namespace MediaBrowser.Providers.Music
{
var url = string.Format("/ws/2/artist/?query=arid:{0}", musicBrainzId);
- using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, false, cancellationToken).ConfigureAwait(false))
+ using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
{
using (var stream = response.Content)
{
@@ -49,11 +46,11 @@ namespace MediaBrowser.Providers.Music
var url = string.Format("/ws/2/artist/?query=\"{0}\"&dismax=true", UrlEncode(nameToSearch));
- using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, true, cancellationToken).ConfigureAwait(false))
+ using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
{
using (var stream = response.Content)
{
- var results = GetResultsFromResponse(stream);
+ var results = GetResultsFromResponse(stream).ToList();
if (results.Count > 0)
{
@@ -67,7 +64,7 @@ namespace MediaBrowser.Providers.Music
// Try again using the search with accent characters url
url = string.Format("/ws/2/artist/?query=artistaccent:\"{0}\"", UrlEncode(nameToSearch));
- using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, true, cancellationToken).ConfigureAwait(false))
+ using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
{
using (var stream = response.Content)
{
@@ -77,18 +74,20 @@ namespace MediaBrowser.Providers.Music
}
}
- return new List<RemoteSearchResult>();
+ return Enumerable.Empty<RemoteSearchResult>();
}
- private List<RemoteSearchResult> GetResultsFromResponse(Stream stream)
+ private IEnumerable<RemoteSearchResult> GetResultsFromResponse(Stream stream)
{
using (var oReader = new StreamReader(stream, Encoding.UTF8))
{
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
+ var settings = new XmlReaderSettings()
+ {
+ ValidationType = ValidationType.None,
+ CheckCharacters = false,
+ IgnoreProcessingInstructions = true,
+ IgnoreComments = true
+ };
using (var reader = XmlReader.Create(oReader, settings))
{
@@ -127,15 +126,13 @@ namespace MediaBrowser.Providers.Music
}
}
- return new List<RemoteSearchResult>();
+ return Enumerable.Empty<RemoteSearchResult>();
}
}
}
- private List<RemoteSearchResult> ParseArtistList(XmlReader reader)
+ private IEnumerable<RemoteSearchResult> ParseArtistList(XmlReader reader)
{
- var list = new List<RemoteSearchResult>();
-
reader.MoveToContent();
reader.Read();
@@ -160,7 +157,7 @@ namespace MediaBrowser.Providers.Music
var artist = ParseArtist(subReader, mbzId);
if (artist != null)
{
- list.Add(artist);
+ yield return artist;
}
}
break;
@@ -177,8 +174,6 @@ namespace MediaBrowser.Providers.Music
reader.Read();
}
}
-
- return list;
}
private RemoteSearchResult ParseArtist(XmlReader reader, string artistId)
@@ -278,7 +273,7 @@ namespace MediaBrowser.Providers.Music
/// </summary>
/// <param name="name">The name.</param>
/// <returns>System.String.</returns>
- private string UrlEncode(string name)
+ private static string UrlEncode(string name)
{
return WebUtility.UrlEncode(name);
}
diff --git a/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs b/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs
index 181e88820..8c8b99e89 100644
--- a/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs
+++ b/MediaBrowser.Providers/People/TvdbPersonImageProvider.cs
@@ -1,42 +1,35 @@
using System;
using System.Collections.Generic;
-using System.IO;
using System.Linq;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using System.Xml;
using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
-using MediaBrowser.Model.Xml;
-using MediaBrowser.Providers.TV;
using MediaBrowser.Providers.TV.TheTVDB;
+using Microsoft.Extensions.Logging;
+using TvDbSharper;
namespace MediaBrowser.Providers.People
{
public class TvdbPersonImageProvider : IRemoteImageProvider, IHasOrder
{
- private readonly IServerConfigurationManager _config;
- private readonly ILibraryManager _libraryManager;
private readonly IHttpClient _httpClient;
- private readonly IFileSystem _fileSystem;
- private readonly IXmlReaderSettingsFactory _xmlSettings;
+ private readonly ILogger _logger;
+ private readonly ILibraryManager _libraryManager;
+ private readonly TvDbClientManager _tvDbClientManager;
- public TvdbPersonImageProvider(IServerConfigurationManager config, ILibraryManager libraryManager, IHttpClient httpClient, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlSettings)
+ public TvdbPersonImageProvider(ILibraryManager libraryManager, IHttpClient httpClient, ILogger<TvdbPersonImageProvider> logger, TvDbClientManager tvDbClientManager)
{
- _config = config;
_libraryManager = libraryManager;
_httpClient = httpClient;
- _fileSystem = fileSystem;
- _xmlSettings = xmlSettings;
+ _logger = logger;
+ _tvDbClientManager = tvDbClientManager;
}
public string Name => ProviderName;
@@ -56,7 +49,7 @@ namespace MediaBrowser.Providers.People
};
}
- public Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
+ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var seriesWithPerson = _libraryManager.GetItemList(new InternalItemsQuery
{
@@ -71,152 +64,44 @@ namespace MediaBrowser.Providers.People
.Where(i => TvdbSeriesProvider.IsValidSeries(i.ProviderIds))
.ToList();
- var infos = seriesWithPerson.Select(i => GetImageFromSeriesData(i, item.Name, cancellationToken))
+ var infos = (await Task.WhenAll(seriesWithPerson.Select(async i =>
+ await GetImageFromSeriesData(i, item.Name, cancellationToken).ConfigureAwait(false)))
+ .ConfigureAwait(false))
.Where(i => i != null)
.Take(1);
- return Task.FromResult(infos);
+ return infos;
}
- private RemoteImageInfo GetImageFromSeriesData(Series series, string personName, CancellationToken cancellationToken)
+ private async Task<RemoteImageInfo> GetImageFromSeriesData(Series series, string personName, CancellationToken cancellationToken)
{
- var tvdbPath = TvdbSeriesProvider.GetSeriesDataPath(_config.ApplicationPaths, series.ProviderIds);
-
- var actorXmlPath = Path.Combine(tvdbPath, "actors.xml");
+ var tvdbId = Convert.ToInt32(series.GetProviderId(MetadataProviders.Tvdb));
try
{
- return GetImageInfo(actorXmlPath, personName, cancellationToken);
- }
- catch (FileNotFoundException)
- {
- return null;
- }
- catch (IOException)
- {
- return null;
- }
- }
-
- private RemoteImageInfo GetImageInfo(string xmlFile, string personName, CancellationToken cancellationToken)
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- using (var fileStream = _fileSystem.GetFileStream(xmlFile, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read))
- {
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
- {
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Actor":
- {
- if (reader.IsEmptyElement)
- {
- reader.Read();
- continue;
- }
- using (var subtree = reader.ReadSubtree())
- {
- var info = FetchImageInfoFromActorNode(personName, subtree);
-
- if (info != null)
- {
- return info;
- }
- }
- break;
- }
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
- }
- }
-
- return null;
- }
-
- /// <summary>
- /// Fetches the data from actor node.
- /// </summary>
- /// <param name="personName">Name of the person.</param>
- /// <param name="reader">The reader.</param>
- /// <returns>System.String.</returns>
- private RemoteImageInfo FetchImageInfoFromActorNode(string personName, XmlReader reader)
- {
- string name = null;
- string image = null;
-
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Name":
- {
- name = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
- break;
- }
-
- case "Image":
- {
- image = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
+ var actorsResult = await _tvDbClientManager
+ .GetActorsAsync(tvdbId, series.GetPreferredMetadataLanguage(), cancellationToken)
+ .ConfigureAwait(false);
+ var actor = actorsResult.Data.FirstOrDefault(a =>
+ string.Equals(a.Name, personName, StringComparison.OrdinalIgnoreCase) &&
+ !string.IsNullOrEmpty(a.Image));
+ if (actor == null)
{
- reader.Read();
+ return null;
}
- }
- if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(image) &&
- string.Equals(name, personName, StringComparison.OrdinalIgnoreCase))
- {
return new RemoteImageInfo
{
- Url = TVUtils.BannerUrl + image,
+ Url = TvdbUtils.BannerUrl + actor.Image,
Type = ImageType.Primary,
ProviderName = Name
-
};
}
-
- return null;
+ catch (TvDbServerException e)
+ {
+ _logger.LogError(e, "Failed to retrieve actor {ActorName} from series {SeriesTvdbId}", personName, tvdbId);
+ return null;
+ }
}
public int Order => 1;
diff --git a/MediaBrowser.Providers/Properties/AssemblyInfo.cs b/MediaBrowser.Providers/Properties/AssemblyInfo.cs
index d2b13fc89..f1c46899c 100644
--- a/MediaBrowser.Providers/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.Providers/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs
index 25ad36620..752c0941d 100644
--- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs
+++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
-using System.IO;
using System.Linq;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using System.Xml;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
@@ -15,7 +12,6 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.Providers.TV.TheTVDB;
using Microsoft.Extensions.Logging;
@@ -28,77 +24,58 @@ namespace MediaBrowser.Providers.TV
private readonly ILibraryManager _libraryManager;
private readonly ILocalizationManager _localization;
private readonly IFileSystem _fileSystem;
+ private readonly TvDbClientManager _tvDbClientManager;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
- private readonly IXmlReaderSettingsFactory _xmlSettings;
+ private const double UnairedEpisodeThresholdDays = 2;
- public MissingEpisodeProvider(ILogger logger, IServerConfigurationManager config, ILibraryManager libraryManager, ILocalizationManager localization, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlSettings)
+ public MissingEpisodeProvider(
+ ILogger logger,
+ IServerConfigurationManager config,
+ ILibraryManager libraryManager,
+ ILocalizationManager localization,
+ IFileSystem fileSystem,
+ TvDbClientManager tvDbClientManager)
{
_logger = logger;
_config = config;
_libraryManager = libraryManager;
_localization = localization;
_fileSystem = fileSystem;
- _xmlSettings = xmlSettings;
+ _tvDbClientManager = tvDbClientManager;
}
public async Task<bool> Run(Series series, bool addNewItems, CancellationToken cancellationToken)
{
var tvdbId = series.GetProviderId(MetadataProviders.Tvdb);
-
- // Todo: Support series by imdb id
- var seriesProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
- seriesProviderIds[MetadataProviders.Tvdb.ToString()] = tvdbId;
-
- var seriesDataPath = TvdbSeriesProvider.GetSeriesDataPath(_config.ApplicationPaths, seriesProviderIds);
-
- // Doesn't have required provider id's
- if (string.IsNullOrWhiteSpace(seriesDataPath))
- {
- return false;
- }
-
- // Check this in order to avoid logging an exception due to directory not existing
- if (!Directory.Exists(seriesDataPath))
+ if (string.IsNullOrEmpty(tvdbId))
{
return false;
}
- var episodeFiles = _fileSystem.GetFilePaths(seriesDataPath)
- .Where(i => string.Equals(Path.GetExtension(i), ".xml", StringComparison.OrdinalIgnoreCase))
- .Select(Path.GetFileNameWithoutExtension)
- .Where(i => i.StartsWith("episode-", StringComparison.OrdinalIgnoreCase))
- .ToList();
+ var episodes = await _tvDbClientManager.GetAllEpisodesAsync(Convert.ToInt32(tvdbId), series.GetPreferredMetadataLanguage(), cancellationToken);
- var episodeLookup = episodeFiles
+ var episodeLookup = episodes
.Select(i =>
{
- var parts = i.Split('-');
-
- if (parts.Length == 3)
- {
- if (int.TryParse(parts[1], NumberStyles.Integer, _usCulture, out var seasonNumber))
- {
- if (int.TryParse(parts[2], NumberStyles.Integer, _usCulture, out var episodeNumber))
- {
- return new ValueTuple<int, int>(seasonNumber, episodeNumber);
- }
- }
- }
-
- return new ValueTuple<int, int>(-1, -1);
+ DateTime.TryParse(i.FirstAired, out var firstAired);
+ var seasonNumber = i.AiredSeason.GetValueOrDefault(-1);
+ var episodeNumber = i.AiredEpisodeNumber.GetValueOrDefault(-1);
+ return (seasonNumber: seasonNumber, episodeNumber: episodeNumber, firstAired: firstAired);
})
- .Where(i => i.Item1 != -1 && i.Item2 != -1)
+ .Where(i => i.seasonNumber != -1 && i.episodeNumber != -1)
+ .OrderBy(i => i.seasonNumber)
+ .ThenBy(i => i.episodeNumber)
.ToList();
var allRecursiveChildren = series.GetRecursiveChildren();
- var hasBadData = HasInvalidContent(series, allRecursiveChildren);
+ var hasBadData = HasInvalidContent(allRecursiveChildren);
// Be conservative here to avoid creating missing episodes for ones they already have
var addMissingEpisodes = !hasBadData && _libraryManager.GetLibraryOptions(series).ImportMissingEpisodes;
- var anySeasonsRemoved = RemoveObsoleteOrMissingSeasons(series, allRecursiveChildren, episodeLookup);
+ var anySeasonsRemoved = RemoveObsoleteOrMissingSeasons(allRecursiveChildren, episodeLookup);
if (anySeasonsRemoved)
{
@@ -106,7 +83,7 @@ namespace MediaBrowser.Providers.TV
allRecursiveChildren = series.GetRecursiveChildren();
}
- var anyEpisodesRemoved = RemoveObsoleteOrMissingEpisodes(series, allRecursiveChildren, episodeLookup, addMissingEpisodes);
+ var anyEpisodesRemoved = RemoveObsoleteOrMissingEpisodes(allRecursiveChildren, episodeLookup, addMissingEpisodes);
if (anyEpisodesRemoved)
{
@@ -118,7 +95,7 @@ namespace MediaBrowser.Providers.TV
if (addNewItems && series.IsMetadataFetcherEnabled(_libraryManager.GetLibraryOptions(series), TvdbSeriesProvider.Current.Name))
{
- hasNewEpisodes = await AddMissingEpisodes(series, allRecursiveChildren, addMissingEpisodes, seriesDataPath, episodeLookup, cancellationToken)
+ hasNewEpisodes = await AddMissingEpisodes(series, allRecursiveChildren, addMissingEpisodes, episodeLookup, cancellationToken)
.ConfigureAwait(false);
}
@@ -134,7 +111,7 @@ namespace MediaBrowser.Providers.TV
/// Returns true if a series has any seasons or episodes without season or episode numbers
/// If this data is missing no virtual items will be added in order to prevent possible duplicates
/// </summary>
- private bool HasInvalidContent(Series series, IList<BaseItem> allItems)
+ private bool HasInvalidContent(IList<BaseItem> allItems)
{
return allItems.OfType<Season>().Any(i => !i.IndexNumber.HasValue) ||
allItems.OfType<Episode>().Any(i =>
@@ -149,43 +126,24 @@ namespace MediaBrowser.Providers.TV
});
}
- private const double UnairedEpisodeThresholdDays = 2;
-
- /// <summary>
- /// Adds the missing episodes.
- /// </summary>
- /// <param name="series">The series.</param>
- /// <returns>Task.</returns>
- private async Task<bool> AddMissingEpisodes(Series series,
- IList<BaseItem> allItems,
+ private async Task<bool> AddMissingEpisodes(
+ Series series,
+ IEnumerable<BaseItem> allItems,
bool addMissingEpisodes,
- string seriesDataPath,
- IEnumerable<ValueTuple<int, int>> episodeLookup,
+ IReadOnlyCollection<(int seasonNumber, int episodenumber, DateTime firstAired)> episodeLookup,
CancellationToken cancellationToken)
{
- var existingEpisodes = allItems.OfType<Episode>()
- .ToList();
+ var existingEpisodes = allItems.OfType<Episode>().ToList();
- var lookup = episodeLookup as IList<ValueTuple<int, int>> ?? episodeLookup.ToList();
-
- var seasonCounts = (from e in lookup
- group e by e.Item1 into g
- select g)
- .ToDictionary(g => g.Key, g => g.Count());
+ var seasonCounts = episodeLookup.GroupBy(e => e.seasonNumber).ToDictionary(g => g.Key, g => g.Count());
var hasChanges = false;
- foreach (var tuple in lookup)
+ foreach (var tuple in episodeLookup)
{
- if (tuple.Item1 <= 0)
- {
- // Ignore season zeros
- continue;
- }
-
- if (tuple.Item2 <= 0)
+ if (tuple.seasonNumber <= 0 || tuple.episodenumber <= 0)
{
- // Ignore episode zeros
+ // Ignore episode/season zeros
continue;
}
@@ -196,33 +154,15 @@ namespace MediaBrowser.Providers.TV
continue;
}
- var airDate = GetAirDate(seriesDataPath, tuple.Item1, tuple.Item2);
-
- if (!airDate.HasValue)
- {
- continue;
- }
-
- var now = DateTime.UtcNow;
+ var airDate = tuple.firstAired;
- now = now.AddDays(0 - UnairedEpisodeThresholdDays);
-
- if (airDate.Value < now)
- {
- if (addMissingEpisodes)
- {
- // tvdb has a lot of nearly blank episodes
- _logger.LogInformation("Creating virtual missing episode {0} {1}x{2}", series.Name, tuple.Item1, tuple.Item2);
- await AddEpisode(series, tuple.Item1, tuple.Item2, cancellationToken).ConfigureAwait(false);
+ var now = DateTime.UtcNow.AddDays(-UnairedEpisodeThresholdDays);
- hasChanges = true;
- }
- }
- else if (airDate.Value > now)
+ if (airDate < now && addMissingEpisodes || airDate > now)
{
// tvdb has a lot of nearly blank episodes
- _logger.LogInformation("Creating virtual unaired episode {0} {1}x{2}", series.Name, tuple.Item1, tuple.Item2);
- await AddEpisode(series, tuple.Item1, tuple.Item2, cancellationToken).ConfigureAwait(false);
+ _logger.LogInformation("Creating virtual missing/unaired episode {0} {1}x{2}", series.Name, tuple.seasonNumber, tuple.episodenumber);
+ await AddEpisode(series, tuple.seasonNumber, tuple.episodenumber, cancellationToken).ConfigureAwait(false);
hasChanges = true;
}
@@ -234,59 +174,58 @@ namespace MediaBrowser.Providers.TV
/// <summary>
/// Removes the virtual entry after a corresponding physical version has been added
/// </summary>
- private bool RemoveObsoleteOrMissingEpisodes(Series series,
- IList<BaseItem> allRecursiveChildren,
- IEnumerable<ValueTuple<int, int>> episodeLookup,
+ private bool RemoveObsoleteOrMissingEpisodes(
+ IEnumerable<BaseItem> allRecursiveChildren,
+ IEnumerable<(int seasonNumber, int episodeNumber, DateTime firstAired)> episodeLookup,
bool allowMissingEpisodes)
{
- var existingEpisodes = allRecursiveChildren.OfType<Episode>()
- .ToList();
-
- var physicalEpisodes = existingEpisodes
- .Where(i => i.LocationType != LocationType.Virtual)
- .ToList();
+ var existingEpisodes = allRecursiveChildren.OfType<Episode>();
- var virtualEpisodes = existingEpisodes
- .Where(i => i.LocationType == LocationType.Virtual)
- .ToList();
+ var physicalEpisodes = new List<Episode>();
+ var virtualEpisodes = new List<Episode>();
+ foreach (var episode in existingEpisodes)
+ {
+ if (episode.LocationType == LocationType.Virtual)
+ {
+ virtualEpisodes.Add(episode);
+ }
+ else
+ {
+ physicalEpisodes.Add(episode);
+ }
+ }
var episodesToRemove = virtualEpisodes
.Where(i =>
{
- if (i.IndexNumber.HasValue && i.ParentIndexNumber.HasValue)
+ if (!i.IndexNumber.HasValue || !i.ParentIndexNumber.HasValue)
{
- var seasonNumber = i.ParentIndexNumber.Value;
- var episodeNumber = i.IndexNumber.Value;
-
- // If there's a physical episode with the same season and episode number, delete it
- if (physicalEpisodes.Any(p =>
- p.ParentIndexNumber.HasValue && (p.ParentIndexNumber.Value) == seasonNumber &&
- p.ContainsEpisodeNumber(episodeNumber)))
- {
- return true;
- }
+ return true;
+ }
- // If the episode no longer exists in the remote lookup, delete it
- if (!episodeLookup.Any(e => e.Item1 == seasonNumber && e.Item2 == episodeNumber))
- {
- return true;
- }
+ var seasonNumber = i.ParentIndexNumber.Value;
+ var episodeNumber = i.IndexNumber.Value;
- if (!allowMissingEpisodes && i.IsMissingEpisode)
- {
- // If it's missing, but not unaired, remove it
- if (!i.PremiereDate.HasValue || i.PremiereDate.Value.ToLocalTime().Date.AddDays(UnairedEpisodeThresholdDays) < DateTime.Now.Date)
- {
- return true;
- }
- }
+ // If there's a physical episode with the same season and episode number, delete it
+ if (physicalEpisodes.Any(p =>
+ p.ParentIndexNumber.HasValue && p.ParentIndexNumber.Value == seasonNumber &&
+ p.ContainsEpisodeNumber(episodeNumber)))
+ {
+ return true;
+ }
- return false;
+ // If the episode no longer exists in the remote lookup, delete it
+ if (!episodeLookup.Any(e => e.seasonNumber == seasonNumber && e.episodeNumber == episodeNumber))
+ {
+ return true;
}
- return true;
- })
- .ToList();
+ // If it's missing, but not unaired, remove it
+ return !allowMissingEpisodes && i.IsMissingEpisode &&
+ (!i.PremiereDate.HasValue ||
+ i.PremiereDate.Value.ToLocalTime().Date.AddDays(UnairedEpisodeThresholdDays) <
+ DateTime.Now.Date);
+ });
var hasChanges = false;
@@ -295,7 +234,6 @@ namespace MediaBrowser.Providers.TV
_libraryManager.DeleteItem(episodeToRemove, new DeleteOptions
{
DeleteFileLocation = true
-
}, false);
hasChanges = true;
@@ -307,22 +245,27 @@ namespace MediaBrowser.Providers.TV
/// <summary>
/// Removes the obsolete or missing seasons.
/// </summary>
- /// <param name="series">The series.</param>
+ /// <param name="allRecursiveChildren"></param>
/// <param name="episodeLookup">The episode lookup.</param>
/// <returns>Task{System.Boolean}.</returns>
- private bool RemoveObsoleteOrMissingSeasons(Series series,
- IList<BaseItem> allRecursiveChildren,
- IEnumerable<ValueTuple<int, int>> episodeLookup)
+ private bool RemoveObsoleteOrMissingSeasons(IList<BaseItem> allRecursiveChildren,
+ IEnumerable<(int seasonNumber, int episodeNumber, DateTime firstAired)> episodeLookup)
{
var existingSeasons = allRecursiveChildren.OfType<Season>().ToList();
- var physicalSeasons = existingSeasons
- .Where(i => i.LocationType != LocationType.Virtual)
- .ToList();
-
- var virtualSeasons = existingSeasons
- .Where(i => i.LocationType == LocationType.Virtual)
- .ToList();
+ var physicalSeasons = new List<Season>();
+ var virtualSeasons = new List<Season>();
+ foreach (var season in existingSeasons)
+ {
+ if (season.LocationType == LocationType.Virtual)
+ {
+ virtualSeasons.Add(season);
+ }
+ else
+ {
+ physicalSeasons.Add(season);
+ }
+ }
var allEpisodes = allRecursiveChildren.OfType<Episode>().ToList();
@@ -334,28 +277,19 @@ namespace MediaBrowser.Providers.TV
var seasonNumber = i.IndexNumber.Value;
// If there's a physical season with the same number, delete it
- if (physicalSeasons.Any(p => p.IndexNumber.HasValue && (p.IndexNumber.Value) == seasonNumber && string.Equals(p.Series.PresentationUniqueKey, i.Series.PresentationUniqueKey, StringComparison.Ordinal)))
+ if (physicalSeasons.Any(p => p.IndexNumber.HasValue && p.IndexNumber.Value == seasonNumber && string.Equals(p.Series.PresentationUniqueKey, i.Series.PresentationUniqueKey, StringComparison.Ordinal)))
{
return true;
}
// If the season no longer exists in the remote lookup, delete it, but only if an existing episode doesn't require it
- if (episodeLookup.All(e => e.Item1 != seasonNumber))
- {
- if (allEpisodes.All(s => s.ParentIndexNumber != seasonNumber || s.IsInSeasonFolder))
- {
- return true;
- }
- }
-
- return false;
+ return episodeLookup.All(e => e.seasonNumber != seasonNumber) && allEpisodes.All(s => s.ParentIndexNumber != seasonNumber || s.IsInSeasonFolder);
}
// Season does not have a number
// Remove if there are no episodes directly in series without a season number
return allEpisodes.All(s => s.ParentIndexNumber.HasValue || s.IsInSeasonFolder);
- })
- .ToList();
+ });
var hasChanges = false;
@@ -392,21 +326,19 @@ namespace MediaBrowser.Providers.TV
season = await provider.AddSeason(series, seasonNumber, true, cancellationToken).ConfigureAwait(false);
}
- var name = string.Format("Episode {0}", episodeNumber.ToString(_usCulture));
+ var name = $"Episode {episodeNumber.ToString(_usCulture)}";
var episode = new Episode
{
Name = name,
IndexNumber = episodeNumber,
ParentIndexNumber = seasonNumber,
- Id = _libraryManager.GetNewItemId((series.Id + seasonNumber.ToString(_usCulture) + name), typeof(Episode)),
+ Id = _libraryManager.GetNewItemId(series.Id + seasonNumber.ToString(_usCulture) + name, typeof(Episode)),
IsVirtualItem = true,
- SeasonId = season == null ? Guid.Empty : season.Id,
+ SeasonId = season?.Id ?? Guid.Empty,
SeriesId = series.Id
};
- episode.SetParent(season);
-
season.AddChild(episode, cancellationToken);
await episode.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), cancellationToken).ConfigureAwait(false);
@@ -417,25 +349,31 @@ namespace MediaBrowser.Providers.TV
/// </summary>
/// <param name="existingEpisodes">The existing episodes.</param>
/// <param name="seasonCounts"></param>
- /// <param name="tuple">The tuple.</param>
+ /// <param name="episodeTuple"></param>
/// <returns>Episode.</returns>
- private Episode GetExistingEpisode(IList<Episode> existingEpisodes, Dictionary<int, int> seasonCounts, ValueTuple<int, int> tuple)
+ private Episode GetExistingEpisode(IList<Episode> existingEpisodes, IReadOnlyDictionary<int, int> seasonCounts, (int seasonNumber, int episodeNumber, DateTime firstAired) episodeTuple)
{
- var s = tuple.Item1;
- var e = tuple.Item2;
+ var seasonNumber = episodeTuple.seasonNumber;
+ var episodeNumber = episodeTuple.episodeNumber;
while (true)
{
- var episode = GetExistingEpisode(existingEpisodes, s, e);
+ var episode = GetExistingEpisode(existingEpisodes, seasonNumber, episodeNumber);
if (episode != null)
+ {
return episode;
+ }
- s--;
+ seasonNumber--;
- if (seasonCounts.ContainsKey(s))
- e += seasonCounts[s];
+ if (seasonCounts.ContainsKey(seasonNumber))
+ {
+ episodeNumber += seasonCounts[seasonNumber];
+ }
else
+ {
break;
+ }
}
return null;
@@ -446,88 +384,5 @@ namespace MediaBrowser.Providers.TV
return existingEpisodes
.FirstOrDefault(i => i.ParentIndexNumber == season && i.ContainsEpisodeNumber(episode));
}
-
- /// <summary>
- /// Gets the air date.
- /// </summary>
- /// <param name="seriesDataPath">The series data path.</param>
- /// <param name="seasonNumber">The season number.</param>
- /// <param name="episodeNumber">The episode number.</param>
- /// <returns>System.Nullable{DateTime}.</returns>
- private DateTime? GetAirDate(string seriesDataPath, int seasonNumber, int episodeNumber)
- {
- // First open up the tvdb xml file and make sure it has valid data
- var filename = string.Format("episode-{0}-{1}.xml", seasonNumber.ToString(_usCulture), episodeNumber.ToString(_usCulture));
-
- var xmlPath = Path.Combine(seriesDataPath, filename);
-
- DateTime? airDate = null;
-
- using (var fileStream = _fileSystem.GetFileStream(xmlPath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read))
- {
- // It appears the best way to filter out invalid entries is to only include those with valid air dates
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "EpisodeName":
- {
- var val = reader.ReadElementContentAsString();
- if (string.IsNullOrWhiteSpace(val))
- {
- // Not valid, ignore these
- return null;
- }
- break;
- }
- case "FirstAired":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (DateTime.TryParse(val, out var date))
- {
- airDate = date.ToUniversalTime();
- }
- }
-
- break;
- }
- default:
- {
- reader.Skip();
- break;
- }
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
- }
- }
-
- return airDate;
- }
}
}
diff --git a/MediaBrowser.Providers/TV/SeriesMetadataService.cs b/MediaBrowser.Providers/TV/SeriesMetadataService.cs
index 5f4f39d45..d5b0b6fd8 100644
--- a/MediaBrowser.Providers/TV/SeriesMetadataService.cs
+++ b/MediaBrowser.Providers/TV/SeriesMetadataService.cs
@@ -8,8 +8,8 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.Providers.Manager;
+using MediaBrowser.Providers.TV.TheTVDB;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.TV
@@ -17,12 +17,22 @@ namespace MediaBrowser.Providers.TV
public class SeriesMetadataService : MetadataService<Series, SeriesInfo>
{
private readonly ILocalizationManager _localization;
- private readonly IXmlReaderSettingsFactory _xmlSettings;
+ private readonly TvDbClientManager _tvDbClientManager;
- public SeriesMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager, ILocalizationManager localization, IXmlReaderSettingsFactory xmlSettings) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
+ public SeriesMetadataService(
+ IServerConfigurationManager serverConfigurationManager,
+ ILogger logger,
+ IProviderManager providerManager,
+ IFileSystem fileSystem,
+ IUserDataManager userDataManager,
+ ILibraryManager libraryManager,
+ ILocalizationManager localization,
+ TvDbClientManager tvDbClientManager
+ )
+ : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
_localization = localization;
- _xmlSettings = xmlSettings;
+ _tvDbClientManager = tvDbClientManager;
}
protected override async Task AfterMetadataRefresh(Series item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
@@ -32,12 +42,13 @@ namespace MediaBrowser.Providers.TV
var seasonProvider = new DummySeasonProvider(ServerConfigurationManager, Logger, _localization, LibraryManager, FileSystem);
await seasonProvider.Run(item, cancellationToken).ConfigureAwait(false);
+ // TODO why does it not register this itself omg
var provider = new MissingEpisodeProvider(Logger,
ServerConfigurationManager,
LibraryManager,
_localization,
FileSystem,
- _xmlSettings);
+ _tvDbClientManager);
try
{
diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs b/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs
new file mode 100644
index 000000000..efb8a0fe8
--- /dev/null
+++ b/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs
@@ -0,0 +1,244 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Threading;
+using System.Threading.Tasks;
+using MediaBrowser.Controller.Providers;
+using MediaBrowser.Model.Entities;
+using Microsoft.Extensions.Caching.Memory;
+using TvDbSharper;
+using TvDbSharper.Dto;
+
+namespace MediaBrowser.Providers.TV.TheTVDB
+{
+ public class TvDbClientManager
+ {
+ private readonly SemaphoreSlim _cacheWriteLock = new SemaphoreSlim(1, 1);
+ private readonly IMemoryCache _cache;
+ private readonly TvDbClient _tvDbClient;
+ private DateTime _tokenCreatedAt;
+ private const string DefaultLanguage = "en";
+
+ public TvDbClientManager(IMemoryCache memoryCache)
+ {
+ _cache = memoryCache;
+ _tvDbClient = new TvDbClient();
+ _tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey);
+ _tokenCreatedAt = DateTime.Now;
+ }
+
+ public TvDbClient TvDbClient
+ {
+ get
+ {
+ // Refresh if necessary
+ if (_tokenCreatedAt > DateTime.Now.Subtract(TimeSpan.FromHours(20)))
+ {
+ try
+ {
+ _tvDbClient.Authentication.RefreshTokenAsync();
+ }
+ catch
+ {
+ _tvDbClient.Authentication.AuthenticateAsync(TvdbUtils.TvdbApiKey);
+ }
+
+ _tokenCreatedAt = DateTime.Now;
+ }
+
+ return _tvDbClient;
+ }
+ }
+
+ public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByNameAsync(string name, string language,
+ CancellationToken cancellationToken)
+ {
+ var cacheKey = GenerateKey("series", name, language);
+ return TryGetValue(cacheKey, language,() => TvDbClient.Search.SearchSeriesByNameAsync(name, cancellationToken));
+ }
+
+ public Task<TvDbResponse<Series>> GetSeriesByIdAsync(int tvdbId, string language,
+ CancellationToken cancellationToken)
+ {
+ var cacheKey = GenerateKey("series", tvdbId, language);
+ return TryGetValue(cacheKey, language,() => TvDbClient.Series.GetAsync(tvdbId, cancellationToken));
+ }
+
+ public Task<TvDbResponse<EpisodeRecord>> GetEpisodesAsync(int episodeTvdbId, string language,
+ CancellationToken cancellationToken)
+ {
+ var cacheKey = GenerateKey("episode", episodeTvdbId, language);
+ return TryGetValue(cacheKey, language,() => TvDbClient.Episodes.GetAsync(episodeTvdbId, cancellationToken));
+ }
+
+ public async Task<List<EpisodeRecord>> GetAllEpisodesAsync(int tvdbId, string language,
+ CancellationToken cancellationToken)
+ {
+ // Traverse all episode pages and join them together
+ var episodes = new List<EpisodeRecord>();
+ var episodePage = await GetEpisodesPageAsync(tvdbId, new EpisodeQuery(), language, cancellationToken)
+ .ConfigureAwait(false);
+ episodes.AddRange(episodePage.Data);
+ if (!episodePage.Links.Next.HasValue || !episodePage.Links.Last.HasValue)
+ {
+ return episodes;
+ }
+
+ int next = episodePage.Links.Next.Value;
+ int last = episodePage.Links.Last.Value;
+
+ for (var page = next; page <= last; ++page)
+ {
+ episodePage = await GetEpisodesPageAsync(tvdbId, page, new EpisodeQuery(), language, cancellationToken)
+ .ConfigureAwait(false);
+ episodes.AddRange(episodePage.Data);
+ }
+
+ return episodes;
+ }
+
+ public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByImdbIdAsync(string imdbId, string language,
+ CancellationToken cancellationToken)
+ {
+ var cacheKey = GenerateKey("series", imdbId, language);
+ return TryGetValue(cacheKey, language,() => TvDbClient.Search.SearchSeriesByImdbIdAsync(imdbId, cancellationToken));
+ }
+
+ public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByZap2ItIdAsync(string zap2ItId, string language,
+ CancellationToken cancellationToken)
+ {
+ var cacheKey = GenerateKey("series", zap2ItId, language);
+ return TryGetValue( cacheKey, language,() => TvDbClient.Search.SearchSeriesByZap2ItIdAsync(zap2ItId, cancellationToken));
+ }
+ public Task<TvDbResponse<Actor[]>> GetActorsAsync(int tvdbId, string language,
+ CancellationToken cancellationToken)
+ {
+ var cacheKey = GenerateKey("actors", tvdbId, language);
+ return TryGetValue(cacheKey, language,() => TvDbClient.Series.GetActorsAsync(tvdbId, cancellationToken));
+ }
+
+ public Task<TvDbResponse<Image[]>> GetImagesAsync(int tvdbId, ImagesQuery imageQuery, string language,
+ CancellationToken cancellationToken)
+ {
+ var cacheKey = GenerateKey("images", tvdbId, language, imageQuery);
+ return TryGetValue(cacheKey, language,() => TvDbClient.Series.GetImagesAsync(tvdbId, imageQuery, cancellationToken));
+ }
+
+ public Task<TvDbResponse<Language[]>> GetLanguagesAsync(CancellationToken cancellationToken)
+ {
+ return TryGetValue("languages", null,() => TvDbClient.Languages.GetAllAsync(cancellationToken));
+ }
+
+ public Task<TvDbResponse<EpisodesSummary>> GetSeriesEpisodeSummaryAsync(int tvdbId, string language,
+ CancellationToken cancellationToken)
+ {
+ var cacheKey = GenerateKey("seriesepisodesummary", tvdbId, language);
+ return TryGetValue(cacheKey, language,
+ () => TvDbClient.Series.GetEpisodesSummaryAsync(tvdbId, cancellationToken));
+ }
+
+ public Task<TvDbResponse<EpisodeRecord[]>> GetEpisodesPageAsync(int tvdbId, int page, EpisodeQuery episodeQuery,
+ string language, CancellationToken cancellationToken)
+ {
+ var cacheKey = GenerateKey(language, tvdbId, episodeQuery);
+
+ return TryGetValue(cacheKey, language,
+ () => TvDbClient.Series.GetEpisodesAsync(tvdbId, page, episodeQuery, cancellationToken));
+ }
+
+ public Task<string> GetEpisodeTvdbId(EpisodeInfo searchInfo, string language,
+ CancellationToken cancellationToken)
+ {
+ searchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(),
+ out var seriesTvdbId);
+
+ var episodeQuery = new EpisodeQuery();
+
+ // Prefer SxE over premiere date as it is more robust
+ if (searchInfo.IndexNumber.HasValue && searchInfo.ParentIndexNumber.HasValue)
+ {
+ episodeQuery.AiredEpisode = searchInfo.IndexNumber.Value;
+ episodeQuery.AiredSeason = searchInfo.ParentIndexNumber.Value;
+ }
+ else if (searchInfo.PremiereDate.HasValue)
+ {
+ // tvdb expects yyyy-mm-dd format
+ episodeQuery.FirstAired = searchInfo.PremiereDate.Value.ToString("yyyy-MM-dd");
+ }
+
+ return GetEpisodeTvdbId(Convert.ToInt32(seriesTvdbId), episodeQuery, language, cancellationToken);
+ }
+
+ public async Task<string> GetEpisodeTvdbId(int seriesTvdbId, EpisodeQuery episodeQuery,
+ string language,
+ CancellationToken cancellationToken)
+ {
+ var episodePage =
+ await GetEpisodesPageAsync(Convert.ToInt32(seriesTvdbId), episodeQuery, language, cancellationToken)
+ .ConfigureAwait(false);
+ return episodePage.Data.FirstOrDefault()?.Id.ToString();
+ }
+
+ public Task<TvDbResponse<EpisodeRecord[]>> GetEpisodesPageAsync(int tvdbId, EpisodeQuery episodeQuery,
+ string language, CancellationToken cancellationToken)
+ {
+ return GetEpisodesPageAsync(tvdbId, 1, episodeQuery, language, cancellationToken);
+ }
+
+ private async Task<T> TryGetValue<T>(string key, string language, Func<Task<T>> resultFactory)
+ {
+ if (_cache.TryGetValue(key, out T cachedValue))
+ {
+ return cachedValue;
+ }
+
+ await _cacheWriteLock.WaitAsync().ConfigureAwait(false);
+ try
+ {
+ if (_cache.TryGetValue(key, out cachedValue))
+ {
+ return cachedValue;
+ }
+
+ _tvDbClient.AcceptedLanguage = TvdbUtils.NormalizeLanguage(language) ?? DefaultLanguage;
+ var result = await resultFactory.Invoke().ConfigureAwait(false);
+ _cache.Set(key, result, TimeSpan.FromHours(1));
+ return result;
+ }
+ finally
+ {
+ _cacheWriteLock.Release();
+ }
+ }
+
+ private static string GenerateKey(params object[] objects)
+ {
+ var key = string.Empty;
+
+ foreach (var obj in objects)
+ {
+ var objType = obj.GetType();
+ if (objType.IsPrimitive || objType == typeof(string))
+ {
+ key += obj + ";";
+ }
+ else
+ {
+ foreach (PropertyInfo propertyInfo in objType.GetProperties())
+ {
+ var currentValue = propertyInfo.GetValue(obj, null);
+ if (currentValue == null)
+ {
+ continue;
+ }
+
+ key += propertyInfo.Name + "=" + currentValue + ";";
+ }
+ }
+ }
+
+ return key;
+ }
+ }
+}
diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs
index 102a3d4ec..c04e98e64 100644
--- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs
+++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs
@@ -1,33 +1,30 @@
+using System;
using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
using System.Threading;
using System.Threading.Tasks;
-using System.Xml;
using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
-using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
+using Microsoft.Extensions.Logging;
+using TvDbSharper;
+using TvDbSharper.Dto;
namespace MediaBrowser.Providers.TV.TheTVDB
{
public class TvdbEpisodeImageProvider : IRemoteImageProvider
{
- private readonly IServerConfigurationManager _config;
- private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly IHttpClient _httpClient;
- private readonly IFileSystem _fileSystem;
+ private readonly ILogger _logger;
+ private readonly TvDbClientManager _tvDbClientManager;
- public TvdbEpisodeImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem)
+ public TvdbEpisodeImageProvider(IHttpClient httpClient, ILogger<TvdbEpisodeImageProvider> logger, TvDbClientManager tvDbClientManager)
{
- _config = config;
_httpClient = httpClient;
- _fileSystem = fileSystem;
+ _logger = logger;
+ _tvDbClientManager = tvDbClientManager;
}
public string Name => "TheTVDB";
@@ -45,113 +42,70 @@ namespace MediaBrowser.Providers.TV.TheTVDB
};
}
- public Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
+ public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var episode = (Episode)item;
var series = episode.Series;
-
+ var imageResult = new List<RemoteImageInfo>();
+ var language = item.GetPreferredMetadataLanguage();
if (series != null && TvdbSeriesProvider.IsValidSeries(series.ProviderIds))
{
- // Process images
- var seriesDataPath = TvdbSeriesProvider.GetSeriesDataPath(_config.ApplicationPaths, series.ProviderIds);
-
- var nodes = TvdbEpisodeProvider.Current.GetEpisodeXmlNodes(seriesDataPath, episode.GetLookupInfo());
-
- var result = nodes.Select(i => GetImageInfo(i, cancellationToken))
- .Where(i => i != null)
- .ToList();
+ var episodeTvdbId = episode.GetProviderId(MetadataProviders.Tvdb);
- return Task.FromResult<IEnumerable<RemoteImageInfo>>(result);
- }
-
- return Task.FromResult<IEnumerable<RemoteImageInfo>>(new RemoteImageInfo[] { });
- }
-
- private RemoteImageInfo GetImageInfo(XmlReader reader, CancellationToken cancellationToken)
- {
- var height = 225;
- var width = 400;
- var url = string.Empty;
-
- // Use XmlReader for best performance
- using (reader)
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
+ // Process images
+ try
{
- if (reader.NodeType == XmlNodeType.Element)
+ if (string.IsNullOrEmpty(episodeTvdbId))
{
- cancellationToken.ThrowIfCancellationRequested();
-
- switch (reader.Name)
+ var episodeInfo = new EpisodeInfo
{
- case "thumb_width":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- width = rval;
- }
- }
- break;
- }
-
- case "thumb_height":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- height = rval;
- }
- }
- break;
- }
-
- case "filename":
- {
- var val = reader.ReadElementContentAsString();
- if (!string.IsNullOrWhiteSpace(val))
- {
- url = TVUtils.BannerUrl + val;
- }
- break;
- }
- default:
- {
- reader.Skip();
- break;
- }
+ IndexNumber = episode.IndexNumber.Value,
+ ParentIndexNumber = episode.ParentIndexNumber.Value,
+ SeriesProviderIds = series.ProviderIds
+ };
+ episodeTvdbId = await _tvDbClientManager
+ .GetEpisodeTvdbId(episodeInfo, language, cancellationToken).ConfigureAwait(false);
+ if (string.IsNullOrEmpty(episodeTvdbId))
+ {
+ _logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
+ episodeInfo.ParentIndexNumber, episodeInfo.IndexNumber, series.GetProviderId(MetadataProviders.Tvdb));
+ return imageResult;
}
}
- else
+
+ var episodeResult =
+ await _tvDbClientManager
+ .GetEpisodesAsync(Convert.ToInt32(episodeTvdbId), language, cancellationToken)
+ .ConfigureAwait(false);
+
+ var image = GetImageInfo(episodeResult.Data);
+ if (image != null)
{
- reader.Read();
+ imageResult.Add(image);
}
}
+ catch (TvDbServerException e)
+ {
+ _logger.LogError(e, "Failed to retrieve episode images for {TvDbId}", episodeTvdbId);
+ }
}
- if (string.IsNullOrEmpty(url))
+ return imageResult;
+ }
+
+ private RemoteImageInfo GetImageInfo(EpisodeRecord episode)
+ {
+ if (string.IsNullOrEmpty(episode.Filename))
{
return null;
}
return new RemoteImageInfo
{
- Width = width,
- Height = height,
+ Width = Convert.ToInt32(episode.ThumbWidth),
+ Height = Convert.ToInt32(episode.ThumbHeight),
ProviderName = Name,
- Url = url,
+ Url = TvdbUtils.BannerUrl + episode.Filename,
Type = ImageType.Primary
};
}
diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs
index be137e879..5474a7c39 100644
--- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs
+++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs
@@ -1,22 +1,16 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using System.Xml;
using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
+using TvDbSharper;
+using TvDbSharper.Dto;
namespace MediaBrowser.Providers.TV.TheTVDB
{
@@ -24,44 +18,52 @@ namespace MediaBrowser.Providers.TV.TheTVDB
/// <summary>
/// Class RemoteEpisodeProvider
/// </summary>
- class TvdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>
+ class TvdbEpisodeProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>, IHasOrder
{
- private static readonly string FullIdKey = MetadataProviders.Tvdb + "-Full";
-
- internal static TvdbEpisodeProvider Current;
- private readonly IFileSystem _fileSystem;
- private readonly IServerConfigurationManager _config;
private readonly IHttpClient _httpClient;
private readonly ILogger _logger;
- private readonly IXmlReaderSettingsFactory _xmlSettings;
+ private readonly TvDbClientManager _tvDbClientManager;
- public TvdbEpisodeProvider(IFileSystem fileSystem, IServerConfigurationManager config, IHttpClient httpClient, ILogger logger, IXmlReaderSettingsFactory xmlSettings)
+ public TvdbEpisodeProvider(IHttpClient httpClient, ILogger<TvdbEpisodeProvider> logger, TvDbClientManager tvDbClientManager)
{
- _fileSystem = fileSystem;
- _config = config;
_httpClient = httpClient;
_logger = logger;
- _xmlSettings = xmlSettings;
- Current = this;
+ _tvDbClientManager = tvDbClientManager;
}
- public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
+ public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
{
var list = new List<RemoteSearchResult>();
// The search query must either provide an episode number or date
- if (!searchInfo.IndexNumber.HasValue && !searchInfo.PremiereDate.HasValue)
+ if (!searchInfo.IndexNumber.HasValue || !searchInfo.PremiereDate.HasValue)
{
- return Task.FromResult((IEnumerable<RemoteSearchResult>)list);
+ return list;
}
if (TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds))
{
- var seriesDataPath = TvdbSeriesProvider.GetSeriesDataPath(_config.ApplicationPaths, searchInfo.SeriesProviderIds);
-
try
{
- var metadataResult = FetchEpisodeData(searchInfo, seriesDataPath, cancellationToken);
+ var episodeTvdbId = searchInfo.GetProviderId(MetadataProviders.Tvdb);
+ if (string.IsNullOrEmpty(episodeTvdbId))
+ {
+ searchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(),
+ out var seriesTvdbId);
+ episodeTvdbId = await _tvDbClientManager
+ .GetEpisodeTvdbId(searchInfo, searchInfo.MetadataLanguage, cancellationToken)
+ .ConfigureAwait(false);
+ if (string.IsNullOrEmpty(episodeTvdbId))
+ {
+ _logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
+ searchInfo.ParentIndexNumber, searchInfo.IndexNumber, seriesTvdbId);
+ return list;
+ }
+ }
+
+ var episodeResult = await _tvDbClientManager.GetEpisodesAsync(Convert.ToInt32(episodeTvdbId),
+ searchInfo.MetadataLanguage, cancellationToken).ConfigureAwait(false);
+ var metadataResult = MapEpisodeToResult(searchInfo, episodeResult.Data);
if (metadataResult.HasMetadata)
{
@@ -80,689 +82,118 @@ namespace MediaBrowser.Providers.TV.TheTVDB
});
}
}
- catch (FileNotFoundException)
- {
- // Don't fail the provider because this will just keep on going and going.
- }
- catch (IOException)
+ catch (TvDbServerException e)
{
- // Don't fail the provider because this will just keep on going and going.
+ _logger.LogError(e, "Failed to retrieve episode with id {TvDbId}", searchInfo.IndexNumber);
}
}
- return Task.FromResult((IEnumerable<RemoteSearchResult>)list);
+ return list;
}
public string Name => "TheTVDB";
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo searchInfo, CancellationToken cancellationToken)
{
- var result = new MetadataResult<Episode>();
- result.QueriedById = true;
+ var result = new MetadataResult<Episode>
+ {
+ QueriedById = true
+ };
if (TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds) &&
(searchInfo.IndexNumber.HasValue || searchInfo.PremiereDate.HasValue))
{
- var seriesDataPath = await TvdbSeriesProvider.Current.EnsureSeriesInfo(searchInfo.SeriesProviderIds, null, null, searchInfo.MetadataLanguage, cancellationToken).ConfigureAwait(false);
-
- if (string.IsNullOrEmpty(seriesDataPath))
- {
- return result;
- }
-
+ var tvdbId = searchInfo.GetProviderId(MetadataProviders.Tvdb);
try
{
- result = FetchEpisodeData(searchInfo, seriesDataPath, cancellationToken);
- }
- catch (FileNotFoundException)
- {
- // Don't fail the provider because this will just keep on going and going.
+ if (string.IsNullOrEmpty(tvdbId))
+ {
+ tvdbId = await _tvDbClientManager
+ .GetEpisodeTvdbId(searchInfo, searchInfo.MetadataLanguage, cancellationToken)
+ .ConfigureAwait(false);
+ if (string.IsNullOrEmpty(tvdbId))
+ {
+ _logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
+ searchInfo.ParentIndexNumber, searchInfo.IndexNumber, tvdbId);
+ return result;
+ }
+ }
+
+ var episodeResult = await _tvDbClientManager.GetEpisodesAsync(
+ Convert.ToInt32(tvdbId), searchInfo.MetadataLanguage,
+ cancellationToken).ConfigureAwait(false);
+
+ result = MapEpisodeToResult(searchInfo, episodeResult.Data);
}
- catch (IOException)
+ catch (TvDbServerException e)
{
- // Don't fail the provider because this will just keep on going and going.
+ _logger.LogError(e, "Failed to retrieve episode with id {TvDbId}", tvdbId);
}
}
else
{
- _logger.LogDebug("No series identity found for {0}", searchInfo.Name);
+ _logger.LogDebug("No series identity found for {EpisodeName}", searchInfo.Name);
}
return result;
}
- /// <summary>
- /// Gets the episode XML files.
- /// </summary>
- /// <param name="seriesDataPath">The series data path.</param>
- /// <param name="searchInfo">The search information.</param>
- /// <returns>List{FileInfo}.</returns>
- internal List<XmlReader> GetEpisodeXmlNodes(string seriesDataPath, EpisodeInfo searchInfo)
- {
- var seriesXmlPath = TvdbSeriesProvider.Current.GetSeriesXmlPath(searchInfo.SeriesProviderIds, searchInfo.MetadataLanguage);
-
- try
- {
- return GetXmlNodes(seriesXmlPath, searchInfo);
- }
- catch (FileNotFoundException)
- {
- return new List<XmlReader>();
- }
- catch (IOException)
- {
- return new List<XmlReader>();
- }
- }
-
- /// <summary>
- /// Fetches the episode data.
- /// </summary>
- /// <param name="id">The identifier.</param>
- /// <param name="seriesDataPath">The series data path.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task{System.Boolean}.</returns>
- private MetadataResult<Episode> FetchEpisodeData(EpisodeInfo id, string seriesDataPath, CancellationToken cancellationToken)
+ private static MetadataResult<Episode> MapEpisodeToResult(EpisodeInfo id, EpisodeRecord episode)
{
- var result = new MetadataResult<Episode>()
+ var result = new MetadataResult<Episode>
{
+ HasMetadata = true,
Item = new Episode
{
IndexNumber = id.IndexNumber,
ParentIndexNumber = id.ParentIndexNumber,
- IndexNumberEnd = id.IndexNumberEnd
- }
- };
-
- var xmlNodes = GetEpisodeXmlNodes(seriesDataPath, id);
-
- if (xmlNodes.Count > 0)
- {
- FetchMainEpisodeInfo(result, xmlNodes[0], id.SeriesDisplayOrder, cancellationToken);
-
- result.HasMetadata = true;
- }
-
- foreach (var node in xmlNodes.Skip(1))
- {
- FetchAdditionalPartInfo(result, node, cancellationToken);
- }
-
- return result;
- }
-
- private List<XmlReader> GetXmlNodes(string xmlFile, EpisodeInfo searchInfo)
- {
- var list = new List<XmlReader>();
-
- if (searchInfo.IndexNumber.HasValue)
- {
- var files = GetEpisodeXmlFiles(searchInfo.SeriesDisplayOrder, searchInfo.ParentIndexNumber, searchInfo.IndexNumber, searchInfo.IndexNumberEnd, Path.GetDirectoryName(xmlFile));
-
- list = files.Select(GetXmlReader).ToList();
- }
-
- if (list.Count == 0 && searchInfo.PremiereDate.HasValue)
- {
- list = GetXmlNodesByPremiereDate(xmlFile, searchInfo.PremiereDate.Value);
- }
-
- return list;
- }
-
- private string GetEpisodeFileName(string seriesDisplayOrder, int? seasonNumber, int? episodeNumber)
- {
- if (string.Equals(seriesDisplayOrder, "absolute", StringComparison.OrdinalIgnoreCase))
- {
- return string.Format("episode-abs-{0}.xml", episodeNumber);
- }
- else if (string.Equals(seriesDisplayOrder, "dvd", StringComparison.OrdinalIgnoreCase))
- {
- return string.Format("episode-dvd-{0}-{1}.xml", seasonNumber.Value, episodeNumber);
- }
- else
- {
- return string.Format("episode-{0}-{1}.xml", seasonNumber.Value, episodeNumber);
- }
- }
-
- private FileSystemMetadata GetEpisodeFileInfoWithFallback(string seriesDataPath, string seriesDisplayOrder, int? seasonNumber, int? episodeNumber)
- {
- var file = Path.Combine(seriesDataPath, GetEpisodeFileName(seriesDisplayOrder, seasonNumber, episodeNumber));
- var fileInfo = _fileSystem.GetFileInfo(file);
-
- if (fileInfo.Exists)
- {
- return fileInfo;
- }
-
- if (!seasonNumber.HasValue)
- {
- return fileInfo;
- }
-
- // revert to aired order
- if (string.Equals(seriesDisplayOrder, "absolute", StringComparison.OrdinalIgnoreCase) || string.Equals(seriesDisplayOrder, "dvd", StringComparison.OrdinalIgnoreCase))
- {
- file = Path.Combine(seriesDataPath, GetEpisodeFileName(null, seasonNumber, episodeNumber));
- return _fileSystem.GetFileInfo(file);
- }
-
- return fileInfo;
- }
-
- private List<FileSystemMetadata> GetEpisodeXmlFiles(string seriesDisplayOrder, int? seasonNumber, int? episodeNumber, int? endingEpisodeNumber, string seriesDataPath)
- {
- var files = new List<FileSystemMetadata>();
-
- if (episodeNumber == null)
- {
- return files;
- }
-
- if (!seasonNumber.HasValue)
- {
- seriesDisplayOrder = "absolute";
- }
-
- var fileInfo = GetEpisodeFileInfoWithFallback(seriesDataPath, seriesDisplayOrder, seasonNumber, episodeNumber);
-
- if (fileInfo.Exists)
- {
- files.Add(fileInfo);
- }
-
- var end = endingEpisodeNumber ?? episodeNumber;
- episodeNumber++;
-
- while (episodeNumber <= end)
- {
- fileInfo = GetEpisodeFileInfoWithFallback(seriesDataPath, seriesDisplayOrder, seasonNumber, episodeNumber);
-
- if (fileInfo.Exists)
- {
- files.Add(fileInfo);
- }
- else
- {
- break;
- }
-
- episodeNumber++;
- }
-
- return files;
- }
-
- private XmlReader GetXmlReader(FileSystemMetadata xmlFile)
- {
- return GetXmlReader(File.ReadAllText(xmlFile.FullName, Encoding.UTF8));
- }
-
- private XmlReader GetXmlReader(string xml)
- {
- var streamReader = new StringReader(xml);
-
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- return XmlReader.Create(streamReader, settings);
- }
-
- private List<XmlReader> GetXmlNodesByPremiereDate(string xmlFile, DateTime premiereDate)
- {
- var list = new List<XmlReader>();
-
- using (var fileStream = _fileSystem.GetFileStream(xmlFile, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read))
- {
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
- {
- // Use XmlReader for best performance
-
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Episode":
- {
- var outerXml = reader.ReadOuterXml();
-
- var airDate = GetEpisodeAirDate(outerXml);
+ IndexNumberEnd = id.IndexNumberEnd,
+ AirsBeforeEpisodeNumber = episode.AirsBeforeEpisode,
+ AirsAfterSeasonNumber = episode.AirsAfterSeason,
+ AirsBeforeSeasonNumber = episode.AirsBeforeSeason,
+ Name = episode.EpisodeName,
+ Overview = episode.Overview,
+ CommunityRating = (float?)episode.SiteRating,
- if (airDate.HasValue && premiereDate.Date == airDate.Value.Date)
- {
- list.Add(GetXmlReader(outerXml));
- return list;
- }
-
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
}
- }
-
- return list;
- }
-
- private DateTime? GetEpisodeAirDate(string xml)
- {
- using (var streamReader = new StringReader(xml))
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "FirstAired":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (DateTime.TryParse(val, out var date))
- {
- date = date.ToUniversalTime();
-
- return date;
- }
- }
-
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
- }
- return null;
- }
-
- private readonly CultureInfo _usCulture = new CultureInfo("en-US");
+ };
+ result.ResetPeople();
- private void FetchMainEpisodeInfo(MetadataResult<Episode> result, XmlReader reader, string seriesOrder, CancellationToken cancellationToken)
- {
var item = result.Item;
+ item.SetProviderId(MetadataProviders.Tvdb, episode.Id.ToString());
+ item.SetProviderId(MetadataProviders.Imdb, episode.ImdbId);
- int? episodeNumber = null;
- int? seasonNumber = null;
- int? combinedEpisodeNumber = null;
- int? combinedSeasonNumber = null;
-
- // Use XmlReader for best performance
- using (reader)
+ if (string.Equals(id.SeriesDisplayOrder, "dvd", StringComparison.OrdinalIgnoreCase))
{
- result.ResetPeople();
-
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "id":
- {
- var val = reader.ReadElementContentAsString();
- if (!string.IsNullOrWhiteSpace(val))
- {
- item.SetProviderId(MetadataProviders.Tvdb, val);
- }
- break;
- }
-
- case "IMDB_ID":
- {
- var val = reader.ReadElementContentAsString();
- if (!string.IsNullOrWhiteSpace(val))
- {
- item.SetProviderId(MetadataProviders.Imdb, val);
- }
- break;
- }
-
- case "EpisodeNumber":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- episodeNumber = rval;
- }
- }
-
- break;
- }
-
- case "SeasonNumber":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- seasonNumber = rval;
- }
- }
-
- break;
- }
-
- case "Combined_episodenumber":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (float.TryParse(val, NumberStyles.Any, _usCulture, out var num))
- {
- combinedEpisodeNumber = Convert.ToInt32(num);
- }
- }
-
- break;
- }
-
- case "Combined_season":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (float.TryParse(val, NumberStyles.Any, _usCulture, out var num))
- {
- combinedSeasonNumber = Convert.ToInt32(num);
- }
- }
-
- break;
- }
-
- case "airsbefore_episode":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- item.AirsBeforeEpisodeNumber = rval;
- }
- }
-
- break;
- }
-
- case "airsafter_season":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- item.AirsAfterSeasonNumber = rval;
- }
- }
-
- break;
- }
-
- case "airsbefore_season":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- item.AirsBeforeSeasonNumber = rval;
- }
- }
-
- break;
- }
-
- case "EpisodeName":
- {
- var val = reader.ReadElementContentAsString();
- if (!item.LockedFields.Contains(MetadataFields.Name))
- {
- if (!string.IsNullOrWhiteSpace(val))
- {
- item.Name = val;
- }
- }
- break;
- }
-
- case "Overview":
- {
- var val = reader.ReadElementContentAsString();
- if (!item.LockedFields.Contains(MetadataFields.Overview))
- {
- if (!string.IsNullOrWhiteSpace(val))
- {
- item.Overview = val;
- }
- }
- break;
- }
- case "Rating":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // float.TryParse is local aware, so it can be probamatic, force us culture
- if (float.TryParse(val, NumberStyles.AllowDecimalPoint, _usCulture, out var rval))
- {
- item.CommunityRating = rval;
- }
- }
- break;
- }
- case "RatingCount":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- //item.VoteCount = rval;
- }
- }
-
- break;
- }
-
- case "FirstAired":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (DateTime.TryParse(val, out var date))
- {
- date = date.ToUniversalTime();
-
- item.PremiereDate = date;
- item.ProductionYear = date.Year;
- }
- }
-
- break;
- }
-
- case "Director":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (!item.LockedFields.Contains(MetadataFields.Cast))
- {
- AddPeople(result, val, PersonType.Director);
- }
- }
-
- break;
- }
- case "GuestStars":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (!item.LockedFields.Contains(MetadataFields.Cast))
- {
- AddGuestStars(result, val);
- }
- }
-
- break;
- }
- case "Writer":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (!item.LockedFields.Contains(MetadataFields.Cast))
- {
- //AddPeople(result, val, PersonType.Writer);
- }
- }
-
- break;
- }
- case "Language":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- result.ResultLanguage = val;
- }
-
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
+ item.IndexNumber = Convert.ToInt32(episode.DvdEpisodeNumber ?? episode.AiredEpisodeNumber);
+ item.ParentIndexNumber = episode.DvdSeason ?? episode.AiredSeason;
}
-
- if (string.Equals(seriesOrder, "dvd", StringComparison.OrdinalIgnoreCase))
+ else if (episode.AiredEpisodeNumber.HasValue)
{
- episodeNumber = combinedEpisodeNumber ?? episodeNumber;
- seasonNumber = combinedSeasonNumber ?? seasonNumber;
+ item.IndexNumber = episode.AiredEpisodeNumber;
}
-
- if (episodeNumber.HasValue)
+ else if (episode.AiredSeason.HasValue)
{
- item.IndexNumber = episodeNumber;
+ item.ParentIndexNumber = episode.AiredSeason;
}
- if (seasonNumber.HasValue)
+ if (DateTime.TryParse(episode.FirstAired, out var date))
{
- item.ParentIndexNumber = seasonNumber;
+ // dates from tvdb are UTC but without offset or Z
+ item.PremiereDate = date;
+ item.ProductionYear = date.Year;
}
- }
- private void AddPeople<T>(MetadataResult<T> result, string val, string personType)
- {
- // Sometimes tvdb actors have leading spaces
- foreach (var person in val.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
- .Where(i => !string.IsNullOrWhiteSpace(i))
- .Select(str => new PersonInfo { Type = personType, Name = str.Trim() }))
+ foreach (var director in episode.Directors)
{
- result.AddPerson(person);
+ result.AddPerson(new PersonInfo
+ {
+ Name = director,
+ Type = PersonType.Director
+ });
}
- }
-
- private void AddGuestStars<T>(MetadataResult<T> result, string val)
- where T : BaseItem
- {
- // example:
- // <GuestStars>|Mark C. Thomas| Dennis Kiefer| David Nelson (David)| Angela Nicholas| Tzi Ma| Kevin P. Kearns (Pasco)|</GuestStars>
- var persons = val.Split('|')
- .Select(i => i.Trim())
- .Where(i => !string.IsNullOrWhiteSpace(i))
- .ToList();
- foreach (var person in persons)
+ foreach (var person in episode.GuestStars)
{
var index = person.IndexOf('(');
string role = null;
@@ -782,106 +213,18 @@ namespace MediaBrowser.Providers.TV.TheTVDB
Role = role
});
}
- }
- private void FetchAdditionalPartInfo(MetadataResult<Episode> result, XmlReader reader, CancellationToken cancellationToken)
- {
- var item = result.Item;
-
- // Use XmlReader for best performance
- using (reader)
+ foreach (var writer in episode.Writers)
{
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
+ result.AddPerson(new PersonInfo
{
- cancellationToken.ThrowIfCancellationRequested();
-
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "EpisodeName":
- {
- var val = reader.ReadElementContentAsString();
- if (!item.LockedFields.Contains(MetadataFields.Name))
- {
- if (!string.IsNullOrWhiteSpace(val))
- {
- item.Name += ", " + val;
- }
- }
- break;
- }
-
- case "Overview":
- {
- var val = reader.ReadElementContentAsString();
- if (!item.LockedFields.Contains(MetadataFields.Overview))
- {
- if (!string.IsNullOrWhiteSpace(val))
- {
- item.Overview += Environment.NewLine + Environment.NewLine + val;
- }
- }
- break;
- }
- case "Director":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (!item.LockedFields.Contains(MetadataFields.Cast))
- {
- AddPeople(result, val, PersonType.Director);
- }
- }
-
- break;
- }
- case "GuestStars":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (!item.LockedFields.Contains(MetadataFields.Cast))
- {
- AddGuestStars(result, val);
- }
- }
-
- break;
- }
- case "Writer":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (!item.LockedFields.Contains(MetadataFields.Cast))
- {
- //AddPeople(result, val, PersonType.Writer);
- }
- }
-
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
+ Name = writer,
+ Type = PersonType.Writer
+ });
}
+
+ result.ResultLanguage = episode.Language.EpisodeName;
+ return result;
}
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs
deleted file mode 100644
index d45696057..000000000
--- a/MediaBrowser.Providers/TV/TheTVDB/TvdbPrescanTask.cs
+++ /dev/null
@@ -1,398 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Xml;
-using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Dto;
-using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Entities.TV;
-using MediaBrowser.Controller.Library;
-using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Net;
-using MediaBrowser.Model.Xml;
-using Microsoft.Extensions.Logging;
-
-namespace MediaBrowser.Providers.TV.TheTVDB
-{
- /// <summary>
- /// Class TvdbPrescanTask
- /// </summary>
- public class TvdbPrescanTask : ILibraryPostScanTask
- {
- public const string TvdbBaseUrl = "https://thetvdb.com/";
-
- /// <summary>
- /// The server time URL
- /// </summary>
- private const string ServerTimeUrl = TvdbBaseUrl + "api/Updates.php?type=none";
-
- /// <summary>
- /// The updates URL
- /// </summary>
- private const string UpdatesUrl = TvdbBaseUrl + "api/Updates.php?type=all&time={0}";
-
- /// <summary>
- /// The _HTTP client
- /// </summary>
- private readonly IHttpClient _httpClient;
- /// <summary>
- /// The _logger
- /// </summary>
- private readonly ILogger _logger;
- /// <summary>
- /// The _config
- /// </summary>
- private readonly IServerConfigurationManager _config;
- private readonly IFileSystem _fileSystem;
- private readonly ILibraryManager _libraryManager;
- private readonly IXmlReaderSettingsFactory _xmlSettings;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="TvdbPrescanTask"/> class.
- /// </summary>
- /// <param name="logger">The logger.</param>
- /// <param name="httpClient">The HTTP client.</param>
- /// <param name="config">The config.</param>
- public TvdbPrescanTask(ILogger logger, IHttpClient httpClient, IServerConfigurationManager config, IFileSystem fileSystem, ILibraryManager libraryManager, IXmlReaderSettingsFactory xmlSettings)
- {
- _logger = logger;
- _httpClient = httpClient;
- _config = config;
- _fileSystem = fileSystem;
- _libraryManager = libraryManager;
- _xmlSettings = xmlSettings;
- }
-
- protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
-
- /// <summary>
- /// Runs the specified progress.
- /// </summary>
- /// <param name="progress">The progress.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task.</returns>
- public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
- {
- var path = TvdbSeriesProvider.GetSeriesDataPath(_config.CommonApplicationPaths);
-
- Directory.CreateDirectory(path);
-
- var timestampFile = Path.Combine(path, "time.txt");
-
- var timestampFileInfo = _fileSystem.GetFileInfo(timestampFile);
-
- // Don't check for tvdb updates anymore frequently than 24 hours
- if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 1)
- {
- return;
- }
-
- // Find out the last time we queried tvdb for updates
- var lastUpdateTime = timestampFileInfo.Exists ? File.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;
-
- string newUpdateTime;
-
- var existingDirectories = _fileSystem.GetDirectoryPaths(path)
- .Select(Path.GetFileName)
- .ToList();
-
- var seriesList = _libraryManager.GetItemList(new InternalItemsQuery()
- {
- IncludeItemTypes = new[] { typeof(Series).Name },
- Recursive = true,
- GroupByPresentationUniqueKey = false,
- DtoOptions = new DtoOptions(false)
- {
- EnableImages = false
- }
-
- }).Cast<Series>()
- .ToList();
-
- var seriesIdsInLibrary = seriesList
- .Where(i => !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb)))
- .Select(i => i.GetProviderId(MetadataProviders.Tvdb))
- .ToList();
-
- var missingSeries = seriesIdsInLibrary.Except(existingDirectories, StringComparer.OrdinalIgnoreCase)
- .ToList();
-
- var enableInternetProviders = seriesList.Count == 0 ? false : seriesList[0].IsMetadataFetcherEnabled(_libraryManager.GetLibraryOptions(seriesList[0]), TvdbSeriesProvider.Current.Name);
- if (!enableInternetProviders)
- {
- progress.Report(100);
- return;
- }
-
- // If this is our first time, update all series
- if (string.IsNullOrEmpty(lastUpdateTime))
- {
- // First get tvdb server time
- using (var response = await _httpClient.SendAsync(new HttpRequestOptions
- {
- Url = ServerTimeUrl,
- CancellationToken = cancellationToken,
- EnableHttpCompression = true,
- BufferContent = false
-
- }, "GET").ConfigureAwait(false))
- {
- // First get tvdb server time
- using (var stream = response.Content)
- {
- newUpdateTime = GetUpdateTime(stream);
- }
- }
-
- existingDirectories.AddRange(missingSeries);
-
- await UpdateSeries(existingDirectories, path, null, progress, cancellationToken).ConfigureAwait(false);
- }
- else
- {
- var seriesToUpdate = await GetSeriesIdsToUpdate(existingDirectories, lastUpdateTime, cancellationToken).ConfigureAwait(false);
-
- newUpdateTime = seriesToUpdate.Item2;
-
- long.TryParse(lastUpdateTime, NumberStyles.Any, UsCulture, out var lastUpdateValue);
-
- var nullableUpdateValue = lastUpdateValue == 0 ? (long?)null : lastUpdateValue;
-
- var listToUpdate = seriesToUpdate.Item1.ToList();
- listToUpdate.AddRange(missingSeries);
-
- await UpdateSeries(listToUpdate, path, nullableUpdateValue, progress, cancellationToken).ConfigureAwait(false);
- }
-
- File.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8);
- progress.Report(100);
- }
-
- /// <summary>
- /// Gets the update time.
- /// </summary>
- /// <param name="response">The response.</param>
- /// <returns>System.String.</returns>
- private string GetUpdateTime(Stream response)
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- using (var streamReader = new StreamReader(response, Encoding.UTF8))
- {
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Time":
- {
- return (reader.ReadElementContentAsString() ?? string.Empty).Trim();
- }
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
- }
-
- return null;
- }
-
- /// <summary>
- /// Gets the series ids to update.
- /// </summary>
- /// <param name="existingSeriesIds">The existing series ids.</param>
- /// <param name="lastUpdateTime">The last update time.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task{IEnumerable{System.String}}.</returns>
- private async Task<Tuple<IEnumerable<string>, string>> GetSeriesIdsToUpdate(IEnumerable<string> existingSeriesIds, string lastUpdateTime, CancellationToken cancellationToken)
- {
- // First get last time
- using (var response = await _httpClient.SendAsync(new HttpRequestOptions
- {
- Url = string.Format(UpdatesUrl, lastUpdateTime),
- CancellationToken = cancellationToken,
- EnableHttpCompression = true,
- BufferContent = false
-
- }, "GET").ConfigureAwait(false))
- {
- using (var stream = response.Content)
- {
- var data = GetUpdatedSeriesIdList(stream);
-
- var existingDictionary = existingSeriesIds.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
-
- var seriesList = data.Item1
- .Where(i => !string.IsNullOrWhiteSpace(i) && existingDictionary.ContainsKey(i));
-
- return new Tuple<IEnumerable<string>, string>(seriesList, data.Item2);
- }
- }
- }
-
- private Tuple<List<string>, string> GetUpdatedSeriesIdList(Stream stream)
- {
- string updateTime = null;
- var idList = new List<string>();
-
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- using (var streamReader = new StreamReader(stream, Encoding.UTF8))
- {
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Time":
- {
- updateTime = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
- break;
- }
- case "Series":
- {
- var id = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
- idList.Add(id);
- break;
- }
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
- }
-
- return new Tuple<List<string>, string>(idList, updateTime);
- }
-
- /// <summary>
- /// Updates the series.
- /// </summary>
- /// <param name="seriesIds">The series ids.</param>
- /// <param name="seriesDataPath">The series data path.</param>
- /// <param name="lastTvDbUpdateTime">The last tv db update time.</param>
- /// <param name="progress">The progress.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task.</returns>
- private async Task UpdateSeries(List<string> seriesIds, string seriesDataPath, long? lastTvDbUpdateTime, IProgress<double> progress, CancellationToken cancellationToken)
- {
- var numComplete = 0;
-
- var seriesList = _libraryManager.GetItemList(new InternalItemsQuery()
- {
- IncludeItemTypes = new[] { typeof(Series).Name },
- Recursive = true,
- GroupByPresentationUniqueKey = false,
- DtoOptions = new DtoOptions(false)
- {
- EnableImages = false
- }
-
- }).Cast<Series>();
-
- // Gather all series into a lookup by tvdb id
- var allSeries = seriesList
- .Where(i => !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb)))
- .ToLookup(i => i.GetProviderId(MetadataProviders.Tvdb));
-
- foreach (var seriesId in seriesIds)
- {
- // Find the preferred language(s) for the movie in the library
- var languages = allSeries[seriesId]
- .Select(i => i.GetPreferredMetadataLanguage())
- .Distinct(StringComparer.OrdinalIgnoreCase)
- .ToList();
-
- foreach (var language in languages)
- {
- try
- {
- await UpdateSeries(seriesId, seriesDataPath, lastTvDbUpdateTime, language, cancellationToken).ConfigureAwait(false);
- }
- catch (HttpException ex)
- {
- _logger.LogError(ex, "Error updating tvdb series id {ID}, language {Language}", seriesId, language);
-
- // Already logged at lower levels, but don't fail the whole operation, unless timed out
- // We have to fail this to make it run again otherwise new episode data could potentially be missing
- if (ex.IsTimedOut)
- {
- throw;
- }
- }
- }
-
- numComplete++;
- double percent = numComplete;
- percent /= seriesIds.Count;
- percent *= 100;
-
- progress.Report(percent);
- }
- }
-
- /// <summary>
- /// Updates the series.
- /// </summary>
- /// <param name="id">The id.</param>
- /// <param name="seriesDataPath">The series data path.</param>
- /// <param name="lastTvDbUpdateTime">The last tv db update time.</param>
- /// <param name="preferredMetadataLanguage">The preferred metadata language.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task.</returns>
- private Task UpdateSeries(string id, string seriesDataPath, long? lastTvDbUpdateTime, string preferredMetadataLanguage, CancellationToken cancellationToken)
- {
- _logger.LogInformation("Updating series from tvdb " + id + ", language " + preferredMetadataLanguage);
-
- seriesDataPath = Path.Combine(seriesDataPath, id);
-
- Directory.CreateDirectory(seriesDataPath);
-
- return TvdbSeriesProvider.Current.DownloadSeriesZip(id, MetadataProviders.Tvdb.ToString(), null, null, seriesDataPath, lastTvDbUpdateTime, preferredMetadataLanguage, cancellationToken);
- }
- }
-}
diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs
index 01ede44bb..94ca603f2 100644
--- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs
+++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs
@@ -1,41 +1,32 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
using System.Linq;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using System.Xml;
using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
-using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
-using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
-using MediaBrowser.Model.Xml;
+using Microsoft.Extensions.Logging;
+using TvDbSharper;
+using TvDbSharper.Dto;
+using RatingType = MediaBrowser.Model.Dto.RatingType;
namespace MediaBrowser.Providers.TV.TheTVDB
{
public class TvdbSeasonImageProvider : IRemoteImageProvider, IHasOrder
{
- private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
-
- private readonly IServerConfigurationManager _config;
private readonly IHttpClient _httpClient;
- private readonly IFileSystem _fileSystem;
- private readonly IXmlReaderSettingsFactory _xmlSettings;
+ private readonly ILogger _logger;
+ private readonly TvDbClientManager _tvDbClientManager;
- public TvdbSeasonImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlSettings)
+ public TvdbSeasonImageProvider(IHttpClient httpClient, ILogger<TvdbSeasonImageProvider> logger, TvDbClientManager tvDbClientManager)
{
- _config = config;
_httpClient = httpClient;
- _fileSystem = fileSystem;
- _xmlSettings = xmlSettings;
+ _logger = logger;
+ _tvDbClientManager = tvDbClientManager;
}
public string Name => ProviderName;
@@ -62,91 +53,66 @@ namespace MediaBrowser.Providers.TV.TheTVDB
var season = (Season)item;
var series = season.Series;
- if (series != null && season.IndexNumber.HasValue && TvdbSeriesProvider.IsValidSeries(series.ProviderIds))
+ if (series == null || !season.IndexNumber.HasValue || !TvdbSeriesProvider.IsValidSeries(series.ProviderIds))
{
- var seriesProviderIds = series.ProviderIds;
- var seasonNumber = season.IndexNumber.Value;
+ return new RemoteImageInfo[] { };
+ }
- var seriesDataPath = await TvdbSeriesProvider.Current.EnsureSeriesInfo(seriesProviderIds, series.Name, series.ProductionYear, series.GetPreferredMetadataLanguage(), cancellationToken).ConfigureAwait(false);
+ var tvdbId = Convert.ToInt32(series.GetProviderId(MetadataProviders.Tvdb));
+ var seasonNumber = season.IndexNumber.Value;
+ var language = item.GetPreferredMetadataLanguage();
+ var remoteImages = new List<RemoteImageInfo>();
- if (!string.IsNullOrEmpty(seriesDataPath))
+ var keyTypes = new[] { KeyType.Season, KeyType.Seasonwide, KeyType.Fanart };
+ foreach (var keyType in keyTypes)
+ {
+ var imageQuery = new ImagesQuery
{
- var path = Path.Combine(seriesDataPath, "banners.xml");
-
- try
- {
- return GetImages(path, item.GetPreferredMetadataLanguage(), seasonNumber, _xmlSettings, _fileSystem, cancellationToken);
- }
- catch (FileNotFoundException)
- {
- // No tvdb data yet. Don't blow up
- }
- catch (IOException)
- {
- // No tvdb data yet. Don't blow up
- }
+ KeyType = keyType,
+ SubKey = seasonNumber.ToString()
+ };
+ try
+ {
+ var imageResults = await _tvDbClientManager
+ .GetImagesAsync(tvdbId, imageQuery, language, cancellationToken).ConfigureAwait(false);
+ remoteImages.AddRange(GetImages(imageResults.Data, language));
+ }
+ catch (TvDbServerException)
+ {
+ _logger.LogDebug("No images of type {KeyType} found for series {TvdbId}", keyType, tvdbId);
}
}
- return new RemoteImageInfo[] { };
+ return remoteImages;
}
- internal static IEnumerable<RemoteImageInfo> GetImages(string xmlPath, string preferredLanguage, int seasonNumber, IXmlReaderSettingsFactory xmlReaderSettingsFactory, IFileSystem fileSystem, CancellationToken cancellationToken)
+ private IEnumerable<RemoteImageInfo> GetImages(Image[] images, string preferredLanguage)
{
- var settings = xmlReaderSettingsFactory.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
var list = new List<RemoteImageInfo>();
-
- using (var fileStream = fileSystem.GetFileStream(xmlPath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read))
+ var languages = _tvDbClientManager.GetLanguagesAsync(CancellationToken.None).Result.Data;
+ foreach (Image image in images)
{
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
+ var imageInfo = new RemoteImageInfo
{
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
+ RatingType = RatingType.Score,
+ CommunityRating = (double?)image.RatingsInfo.Average,
+ VoteCount = image.RatingsInfo.Count,
+ Url = TvdbUtils.BannerUrl + image.FileName,
+ ProviderName = ProviderName,
+ Language = languages.FirstOrDefault(lang => lang.Id == image.LanguageId)?.Abbreviation,
+ ThumbnailUrl = TvdbUtils.BannerUrl + image.Thumbnail
+ };
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Banner":
- {
- if (reader.IsEmptyElement)
- {
- reader.Read();
- continue;
- }
- using (var subtree = reader.ReadSubtree())
- {
- AddImage(subtree, list, seasonNumber);
- }
- break;
- }
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
+ var resolution = image.Resolution.Split('x');
+ if (resolution.Length == 2)
+ {
+ imageInfo.Width = Convert.ToInt32(resolution[0]);
+ imageInfo.Height = Convert.ToInt32(resolution[1]);
}
- }
+ imageInfo.Type = TvdbUtils.GetImageTypeFromKeyType(image.KeyType);
+ list.Add(imageInfo);
+ }
var isLanguageEn = string.Equals(preferredLanguage, "en", StringComparison.OrdinalIgnoreCase);
return list.OrderByDescending(i =>
@@ -155,6 +121,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
{
return 3;
}
+
if (!isLanguageEn)
{
if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase))
@@ -162,177 +129,18 @@ namespace MediaBrowser.Providers.TV.TheTVDB
return 2;
}
}
+
if (string.IsNullOrEmpty(i.Language))
{
return isLanguageEn ? 3 : 2;
}
+
return 0;
})
.ThenByDescending(i => i.CommunityRating ?? 0)
.ThenByDescending(i => i.VoteCount ?? 0);
}
- private static void AddImage(XmlReader reader, List<RemoteImageInfo> images, int seasonNumber)
- {
- reader.MoveToContent();
-
- string bannerType = null;
- string bannerType2 = null;
- string url = null;
- int? bannerSeason = null;
- int? width = null;
- int? height = null;
- string language = null;
- double? rating = null;
- int? voteCount = null;
- string thumbnailUrl = null;
-
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Rating":
- {
- var val = reader.ReadElementContentAsString() ?? string.Empty;
-
- if (double.TryParse(val, NumberStyles.Any, UsCulture, out var rval))
- {
- rating = rval;
- }
-
- break;
- }
-
- case "RatingCount":
- {
- var val = reader.ReadElementContentAsString() ?? string.Empty;
-
- if (int.TryParse(val, NumberStyles.Integer, UsCulture, out var rval))
- {
- voteCount = rval;
- }
-
- break;
- }
-
- case "Language":
- {
- language = reader.ReadElementContentAsString() ?? string.Empty;
- break;
- }
-
- case "ThumbnailPath":
- {
- thumbnailUrl = reader.ReadElementContentAsString() ?? string.Empty;
- break;
- }
-
- case "BannerType":
- {
- bannerType = reader.ReadElementContentAsString() ?? string.Empty;
- break;
- }
-
- case "BannerType2":
- {
- bannerType2 = reader.ReadElementContentAsString() ?? string.Empty;
-
- // Sometimes the resolution is stuffed in here
- var resolutionParts = bannerType2.Split('x');
-
- if (resolutionParts.Length == 2)
- {
- if (int.TryParse(resolutionParts[0], NumberStyles.Integer, UsCulture, out var rval))
- {
- width = rval;
- }
-
- if (int.TryParse(resolutionParts[1], NumberStyles.Integer, UsCulture, out rval))
- {
- height = rval;
- }
-
- }
-
- break;
- }
-
- case "BannerPath":
- {
- url = reader.ReadElementContentAsString() ?? string.Empty;
- break;
- }
-
- case "Season":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- bannerSeason = int.Parse(val);
- }
- break;
- }
-
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
-
- if (!string.IsNullOrEmpty(url) && bannerSeason.HasValue && bannerSeason.Value == seasonNumber)
- {
- var imageInfo = new RemoteImageInfo
- {
- RatingType = RatingType.Score,
- CommunityRating = rating,
- VoteCount = voteCount,
- Url = TVUtils.BannerUrl + url,
- ProviderName = ProviderName,
- Language = language,
- Width = width,
- Height = height
- };
-
- if (!string.IsNullOrEmpty(thumbnailUrl))
- {
- imageInfo.ThumbnailUrl = TVUtils.BannerUrl + thumbnailUrl;
- }
-
- if (string.Equals(bannerType, "season", StringComparison.OrdinalIgnoreCase))
- {
- if (string.Equals(bannerType2, "season", StringComparison.OrdinalIgnoreCase))
- {
- imageInfo.Type = ImageType.Primary;
- images.Add(imageInfo);
- }
- else if (string.Equals(bannerType2, "seasonwide", StringComparison.OrdinalIgnoreCase))
- {
- imageInfo.Type = ImageType.Banner;
- images.Add(imageInfo);
- }
- }
- else if (string.Equals(bannerType, "fanart", StringComparison.OrdinalIgnoreCase))
- {
- imageInfo.Type = ImageType.Backdrop;
- images.Add(imageInfo);
- }
- }
-
- }
-
public int Order => 0;
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs
index 2b4337ed1..365f49fb7 100644
--- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs
+++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesImageProvider.cs
@@ -1,40 +1,32 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
using System.Linq;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using System.Xml;
using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Entities.TV;
-using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
-using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
-using MediaBrowser.Model.Xml;
+using Microsoft.Extensions.Logging;
+using TvDbSharper;
+using TvDbSharper.Dto;
+using RatingType = MediaBrowser.Model.Dto.RatingType;
+using Series = MediaBrowser.Controller.Entities.TV.Series;
namespace MediaBrowser.Providers.TV.TheTVDB
{
public class TvdbSeriesImageProvider : IRemoteImageProvider, IHasOrder
{
- private readonly IServerConfigurationManager _config;
private readonly IHttpClient _httpClient;
- private readonly CultureInfo _usCulture = new CultureInfo("en-US");
- private readonly IFileSystem _fileSystem;
- private readonly IXmlReaderSettingsFactory _xmlReaderSettingsFactory;
+ private readonly ILogger _logger;
+ private readonly TvDbClientManager _tvDbClientManager;
- public TvdbSeriesImageProvider(IServerConfigurationManager config, IHttpClient httpClient, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public TvdbSeriesImageProvider(IHttpClient httpClient, ILogger<TvdbSeriesImageProvider> logger, TvDbClientManager tvDbClientManager)
{
- _config = config;
_httpClient = httpClient;
- _fileSystem = fileSystem;
- _xmlReaderSettingsFactory = xmlReaderSettingsFactory;
+ _logger = logger;
+ _tvDbClientManager = tvDbClientManager;
}
public string Name => ProviderName;
@@ -58,273 +50,92 @@ namespace MediaBrowser.Providers.TV.TheTVDB
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
- if (TvdbSeriesProvider.IsValidSeries(item.ProviderIds))
+ if (!TvdbSeriesProvider.IsValidSeries(item.ProviderIds))
{
- var language = item.GetPreferredMetadataLanguage();
-
- var seriesDataPath = await TvdbSeriesProvider.Current.EnsureSeriesInfo(item.ProviderIds, item.Name, item.ProductionYear, language, cancellationToken).ConfigureAwait(false);
+ return Array.Empty<RemoteImageInfo>();
+ }
- if (string.IsNullOrEmpty(seriesDataPath))
+ var language = item.GetPreferredMetadataLanguage();
+ var remoteImages = new List<RemoteImageInfo>();
+ var keyTypes = new[] { KeyType.Poster, KeyType.Series, KeyType.Fanart };
+ var tvdbId = Convert.ToInt32(item.GetProviderId(MetadataProviders.Tvdb));
+ foreach (KeyType keyType in keyTypes)
+ {
+ var imageQuery = new ImagesQuery
{
- return new RemoteImageInfo[] { };
- }
-
- var path = Path.Combine(seriesDataPath, "banners.xml");
-
+ KeyType = keyType
+ };
try
{
- return GetImages(path, language, cancellationToken);
- }
- catch (FileNotFoundException)
- {
- // No tvdb data yet. Don't blow up
+ var imageResults =
+ await _tvDbClientManager.GetImagesAsync(tvdbId, imageQuery, language, cancellationToken)
+ .ConfigureAwait(false);
+
+ remoteImages.AddRange(GetImages(imageResults.Data, language));
}
- catch (IOException)
+ catch (TvDbServerException)
{
- // No tvdb data yet. Don't blow up
+ _logger.LogDebug("No images of type {KeyType} exist for series {TvDbId}", keyType,
+ tvdbId);
}
}
-
- return new RemoteImageInfo[] { };
+ return remoteImages;
}
- private IEnumerable<RemoteImageInfo> GetImages(string xmlPath, string preferredLanguage, CancellationToken cancellationToken)
+ private IEnumerable<RemoteImageInfo> GetImages(Image[] images, string preferredLanguage)
{
- var settings = _xmlReaderSettingsFactory.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
var list = new List<RemoteImageInfo>();
+ var languages = _tvDbClientManager.GetLanguagesAsync(CancellationToken.None).Result.Data;
- using (var fileStream = _fileSystem.GetFileStream(xmlPath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read))
+ foreach (Image image in images)
{
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
+ var imageInfo = new RemoteImageInfo
{
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
+ RatingType = RatingType.Score,
+ CommunityRating = (double?)image.RatingsInfo.Average,
+ VoteCount = image.RatingsInfo.Count,
+ Url = TvdbUtils.BannerUrl + image.FileName,
+ ProviderName = Name,
+ Language = languages.FirstOrDefault(lang => lang.Id == image.LanguageId)?.Abbreviation,
+ ThumbnailUrl = TvdbUtils.BannerUrl + image.Thumbnail
+ };
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Banner":
- {
- if (reader.IsEmptyElement)
- {
- reader.Read();
- continue;
- }
- using (var subtree = reader.ReadSubtree())
- {
- AddImage(subtree, list);
- }
- break;
- }
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
+ var resolution = image.Resolution.Split('x');
+ if (resolution.Length == 2)
+ {
+ imageInfo.Width = Convert.ToInt32(resolution[0]);
+ imageInfo.Height = Convert.ToInt32(resolution[1]);
}
- }
+ imageInfo.Type = TvdbUtils.GetImageTypeFromKeyType(image.KeyType);
+ list.Add(imageInfo);
+ }
var isLanguageEn = string.Equals(preferredLanguage, "en", StringComparison.OrdinalIgnoreCase);
return list.OrderByDescending(i =>
- {
- if (string.Equals(preferredLanguage, i.Language, StringComparison.OrdinalIgnoreCase))
- {
- return 3;
- }
- if (!isLanguageEn)
{
- if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase))
+ if (string.Equals(preferredLanguage, i.Language, StringComparison.OrdinalIgnoreCase))
{
- return 2;
+ return 3;
}
- }
- if (string.IsNullOrEmpty(i.Language))
- {
- return isLanguageEn ? 3 : 2;
- }
- return 0;
- })
- .ThenByDescending(i => i.CommunityRating ?? 0)
- .ThenByDescending(i => i.VoteCount ?? 0);
- }
-
- private void AddImage(XmlReader reader, List<RemoteImageInfo> images)
- {
- reader.MoveToContent();
- string bannerType = null;
- string url = null;
- int? bannerSeason = null;
- int? width = null;
- int? height = null;
- string language = null;
- double? rating = null;
- int? voteCount = null;
- string thumbnailUrl = null;
-
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
+ if (!isLanguageEn)
{
- case "Rating":
- {
- var val = reader.ReadElementContentAsString() ?? string.Empty;
-
- if (double.TryParse(val, NumberStyles.Any, _usCulture, out var rval))
- {
- rating = rval;
- }
-
- break;
- }
-
- case "RatingCount":
- {
- var val = reader.ReadElementContentAsString() ?? string.Empty;
-
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- voteCount = rval;
- }
-
- break;
- }
-
- case "Language":
- {
- language = reader.ReadElementContentAsString() ?? string.Empty;
- break;
- }
-
- case "ThumbnailPath":
- {
- thumbnailUrl = reader.ReadElementContentAsString() ?? string.Empty;
- break;
- }
-
- case "BannerType":
- {
- bannerType = reader.ReadElementContentAsString() ?? string.Empty;
-
- break;
- }
-
- case "BannerPath":
- {
- url = reader.ReadElementContentAsString() ?? string.Empty;
- break;
- }
-
- case "BannerType2":
- {
- var bannerType2 = reader.ReadElementContentAsString() ?? string.Empty;
-
- // Sometimes the resolution is stuffed in here
- var resolutionParts = bannerType2.Split('x');
-
- if (resolutionParts.Length == 2)
- {
- if (int.TryParse(resolutionParts[0], NumberStyles.Integer, _usCulture, out var rval))
- {
- width = rval;
- }
-
- if (int.TryParse(resolutionParts[1], NumberStyles.Integer, _usCulture, out rval))
- {
- height = rval;
- }
-
- }
-
- break;
- }
-
- case "Season":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- bannerSeason = int.Parse(val);
- }
- break;
- }
-
-
- default:
- reader.Skip();
- break;
+ if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase))
+ {
+ return 2;
+ }
}
- }
- else
- {
- reader.Read();
- }
- }
- if (!string.IsNullOrEmpty(url) && !bannerSeason.HasValue)
- {
- var imageInfo = new RemoteImageInfo
- {
- RatingType = RatingType.Score,
- CommunityRating = rating,
- VoteCount = voteCount,
- Url = TVUtils.BannerUrl + url,
- ProviderName = Name,
- Language = language,
- Width = width,
- Height = height
- };
-
- if (!string.IsNullOrEmpty(thumbnailUrl))
- {
- imageInfo.ThumbnailUrl = TVUtils.BannerUrl + thumbnailUrl;
- }
-
- if (string.Equals(bannerType, "poster", StringComparison.OrdinalIgnoreCase))
- {
- imageInfo.Type = ImageType.Primary;
- images.Add(imageInfo);
- }
- else if (string.Equals(bannerType, "series", StringComparison.OrdinalIgnoreCase))
- {
- imageInfo.Type = ImageType.Banner;
- images.Add(imageInfo);
- }
- else if (string.Equals(bannerType, "fanart", StringComparison.OrdinalIgnoreCase))
- {
- imageInfo.Type = ImageType.Backdrop;
- images.Add(imageInfo);
- }
- }
+ if (string.IsNullOrEmpty(i.Language))
+ {
+ return isLanguageEn ? 3 : 2;
+ }
+ return 0;
+ })
+ .ThenByDescending(i => i.CommunityRating ?? 0)
+ .ThenByDescending(i => i.VoteCount ?? 0);
}
public int Order => 0;
diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs
index 52e60a8ed..5ea73dfbf 100644
--- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs
+++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs
@@ -1,72 +1,41 @@
using System;
using System.Collections.Generic;
using System.Globalization;
-using System.IO;
using System.Linq;
-using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using System.Xml;
-using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Net;
using MediaBrowser.Model.Providers;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
+using TvDbSharper;
+using TvDbSharper.Dto;
+using Series = MediaBrowser.Controller.Entities.TV.Series;
namespace MediaBrowser.Providers.TV.TheTVDB
{
public class TvdbSeriesProvider : IRemoteMetadataProvider<Series, SeriesInfo>, IHasOrder
{
internal static TvdbSeriesProvider Current { get; private set; }
- private readonly IZipClient _zipClient;
private readonly IHttpClient _httpClient;
- private readonly IFileSystem _fileSystem;
- private readonly IXmlReaderSettingsFactory _xmlSettings;
- private readonly IServerConfigurationManager _config;
- private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly ILogger _logger;
private readonly ILibraryManager _libraryManager;
private readonly ILocalizationManager _localizationManager;
+ private readonly TvDbClientManager _tvDbClientManager;
- public TvdbSeriesProvider(IZipClient zipClient, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager config, ILogger logger, ILibraryManager libraryManager, IXmlReaderSettingsFactory xmlSettings, ILocalizationManager localizationManager)
+ public TvdbSeriesProvider(IHttpClient httpClient, ILogger<TvdbSeriesProvider> logger, ILibraryManager libraryManager, ILocalizationManager localizationManager, TvDbClientManager tvDbClientManager)
{
- _zipClient = zipClient;
_httpClient = httpClient;
- _fileSystem = fileSystem;
- _config = config;
_logger = logger;
_libraryManager = libraryManager;
- _xmlSettings = xmlSettings;
_localizationManager = localizationManager;
Current = this;
- }
-
- public const string TvdbBaseUrl = "https://www.thetvdb.com/";
-
- private const string SeriesSearchUrl = TvdbBaseUrl + "api/GetSeries.php?seriesname={0}&language={1}";
- private const string SeriesGetZip = TvdbBaseUrl + "api/{0}/series/{1}/all/{2}.zip";
- private const string GetSeriesByImdbId = TvdbBaseUrl + "api/GetSeriesByRemoteID.php?imdbid={0}&language={1}";
- private const string GetSeriesByZap2ItId = TvdbBaseUrl + "api/GetSeriesByRemoteID.php?zap2it={0}&language={1}";
-
- private string NormalizeLanguage(string language)
- {
- if (string.IsNullOrWhiteSpace(language))
- {
- return language;
- }
-
- // pt-br is just pt to tvdb
- return language.Split('-')[0].ToLowerInvariant();
+ _tvDbClientManager = tvDbClientManager;
}
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
@@ -96,8 +65,10 @@ namespace MediaBrowser.Providers.TV.TheTVDB
public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo itemId, CancellationToken cancellationToken)
{
- var result = new MetadataResult<Series>();
- result.QueriedById = true;
+ var result = new MetadataResult<Series>
+ {
+ QueriedById = true
+ };
if (!IsValidSeries(itemId.ProviderIds))
{
@@ -109,428 +80,100 @@ namespace MediaBrowser.Providers.TV.TheTVDB
if (IsValidSeries(itemId.ProviderIds))
{
- var seriesDataPath = await EnsureSeriesInfo(itemId.ProviderIds, itemId.Name, itemId.Year, itemId.MetadataLanguage, cancellationToken).ConfigureAwait(false);
-
- if (string.IsNullOrEmpty(seriesDataPath))
- {
- return result;
- }
-
result.Item = new Series();
result.HasMetadata = true;
- FetchSeriesData(result, itemId.MetadataLanguage, itemId.ProviderIds, cancellationToken);
+ await FetchSeriesData(result, itemId.MetadataLanguage, itemId.ProviderIds, cancellationToken)
+ .ConfigureAwait(false);
}
return result;
}
- /// <summary>
- /// Fetches the series data.
- /// </summary>
- /// <param name="result">The result.</param>
- /// <param name="metadataLanguage">The metadata language.</param>
- /// <param name="seriesProviderIds">The series provider ids.</param>
- /// <param name="cancellationToken">The cancellation token.</param>
- /// <returns>Task{System.Boolean}.</returns>
- private void FetchSeriesData(MetadataResult<Series> result, string metadataLanguage, Dictionary<string, string> seriesProviderIds, CancellationToken cancellationToken)
+ private async Task FetchSeriesData(MetadataResult<Series> result, string metadataLanguage, Dictionary<string, string> seriesProviderIds, CancellationToken cancellationToken)
{
var series = result.Item;
- if (seriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out string id) && !string.IsNullOrEmpty(id))
+ if (seriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out var tvdbId) && !string.IsNullOrEmpty(tvdbId))
{
- series.SetProviderId(MetadataProviders.Tvdb, id);
+ series.SetProviderId(MetadataProviders.Tvdb, tvdbId);
}
- if (seriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out id) && !string.IsNullOrEmpty(id))
+ if (seriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out var imdbId) && !string.IsNullOrEmpty(imdbId))
{
- series.SetProviderId(MetadataProviders.Imdb, id);
+ series.SetProviderId(MetadataProviders.Imdb, imdbId);
+ tvdbId = await GetSeriesByRemoteId(imdbId, MetadataProviders.Imdb.ToString(), metadataLanguage,
+ cancellationToken).ConfigureAwait(false);
}
- if (seriesProviderIds.TryGetValue(MetadataProviders.Zap2It.ToString(), out id) && !string.IsNullOrEmpty(id))
+ if (seriesProviderIds.TryGetValue(MetadataProviders.Zap2It.ToString(), out var zap2It) && !string.IsNullOrEmpty(zap2It))
{
- series.SetProviderId(MetadataProviders.Zap2It, id);
+ series.SetProviderId(MetadataProviders.Zap2It, zap2It);
+ tvdbId = await GetSeriesByRemoteId(zap2It, MetadataProviders.Zap2It.ToString(), metadataLanguage,
+ cancellationToken).ConfigureAwait(false);
}
- var seriesDataPath = GetSeriesDataPath(_config.ApplicationPaths, seriesProviderIds);
-
- var seriesXmlPath = GetSeriesXmlPath(seriesProviderIds, metadataLanguage);
- var actorsXmlPath = Path.Combine(seriesDataPath, "actors.xml");
-
- FetchSeriesInfo(result, seriesXmlPath, cancellationToken);
-
- cancellationToken.ThrowIfCancellationRequested();
-
- result.ResetPeople();
-
- FetchActors(result, actorsXmlPath);
- }
-
- /// <summary>
- /// Downloads the series zip.
- /// </summary>
- internal async Task DownloadSeriesZip(string seriesId, string idType, string seriesName, int? seriesYear, string seriesDataPath, long? lastTvDbUpdateTime, string preferredMetadataLanguage, CancellationToken cancellationToken)
- {
try
{
- await DownloadSeriesZip(seriesId, idType, seriesName, seriesYear, seriesDataPath, lastTvDbUpdateTime, preferredMetadataLanguage, preferredMetadataLanguage, cancellationToken).ConfigureAwait(false);
- return;
- }
- catch (HttpException ex)
- {
- if (!ex.StatusCode.HasValue || ex.StatusCode.Value != HttpStatusCode.NotFound)
- {
- throw;
- }
- }
-
- if (!string.Equals(preferredMetadataLanguage, "en", StringComparison.OrdinalIgnoreCase))
- {
- await DownloadSeriesZip(seriesId, idType, seriesName, seriesYear, seriesDataPath, lastTvDbUpdateTime, "en", preferredMetadataLanguage, cancellationToken).ConfigureAwait(false);
- }
- }
-
- private async Task DownloadSeriesZip(string seriesId, string idType, string seriesName, int? seriesYear, string seriesDataPath, long? lastTvDbUpdateTime, string preferredMetadataLanguage, string saveAsMetadataLanguage, CancellationToken cancellationToken)
- {
- if (string.IsNullOrWhiteSpace(seriesId))
- {
- throw new ArgumentNullException(nameof(seriesId));
- }
-
- if (!string.Equals(idType, "tvdb", StringComparison.OrdinalIgnoreCase))
- {
- seriesId = await GetSeriesByRemoteId(seriesId, idType, preferredMetadataLanguage, cancellationToken).ConfigureAwait(false);
+ var seriesResult =
+ await _tvDbClientManager
+ .GetSeriesByIdAsync(Convert.ToInt32(tvdbId), metadataLanguage, cancellationToken)
+ .ConfigureAwait(false);
+ MapSeriesToResult(result, seriesResult.Data, metadataLanguage);
}
-
- // If searching by remote id came up empty, then do a regular search
- if (string.IsNullOrWhiteSpace(seriesId) && !string.IsNullOrWhiteSpace(seriesName))
+ catch (TvDbServerException e)
{
- var searchInfo = new SeriesInfo
- {
- Name = seriesName,
- Year = seriesYear,
- MetadataLanguage = preferredMetadataLanguage
- };
- var results = await GetSearchResults(searchInfo, cancellationToken).ConfigureAwait(false);
- var result = results.FirstOrDefault();
- if (result != null)
- {
- seriesId = result.GetProviderId(MetadataProviders.Tvdb);
- }
- }
-
- if (string.IsNullOrWhiteSpace(seriesId))
- {
- throw new ArgumentNullException(nameof(seriesId));
+ _logger.LogError(e, "Failed to retrieve series with id {TvdbId}", tvdbId);
+ return;
}
- var url = string.Format(SeriesGetZip, TVUtils.TvdbApiKey, seriesId, NormalizeLanguage(preferredMetadataLanguage));
-
- using (var response = await _httpClient.SendAsync(new HttpRequestOptions
- {
- Url = url,
- CancellationToken = cancellationToken,
- BufferContent = false
-
- }, "GET").ConfigureAwait(false))
- {
- using (var zipStream = response.Content)
- {
- // Delete existing files
- DeleteXmlFiles(seriesDataPath);
-
- // Copy to memory stream because we need a seekable stream
- using (var ms = new MemoryStream())
- {
- await zipStream.CopyToAsync(ms).ConfigureAwait(false);
+ cancellationToken.ThrowIfCancellationRequested();
- ms.Position = 0;
- _zipClient.ExtractAllFromZip(ms, seriesDataPath, true);
- }
- }
- }
+ result.ResetPeople();
- // Sanitize all files, except for extracted episode files
- foreach (var file in _fileSystem.GetFilePaths(seriesDataPath, true).ToList()
- .Where(i => string.Equals(Path.GetExtension(i), ".xml", StringComparison.OrdinalIgnoreCase))
- .Where(i => !Path.GetFileName(i).StartsWith("episode-", StringComparison.OrdinalIgnoreCase)))
+ try
{
- await SanitizeXmlFile(file).ConfigureAwait(false);
+ var actorsResult = await _tvDbClientManager
+ .GetActorsAsync(Convert.ToInt32(tvdbId), metadataLanguage, cancellationToken).ConfigureAwait(false);
+ MapActorsToResult(result, actorsResult.Data);
}
-
- var downloadLangaugeXmlFile = Path.Combine(seriesDataPath, NormalizeLanguage(preferredMetadataLanguage) + ".xml");
- var saveAsLanguageXmlFile = Path.Combine(seriesDataPath, saveAsMetadataLanguage + ".xml");
-
- if (!string.Equals(downloadLangaugeXmlFile, saveAsLanguageXmlFile, StringComparison.OrdinalIgnoreCase))
+ catch (TvDbServerException e)
{
- File.Copy(downloadLangaugeXmlFile, saveAsLanguageXmlFile, true);
+ _logger.LogError(e, "Failed to retrieve actors for series {TvdbId}", tvdbId);
}
-
- await ExtractEpisodes(seriesDataPath, downloadLangaugeXmlFile, lastTvDbUpdateTime).ConfigureAwait(false);
}
private async Task<string> GetSeriesByRemoteId(string id, string idType, string language, CancellationToken cancellationToken)
{
- string url;
- if (string.Equals(idType, MetadataProviders.Zap2It.ToString(), StringComparison.OrdinalIgnoreCase))
- {
- url = string.Format(GetSeriesByZap2ItId, id, NormalizeLanguage(language));
- }
- else
- {
- url = string.Format(GetSeriesByImdbId, id, NormalizeLanguage(language));
- }
-
- using (var response = await _httpClient.SendAsync(new HttpRequestOptions
- {
- Url = url,
- CancellationToken = cancellationToken,
- BufferContent = false
-
- }, "GET").ConfigureAwait(false))
- {
- using (var result = response.Content)
- {
- return FindSeriesId(result);
- }
- }
- }
-
- private string FindSeriesId(Stream stream)
- {
- using (var streamReader = new StreamReader(stream, Encoding.UTF8))
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Series":
- {
- if (reader.IsEmptyElement)
- {
- reader.Read();
- continue;
- }
- using (var subtree = reader.ReadSubtree())
- {
- return FindSeriesId(subtree);
- }
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
- }
+ TvDbResponse<SeriesSearchResult[]> result = null;
- return null;
- }
-
- private string FindSeriesId(XmlReader reader)
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
+ try
{
- if (reader.NodeType == XmlNodeType.Element)
+ if (string.Equals(idType, MetadataProviders.Zap2It.ToString(), StringComparison.OrdinalIgnoreCase))
{
- switch (reader.Name)
- {
- case "seriesid":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- return val;
- }
-
- return null;
- }
-
- default:
- reader.Skip();
- break;
- }
+ result = await _tvDbClientManager.GetSeriesByZap2ItIdAsync(id, language, cancellationToken)
+ .ConfigureAwait(false);
}
else
{
- reader.Read();
+ result = await _tvDbClientManager.GetSeriesByImdbIdAsync(id, language, cancellationToken)
+ .ConfigureAwait(false);
}
}
-
- return null;
- }
-
- internal static bool IsValidSeries(Dictionary<string, string> seriesProviderIds)
- {
- if (seriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out string id))
+ catch (TvDbServerException e)
{
- // This check should ideally never be necessary but we're seeing some cases of this and haven't tracked them down yet.
- if (!string.IsNullOrWhiteSpace(id))
- {
- return true;
- }
+ _logger.LogError(e, "Failed to retrieve series with remote id {RemoteId}", id);
}
- if (seriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out id))
- {
- // This check should ideally never be necessary but we're seeing some cases of this and haven't tracked them down yet.
- if (!string.IsNullOrWhiteSpace(id))
- {
- return true;
- }
- }
-
- if (seriesProviderIds.TryGetValue(MetadataProviders.Zap2It.ToString(), out id))
- {
- // This check should ideally never be necessary but we're seeing some cases of this and haven't tracked them down yet.
- if (!string.IsNullOrWhiteSpace(id))
- {
- return true;
- }
- }
- return false;
- }
-
- private SemaphoreSlim _ensureSemaphore = new SemaphoreSlim(1, 1);
- internal async Task<string> EnsureSeriesInfo(Dictionary<string, string> seriesProviderIds, string seriesName, int? seriesYear, string preferredMetadataLanguage, CancellationToken cancellationToken)
- {
- await _ensureSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
-
- try
- {
- if (seriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out string seriesId) && !string.IsNullOrWhiteSpace(seriesId))
- {
- var seriesDataPath = GetSeriesDataPath(_config.ApplicationPaths, seriesProviderIds);
-
- // Only download if not already there
- // The post-scan task will take care of updates so we don't need to re-download here
- if (!IsCacheValid(seriesDataPath, preferredMetadataLanguage))
- {
- await DownloadSeriesZip(seriesId, MetadataProviders.Tvdb.ToString(), seriesName, seriesYear, seriesDataPath, null, preferredMetadataLanguage, cancellationToken).ConfigureAwait(false);
- }
-
- return seriesDataPath;
- }
-
- if (seriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out seriesId) && !string.IsNullOrWhiteSpace(seriesId))
- {
- var seriesDataPath = GetSeriesDataPath(_config.ApplicationPaths, seriesProviderIds);
-
- // Only download if not already there
- // The post-scan task will take care of updates so we don't need to re-download here
- if (!IsCacheValid(seriesDataPath, preferredMetadataLanguage))
- {
- try
- {
- await DownloadSeriesZip(seriesId, MetadataProviders.Imdb.ToString(), seriesName, seriesYear, seriesDataPath, null, preferredMetadataLanguage, cancellationToken).ConfigureAwait(false);
- }
- catch (ArgumentNullException)
- {
- // Unable to determine tvdb id based on imdb id
- return null;
- }
- }
-
- return seriesDataPath;
- }
-
- if (seriesProviderIds.TryGetValue(MetadataProviders.Zap2It.ToString(), out seriesId) && !string.IsNullOrWhiteSpace(seriesId))
- {
- var seriesDataPath = GetSeriesDataPath(_config.ApplicationPaths, seriesProviderIds);
-
- // Only download if not already there
- // The post-scan task will take care of updates so we don't need to re-download here
- if (!IsCacheValid(seriesDataPath, preferredMetadataLanguage))
- {
- try
- {
- await DownloadSeriesZip(seriesId, MetadataProviders.Zap2It.ToString(), seriesName, seriesYear, seriesDataPath, null, preferredMetadataLanguage, cancellationToken).ConfigureAwait(false);
- }
- catch (ArgumentNullException)
- {
- // Unable to determine tvdb id based on Zap2It id
- return null;
- }
- }
-
- return seriesDataPath;
- }
-
- return null;
- }
- finally
- {
- _ensureSemaphore.Release();
- }
+ return result?.Data.First().Id.ToString();
}
- private bool IsCacheValid(string seriesDataPath, string preferredMetadataLanguage)
+ internal static bool IsValidSeries(Dictionary<string, string> seriesProviderIds)
{
- try
- {
- var files = _fileSystem.GetFiles(seriesDataPath, new[] { ".xml" }, true, false)
- .ToList();
-
- var seriesXmlFilename = preferredMetadataLanguage + ".xml";
-
- const int cacheHours = 12;
-
- var seriesFile = files.FirstOrDefault(i => string.Equals(seriesXmlFilename, i.Name, StringComparison.OrdinalIgnoreCase));
- // No need to check age if automatic updates are enabled
- if (seriesFile == null || !seriesFile.Exists || (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(seriesFile)).TotalHours > cacheHours)
- {
- return false;
- }
-
- var actorsXml = files.FirstOrDefault(i => string.Equals("actors.xml", i.Name, StringComparison.OrdinalIgnoreCase));
- // No need to check age if automatic updates are enabled
- if (actorsXml == null || !actorsXml.Exists || (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(actorsXml)).TotalHours > cacheHours)
- {
- return false;
- }
-
- var bannersXml = files.FirstOrDefault(i => string.Equals("banners.xml", i.Name, StringComparison.OrdinalIgnoreCase));
- // No need to check age if automatic updates are enabled
- if (bannersXml == null || !bannersXml.Exists || (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(bannersXml)).TotalHours > cacheHours)
- {
- return false;
- }
- return true;
- }
- catch (FileNotFoundException)
- {
- return false;
- }
- catch (IOException)
- {
- return false;
- }
+ return seriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out _) ||
+ seriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out _) ||
+ seriesProviderIds.TryGetValue(MetadataProviders.Zap2It.ToString(), out _);
}
/// <summary>
@@ -543,7 +186,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
/// <returns>Task{System.String}.</returns>
private async Task<IEnumerable<RemoteSearchResult>> FindSeries(string name, int? year, string language, CancellationToken cancellationToken)
{
- var results = (await FindSeriesInternal(name, language, cancellationToken).ConfigureAwait(false));
+ var results = await FindSeriesInternal(name, language, cancellationToken).ConfigureAwait(false);
if (results.Count == 0)
{
@@ -552,7 +195,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
if (!string.IsNullOrWhiteSpace(nameWithoutYear) && !string.Equals(nameWithoutYear, name, StringComparison.OrdinalIgnoreCase))
{
- results = (await FindSeriesInternal(nameWithoutYear, language, cancellationToken).ConfigureAwait(false));
+ results = await FindSeriesInternal(nameWithoutYear, language, cancellationToken).ConfigureAwait(false);
}
}
@@ -570,194 +213,59 @@ namespace MediaBrowser.Providers.TV.TheTVDB
private async Task<List<RemoteSearchResult>> FindSeriesInternal(string name, string language, CancellationToken cancellationToken)
{
- var url = string.Format(SeriesSearchUrl, WebUtility.UrlEncode(name), NormalizeLanguage(language));
-
var comparableName = GetComparableName(name);
-
var list = new List<Tuple<List<string>, RemoteSearchResult>>();
-
- using (var response = await _httpClient.SendAsync(new HttpRequestOptions
- {
- Url = url,
- CancellationToken = cancellationToken,
- BufferContent = false
-
- }, "GET").ConfigureAwait(false))
+ TvDbResponse<SeriesSearchResult[]> result;
+ try
{
- using (var stream = response.Content)
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- using (var streamReader = new StreamReader(stream, Encoding.UTF8))
- {
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Series":
- {
- if (reader.IsEmptyElement)
- {
- reader.Read();
- continue;
- }
- using (var subtree = reader.ReadSubtree())
- {
- var searchResultInfo = GetSeriesSearchResultFromSubTree(subtree);
- if (searchResultInfo != null)
- {
- searchResultInfo.Item2.SearchProviderName = Name;
- list.Add(searchResultInfo);
- }
- }
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
- }
- }
+ result = await _tvDbClientManager.GetSeriesByNameAsync(comparableName, language, cancellationToken)
+ .ConfigureAwait(false);
}
-
- return list
- .OrderBy(i => i.Item1.Contains(comparableName, StringComparer.OrdinalIgnoreCase) ? 0 : 1)
- .ThenBy(i => list.IndexOf(i))
- .Select(i => i.Item2)
- .ToList();
- }
-
- private Tuple<List<string>, RemoteSearchResult> GetSeriesSearchResultFromSubTree(XmlReader reader)
- {
- var searchResult = new RemoteSearchResult
+ catch (TvDbServerException e)
{
- SearchProviderName = Name
- };
-
- var tvdbTitles = new List<string>();
- string seriesId = null;
-
- reader.MoveToContent();
- reader.Read();
+ _logger.LogError(e, "No series results found for {Name}", comparableName);
+ return new List<RemoteSearchResult>();
+ }
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
+ foreach (var seriesSearchResult in result.Data)
{
- if (reader.NodeType == XmlNodeType.Element)
+ var tvdbTitles = new List<string>
{
- switch (reader.Name)
- {
- case "SeriesName":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- tvdbTitles.Add(GetComparableName(val));
- }
- break;
- }
-
- case "AliasNames":
- {
- var val = reader.ReadElementContentAsString();
-
- var alias = (val ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(GetComparableName);
- tvdbTitles.AddRange(alias);
- break;
- }
-
- case "IMDB_ID":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- searchResult.SetProviderId(MetadataProviders.Imdb, val);
- }
- break;
- }
-
- case "banner":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- searchResult.ImageUrl = TVUtils.BannerUrl + val;
- }
- break;
- }
-
- case "FirstAired":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (DateTime.TryParse(val, out var date))
- {
- searchResult.ProductionYear = date.Year;
- }
- }
- break;
- }
-
- case "id":
- case "seriesid":
- {
- var val = reader.ReadElementContentAsString();
+ GetComparableName(seriesSearchResult.SeriesName)
+ };
+ tvdbTitles.AddRange(seriesSearchResult.Aliases.Select(GetComparableName));
- if (!string.IsNullOrWhiteSpace(val))
- {
- seriesId = val;
- }
- break;
- }
+ DateTime.TryParse(seriesSearchResult.FirstAired, out var firstAired);
+ var remoteSearchResult = new RemoteSearchResult
+ {
+ Name = tvdbTitles.FirstOrDefault(),
+ ProductionYear = firstAired.Year,
+ SearchProviderName = Name,
+ ImageUrl = TvdbUtils.BannerUrl + seriesSearchResult.Banner
- default:
- reader.Skip();
- break;
- }
+ };
+ try
+ {
+ var seriesSesult =
+ await _tvDbClientManager.GetSeriesByIdAsync(seriesSearchResult.Id, language, cancellationToken)
+ .ConfigureAwait(false);
+ remoteSearchResult.SetProviderId(MetadataProviders.Imdb, seriesSesult.Data.ImdbId);
+ remoteSearchResult.SetProviderId(MetadataProviders.Zap2It, seriesSesult.Data.Zap2itId);
}
- else
+ catch (TvDbServerException e)
{
- reader.Read();
+ _logger.LogError(e, "Unable to retrieve series with id {TvdbId}", seriesSearchResult.Id);
}
- }
- if (tvdbTitles.Count == 0)
- {
- return null;
+ remoteSearchResult.SetProviderId(MetadataProviders.Tvdb, seriesSearchResult.Id.ToString());
+ list.Add(new Tuple<List<string>, RemoteSearchResult>(tvdbTitles, remoteSearchResult));
}
- searchResult.Name = tvdbTitles.FirstOrDefault();
- searchResult.SetProviderId(MetadataProviders.Tvdb, seriesId);
-
- return new Tuple<List<string>, RemoteSearchResult>(tvdbTitles, searchResult);
+ return list
+ .OrderBy(i => i.Item1.Contains(comparableName, StringComparer.OrdinalIgnoreCase) ? 0 : 1)
+ .ThenBy(i => list.IndexOf(i))
+ .Select(i => i.Item2)
+ .ToList();
}
/// <summary>
@@ -767,7 +275,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
/// <summary>
/// The spacers
/// </summary>
- const string spacers = "/,.:;\\(){}[]+-_=–*"; // (there are not actually two - in the they are different char codes)
+ const string spacers = "/,.:;\\(){}[]+-_=–*"; // (there are two types of dashes, short and long)
/// <summary>
/// Gets the name of the comparable.
@@ -781,7 +289,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
var sb = new StringBuilder();
foreach (var c in name)
{
- if ((int)c >= 0x2B0 && (int)c <= 0x0333)
+ if (c >= 0x2B0 && c <= 0x0333)
{
// skip char modifier and diacritics
}
@@ -817,895 +325,82 @@ namespace MediaBrowser.Providers.TV.TheTVDB
return name.Trim();
}
- private void FetchSeriesInfo(MetadataResult<Series> result, string seriesXmlPath, CancellationToken cancellationToken)
+ private void MapSeriesToResult(MetadataResult<Series> result, TvDbSharper.Dto.Series tvdbSeries, string metadataLanguage)
{
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- var episiodeAirDates = new List<DateTime>();
-
- using (var fileStream = _fileSystem.GetFileStream(seriesXmlPath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read))
+ Series series = result.Item;
+ series.SetProviderId(MetadataProviders.Tvdb, tvdbSeries.Id.ToString());
+ series.Name = tvdbSeries.SeriesName;
+ series.Overview = (tvdbSeries.Overview ?? string.Empty).Trim();
+ result.ResultLanguage = metadataLanguage;
+ series.AirDays = TVUtils.GetAirDays(tvdbSeries.AirsDayOfWeek);
+ series.AirTime = tvdbSeries.AirsTime;
+ series.CommunityRating = (float?)tvdbSeries.SiteRating;
+ series.SetProviderId(MetadataProviders.Imdb, tvdbSeries.ImdbId);
+ series.SetProviderId(MetadataProviders.Zap2It, tvdbSeries.Zap2itId);
+ if (Enum.TryParse(tvdbSeries.Status, true, out SeriesStatus seriesStatus))
{
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
- {
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Series":
- {
- if (reader.IsEmptyElement)
- {
- reader.Read();
- continue;
- }
- using (var subtree = reader.ReadSubtree())
- {
- FetchDataFromSeriesNode(result, subtree, cancellationToken);
- }
- break;
- }
-
- case "Episode":
- {
- if (reader.IsEmptyElement)
- {
- reader.Read();
- continue;
- }
- using (var subtree = reader.ReadSubtree())
- {
- var date = GetFirstAiredDateFromEpisodeNode(subtree, cancellationToken);
-
- if (date.HasValue)
- {
- episiodeAirDates.Add(date.Value);
- }
- }
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
- }
- }
-
- if (result.Item.Status.HasValue && result.Item.Status.Value == SeriesStatus.Ended && episiodeAirDates.Count > 0)
- {
- result.Item.EndDate = episiodeAirDates.Max();
- }
- }
-
- private DateTime? GetFirstAiredDateFromEpisodeNode(XmlReader reader, CancellationToken cancellationToken)
- {
- DateTime? airDate = null;
- int? seasonNumber = null;
-
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "FirstAired":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (DateTime.TryParse(val, out var date))
- {
- airDate = date.ToUniversalTime();
- }
- }
-
- break;
- }
-
- case "SeasonNumber":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- seasonNumber = rval;
- }
- }
-
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
-
- if (seasonNumber.HasValue && seasonNumber.Value != 0)
- {
- return airDate;
- }
-
- return null;
- }
-
- /// <summary>
- /// Fetches the actors.
- /// </summary>
- /// <param name="result">The result.</param>
- /// <param name="actorsXmlPath">The actors XML path.</param>
- private void FetchActors(MetadataResult<Series> result, string actorsXmlPath)
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- using (var fileStream = _fileSystem.GetFileStream(actorsXmlPath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read))
- {
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
- {
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Actor":
- {
- if (reader.IsEmptyElement)
- {
- reader.Read();
- continue;
- }
- using (var subtree = reader.ReadSubtree())
- {
- FetchDataFromActorNode(result, subtree);
- }
- break;
- }
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
- }
- }
- }
-
- /// <summary>
- /// Fetches the data from actor node.
- /// </summary>
- /// <param name="result">The result.</param>
- /// <param name="reader">The reader.</param>
- private void FetchDataFromActorNode(MetadataResult<Series> result, XmlReader reader)
- {
- reader.MoveToContent();
-
- var personInfo = new PersonInfo();
-
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Name":
- {
- personInfo.Name = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
- break;
- }
-
- case "Role":
- {
- personInfo.Role = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
- break;
- }
-
- case "id":
- {
- reader.Skip();
- break;
- }
-
- case "Image":
- {
- var url = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
- if (!string.IsNullOrWhiteSpace(url))
- {
- personInfo.ImageUrl = TVUtils.BannerUrl + url;
- }
- break;
- }
-
- case "SortOrder":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- personInfo.SortOrder = rval;
- }
- }
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
-
- personInfo.Type = PersonType.Actor;
-
- if (!string.IsNullOrWhiteSpace(personInfo.Name))
- {
- result.AddPerson(personInfo);
- }
- }
-
- private void FetchDataFromSeriesNode(MetadataResult<Series> result, XmlReader reader, CancellationToken cancellationToken)
- {
- Series item = result.Item;
-
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "id":
- {
- item.SetProviderId(MetadataProviders.Tvdb.ToString(), (reader.ReadElementContentAsString() ?? string.Empty).Trim());
- break;
- }
-
- case "SeriesName":
- {
- item.Name = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
- break;
- }
-
- case "Overview":
- {
- item.Overview = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
- break;
- }
-
- case "Language":
- {
- result.ResultLanguage = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
- break;
- }
-
- case "Airs_DayOfWeek":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- item.AirDays = TVUtils.GetAirDays(val);
- }
- break;
- }
-
- case "Airs_Time":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- item.AirTime = val;
- }
- break;
- }
-
- case "ContentRating":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- item.OfficialRating = val;
- }
- break;
- }
-
- case "Rating":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // float.TryParse is local aware, so it can be probamatic, force us culture
- if (float.TryParse(val, NumberStyles.AllowDecimalPoint, _usCulture, out var rval))
- {
- item.CommunityRating = rval;
- }
- }
- break;
- }
- case "RatingCount":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- //item.VoteCount = rval;
- }
- }
-
- break;
- }
-
- case "IMDB_ID":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- item.SetProviderId(MetadataProviders.Imdb, val);
- }
-
- break;
- }
-
- case "zap2it_id":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- item.SetProviderId(MetadataProviders.Zap2It, val);
- }
-
- break;
- }
-
- case "Status":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (Enum.TryParse(val, true, out SeriesStatus seriesStatus))
- item.Status = seriesStatus;
- }
-
- break;
- }
-
- case "FirstAired":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (DateTime.TryParse(val, out var date))
- {
- date = date.ToUniversalTime();
-
- item.PremiereDate = date;
- item.ProductionYear = date.Year;
- }
- }
-
- break;
- }
-
- case "Runtime":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- // int.TryParse is local aware, so it can be probamatic, force us culture
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var rval))
- {
- item.RunTimeTicks = TimeSpan.FromMinutes(rval).Ticks;
- }
- }
-
- break;
- }
-
- case "Genre":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- var vals = val
- .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(i => i.Trim())
- .Where(i => !string.IsNullOrWhiteSpace(i))
- .ToList();
-
- if (vals.Count > 0)
- {
- item.Genres = Array.Empty<string>();
-
- foreach (var genre in vals)
- {
- item.AddGenre(genre);
- }
- }
- }
-
- break;
- }
-
- case "Network":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- var vals = val
- .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(i => i.Trim())
- .Where(i => !string.IsNullOrWhiteSpace(i))
- .ToList();
-
- if (vals.Count > 0)
- {
- item.SetStudios(vals);
- }
- }
-
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
-
- /// <summary>
- /// Extracts info for each episode into invididual xml files so that they can be easily accessed without having to step through the entire series xml
- /// </summary>
- /// <param name="seriesDataPath">The series data path.</param>
- /// <param name="xmlFile">The XML file.</param>
- /// <param name="lastTvDbUpdateTime">The last tv db update time.</param>
- /// <returns>Task.</returns>
- private async Task ExtractEpisodes(string seriesDataPath, string xmlFile, long? lastTvDbUpdateTime)
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- using (var fileStream = _fileSystem.GetFileStream(xmlFile, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read))
- {
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
- {
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "Episode":
- {
- var outerXml = reader.ReadOuterXml();
-
- await SaveEpsiodeXml(seriesDataPath, outerXml, lastTvDbUpdateTime).ConfigureAwait(false);
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
- }
- }
- }
-
- private async Task SaveEpsiodeXml(string seriesDataPath, string xml, long? lastTvDbUpdateTime)
- {
- var settings = _xmlSettings.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- var seasonNumber = -1;
- var episodeNumber = -1;
- var absoluteNumber = -1;
- var lastUpdateString = string.Empty;
-
- var dvdSeasonNumber = -1;
- var dvdEpisodeNumber = -1.0;
-
- using (var streamReader = new StringReader(xml))
- {
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- reader.MoveToContent();
- reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- switch (reader.Name)
- {
- case "lastupdated":
- {
- lastUpdateString = reader.ReadElementContentAsString();
- break;
- }
-
- case "EpisodeNumber":
- {
- var val = reader.ReadElementContentAsString();
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var num))
- {
- episodeNumber = num;
- }
- }
- break;
- }
-
- case "Combined_episodenumber":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (float.TryParse(val, NumberStyles.Any, _usCulture, out var num))
- {
- dvdEpisodeNumber = num;
- }
- }
-
- break;
- }
-
- case "Combined_season":
- {
- var val = reader.ReadElementContentAsString();
-
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (float.TryParse(val, NumberStyles.Any, _usCulture, out var num))
- {
- dvdSeasonNumber = Convert.ToInt32(num);
- }
- }
-
- break;
- }
-
- case "absolute_number":
- {
- var val = reader.ReadElementContentAsString();
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var num))
- {
- absoluteNumber = num;
- }
- }
- break;
- }
-
- case "SeasonNumber":
- {
- var val = reader.ReadElementContentAsString();
- if (!string.IsNullOrWhiteSpace(val))
- {
- if (int.TryParse(val, NumberStyles.Integer, _usCulture, out var num))
- {
- seasonNumber = num;
- }
- }
- break;
- }
-
- default:
- reader.Skip();
- break;
- }
- }
- else
- {
- reader.Read();
- }
- }
- }
+ series.Status = seriesStatus;
}
- var hasEpisodeChanged = true;
- if (!string.IsNullOrWhiteSpace(lastUpdateString) && lastTvDbUpdateTime.HasValue)
+ if (DateTime.TryParse(tvdbSeries.FirstAired, out var date))
{
- if (long.TryParse(lastUpdateString, NumberStyles.Any, _usCulture, out var num))
- {
- hasEpisodeChanged = num >= lastTvDbUpdateTime.Value;
- }
+ // dates from tvdb are UTC but without offset or Z
+ series.PremiereDate = date;
+ series.ProductionYear = date.Year;
}
- var file = Path.Combine(seriesDataPath, string.Format("episode-{0}-{1}.xml", seasonNumber, episodeNumber));
-
- // Only save the file if not already there, or if the episode has changed
- if (hasEpisodeChanged || !File.Exists(file))
+ series.RunTimeTicks = TimeSpan.FromMinutes(Convert.ToDouble(tvdbSeries.Runtime)).Ticks;
+ foreach (var genre in tvdbSeries.Genre)
{
- using (var fileStream = _fileSystem.GetFileStream(file, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.None, true))
- {
- using (var writer = XmlWriter.Create(fileStream, new XmlWriterSettings
- {
- Encoding = Encoding.UTF8,
- Async = true
- }))
- {
- await writer.WriteRawAsync(xml).ConfigureAwait(false);
- }
- }
+ series.AddGenre(genre);
}
- if (absoluteNumber != -1)
- {
- file = Path.Combine(seriesDataPath, string.Format("episode-abs-{0}.xml", absoluteNumber));
+ series.AddStudio(tvdbSeries.Network);
- // Only save the file if not already there, or if the episode has changed
- if (hasEpisodeChanged || !File.Exists(file))
- {
- using (var fileStream = _fileSystem.GetFileStream(file, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.None, true))
- {
- using (var writer = XmlWriter.Create(fileStream, new XmlWriterSettings
- {
- Encoding = Encoding.UTF8,
- Async = true
- }))
- {
- await writer.WriteRawAsync(xml).ConfigureAwait(false);
- }
- }
- }
- }
-
- if (dvdSeasonNumber != -1 && dvdEpisodeNumber != -1 && (dvdSeasonNumber != seasonNumber || dvdEpisodeNumber != episodeNumber))
+ if (result.Item.Status.HasValue && result.Item.Status.Value == SeriesStatus.Ended)
{
- file = Path.Combine(seriesDataPath, string.Format("episode-dvd-{0}-{1}.xml", dvdSeasonNumber, dvdEpisodeNumber));
-
- // Only save the file if not already there, or if the episode has changed
- if (hasEpisodeChanged || !File.Exists(file))
+ try
{
- using (var fileStream = _fileSystem.GetFileStream(file, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.None, true))
+ var episodeSummary = _tvDbClientManager
+ .GetSeriesEpisodeSummaryAsync(tvdbSeries.Id, metadataLanguage, CancellationToken.None).Result.Data;
+ var maxSeasonNumber = episodeSummary.AiredSeasons.Select(s => Convert.ToInt32(s)).Max();
+ var episodeQuery = new EpisodeQuery
{
- using (var writer = XmlWriter.Create(fileStream, new XmlWriterSettings
- {
- Encoding = Encoding.UTF8,
- Async = true
- }))
+ AiredSeason = maxSeasonNumber
+ };
+ var episodesPage =
+ _tvDbClientManager.GetEpisodesPageAsync(tvdbSeries.Id, episodeQuery, metadataLanguage, CancellationToken.None).Result.Data;
+ result.Item.EndDate = episodesPage.Select(e =>
{
- await writer.WriteRawAsync(xml).ConfigureAwait(false);
- }
- }
+ DateTime.TryParse(e.FirstAired, out var firstAired);
+ return firstAired;
+ }).Max();
}
- }
- }
-
- /// <summary>
- /// Gets the series data path.
- /// </summary>
- /// <param name="appPaths">The app paths.</param>
- /// <param name="seriesProviderIds">The series provider ids.</param>
- /// <returns>System.String.</returns>
- internal static string GetSeriesDataPath(IApplicationPaths appPaths, Dictionary<string, string> seriesProviderIds)
- {
- if (seriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out string seriesId) && !string.IsNullOrEmpty(seriesId))
- {
- var seriesDataPath = Path.Combine(GetSeriesDataPath(appPaths), seriesId);
-
- return seriesDataPath;
- }
-
- if (seriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out seriesId) && !string.IsNullOrEmpty(seriesId))
- {
- var seriesDataPath = Path.Combine(GetSeriesDataPath(appPaths), seriesId);
-
- return seriesDataPath;
- }
-
- if (seriesProviderIds.TryGetValue(MetadataProviders.Zap2It.ToString(), out seriesId) && !string.IsNullOrEmpty(seriesId))
- {
- var seriesDataPath = Path.Combine(GetSeriesDataPath(appPaths), seriesId);
-
- return seriesDataPath;
- }
-
- return null;
- }
-
- public string GetSeriesXmlPath(Dictionary<string, string> seriesProviderIds, string language)
- {
- var seriesDataPath = GetSeriesDataPath(_config.ApplicationPaths, seriesProviderIds);
-
- var seriesXmlFilename = language.ToLowerInvariant() + ".xml";
-
- return Path.Combine(seriesDataPath, seriesXmlFilename);
- }
-
- /// <summary>
- /// Gets the series data path.
- /// </summary>
- /// <param name="appPaths">The app paths.</param>
- /// <returns>System.String.</returns>
- internal static string GetSeriesDataPath(IApplicationPaths appPaths)
- {
- var dataPath = Path.Combine(appPaths.CachePath, "tvdb");
-
- return dataPath;
- }
-
- private void DeleteXmlFiles(string path)
- {
- try
- {
- foreach (var file in _fileSystem.GetFilePaths(path, true)
- .ToList())
+ catch (TvDbServerException e)
{
- _fileSystem.DeleteFile(file);
+ _logger.LogError(e, "Failed to find series end date for series {TvdbId}", tvdbSeries.Id);
}
}
- catch (IOException)
- {
- // No biggie
- }
}
- /// <summary>
- /// Sanitizes the XML file.
- /// </summary>
- /// <param name="file">The file.</param>
- /// <returns>Task.</returns>
- private async Task SanitizeXmlFile(string file)
+ private static void MapActorsToResult(MetadataResult<Series> result, IEnumerable<Actor> actors)
{
- string validXml;
-
- using (var fileStream = _fileSystem.GetFileStream(file, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read, true))
- {
- using (var reader = new StreamReader(fileStream))
- {
- var xml = await reader.ReadToEndAsync().ConfigureAwait(false);
-
- validXml = StripInvalidXmlCharacters(xml);
- }
- }
-
- using (var fileStream = _fileSystem.GetFileStream(file, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
+ foreach (Actor actor in actors)
{
- using (var writer = new StreamWriter(fileStream))
+ var personInfo = new PersonInfo
{
- await writer.WriteAsync(validXml).ConfigureAwait(false);
- }
- }
- }
-
- /// <summary>
- /// Strips the invalid XML characters.
- /// </summary>
- /// <param name="inString">The in string.</param>
- /// <returns>System.String.</returns>
- public static string StripInvalidXmlCharacters(string inString)
- {
- if (inString == null) return null;
-
- var sbOutput = new StringBuilder();
- char ch;
+ Type = PersonType.Actor,
+ Name = (actor.Name ?? string.Empty).Trim(),
+ Role = actor.Role,
+ ImageUrl = TvdbUtils.BannerUrl + actor.Image,
+ SortOrder = actor.SortOrder
+ };
- for (int i = 0; i < inString.Length; i++)
- {
- ch = inString[i];
- if ((ch >= 0x0020 && ch <= 0xD7FF) ||
- (ch >= 0xE000 && ch <= 0xFFFD) ||
- ch == 0x0009 ||
- ch == 0x000A ||
- ch == 0x000D)
+ if (!string.IsNullOrWhiteSpace(personInfo.Name))
{
- sbOutput.Append(ch);
+ result.AddPerson(personInfo);
}
}
- return sbOutput.ToString();
}
public string Name => "TheTVDB";
@@ -1717,7 +412,8 @@ namespace MediaBrowser.Providers.TV.TheTVDB
return;
}
- var srch = await FindSeries(info.Name, info.Year, info.MetadataLanguage, CancellationToken.None).ConfigureAwait(false);
+ var srch = await FindSeries(info.Name, info.Year, info.MetadataLanguage, CancellationToken.None)
+ .ConfigureAwait(false);
var entry = srch.FirstOrDefault();
diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbUtils.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbUtils.cs
new file mode 100644
index 000000000..112cbf800
--- /dev/null
+++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbUtils.cs
@@ -0,0 +1,36 @@
+using System;
+using System.ComponentModel;
+using MediaBrowser.Model.Entities;
+namespace MediaBrowser.Providers.TV.TheTVDB
+{
+ public static class TvdbUtils
+ {
+ public const string TvdbApiKey = "OG4V3YJ3FAP7FP2K";
+ public const string TvdbBaseUrl = "https://www.thetvdb.com/";
+ public const string BannerUrl = TvdbBaseUrl + "banners/";
+
+ public static ImageType GetImageTypeFromKeyType(string keyType)
+ {
+ switch (keyType.ToLowerInvariant())
+ {
+ case "poster":
+ case "season": return ImageType.Primary;
+ case "series":
+ case "seasonwide": return ImageType.Banner;
+ case "fanart": return ImageType.Backdrop;
+ default: throw new ArgumentException($"Invalid or unknown keytype: {keyType}", nameof(keyType));
+ }
+ }
+
+ public static string NormalizeLanguage(string language)
+ {
+ if (string.IsNullOrWhiteSpace(language))
+ {
+ return null;
+ }
+
+ // pt-br is just pt to tvdb
+ return language.Split('-')[0].ToLowerInvariant();
+ }
+ }
+}
diff --git a/MediaBrowser.Providers/TV/TvExternalIds.cs b/MediaBrowser.Providers/TV/TvExternalIds.cs
index 5c246e300..3f889fbbe 100644
--- a/MediaBrowser.Providers/TV/TvExternalIds.cs
+++ b/MediaBrowser.Providers/TV/TvExternalIds.cs
@@ -25,7 +25,7 @@ namespace MediaBrowser.Providers.TV
public string Key => MetadataProviders.Tvdb.ToString();
- public string UrlFormatString => TvdbPrescanTask.TvdbBaseUrl + "?tab=series&id={0}";
+ public string UrlFormatString => TvdbUtils.TvdbBaseUrl + "?tab=series&id={0}";
public bool Supports(IHasProviderIds item)
{
@@ -53,7 +53,7 @@ namespace MediaBrowser.Providers.TV
public string Key => MetadataProviders.Tvdb.ToString();
- public string UrlFormatString => TvdbPrescanTask.TvdbBaseUrl + "?tab=episode&id={0}";
+ public string UrlFormatString => TvdbUtils.TvdbBaseUrl + "?tab=episode&id={0}";
public bool Supports(IHasProviderIds item)
{
diff --git a/MediaBrowser.Tests/Properties/AssemblyInfo.cs b/MediaBrowser.Tests/Properties/AssemblyInfo.cs
index 9bc2a19f2..1bd3ef5d6 100644
--- a/MediaBrowser.Tests/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.Tests/Properties/AssemblyInfo.cs
@@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
+[assembly: AssemblyProduct("Jellyfin System")]
[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs
index 531978e1d..58ab2d27b 100644
--- a/MediaBrowser.WebDashboard/Api/DashboardService.cs
+++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs
@@ -13,7 +13,6 @@ using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Plugins;
-using MediaBrowser.Model.Reflection;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Services;
using Microsoft.Extensions.Logging;
@@ -117,20 +116,26 @@ namespace MediaBrowser.WebDashboard.Api
private readonly IFileSystem _fileSystem;
private readonly ILocalizationManager _localization;
private readonly IJsonSerializer _jsonSerializer;
- private readonly IAssemblyInfo _assemblyInfo;
private IResourceFileManager _resourceFileManager;
/// <summary>
/// Initializes a new instance of the <see cref="DashboardService" /> class.
/// </summary>
- public DashboardService(IServerApplicationHost appHost, IResourceFileManager resourceFileManager, IServerConfigurationManager serverConfigurationManager, IFileSystem fileSystem, ILocalizationManager localization, IJsonSerializer jsonSerializer, IAssemblyInfo assemblyInfo, ILogger logger, IHttpResultFactory resultFactory)
+ public DashboardService(
+ IServerApplicationHost appHost,
+ IResourceFileManager resourceFileManager,
+ IServerConfigurationManager serverConfigurationManager,
+ IFileSystem fileSystem,
+ ILocalizationManager localization,
+ IJsonSerializer jsonSerializer,
+ ILogger logger,
+ IHttpResultFactory resultFactory)
{
_appHost = appHost;
_serverConfigurationManager = serverConfigurationManager;
_fileSystem = fileSystem;
_localization = localization;
_jsonSerializer = jsonSerializer;
- _assemblyInfo = assemblyInfo;
_logger = logger;
_resultFactory = resultFactory;
_resourceFileManager = resourceFileManager;
@@ -149,7 +154,7 @@ namespace MediaBrowser.WebDashboard.Api
return _serverConfigurationManager.Configuration.DashboardSourcePath;
}
- return Path.Combine(_serverConfigurationManager.ApplicationPaths.ApplicationResourcesPath, "jellyfin-web", "src");
+ return _serverConfigurationManager.ApplicationPaths.WebPath;
}
}
@@ -187,7 +192,7 @@ namespace MediaBrowser.WebDashboard.Api
if (altPage != null)
{
plugin = altPage.Item2;
- stream = _assemblyInfo.GetManifestResourceStream(plugin.GetType(), altPage.Item1.EmbeddedResourcePath);
+ stream = plugin.GetType().Assembly.GetManifestResourceStream(altPage.Item1.EmbeddedResourcePath);
isJs = string.Equals(Path.GetExtension(altPage.Item1.EmbeddedResourcePath), ".js", StringComparison.OrdinalIgnoreCase);
isTemplate = altPage.Item1.EmbeddedResourcePath.EndsWith(".template.html");
diff --git a/MediaBrowser.WebDashboard/Properties/AssemblyInfo.cs b/MediaBrowser.WebDashboard/Properties/AssemblyInfo.cs
index 416ce4826..584d49021 100644
--- a/MediaBrowser.WebDashboard/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.WebDashboard/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/MediaBrowser.WebDashboard/jellyfin-web b/MediaBrowser.WebDashboard/jellyfin-web
-Subproject b4842e325e9d7d708193b4a27060cfe4c978df5
+Subproject ec5a3b6e5efb6041153b92818aee562f20ee994
diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs
index f20dbbb6e..5896497ab 100644
--- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs
+++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs
@@ -13,8 +13,6 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.XbmcMetadata.Configuration;
using MediaBrowser.XbmcMetadata.Savers;
using Microsoft.Extensions.Logging;
@@ -28,9 +26,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
/// The logger
/// </summary>
protected ILogger Logger { get; private set; }
- protected IFileSystem FileSystem { get; private set; }
protected IProviderManager ProviderManager { get; private set; }
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly IConfigurationManager _config;
@@ -39,13 +35,11 @@ namespace MediaBrowser.XbmcMetadata.Parsers
/// <summary>
/// Initializes a new instance of the <see cref="BaseNfoParser{T}" /> class.
/// </summary>
- public BaseNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public BaseNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager)
{
Logger = logger;
_config = config;
ProviderManager = providerManager;
- FileSystem = fileSystem;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
/// <summary>
@@ -68,12 +62,6 @@ namespace MediaBrowser.XbmcMetadata.Parsers
throw new ArgumentException("The metadata file was empty or null.", nameof(metadataFile));
}
- var settings = XmlReaderSettingsFactory.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
_validProviderIds = _validProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var idInfos = ProviderManager.GetExternalIdInfos(item.Item);
@@ -92,7 +80,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
_validProviderIds.Add("tmdbcolid", "TmdbCollection");
_validProviderIds.Add("imdb_id", "Imdb");
- Fetch(item, metadataFile, settings, cancellationToken);
+ Fetch(item, metadataFile, GetXmlReaderSettings(), cancellationToken);
}
protected virtual bool SupportsUrlAfterClosingXmlTag => false;
@@ -109,31 +97,26 @@ namespace MediaBrowser.XbmcMetadata.Parsers
if (!SupportsUrlAfterClosingXmlTag)
{
using (var fileStream = File.OpenRead(metadataFile))
+ using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
+ using (var reader = XmlReader.Create(streamReader, settings))
{
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
- {
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
- {
- item.ResetPeople();
+ item.ResetPeople();
- reader.MoveToContent();
- reader.Read();
+ reader.MoveToContent();
+ reader.Read();
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
+ // Loop through each element
+ while (!reader.EOF && reader.ReadState == ReadState.Interactive)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
- if (reader.NodeType == XmlNodeType.Element)
- {
- FetchDataFromXmlNode(reader, item);
- }
- else
- {
- reader.Read();
- }
- }
+ if (reader.NodeType == XmlNodeType.Element)
+ {
+ FetchDataFromXmlNode(reader, item);
+ }
+ else
+ {
+ reader.Read();
}
}
}
@@ -141,81 +124,76 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
using (var fileStream = File.OpenRead(metadataFile))
+ using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
- {
- item.ResetPeople();
-
- // Need to handle a url after the xml data
- // http://kodi.wiki/view/NFO_files/movies
+ item.ResetPeople();
- var xml = streamReader.ReadToEnd();
+ // Need to handle a url after the xml data
+ // http://kodi.wiki/view/NFO_files/movies
- // Find last closing Tag
- // Need to do this in two steps to account for random > characters after the closing xml
- var index = xml.LastIndexOf(@"</", StringComparison.Ordinal);
+ var xml = streamReader.ReadToEnd();
- // If closing tag exists, move to end of Tag
- if (index != -1)
- {
- index = xml.IndexOf('>', index);
- }
+ // Find last closing Tag
+ // Need to do this in two steps to account for random > characters after the closing xml
+ var index = xml.LastIndexOf(@"</", StringComparison.Ordinal);
- if (index != -1)
- {
- var endingXml = xml.Substring(index);
+ // If closing tag exists, move to end of Tag
+ if (index != -1)
+ {
+ index = xml.IndexOf('>', index);
+ }
- ParseProviderLinks(item.Item, endingXml);
+ if (index != -1)
+ {
+ var endingXml = xml.Substring(index);
- // If the file is just an imdb url, don't go any further
- if (index == 0)
- {
- return;
- }
+ ParseProviderLinks(item.Item, endingXml);
- xml = xml.Substring(0, index + 1);
- }
- else
+ // If the file is just an imdb url, don't go any further
+ if (index == 0)
{
- // If the file is just an Imdb url, handle that
-
- ParseProviderLinks(item.Item, xml);
-
return;
}
- // These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
- try
+ xml = xml.Substring(0, index + 1);
+ }
+ else
+ {
+ // If the file is just an Imdb url, handle that
+
+ ParseProviderLinks(item.Item, xml);
+
+ return;
+ }
+
+ // These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
+ try
+ {
+ using (var stringReader = new StringReader(xml))
+ using (var reader = XmlReader.Create(stringReader, settings))
{
- using (var stringReader = new StringReader(xml))
+ reader.MoveToContent();
+ reader.Read();
+
+ // Loop through each element
+ while (!reader.EOF && reader.ReadState == ReadState.Interactive)
{
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(stringReader, settings))
+ cancellationToken.ThrowIfCancellationRequested();
+
+ if (reader.NodeType == XmlNodeType.Element)
+ {
+ FetchDataFromXmlNode(reader, item);
+ }
+ else
{
- reader.MoveToContent();
reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- if (reader.NodeType == XmlNodeType.Element)
- {
- FetchDataFromXmlNode(reader, item);
- }
- else
- {
- reader.Read();
- }
- }
}
}
}
- catch (XmlException)
- {
+ }
+ catch (XmlException)
+ {
- }
}
}
}
@@ -920,6 +898,15 @@ namespace MediaBrowser.XbmcMetadata.Parsers
};
}
+ internal XmlReaderSettings GetXmlReaderSettings()
+ => new XmlReaderSettings()
+ {
+ ValidationType = ValidationType.None,
+ CheckCharacters = false,
+ IgnoreProcessingInstructions = true,
+ IgnoreComments = true
+ };
+
/// <summary>
/// Used to split names of comma or pipe delimeted genres and people
/// </summary>
@@ -935,19 +922,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
value = value.Trim().Trim(separator);
- return string.IsNullOrWhiteSpace(value) ? Array.Empty<string>() : Split(value, separator, StringSplitOptions.RemoveEmptyEntries);
- }
-
- /// <summary>
- /// Provides an additional overload for string.split
- /// </summary>
- /// <param name="val">The val.</param>
- /// <param name="separators">The separators.</param>
- /// <param name="options">The options.</param>
- /// <returns>System.String[][].</returns>
- private string[] Split(string val, char[] separators, StringSplitOptions options)
- {
- return val.Split(separators, options);
+ return string.IsNullOrWhiteSpace(value) ? Array.Empty<string>() : value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
}
}
}
diff --git a/MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs
index a8cb6ac40..7f4224076 100644
--- a/MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs
+++ b/MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs
@@ -8,8 +8,6 @@ using System.Xml;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Parsers
@@ -29,53 +27,48 @@ namespace MediaBrowser.XbmcMetadata.Parsers
protected override void Fetch(MetadataResult<Episode> item, string metadataFile, XmlReaderSettings settings, CancellationToken cancellationToken)
{
using (var fileStream = File.OpenRead(metadataFile))
+ using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
- {
- item.ResetPeople();
+ item.ResetPeople();
- var xml = streamReader.ReadToEnd();
+ var xml = streamReader.ReadToEnd();
- var srch = "</episodedetails>";
- var index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
+ var srch = "</episodedetails>";
+ var index = xml.IndexOf(srch, StringComparison.OrdinalIgnoreCase);
- if (index != -1)
- {
- xml = xml.Substring(0, index + srch.Length);
- }
+ if (index != -1)
+ {
+ xml = xml.Substring(0, index + srch.Length);
+ }
- // These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
- try
+ // These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
+ try
+ {
+ using (var stringReader = new StringReader(xml))
+ using (var reader = XmlReader.Create(stringReader, settings))
{
- using (var stringReader = new StringReader(xml))
+ reader.MoveToContent();
+ reader.Read();
+
+ // Loop through each element
+ while (!reader.EOF && reader.ReadState == ReadState.Interactive)
{
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(stringReader, settings))
+ cancellationToken.ThrowIfCancellationRequested();
+
+ if (reader.NodeType == XmlNodeType.Element)
+ {
+ FetchDataFromXmlNode(reader, item);
+ }
+ else
{
- reader.MoveToContent();
reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- cancellationToken.ThrowIfCancellationRequested();
-
- if (reader.NodeType == XmlNodeType.Element)
- {
- FetchDataFromXmlNode(reader, item);
- }
- else
- {
- reader.Read();
- }
- }
}
}
}
- catch (XmlException)
- {
+ }
+ catch (XmlException)
+ {
- }
}
}
}
@@ -220,7 +213,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
}
- public EpisodeNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(logger, config, providerManager, fileSystem, xmlReaderSettingsFactory)
+ public EpisodeNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager)
+ : base(logger, config, providerManager)
{
}
}
diff --git a/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs
index a3e48d30d..0c4de9f33 100644
--- a/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs
+++ b/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs
@@ -7,8 +7,6 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Parsers
@@ -126,14 +124,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
// These are not going to be valid xml so no sense in causing the provider to fail and spamming the log with exceptions
try
{
- var settings = XmlReaderSettingsFactory.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
-
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(stringReader, settings))
+ using (var reader = XmlReader.Create(stringReader, GetXmlReaderSettings()))
{
reader.MoveToContent();
reader.Read();
@@ -167,7 +158,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
}
- public MovieNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(logger, config, providerManager, fileSystem, xmlReaderSettingsFactory)
+ public MovieNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager)
+ : base(logger, config, providerManager)
{
}
}
diff --git a/MediaBrowser.XbmcMetadata/Parsers/SeasonNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/SeasonNfoParser.cs
index 17f36d82d..882f3a9d3 100644
--- a/MediaBrowser.XbmcMetadata/Parsers/SeasonNfoParser.cs
+++ b/MediaBrowser.XbmcMetadata/Parsers/SeasonNfoParser.cs
@@ -3,8 +3,6 @@ using System.Xml;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Parsers
@@ -42,7 +40,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
}
- public SeasonNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(logger, config, providerManager, fileSystem, xmlReaderSettingsFactory)
+ public SeasonNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager)
+ : base(logger, config, providerManager)
{
}
}
diff --git a/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs
index 700656b65..b0f25ae64 100644
--- a/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs
+++ b/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs
@@ -5,8 +5,6 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Parsers
@@ -94,7 +92,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers
}
}
- public SeriesNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(logger, config, providerManager, fileSystem, xmlReaderSettingsFactory)
+ public SeriesNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager)
+ : base(logger, config, providerManager)
{
}
}
diff --git a/MediaBrowser.XbmcMetadata/Properties/AssemblyInfo.cs b/MediaBrowser.XbmcMetadata/Properties/AssemblyInfo.cs
index 11e513f1b..b3e2f2717 100644
--- a/MediaBrowser.XbmcMetadata/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.XbmcMetadata/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/MediaBrowser.XbmcMetadata/Providers/AlbumNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/AlbumNfoProvider.cs
index 1e22bf358..6e6a22794 100644
--- a/MediaBrowser.XbmcMetadata/Providers/AlbumNfoProvider.cs
+++ b/MediaBrowser.XbmcMetadata/Providers/AlbumNfoProvider.cs
@@ -4,7 +4,6 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.XbmcMetadata.Parsers;
using Microsoft.Extensions.Logging;
@@ -15,20 +14,18 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
- public AlbumNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public AlbumNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<MusicAlbum> result, string path, CancellationToken cancellationToken)
{
- new BaseNfoParser<MusicAlbum>(_logger, _config, _providerManager, FileSystem, XmlReaderSettingsFactory).Fetch(result, path, cancellationToken);
+ new BaseNfoParser<MusicAlbum>(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)
diff --git a/MediaBrowser.XbmcMetadata/Providers/ArtistNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/ArtistNfoProvider.cs
index ad811b475..20abfc7f3 100644
--- a/MediaBrowser.XbmcMetadata/Providers/ArtistNfoProvider.cs
+++ b/MediaBrowser.XbmcMetadata/Providers/ArtistNfoProvider.cs
@@ -4,7 +4,6 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.XbmcMetadata.Parsers;
using Microsoft.Extensions.Logging;
@@ -15,20 +14,18 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
- public ArtistNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public ArtistNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<MusicArtist> result, string path, CancellationToken cancellationToken)
{
- new BaseNfoParser<MusicArtist>(_logger, _config, _providerManager, FileSystem, XmlReaderSettingsFactory).Fetch(result, path, cancellationToken);
+ new BaseNfoParser<MusicArtist>(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)
diff --git a/MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs
index 94f104f61..28a0514d5 100644
--- a/MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs
+++ b/MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs
@@ -4,7 +4,6 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.XbmcMetadata.Parsers;
using MediaBrowser.XbmcMetadata.Savers;
using Microsoft.Extensions.Logging;
@@ -17,15 +16,13 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
- public BaseVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public BaseVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<T> result, string path, CancellationToken cancellationToken)
@@ -34,7 +31,7 @@ namespace MediaBrowser.XbmcMetadata.Providers
{
Item = result.Item
};
- new MovieNfoParser(_logger, _config, _providerManager, FileSystem, XmlReaderSettingsFactory).Fetch(tmpItem, path, cancellationToken);
+ new MovieNfoParser(_logger, _config, _providerManager).Fetch(tmpItem, path, cancellationToken);
result.Item = (T)tmpItem.Item;
result.People = tmpItem.People;
diff --git a/MediaBrowser.XbmcMetadata/Providers/EpisodeNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/EpisodeNfoProvider.cs
index bf05f0f38..f90f283cf 100644
--- a/MediaBrowser.XbmcMetadata/Providers/EpisodeNfoProvider.cs
+++ b/MediaBrowser.XbmcMetadata/Providers/EpisodeNfoProvider.cs
@@ -5,7 +5,6 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.XbmcMetadata.Parsers;
using Microsoft.Extensions.Logging;
@@ -16,22 +15,20 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
- public EpisodeNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public EpisodeNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<Episode> result, string path, CancellationToken cancellationToken)
{
var images = new List<LocalImageInfo>();
- new EpisodeNfoParser(_logger, _config, _providerManager, FileSystem, XmlReaderSettingsFactory).Fetch(result, images, path, cancellationToken);
+ new EpisodeNfoParser(_logger, _config, _providerManager).Fetch(result, images, path, cancellationToken);
result.Images = images;
}
diff --git a/MediaBrowser.XbmcMetadata/Providers/MovieNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/MovieNfoProvider.cs
index 77b3b3781..d21164c02 100644
--- a/MediaBrowser.XbmcMetadata/Providers/MovieNfoProvider.cs
+++ b/MediaBrowser.XbmcMetadata/Providers/MovieNfoProvider.cs
@@ -3,28 +3,30 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Providers
{
public class MovieNfoProvider : BaseVideoNfoProvider<Movie>
{
- public MovieNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, logger, config, providerManager, xmlReaderSettingsFactory)
+ public MovieNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
+ : base(fileSystem, logger, config, providerManager)
{
}
}
public class MusicVideoNfoProvider : BaseVideoNfoProvider<MusicVideo>
{
- public MusicVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, logger, config, providerManager, xmlReaderSettingsFactory)
+ public MusicVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
+ : base(fileSystem, logger, config, providerManager)
{
}
}
public class VideoNfoProvider : BaseVideoNfoProvider<Video>
{
- public VideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, logger, config, providerManager, xmlReaderSettingsFactory)
+ public VideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
+ : base(fileSystem, logger, config, providerManager)
{
}
}
diff --git a/MediaBrowser.XbmcMetadata/Providers/SeasonNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/SeasonNfoProvider.cs
index e669a86a3..0ebc30293 100644
--- a/MediaBrowser.XbmcMetadata/Providers/SeasonNfoProvider.cs
+++ b/MediaBrowser.XbmcMetadata/Providers/SeasonNfoProvider.cs
@@ -4,7 +4,6 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.XbmcMetadata.Parsers;
using Microsoft.Extensions.Logging;
@@ -15,26 +14,22 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
- public SeasonNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public SeasonNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<Season> result, string path, CancellationToken cancellationToken)
{
- new SeasonNfoParser(_logger, _config, _providerManager, FileSystem, XmlReaderSettingsFactory).Fetch(result, path, cancellationToken);
+ new SeasonNfoParser(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)
- {
- return directoryService.GetFile(Path.Combine(info.Path, "season.nfo"));
- }
+ => directoryService.GetFile(Path.Combine(info.Path, "season.nfo"));
}
}
diff --git a/MediaBrowser.XbmcMetadata/Providers/SeriesNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/SeriesNfoProvider.cs
index d90a65535..19ac3dc97 100644
--- a/MediaBrowser.XbmcMetadata/Providers/SeriesNfoProvider.cs
+++ b/MediaBrowser.XbmcMetadata/Providers/SeriesNfoProvider.cs
@@ -4,7 +4,6 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.XbmcMetadata.Parsers;
using Microsoft.Extensions.Logging;
@@ -15,27 +14,21 @@ namespace MediaBrowser.XbmcMetadata.Providers
private readonly ILogger _logger;
private readonly IConfigurationManager _config;
private readonly IProviderManager _providerManager;
- private readonly IFileSystem _fileSystem;
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
- public SeriesNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem1, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ public SeriesNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_config = config;
_providerManager = providerManager;
- _fileSystem = fileSystem1;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
}
protected override void Fetch(MetadataResult<Series> result, string path, CancellationToken cancellationToken)
{
- new SeriesNfoParser(_logger, _config, _providerManager, _fileSystem, XmlReaderSettingsFactory).Fetch(result, path, cancellationToken);
+ new SeriesNfoParser(_logger, _config, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)
- {
- return directoryService.GetFile(Path.Combine(info.Path, "tvshow.nfo"));
- }
+ => directoryService.GetFile(Path.Combine(info.Path, "tvshow.nfo"));
}
}
diff --git a/MediaBrowser.XbmcMetadata/Savers/AlbumNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/AlbumNfoSaver.cs
index 79f119d7f..430b93199 100644
--- a/MediaBrowser.XbmcMetadata/Savers/AlbumNfoSaver.cs
+++ b/MediaBrowser.XbmcMetadata/Savers/AlbumNfoSaver.cs
@@ -9,7 +9,6 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Savers
@@ -94,7 +93,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
return list;
}
- public AlbumNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
+ public AlbumNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger)
+ : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
}
diff --git a/MediaBrowser.XbmcMetadata/Savers/ArtistNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/ArtistNfoSaver.cs
index f01132fd9..0876db5c1 100644
--- a/MediaBrowser.XbmcMetadata/Savers/ArtistNfoSaver.cs
+++ b/MediaBrowser.XbmcMetadata/Savers/ArtistNfoSaver.cs
@@ -7,7 +7,6 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.XbmcMetadata.Configuration;
using Microsoft.Extensions.Logging;
@@ -85,7 +84,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
return list;
}
- public ArtistNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
+ public ArtistNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger)
+ : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
}
diff --git a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs
index 4925c7cd1..3ae72c472 100644
--- a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs
+++ b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs
@@ -18,7 +18,6 @@ using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.XbmcMetadata.Configuration;
using Microsoft.Extensions.Logging;
@@ -97,10 +96,15 @@ namespace MediaBrowser.XbmcMetadata.Savers
}.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
- protected BaseNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory)
+ protected BaseNfoSaver(
+ IFileSystem fileSystem,
+ IServerConfigurationManager configurationManager,
+ ILibraryManager libraryManager,
+ IUserManager userManager,
+ IUserDataManager userDataManager,
+ ILogger logger)
{
Logger = logger;
- XmlReaderSettingsFactory = xmlReaderSettingsFactory;
UserDataManager = userDataManager;
UserManager = userManager;
LibraryManager = libraryManager;
@@ -114,7 +118,6 @@ namespace MediaBrowser.XbmcMetadata.Savers
protected IUserManager UserManager { get; private set; }
protected IUserDataManager UserDataManager { get; private set; }
protected ILogger Logger { get; private set; }
- protected IXmlReaderSettingsFactory XmlReaderSettingsFactory { get; private set; }
protected ItemUpdateType MinimumUpdateType
{
@@ -961,52 +964,49 @@ namespace MediaBrowser.XbmcMetadata.Savers
private void AddCustomTags(string path, List<string> xmlTagsUsed, XmlWriter writer, ILogger logger, IFileSystem fileSystem)
{
- var settings = XmlReaderSettingsFactory.Create(false);
-
- settings.CheckCharacters = false;
- settings.IgnoreProcessingInstructions = true;
- settings.IgnoreComments = true;
+ var settings = new XmlReaderSettings()
+ {
+ ValidationType = ValidationType.None,
+ CheckCharacters = false,
+ IgnoreProcessingInstructions = true,
+ IgnoreComments = true
+ };
using (var fileStream = File.OpenRead(path))
+ using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
+ using (var reader = XmlReader.Create(streamReader, settings))
{
- using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
+ try
+ {
+ reader.MoveToContent();
+ }
+ catch (Exception ex)
{
- // Use XmlReader for best performance
- using (var reader = XmlReader.Create(streamReader, settings))
+ logger.LogError(ex, "Error reading existing xml tags from {path}.", path);
+ return;
+ }
+
+ reader.Read();
+
+ // Loop through each element
+ while (!reader.EOF && reader.ReadState == ReadState.Interactive)
+ {
+ if (reader.NodeType == XmlNodeType.Element)
{
- try
+ var name = reader.Name;
+
+ if (!CommonTags.ContainsKey(name) && !xmlTagsUsed.Contains(name, StringComparer.OrdinalIgnoreCase))
{
- reader.MoveToContent();
+ writer.WriteNode(reader, false);
}
- catch (Exception ex)
+ else
{
- logger.LogError(ex, "Error reading existing xml tags from {path}.", path);
- return;
+ reader.Skip();
}
-
+ }
+ else
+ {
reader.Read();
-
- // Loop through each element
- while (!reader.EOF && reader.ReadState == ReadState.Interactive)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- var name = reader.Name;
-
- if (!CommonTags.ContainsKey(name) && !xmlTagsUsed.Contains(name, StringComparer.OrdinalIgnoreCase))
- {
- writer.WriteNode(reader, false);
- }
- else
- {
- reader.Skip();
- }
- }
- else
- {
- reader.Read();
- }
- }
}
}
}
diff --git a/MediaBrowser.XbmcMetadata/Savers/EpisodeNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/EpisodeNfoSaver.cs
index 05a7a44f9..cf1b6468a 100644
--- a/MediaBrowser.XbmcMetadata/Savers/EpisodeNfoSaver.cs
+++ b/MediaBrowser.XbmcMetadata/Savers/EpisodeNfoSaver.cs
@@ -7,7 +7,6 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using MediaBrowser.XbmcMetadata.Configuration;
using Microsoft.Extensions.Logging;
@@ -109,7 +108,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
return list;
}
- public EpisodeNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
+ public EpisodeNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger)
+ : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
}
diff --git a/MediaBrowser.XbmcMetadata/Savers/MovieNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/MovieNfoSaver.cs
index b3bbe539a..5e0eff029 100644
--- a/MediaBrowser.XbmcMetadata/Savers/MovieNfoSaver.cs
+++ b/MediaBrowser.XbmcMetadata/Savers/MovieNfoSaver.cs
@@ -9,7 +9,6 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Savers
@@ -129,7 +128,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
return list;
}
- public MovieNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
+ public MovieNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger)
+ : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
}
diff --git a/MediaBrowser.XbmcMetadata/Savers/SeasonNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/SeasonNfoSaver.cs
index 5246bec02..aa8d3e96c 100644
--- a/MediaBrowser.XbmcMetadata/Savers/SeasonNfoSaver.cs
+++ b/MediaBrowser.XbmcMetadata/Savers/SeasonNfoSaver.cs
@@ -7,7 +7,6 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Savers
@@ -66,9 +65,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
ILibraryManager libraryManager,
IUserManager userManager,
IUserDataManager userDataManager,
- ILogger logger,
- IXmlReaderSettingsFactory xmlReaderSettingsFactory)
- : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
+ ILogger logger)
+ : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
}
diff --git a/MediaBrowser.XbmcMetadata/Savers/SeriesNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/SeriesNfoSaver.cs
index 0ef267a1d..b0fc8c368 100644
--- a/MediaBrowser.XbmcMetadata/Savers/SeriesNfoSaver.cs
+++ b/MediaBrowser.XbmcMetadata/Savers/SeriesNfoSaver.cs
@@ -7,7 +7,6 @@ using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Xml;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.XbmcMetadata.Savers
@@ -83,7 +82,8 @@ namespace MediaBrowser.XbmcMetadata.Savers
return list;
}
- public SeriesNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger, IXmlReaderSettingsFactory xmlReaderSettingsFactory) : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger, xmlReaderSettingsFactory)
+ public SeriesNfoSaver(IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger)
+ : base(fileSystem, configurationManager, libraryManager, userManager, userDataManager, logger)
{
}
}
diff --git a/MediaBrowser.sln b/MediaBrowser.sln
index 62ae58d73..3ed86d65c 100644
--- a/MediaBrowser.sln
+++ b/MediaBrowser.sln
@@ -1,4 +1,5 @@
-Microsoft Visual Studio Solution File, Format Version 12.00
+
+Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.3
MinimumVisualStudioVersion = 10.0.40219.1
@@ -14,8 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediaBrowser.WebDashboard",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediaBrowser.Providers", "MediaBrowser.Providers\MediaBrowser.Providers.csproj", "{442B5058-DCAF-4263-BB6A-F21E31120A1B}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenSubtitlesHandler", "OpenSubtitlesHandler\OpenSubtitlesHandler.csproj", "{4A4402D4-E910-443B-B8FC-2C18286A2CA0}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediaBrowser.XbmcMetadata", "MediaBrowser.XbmcMetadata\MediaBrowser.XbmcMetadata.csproj", "{23499896-B135-4527-8574-C26E926EA99E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediaBrowser.LocalMetadata", "MediaBrowser.LocalMetadata\MediaBrowser.LocalMetadata.csproj", "{7EF9F3E0-697D-42F3-A08F-19DEB5F84392}"
@@ -36,8 +35,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Emby.Dlna", "Emby.Dlna\Emby
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.Nat", "Mono.Nat\Mono.Nat.csproj", "{CB7F2326-6497-4A3D-BA03-48513B17A7BE}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SocketHttpListener", "SocketHttpListener\SocketHttpListener.csproj", "{1D74413B-E7CF-455B-B021-F52BDF881542}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Emby.Notifications", "Emby.Notifications\Emby.Notifications.csproj", "{2E030C33-6923-4530-9E54-FA29FA6AD1A9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Emby.Naming", "Emby.Naming\Emby.Naming.csproj", "{E5AF7B26-2239-4CE0-B477-0AA2018EDAA2}"
@@ -56,7 +53,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
SharedVersion.cs = SharedVersion.cs
EndProjectSection
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Drawing.Skia", "Jellyfin.Drawing.Skia\Jellyfin.Drawing.Skia.csproj", "{154872D9-6C12-4007-96E3-8F70A58386CE}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jellyfin.Drawing.Skia", "Jellyfin.Drawing.Skia\Jellyfin.Drawing.Skia.csproj", "{154872D9-6C12-4007-96E3-8F70A58386CE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -132,10 +129,6 @@ Global
{CB7F2326-6497-4A3D-BA03-48513B17A7BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB7F2326-6497-4A3D-BA03-48513B17A7BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB7F2326-6497-4A3D-BA03-48513B17A7BE}.Release|Any CPU.Build.0 = Release|Any CPU
- {1D74413B-E7CF-455B-B021-F52BDF881542}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {1D74413B-E7CF-455B-B021-F52BDF881542}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {1D74413B-E7CF-455B-B021-F52BDF881542}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {1D74413B-E7CF-455B-B021-F52BDF881542}.Release|Any CPU.Build.0 = Release|Any CPU
{2E030C33-6923-4530-9E54-FA29FA6AD1A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E030C33-6923-4530-9E54-FA29FA6AD1A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E030C33-6923-4530-9E54-FA29FA6AD1A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -185,7 +178,7 @@ Global
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0
$0.StandardHeader = $1
- $1.Text = @### This header should be used to start new files.\n### It provides an explicit per-file license reference that should be present on all new files.\n### To use this header, delete these lines and the following empty line, modify <filename> to\n### the proper full path, and then add new code following the header and a single empty line.\n\n// ${FileName}\n// Part of the Jellyfin project (https://jellyfin.media)\n//\n// All copyright belongs to the Jellyfin contributors; a full list can\n// be found in the file CONTRIBUTORS.md\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, version 2.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n
+ $1.IncludeInNewFiles = False
$0.DotNetNamingPolicy = $2
$2.DirectoryNamespaceAssociation = PrefixedHierarchical
EndGlobalSection
diff --git a/Mono.Nat/Properties/AssemblyInfo.cs b/Mono.Nat/Properties/AssemblyInfo.cs
index ea1c9dee6..dc47f2ffe 100644
--- a/Mono.Nat/Properties/AssemblyInfo.cs
+++ b/Mono.Nat/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2006 Alan McGovern. Copyright © 2007 Ben Motmans. Code releases unde the MIT license. Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2006 Alan McGovern. Copyright © 2007 Ben Motmans. Code releases under the MIT license. Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/OpenSubtitlesHandler/Console/OSHConsole.cs b/OpenSubtitlesHandler/Console/OSHConsole.cs
deleted file mode 100644
index 396b28cbc..000000000
--- a/OpenSubtitlesHandler/Console/OSHConsole.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System;
-
-namespace OpenSubtitlesHandler.Console
-{
- public class OSHConsole
- {
- /// <summary>
- /// Write line to the console and raise the "LineWritten" event
- /// </summary>
- ///
- /// <param name="text">The debug line</param>
- /// <param name="code">The status</param>
- public static void WriteLine(string text, DebugCode code = DebugCode.None)
- {
- if (LineWritten != null)
- LineWritten(null, new DebugEventArgs(text, code));
- }
- /// <summary>
- /// Update the last written line
- /// </summary>
- /// <param name="text">The debug line</param>
- /// <param name="code">The status</param>
- public static void UpdateLine(string text, DebugCode code = DebugCode.None)
- {
- if (UpdateLastLine != null)
- UpdateLastLine(null, new DebugEventArgs(text, code));
- }
-
- public static event EventHandler<DebugEventArgs> LineWritten;
- public static event EventHandler<DebugEventArgs> UpdateLastLine;
- }
- public enum DebugCode
- {
- None,
- Good,
- Warning,
- Error
- }
- /// <summary>
- /// Console Debug Args
- /// </summary>
- public class DebugEventArgs : EventArgs
- {
- public DebugCode Code { get; private set; }
- public string Text { get; private set; }
-
- /// <summary>
- /// Console Debug Args
- /// </summary>
- /// <param name="text">The debug line</param>
- /// <param name="code">The status</param>
- public DebugEventArgs(string text, DebugCode code)
- {
- this.Text = text;
- this.Code = code;
- }
- }
- public struct DebugLine
- {
- public DebugLine(string debugLine, DebugCode status)
- {
- this.debugLine = debugLine;
- this.status = status;
- }
- string debugLine;
- DebugCode status;
-
- public string Text
- { get { return debugLine; } set { debugLine = value; } }
- public DebugCode Code
- { get { return status; } set { status = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/Interfaces/IMethodResponse.cs b/OpenSubtitlesHandler/Interfaces/IMethodResponse.cs
deleted file mode 100644
index 3450beff5..000000000
--- a/OpenSubtitlesHandler/Interfaces/IMethodResponse.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-using System;
-
-namespace OpenSubtitlesHandler
-{
- /// <summary>
- /// When you call a method to communicate with OpenSubtitles server, that method should return this response with the reuired information.
- /// </summary>
- public abstract class IMethodResponse
- {
- public IMethodResponse() { LoadAttributes(); }
- public IMethodResponse(string name, string message)
- {
- this.name = name;
- this.message = message;
- }
- protected string name;
- protected string message;
- protected double seconds;
- protected string status;
-
- protected void LoadAttributes()
- {
- //foreach (Attribute attr in Attribute.GetCustomAttributes(this.GetType()))
- //{
- // if (attr.GetType() == typeof(MethodResponseDescription))
- // {
- // this.name = ((MethodResponseDescription)attr).Name;
- // this.message = ((MethodResponseDescription)attr).Message;
- // break;
- // }
- //}
- }
-
- [Description("The name of this response"), Category("MethodResponse")]
- public virtual string Name { get { return name; } set { name = value; } }
- [Description("The message about this response"), Category("MethodResponse")]
- public virtual string Message { get { return message; } set { message = value; } }
- [Description("Time taken to execute this command on server"), Category("MethodResponse")]
- public double Seconds { get { return seconds; } set { seconds = value; } }
- [Description("The status"), Category("MethodResponse")]
- public string Status { get { return status; } set { status = value; } }
- }
-
- public class DescriptionAttribute : Attribute
- {
- public DescriptionAttribute(string text) { }
- }
-
- public class CategoryAttribute : Attribute
- {
- public CategoryAttribute(string text) { }
- }
-}
diff --git a/OpenSubtitlesHandler/Interfaces/MethodResponseAttr.cs b/OpenSubtitlesHandler/Interfaces/MethodResponseAttr.cs
deleted file mode 100644
index a7e49032d..000000000
--- a/OpenSubtitlesHandler/Interfaces/MethodResponseAttr.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-using System;
-
-namespace OpenSubtitlesHandler
-{
- /// <summary>
- /// Attributes to describe a method response object.
- /// </summary>
- public class MethodResponseDescription : Attribute
- {
- public MethodResponseDescription(string name, string message)
- {
- this.name = name;
- this.message = message;
- }
-
- private string name;
- private string message;
-
- public string Name { get { return name; } set { name = value; } }
- public string Message { get { return message; } set { message = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/Languages/DetectLanguageResult.cs b/OpenSubtitlesHandler/Languages/DetectLanguageResult.cs
deleted file mode 100644
index 3e72dc65c..000000000
--- a/OpenSubtitlesHandler/Languages/DetectLanguageResult.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-namespace OpenSubtitlesHandler
-{
- public struct DetectLanguageResult
- {
- private string inputSample;
- private string languageID;
-
- public string LanguageID
- { get { return languageID; } set { languageID = value; } }
- public string InputSample
- { get { return inputSample; } set { inputSample = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseAddComment.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseAddComment.cs
deleted file mode 100644
index 03d0337d4..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseAddComment.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("AddComment method response",
- "AddComment method response hold all expected values from server.")]
- public class MethodResponseAddComment : IMethodResponse
- {
- public MethodResponseAddComment()
- : base()
- { }
- public MethodResponseAddComment(string name, string message)
- : base(name, message)
- { }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseAddRequest.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseAddRequest.cs
deleted file mode 100644
index b996043c2..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseAddRequest.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("AddRequest method response",
- "AddRequest method response hold all expected values from server.")]
- public class MethodResponseAddRequest : IMethodResponse
- {
- public MethodResponseAddRequest()
- : base()
- { }
- public MethodResponseAddRequest(string name, string message)
- : base(name, message)
- { }
- private string _request_url;
-
- public string request_url { get { return _request_url; } set { _request_url = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseAutoUpdate.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseAutoUpdate.cs
deleted file mode 100644
index 6ee14f1f8..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseAutoUpdate.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("AutoUpdate method response",
- "AutoUpdate method response hold all expected values from server.")]
- public class MethodResponseAutoUpdate : IMethodResponse
- {
- public MethodResponseAutoUpdate()
- : base()
- { }
- public MethodResponseAutoUpdate(string name, string message)
- : base(name, message)
- { }
-
- private string _version;
- private string _url_windows;
- private string _comments;
- private string _url_linux;
- /// <summary>
- /// Latest application version
- /// </summary>
- [Description("Latest application version"), Category("AutoUpdate")]
- public string version { get { return _version; } set { _version = value; } }
- /// <summary>
- /// Download URL for Windows version
- /// </summary>
- [Description("Download URL for Windows version"), Category("AutoUpdate")]
- public string url_windows { get { return _url_windows; } set { _url_windows = value; } }
- /// <summary>
- /// Application changelog and other comments
- /// </summary>
- [Description("Application changelog and other comments"), Category("AutoUpdate")]
- public string comments { get { return _comments; } set { _comments = value; } }
- /// <summary>
- /// Download URL for Linux version
- /// </summary>
- [Description("Download URL for Linux version"), Category("AutoUpdate")]
- public string url_linux { get { return _url_linux; } set { _url_linux = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash.cs
deleted file mode 100644
index 4bb326244..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("CheckMovieHash method response",
- "CheckMovieHash method response hold all expected values from server.")]
- public class MethodResponseCheckMovieHash : IMethodResponse
- {
- public MethodResponseCheckMovieHash()
- : base()
- { }
- public MethodResponseCheckMovieHash(string name, string message)
- : base(name, message)
- { }
- private List<CheckMovieHashResult> results = new List<CheckMovieHashResult>();
- public List<CheckMovieHashResult> Results
- { get { return results; } set { results = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash2.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash2.cs
deleted file mode 100644
index 72b4c3b15..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash2.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("CheckMovieHash2 method response",
- "CheckMovieHash2 method response hold all expected values from server.")]
- public class MethodResponseCheckMovieHash2 : IMethodResponse
- {
- public MethodResponseCheckMovieHash2()
- : base()
- { }
- public MethodResponseCheckMovieHash2(string name, string message)
- : base(name, message)
- { }
- private List<CheckMovieHash2Result> results = new List<CheckMovieHash2Result>();
- public List<CheckMovieHash2Result> Results
- { get { return results; } set { results = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckSubHash.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckSubHash.cs
deleted file mode 100644
index 04e287ea7..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckSubHash.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("CheckSubHash method response",
- "CheckSubHash method response hold all expected values from server.")]
- public class MethodResponseCheckSubHash : IMethodResponse
- {
- public MethodResponseCheckSubHash()
- : base()
- { }
- public MethodResponseCheckSubHash(string name, string message)
- : base(name, message)
- { }
- private List<CheckSubHashResult> results = new List<CheckSubHashResult>();
-
- public List<CheckSubHashResult> Results { get { return results; } set { results = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseDetectLanguage.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseDetectLanguage.cs
deleted file mode 100644
index 6bf21d50e..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseDetectLanguage.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-using System.Collections.Generic;
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("DetectLanguage method response",
- "DetectLanguage method response hold all expected values from server.")]
- public class MethodResponseDetectLanguage : IMethodResponse
- {
- public MethodResponseDetectLanguage()
- : base()
- { }
- public MethodResponseDetectLanguage(string name, string message)
- : base(name, message)
- { }
- private List<DetectLanguageResult> results = new List<DetectLanguageResult>();
-
- public List<DetectLanguageResult> Results
- { get { return results; } set { results = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseError.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseError.cs
deleted file mode 100644
index 7ed807067..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseError.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- /// <summary>
- /// Response that can be used for general error like internet connection fail.
- /// </summary>
- [MethodResponseDescription("Error method response",
- "Error method response that describes error that occured")]
- public class MethodResponseError : IMethodResponse
- {
- public MethodResponseError()
- : base()
- { }
- public MethodResponseError(string name, string message)
- : base(name, message)
- { }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetAvailableTranslations.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetAvailableTranslations.cs
deleted file mode 100644
index 91803f4b3..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetAvailableTranslations.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("GetAvailableTranslations method response",
- "GetAvailableTranslations method response hold all expected values from server.")]
- public class MethodResponseGetAvailableTranslations : IMethodResponse
- {
- public MethodResponseGetAvailableTranslations()
- : base()
- { }
- public MethodResponseGetAvailableTranslations(string name, string message)
- : base(name, message)
- { }
- private List<GetAvailableTranslationsResult> results = new List<GetAvailableTranslationsResult>();
- public List<GetAvailableTranslationsResult> Results { get { return results; } set { results = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetComments.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetComments.cs
deleted file mode 100644
index 421e1783b..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetComments.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("GetComments method response",
- "GetComments method response hold all expected values from server.")]
- public class MethodResponseGetComments : IMethodResponse
- {
- public MethodResponseGetComments()
- : base()
- { }
- public MethodResponseGetComments(string name, string message)
- : base(name, message)
- { }
- private List<GetCommentsResult> results = new List<GetCommentsResult>();
-
- public List<GetCommentsResult> Results
- { get { return results; } set { results = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetSubLanguages.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetSubLanguages.cs
deleted file mode 100644
index 905b87c91..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetSubLanguages.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("GetSubLanguages method response",
- "GetSubLanguages method response hold all expected values from server.")]
- public class MethodResponseGetSubLanguages : IMethodResponse
- {
- public MethodResponseGetSubLanguages()
- : base()
- { }
- public MethodResponseGetSubLanguages(string name, string message)
- : base(name, message)
- { }
- private List<SubtitleLanguage> languages = new List<SubtitleLanguage>();
-
- public List<SubtitleLanguage> Languages
- { get { return languages; } set { languages = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetTranslation.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetTranslation.cs
deleted file mode 100644
index f008f7711..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetTranslation.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("GetTranslation method response",
- "GetTranslation method response hold all expected values from server.")]
- public class MethodResponseGetTranslation : IMethodResponse
- {
- public MethodResponseGetTranslation()
- : base()
- { }
- public MethodResponseGetTranslation(string name, string message)
- : base(name, message)
- { }
- private string data;
-
- public string ContentData { get { return data; } set { data = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovie.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovie.cs
deleted file mode 100644
index 1148b5f47..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovie.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("InsertMovie method response",
- "InsertMovie method response hold all expected values from server.")]
- public class MethodResponseInsertMovie : IMethodResponse
- {
- public MethodResponseInsertMovie()
- : base()
- { }
- public MethodResponseInsertMovie(string name, string message)
- : base(name, message)
- { }
- private string _ID;
- public string ID
- { get { return _ID; } set { _ID = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovieHash.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovieHash.cs
deleted file mode 100644
index 74f52837c..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovieHash.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-using System.Collections.Generic;
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("InsertMovieHash method response",
- "InsertMovieHash method response hold all expected values from server.")]
- public class MethodResponseInsertMovieHash : IMethodResponse
- {
- public MethodResponseInsertMovieHash()
- : base()
- { }
- public MethodResponseInsertMovieHash(string name, string message)
- : base(name, message)
- { }
- private List<string> _accepted_moviehashes = new List<string>();
- private List<string> _new_imdbs = new List<string>();
-
- public List<string> accepted_moviehashes { get { return _accepted_moviehashes; } set { _accepted_moviehashes = value; } }
- public List<string> new_imdbs { get { return _new_imdbs; } set { _new_imdbs = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseLogIn.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseLogIn.cs
deleted file mode 100644
index 44d294382..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseLogIn.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- /// <summary>
- /// Response can be used for log in/out operation.
- /// </summary>
- [MethodResponseDescription("LogIn method response",
- "LogIn method response hold all expected values from server.")]
- public class MethodResponseLogIn : IMethodResponse
- {
- public MethodResponseLogIn()
- : base()
- { }
- public MethodResponseLogIn(string name, string message)
- : base(name, message)
- { }
- private string token;
-
- public string Token { get { return token; } set { token = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieDetails.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieDetails.cs
deleted file mode 100644
index 6126c0053..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieDetails.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("MovieDetails method response",
- "MovieDetails method response hold all expected values from server.")]
- public class MethodResponseMovieDetails : IMethodResponse
- {
- public MethodResponseMovieDetails()
- : base()
- { }
- public MethodResponseMovieDetails(string name, string message)
- : base(name, message)
- { }
- // Details
- private string id;
- private string title;
- private string year;
- private string coverLink;
-
- private string duration;
- private string tagline;
- private string plot;
- private string goofs;
- private string trivia;
- private List<string> cast = new List<string>();
- private List<string> directors = new List<string>();
- private List<string> writers = new List<string>();
- private List<string> awards = new List<string>();
- private List<string> genres = new List<string>();
- private List<string> country = new List<string>();
- private List<string> language = new List<string>();
- private List<string> certification = new List<string>();
-
- // Details
- public string ID { get { return id; } set { id = value; } }
- public string Title { get { return title; } set { title = value; } }
- public string Year { get { return year; } set { year = value; } }
- public string CoverLink { get { return coverLink; } set { coverLink = value; } }
- public string Duration { get { return duration; } set { duration = value; } }
- public string Tagline { get { return tagline; } set { tagline = value; } }
- public string Plot { get { return plot; } set { plot = value; } }
- public string Goofs { get { return goofs; } set { goofs = value; } }
- public string Trivia { get { return trivia; } set { trivia = value; } }
- public List<string> Cast { get { return cast; } set { cast = value; } }
- public List<string> Directors { get { return directors; } set { directors = value; } }
- public List<string> Writers { get { return writers; } set { writers = value; } }
- public List<string> Genres { get { return genres; } set { genres = value; } }
- public List<string> Awards { get { return awards; } set { awards = value; } }
- public List<string> Country { get { return country; } set { country = value; } }
- public List<string> Language { get { return language; } set { language = value; } }
- public List<string> Certification { get { return certification; } set { certification = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieSearch.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieSearch.cs
deleted file mode 100644
index 93cd70346..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieSearch.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("MovieSearch method response",
- "MovieSearch method response hold all expected values from server.")]
- public class MethodResponseMovieSearch : IMethodResponse
- {
- public MethodResponseMovieSearch()
- : base()
- {
- results = new List<MovieSearchResult>();
- }
- public MethodResponseMovieSearch(string name, string message)
- : base(name, message)
- {
- results = new List<MovieSearchResult>();
- }
- private List<MovieSearchResult> results;
-
- public List<MovieSearchResult> Results
- { get { return results; } set { results = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseNoOperation.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseNoOperation.cs
deleted file mode 100644
index 02a9993cb..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseNoOperation.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("NoOperation method response",
- "NoOperation method response hold all expected values from server.")]
- public class MethodResponseNoOperation : IMethodResponse
- {
- public MethodResponseNoOperation()
- : base() { }
- public MethodResponseNoOperation(string name, string message)
- : base(name, message)
- { }
-
- private string _global_wrh_download_limit;
- private string _client_ip;
- private string _limit_check_by;
- private string _client_24h_download_count;
- private string _client_downlaod_quota;
- private string _client_24h_download_limit;
-
- public string global_wrh_download_limit
- { get { return _global_wrh_download_limit; } set { _global_wrh_download_limit = value; } }
- public string client_ip
- { get { return _client_ip; } set { _client_ip = value; } }
- public string limit_check_by
- { get { return _limit_check_by; } set { _limit_check_by = value; } }
- public string client_24h_download_count
- { get { return _client_24h_download_count; } set { _client_24h_download_count = value; } }
- public string client_downlaod_quota
- { get { return _client_downlaod_quota; } set { _client_downlaod_quota = value; } }
- public string client_24h_download_limit
- { get { return _client_24h_download_limit; } set { _client_24h_download_limit = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongImdbMovie.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongImdbMovie.cs
deleted file mode 100644
index 391fec58a..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongImdbMovie.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("ReportWrongImdbMovie method response",
- "ReportWrongImdbMovie method response hold all expected values from server.")]
- public class MethodResponseReportWrongImdbMovie : IMethodResponse
- {
- public MethodResponseReportWrongImdbMovie()
- : base()
- { }
- public MethodResponseReportWrongImdbMovie(string name, string message)
- : base(name, message)
- { }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongMovieHash.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongMovieHash.cs
deleted file mode 100644
index 5696e7084..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongMovieHash.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("ReportWrongMovieHash method response",
- "ReportWrongMovieHash method response hold all expected values from server.")]
- public class MethodResponseReportWrongMovieHash : IMethodResponse
- {
- public MethodResponseReportWrongMovieHash()
- : base()
- { }
- public MethodResponseReportWrongMovieHash(string name, string message)
- : base(name, message)
- { }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseSearchToMail.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseSearchToMail.cs
deleted file mode 100644
index ea248bc22..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseSearchToMail.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("SearchToMail method response",
- "SearchToMail method response hold all expected values from server.")]
- public class MethodResponseSearchToMail : IMethodResponse
- {
- public MethodResponseSearchToMail()
- : base()
- { }
- public MethodResponseSearchToMail(string name, string message)
- : base(name, message)
- { }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseServerInfo.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseServerInfo.cs
deleted file mode 100644
index 973550e9f..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseServerInfo.cs
+++ /dev/null
@@ -1,131 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("ServerInfo method response",
- "ServerInfo method response hold all expected values from server.")]
- public class MethodResponseServerInfo : IMethodResponse
- {
- public MethodResponseServerInfo()
- : base()
- { }
- public MethodResponseServerInfo(string name, string message)
- : base(name, message)
- { }
- private string _xmlrpc_version;
- private string _xmlrpc_url;
- private string _application;
- private string _contact;
- private string _website_url;
- private int _users_online_total;
- private int _users_online_program;
- private int _users_loggedin;
- private string _users_max_alltime;
- private string _users_registered;
- private string _subs_downloads;
- private string _subs_subtitle_files;
- private string _movies_total;
- private string _movies_aka;
- private string _total_subtitles_languages;
- private List<string> _last_update_strings = new List<string>();
-
- /// <summary>
- /// Version of server's XML-RPC API implementation
- /// </summary>
- [Description("Version of server's XML-RPC API implementation"), Category("OS")]
- public string xmlrpc_version { get { return _xmlrpc_version; } set { _xmlrpc_version = value; } }
- /// <summary>
- /// XML-RPC interface URL
- /// </summary>
- [Description("XML-RPC interface URL"), Category("OS")]
- public string xmlrpc_url { get { return _xmlrpc_url; } set { _xmlrpc_url = value; } }
- /// <summary>
- /// Server's application name and version
- /// </summary>
- [Description("Server's application name and version"), Category("OS")]
- public string application { get { return _application; } set { _application = value; } }
- /// <summary>
- /// Contact e-mail address for server related quuestions and problems
- /// </summary>
- [Description("Contact e-mail address for server related quuestions and problems"), Category("OS")]
- public string contact { get { return _contact; } set { _contact = value; } }
- /// <summary>
- /// Main server URL
- /// </summary>
- [Description("Main server URL"), Category("OS")]
- public string website_url { get { return _website_url; } set { _website_url = value; } }
- /// <summary>
- /// Number of users currently online
- /// </summary>
- [Description("Number of users currently online"), Category("OS")]
- public int users_online_total { get { return _users_online_total; } set { _users_online_total = value; } }
- /// <summary>
- /// Number of users currently online using a client application (XML-RPC API)
- /// </summary>
- [Description("Number of users currently online using a client application (XML-RPC API)"), Category("OS")]
- public int users_online_program { get { return _users_online_program; } set { _users_online_program = value; } }
- /// <summary>
- /// Number of currently logged-in users
- /// </summary>
- [Description("Number of currently logged-in users"), Category("OS")]
- public int users_loggedin { get { return _users_loggedin; } set { _users_loggedin = value; } }
- /// <summary>
- /// Maximum number of users throughout the history
- /// </summary>
- [Description("Maximum number of users throughout the history"), Category("OS")]
- public string users_max_alltime { get { return _users_max_alltime; } set { _users_max_alltime = value; } }
- /// <summary>
- /// Number of registered users
- /// </summary>
- [Description("Number of registered users"), Category("OS")]
- public string users_registered { get { return _users_registered; } set { _users_registered = value; } }
- /// <summary>
- /// Total number of subtitle downloads
- /// </summary>
- [Description("Total number of subtitle downloads"), Category("OS")]
- public string subs_downloads { get { return _subs_downloads; } set { _subs_downloads = value; } }
- /// <summary>
- /// Total number of subtitle files stored on the server
- /// </summary>
- [Description("Total number of subtitle files stored on the server"), Category("OS")]
- public string subs_subtitle_files { get { return _subs_subtitle_files; } set { _subs_subtitle_files = value; } }
- /// <summary>
- /// Total number of movies in the database
- /// </summary>
- [Description("Total number of movies in the database"), Category("OS")]
- public string movies_total { get { return _movies_total; } set { _movies_total = value; } }
- /// <summary>
- /// Total number of movie A.K.A. titles in the database
- /// </summary>
- [Description("Total number of movie A.K.A. titles in the database"), Category("OS")]
- public string movies_aka { get { return _movies_aka; } set { _movies_aka = value; } }
- /// <summary>
- /// Total number of subtitle languages supported
- /// </summary>
- [Description("Total number of subtitle languages supported"), Category("OS")]
- public string total_subtitles_languages { get { return _total_subtitles_languages; } set { _total_subtitles_languages = value; } }
- /// <summary>
- /// Structure containing information about last updates of translations.
- /// </summary>
- [Description("Structure containing information about last updates of translations"), Category("OS")]
- public List<string> last_update_strings { get { return _last_update_strings; } set { _last_update_strings = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleDownload.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleDownload.cs
deleted file mode 100644
index 6a5d57d19..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleDownload.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-namespace OpenSubtitlesHandler
-{
- /// <summary>
- /// The response that should be used by subtitle download methods.
- /// </summary>
- [MethodResponseDescription("SubtitleDownload method response",
- "SubtitleDownload method response hold all expected values from server.")]
- public class MethodResponseSubtitleDownload : IMethodResponse
- {
- public MethodResponseSubtitleDownload()
- : base()
- {
- results = new List<SubtitleDownloadResult>();
- }
- public MethodResponseSubtitleDownload(string name, string message)
- : base(name, message)
- {
- results = new List<SubtitleDownloadResult>();
- }
- private List<SubtitleDownloadResult> results;
- public List<SubtitleDownloadResult> Results
- { get { return results; } set { results = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleSearch.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleSearch.cs
deleted file mode 100644
index 0dce20349..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleSearch.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace OpenSubtitlesHandler
-{
- /// <summary>
- /// Response to SearchSubtitle successed call.
- /// </summary>
- [MethodResponseDescription("SubtitleSearch method response",
- "SubtitleSearch method response hold all expected values from server.")]
- public class MethodResponseSubtitleSearch : IMethodResponse
- {
- public MethodResponseSubtitleSearch()
- : base()
- {
- results = new List<SubtitleSearchResult>();
- }
- public MethodResponseSubtitleSearch(string name, string message)
- : base(name, message)
- {
- results = new List<SubtitleSearchResult>();
- }
-
- private List<SubtitleSearchResult> results;
- public List<SubtitleSearchResult> Results
- { get { return results; } set { results = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitlesVote.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitlesVote.cs
deleted file mode 100644
index f02f822f0..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitlesVote.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("SubtitlesVote method response",
- "SubtitlesVote method response hold all expected values from server.")]
- public class MethodResponseSubtitlesVote : IMethodResponse
- {
- public MethodResponseSubtitlesVote()
- : base()
- { }
- public MethodResponseSubtitlesVote(string name, string message)
- : base(name, message)
- { }
- private string _SubRating;
- private string _SubSumVotes;
- private string _IDSubtitle;
-
- public string SubRating
- { get { return _SubRating; } set { _SubRating = value; } }
- public string SubSumVotes
- { get { return _SubSumVotes; } set { _SubSumVotes = value; } }
- public string IDSubtitle
- { get { return _IDSubtitle; } set { _IDSubtitle = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseTryUploadSubtitles.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseTryUploadSubtitles.cs
deleted file mode 100644
index cb3866a62..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseTryUploadSubtitles.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("TryUploadSubtitles method response",
- "TryUploadSubtitles method response hold all expected values from server.")]
- public class MethodResponseTryUploadSubtitles : IMethodResponse
- {
- public MethodResponseTryUploadSubtitles()
- : base()
- { }
- public MethodResponseTryUploadSubtitles(string name, string message)
- : base(name, message)
- { }
- private int alreadyindb;
- private List<SubtitleSearchResult> results = new List<SubtitleSearchResult>();
-
- public int AlreadyInDB { get { return alreadyindb; } set { alreadyindb = value; } }
- public List<SubtitleSearchResult> Results { get { return results; } set { results = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseUploadSubtitles.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseUploadSubtitles.cs
deleted file mode 100644
index bda950bef..000000000
--- a/OpenSubtitlesHandler/MethodResponses/MethodResponseUploadSubtitles.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- [MethodResponseDescription("UploadSubtitles method response",
- "UploadSubtitles method response hold all expected values from server.")]
- public class MethodResponseUploadSubtitles : IMethodResponse
- {
- public MethodResponseUploadSubtitles()
- : base()
- { }
- public MethodResponseUploadSubtitles(string name, string message)
- : base(name, message)
- { }
- private string _data;
- private bool _subtitles;
-
- public string Data { get { return _data; } set { _data = value; } }
- public bool SubTitles { get { return _subtitles; } set { _subtitles = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/Methods Implemeted.txt b/OpenSubtitlesHandler/Methods Implemeted.txt
deleted file mode 100644
index e3493d9a2..000000000
--- a/OpenSubtitlesHandler/Methods Implemeted.txt
+++ /dev/null
@@ -1,39 +0,0 @@
-List of available OpenSubtitles.org server XML-RPC methods.
-==========================================================
-Legends:
-* OK: this method is fully implemented, tested and works fine.
-* TODO: this method is in the plan to be added.
-* NOT TESTED: this method added and expected to work fine but never tested.
-* NOT WORK (x): this method added but not work. x= Description of the error.
-
---------------------------------------------
-Method name | Status
--------------------------|------------------
-LogIn | OK
-LogOut | OK
-NoOperation | OK
-SearchSubtitles | OK
-DownloadSubtitles | OK
-SearchToMail | OK
-TryUploadSubtitles | OK
-UploadSubtitles | OK
-SearchMoviesOnIMDB | OK
-GetIMDBMovieDetails | OK
-InsertMovie | OK
-InsertMovieHash | OK
-ServerInfo | OK
-ReportWrongMovieHash | OK
-ReportWrongImdbMovie | OK
-SubtitlesVote | OK
-AddComment | OK
-AddRequest | OK
-GetComments | OK
-GetSubLanguages | OK
-DetectLanguage | OK
-GetAvailableTranslations | OK
-GetTranslation | NOT WORK (Returns status of error 410 'Other or unknown error')
-AutoUpdate | NOT WORK (Returns status: 'parse error. not well formed')
-CheckMovieHash | OK
-CheckMovieHash2 | OK
-CheckSubHash | OK
---------------------------------------------
diff --git a/OpenSubtitlesHandler/MovieHasher.cs b/OpenSubtitlesHandler/MovieHasher.cs
deleted file mode 100644
index 25d91c1ac..000000000
--- a/OpenSubtitlesHandler/MovieHasher.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using System;
-using System.IO;
-using System.Text;
-
-namespace OpenSubtitlesHandler
-{
- public class MovieHasher
- {
- public static byte[] ComputeMovieHash(Stream input)
- {
- using (input)
- {
- long lhash, streamsize;
- streamsize = input.Length;
- lhash = streamsize;
-
- long i = 0;
- byte[] buffer = new byte[sizeof(long)];
- while (i < 65536 / sizeof(long) && (input.Read(buffer, 0, sizeof(long)) > 0))
- {
- i++;
- lhash += BitConverter.ToInt64(buffer, 0);
- }
-
- input.Position = Math.Max(0, streamsize - 65536);
- i = 0;
- while (i < 65536 / sizeof(long) && (input.Read(buffer, 0, sizeof(long)) > 0))
- {
- i++;
- lhash += BitConverter.ToInt64(buffer, 0);
- }
- byte[] result = BitConverter.GetBytes(lhash);
- Array.Reverse(result);
- return result;
- }
- }
-
- public static string ToHexadecimal(byte[] bytes)
- {
- var hexBuilder = new StringBuilder();
- for (int i = 0; i < bytes.Length; i++)
- {
- hexBuilder.Append(bytes[i].ToString("x2"));
- }
- return hexBuilder.ToString();
- }
- }
-}
diff --git a/OpenSubtitlesHandler/Movies/CheckMovieHash2Data.cs b/OpenSubtitlesHandler/Movies/CheckMovieHash2Data.cs
deleted file mode 100644
index 953590137..000000000
--- a/OpenSubtitlesHandler/Movies/CheckMovieHash2Data.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- public struct CheckMovieHash2Data
- {
- private string _MovieHash;
- private string _MovieImdbID;
- private string _MovieName;
- private string _MovieYear;
- private string _MovieKind;
- private string _SeriesSeason;
- private string _SeriesEpisode;
- private string _SeenCount;
-
- public string MovieHash { get { return _MovieHash; } set { _MovieHash = value; } }
- public string MovieImdbID { get { return _MovieImdbID; } set { _MovieImdbID = value; } }
- public string MovieName { get { return _MovieName; } set { _MovieName = value; } }
- public string MovieYear { get { return _MovieYear; } set { _MovieYear = value; } }
- public string MovieKind { get { return _MovieKind; } set { _MovieKind = value; } }
- public string SeriesSeason { get { return _SeriesSeason; } set { _SeriesSeason = value; } }
- public string SeriesEpisode { get { return _SeriesEpisode; } set { _SeriesEpisode = value; } }
- public string SeenCount { get { return _SeenCount; } set { _SeenCount = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/Movies/CheckMovieHash2Result.cs b/OpenSubtitlesHandler/Movies/CheckMovieHash2Result.cs
deleted file mode 100644
index 96652fae7..000000000
--- a/OpenSubtitlesHandler/Movies/CheckMovieHash2Result.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace OpenSubtitlesHandler
-{
- public class CheckMovieHash2Result
- {
- private string name;
- private List<CheckMovieHash2Data> data = new List<CheckMovieHash2Data>();
-
- public string Name { get { return name; } set { name = value; } }
- public List<CheckMovieHash2Data> Items { get { return data; } set { data = value; } }
-
- public override string ToString()
- {
- return name;
- }
- }
-}
diff --git a/OpenSubtitlesHandler/Movies/CheckMovieHashResult.cs b/OpenSubtitlesHandler/Movies/CheckMovieHashResult.cs
deleted file mode 100644
index 0d6c79f80..000000000
--- a/OpenSubtitlesHandler/Movies/CheckMovieHashResult.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- public struct CheckMovieHashResult
- {
- private string name;
- private string _MovieHash;
- private string _MovieImdbID;
- private string _MovieName;
- private string _MovieYear;
-
- public string MovieHash { get { return _MovieHash; } set { _MovieHash = value; } }
- public string MovieImdbID { get { return _MovieImdbID; } set { _MovieImdbID = value; } }
- public string MovieName { get { return _MovieName; } set { _MovieName = value; } }
- public string MovieYear { get { return _MovieYear; } set { _MovieYear = value; } }
- public string Name { get { return name; } set { name = value; } }
-
- public override string ToString()
- {
- return name;
- }
- }
-}
diff --git a/OpenSubtitlesHandler/Movies/InsertMovieHashParameters.cs b/OpenSubtitlesHandler/Movies/InsertMovieHashParameters.cs
deleted file mode 100644
index d0de7f8c6..000000000
--- a/OpenSubtitlesHandler/Movies/InsertMovieHashParameters.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- public class InsertMovieHashParameters
- {
- private string _moviehash = "";
- private string _moviebytesize = "";
- private string _imdbid = "";
- private string _movietimems = "";
- private string _moviefps = "";
- private string _moviefilename = "";
-
- public string moviehash { get { return _moviehash; } set { _moviehash = value; } }
- public string moviebytesize { get { return _moviebytesize; } set { _moviebytesize = value; } }
- public string imdbid { get { return _imdbid; } set { _imdbid = value; } }
- public string movietimems { get { return _movietimems; } set { _movietimems = value; } }
- public string moviefps { get { return _moviefps; } set { _moviefps = value; } }
- public string moviefilename { get { return _moviefilename; } set { _moviefilename = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/Movies/MovieSearchResult.cs b/OpenSubtitlesHandler/Movies/MovieSearchResult.cs
deleted file mode 100644
index d77116583..000000000
--- a/OpenSubtitlesHandler/Movies/MovieSearchResult.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- public struct MovieSearchResult
- {
- private string id;
- private string title;
-
- public string ID
- { get { return id; } set { id = value; } }
- public string Title
- { get { return title; } set { title = value; } }
- /// <summary>
- /// Title
- /// </summary>
- /// <returns></returns>
- public override string ToString()
- {
- return title;
- }
- }
-}
diff --git a/OpenSubtitlesHandler/Movies/SearchToMailMovieParameter.cs b/OpenSubtitlesHandler/Movies/SearchToMailMovieParameter.cs
deleted file mode 100644
index a0ecc87f8..000000000
--- a/OpenSubtitlesHandler/Movies/SearchToMailMovieParameter.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- public struct SearchToMailMovieParameter
- {
- private string _moviehash;
- private double _moviesize;
-
- public string moviehash { get { return _moviehash; } set { _moviehash = value; } }
- public double moviesize { get { return _moviesize; } set { _moviesize = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/OpenSubtitles.cs b/OpenSubtitlesHandler/OpenSubtitles.cs
deleted file mode 100644
index 76f70dc07..000000000
--- a/OpenSubtitlesHandler/OpenSubtitles.cs
+++ /dev/null
@@ -1,2744 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using OpenSubtitlesHandler.Console;
-using XmlRpcHandler;
-
-namespace OpenSubtitlesHandler
-{
- /// <summary>
- /// The core of the OpenSubtitles Handler library. All members are static.
- /// </summary>
- public sealed class OpenSubtitles
- {
- private static string XML_PRC_USERAGENT = "";
- // This is session id after log in, important value and MUST be set by LogIn before any other call.
- private static string TOKEN = "";
-
- /// <summary>
- /// Set the useragent value. This must be called before doing anything else.
- /// </summary>
- /// <param name="agent">The useragent value</param>
- public static void SetUserAgent(string agent)
- {
- XML_PRC_USERAGENT = agent;
- }
-
- /*Session handling*/
- /// <summary>
- /// Send a LogIn request, this must be called before anything else in this class.
- /// </summary>
- /// <param name="userName">The user name of OpenSubtitles</param>
- /// <param name="password">The password</param>
- /// <param name="language">The language, usally en</param>
- /// <returns>Status of the login operation</returns>
- public static IMethodResponse LogIn(string userName, string password, string language)
- {
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(userName));
- parms.Add(new XmlRpcValueBasic(password));
- parms.Add(new XmlRpcValueBasic(language));
- parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT));
- var call = new XmlRpcMethodCall("LogIn", parms);
- OSHConsole.WriteLine("Sending LogIn request to the server ...", DebugCode.Good);
-
- //File.WriteAllText(".\\request.txt", Encoding.UTF8.GetString(XmlRpcGenerator.Generate(call)));
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
-
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response. We expect Struct here.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- var re = new MethodResponseLogIn("Success", "Log in successful.");
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "token": re.Token = TOKEN = MEMBER.Data.Data.ToString(); OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": re.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "status": re.Status = MEMBER.Data.Data.ToString(); OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- }
- }
- return re;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "Log in failed !");
- }
-
- public static async Task<IMethodResponse> LogInAsync(string userName, string password, string language, CancellationToken cancellationToken)
- {
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(userName));
- parms.Add(new XmlRpcValueBasic(password));
- parms.Add(new XmlRpcValueBasic(language));
- parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT));
- var call = new XmlRpcMethodCall("LogIn", parms);
- OSHConsole.WriteLine("Sending LogIn request to the server ...", DebugCode.Good);
-
- //File.WriteAllText(".\\request.txt", Encoding.UTF8.GetString(XmlRpcGenerator.Generate(call)));
- // Send the request to the server
- var stream = await Utilities.SendRequestAsync(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT, cancellationToken)
- .ConfigureAwait(false);
-
- string response = Utilities.GetStreamString(stream);
-
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response. We expect Struct here.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- var re = new MethodResponseLogIn("Success", "Log in successful.");
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "token":
- re.Token = TOKEN = MEMBER.Data.Data.ToString();
- OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "seconds":
- re.Seconds = double.Parse(MEMBER.Data.Data.ToString(), CultureInfo.InvariantCulture);
- OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "status":
- re.Status = MEMBER.Data.Data.ToString();
- OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- }
- }
- return re;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "Log in failed !");
- }
-
- /// <summary>
- /// Log out from the server. Call this to terminate the session.
- /// </summary>
- /// <returns></returns>
- public static IMethodResponse LogOut()
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- var call = new XmlRpcMethodCall("LogOut", parms);
-
- OSHConsole.WriteLine("Sending LogOut request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response. We expect Struct here.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var strct = (XmlRpcValueStruct)calls[0].Parameters[0];
- OSHConsole.WriteLine("STATUS=" + ((XmlRpcValueBasic)strct.Members[0].Data).Data.ToString());
- OSHConsole.WriteLine("SECONDS=" + ((XmlRpcValueBasic)strct.Members[1].Data).Data.ToString());
- var re = new MethodResponseLogIn("Success", "Log out successful.");
- re.Status = ((XmlRpcValueBasic)strct.Members[0].Data).Data.ToString();
- re.Seconds = (double)((XmlRpcValueBasic)strct.Members[1].Data).Data;
- return re;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "Log out failed !");
- }
- /// <summary>
- /// keep-alive user's session, verify token/session validity
- /// </summary>
- /// <returns>Status of the call operation</returns>
- public static IMethodResponse NoOperation()
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT, XmlRpcBasicValueType.String));
- var call = new XmlRpcMethodCall("NoOperation", parms);
-
- OSHConsole.WriteLine("Sending NoOperation request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response. We expect Struct here.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var R = new MethodResponseNoOperation();
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data); break;
- case "download_limits":
- var dlStruct = (XmlRpcValueStruct)MEMBER.Data;
- foreach (XmlRpcStructMember dlmember in dlStruct.Members)
- {
- OSHConsole.WriteLine(" >" + dlmember.Name + "= " + dlmember.Data.Data.ToString());
- switch (dlmember.Name)
- {
- case "global_wrh_download_limit": R.global_wrh_download_limit = dlmember.Data.Data.ToString(); break;
- case "client_ip": R.client_ip = dlmember.Data.Data.ToString(); break;
- case "limit_check_by": R.limit_check_by = dlmember.Data.Data.ToString(); break;
- case "client_24h_download_count": R.client_24h_download_count = dlmember.Data.Data.ToString(); break;
- case "client_downlaod_quota": R.client_downlaod_quota = dlmember.Data.Data.ToString(); break;
- case "client_24h_download_limit": R.client_24h_download_limit = dlmember.Data.Data.ToString(); break;
- }
- }
- break;
- }
- }
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "NoOperation call failed !");
- }
- /*Search and download*/
- /// <summary>
- /// Search for subtitle files matching your videos using either video file hashes or IMDb IDs.
- /// </summary>
- /// <param name="parameters">List of search subtitle parameters which each one represents 'struct parameter' as descriped at http://trac.opensubtitles.org/projects/opensubtitles/wiki/XmlRpcSearchSubtitles </param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitleSearch'</returns>
- public static IMethodResponse SearchSubtitles(SubtitleSearchParameters[] parameters)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- if (parameters == null)
- {
- OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error);
- return new MethodResponseError("Fail", "No subtitle search parameter passed");
- }
- if (parameters.Length == 0)
- {
- OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error);
- return new MethodResponseError("Fail", "No subtitle search parameter passed");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- // Add token param
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- // Add subtitle search parameters. Each one will be like 'array' of structs.
- var array = new XmlRpcValueArray();
- foreach (SubtitleSearchParameters param in parameters)
- {
- var strct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- // sublanguageid member
- var member = new XmlRpcStructMember("sublanguageid",
- new XmlRpcValueBasic(param.SubLangaugeID, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- // moviehash member
- if (param.MovieHash.Length > 0 && param.MovieByteSize > 0)
- {
- member = new XmlRpcStructMember("moviehash",
- new XmlRpcValueBasic(param.MovieHash, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- // moviehash member
- member = new XmlRpcStructMember("moviebytesize",
- new XmlRpcValueBasic(param.MovieByteSize, XmlRpcBasicValueType.Int));
- strct.Members.Add(member);
- }
- if (param.Query.Length > 0)
- {
- member = new XmlRpcStructMember("query",
- new XmlRpcValueBasic(param.Query, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- }
-
- if (param.Episode.Length > 0 && param.Season.Length > 0)
- {
- member = new XmlRpcStructMember("season",
- new XmlRpcValueBasic(param.Season, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- member = new XmlRpcStructMember("episode",
- new XmlRpcValueBasic(param.Episode, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- }
-
- // imdbid member
- if (param.IMDbID.Length > 0)
- {
- member = new XmlRpcStructMember("imdbid",
- new XmlRpcValueBasic(param.IMDbID, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- }
- // Add the struct to the array
- array.Values.Add(strct);
- }
- // Add the array to the parameters
- parms.Add(array);
- // Call !
- var call = new XmlRpcMethodCall("SearchSubtitles", parms);
- OSHConsole.WriteLine("Sending SearchSubtitles request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
-
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- // We expect Struct of 3 members:
- //* the first is status
- //* the second is [array of structs, each one includes subtitle file].
- //* the third is [double basic value] represent seconds token by server.
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseSubtitleSearch();
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- if (MEMBER.Name == "status")
- {
- R.Status = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine("Status= " + R.Status);
- }
- else if (MEMBER.Name == "seconds")
- {
- R.Seconds = (double)MEMBER.Data.Data;
- OSHConsole.WriteLine("Seconds= " + R.Seconds);
- }
- else if (MEMBER.Name == "data")
- {
- if (MEMBER.Data is XmlRpcValueArray)
- {
- OSHConsole.WriteLine("Search results: ");
-
- var rarray = (XmlRpcValueArray)MEMBER.Data;
- foreach (IXmlRpcValue subStruct in rarray.Values)
- {
- if (subStruct == null) continue;
- if (!(subStruct is XmlRpcValueStruct)) continue;
-
- var result = new SubtitleSearchResult();
- foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
- {
- // To avoid errors of arranged info or missing ones, let's do it with switch..
- switch (submember.Name)
- {
- case "IDMovie": result.IDMovie = submember.Data.Data.ToString(); break;
- case "IDMovieImdb": result.IDMovieImdb = submember.Data.Data.ToString(); break;
- case "IDSubMovieFile": result.IDSubMovieFile = submember.Data.Data.ToString(); break;
- case "IDSubtitle": result.IDSubtitle = submember.Data.Data.ToString(); break;
- case "IDSubtitleFile": result.IDSubtitleFile = submember.Data.Data.ToString(); break;
- case "ISO639": result.ISO639 = submember.Data.Data.ToString(); break;
- case "LanguageName": result.LanguageName = submember.Data.Data.ToString(); break;
- case "MovieByteSize": result.MovieByteSize = submember.Data.Data.ToString(); break;
- case "MovieHash": result.MovieHash = submember.Data.Data.ToString(); break;
- case "MovieImdbRating": result.MovieImdbRating = submember.Data.Data.ToString(); break;
- case "MovieName": result.MovieName = submember.Data.Data.ToString(); break;
- case "MovieNameEng": result.MovieNameEng = submember.Data.Data.ToString(); break;
- case "MovieReleaseName": result.MovieReleaseName = submember.Data.Data.ToString(); break;
- case "MovieTimeMS": result.MovieTimeMS = submember.Data.Data.ToString(); break;
- case "MovieYear": result.MovieYear = submember.Data.Data.ToString(); break;
- case "SubActualCD": result.SubActualCD = submember.Data.Data.ToString(); break;
- case "SubAddDate": result.SubAddDate = submember.Data.Data.ToString(); break;
- case "SubAuthorComment": result.SubAuthorComment = submember.Data.Data.ToString(); break;
- case "SubBad": result.SubBad = submember.Data.Data.ToString(); break;
- case "SubDownloadLink": result.SubDownloadLink = submember.Data.Data.ToString(); break;
- case "SubDownloadsCnt": result.SubDownloadsCnt = submember.Data.Data.ToString(); break;
- case "SeriesEpisode": result.SeriesEpisode = submember.Data.Data.ToString(); break;
- case "SeriesSeason": result.SeriesSeason = submember.Data.Data.ToString(); break;
- case "SubFileName": result.SubFileName = submember.Data.Data.ToString(); break;
- case "SubFormat": result.SubFormat = submember.Data.Data.ToString(); break;
- case "SubHash": result.SubHash = submember.Data.Data.ToString(); break;
- case "SubLanguageID": result.SubLanguageID = submember.Data.Data.ToString(); break;
- case "SubRating": result.SubRating = submember.Data.Data.ToString(); break;
- case "SubSize": result.SubSize = submember.Data.Data.ToString(); break;
- case "SubSumCD": result.SubSumCD = submember.Data.Data.ToString(); break;
- case "UserID": result.UserID = submember.Data.Data.ToString(); break;
- case "UserNickName": result.UserNickName = submember.Data.Data.ToString(); break;
- case "ZipDownloadLink": result.ZipDownloadLink = submember.Data.Data.ToString(); break;
- }
- }
- R.Results.Add(result);
- OSHConsole.WriteLine(">" + result.ToString());
- }
- }
- else// Unknown data ?
- {
- OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
- }
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "Search Subtitles call failed !");
- }
-
- public static async Task<IMethodResponse> SearchSubtitlesAsync(SubtitleSearchParameters[] parameters, CancellationToken cancellationToken)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- if (parameters == null)
- {
- OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error);
- return new MethodResponseError("Fail", "No subtitle search parameter passed");
- }
- if (parameters.Length == 0)
- {
- OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error);
- return new MethodResponseError("Fail", "No subtitle search parameter passed");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- // Add token param
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- // Add subtitle search parameters. Each one will be like 'array' of structs.
- var array = new XmlRpcValueArray();
- foreach (SubtitleSearchParameters param in parameters)
- {
- var strct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- // sublanguageid member
- var member = new XmlRpcStructMember("sublanguageid",
- new XmlRpcValueBasic(param.SubLangaugeID, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- // moviehash member
- if (param.MovieHash.Length > 0 && param.MovieByteSize > 0)
- {
- member = new XmlRpcStructMember("moviehash",
- new XmlRpcValueBasic(param.MovieHash, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- // moviehash member
- member = new XmlRpcStructMember("moviebytesize",
- new XmlRpcValueBasic(param.MovieByteSize, XmlRpcBasicValueType.Int));
- strct.Members.Add(member);
- }
- if (param.Query.Length > 0)
- {
- member = new XmlRpcStructMember("query",
- new XmlRpcValueBasic(param.Query, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- }
-
- if (param.Episode.Length > 0 && param.Season.Length > 0)
- {
- member = new XmlRpcStructMember("season",
- new XmlRpcValueBasic(param.Season, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- member = new XmlRpcStructMember("episode",
- new XmlRpcValueBasic(param.Episode, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- }
-
- // imdbid member
- if (param.IMDbID.Length > 0)
- {
- member = new XmlRpcStructMember("imdbid",
- new XmlRpcValueBasic(param.IMDbID, XmlRpcBasicValueType.String));
- strct.Members.Add(member);
- }
- // Add the struct to the array
- array.Values.Add(strct);
- }
- // Add the array to the parameters
- parms.Add(array);
- // Call !
- var call = new XmlRpcMethodCall("SearchSubtitles", parms);
- OSHConsole.WriteLine("Sending SearchSubtitles request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(await Utilities.SendRequestAsync(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT, cancellationToken).ConfigureAwait(false));
-
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- // We expect Struct of 3 members:
- //* the first is status
- //* the second is [array of structs, each one includes subtitle file].
- //* the third is [double basic value] represent seconds token by server.
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseSubtitleSearch();
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- if (MEMBER.Name == "status")
- {
- R.Status = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine("Status= " + R.Status);
- }
- else if (MEMBER.Name == "seconds")
- {
- R.Seconds = (double)MEMBER.Data.Data;
- OSHConsole.WriteLine("Seconds= " + R.Seconds);
- }
- else if (MEMBER.Name == "data")
- {
- if (MEMBER.Data is XmlRpcValueArray)
- {
- OSHConsole.WriteLine("Search results: ");
-
- var rarray = (XmlRpcValueArray)MEMBER.Data;
- foreach (IXmlRpcValue subStruct in rarray.Values)
- {
- if (subStruct == null) continue;
- if (!(subStruct is XmlRpcValueStruct)) continue;
-
- var result = new SubtitleSearchResult();
- foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
- {
- // To avoid errors of arranged info or missing ones, let's do it with switch..
- switch (submember.Name)
- {
- case "IDMovie": result.IDMovie = submember.Data.Data.ToString(); break;
- case "IDMovieImdb": result.IDMovieImdb = submember.Data.Data.ToString(); break;
- case "IDSubMovieFile": result.IDSubMovieFile = submember.Data.Data.ToString(); break;
- case "IDSubtitle": result.IDSubtitle = submember.Data.Data.ToString(); break;
- case "IDSubtitleFile": result.IDSubtitleFile = submember.Data.Data.ToString(); break;
- case "ISO639": result.ISO639 = submember.Data.Data.ToString(); break;
- case "LanguageName": result.LanguageName = submember.Data.Data.ToString(); break;
- case "MovieByteSize": result.MovieByteSize = submember.Data.Data.ToString(); break;
- case "MovieHash": result.MovieHash = submember.Data.Data.ToString(); break;
- case "MovieImdbRating": result.MovieImdbRating = submember.Data.Data.ToString(); break;
- case "MovieName": result.MovieName = submember.Data.Data.ToString(); break;
- case "MovieNameEng": result.MovieNameEng = submember.Data.Data.ToString(); break;
- case "MovieReleaseName": result.MovieReleaseName = submember.Data.Data.ToString(); break;
- case "MovieTimeMS": result.MovieTimeMS = submember.Data.Data.ToString(); break;
- case "MovieYear": result.MovieYear = submember.Data.Data.ToString(); break;
- case "SubActualCD": result.SubActualCD = submember.Data.Data.ToString(); break;
- case "SubAddDate": result.SubAddDate = submember.Data.Data.ToString(); break;
- case "SubAuthorComment": result.SubAuthorComment = submember.Data.Data.ToString(); break;
- case "SubBad": result.SubBad = submember.Data.Data.ToString(); break;
- case "SubDownloadLink": result.SubDownloadLink = submember.Data.Data.ToString(); break;
- case "SubDownloadsCnt": result.SubDownloadsCnt = submember.Data.Data.ToString(); break;
- case "SeriesEpisode": result.SeriesEpisode = submember.Data.Data.ToString(); break;
- case "SeriesSeason": result.SeriesSeason = submember.Data.Data.ToString(); break;
- case "SubFileName": result.SubFileName = submember.Data.Data.ToString(); break;
- case "SubFormat": result.SubFormat = submember.Data.Data.ToString(); break;
- case "SubHash": result.SubHash = submember.Data.Data.ToString(); break;
- case "SubLanguageID": result.SubLanguageID = submember.Data.Data.ToString(); break;
- case "SubRating": result.SubRating = submember.Data.Data.ToString(); break;
- case "SubSize": result.SubSize = submember.Data.Data.ToString(); break;
- case "SubSumCD": result.SubSumCD = submember.Data.Data.ToString(); break;
- case "UserID": result.UserID = submember.Data.Data.ToString(); break;
- case "UserNickName": result.UserNickName = submember.Data.Data.ToString(); break;
- case "ZipDownloadLink": result.ZipDownloadLink = submember.Data.Data.ToString(); break;
- }
- }
- R.Results.Add(result);
- OSHConsole.WriteLine(">" + result.ToString());
- }
- }
- else// Unknown data ?
- {
- OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
- }
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "Search Subtitles call failed !");
- }
-
- /// <summary>
- /// Download subtitle file(s)
- /// </summary>
- /// <param name="subIDS">The subtitle IDS (an array of IDSubtitleFile value that given by server as SearchSubtiles results)</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitleDownload' which will hold downloaded subtitles</returns>
- public static IMethodResponse DownloadSubtitles(int[] subIDS)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- if (subIDS == null)
- {
- OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
- return new MethodResponseError("Fail", "No subtitle id passed");
- }
- if (subIDS.Length == 0)
- {
- OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
- return new MethodResponseError("Fail", "No subtitle id passed");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- // Add token param
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- // Add subtitle search parameters. Each one will be like 'array' of structs.
- var array = new XmlRpcValueArray();
- foreach (int id in subIDS)
- {
- array.Values.Add(new XmlRpcValueBasic(id, XmlRpcBasicValueType.Int));
- }
- // Add the array to the parameters
- parms.Add(array);
- // Call !
- var call = new XmlRpcMethodCall("DownloadSubtitles", parms);
- OSHConsole.WriteLine("Sending DownloadSubtitles request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- // We expect Struct of 3 members:
- //* the first is status
- //* the second is [array of structs, each one includes subtitle file].
- //* the third is [double basic value] represent seconds token by server.
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseSubtitleDownload();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- if (MEMBER.Name == "status")
- {
- R.Status = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine("Status= " + R.Status);
- }
- else if (MEMBER.Name == "seconds")
- {
- R.Seconds = (double)MEMBER.Data.Data;
- OSHConsole.WriteLine("Seconds= " + R.Seconds);
- }
- else if (MEMBER.Name == "data")
- {
- if (MEMBER.Data is XmlRpcValueArray)
- {
- OSHConsole.WriteLine("Download results:");
- var rarray = (XmlRpcValueArray)MEMBER.Data;
- foreach (IXmlRpcValue subStruct in rarray.Values)
- {
- if (subStruct == null) continue;
- if (!(subStruct is XmlRpcValueStruct)) continue;
-
- var result = new SubtitleDownloadResult();
- foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
- {
- // To avoid errors of arranged info or missing ones, let's do it with switch..
- switch (submember.Name)
- {
- case "idsubtitlefile": result.IdSubtitleFile = (string)submember.Data.Data; break;
- case "data": result.Data = (string)submember.Data.Data; break;
- }
- }
- R.Results.Add(result);
- OSHConsole.WriteLine("> IDSubtilteFile= " + result.ToString());
- }
- }
- else// Unknown data ?
- {
- OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
- }
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "DownloadSubtitles call failed !");
- }
-
- public static async Task<IMethodResponse> DownloadSubtitlesAsync(int[] subIDS, CancellationToken cancellationToken)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- if (subIDS == null)
- {
- OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
- return new MethodResponseError("Fail", "No subtitle id passed");
- }
- if (subIDS.Length == 0)
- {
- OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
- return new MethodResponseError("Fail", "No subtitle id passed");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- // Add token param
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- // Add subtitle search parameters. Each one will be like 'array' of structs.
- var array = new XmlRpcValueArray();
- foreach (int id in subIDS)
- {
- array.Values.Add(new XmlRpcValueBasic(id, XmlRpcBasicValueType.Int));
- }
- // Add the array to the parameters
- parms.Add(array);
- // Call !
- var call = new XmlRpcMethodCall("DownloadSubtitles", parms);
- OSHConsole.WriteLine("Sending DownloadSubtitles request to the server ...", DebugCode.Good);
- // Send the request to the server
-
- var httpResponse = await Utilities.SendRequestAsync(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT, cancellationToken).ConfigureAwait(false);
-
- string response = Utilities.GetStreamString(httpResponse);
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- // We expect Struct of 3 members:
- //* the first is status
- //* the second is [array of structs, each one includes subtitle file].
- //* the third is [double basic value] represent seconds token by server.
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseSubtitleDownload();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- if (MEMBER.Name == "status")
- {
- R.Status = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine("Status= " + R.Status);
- }
- else if (MEMBER.Name == "seconds")
- {
- R.Seconds = (double)MEMBER.Data.Data;
- OSHConsole.WriteLine("Seconds= " + R.Seconds);
- }
- else if (MEMBER.Name == "data")
- {
- if (MEMBER.Data is XmlRpcValueArray)
- {
- OSHConsole.WriteLine("Download results:");
- var rarray = (XmlRpcValueArray)MEMBER.Data;
- foreach (IXmlRpcValue subStruct in rarray.Values)
- {
- if (subStruct == null) continue;
- if (!(subStruct is XmlRpcValueStruct)) continue;
-
- var result = new SubtitleDownloadResult();
- foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
- {
- // To avoid errors of arranged info or missing ones, let's do it with switch..
- switch (submember.Name)
- {
- case "idsubtitlefile": result.IdSubtitleFile = (string)submember.Data.Data; break;
- case "data": result.Data = (string)submember.Data.Data; break;
- }
- }
- R.Results.Add(result);
- OSHConsole.WriteLine("> IDSubtilteFile= " + result.ToString());
- }
- }
- else// Unknown data ?
- {
- OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
- }
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "DownloadSubtitles call failed !");
- }
-
- /// <summary>
- /// Returns comments for subtitles
- /// </summary>
- /// <param name="subIDS">The subtitle IDS (an array of IDSubtitleFile value that given by server as SearchSubtiles results)</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetComments'</returns>
- public static IMethodResponse GetComments(int[] subIDS)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- if (subIDS == null)
- {
- OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
- return new MethodResponseError("Fail", "No subtitle id passed");
- }
- if (subIDS.Length == 0)
- {
- OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
- return new MethodResponseError("Fail", "No subtitle id passed");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- // Add token param
- parms.Add(new XmlRpcValueBasic(TOKEN));
- // Add subtitle search parameters. Each one will be like 'array' of structs.
- var array = new XmlRpcValueArray(subIDS);
- // Add the array to the parameters
- parms.Add(array);
- // Call !
- var call = new XmlRpcMethodCall("GetComments", parms);
- OSHConsole.WriteLine("Sending GetComments request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseGetComments();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- if (MEMBER.Name == "status")
- {
- R.Status = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine("Status= " + R.Status);
- }
- else if (MEMBER.Name == "seconds")
- {
- R.Seconds = (double)MEMBER.Data.Data;
- OSHConsole.WriteLine("Seconds= " + R.Seconds);
- }
- else if (MEMBER.Name == "data")
- {
- if (MEMBER.Data is XmlRpcValueArray)
- {
- OSHConsole.WriteLine("Comments results:");
- var rarray = (XmlRpcValueArray)MEMBER.Data;
- foreach (IXmlRpcValue commentStruct in rarray.Values)
- {
- if (commentStruct == null) continue;
- if (!(commentStruct is XmlRpcValueStruct)) continue;
-
- var result = new GetCommentsResult();
- foreach (XmlRpcStructMember commentmember in ((XmlRpcValueStruct)commentStruct).Members)
- {
- // To avoid errors of arranged info or missing ones, let's do it with switch..
- switch (commentmember.Name)
- {
- case "IDSubtitle": result.IDSubtitle = (string)commentmember.Data.Data; break;
- case "UserID": result.UserID = (string)commentmember.Data.Data; break;
- case "UserNickName": result.UserNickName = (string)commentmember.Data.Data; break;
- case "Comment": result.Comment = (string)commentmember.Data.Data; break;
- case "Created": result.Created = (string)commentmember.Data.Data; break;
- }
- }
- R.Results.Add(result);
- OSHConsole.WriteLine("> IDSubtitle= " + result.ToString());
- }
- }
- else// Unknown data ?
- {
- OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
- }
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "GetComments call failed !");
- }
-
- /// <summary>
- /// Schedule a periodical search for subtitles matching given video files, send results to user's e-mail address.
- /// </summary>
- /// <param name="languageIDS">The language 3 lenght ids array</param>
- /// <param name="movies">The movies parameters</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSearchToMail'</returns>
- public static IMethodResponse SearchToMail(string[] languageIDS, SearchToMailMovieParameter[] movies)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- // Array of sub langs
- var a = new XmlRpcValueArray(languageIDS);
- parms.Add(a);
- // Array of video parameters
- a = new XmlRpcValueArray();
- foreach (SearchToMailMovieParameter p in movies)
- {
- var str = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- str.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(p.moviehash)));
- str.Members.Add(new XmlRpcStructMember("moviesize", new XmlRpcValueBasic(p.moviesize)));
- a.Values.Add(str);
- }
- parms.Add(a);
- var call = new XmlRpcMethodCall("SearchToMail", parms);
-
- OSHConsole.WriteLine("Sending SearchToMail request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseSearchToMail();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "SearchToMail call failed !");
- }
- /*Movies*/
- /// <summary>
- /// Search for a movie (using movie title)
- /// </summary>
- /// <param name="query">Movie title user is searching for, this is cleaned-up a bit (remove dvdrip, etc.) before searching </param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitleSearch'</returns>
- public static IMethodResponse SearchMoviesOnIMDB(string query)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- // Add token param
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- // Add query param
- parms.Add(new XmlRpcValueBasic(query, XmlRpcBasicValueType.String));
- // Call !
- var call = new XmlRpcMethodCall("SearchMoviesOnIMDB", parms);
- OSHConsole.WriteLine("Sending SearchMoviesOnIMDB request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseMovieSearch();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- if (MEMBER.Name == "status")
- {
- R.Status = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine("Status= " + R.Status);
- }
- else if (MEMBER.Name == "seconds")
- {
- R.Seconds = (double)MEMBER.Data.Data;
- OSHConsole.WriteLine("Seconds= " + R.Seconds);
- }
- else if (MEMBER.Name == "data")
- {
- if (MEMBER.Data is XmlRpcValueArray)
- {
- OSHConsole.WriteLine("Search results:");
- var rarray = (XmlRpcValueArray)MEMBER.Data;
- foreach (IXmlRpcValue subStruct in rarray.Values)
- {
- if (subStruct == null) continue;
- if (!(subStruct is XmlRpcValueStruct)) continue;
-
- var result = new MovieSearchResult();
- foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
- {
- // To avoid errors of arranged info or missing ones, let's do it with switch..
- switch (submember.Name)
- {
- case "id": result.ID = (string)submember.Data.Data; break;
- case "title": result.Title = (string)submember.Data.Data; break;
- }
- }
- R.Results.Add(result);
- OSHConsole.WriteLine(">" + result.ToString());
- }
- }
- else// Unknown data ?
- {
- OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
- }
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "SearchMoviesOnIMDB call failed !");
- }
- /// <summary>
- /// Get movie details for given IMDb ID
- /// </summary>
- /// <param name="imdbid">http://www.imdb.com/</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseMovieDetails'</returns>
- public static IMethodResponse GetIMDBMovieDetails(string imdbid)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- // Add token param
- parms.Add(new XmlRpcValueBasic(TOKEN));
- // Add query param
- parms.Add(new XmlRpcValueBasic(imdbid));
- // Call !
- var call = new XmlRpcMethodCall("GetIMDBMovieDetails", parms);
- OSHConsole.WriteLine("Sending GetIMDBMovieDetails request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseMovieDetails();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- if (MEMBER.Name == "status")
- {
- R.Status = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine("Status= " + R.Status);
- }
- else if (MEMBER.Name == "seconds")
- {
- R.Seconds = (double)MEMBER.Data.Data;
- OSHConsole.WriteLine("Seconds= " + R.Seconds);
- }
- else if (MEMBER.Name == "data")
- {
- // We expect struct with details...
- if (MEMBER.Data is XmlRpcValueStruct)
- {
- OSHConsole.WriteLine("Details result:");
- var detailsStruct = (XmlRpcValueStruct)MEMBER.Data;
- foreach (XmlRpcStructMember dmem in detailsStruct.Members)
- {
- switch (dmem.Name)
- {
- case "id": R.ID = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
- case "title": R.Title = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
- case "year": R.Year = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
- case "cover": R.CoverLink = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
- case "duration": R.Duration = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
- case "tagline": R.Tagline = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
- case "plot": R.Plot = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
- case "goofs": R.Goofs = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
- case "trivia": R.Trivia = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
- case "cast":
- // this is another struct with cast members...
- OSHConsole.WriteLine(">" + dmem.Name + "= ");
- var castStruct = (XmlRpcValueStruct)dmem.Data;
- foreach (XmlRpcStructMember castMemeber in castStruct.Members)
- {
- R.Cast.Add(castMemeber.Data.Data.ToString());
- OSHConsole.WriteLine(" >" + castMemeber.Data.Data.ToString());
- }
- break;
- case "directors":
- OSHConsole.WriteLine(">" + dmem.Name + "= ");
- // this is another struct with directors members...
- var directorsStruct = (XmlRpcValueStruct)dmem.Data;
- foreach (XmlRpcStructMember directorsMember in directorsStruct.Members)
- {
- R.Directors.Add(directorsMember.Data.Data.ToString());
- OSHConsole.WriteLine(" >" + directorsMember.Data.Data.ToString());
- }
- break;
- case "writers":
- OSHConsole.WriteLine(">" + dmem.Name + "= ");
- // this is another struct with writers members...
- var writersStruct = (XmlRpcValueStruct)dmem.Data;
- foreach (XmlRpcStructMember writersMember in writersStruct.Members)
- {
- R.Writers.Add(writersMember.Data.Data.ToString());
- OSHConsole.WriteLine("+->" + writersMember.Data.Data.ToString());
- }
- break;
- case "awards":
- // this is an array of genres...
- var awardsArray = (XmlRpcValueArray)dmem.Data;
- foreach (XmlRpcValueBasic award in awardsArray.Values)
- {
- R.Awards.Add(award.Data.ToString());
- OSHConsole.WriteLine(" >" + award.Data.ToString());
- }
- break;
- case "genres":
- OSHConsole.WriteLine(">" + dmem.Name + "= ");
- // this is an array of genres...
- var genresArray = (XmlRpcValueArray)dmem.Data;
- foreach (XmlRpcValueBasic genre in genresArray.Values)
- {
- R.Genres.Add(genre.Data.ToString());
- OSHConsole.WriteLine(" >" + genre.Data.ToString());
- }
- break;
- case "country":
- OSHConsole.WriteLine(">" + dmem.Name + "= ");
- // this is an array of country...
- var countryArray = (XmlRpcValueArray)dmem.Data;
- foreach (XmlRpcValueBasic country in countryArray.Values)
- {
- R.Country.Add(country.Data.ToString());
- OSHConsole.WriteLine(" >" + country.Data.ToString());
- }
- break;
- case "language":
- OSHConsole.WriteLine(">" + dmem.Name + "= ");
- // this is an array of language...
- var languageArray = (XmlRpcValueArray)dmem.Data;
- foreach (XmlRpcValueBasic language in languageArray.Values)
- {
- R.Language.Add(language.Data.ToString());
- OSHConsole.WriteLine(" >" + language.Data.ToString());
- }
- break;
- case "certification":
- OSHConsole.WriteLine(">" + dmem.Name + "= ");
- // this is an array of certification...
- var certificationArray = (XmlRpcValueArray)dmem.Data;
- foreach (XmlRpcValueBasic certification in certificationArray.Values)
- {
- R.Certification.Add(certification.Data.ToString());
- OSHConsole.WriteLine(" >" + certification.Data.ToString());
- }
- break;
- }
- }
- }
- else// Unknown data ?
- {
- OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
- }
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "GetIMDBMovieDetails call failed !");
- }
- /// <summary>
- /// Allows registered users to insert new movies (not stored in IMDb) to the database.
- /// </summary>
- /// <param name="movieName">Movie title </param>
- /// <param name="movieyear">Release year </param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseInsertMovie'</returns>
- public static IMethodResponse InsertMovie(string movieName, string movieyear)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- // Add token param
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- // Add movieinfo struct
- var movieinfo = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- movieinfo.Members.Add(new XmlRpcStructMember("moviename", new XmlRpcValueBasic(movieName)));
- movieinfo.Members.Add(new XmlRpcStructMember("movieyear", new XmlRpcValueBasic(movieyear)));
- parms.Add(movieinfo);
- // Call !
- var call = new XmlRpcMethodCall("InsertMovie", parms);
- OSHConsole.WriteLine("Sending InsertMovie request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseInsertMovie();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- if (MEMBER.Name == "status")
- {
- R.Status = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine("Status= " + R.Status);
- }
- else if (MEMBER.Name == "seconds")
- {
- R.Seconds = (double)MEMBER.Data.Data;
- OSHConsole.WriteLine("Seconds= " + R.Seconds);
- }
- else if (MEMBER.Name == "id")
- {
- R.ID = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine("ID= " + R.Seconds);
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "InsertMovie call failed !");
- }
- /// <summary>
- /// Inserts or updates data to tables, which are used for CheckMovieHash() and !CheckMovieHash2().
- /// </summary>
- /// <param name="parameters">The parameters</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseInsertMovieHash'</returns>
- public static IMethodResponse InsertMovieHash(InsertMovieHashParameters[] parameters)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- foreach (InsertMovieHashParameters p in parameters)
- {
- var pstruct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- pstruct.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(p.moviehash)));
- pstruct.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(p.moviebytesize)));
- pstruct.Members.Add(new XmlRpcStructMember("imdbid", new XmlRpcValueBasic(p.imdbid)));
- pstruct.Members.Add(new XmlRpcStructMember("movietimems", new XmlRpcValueBasic(p.movietimems)));
- pstruct.Members.Add(new XmlRpcStructMember("moviefps", new XmlRpcValueBasic(p.moviefps)));
- pstruct.Members.Add(new XmlRpcStructMember("moviefilename", new XmlRpcValueBasic(p.moviefilename)));
- parms.Add(pstruct);
- }
- var call = new XmlRpcMethodCall("InsertMovieHash", parms);
-
- OSHConsole.WriteLine("Sending InsertMovieHash request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseInsertMovieHash();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status":
- R.Status = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "seconds":
- R.Seconds = (double)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "data":
- var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
- foreach (XmlRpcStructMember dataMember in dataStruct.Members)
- {
- switch (dataMember.Name)
- {
- case "accepted_moviehashes":
- var mh = (XmlRpcValueArray)dataMember.Data;
- foreach (IXmlRpcValue val in mh.Values)
- {
- if (val is XmlRpcValueBasic)
- {
- R.accepted_moviehashes.Add(val.Data.ToString());
- }
- }
- break;
- case "new_imdbs":
- var mi = (XmlRpcValueArray)dataMember.Data;
- foreach (IXmlRpcValue val in mi.Values)
- {
- if (val is XmlRpcValueBasic)
- {
- R.new_imdbs.Add(val.Data.ToString());
- }
- }
- break;
- }
- }
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "InsertMovieHash call failed !");
- }
- /*Reporting and rating*/
- /// <summary>
- /// Get basic server information and statistics
- /// </summary>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseServerInfo'</returns>
- public static IMethodResponse ServerInfo()
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT, XmlRpcBasicValueType.String));
- var call = new XmlRpcMethodCall("ServerInfo", parms);
-
- OSHConsole.WriteLine("Sending ServerInfo request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseServerInfo();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status":
- R.Status = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "seconds":
- R.Seconds = (double)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "xmlrpc_version":
- R.xmlrpc_version = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "xmlrpc_url":
- R.xmlrpc_url = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "application":
- R.application = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "contact":
- R.contact = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "website_url":
- R.website_url = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "users_online_total":
- R.users_online_total = (int)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "users_online_program":
- R.users_online_program = (int)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "users_loggedin":
- R.users_loggedin = (int)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "users_max_alltime":
- R.users_max_alltime = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "users_registered":
- R.users_registered = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "subs_downloads":
- R.subs_downloads = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "subs_subtitle_files":
- R.subs_subtitle_files = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "movies_total":
- R.movies_total = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "movies_aka":
- R.movies_aka = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "total_subtitles_languages":
- R.total_subtitles_languages = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "last_update_strings":
- //R.total_subtitles_languages = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + ":");
- var luStruct = (XmlRpcValueStruct)MEMBER.Data;
- foreach (XmlRpcStructMember luMemeber in luStruct.Members)
- {
- R.last_update_strings.Add(luMemeber.Name + " [" + luMemeber.Data.Data.ToString() + "]");
- OSHConsole.WriteLine(" >" + luMemeber.Name + "= " + luMemeber.Data.Data.ToString());
- }
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "ServerInfo call failed !");
- }
- /// <summary>
- /// Report wrong subtitle file <--> video file combination
- /// </summary>
- /// <param name="IDSubMovieFile">Identifier of the subtitle file <--> video file combination </param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseReportWrongMovieHash'</returns>
- public static IMethodResponse ReportWrongMovieHash(string IDSubMovieFile)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- parms.Add(new XmlRpcValueBasic(IDSubMovieFile, XmlRpcBasicValueType.String));
- var call = new XmlRpcMethodCall("ReportWrongMovieHash", parms);
-
- OSHConsole.WriteLine("Sending ReportWrongMovieHash request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseReportWrongMovieHash();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status":
- R.Status = (string)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- case "seconds":
- R.Seconds = (double)MEMBER.Data.Data;
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "ReportWrongMovieHash call failed !");
- }
- /// <summary>
- /// This method is needed to report bad movie hash for imdbid. This method should be used for correcting wrong entries,
- /// when using CheckMovieHash2. Pass moviehash and moviebytesize for file, and imdbid as new, corrected one IMDBID
- /// (id number without trailing zeroes). After some reports, moviehash will be linked to new imdbid.
- /// </summary>
- /// <param name="moviehash">The movie hash</param>
- /// <param name="moviebytesize">The movie size in bytes</param>
- /// <param name="imdbid">The movie imbid</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseReportWrongImdbMovie'</returns>
- public static IMethodResponse ReportWrongImdbMovie(string moviehash, string moviebytesize, string imdbid)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- s.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(moviehash)));
- s.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(moviebytesize)));
- s.Members.Add(new XmlRpcStructMember("imdbid", new XmlRpcValueBasic(imdbid)));
- parms.Add(s);
- var call = new XmlRpcMethodCall("ReportWrongImdbMovie", parms);
-
- OSHConsole.WriteLine("Sending ReportWrongImdbMovie request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseAddComment();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "ReportWrongImdbMovie call failed !");
- }
- /// <summary>
- /// Rate subtitles
- /// </summary>
- /// <param name="idsubtitle">Id of subtitle (NOT subtitle file) user wants to rate </param>
- /// <param name="score">Subtitle rating, must be in interval 1 (worst) to 10 (best). </param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitlesVote'</returns>
- public static IMethodResponse SubtitlesVote(int idsubtitle, int score)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- s.Members.Add(new XmlRpcStructMember("idsubtitle", new XmlRpcValueBasic(idsubtitle)));
- s.Members.Add(new XmlRpcStructMember("score", new XmlRpcValueBasic(score)));
- parms.Add(s);
- var call = new XmlRpcMethodCall("SubtitlesVote", parms);
-
- OSHConsole.WriteLine("Sending SubtitlesVote request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseSubtitlesVote();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "data":
- var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
- foreach (XmlRpcStructMember dataMemeber in dataStruct.Members)
- {
- OSHConsole.WriteLine(" >" + dataMemeber.Name + "= " + dataMemeber.Data.Data.ToString());
- switch (dataMemeber.Name)
- {
- case "SubRating": R.SubRating = dataMemeber.Data.Data.ToString(); break;
- case "SubSumVotes": R.SubSumVotes = dataMemeber.Data.Data.ToString(); break;
- case "IDSubtitle": R.IDSubtitle = dataMemeber.Data.Data.ToString(); break;
- }
- }
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "SubtitlesVote call failed !");
- }
- /// <summary>
- /// Add comment to a subtitle
- /// </summary>
- /// <param name="idsubtitle">Subtitle identifier (BEWARE! this is not the ID of subtitle file but of the whole subtitle (a subtitle can contain multiple subtitle files))</param>
- /// <param name="comment">User's comment</param>
- /// <param name="badsubtitle">Optional parameter. If set to 1, subtitles are marked as bad.</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseAddComment'</returns>
- public static IMethodResponse AddComment(int idsubtitle, string comment, int badsubtitle)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- s.Members.Add(new XmlRpcStructMember("idsubtitle", new XmlRpcValueBasic(idsubtitle)));
- s.Members.Add(new XmlRpcStructMember("comment", new XmlRpcValueBasic(comment)));
- s.Members.Add(new XmlRpcStructMember("badsubtitle", new XmlRpcValueBasic(badsubtitle)));
- parms.Add(s);
- var call = new XmlRpcMethodCall("AddComment", parms);
-
- OSHConsole.WriteLine("Sending AddComment request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseAddComment();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (var MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "AddComment call failed !");
- }
- /// <summary>
- /// Add new request for subtitles, user must be logged in
- /// </summary>
- /// <param name="sublanguageid">The subtitle language id 3 length</param>
- /// <param name="idmovieimdb">http://www.imdb.com/</param>
- /// <param name="comment">The comment</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseAddRequest'</returns>
- public static IMethodResponse AddRequest(string sublanguageid, string idmovieimdb, string comment)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- s.Members.Add(new XmlRpcStructMember("sublanguageid", new XmlRpcValueBasic(sublanguageid)));
- s.Members.Add(new XmlRpcStructMember("idmovieimdb", new XmlRpcValueBasic(idmovieimdb)));
- s.Members.Add(new XmlRpcStructMember("comment", new XmlRpcValueBasic(comment)));
- parms.Add(s);
- var call = new XmlRpcMethodCall("AddRequest", parms);
-
- OSHConsole.WriteLine("Sending AddRequest request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseAddRequest();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "data":
- var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
- foreach (XmlRpcStructMember dataMemeber in dataStruct.Members)
- {
- switch (dataMemeber.Name)
- {
- case "request_url": R.request_url = dataMemeber.Data.Data.ToString(); OSHConsole.WriteLine(">" + dataMemeber.Name + "= " + dataMemeber.Data.Data.ToString()); break;
- }
- }
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "AddRequest call failed !");
- }
- /*User interface*/
- /// <summary>
- /// Get list of supported subtitle languages
- /// </summary>
- /// <param name="language">ISO639-1 2-letter language code of user's interface language. </param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetSubLanguages'</returns>
- public static IMethodResponse GetSubLanguages(string language)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN));
- parms.Add(new XmlRpcValueBasic(language));
- var call = new XmlRpcMethodCall("GetSubLanguages", parms);
-
- OSHConsole.WriteLine("Sending GetSubLanguages request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseGetSubLanguages();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "data":// array of structs
- var array = (XmlRpcValueArray)MEMBER.Data;
- foreach (IXmlRpcValue value in array.Values)
- {
- if (value is XmlRpcValueStruct)
- {
- var valueStruct = (XmlRpcValueStruct)value;
- var lang = new SubtitleLanguage();
- OSHConsole.WriteLine(">SubLanguage:");
- foreach (XmlRpcStructMember langMemeber in valueStruct.Members)
- {
- OSHConsole.WriteLine(" >" + langMemeber.Name + "= " + langMemeber.Data.Data.ToString());
- switch (langMemeber.Name)
- {
- case "SubLanguageID": lang.SubLanguageID = langMemeber.Data.Data.ToString(); break;
- case "LanguageName": lang.LanguageName = langMemeber.Data.Data.ToString(); break;
- case "ISO639": lang.ISO639 = langMemeber.Data.Data.ToString(); break;
- }
- }
- R.Languages.Add(lang);
- }
- else
- {
- OSHConsole.WriteLine(">" + MEMBER.Name + "= " +
- MEMBER.Data.Data.ToString() + " [Struct expected !]", DebugCode.Warning);
- }
- }
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "GetSubLanguages call failed !");
- }
- /// <summary>
- /// Detect language for given strings
- /// </summary>
- /// <param name="texts">Array of strings you want language detected for</param>
- /// <param name="encodingUsed">The encoding that will be used to get buffer of given strings. (this is not OS official parameter)</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseDetectLanguage'</returns>
- public static IMethodResponse DetectLanguage(string[] texts, Encoding encodingUsed)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- // We need to gzip texts then code them with base 24
- var decodedTexts = new List<string>();
- foreach (string text in texts)
- {
- // compress
- Stream str = new MemoryStream();
- byte[] stringData = encodingUsed.GetBytes(text);
- str.Write(stringData, 0, stringData.Length);
- str.Position = 0;
- byte[] data = Utilities.Compress(str);
- //base 64
- decodedTexts.Add(Convert.ToBase64String(data));
- }
- parms.Add(new XmlRpcValueArray(decodedTexts.ToArray()));
- var call = new XmlRpcMethodCall("DetectLanguage", parms);
-
- OSHConsole.WriteLine("Sending DetectLanguage request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseDetectLanguage();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "data":
- if (MEMBER.Data is XmlRpcValueStruct)
- {
- OSHConsole.WriteLine(">Languages:");
- var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
- foreach (XmlRpcStructMember dataMember in dataStruct.Members)
- {
- var lang = new DetectLanguageResult();
- lang.InputSample = dataMember.Name;
- lang.LanguageID = dataMember.Data.Data.ToString();
- R.Results.Add(lang);
- OSHConsole.WriteLine(" >" + dataMember.Name + " (" + dataMember.Data.Data.ToString() + ")");
- }
- }
- else
- {
- OSHConsole.WriteLine(">Languages ?? Struct expected but server return another type!!", DebugCode.Warning);
- }
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "DetectLanguage call failed !");
- }
- /// <summary>
- /// Get available translations for given program
- /// </summary>
- /// <param name="program">Name of the program/client application you want translations for. Currently supported values: subdownloader, oscar</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetAvailableTranslations'</returns>
- public static IMethodResponse GetAvailableTranslations(string program)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN));
- parms.Add(new XmlRpcValueBasic(program));
- var call = new XmlRpcMethodCall("GetAvailableTranslations", parms);
-
- OSHConsole.WriteLine("Sending GetAvailableTranslations request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseGetAvailableTranslations();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "data":
- var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
- OSHConsole.WriteLine(">data:");
- foreach (XmlRpcStructMember dataMember in dataStruct.Members)
- {
- if (dataMember.Data is XmlRpcValueStruct)
- {
- var resStruct = (XmlRpcValueStruct)dataMember.Data;
- var res = new GetAvailableTranslationsResult();
- res.LanguageID = dataMember.Name;
- OSHConsole.WriteLine(" >LanguageID: " + dataMember.Name);
- foreach (XmlRpcStructMember resMember in resStruct.Members)
- {
- switch (resMember.Name)
- {
- case "LastCreated": res.LastCreated = resMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + resMember.Name + "= " + resMember.Data.Data.ToString()); break;
- case "StringsNo": res.StringsNo = resMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + resMember.Name + "= " + resMember.Data.Data.ToString()); break;
- }
- R.Results.Add(res);
- }
- }
- else
- {
- OSHConsole.WriteLine(" >Struct expected !!", DebugCode.Warning);
- }
- }
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "GetAvailableTranslations call failed !");
- }
- /// <summary>
- /// Get a translation for given program and language
- /// </summary>
- /// <param name="iso639">language ​ISO639-1 2-letter code </param>
- /// <param name="format">available formats: [gnugettext compatible: mo, po] and [additional: txt, xml]</param>
- /// <param name="program">Name of the program/client application you want translations for. (currently supported values: subdownloader, oscar)</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetTranslation'</returns>
- public static IMethodResponse GetTranslation(string iso639, string format, string program)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN));
- parms.Add(new XmlRpcValueBasic(iso639));
- parms.Add(new XmlRpcValueBasic(format));
- parms.Add(new XmlRpcValueBasic(program));
- var call = new XmlRpcMethodCall("GetTranslation", parms);
-
- OSHConsole.WriteLine("Sending GetTranslation request to the server ...", DebugCode.Good);
- // Send the request to the server
- //File.WriteAllText(".\\REQUEST_GetTranslation.xml", Encoding.ASCII.GetString(XmlRpcGenerator.Generate(call)));
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseGetTranslation();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "data": R.ContentData = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "GetTranslation call failed !");
- }
- /// <summary>
- /// Check for the latest version of given application
- /// </summary>
- /// <param name="program">name of the program/client application you want to check. (Currently supported values: subdownloader, oscar)</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseAutoUpdate'</returns>
- public static IMethodResponse AutoUpdate(string program)
- {
- /*if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }*/
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- // parms.Add(new XmlRpcValueBasic(TOKEN));
- parms.Add(new XmlRpcValueBasic(program));
- // parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT));
-
- var call = new XmlRpcMethodCall("AutoUpdate", parms);
- OSHConsole.WriteLine("Sending AutoUpdate request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseAutoUpdate();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "version": R.version = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "url_windows": R.url_windows = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "url_linux": R.url_linux = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "comments": R.comments = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "AutoUpdate call failed !");
- }
- /*Checking*/
- /// <summary>
- /// Check if video file hashes are already stored in the database
- /// </summary>
- /// <param name="hashes">Array of video file hashes</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseCheckMovieHash'</returns>
- public static IMethodResponse CheckMovieHash(string[] hashes)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN));
- parms.Add(new XmlRpcValueArray(hashes));
- var call = new XmlRpcMethodCall("CheckMovieHash", parms);
-
- OSHConsole.WriteLine("Sending CheckMovieHash request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseCheckMovieHash();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "data":
- var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
- OSHConsole.WriteLine(">Data:");
- foreach (XmlRpcStructMember dataMember in dataStruct.Members)
- {
- var res = new CheckMovieHashResult();
- res.Name = dataMember.Name;
- OSHConsole.WriteLine(" >" + res.Name + ":");
- var movieStruct = (XmlRpcValueStruct)dataMember.Data;
- foreach (XmlRpcStructMember movieMember in movieStruct.Members)
- {
- switch (movieMember.Name)
- {
- case "MovieHash": res.MovieHash = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- case "MovieImdbID": res.MovieImdbID = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- case "MovieName": res.MovieName = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- case "MovieYear": res.MovieYear = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- }
- }
- R.Results.Add(res);
- }
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "CheckMovieHash call failed !");
- }
- /// <summary>
- /// Check if video file hashes are already stored in the database. This method returns matching !MovieImdbID, MovieName, MovieYear, SeriesSeason, SeriesEpisode,
- /// MovieKind if available for each $moviehash, always sorted by SeenCount DESC.
- /// </summary>
- /// <param name="hashes">Array of video file hashes</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseCheckMovieHash2'</returns>
- public static IMethodResponse CheckMovieHash2(string[] hashes)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN));
- parms.Add(new XmlRpcValueArray(hashes));
- var call = new XmlRpcMethodCall("CheckMovieHash2", parms);
-
- OSHConsole.WriteLine("Sending CheckMovieHash2 request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseCheckMovieHash2();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "data":
- var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
- OSHConsole.WriteLine(">Data:");
- foreach (XmlRpcStructMember dataMember in dataStruct.Members)
- {
- var res = new CheckMovieHash2Result();
- res.Name = dataMember.Name;
- OSHConsole.WriteLine(" >" + res.Name + ":");
-
- var dataArray = (XmlRpcValueArray)dataMember.Data;
- foreach (XmlRpcValueStruct movieStruct in dataArray.Values)
- {
- var d = new CheckMovieHash2Data();
- foreach (XmlRpcStructMember movieMember in movieStruct.Members)
- {
- switch (movieMember.Name)
- {
- case "MovieHash": d.MovieHash = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- case "MovieImdbID": d.MovieImdbID = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- case "MovieName": d.MovieName = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- case "MovieYear": d.MovieYear = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- case "MovieKind": d.MovieKind = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- case "SeriesSeason": d.SeriesSeason = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- case "SeriesEpisode": d.SeriesEpisode = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- case "SeenCount": d.MovieYear = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
- }
- }
- res.Items.Add(d);
- }
- R.Results.Add(res);
- }
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "CheckMovieHash2 call failed !");
- }
- /// <summary>
- /// Check if given subtitle files are already stored in the database
- /// </summary>
- /// <param name="hashes">Array of subtitle file hashes (MD5 hashes of subtitle file contents) </param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseCheckSubHash'</returns>
- public static IMethodResponse CheckSubHash(string[] hashes)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN));
- parms.Add(new XmlRpcValueArray(hashes));
- var call = new XmlRpcMethodCall("CheckSubHash", parms);
-
- OSHConsole.WriteLine("Sending CheckSubHash request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseCheckSubHash();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "data":
- OSHConsole.WriteLine(">Data:");
- var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
- foreach (XmlRpcStructMember dataMember in dataStruct.Members)
- {
- OSHConsole.WriteLine(" >" + dataMember.Name + "= " + dataMember.Data.Data.ToString());
- var r = new CheckSubHashResult();
- r.Hash = dataMember.Name;
- r.SubID = dataMember.Data.Data.ToString();
- R.Results.Add(r);
- }
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "CheckSubHash call failed !");
- }
- /*Upload*/
- /// <summary>
- /// Try to upload subtitles, perform pre-upload checking (i.e. check if subtitles already exist on server)
- /// </summary>
- /// <param name="subs">The subtitle parameters collection to try to upload</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseTryUploadSubtitles'</returns>
- public static IMethodResponse TryUploadSubtitles(TryUploadSubtitlesParameters[] subs)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
- var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- int i = 1;
- foreach (var cd in subs)
- {
- var member = new XmlRpcStructMember("cd" + i, null);
- var memberStruct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- memberStruct.Members.Add(new XmlRpcStructMember("subhash", new XmlRpcValueBasic(cd.subhash)));
- memberStruct.Members.Add(new XmlRpcStructMember("subfilename", new XmlRpcValueBasic(cd.subfilename)));
- memberStruct.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(cd.moviehash)));
- memberStruct.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(cd.moviebytesize)));
- memberStruct.Members.Add(new XmlRpcStructMember("moviefps", new XmlRpcValueBasic(cd.moviefps)));
- memberStruct.Members.Add(new XmlRpcStructMember("movietimems", new XmlRpcValueBasic(cd.movietimems)));
- memberStruct.Members.Add(new XmlRpcStructMember("movieframes", new XmlRpcValueBasic(cd.movieframes)));
- memberStruct.Members.Add(new XmlRpcStructMember("moviefilename", new XmlRpcValueBasic(cd.moviefilename)));
- member.Data = memberStruct;
- s.Members.Add(member);
- i++;
- }
- parms.Add(s);
- var call = new XmlRpcMethodCall("TryUploadSubtitles", parms);
-
- OSHConsole.WriteLine("Sending TryUploadSubtitles request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseTryUploadSubtitles();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "alreadyindb": R.AlreadyInDB = (int)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "data":
- if (MEMBER.Data is XmlRpcValueArray)
- {
- OSHConsole.WriteLine("Results: ");
-
- var rarray = (XmlRpcValueArray)MEMBER.Data;
- foreach (IXmlRpcValue subStruct in rarray.Values)
- {
- if (subStruct == null) continue;
- if (!(subStruct is XmlRpcValueStruct)) continue;
-
- var result = new SubtitleSearchResult();
- foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
- {
- // To avoid errors of arranged info or missing ones, let's do it with switch..
- switch (submember.Name)
- {
- case "IDMovie": result.IDMovie = submember.Data.Data.ToString(); break;
- case "IDMovieImdb": result.IDMovieImdb = submember.Data.Data.ToString(); break;
- case "IDSubMovieFile": result.IDSubMovieFile = submember.Data.Data.ToString(); break;
- case "IDSubtitle": result.IDSubtitle = submember.Data.Data.ToString(); break;
- case "IDSubtitleFile": result.IDSubtitleFile = submember.Data.Data.ToString(); break;
- case "ISO639": result.ISO639 = submember.Data.Data.ToString(); break;
- case "LanguageName": result.LanguageName = submember.Data.Data.ToString(); break;
- case "MovieByteSize": result.MovieByteSize = submember.Data.Data.ToString(); break;
- case "MovieHash": result.MovieHash = submember.Data.Data.ToString(); break;
- case "MovieImdbRating": result.MovieImdbRating = submember.Data.Data.ToString(); break;
- case "MovieName": result.MovieName = submember.Data.Data.ToString(); break;
- case "MovieNameEng": result.MovieNameEng = submember.Data.Data.ToString(); break;
- case "MovieReleaseName": result.MovieReleaseName = submember.Data.Data.ToString(); break;
- case "MovieTimeMS": result.MovieTimeMS = submember.Data.Data.ToString(); break;
- case "MovieYear": result.MovieYear = submember.Data.Data.ToString(); break;
- case "SubActualCD": result.SubActualCD = submember.Data.Data.ToString(); break;
- case "SubAddDate": result.SubAddDate = submember.Data.Data.ToString(); break;
- case "SubAuthorComment": result.SubAuthorComment = submember.Data.Data.ToString(); break;
- case "SubBad": result.SubBad = submember.Data.Data.ToString(); break;
- case "SubDownloadLink": result.SubDownloadLink = submember.Data.Data.ToString(); break;
- case "SubDownloadsCnt": result.SubDownloadsCnt = submember.Data.Data.ToString(); break;
- case "SubFileName": result.SubFileName = submember.Data.Data.ToString(); break;
- case "SubFormat": result.SubFormat = submember.Data.Data.ToString(); break;
- case "SubHash": result.SubHash = submember.Data.Data.ToString(); break;
- case "SubLanguageID": result.SubLanguageID = submember.Data.Data.ToString(); break;
- case "SubRating": result.SubRating = submember.Data.Data.ToString(); break;
- case "SubSize": result.SubSize = submember.Data.Data.ToString(); break;
- case "SubSumCD": result.SubSumCD = submember.Data.Data.ToString(); break;
- case "UserID": result.UserID = submember.Data.Data.ToString(); break;
- case "UserNickName": result.UserNickName = submember.Data.Data.ToString(); break;
- case "ZipDownloadLink": result.ZipDownloadLink = submember.Data.Data.ToString(); break;
- }
- }
- R.Results.Add(result);
- OSHConsole.WriteLine(">" + result.ToString());
- }
- }
- else// Unknown data ?
- {
- OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
- }
- break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "TryUploadSubtitles call failed !");
- }
- /// <summary>
- /// Upload given subtitles to OSDb server
- /// </summary>
- /// <param name="info">The pamaters of upload method</param>
- /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseUploadSubtitles'</returns>
- public static IMethodResponse UploadSubtitles(UploadSubtitleInfoParameters info)
- {
- if (TOKEN == "")
- {
- OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
- return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
- }
- // Method call ..
- var parms = new List<IXmlRpcValue>();
- parms.Add(new XmlRpcValueBasic(TOKEN));
- // Main struct
- var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
-
- // Base info member as struct
- var member = new XmlRpcStructMember("baseinfo", null);
- var memberStruct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- memberStruct.Members.Add(new XmlRpcStructMember("idmovieimdb", new XmlRpcValueBasic(info.idmovieimdb)));
- memberStruct.Members.Add(new XmlRpcStructMember("sublanguageid", new XmlRpcValueBasic(info.sublanguageid)));
- memberStruct.Members.Add(new XmlRpcStructMember("moviereleasename", new XmlRpcValueBasic(info.moviereleasename)));
- memberStruct.Members.Add(new XmlRpcStructMember("movieaka", new XmlRpcValueBasic(info.movieaka)));
- memberStruct.Members.Add(new XmlRpcStructMember("subauthorcomment", new XmlRpcValueBasic(info.subauthorcomment)));
- // memberStruct.Members.Add(new XmlRpcStructMember("hearingimpaired", new XmlRpcValueBasic(info.hearingimpaired)));
- // memberStruct.Members.Add(new XmlRpcStructMember("highdefinition", new XmlRpcValueBasic(info.highdefinition)));
- // memberStruct.Members.Add(new XmlRpcStructMember("automatictranslation", new XmlRpcValueBasic(info.automatictranslation)));
- member.Data = memberStruct;
- s.Members.Add(member);
-
- // CDS members
- int i = 1;
- foreach (UploadSubtitleParameters cd in info.CDS)
- {
- var member2 = new XmlRpcStructMember("cd" + i, null);
- var memberStruct2 = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- memberStruct2.Members.Add(new XmlRpcStructMember("subhash", new XmlRpcValueBasic(cd.subhash)));
- memberStruct2.Members.Add(new XmlRpcStructMember("subfilename", new XmlRpcValueBasic(cd.subfilename)));
- memberStruct2.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(cd.moviehash)));
- memberStruct2.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(cd.moviebytesize)));
- memberStruct2.Members.Add(new XmlRpcStructMember("moviefps", new XmlRpcValueBasic(cd.moviefps)));
- memberStruct2.Members.Add(new XmlRpcStructMember("movietimems", new XmlRpcValueBasic(cd.movietimems)));
- memberStruct2.Members.Add(new XmlRpcStructMember("movieframes", new XmlRpcValueBasic(cd.movieframes)));
- memberStruct2.Members.Add(new XmlRpcStructMember("moviefilename", new XmlRpcValueBasic(cd.moviefilename)));
- memberStruct2.Members.Add(new XmlRpcStructMember("subcontent", new XmlRpcValueBasic(cd.subcontent)));
- member2.Data = memberStruct2;
- s.Members.Add(member2);
- i++;
- }
-
- // add main struct to parameters
- parms.Add(s);
- // add user agent
- //parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT));
- var call = new XmlRpcMethodCall("UploadSubtitles", parms);
- OSHConsole.WriteLine("Sending UploadSubtitles request to the server ...", DebugCode.Good);
- // Send the request to the server
- string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
- if (!response.Contains("ERROR:"))
- {
- // No error occur, get and decode the response.
- XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
- if (calls.Length > 0)
- {
- if (calls[0].Parameters.Count > 0)
- {
- var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
- // Create the response, we'll need it later
- var R = new MethodResponseUploadSubtitles();
-
- // To make sure response is not currepted by server, do it in loop
- foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
- {
- switch (MEMBER.Name)
- {
- case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "data": R.Data = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- case "subtitles": R.SubTitles = (bool)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
- }
- }
- // Return the response to user !!
- return R;
- }
- }
- }
- else
- {
- OSHConsole.WriteLine(response, DebugCode.Error);
- return new MethodResponseError("Fail", response);
- }
- return new MethodResponseError("Fail", "UploadSubtitles call failed !");
- }
- }
-}
diff --git a/OpenSubtitlesHandler/OpenSubtitlesHandler.csproj b/OpenSubtitlesHandler/OpenSubtitlesHandler.csproj
deleted file mode 100644
index eabd3e070..000000000
--- a/OpenSubtitlesHandler/OpenSubtitlesHandler.csproj
+++ /dev/null
@@ -1,13 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
- <ItemGroup>
- <ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
- <ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
- </ItemGroup>
-
- <PropertyGroup>
- <TargetFramework>netstandard2.0</TargetFramework>
- <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
- </PropertyGroup>
-
-</Project>
diff --git a/OpenSubtitlesHandler/OtherTypes/GetAvailableTranslationsResult.cs b/OpenSubtitlesHandler/OtherTypes/GetAvailableTranslationsResult.cs
deleted file mode 100644
index 39d048545..000000000
--- a/OpenSubtitlesHandler/OtherTypes/GetAvailableTranslationsResult.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-namespace OpenSubtitlesHandler
-{
- public struct GetAvailableTranslationsResult
- {
- private string _language;
- private string _LastCreated;
- private string _StringsNo;
-
- public string LanguageID { get { return _language; } set { _language = value; } }
- public string LastCreated { get { return _LastCreated; } set { _LastCreated = value; } }
- public string StringsNo { get { return _StringsNo; } set { _StringsNo = value; } }
- /// <summary>
- /// LanguageID (LastCreated)
- /// </summary>
- /// <returns></returns>
- public override string ToString()
- {
- return _language + " (" + _LastCreated + ")";
- }
- }
-}
diff --git a/OpenSubtitlesHandler/OtherTypes/GetCommentsResult.cs b/OpenSubtitlesHandler/OtherTypes/GetCommentsResult.cs
deleted file mode 100644
index 8f4aa9db4..000000000
--- a/OpenSubtitlesHandler/OtherTypes/GetCommentsResult.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- public struct GetCommentsResult
- {
- private string _IDSubtitle;
- private string _UserID;
- private string _UserNickName;
- private string _Comment;
- private string _Created;
-
- public string IDSubtitle { get { return _IDSubtitle; } set { _IDSubtitle = value; } }
- public string UserID { get { return _UserID; } set { _UserID = value; } }
- public string UserNickName { get { return _UserNickName; } set { _UserNickName = value; } }
- public string Comment { get { return _Comment; } set { _Comment = value; } }
- public string Created { get { return _Created; } set { _Created = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/Properties/AssemblyInfo.cs b/OpenSubtitlesHandler/Properties/AssemblyInfo.cs
deleted file mode 100644
index b5ae23021..000000000
--- a/OpenSubtitlesHandler/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System.Reflection;
-using System.Resources;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("OpenSubtitlesHandler")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2013 Ala Ibrahim Hadid. Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-[assembly: NeutralResourcesLanguage("en")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-[assembly: AssemblyVersion("1.0.3.0")]
-[assembly: AssemblyFileVersion("2019.1.20.3")]
diff --git a/OpenSubtitlesHandler/Readme.txt b/OpenSubtitlesHandler/Readme.txt
deleted file mode 100644
index d5814aec1..000000000
--- a/OpenSubtitlesHandler/Readme.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-OpenSubtitlesHandler
-====================
-This project is for OpenSubtitles.org integration‏. The point is to allow user to access OpenSubtitles.org database directly
-within ASM without the need to open internet browser.
-The plan: Implement the "OSDb protocol" http://trac.opensubtitles.org/projects/opensubtitles/wiki/OSDb
-
-Copyright:
-=========
-This library ann all its content are written by Ala Ibrahim Hadid.
-Copyright © Ala Ibrahim Hadid 2013
-mailto:ahdsoftwares@hotmail.com
-
-Resources:
-==========
-* GetHash.dll: this dll is used to compute hash for movie.
- For more information please visit http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes#C2
-
-XML_RPC:
-========
-This class is created to generate XML-RPC requests as XML String. All you need is to call XML_RPC.Generate() method.
diff --git a/OpenSubtitlesHandler/SubtitleTypes/CheckSubHashResult.cs b/OpenSubtitlesHandler/SubtitleTypes/CheckSubHashResult.cs
deleted file mode 100644
index a2fbe8773..000000000
--- a/OpenSubtitlesHandler/SubtitleTypes/CheckSubHashResult.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- public struct CheckSubHashResult
- {
- private string _hash;
- private string _id;
-
- public string Hash { get { return _hash; } set { _hash = value; } }
- public string SubID { get { return _id; } set { _id = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleDownloadResult.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleDownloadResult.cs
deleted file mode 100644
index e4194994c..000000000
--- a/OpenSubtitlesHandler/SubtitleTypes/SubtitleDownloadResult.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- public struct SubtitleDownloadResult
- {
- private string idsubtitlefile;
- private string data;
-
- public string IdSubtitleFile
- { get { return idsubtitlefile; } set { idsubtitlefile = value; } }
- /// <summary>
- /// Get or set the data of subtitle file. To decode, decode the string to base64 and then decompress with GZIP.
- /// </summary>
- public string Data
- { get { return data; } set { data = value; } }
- /// <summary>
- /// IdSubtitleFile
- /// </summary>
- /// <returns></returns>
- public override string ToString()
- {
- return idsubtitlefile.ToString();
- }
- }
-}
diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleLanguage.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleLanguage.cs
deleted file mode 100644
index b2dc15413..000000000
--- a/OpenSubtitlesHandler/SubtitleTypes/SubtitleLanguage.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-namespace OpenSubtitlesHandler
-{
- public struct SubtitleLanguage
- {
- private string _SubLanguageID;
- private string _LanguageName;
- private string _ISO639;
-
- public string SubLanguageID { get { return _SubLanguageID; } set { _SubLanguageID = value; } }
- public string LanguageName { get { return _LanguageName; } set { _LanguageName = value; } }
- public string ISO639 { get { return _ISO639; } set { _ISO639 = value; } }
- /// <summary>
- /// LanguageName [SubLanguageID]
- /// </summary>
- /// <returns>LanguageName [SubLanguageID]</returns>
- public override string ToString()
- {
- return _LanguageName + " [" + _SubLanguageID + "]";
- }
- }
-}
diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs
deleted file mode 100644
index 5c8f8c01a..000000000
--- a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- /// <summary>
- /// Paramaters for subtitle search call
- /// </summary>
- public struct SubtitleSearchParameters
- {
- public SubtitleSearchParameters(string subLanguageId, string query = "", string season = "", string episode = "", string movieHash = "", long movieByteSize = 0, string imdbid = "")
- {
- this.subLanguageId = subLanguageId;
- this.movieHash = movieHash;
- this.movieByteSize = movieByteSize;
- this.imdbid = imdbid;
- this._episode = episode;
- this._season = season;
- this._query = query;
- }
-
- private string subLanguageId;
- private string movieHash;
- private long movieByteSize;
- private string imdbid;
- private string _query;
- private string _episode;
-
- public string Episode
- {
- get { return _episode; }
- set { _episode = value; }
- }
-
- public string Season
- {
- get { return _season; }
- set { _season = value; }
- }
-
- private string _season;
-
- public string Query
- {
- get { return _query; }
- set { _query = value; }
- }
-
- /// <summary>
- /// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo')
- /// </summary>
- public string SubLangaugeID { get { return subLanguageId; } set { subLanguageId = value; } }
- /// <summary>
- /// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes
- /// </summary>
- public string MovieHash { get { return movieHash; } set { movieHash = value; } }
- /// <summary>
- /// Size of video file in bytes
- /// </summary>
- public long MovieByteSize { get { return movieByteSize; } set { movieByteSize = value; } }
- /// <summary>
- /// ​IMDb ID of movie this video is part of, belongs to.
- /// </summary>
- public string IMDbID { get { return imdbid; } set { imdbid = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchResult.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchResult.cs
deleted file mode 100644
index a4a8dd3e6..000000000
--- a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchResult.cs
+++ /dev/null
@@ -1,136 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- /// <summary>
- /// The subtitle search result that comes with server response on SearchSubtitles successed call
- /// </summary>
- public struct SubtitleSearchResult
- {
- private string _IDSubMovieFile;
- private string _MovieHash;
- private string _MovieByteSize;
- private string _MovieTimeMS;
- private string _IDSubtitleFile;
- private string _SubFileName;
- private string _SubActualCD;
- private string _SubSize;
- private string _SubHash;
- private string _IDSubtitle;
- private string _UserID;
- private string _SubLanguageID;
- private string _SubFormat;
- private string _SeriesSeason;
- private string _SeriesEpisode;
- private string _SubSumCD;
- private string _SubAuthorComment;
- private string _SubAddDate;
- private string _SubBad;
- private string _SubRating;
- private string _SubDownloadsCnt;
- private string _MovieReleaseName;
- private string _IDMovie;
- private string _IDMovieImdb;
- private string _MovieName;
- private string _MovieNameEng;
- private string _MovieYear;
- private string _MovieImdbRating;
- private string _UserNickName;
- private string _ISO639;
- private string _LanguageName;
- private string _SubDownloadLink;
- private string _ZipDownloadLink;
-
- public string IDSubMovieFile
- { get { return _IDSubMovieFile; } set { _IDSubMovieFile = value; } }
- public string MovieHash
- { get { return _MovieHash; } set { _MovieHash = value; } }
- public string MovieByteSize
- { get { return _MovieByteSize; } set { _MovieByteSize = value; } }
- public string MovieTimeMS
- { get { return _MovieTimeMS; } set { _MovieTimeMS = value; } }
- public string IDSubtitleFile
- { get { return _IDSubtitleFile; } set { _IDSubtitleFile = value; } }
- public string SubFileName
- { get { return _SubFileName; } set { _SubFileName = value; } }
- public string SubActualCD
- { get { return _SubActualCD; } set { _SubActualCD = value; } }
- public string SubSize
- { get { return _SubSize; } set { _SubSize = value; } }
- public string SubHash
- { get { return _SubHash; } set { _SubHash = value; } }
- public string IDSubtitle
- { get { return _IDSubtitle; } set { _IDSubtitle = value; } }
- public string UserID
- { get { return _UserID; } set { _UserID = value; } }
- public string SubLanguageID
- { get { return _SubLanguageID; } set { _SubLanguageID = value; } }
- public string SubFormat
- { get { return _SubFormat; } set { _SubFormat = value; } }
- public string SubSumCD
- { get { return _SubSumCD; } set { _SubSumCD = value; } }
- public string SubAuthorComment
- { get { return _SubAuthorComment; } set { _SubAuthorComment = value; } }
- public string SubAddDate
- { get { return _SubAddDate; } set { _SubAddDate = value; } }
- public string SubBad
- { get { return _SubBad; } set { _SubBad = value; } }
- public string SubRating
- { get { return _SubRating; } set { _SubRating = value; } }
- public string SubDownloadsCnt
- { get { return _SubDownloadsCnt; } set { _SubDownloadsCnt = value; } }
- public string MovieReleaseName
- { get { return _MovieReleaseName; } set { _MovieReleaseName = value; } }
- public string IDMovie
- { get { return _IDMovie; } set { _IDMovie = value; } }
- public string IDMovieImdb
- { get { return _IDMovieImdb; } set { _IDMovieImdb = value; } }
- public string MovieName
- { get { return _MovieName; } set { _MovieName = value; } }
- public string MovieNameEng
- { get { return _MovieNameEng; } set { _MovieNameEng = value; } }
- public string MovieYear
- { get { return _MovieYear; } set { _MovieYear = value; } }
- public string MovieImdbRating
- { get { return _MovieImdbRating; } set { _MovieImdbRating = value; } }
- public string UserNickName
- { get { return _UserNickName; } set { _UserNickName = value; } }
- public string ISO639
- { get { return _ISO639; } set { _ISO639 = value; } }
- public string LanguageName
- { get { return _LanguageName; } set { _LanguageName = value; } }
- public string SubDownloadLink
- { get { return _SubDownloadLink; } set { _SubDownloadLink = value; } }
- public string ZipDownloadLink
- { get { return _ZipDownloadLink; } set { _ZipDownloadLink = value; } }
- public string SeriesSeason
- { get { return _SeriesSeason; } set { _SeriesSeason = value; } }
- public string SeriesEpisode
- { get { return _SeriesEpisode; } set { _SeriesEpisode = value; } }
- /// <summary>
- /// SubFileName + " (" + SubFormat + ")"
- /// </summary>
- /// <returns></returns>
- public override string ToString()
- {
- return _SubFileName + " (" + _SubFormat + ")";
- }
- }
-}
diff --git a/OpenSubtitlesHandler/SubtitleTypes/TryUploadSubtitlesParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/TryUploadSubtitlesParameters.cs
deleted file mode 100644
index 11f3a706c..000000000
--- a/OpenSubtitlesHandler/SubtitleTypes/TryUploadSubtitlesParameters.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- public class TryUploadSubtitlesParameters
- {
- private string _subhash = "";
- private string _subfilename = "";
- private string _moviehash = "";
- private string _moviebytesize = "";
- private int _movietimems = 0;
- private int _movieframes = 0;
- private double _moviefps = 0;
- private string _moviefilename = "";
-
- public string subhash { get { return _subhash; } set { _subhash = value; } }
- public string subfilename { get { return _subfilename; } set { _subfilename = value; } }
- public string moviehash { get { return _moviehash; } set { _moviehash = value; } }
- public string moviebytesize { get { return _moviebytesize; } set { _moviebytesize = value; } }
- public int movietimems { get { return _movietimems; } set { _movietimems = value; } }
- public int movieframes { get { return _movieframes; } set { _movieframes = value; } }
- public double moviefps { get { return _moviefps; } set { _moviefps = value; } }
- public string moviefilename { get { return _moviefilename; } set { _moviefilename = value; } }
-
- public override string ToString()
- {
- return _subfilename + " (" + _subhash + ")";
- }
- }
-}
diff --git a/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleInfoParameter.cs b/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleInfoParameter.cs
deleted file mode 100644
index 133cc1d23..000000000
--- a/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleInfoParameter.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace OpenSubtitlesHandler
-{
- public class UploadSubtitleInfoParameters
- {
- private string _idmovieimdb;
- private string _moviereleasename;
- private string _movieaka;
- private string _sublanguageid;
- private string _subauthorcomment;
- private bool _hearingimpaired;
- private bool _highdefinition;
- private bool _automatictranslation;
- private List<UploadSubtitleParameters> cds;
-
- public string idmovieimdb { get { return _idmovieimdb; } set { _idmovieimdb = value; } }
- public string moviereleasename { get { return _moviereleasename; } set { _moviereleasename = value; } }
- public string movieaka { get { return _movieaka; } set { _movieaka = value; } }
- public string sublanguageid { get { return _sublanguageid; } set { _sublanguageid = value; } }
- public string subauthorcomment { get { return _subauthorcomment; } set { _subauthorcomment = value; } }
- public bool hearingimpaired { get { return _hearingimpaired; } set { _hearingimpaired = value; } }
- public bool highdefinition { get { return _highdefinition; } set { _highdefinition = value; } }
- public bool automatictranslation { get { return _automatictranslation; } set { _automatictranslation = value; } }
- public List<UploadSubtitleParameters> CDS { get { return cds; } set { cds = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleParameters.cs
deleted file mode 100644
index 9910dadc5..000000000
--- a/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleParameters.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace OpenSubtitlesHandler
-{
- public struct UploadSubtitleParameters
- {
- private string _subhash;
- private string _subfilename;
- private string _moviehash;
- private double _moviebytesize;
- private int _movietimems;
- private int _movieframes;
- private double _moviefps;
- private string _moviefilename;
- private string _subcontent;
-
- public string subhash { get { return _subhash; } set { _subhash = value; } }
- public string subfilename { get { return _subfilename; } set { _subfilename = value; } }
- public string moviehash { get { return _moviehash; } set { _moviehash = value; } }
- public double moviebytesize { get { return _moviebytesize; } set { _moviebytesize = value; } }
- public int movietimems { get { return _movietimems; } set { _movietimems = value; } }
- public int movieframes { get { return _movieframes; } set { _movieframes = value; } }
- public double moviefps { get { return _moviefps; } set { _moviefps = value; } }
- public string moviefilename { get { return _moviefilename; } set { _moviefilename = value; } }
- /// <summary>
- /// Sub content. Note: this value must be the subtitle file gziped and then base64 decoded.
- /// </summary>
- public string subcontent { get { return _subcontent; } set { _subcontent = value; } }
-
- public override string ToString()
- {
- return _subfilename + " (" + _subhash + ")";
- }
- }
-}
diff --git a/OpenSubtitlesHandler/Utilities.cs b/OpenSubtitlesHandler/Utilities.cs
deleted file mode 100644
index 429e28a8f..000000000
--- a/OpenSubtitlesHandler/Utilities.cs
+++ /dev/null
@@ -1,174 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using MediaBrowser.Common.Net;
-using MediaBrowser.Model.Cryptography;
-
-namespace OpenSubtitlesHandler
-{
- /// <summary>
- /// Include helper methods. All member are statics.
- /// </summary>
- public sealed class Utilities
- {
- public static ICryptoProvider CryptographyProvider { get; set; }
- public static IHttpClient HttpClient { get; set; }
- private static string XML_RPC_SERVER = "https://api.opensubtitles.org/xml-rpc";
- //private static string XML_RPC_SERVER = "https://92.240.234.122/xml-rpc";
- private static string HostHeader = "api.opensubtitles.org:443";
-
- /// <summary>
- /// Compute movie hash
- /// </summary>
- /// <returns>The hash as Hexadecimal string</returns>
- public static string ComputeHash(Stream stream)
- {
- byte[] hash = MovieHasher.ComputeMovieHash(stream);
- return MovieHasher.ToHexadecimal(hash);
- }
- /// <summary>
- /// Decompress data using GZip
- /// </summary>
- /// <param name="dataToDecompress">The stream that hold the data</param>
- /// <returns>Bytes array of decompressed data</returns>
- public static byte[] Decompress(Stream dataToDecompress)
- {
- using (var target = new MemoryStream())
- {
- using (var decompressionStream = new System.IO.Compression.GZipStream(dataToDecompress, System.IO.Compression.CompressionMode.Decompress))
- {
- decompressionStream.CopyTo(target);
- }
- return target.ToArray();
- }
- }
-
- /// <summary>
- /// Compress data using GZip (the retunred buffer will be WITHOUT HEADER)
- /// </summary>
- /// <param name="dataToCompress">The stream that hold the data</param>
- /// <returns>Bytes array of compressed data WITHOUT HEADER bytes</returns>
- public static byte[] Compress(Stream dataToCompress)
- {
- /*using (var compressed = new MemoryStream())
- {
- using (var compressor = new System.IO.Compression.GZipStream(compressed,
- System.IO.Compression.CompressionMode.Compress))
- {
- dataToCompress.CopyTo(compressor);
- }
- // Get the compressed bytes only after closing the GZipStream
- return compressed.ToArray();
- }*/
- //using (var compressedOutput = new MemoryStream())
- //{
- // using (var compressedStream = new ZlibStream(compressedOutput,
- // Ionic.Zlib.CompressionMode.Compress,
- // CompressionLevel.Default, false))
- // {
- // var buffer = new byte[4096];
- // int byteCount;
- // do
- // {
- // byteCount = dataToCompress.Read(buffer, 0, buffer.Length);
-
- // if (byteCount > 0)
- // {
- // compressedStream.Write(buffer, 0, byteCount);
- // }
- // } while (byteCount > 0);
- // }
- // return compressedOutput.ToArray();
- //}
-
- throw new NotImplementedException();
- }
-
- /// <summary>
- /// Handle server response stream and decode it as given encoding string.
- /// </summary>
- /// <returns>The string of the stream after decode using given encoding</returns>
- public static string GetStreamString(Stream responseStream)
- {
- using (responseStream)
- {
- // Handle response, should be XML text.
- var data = new List<byte>();
- while (true)
- {
- int r = responseStream.ReadByte();
- if (r < 0)
- break;
- data.Add((byte)r);
- }
- var bytes = data.ToArray();
- return Encoding.ASCII.GetString(bytes, 0, bytes.Length);
- }
- }
-
- public static byte[] GetASCIIBytes(string text)
- {
- return Encoding.ASCII.GetBytes(text);
- }
-
- /// <summary>
- /// Send a request to the server
- /// </summary>
- /// <param name="request">The request buffer to send as bytes array.</param>
- /// <param name="userAgent">The user agent value.</param>
- /// <returns>Response of the server or stream of error message as string started with 'ERROR:' keyword.</returns>
- public static Stream SendRequest(byte[] request, string userAgent)
- {
- return SendRequestAsync(request, userAgent, CancellationToken.None).Result;
- }
-
- public static async Task<Stream> SendRequestAsync(byte[] request, string userAgent, CancellationToken cancellationToken)
- {
- var options = new HttpRequestOptions
- {
- RequestContentBytes = request,
- RequestContentType = "text/xml",
- UserAgent = userAgent,
- Host = HostHeader,
- Url = XML_RPC_SERVER,
-
- // Response parsing will fail with this enabled
- EnableHttpCompression = false,
-
- CancellationToken = cancellationToken,
- BufferContent = false
- };
-
- if (string.IsNullOrEmpty(options.UserAgent))
- {
- options.UserAgent = "xmlrpc-epi-php/0.2 (PHP)";
- }
-
- var result = await HttpClient.Post(options).ConfigureAwait(false);
-
- return result.Content;
- }
-
- }
-}
diff --git a/OpenSubtitlesHandler/XML-RPC/Docs/XML-RPC.txt b/OpenSubtitlesHandler/XML-RPC/Docs/XML-RPC.txt
deleted file mode 100644
index a4de38cde..000000000
--- a/OpenSubtitlesHandler/XML-RPC/Docs/XML-RPC.txt
+++ /dev/null
@@ -1,225 +0,0 @@
-XML-RPC Specification
-
-Tue, Jun 15, 1999; by Dave Winer.
-
-Updated 6/30/03 DW
-
-Updated 10/16/99 DW
-
-Updated 1/21/99 DW
-
-This specification documents the XML-RPC protocol implemented in UserLand Frontier 5.1.
-
-For a non-technical explanation, see XML-RPC for Newbies.
-
-This page provides all the information that an implementor needs.
-
-Overview
-
-XML-RPC is a Remote Procedure Calling protocol that works over the Internet.
-
-An XML-RPC message is an HTTP-POST request. The body of the request is in XML. A procedure executes on the server and the value it returns is also formatted in XML.
-
-Procedure parameters can be scalars, numbers, strings, dates, etc.; and can also be complex record and list structures.
-
-Request example
-
-Here's an example of an XML-RPC request:
-
-POST /RPC2 HTTP/1.0
-User-Agent: Frontier/5.1.2 (WinNT)
-Host: betty.userland.com
-Content-Type: text/xml
-Content-length: 181
-
-<?xml version="1.0"?>
- <methodCall>
- <methodName>examples.getStateName</methodName>
- <params>
- <param>
- <value>
- <i4>41</i4>
- </value>
- </param>
- </params>
- </methodCall>
-
-Header requirements
-
-The format of the URI in the first line of the header is not specified. For example, it could be empty, a single slash, if the server is only handling XML-RPC calls. However, if the server is handling a mix of incoming HTTP requests, we allow the URI to help route the request to the code that handles XML-RPC requests. (In the example, the URI is /RPC2, telling the server to route the request to the "RPC2" responder.)
-
-A User-Agent and Host must be specified.
-
-The Content-Type is text/xml.
-
-The Content-Length must be specified and must be correct.
-
-Payload format
-
-The payload is in XML, a single <methodCall> structure.
-
-The <methodCall> must contain a <methodName> sub-item, a string, containing the name of the method to be called. The string may only contain identifier characters, upper and lower-case A-Z, the numeric characters, 0-9, underscore, dot, colon and slash. It's entirely up to the server to decide how to interpret the characters in a methodName.
-
-For example, the methodName could be the name of a file containing a script that executes on an incoming request. It could be the name of a cell in a database table. Or it could be a path to a file contained within a hierarchy of folders and files.
-
-If the procedure call has parameters, the <methodCall> must contain a <params> sub-item. The <params> sub-item can contain any number of <param>s, each of which has a <value>.
-
-Scalar <value>s
-
-<value>s can be scalars, type is indicated by nesting the value inside one of the tags listed in this table:
-
-Tag Type Example
-<i4> or <int> four-byte signed integer -12
-<boolean> 0 (false) or 1 (true) 1
-<string> string hello world
-<double> double-precision signed floating point number -12.214
-<dateTime.iso8601> date/time 19980717T14:08:55
-<base64> base64-encoded binary eW91IGNhbid0IHJlYWQgdGhpcyE=
-
-If no type is indicated, the type is string.
-
-<struct>s
-
-A value can also be of type <struct>.
-
-A <struct> contains <member>s and each <member> contains a <name> and a <value>.
-
-Here's an example of a two-element <struct>:
-
-<struct>
- <member>
- <name>lowerBound</name>
- <value><i4>18</i4></value>
- </member>
- <member>
- <name>upperBound</name>
- <value><i4>139</i4></value>
- </member>
- </struct>
-
-<struct>s can be recursive, any <value> may contain a <struct> or any other type, including an <array>, described below.
-
-<array>s
-
-A value can also be of type <array>.
-
-An <array> contains a single <data> element, which can contain any number of <value>s.
-
-Here's an example of a four-element array:
-
-<array>
- <data>
- <value><i4>12</i4></value>
- <value><string>Egypt</string></value>
- <value><boolean>0</boolean></value>
- <value><i4>-31</i4></value>
- </data>
- </array>
-
-<array> elements do not have names.
-
-You can mix types as the example above illustrates.
-
-<arrays>s can be recursive, any value may contain an <array> or any other type, including a <struct>, described above.
-
-Response example
-
-Here's an example of a response to an XML-RPC request:
-
-HTTP/1.1 200 OK
-Connection: close
-Content-Length: 158
-Content-Type: text/xml
-Date: Fri, 17 Jul 1998 19:55:08 GMT
-Server: UserLand Frontier/5.1.2-WinNT
-
-<?xml version="1.0"?> <methodResponse> <params> <param> <value><string>South Dakota</string></value> </param> </params> </methodResponse>
-
-Response format
-
-Unless there's a lower-level error, always return 200 OK.
-
-The Content-Type is text/xml. Content-Length must be present and correct.
-
-The body of the response is a single XML structure, a <methodResponse>, which can contain a single <params> which contains a single <param> which contains a single <value>.
-
-The <methodResponse> could also contain a <fault> which contains a <value> which is a <struct> containing two elements, one named <faultCode>, an <int> and one named <faultString>, a <string>.
-
-A <methodResponse> can not contain both a <fault> and a <params>.
-
-Fault example
-
-HTTP/1.1 200 OK
-Connection: close
-Content-Length: 426
-Content-Type: text/xml
-Date: Fri, 17 Jul 1998 19:55:02 GMT
-Server: UserLand Frontier/5.1.2-WinNT
-
-<?xml version="1.0"?> <methodResponse> <fault> <value> <struct> <member> <name>faultCode</name> <value><int>4</int></value> </member> <member> <name>faultString</name> <value><string>Too many parameters.</string></value> </member> </struct> </value> </fault> </methodResponse>
-
-Strategies/Goals
-
-Firewalls. The goal of this protocol is to lay a compatible foundation across different environments, no new power is provided beyond the capabilities of the CGI interface. Firewall software can watch for POSTs whose Content-Type is text/xml.
-
-Discoverability. We wanted a clean, extensible format that's very simple. It should be possible for an HTML coder to be able to look at a file containing an XML-RPC procedure call, understand what it's doing, and be able to modify it and have it work on the first or second try.
-
-Easy to implement. We also wanted it to be an easy to implement protocol that could quickly be adapted to run in other environments or on other operating systems.
-
-Updated 1/21/99 DW
-
-The following questions came up on the UserLand discussion group as XML-RPC was being implemented in Python.
-
- The Response Format section says "The body of the response is a single XML structure, a <methodResponse>, which can contain a single <params>..." This is confusing. Can we leave out the <params>?
-
- No you cannot leave it out if the procedure executed successfully. There are only two options, either a response contains a <params> structure or it contains a <fault> structure. That's why we used the word "can" in that sentence.
-
- Is "boolean" a distinct data type, or can boolean values be interchanged with integers (e.g. zero=false, non-zero=true)?
-
- Yes, boolean is a distinct data type. Some languages/environments allow for an easy coercion from zero to false and one to true, but if you mean true, send a boolean type with the value true, so your intent can't possibly be misunderstood.
-
- What is the legal syntax (and range) for integers? How to deal with leading zeros? Is a leading plus sign allowed? How to deal with whitespace?
-
- An integer is a 32-bit signed number. You can include a plus or minus at the beginning of a string of numeric characters. Leading zeros are collapsed. Whitespace is not permitted. Just numeric characters preceeded by a plus or minus.
-
- What is the legal syntax (and range) for floating point values (doubles)? How is the exponent represented? How to deal with whitespace? Can infinity and "not a number" be represented?
-
- There is no representation for infinity or negative infinity or "not a number". At this time, only decimal point notation is allowed, a plus or a minus, followed by any number of numeric characters, followed by a period and any number of numeric characters. Whitespace is not allowed. The range of allowable values is implementation-dependent, is not specified.
-
- What characters are allowed in strings? Non-printable characters? Null characters? Can a "string" be used to hold an arbitrary chunk of binary data?
-
- Any characters are allowed in a string except < and &, which are encoded as &lt; and &amp;. A string can be used to encode binary data.
-
- Does the "struct" element keep the order of keys. Or in other words, is the struct "foo=1, bar=2" equivalent to "bar=2, foo=1" or not?
-
- The struct element does not preserve the order of the keys. The two structs are equivalent.
-
- Can the <fault> struct contain other members than <faultCode> and <faultString>? Is there a global list of faultCodes? (so they can be mapped to distinct exceptions for languages like Python and Java)?
-
- A <fault> struct may not contain members other than those specified. This is true for all other structures. We believe the specification is flexible enough so that all reasonable data-transfer needs can be accomodated within the specified structures. If you believe strongly that this is not true, please post a message on the discussion group.
-
- There is no global list of fault codes. It is up to the server implementer, or higher-level standards to specify fault codes.
-
- What timezone should be assumed for the dateTime.iso8601 type? UTC? localtime?
-
- Don't assume a timezone. It should be specified by the server in its documentation what assumptions it makes about timezones.
-
-Additions
-
- <base64> type. 1/21/99 DW.
-
-Updated 6/30/03 DW
-
-Removed "ASCII" from definition of string.
-
-Changed copyright dates, below, to 1999-2003 from 1998-99.
-
-Copyright and disclaimer
-
-© Copyright 1998-2003 UserLand Software. All Rights Reserved.
-
-This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and these paragraphs are included on all such copies and derivative works.
-
-This document may not be modified in any way, such as by removing the copyright notice or references to UserLand or other organizations. Further, while these copyright restrictions apply to the written XML-RPC specification, no claim of ownership is made by UserLand to the protocol it describes. Any party may, for commercial or non-commercial purposes, implement this protocol without royalty or license fee to UserLand. The limited permissions granted herein are perpetual and will not be revoked by UserLand or its successors or assigns.
-
-This document and the information contained herein is provided on an "AS IS" basis and USERLAND DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/OpenSubtitlesHandler/XML-RPC/Enums/XmlRpcValueType.cs b/OpenSubtitlesHandler/XML-RPC/Enums/XmlRpcValueType.cs
deleted file mode 100644
index 51e0ee98f..000000000
--- a/OpenSubtitlesHandler/XML-RPC/Enums/XmlRpcValueType.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-namespace XmlRpcHandler
-{
- public enum XmlRpcBasicValueType
- {
- String, Int, Boolean, Double, dateTime_iso8601, base64
- }
-}
diff --git a/OpenSubtitlesHandler/XML-RPC/Types/XmlRpcMethodCall.cs b/OpenSubtitlesHandler/XML-RPC/Types/XmlRpcMethodCall.cs
deleted file mode 100644
index 7cc1a164f..000000000
--- a/OpenSubtitlesHandler/XML-RPC/Types/XmlRpcMethodCall.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace XmlRpcHandler
-{
- /// <summary>
- /// A method call
- /// </summary>
- public struct XmlRpcMethodCall
- {
- /// <summary>
- /// A method call
- /// </summary>
- /// <param name="name">The name of this method</param>
- public XmlRpcMethodCall(string name)
- {
- this.name = name;
- this.parameters = new List<IXmlRpcValue>();
- }
- /// <summary>
- /// A method call
- /// </summary>
- /// <param name="name">The name of this method</param>
- /// <param name="parameters">A list of parameters</param>
- public XmlRpcMethodCall(string name, List<IXmlRpcValue> parameters)
- {
- this.name = name;
- this.parameters = parameters;
- }
-
- private string name;
- private List<IXmlRpcValue> parameters;
-
- /// <summary>
- /// Get or set the name of this method
- /// </summary>
- public string Name
- { get { return name; } set { name = value; } }
- /// <summary>
- /// Get or set the parameters to be sent
- /// </summary>
- public List<IXmlRpcValue> Parameters
- { get { return parameters; } set { parameters = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/XML-RPC/Values/IXmlRpcValue.cs b/OpenSubtitlesHandler/XML-RPC/Values/IXmlRpcValue.cs
deleted file mode 100644
index c918790cb..000000000
--- a/OpenSubtitlesHandler/XML-RPC/Values/IXmlRpcValue.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace XmlRpcHandler
-{
- public abstract class IXmlRpcValue
- {
- public IXmlRpcValue()
- { }
- public IXmlRpcValue(object data)
- {
- this.data = data;
- }
- private object data;
- /// <summary>
- /// Get or set the data of this value
- /// </summary>
- public virtual object Data { get { return data; } set { data = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcStructMember.cs b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcStructMember.cs
deleted file mode 100644
index 2aad7ebff..000000000
--- a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcStructMember.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-namespace XmlRpcHandler
-{
- public class XmlRpcStructMember
- {
- public XmlRpcStructMember(string name, IXmlRpcValue data)
- {
- this.name = name;
- this.data = data;
- }
- private string name;
- private IXmlRpcValue data;
-
- /// <summary>
- /// Get or set the name of this member
- /// </summary>
- public string Name
- { get { return name; } set { name = value; } }
- /// <summary>
- /// Get or set the data of this member
- /// </summary>
- public IXmlRpcValue Data
- { get { return data; } set { data = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueArray.cs b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueArray.cs
deleted file mode 100644
index d10a80175..000000000
--- a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueArray.cs
+++ /dev/null
@@ -1,121 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-using System;
-using System.Collections.Generic;
-
-namespace XmlRpcHandler
-{
- public class XmlRpcValueArray : IXmlRpcValue
- {
- public XmlRpcValueArray() :
- base()
- {
- values = new List<IXmlRpcValue>();
- }
- public XmlRpcValueArray(object data) :
- base(data)
- {
- values = new List<IXmlRpcValue>();
- }
- public XmlRpcValueArray(string[] texts) :
- base()
- {
- values = new List<IXmlRpcValue>();
- foreach (string val in texts)
- {
- values.Add(new XmlRpcValueBasic(val));
- }
- }
- public XmlRpcValueArray(int[] ints) :
- base()
- {
- values = new List<IXmlRpcValue>();
- foreach (int val in ints)
- {
- values.Add(new XmlRpcValueBasic(val));
- }
- }
- public XmlRpcValueArray(double[] doubles) :
- base()
- {
- values = new List<IXmlRpcValue>();
- foreach (double val in doubles)
- {
- values.Add(new XmlRpcValueBasic(val));
- }
- }
- public XmlRpcValueArray(bool[] bools) :
- base()
- {
- values = new List<IXmlRpcValue>();
- foreach (bool val in bools)
- {
- values.Add(new XmlRpcValueBasic(val));
- }
- }
- public XmlRpcValueArray(long[] base24s) :
- base()
- {
- values = new List<IXmlRpcValue>();
- foreach (long val in base24s)
- {
- values.Add(new XmlRpcValueBasic(val));
- }
- }
- public XmlRpcValueArray(DateTime[] dates) :
- base()
- {
- values = new List<IXmlRpcValue>();
- foreach (var val in dates)
- {
- values.Add(new XmlRpcValueBasic(val));
- }
- }
- public XmlRpcValueArray(XmlRpcValueBasic[] basicValues) :
- base()
- {
- values = new List<IXmlRpcValue>();
- foreach (var val in basicValues)
- {
- values.Add(val);
- }
- }
- public XmlRpcValueArray(XmlRpcValueStruct[] structs) :
- base()
- {
- values = new List<IXmlRpcValue>();
- foreach (var val in structs)
- {
- values.Add(val);
- }
- }
- public XmlRpcValueArray(XmlRpcValueArray[] arrays) :
- base()
- {
- values = new List<IXmlRpcValue>();
- foreach (var val in arrays)
- {
- values.Add(val);
- }
- }
- private List<IXmlRpcValue> values;
-
- public List<IXmlRpcValue> Values { get { return values; } set { values = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueBasic.cs b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueBasic.cs
deleted file mode 100644
index f2811b988..000000000
--- a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueBasic.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-using System;
-
-namespace XmlRpcHandler
-{
- public class XmlRpcValueBasic : IXmlRpcValue
- {
- public XmlRpcValueBasic()
- : base()
- { }
- public XmlRpcValueBasic(string data)
- : base(data)
- { this.type = XmlRpcBasicValueType.String; }
- public XmlRpcValueBasic(int data)
- : base(data)
- { this.type = XmlRpcBasicValueType.Int; }
- public XmlRpcValueBasic(double data)
- : base(data)
- { this.type = XmlRpcBasicValueType.Double; }
- public XmlRpcValueBasic(DateTime data)
- : base(data)
- { this.type = XmlRpcBasicValueType.dateTime_iso8601; }
- public XmlRpcValueBasic(bool data)
- : base(data)
- { this.type = XmlRpcBasicValueType.Boolean; }
- public XmlRpcValueBasic(long data)
- : base(data)
- { this.type = XmlRpcBasicValueType.base64; }
- public XmlRpcValueBasic(object data, XmlRpcBasicValueType type)
- : base(data)
- { this.type = type; }
-
- private XmlRpcBasicValueType type = XmlRpcBasicValueType.String;
- /// <summary>
- /// Get or set the type of this basic value
- /// </summary>
- public XmlRpcBasicValueType ValueType { get { return type; } set { type = value; } }
- /*Oprators. help a lot.*/
- public static implicit operator string(XmlRpcValueBasic f)
- {
- if (f.type == XmlRpcBasicValueType.String)
- return f.Data.ToString();
- else
- throw new Exception("Unable to convert, this value is not string type.");
- }
- public static implicit operator int(XmlRpcValueBasic f)
- {
- if (f.type == XmlRpcBasicValueType.String)
- return (int)f.Data;
- else
- throw new Exception("Unable to convert, this value is not int type.");
- }
- public static implicit operator double(XmlRpcValueBasic f)
- {
- if (f.type == XmlRpcBasicValueType.String)
- return (double)f.Data;
- else
- throw new Exception("Unable to convert, this value is not double type.");
- }
- public static implicit operator bool(XmlRpcValueBasic f)
- {
- if (f.type == XmlRpcBasicValueType.String)
- return (bool)f.Data;
- else
- throw new Exception("Unable to convert, this value is not bool type.");
- }
- public static implicit operator long(XmlRpcValueBasic f)
- {
- if (f.type == XmlRpcBasicValueType.String)
- return (long)f.Data;
- else
- throw new Exception("Unable to convert, this value is not long type.");
- }
- public static implicit operator DateTime(XmlRpcValueBasic f)
- {
- if (f.type == XmlRpcBasicValueType.String)
- return (DateTime)f.Data;
- else
- throw new Exception("Unable to convert, this value is not DateTime type.");
- }
- }
-}
diff --git a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueStruct.cs b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueStruct.cs
deleted file mode 100644
index 4863e38e8..000000000
--- a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueStruct.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-using System.Collections.Generic;
-
-namespace XmlRpcHandler
-{
- /// <summary>
- /// Represents XML-RPC struct
- /// </summary>
- public class XmlRpcValueStruct : IXmlRpcValue
- {
- /// <summary>
- /// Represents XML-RPC struct
- /// </summary>
- /// <param name="members"></param>
- public XmlRpcValueStruct(List<XmlRpcStructMember> members)
- { this.members = members; }
-
- private List<XmlRpcStructMember> members;
- /// <summary>
- /// Get or set the members collection
- /// </summary>
- public List<XmlRpcStructMember> Members
- { get { return members; } set { members = value; } }
- }
-}
diff --git a/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs b/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs
deleted file mode 100644
index a79a278fa..000000000
--- a/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs
+++ /dev/null
@@ -1,350 +0,0 @@
-/* This file is part of OpenSubtitles Handler
- A library that handle OpenSubtitles.org XML-RPC methods.
-
- Copyright © Ala Ibrahim Hadid 2013
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Text;
-using System.Xml;
-using OpenSubtitlesHandler;
-
-namespace XmlRpcHandler
-{
- /// <summary>
- /// A class for making XML-RPC requests. The requests then can be sent directly as http request.
- /// </summary>
- public class XmlRpcGenerator
- {
- /// <summary>
- /// Generate XML-RPC request using method call.
- /// </summary>
- /// <param name="method">The method call</param>
- /// <returns>The request in xml.</returns>
- public static byte[] Generate(XmlRpcMethodCall method)
- { return Generate(new XmlRpcMethodCall[] { method }); }
- /// <summary>
- /// Generate XML-RPC request using method calls array.
- /// </summary>
- /// <param name="methods">The method calls array</param>
- /// <returns>The request in utf8 xml string as buffer</returns>
- public static byte[] Generate(XmlRpcMethodCall[] methods)
- {
- if (methods == null)
- throw new Exception("No method to write !");
- if (methods.Length == 0)
- throw new Exception("No method to write !");
- // Create xml
- var sett = new XmlWriterSettings();
- sett.Indent = true;
-
- sett.Encoding = Encoding.UTF8;
-
- using (var ms = new MemoryStream())
- {
- using (var XMLwrt = XmlWriter.Create(ms, sett))
- {
- // Let's write the methods
- foreach (XmlRpcMethodCall method in methods)
- {
- XMLwrt.WriteStartElement("methodCall");//methodCall
- XMLwrt.WriteStartElement("methodName");//methodName
- XMLwrt.WriteString(method.Name);
- XMLwrt.WriteEndElement();//methodName
- XMLwrt.WriteStartElement("params");//params
- // Write values
- foreach (IXmlRpcValue p in method.Parameters)
- {
- XMLwrt.WriteStartElement("param");//param
- if (p is XmlRpcValueBasic)
- {
- WriteBasicValue(XMLwrt, (XmlRpcValueBasic)p);
- }
- else if (p is XmlRpcValueStruct)
- {
- WriteStructValue(XMLwrt, (XmlRpcValueStruct)p);
- }
- else if (p is XmlRpcValueArray)
- {
- WriteArrayValue(XMLwrt, (XmlRpcValueArray)p);
- }
- XMLwrt.WriteEndElement();//param
- }
-
- XMLwrt.WriteEndElement();//params
- XMLwrt.WriteEndElement();//methodCall
- }
- XMLwrt.Flush();
- return ms.ToArray();
- }
- }
- }
- /// <summary>
- /// Decode response then return the values
- /// </summary>
- /// <param name="xmlResponse">The response xml string as provided by server as methodResponse</param>
- /// <returns></returns>
- public static XmlRpcMethodCall[] DecodeMethodResponse(string xmlResponse)
- {
- var methods = new List<XmlRpcMethodCall>();
- var sett = new XmlReaderSettings();
- sett.DtdProcessing = DtdProcessing.Ignore;
- sett.IgnoreWhitespace = true;
- MemoryStream str;
- if (xmlResponse.Contains(@"encoding=""utf-8"""))
- {
- str = new MemoryStream(Encoding.UTF8.GetBytes(xmlResponse));
- }
- else
- {
- str = new MemoryStream(Utilities.GetASCIIBytes(xmlResponse));
- }
- using (str)
- {
- using (var XMLread = XmlReader.Create(str, sett))
- {
- var call = new XmlRpcMethodCall("methodResponse");
- // Read parameters
- while (XMLread.Read())
- {
- if (XMLread.Name == "param" && XMLread.IsStartElement())
- {
- IXmlRpcValue val = ReadValue(XMLread);
- if (val != null)
- call.Parameters.Add(val);
- }
- }
- methods.Add(call);
- return methods.ToArray();
- }
- }
- }
-
- private static void WriteBasicValue(XmlWriter XMLwrt, XmlRpcValueBasic val)
- {
- XMLwrt.WriteStartElement("value");//value
- switch (val.ValueType)
- {
- case XmlRpcBasicValueType.String:
- XMLwrt.WriteStartElement("string");
- if (val.Data != null)
- XMLwrt.WriteString(val.Data.ToString());
- XMLwrt.WriteEndElement();
- break;
- case XmlRpcBasicValueType.Int:
- XMLwrt.WriteStartElement("int");
- if (val.Data != null)
- XMLwrt.WriteString(val.Data.ToString());
- XMLwrt.WriteEndElement();
- break;
- case XmlRpcBasicValueType.Boolean:
- XMLwrt.WriteStartElement("boolean");
- if (val.Data != null)
- XMLwrt.WriteString(((bool)val.Data) ? "1" : "0");
- XMLwrt.WriteEndElement();
- break;
- case XmlRpcBasicValueType.Double:
- XMLwrt.WriteStartElement("double");
- if (val.Data != null)
- XMLwrt.WriteString(val.Data.ToString());
- XMLwrt.WriteEndElement();
- break;
- case XmlRpcBasicValueType.dateTime_iso8601:
- XMLwrt.WriteStartElement("dateTime.iso8601");
- // Get date time format
- if (val.Data != null)
- {
- var time = (DateTime)val.Data;
- string dt = time.Year + time.Month.ToString("D2") + time.Day.ToString("D2") +
- "T" + time.Hour.ToString("D2") + ":" + time.Minute.ToString("D2") + ":" +
- time.Second.ToString("D2");
- XMLwrt.WriteString(dt);
- }
- XMLwrt.WriteEndElement();
- break;
- case XmlRpcBasicValueType.base64:
- XMLwrt.WriteStartElement("base64");
- if (val.Data != null)
- XMLwrt.WriteString(Convert.ToBase64String(BitConverter.GetBytes((long)val.Data)));
- XMLwrt.WriteEndElement();
- break;
- }
- XMLwrt.WriteEndElement();//value
- }
- private static void WriteStructValue(XmlWriter XMLwrt, XmlRpcValueStruct val)
- {
- XMLwrt.WriteStartElement("value");//value
- XMLwrt.WriteStartElement("struct");//struct
- foreach (XmlRpcStructMember member in val.Members)
- {
- XMLwrt.WriteStartElement("member");//member
-
- XMLwrt.WriteStartElement("name");//name
- XMLwrt.WriteString(member.Name);
- XMLwrt.WriteEndElement();//name
-
- if (member.Data is XmlRpcValueBasic)
- {
- WriteBasicValue(XMLwrt, (XmlRpcValueBasic)member.Data);
- }
- else if (member.Data is XmlRpcValueStruct)
- {
- WriteStructValue(XMLwrt, (XmlRpcValueStruct)member.Data);
- }
- else if (member.Data is XmlRpcValueArray)
- {
- WriteArrayValue(XMLwrt, (XmlRpcValueArray)member.Data);
- }
-
- XMLwrt.WriteEndElement();//member
- }
- XMLwrt.WriteEndElement();//struct
- XMLwrt.WriteEndElement();//value
- }
- private static void WriteArrayValue(XmlWriter XMLwrt, XmlRpcValueArray val)
- {
- XMLwrt.WriteStartElement("value");//value
- XMLwrt.WriteStartElement("array");//array
- XMLwrt.WriteStartElement("data");//data
- foreach (IXmlRpcValue o in val.Values)
- {
- if (o is XmlRpcValueBasic)
- {
- WriteBasicValue(XMLwrt, (XmlRpcValueBasic)o);
- }
- else if (o is XmlRpcValueStruct)
- {
- WriteStructValue(XMLwrt, (XmlRpcValueStruct)o);
- }
- else if (o is XmlRpcValueArray)
- {
- WriteArrayValue(XMLwrt, (XmlRpcValueArray)o);
- }
- }
- XMLwrt.WriteEndElement();//data
- XMLwrt.WriteEndElement();//array
- XMLwrt.WriteEndElement();//value
- }
- private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
-
- private static string ReadString(XmlReader reader)
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- return reader.ReadElementContentAsString();
- }
- return reader.ReadContentAsString();
- }
-
- private static IXmlRpcValue ReadValue(XmlReader xmlReader, bool skipRead = false)
- {
- while (skipRead || xmlReader.Read())
- {
- if (xmlReader.Name == "value" && xmlReader.IsStartElement())
- {
- xmlReader.Read();
- if (xmlReader.Name == "string" && xmlReader.IsStartElement())
- {
- return new XmlRpcValueBasic(ReadString(xmlReader), XmlRpcBasicValueType.String);
- }
- else if (xmlReader.Name == "int" && xmlReader.IsStartElement())
- {
- return new XmlRpcValueBasic(int.Parse(ReadString(xmlReader), UsCulture), XmlRpcBasicValueType.Int);
- }
- else if (xmlReader.Name == "boolean" && xmlReader.IsStartElement())
- {
- return new XmlRpcValueBasic(ReadString(xmlReader) == "1", XmlRpcBasicValueType.Boolean);
- }
- else if (xmlReader.Name == "double" && xmlReader.IsStartElement())
- {
- return new XmlRpcValueBasic(double.Parse(ReadString(xmlReader), UsCulture), XmlRpcBasicValueType.Double);
- }
- else if (xmlReader.Name == "dateTime.iso8601" && xmlReader.IsStartElement())
- {
- string date = ReadString(xmlReader);
- int year = int.Parse(date.Substring(0, 4), UsCulture);
- int month = int.Parse(date.Substring(4, 2), UsCulture);
- int day = int.Parse(date.Substring(6, 2), UsCulture);
- int hour = int.Parse(date.Substring(9, 2), UsCulture);
- int minute = int.Parse(date.Substring(12, 2), UsCulture);//19980717T14:08:55
- int sec = int.Parse(date.Substring(15, 2), UsCulture);
- var time = new DateTime(year, month, day, hour, minute, sec);
- return new XmlRpcValueBasic(time, XmlRpcBasicValueType.dateTime_iso8601);
- }
- else if (xmlReader.Name == "base64" && xmlReader.IsStartElement())
- {
- return new XmlRpcValueBasic(BitConverter.ToInt64(Convert.FromBase64String(ReadString(xmlReader)), 0)
- , XmlRpcBasicValueType.Double);
- }
- else if (xmlReader.Name == "struct" && xmlReader.IsStartElement())
- {
- var strct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
- // Read members...
- while (xmlReader.Read())
- {
- if (xmlReader.Name == "member" && xmlReader.IsStartElement())
- {
- var member = new XmlRpcStructMember("", null);
- xmlReader.Read();// read name
- member.Name = ReadString(xmlReader);
-
- IXmlRpcValue val = ReadValue(xmlReader, true);
- if (val != null)
- {
- member.Data = val;
- strct.Members.Add(member);
- }
- }
- else if (xmlReader.Name == "struct" && !xmlReader.IsStartElement())
- {
- return strct;
- }
- }
- return strct;
- }
- else if (xmlReader.Name == "array" && xmlReader.IsStartElement())
- {
- var array = new XmlRpcValueArray();
- // Read members...
- while (xmlReader.Read())
- {
- if (xmlReader.Name == "array" && !xmlReader.IsStartElement())
- {
- return array;
- }
- else
- {
- IXmlRpcValue val = ReadValue(xmlReader);
- if (val != null)
- array.Values.Add(val);
- }
- }
- return array;
- }
- }
- else break;
-
- if (skipRead)
- {
- return null;
- }
- }
- return null;
- }
- }
-}
diff --git a/README.md b/README.md
index d869c8978..1f635bdd2 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
<a href="https://github.com/jellyfin/jellyfin"><img alt="GPL 2.0 License" src="https://img.shields.io/github/license/jellyfin/jellyfin.svg"/></a>
<a href="https://github.com/jellyfin/jellyfin/releases"><img alt="Current Release" src="https://img.shields.io/github/release/jellyfin/jellyfin.svg"/></a>
<a href="https://translate.jellyfin.org/engage/jellyfin/?utm_source=widget"><img alt="Translations" src="https://translate.jellyfin.org/widgets/jellyfin/-/svg-badge.svg"/></a>
-<a href="https://cloud.drone.io/jellyfin/jellyfin"><img alt="Build Status" src="https://cloud.drone.io/api/badges/jellyfin/jellyfin/status.svg"/></a>
+<a href="https://dev.azure.com/jellyfin-project/jellyfin/_build?definitionId=1"><img alt="Azure DevOps builds" src="https://dev.azure.com/jellyfin-project/jellyfin/_apis/build/status/Jellyfin%20CI"></a>
<a href="https://hub.docker.com/r/jellyfin/jellyfin"><img alt="Docker Pull Count" src="https://img.shields.io/docker/pulls/jellyfin/jellyfin.svg"/></a>
</br>
<a href="https://opencollective.com/jellyfin"><img alt="Donate" src="https://img.shields.io/opencollective/all/jellyfin.svg?label=backers"/></a>
diff --git a/RSSDP/ISsdpCommunicationsServer.cs b/RSSDP/ISsdpCommunicationsServer.cs
index ef75f997f..c99d684a1 100644
--- a/RSSDP/ISsdpCommunicationsServer.cs
+++ b/RSSDP/ISsdpCommunicationsServer.cs
@@ -45,8 +45,8 @@ namespace Rssdp.Infrastructure
/// <summary>
/// Sends a message to the SSDP multicast address and port.
/// </summary>
- Task SendMulticastMessage(string message, CancellationToken cancellationToken);
- Task SendMulticastMessage(string message, int sendCount, CancellationToken cancellationToken);
+ Task SendMulticastMessage(string message, IpAddressInfo fromLocalIpAddress, CancellationToken cancellationToken);
+ Task SendMulticastMessage(string message, int sendCount, IpAddressInfo fromLocalIpAddress, CancellationToken cancellationToken);
#endregion
@@ -63,4 +63,4 @@ namespace Rssdp.Infrastructure
#endregion
}
-} \ No newline at end of file
+}
diff --git a/RSSDP/Properties/AssemblyInfo.cs b/RSSDP/Properties/AssemblyInfo.cs
index d2bb7c6f3..55f7b6a83 100644
--- a/RSSDP/Properties/AssemblyInfo.cs
+++ b/RSSDP/Properties/AssemblyInfo.cs
@@ -9,8 +9,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2015 Troy Willmot. Code released under the MIT license. Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
+[assembly: AssemblyProduct("Jellyfin Server")]
+[assembly: AssemblyCopyright("Copyright © 2015 Troy Willmot. Code released under the MIT license. Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/RSSDP/RSSDP.csproj b/RSSDP/RSSDP.csproj
index f06d4687b..456a93aa8 100644
--- a/RSSDP/RSSDP.csproj
+++ b/RSSDP/RSSDP.csproj
@@ -3,6 +3,7 @@
<ItemGroup>
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
+ <ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
</ItemGroup>
<PropertyGroup>
diff --git a/RSSDP/SsdpCommunicationsServer.cs b/RSSDP/SsdpCommunicationsServer.cs
index 04e76ef59..d9a4b6ac0 100644
--- a/RSSDP/SsdpCommunicationsServer.cs
+++ b/RSSDP/SsdpCommunicationsServer.cs
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Net;
+using MediaBrowser.Controller.Configuration;
namespace Rssdp.Infrastructure
{
@@ -45,6 +46,7 @@ namespace Rssdp.Infrastructure
private readonly ILogger _logger;
private ISocketFactory _SocketFactory;
private readonly INetworkManager _networkManager;
+ private readonly IServerConfigurationManager _config;
private int _LocalPort;
private int _MulticastTtl;
@@ -74,9 +76,11 @@ namespace Rssdp.Infrastructure
/// Minimum constructor.
/// </summary>
/// <exception cref="ArgumentNullException">The <paramref name="socketFactory"/> argument is null.</exception>
- public SsdpCommunicationsServer(ISocketFactory socketFactory, INetworkManager networkManager, ILogger logger, bool enableMultiSocketBinding)
+ public SsdpCommunicationsServer(IServerConfigurationManager config, ISocketFactory socketFactory,
+ INetworkManager networkManager, ILogger logger, bool enableMultiSocketBinding)
: this(socketFactory, 0, SsdpConstants.SsdpDefaultMulticastTimeToLive, networkManager, logger, enableMultiSocketBinding)
{
+ _config = config;
}
/// <summary>
@@ -236,15 +240,15 @@ namespace Rssdp.Infrastructure
}
}
- public Task SendMulticastMessage(string message, CancellationToken cancellationToken)
+ public Task SendMulticastMessage(string message, IpAddressInfo fromLocalIpAddress, CancellationToken cancellationToken)
{
- return SendMulticastMessage(message, SsdpConstants.UdpResendCount, cancellationToken);
+ return SendMulticastMessage(message, SsdpConstants.UdpResendCount, fromLocalIpAddress, cancellationToken);
}
/// <summary>
/// Sends a message to the SSDP multicast address and port.
/// </summary>
- public async Task SendMulticastMessage(string message, int sendCount, CancellationToken cancellationToken)
+ public async Task SendMulticastMessage(string message, int sendCount, IpAddressInfo fromLocalIpAddress, CancellationToken cancellationToken)
{
if (message == null) throw new ArgumentNullException(nameof(message));
@@ -264,7 +268,7 @@ namespace Rssdp.Infrastructure
IpAddress = new IpAddressInfo(SsdpConstants.MulticastLocalAdminAddress, IpAddressFamily.InterNetwork),
Port = SsdpConstants.MulticastPort
- }, cancellationToken).ConfigureAwait(false);
+ }, fromLocalIpAddress, cancellationToken).ConfigureAwait(false);
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
}
@@ -332,14 +336,15 @@ namespace Rssdp.Infrastructure
#region Private Methods
- private Task SendMessageIfSocketNotDisposed(byte[] messageData, IpEndPointInfo destination, CancellationToken cancellationToken)
+ private Task SendMessageIfSocketNotDisposed(byte[] messageData, IpEndPointInfo destination, IpAddressInfo fromLocalIpAddress, CancellationToken cancellationToken)
{
var sockets = _sendSockets;
if (sockets != null)
{
sockets = sockets.ToList();
- var tasks = sockets.Select(s => SendFromSocket(s, messageData, destination, cancellationToken));
+ var tasks = sockets.Where(s => (fromLocalIpAddress == null || fromLocalIpAddress.Equals(s.LocalIPAddress)))
+ .Select(s => SendFromSocket(s, messageData, destination, cancellationToken));
return Task.WhenAll(tasks);
}
@@ -363,11 +368,11 @@ namespace Rssdp.Infrastructure
if (_enableMultiSocketBinding)
{
- foreach (var address in _networkManager.GetLocalIpAddresses())
+ foreach (var address in _networkManager.GetLocalIpAddresses(_config.Configuration.IgnoreVirtualInterfaces))
{
if (address.AddressFamily == IpAddressFamily.InterNetworkV6)
{
- // Not supported ?
+ // Not support IPv6 right now
continue;
}
diff --git a/RSSDP/SsdpDeviceLocator.cs b/RSSDP/SsdpDeviceLocator.cs
index 128bdfcbb..e17e14c1a 100644
--- a/RSSDP/SsdpDeviceLocator.cs
+++ b/RSSDP/SsdpDeviceLocator.cs
@@ -354,7 +354,7 @@ namespace Rssdp.Infrastructure
var message = BuildMessage(header, values);
- return _CommunicationsServer.SendMulticastMessage(message, cancellationToken);
+ return _CommunicationsServer.SendMulticastMessage(message, null, cancellationToken);
}
private void ProcessSearchResponseMessage(HttpResponseMessage message, IpAddressInfo localIpAddress)
diff --git a/RSSDP/SsdpDevicePublisher.cs b/RSSDP/SsdpDevicePublisher.cs
index ce64ba117..921f33c21 100644
--- a/RSSDP/SsdpDevicePublisher.cs
+++ b/RSSDP/SsdpDevicePublisher.cs
@@ -7,6 +7,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Net;
+using MediaBrowser.Common.Net;
using Rssdp;
namespace Rssdp.Infrastructure
@@ -16,10 +17,12 @@ namespace Rssdp.Infrastructure
/// </summary>
public class SsdpDevicePublisher : DisposableManagedObjectBase, ISsdpDevicePublisher
{
+ private readonly INetworkManager _networkManager;
private ISsdpCommunicationsServer _CommsServer;
private string _OSName;
private string _OSVersion;
+ private bool _sendOnlyMatchedHost;
private bool _SupportPnpRootDevice;
@@ -37,9 +40,11 @@ namespace Rssdp.Infrastructure
/// <summary>
/// Default constructor.
/// </summary>
- public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer, string osName, string osVersion)
+ public SsdpDevicePublisher(ISsdpCommunicationsServer communicationsServer, INetworkManager networkManager,
+ string osName, string osVersion, bool sendOnlyMatchedHost)
{
if (communicationsServer == null) throw new ArgumentNullException(nameof(communicationsServer));
+ if (networkManager == null) throw new ArgumentNullException(nameof(networkManager));
if (osName == null) throw new ArgumentNullException(nameof(osName));
if (osName.Length == 0) throw new ArgumentException("osName cannot be an empty string.", nameof(osName));
if (osVersion == null) throw new ArgumentNullException(nameof(osVersion));
@@ -51,10 +56,12 @@ namespace Rssdp.Infrastructure
_RecentSearchRequests = new Dictionary<string, SearchRequest>(StringComparer.OrdinalIgnoreCase);
_Random = new Random();
+ _networkManager = networkManager;
_CommsServer = communicationsServer;
_CommsServer.RequestReceived += CommsServer_RequestReceived;
_OSName = osName;
_OSVersion = osVersion;
+ _sendOnlyMatchedHost = sendOnlyMatchedHost;
_CommsServer.BeginListeningForBroadcasts();
}
@@ -250,7 +257,11 @@ namespace Rssdp.Infrastructure
foreach (var device in deviceList)
{
- SendDeviceSearchResponses(device, remoteEndPoint, receivedOnlocalIpAddress, cancellationToken);
+ if (!_sendOnlyMatchedHost ||
+ _networkManager.IsInSameSubnet(device.ToRootDevice().Address, remoteEndPoint.IpAddress, device.ToRootDevice().SubnetMask))
+ {
+ SendDeviceSearchResponses(device, remoteEndPoint, receivedOnlocalIpAddress, cancellationToken);
+ }
}
}
else
@@ -427,7 +438,7 @@ namespace Rssdp.Infrastructure
var message = BuildMessage(header, values);
- _CommsServer.SendMulticastMessage(message, cancellationToken);
+ _CommsServer.SendMulticastMessage(message, _sendOnlyMatchedHost ? rootDevice.Address : null, cancellationToken);
//WriteTrace(String.Format("Sent alive notification"), device);
}
@@ -472,7 +483,7 @@ namespace Rssdp.Infrastructure
var sendCount = IsDisposed ? 1 : 3;
WriteTrace(String.Format("Sent byebye notification"), device);
- return _CommsServer.SendMulticastMessage(message, sendCount, cancellationToken);
+ return _CommsServer.SendMulticastMessage(message, sendCount, _sendOnlyMatchedHost ? device.ToRootDevice().Address : null, cancellationToken);
}
private void DisposeRebroadcastTimer()
diff --git a/RSSDP/SsdpRootDevice.cs b/RSSDP/SsdpRootDevice.cs
index a2b0f60f5..d918b9040 100644
--- a/RSSDP/SsdpRootDevice.cs
+++ b/RSSDP/SsdpRootDevice.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using System.Xml;
using Rssdp.Infrastructure;
+using MediaBrowser.Model.Net;
namespace Rssdp
{
@@ -52,6 +53,15 @@ namespace Rssdp
/// </summary>
public Uri Location { get; set; }
+ /// <summary>
+ /// Gets or sets the Address used to check if the received message from same interface with this device/tree. Required.
+ /// </summary>
+ public IpAddressInfo Address { get; set; }
+
+ /// <summary>
+ /// Gets or sets the SubnetMask used to check if the received message from same interface with this device/tree. Required.
+ /// </summary>
+ public IpAddressInfo SubnetMask { get; set; }
/// <summary>
/// The base URL to use for all relative url's provided in other propertise (and those of child devices). Optional.
diff --git a/SharedVersion.cs b/SharedVersion.cs
index 294748b77..785ba9301 100644
--- a/SharedVersion.cs
+++ b/SharedVersion.cs
@@ -1,4 +1,4 @@
using System.Reflection;
-[assembly: AssemblyVersion("10.2.0")]
-[assembly: AssemblyFileVersion("10.2.0")]
+[assembly: AssemblyVersion("10.2.2")]
+[assembly: AssemblyFileVersion("10.2.2")]
diff --git a/SocketHttpListener/ByteOrder.cs b/SocketHttpListener/ByteOrder.cs
deleted file mode 100644
index c04150c74..000000000
--- a/SocketHttpListener/ByteOrder.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace SocketHttpListener
-{
- /// <summary>
- /// Contains the values that indicate whether the byte order is a Little-endian or Big-endian.
- /// </summary>
- public enum ByteOrder : byte
- {
- /// <summary>
- /// Indicates a Little-endian.
- /// </summary>
- Little,
- /// <summary>
- /// Indicates a Big-endian.
- /// </summary>
- Big
- }
-}
diff --git a/SocketHttpListener/CloseEventArgs.cs b/SocketHttpListener/CloseEventArgs.cs
deleted file mode 100644
index c6460fd23..000000000
--- a/SocketHttpListener/CloseEventArgs.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-using System;
-using System.Text;
-
-namespace SocketHttpListener
-{
- /// <summary>
- /// Contains the event data associated with a <see cref="WebSocket.OnClose"/> event.
- /// </summary>
- /// <remarks>
- /// A <see cref="WebSocket.OnClose"/> event occurs when the WebSocket connection has been closed.
- /// If you would like to get the reason for the close, you should access the <see cref="Code"/> or
- /// <see cref="Reason"/> property.
- /// </remarks>
- public class CloseEventArgs : EventArgs
- {
- #region Private Fields
-
- private bool _clean;
- private ushort _code;
- private string _reason;
-
- #endregion
-
- #region Internal Constructors
-
- internal CloseEventArgs(PayloadData payload)
- {
- var data = payload.ApplicationData;
- var len = data.Length;
- _code = len > 1
- ? data.SubArray(0, 2).ToUInt16(ByteOrder.Big)
- : (ushort)CloseStatusCode.NoStatusCode;
-
- _reason = len > 2
- ? GetUtf8String(data.SubArray(2, len - 2))
- : string.Empty;
- }
-
- private static string GetUtf8String(byte[] bytes)
- {
- return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
- }
-
- #endregion
-
- #region Public Properties
-
- /// <summary>
- /// Gets the status code for the close.
- /// </summary>
- /// <value>
- /// A <see cref="ushort"/> that represents the status code for the close if any.
- /// </value>
- public ushort Code => _code;
-
- /// <summary>
- /// Gets the reason for the close.
- /// </summary>
- /// <value>
- /// A <see cref="string"/> that represents the reason for the close if any.
- /// </value>
- public string Reason => _reason;
-
- /// <summary>
- /// Gets a value indicating whether the WebSocket connection has been closed cleanly.
- /// </summary>
- /// <value>
- /// <c>true</c> if the WebSocket connection has been closed cleanly; otherwise, <c>false</c>.
- /// </value>
- public bool WasClean
- {
- get => _clean;
-
- internal set => _clean = value;
- }
-
- #endregion
- }
-}
diff --git a/SocketHttpListener/CloseStatusCode.cs b/SocketHttpListener/CloseStatusCode.cs
deleted file mode 100644
index 428595bb0..000000000
--- a/SocketHttpListener/CloseStatusCode.cs
+++ /dev/null
@@ -1,94 +0,0 @@
-namespace SocketHttpListener
-{
- /// <summary>
- /// Contains the values of the status code for the WebSocket connection close.
- /// </summary>
- /// <remarks>
- /// <para>
- /// The values of the status code are defined in
- /// <see href="http://tools.ietf.org/html/rfc6455#section-7.4">Section 7.4</see>
- /// of RFC 6455.
- /// </para>
- /// <para>
- /// "Reserved value" must not be set as a status code in a close control frame
- /// by an endpoint. It's designated for use in applications expecting a status
- /// code to indicate that the connection was closed due to the system grounds.
- /// </para>
- /// </remarks>
- public enum CloseStatusCode : ushort
- {
- /// <summary>
- /// Equivalent to close status 1000.
- /// Indicates a normal close.
- /// </summary>
- Normal = 1000,
- /// <summary>
- /// Equivalent to close status 1001.
- /// Indicates that an endpoint is going away.
- /// </summary>
- Away = 1001,
- /// <summary>
- /// Equivalent to close status 1002.
- /// Indicates that an endpoint is terminating the connection due to a protocol error.
- /// </summary>
- ProtocolError = 1002,
- /// <summary>
- /// Equivalent to close status 1003.
- /// Indicates that an endpoint is terminating the connection because it has received
- /// an unacceptable type message.
- /// </summary>
- IncorrectData = 1003,
- /// <summary>
- /// Equivalent to close status 1004.
- /// Still undefined. Reserved value.
- /// </summary>
- Undefined = 1004,
- /// <summary>
- /// Equivalent to close status 1005.
- /// Indicates that no status code was actually present. Reserved value.
- /// </summary>
- NoStatusCode = 1005,
- /// <summary>
- /// Equivalent to close status 1006.
- /// Indicates that the connection was closed abnormally. Reserved value.
- /// </summary>
- Abnormal = 1006,
- /// <summary>
- /// Equivalent to close status 1007.
- /// Indicates that an endpoint is terminating the connection because it has received
- /// a message that contains a data that isn't consistent with the type of the message.
- /// </summary>
- InconsistentData = 1007,
- /// <summary>
- /// Equivalent to close status 1008.
- /// Indicates that an endpoint is terminating the connection because it has received
- /// a message that violates its policy.
- /// </summary>
- PolicyViolation = 1008,
- /// <summary>
- /// Equivalent to close status 1009.
- /// Indicates that an endpoint is terminating the connection because it has received
- /// a message that is too big to process.
- /// </summary>
- TooBig = 1009,
- /// <summary>
- /// Equivalent to close status 1010.
- /// Indicates that the client is terminating the connection because it has expected
- /// the server to negotiate one or more extension, but the server didn't return them
- /// in the handshake response.
- /// </summary>
- IgnoreExtension = 1010,
- /// <summary>
- /// Equivalent to close status 1011.
- /// Indicates that the server is terminating the connection because it has encountered
- /// an unexpected condition that prevented it from fulfilling the request.
- /// </summary>
- ServerError = 1011,
- /// <summary>
- /// Equivalent to close status 1015.
- /// Indicates that the connection was closed due to a failure to perform a TLS handshake.
- /// Reserved value.
- /// </summary>
- TlsHandshakeFailure = 1015
- }
-}
diff --git a/SocketHttpListener/CompressionMethod.cs b/SocketHttpListener/CompressionMethod.cs
deleted file mode 100644
index d6bcd63d8..000000000
--- a/SocketHttpListener/CompressionMethod.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-namespace SocketHttpListener
-{
- /// <summary>
- /// Contains the values of the compression method used to compress the message on the WebSocket
- /// connection.
- /// </summary>
- /// <remarks>
- /// The values of the compression method are defined in
- /// <see href="http://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-09">Compression
- /// Extensions for WebSocket</see>.
- /// </remarks>
- public enum CompressionMethod : byte
- {
- /// <summary>
- /// Indicates non compression.
- /// </summary>
- None,
- /// <summary>
- /// Indicates using DEFLATE.
- /// </summary>
- Deflate
- }
-}
diff --git a/SocketHttpListener/ErrorEventArgs.cs b/SocketHttpListener/ErrorEventArgs.cs
deleted file mode 100644
index 9502d2a15..000000000
--- a/SocketHttpListener/ErrorEventArgs.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using System;
-
-namespace SocketHttpListener
-{
- /// <summary>
- /// Contains the event data associated with a <see cref="WebSocket.OnError"/> event.
- /// </summary>
- /// <remarks>
- /// A <see cref="WebSocket.OnError"/> event occurs when the <see cref="WebSocket"/> gets an error.
- /// If you would like to get the error message, you should access the <see cref="Message"/>
- /// property.
- /// </remarks>
- public class ErrorEventArgs : EventArgs
- {
- #region Private Fields
-
- private string _message;
-
- #endregion
-
- #region Internal Constructors
-
- internal ErrorEventArgs(string message)
- {
- _message = message;
- }
-
- #endregion
-
- #region Public Properties
-
- /// <summary>
- /// Gets the error message.
- /// </summary>
- /// <value>
- /// A <see cref="string"/> that represents the error message.
- /// </value>
- public string Message => _message;
-
- #endregion
- }
-}
diff --git a/SocketHttpListener/Ext.cs b/SocketHttpListener/Ext.cs
deleted file mode 100644
index a02b48061..000000000
--- a/SocketHttpListener/Ext.cs
+++ /dev/null
@@ -1,960 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.IO.Compression;
-using System.Net;
-using System.Text;
-using System.Threading.Tasks;
-using MediaBrowser.Model.Services;
-using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
-using WebSocketState = System.Net.WebSockets.WebSocketState;
-
-namespace SocketHttpListener
-{
- /// <summary>
- /// Provides a set of static methods for the websocket-sharp.
- /// </summary>
- public static class Ext
- {
- #region Private Const Fields
-
- private const string _tspecials = "()<>@,;:\\\"/[]?={} \t";
-
- #endregion
-
- #region Private Methods
-
- private static MemoryStream compress(this Stream stream)
- {
- var output = new MemoryStream();
- if (stream.Length == 0)
- return output;
-
- stream.Position = 0;
- using (var ds = new DeflateStream(output, CompressionMode.Compress, true))
- {
- stream.CopyTo(ds);
- //ds.Close(); // "BFINAL" set to 1.
- output.Position = 0;
-
- return output;
- }
- }
-
- private static byte[] decompress(this byte[] value)
- {
- if (value.Length == 0)
- return value;
-
- using (var input = new MemoryStream(value))
- {
- return input.decompressToArray();
- }
- }
-
- private static MemoryStream decompress(this Stream stream)
- {
- var output = new MemoryStream();
- if (stream.Length == 0)
- return output;
-
- stream.Position = 0;
- using (var ds = new DeflateStream(stream, CompressionMode.Decompress, true))
- {
- ds.CopyTo(output, true);
- return output;
- }
- }
-
- private static byte[] decompressToArray(this Stream stream)
- {
- using (var decomp = stream.decompress())
- {
- return decomp.ToArray();
- }
- }
-
- private static byte[] readBytes(this Stream stream, byte[] buffer, int offset, int length)
- {
- var len = stream.Read(buffer, offset, length);
- if (len < 1)
- return buffer.SubArray(0, offset);
-
- var tmp = 0;
- while (len < length)
- {
- tmp = stream.Read(buffer, offset + len, length - len);
- if (tmp < 1)
- break;
-
- len += tmp;
- }
-
- return len < length
- ? buffer.SubArray(0, offset + len)
- : buffer;
- }
-
- private static bool readBytes(
- this Stream stream, byte[] buffer, int offset, int length, Stream dest)
- {
- var bytes = stream.readBytes(buffer, offset, length);
- var len = bytes.Length;
- dest.Write(bytes, 0, len);
-
- return len == offset + length;
- }
-
- #endregion
-
- #region Internal Methods
-
- internal static byte[] Append(this ushort code, string reason)
- {
- using (var buffer = new MemoryStream())
- {
- var tmp = code.ToByteArrayInternally(ByteOrder.Big);
- buffer.Write(tmp, 0, 2);
- if (reason != null && reason.Length > 0)
- {
- tmp = Encoding.UTF8.GetBytes(reason);
- buffer.Write(tmp, 0, tmp.Length);
- }
-
- return buffer.ToArray();
- }
- }
-
- internal static string CheckIfClosable(this WebSocketState state)
- {
- return state == WebSocketState.CloseSent
- ? "While closing the WebSocket connection."
- : state == WebSocketState.Closed
- ? "The WebSocket connection has already been closed."
- : null;
- }
-
- internal static string CheckIfOpen(this WebSocketState state)
- {
- return state == WebSocketState.Connecting
- ? "A WebSocket connection isn't established."
- : state == WebSocketState.CloseSent
- ? "While closing the WebSocket connection."
- : state == WebSocketState.Closed
- ? "The WebSocket connection has already been closed."
- : null;
- }
-
- internal static string CheckIfValidControlData(this byte[] data, string paramName)
- {
- return data.Length > 125
- ? string.Format("'{0}' length must be less.", paramName)
- : null;
- }
-
- internal static Stream Compress(this Stream stream, CompressionMethod method)
- {
- return method == CompressionMethod.Deflate
- ? stream.compress()
- : stream;
- }
-
- internal static bool Contains<T>(this IEnumerable<T> source, Func<T, bool> condition)
- {
- foreach (T elm in source)
- if (condition(elm))
- return true;
-
- return false;
- }
-
- internal static void CopyTo(this Stream src, Stream dest, bool setDefaultPosition)
- {
- var readLen = 0;
- var bufferLen = 256;
- var buffer = new byte[bufferLen];
- while ((readLen = src.Read(buffer, 0, bufferLen)) > 0)
- {
- dest.Write(buffer, 0, readLen);
- }
-
- if (setDefaultPosition)
- dest.Position = 0;
- }
-
- internal static byte[] Decompress(this byte[] value, CompressionMethod method)
- {
- return method == CompressionMethod.Deflate
- ? value.decompress()
- : value;
- }
-
- internal static byte[] DecompressToArray(this Stream stream, CompressionMethod method)
- {
- return method == CompressionMethod.Deflate
- ? stream.decompressToArray()
- : stream.ToByteArray();
- }
-
- /// <summary>
- /// Determines whether the specified <see cref="int"/> equals the specified <see cref="char"/>,
- /// and invokes the specified Action&lt;int&gt; delegate at the same time.
- /// </summary>
- /// <returns>
- /// <c>true</c> if <paramref name="value"/> equals <paramref name="c"/>;
- /// otherwise, <c>false</c>.
- /// </returns>
- /// <param name="value">
- /// An <see cref="int"/> to compare.
- /// </param>
- /// <param name="c">
- /// A <see cref="char"/> to compare.
- /// </param>
- /// <param name="action">
- /// An Action&lt;int&gt; delegate that references the method(s) called at
- /// the same time as comparing. An <see cref="int"/> parameter to pass to
- /// the method(s) is <paramref name="value"/>.
- /// </param>
- /// <exception cref="ArgumentOutOfRangeException">
- /// <paramref name="value"/> isn't between 0 and 255.
- /// </exception>
- internal static bool EqualsWith(this int value, char c, Action<int> action)
- {
- if (value < 0 || value > 255)
- throw new ArgumentOutOfRangeException(nameof(value));
-
- action(value);
- return value == c - 0;
- }
-
- internal static string GetMessage(this CloseStatusCode code)
- {
- return code == CloseStatusCode.ProtocolError
- ? "A WebSocket protocol error has occurred."
- : code == CloseStatusCode.IncorrectData
- ? "An incorrect data has been received."
- : code == CloseStatusCode.Abnormal
- ? "An exception has occurred."
- : code == CloseStatusCode.InconsistentData
- ? "An inconsistent data has been received."
- : code == CloseStatusCode.PolicyViolation
- ? "A policy violation has occurred."
- : code == CloseStatusCode.TooBig
- ? "A too big data has been received."
- : code == CloseStatusCode.IgnoreExtension
- ? "WebSocket client did not receive expected extension(s)."
- : code == CloseStatusCode.ServerError
- ? "WebSocket server got an internal error."
- : code == CloseStatusCode.TlsHandshakeFailure
- ? "An error has occurred while handshaking."
- : string.Empty;
- }
-
- internal static string GetNameInternal(this string nameAndValue, string separator)
- {
- var i = nameAndValue.IndexOf(separator);
- return i > 0
- ? nameAndValue.Substring(0, i).Trim()
- : null;
- }
-
- internal static string GetValueInternal(this string nameAndValue, string separator)
- {
- var i = nameAndValue.IndexOf(separator);
- return i >= 0 && i < nameAndValue.Length - 1
- ? nameAndValue.Substring(i + 1).Trim()
- : null;
- }
-
- internal static bool IsCompressionExtension(this string value, CompressionMethod method)
- {
- return value.StartsWith(method.ToExtensionString());
- }
-
- internal static bool IsPortNumber(this int value)
- {
- return value > 0 && value < 65536;
- }
-
- internal static bool IsReserved(this ushort code)
- {
- return code == (ushort)CloseStatusCode.Undefined ||
- code == (ushort)CloseStatusCode.NoStatusCode ||
- code == (ushort)CloseStatusCode.Abnormal ||
- code == (ushort)CloseStatusCode.TlsHandshakeFailure;
- }
-
- internal static bool IsReserved(this CloseStatusCode code)
- {
- return code == CloseStatusCode.Undefined ||
- code == CloseStatusCode.NoStatusCode ||
- code == CloseStatusCode.Abnormal ||
- code == CloseStatusCode.TlsHandshakeFailure;
- }
-
- internal static bool IsText(this string value)
- {
- var len = value.Length;
- for (var i = 0; i < len; i++)
- {
- char c = value[i];
- if (c < 0x20 && !"\r\n\t".Contains(c))
- return false;
-
- if (c == 0x7f)
- return false;
-
- if (c == '\n' && ++i < len)
- {
- c = value[i];
- if (!" \t".Contains(c))
- return false;
- }
- }
-
- return true;
- }
-
- internal static bool IsToken(this string value)
- {
- foreach (char c in value)
- if (c < 0x20 || c >= 0x7f || _tspecials.Contains(c))
- return false;
-
- return true;
- }
-
- internal static string Quote(this string value)
- {
- return value.IsToken()
- ? value
- : string.Format("\"{0}\"", value.Replace("\"", "\\\""));
- }
-
- internal static byte[] ReadBytes(this Stream stream, int length)
- {
- return stream.readBytes(new byte[length], 0, length);
- }
-
- internal static byte[] ReadBytes(this Stream stream, long length, int bufferLength)
- {
- using (var result = new MemoryStream())
- {
- var count = length / bufferLength;
- var rem = (int)(length % bufferLength);
-
- var buffer = new byte[bufferLength];
- var end = false;
- for (long i = 0; i < count; i++)
- {
- if (!stream.readBytes(buffer, 0, bufferLength, result))
- {
- end = true;
- break;
- }
- }
-
- if (!end && rem > 0)
- stream.readBytes(new byte[rem], 0, rem, result);
-
- return result.ToArray();
- }
- }
-
- internal static async Task<byte[]> ReadBytesAsync(this Stream stream, int length)
- {
- var buffer = new byte[length];
-
- var len = await stream.ReadAsync(buffer, 0, length).ConfigureAwait(false);
- var bytes = len < 1
- ? new byte[0]
- : len < length
- ? stream.readBytes(buffer, len, length - len)
- : buffer;
-
- return bytes;
- }
-
- internal static string RemovePrefix(this string value, params string[] prefixes)
- {
- var i = 0;
- foreach (var prefix in prefixes)
- {
- if (value.StartsWith(prefix))
- {
- i = prefix.Length;
- break;
- }
- }
-
- return i > 0
- ? value.Substring(i)
- : value;
- }
-
- internal static T[] Reverse<T>(this T[] array)
- {
- var len = array.Length;
- T[] reverse = new T[len];
-
- var end = len - 1;
- for (var i = 0; i <= end; i++)
- reverse[i] = array[end - i];
-
- return reverse;
- }
-
- internal static IEnumerable<string> SplitHeaderValue(
- this string value, params char[] separator)
- {
- var len = value.Length;
- var separators = new string(separator);
-
- var buffer = new StringBuilder(32);
- var quoted = false;
- var escaped = false;
-
- char c;
- for (var i = 0; i < len; i++)
- {
- c = value[i];
- if (c == '"')
- {
- if (escaped)
- escaped = !escaped;
- else
- quoted = !quoted;
- }
- else if (c == '\\')
- {
- if (i < len - 1 && value[i + 1] == '"')
- escaped = true;
- }
- else if (separators.Contains(c))
- {
- if (!quoted)
- {
- yield return buffer.ToString();
- buffer.Length = 0;
-
- continue;
- }
- }
- else
- {
- }
-
- buffer.Append(c);
- }
-
- if (buffer.Length > 0)
- yield return buffer.ToString();
- }
-
- internal static byte[] ToByteArray(this Stream stream)
- {
- using (var output = new MemoryStream())
- {
- stream.Position = 0;
- stream.CopyTo(output);
-
- return output.ToArray();
- }
- }
-
- internal static byte[] ToByteArrayInternally(this ushort value, ByteOrder order)
- {
- var bytes = BitConverter.GetBytes(value);
- if (!order.IsHostOrder())
- Array.Reverse(bytes);
-
- return bytes;
- }
-
- internal static byte[] ToByteArrayInternally(this ulong value, ByteOrder order)
- {
- var bytes = BitConverter.GetBytes(value);
- if (!order.IsHostOrder())
- Array.Reverse(bytes);
-
- return bytes;
- }
-
- internal static string ToExtensionString(
- this CompressionMethod method, params string[] parameters)
- {
- if (method == CompressionMethod.None)
- return string.Empty;
-
- var m = string.Format("permessage-{0}", method.ToString().ToLowerInvariant());
- if (parameters == null || parameters.Length == 0)
- return m;
-
- return string.Format("{0}; {1}", m, parameters.ToString("; "));
- }
-
- internal static List<TSource> ToList<TSource>(this IEnumerable<TSource> source)
- {
- return new List<TSource>(source);
- }
-
- internal static ushort ToUInt16(this byte[] src, ByteOrder srcOrder)
- {
- return BitConverter.ToUInt16(src.ToHostOrder(srcOrder), 0);
- }
-
- internal static ulong ToUInt64(this byte[] src, ByteOrder srcOrder)
- {
- return BitConverter.ToUInt64(src.ToHostOrder(srcOrder), 0);
- }
-
- internal static string TrimEndSlash(this string value)
- {
- value = value.TrimEnd('/');
- return value.Length > 0
- ? value
- : "/";
- }
-
- internal static string Unquote(this string value)
- {
- var start = value.IndexOf('\"');
- var end = value.LastIndexOf('\"');
- if (start < end)
- value = value.Substring(start + 1, end - start - 1).Replace("\\\"", "\"");
-
- return value.Trim();
- }
-
- internal static void WriteBytes(this Stream stream, byte[] value)
- {
- using (var src = new MemoryStream(value))
- {
- src.CopyTo(stream);
- }
- }
-
- #endregion
-
- #region Public Methods
-
- /// <summary>
- /// Determines whether the specified <see cref="string"/> contains any of characters
- /// in the specified array of <see cref="char"/>.
- /// </summary>
- /// <returns>
- /// <c>true</c> if <paramref name="value"/> contains any of <paramref name="chars"/>;
- /// otherwise, <c>false</c>.
- /// </returns>
- /// <param name="value">
- /// A <see cref="string"/> to test.
- /// </param>
- /// <param name="chars">
- /// An array of <see cref="char"/> that contains characters to find.
- /// </param>
- public static bool Contains(this string value, params char[] chars)
- {
- return chars == null || chars.Length == 0
- ? true
- : value == null || value.Length == 0
- ? false
- : value.IndexOfAny(chars) != -1;
- }
-
- /// <summary>
- /// Determines whether the specified <see cref="QueryParamCollection"/> contains the entry
- /// with the specified <paramref name="name"/>.
- /// </summary>
- /// <returns>
- /// <c>true</c> if <paramref name="collection"/> contains the entry
- /// with <paramref name="name"/>; otherwise, <c>false</c>.
- /// </returns>
- /// <param name="collection">
- /// A <see cref="QueryParamCollection"/> to test.
- /// </param>
- /// <param name="name">
- /// A <see cref="string"/> that represents the key of the entry to find.
- /// </param>
- public static bool Contains(this QueryParamCollection collection, string name)
- {
- return collection == null || collection.Count == 0
- ? false
- : collection[name] != null;
- }
-
- /// <summary>
- /// Determines whether the specified <see cref="QueryParamCollection"/> contains the entry
- /// with the specified both <paramref name="name"/> and <paramref name="value"/>.
- /// </summary>
- /// <returns>
- /// <c>true</c> if <paramref name="collection"/> contains the entry
- /// with both <paramref name="name"/> and <paramref name="value"/>;
- /// otherwise, <c>false</c>.
- /// </returns>
- /// <param name="collection">
- /// A <see cref="QueryParamCollection"/> to test.
- /// </param>
- /// <param name="name">
- /// A <see cref="string"/> that represents the key of the entry to find.
- /// </param>
- /// <param name="value">
- /// A <see cref="string"/> that represents the value of the entry to find.
- /// </param>
- public static bool Contains(this QueryParamCollection collection, string name, string value)
- {
- if (collection == null || collection.Count == 0)
- return false;
-
- var values = collection[name];
- if (values == null)
- return false;
-
- foreach (var v in values.Split(','))
- if (v.Trim().Equals(value, StringComparison.OrdinalIgnoreCase))
- return true;
-
- return false;
- }
-
- /// <summary>
- /// Emits the specified <c>EventHandler&lt;TEventArgs&gt;</c> delegate
- /// if it isn't <see langword="null"/>.
- /// </summary>
- /// <param name="eventHandler">
- /// An <c>EventHandler&lt;TEventArgs&gt;</c> to emit.
- /// </param>
- /// <param name="sender">
- /// An <see cref="object"/> from which emits this <paramref name="eventHandler"/>.
- /// </param>
- /// <param name="e">
- /// A <c>TEventArgs</c> that represents the event data.
- /// </param>
- /// <typeparam name="TEventArgs">
- /// The type of the event data generated by the event.
- /// </typeparam>
- public static void Emit<TEventArgs>(
- this EventHandler<TEventArgs> eventHandler, object sender, TEventArgs e)
- where TEventArgs : EventArgs
- {
- if (eventHandler != null)
- eventHandler(sender, e);
- }
-
- /// <summary>
- /// Gets the description of the specified HTTP status <paramref name="code"/>.
- /// </summary>
- /// <returns>
- /// A <see cref="string"/> that represents the description of the HTTP status code.
- /// </returns>
- /// <param name="code">
- /// One of <see cref="HttpStatusCode"/> enum values, indicates the HTTP status codes.
- /// </param>
- public static string GetDescription(this HttpStatusCode code)
- {
- return ((int)code).GetStatusDescription();
- }
-
- /// <summary>
- /// Gets the description of the specified HTTP status <paramref name="code"/>.
- /// </summary>
- /// <returns>
- /// A <see cref="string"/> that represents the description of the HTTP status code.
- /// </returns>
- /// <param name="code">
- /// An <see cref="int"/> that represents the HTTP status code.
- /// </param>
- public static string GetStatusDescription(this int code)
- {
- switch (code)
- {
- case 100: return "Continue";
- case 101: return "Switching Protocols";
- case 102: return "Processing";
- case 200: return "OK";
- case 201: return "Created";
- case 202: return "Accepted";
- case 203: return "Non-Authoritative Information";
- case 204: return "No Content";
- case 205: return "Reset Content";
- case 206: return "Partial Content";
- case 207: return "Multi-Status";
- case 300: return "Multiple Choices";
- case 301: return "Moved Permanently";
- case 302: return "Found";
- case 303: return "See Other";
- case 304: return "Not Modified";
- case 305: return "Use Proxy";
- case 307: return "Temporary Redirect";
- case 400: return "Bad Request";
- case 401: return "Unauthorized";
- case 402: return "Payment Required";
- case 403: return "Forbidden";
- case 404: return "Not Found";
- case 405: return "Method Not Allowed";
- case 406: return "Not Acceptable";
- case 407: return "Proxy Authentication Required";
- case 408: return "Request Timeout";
- case 409: return "Conflict";
- case 410: return "Gone";
- case 411: return "Length Required";
- case 412: return "Precondition Failed";
- case 413: return "Request Entity Too Large";
- case 414: return "Request-Uri Too Long";
- case 415: return "Unsupported Media Type";
- case 416: return "Requested Range Not Satisfiable";
- case 417: return "Expectation Failed";
- case 422: return "Unprocessable Entity";
- case 423: return "Locked";
- case 424: return "Failed Dependency";
- case 500: return "Internal Server Error";
- case 501: return "Not Implemented";
- case 502: return "Bad Gateway";
- case 503: return "Service Unavailable";
- case 504: return "Gateway Timeout";
- case 505: return "Http Version Not Supported";
- case 507: return "Insufficient Storage";
- }
-
- return string.Empty;
- }
-
- /// <summary>
- /// Determines whether the specified <see cref="ByteOrder"/> is host
- /// (this computer architecture) byte order.
- /// </summary>
- /// <returns>
- /// <c>true</c> if <paramref name="order"/> is host byte order;
- /// otherwise, <c>false</c>.
- /// </returns>
- /// <param name="order">
- /// One of the <see cref="ByteOrder"/> enum values, to test.
- /// </param>
- public static bool IsHostOrder(this ByteOrder order)
- {
- // true : !(true ^ true) or !(false ^ false)
- // false: !(true ^ false) or !(false ^ true)
- return !(BitConverter.IsLittleEndian ^ (order == ByteOrder.Little));
- }
-
- /// <summary>
- /// Determines whether the specified <see cref="string"/> is a predefined scheme.
- /// </summary>
- /// <returns>
- /// <c>true</c> if <paramref name="value"/> is a predefined scheme; otherwise, <c>false</c>.
- /// </returns>
- /// <param name="value">
- /// A <see cref="string"/> to test.
- /// </param>
- public static bool IsPredefinedScheme(this string value)
- {
- if (value == null || value.Length < 2)
- return false;
-
- var c = value[0];
- if (c == 'h')
- return value == "http" || value == "https";
-
- if (c == 'w')
- return value == "ws" || value == "wss";
-
- if (c == 'f')
- return value == "file" || value == "ftp";
-
- if (c == 'n')
- {
- c = value[1];
- return c == 'e'
- ? value == "news" || value == "net.pipe" || value == "net.tcp"
- : value == "nntp";
- }
-
- return (c == 'g' && value == "gopher") || (c == 'm' && value == "mailto");
- }
-
- /// <summary>
- /// Determines whether the specified <see cref="string"/> is a URI string.
- /// </summary>
- /// <returns>
- /// <c>true</c> if <paramref name="value"/> may be a URI string; otherwise, <c>false</c>.
- /// </returns>
- /// <param name="value">
- /// A <see cref="string"/> to test.
- /// </param>
- public static bool MaybeUri(this string value)
- {
- if (value == null || value.Length == 0)
- return false;
-
- var i = value.IndexOf(':');
- if (i == -1)
- return false;
-
- if (i >= 10)
- return false;
-
- return value.Substring(0, i).IsPredefinedScheme();
- }
-
- /// <summary>
- /// Retrieves a sub-array from the specified <paramref name="array"/>.
- /// A sub-array starts at the specified element position.
- /// </summary>
- /// <returns>
- /// An array of T that receives a sub-array, or an empty array of T if any problems
- /// with the parameters.
- /// </returns>
- /// <param name="array">
- /// An array of T that contains the data to retrieve a sub-array.
- /// </param>
- /// <param name="startIndex">
- /// An <see cref="int"/> that contains the zero-based starting position of a sub-array
- /// in <paramref name="array"/>.
- /// </param>
- /// <param name="length">
- /// An <see cref="int"/> that contains the number of elements to retrieve a sub-array.
- /// </param>
- /// <typeparam name="T">
- /// The type of elements in the <paramref name="array"/>.
- /// </typeparam>
- public static T[] SubArray<T>(this T[] array, int startIndex, int length)
- {
- if (array == null || array.Length == 0)
- return new T[0];
-
- if (startIndex < 0 || length <= 0)
- return new T[0];
-
- if (startIndex + length > array.Length)
- return new T[0];
-
- if (startIndex == 0 && array.Length == length)
- return array;
-
- T[] subArray = new T[length];
- Array.Copy(array, startIndex, subArray, 0, length);
-
- return subArray;
- }
-
- /// <summary>
- /// Converts the order of the specified array of <see cref="byte"/> to the host byte order.
- /// </summary>
- /// <returns>
- /// An array of <see cref="byte"/> converted from <paramref name="src"/>.
- /// </returns>
- /// <param name="src">
- /// An array of <see cref="byte"/> to convert.
- /// </param>
- /// <param name="srcOrder">
- /// One of the <see cref="ByteOrder"/> enum values, indicates the byte order of
- /// <paramref name="src"/>.
- /// </param>
- /// <exception cref="ArgumentNullException">
- /// <paramref name="src"/> is <see langword="null"/>.
- /// </exception>
- public static byte[] ToHostOrder(this byte[] src, ByteOrder srcOrder)
- {
- if (src == null)
- throw new ArgumentNullException(nameof(src));
-
- return src.Length > 1 && !srcOrder.IsHostOrder()
- ? src.Reverse()
- : src;
- }
-
- /// <summary>
- /// Converts the specified <paramref name="array"/> to a <see cref="string"/> that
- /// concatenates the each element of <paramref name="array"/> across the specified
- /// <paramref name="separator"/>.
- /// </summary>
- /// <returns>
- /// A <see cref="string"/> converted from <paramref name="array"/>,
- /// or <see cref="String.Empty"/> if <paramref name="array"/> is empty.
- /// </returns>
- /// <param name="array">
- /// An array of T to convert.
- /// </param>
- /// <param name="separator">
- /// A <see cref="string"/> that represents the separator string.
- /// </param>
- /// <typeparam name="T">
- /// The type of elements in <paramref name="array"/>.
- /// </typeparam>
- /// <exception cref="ArgumentNullException">
- /// <paramref name="array"/> is <see langword="null"/>.
- /// </exception>
- public static string ToString<T>(this T[] array, string separator)
- {
- if (array == null)
- throw new ArgumentNullException(nameof(array));
-
- var len = array.Length;
- if (len == 0)
- return string.Empty;
-
- if (separator == null)
- separator = string.Empty;
-
- var buff = new StringBuilder(64);
- (len - 1).Times(i => buff.AppendFormat("{0}{1}", array[i].ToString(), separator));
-
- buff.Append(array[len - 1].ToString());
- return buff.ToString();
- }
-
- /// <summary>
- /// Executes the specified <c>Action&lt;int&gt;</c> delegate <paramref name="n"/> times.
- /// </summary>
- /// <param name="n">
- /// An <see cref="int"/> is the number of times to execute.
- /// </param>
- /// <param name="action">
- /// An <c>Action&lt;int&gt;</c> delegate that references the method(s) to execute.
- /// An <see cref="int"/> parameter to pass to the method(s) is the zero-based count of
- /// iteration.
- /// </param>
- public static void Times(this int n, Action<int> action)
- {
- if (n > 0 && action != null)
- for (int i = 0; i < n; i++)
- action(i);
- }
-
- /// <summary>
- /// Converts the specified <see cref="string"/> to a <see cref="Uri"/>.
- /// </summary>
- /// <returns>
- /// A <see cref="Uri"/> converted from <paramref name="uriString"/>, or <see langword="null"/>
- /// if <paramref name="uriString"/> isn't successfully converted.
- /// </returns>
- /// <param name="uriString">
- /// A <see cref="string"/> to convert.
- /// </param>
- public static Uri ToUri(this string uriString)
- {
- return Uri.TryCreate(
- uriString, uriString.MaybeUri() ? UriKind.Absolute : UriKind.Relative, out var res)
- ? res
- : null;
- }
-
- /// <summary>
- /// URL-decodes the specified <see cref="string"/>.
- /// </summary>
- /// <returns>
- /// A <see cref="string"/> that receives the decoded string, or the <paramref name="value"/>
- /// if it's <see langword="null"/> or empty.
- /// </returns>
- /// <param name="value">
- /// A <see cref="string"/> to decode.
- /// </param>
- public static string UrlDecode(this string value)
- {
- return value == null || value.Length == 0
- ? value
- : WebUtility.UrlDecode(value);
- }
-
- #endregion
- }
-}
diff --git a/SocketHttpListener/Fin.cs b/SocketHttpListener/Fin.cs
deleted file mode 100644
index c8ffbf2b2..000000000
--- a/SocketHttpListener/Fin.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace SocketHttpListener
-{
- internal enum Fin : byte
- {
- More = 0x0,
- Final = 0x1
- }
-}
diff --git a/SocketHttpListener/HttpBase.cs b/SocketHttpListener/HttpBase.cs
deleted file mode 100644
index c386b9374..000000000
--- a/SocketHttpListener/HttpBase.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-using System;
-using System.Text;
-using MediaBrowser.Model.Services;
-
-namespace SocketHttpListener
-{
- internal abstract class HttpBase
- {
- #region Private Fields
-
- private QueryParamCollection _headers;
- private Version _version;
-
- #endregion
-
- #region Protected Fields
-
- protected const string CrLf = "\r\n";
-
- #endregion
-
- #region Protected Constructors
-
- protected HttpBase(Version version, QueryParamCollection headers)
- {
- _version = version;
- _headers = headers;
- }
-
- #endregion
-
- #region Public Properties
-
- public QueryParamCollection Headers => _headers;
-
- public Version ProtocolVersion => _version;
-
- #endregion
-
- #region Private Methods
-
- private static Encoding getEncoding(string contentType)
- {
- if (contentType == null || contentType.Length == 0)
- return Encoding.UTF8;
-
- var i = contentType.IndexOf("charset=", StringComparison.Ordinal);
- if (i == -1)
- return Encoding.UTF8;
-
- var charset = contentType.Substring(i + 8);
- i = charset.IndexOf(';');
- if (i != -1)
- charset = charset.Substring(0, i).TrimEnd();
-
- return Encoding.GetEncoding(charset.Trim('"'));
- }
-
- #endregion
-
- #region Public Methods
-
- public byte[] ToByteArray()
- {
- return Encoding.UTF8.GetBytes(ToString());
- }
-
- #endregion
- }
-}
diff --git a/SocketHttpListener/HttpResponse.cs b/SocketHttpListener/HttpResponse.cs
deleted file mode 100644
index d5d9b4a1c..000000000
--- a/SocketHttpListener/HttpResponse.cs
+++ /dev/null
@@ -1,123 +0,0 @@
-using System;
-using System.Linq;
-using System.Net;
-using System.Text;
-using MediaBrowser.Model.Services;
-using SocketHttpListener.Net;
-using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
-using HttpVersion = SocketHttpListener.Net.HttpVersion;
-
-namespace SocketHttpListener
-{
- internal class HttpResponse : HttpBase
- {
- #region Private Fields
-
- private string _code;
- private string _reason;
-
- #endregion
-
- #region Private Constructors
-
- private HttpResponse(string code, string reason, Version version, QueryParamCollection headers)
- : base(version, headers)
- {
- _code = code;
- _reason = reason;
- }
-
- #endregion
-
- #region Internal Constructors
-
- internal HttpResponse(HttpStatusCode code)
- : this(code, code.GetDescription())
- {
- }
-
- internal HttpResponse(HttpStatusCode code, string reason)
- : this(((int)code).ToString(), reason, HttpVersion.Version11, new QueryParamCollection())
- {
- Headers["Server"] = "websocket-sharp/1.0";
- }
-
- #endregion
-
- #region Public Properties
-
- public CookieCollection Cookies => GetCookies(Headers, true);
-
- private static CookieCollection GetCookies(QueryParamCollection headers, bool response)
- {
- var name = response ? "Set-Cookie" : "Cookie";
- return headers == null || !headers.Contains(name)
- ? new CookieCollection()
- : CookieHelper.Parse(headers[name], response);
- }
-
- public bool IsProxyAuthenticationRequired => _code == "407";
-
- public bool IsUnauthorized => _code == "401";
-
- public bool IsWebSocketResponse
- {
- get
- {
- var headers = Headers;
- return ProtocolVersion > HttpVersion.Version10 &&
- _code == "101" &&
- headers.Contains("Upgrade", "websocket") &&
- headers.Contains("Connection", "Upgrade");
- }
- }
-
- public string Reason => _reason;
-
- public string StatusCode => _code;
-
- #endregion
-
- #region Internal Methods
-
- internal static HttpResponse CreateCloseResponse(HttpStatusCode code)
- {
- var res = new HttpResponse(code);
- res.Headers["Connection"] = "close";
-
- return res;
- }
-
- #endregion
-
- #region Public Methods
-
- public void SetCookies(CookieCollection cookies)
- {
- if (cookies == null || cookies.Count == 0)
- return;
-
- var headers = Headers;
- var sorted = cookies.OfType<Cookie>().OrderBy(i => i.Name).ToList();
-
- foreach (var cookie in sorted)
- headers.Add("Set-Cookie", cookie.ToString());
- }
-
- public override string ToString()
- {
- var output = new StringBuilder(64);
- output.AppendFormat("HTTP/{0} {1} {2}{3}", ProtocolVersion, _code, _reason, CrLf);
-
- var headers = Headers;
- foreach (var key in headers.Keys)
- output.AppendFormat("{0}: {1}{2}", key, headers[key], CrLf);
-
- output.Append(CrLf);
-
- return output.ToString();
- }
-
- #endregion
- }
-}
diff --git a/SocketHttpListener/Mask.cs b/SocketHttpListener/Mask.cs
deleted file mode 100644
index c56f5b08c..000000000
--- a/SocketHttpListener/Mask.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace SocketHttpListener
-{
- internal enum Mask : byte
- {
- Unmask = 0x0,
- Mask = 0x1
- }
-}
diff --git a/SocketHttpListener/MessageEventArgs.cs b/SocketHttpListener/MessageEventArgs.cs
deleted file mode 100644
index 8e2151cb7..000000000
--- a/SocketHttpListener/MessageEventArgs.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-using System;
-using System.Text;
-
-namespace SocketHttpListener
-{
- /// <summary>
- /// Contains the event data associated with a <see cref="WebSocket.OnMessage"/> event.
- /// </summary>
- /// <remarks>
- /// A <see cref="WebSocket.OnMessage"/> event occurs when the <see cref="WebSocket"/> receives
- /// a text or binary data frame.
- /// If you want to get the received data, you access the <see cref="Data"/> or
- /// <see cref="RawData"/> property.
- /// </remarks>
- public class MessageEventArgs : EventArgs
- {
- #region Private Fields
-
- private string _data;
- private Opcode _opcode;
- private byte[] _rawData;
-
- #endregion
-
- #region Internal Constructors
-
- internal MessageEventArgs(Opcode opcode, byte[] data)
- {
- _opcode = opcode;
- _rawData = data;
- _data = convertToString(opcode, data);
- }
-
- internal MessageEventArgs(Opcode opcode, PayloadData payload)
- {
- _opcode = opcode;
- _rawData = payload.ApplicationData;
- _data = convertToString(opcode, _rawData);
- }
-
- #endregion
-
- #region Public Properties
-
- /// <summary>
- /// Gets the received data as a <see cref="string"/>.
- /// </summary>
- /// <value>
- /// A <see cref="string"/> that contains the received data.
- /// </value>
- public string Data => _data;
-
- /// <summary>
- /// Gets the received data as an array of <see cref="byte"/>.
- /// </summary>
- /// <value>
- /// An array of <see cref="byte"/> that contains the received data.
- /// </value>
- public byte[] RawData => _rawData;
-
- /// <summary>
- /// Gets the type of the received data.
- /// </summary>
- /// <value>
- /// One of the <see cref="Opcode"/> values, indicates the type of the received data.
- /// </value>
- public Opcode Type => _opcode;
-
- #endregion
-
- #region Private Methods
-
- private static string convertToString(Opcode opcode, byte[] data)
- {
- return data.Length == 0
- ? string.Empty
- : opcode == Opcode.Text
- ? Encoding.UTF8.GetString(data, 0, data.Length)
- : opcode.ToString();
- }
-
- #endregion
- }
-}
diff --git a/SocketHttpListener/Net/AuthenticationSchemeSelector.cs b/SocketHttpListener/Net/AuthenticationSchemeSelector.cs
deleted file mode 100644
index 77e6d0b8a..000000000
--- a/SocketHttpListener/Net/AuthenticationSchemeSelector.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-using System.Net;
-
-namespace SocketHttpListener.Net
-{
- public delegate AuthenticationSchemes AuthenticationSchemeSelector(HttpListenerRequest httpRequest);
-}
diff --git a/SocketHttpListener/Net/AuthenticationTypes.cs b/SocketHttpListener/Net/AuthenticationTypes.cs
deleted file mode 100644
index a3dbe9dff..000000000
--- a/SocketHttpListener/Net/AuthenticationTypes.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace SocketHttpListener.Net
-{
- internal class AuthenticationTypes
- {
- internal const string NTLM = "NTLM";
- internal const string Negotiate = "Negotiate";
- internal const string Basic = "Basic";
- }
-}
diff --git a/SocketHttpListener/Net/BoundaryType.cs b/SocketHttpListener/Net/BoundaryType.cs
deleted file mode 100644
index da0b22910..000000000
--- a/SocketHttpListener/Net/BoundaryType.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace SocketHttpListener.Net
-{
- internal enum BoundaryType
- {
- ContentLength = 0, // Content-Length: XXX
- Chunked = 1, // Transfer-Encoding: chunked
- Multipart = 3,
- None = 4,
- Invalid = 5,
- }
-}
diff --git a/SocketHttpListener/Net/ChunkStream.cs b/SocketHttpListener/Net/ChunkStream.cs
deleted file mode 100644
index 3836947d4..000000000
--- a/SocketHttpListener/Net/ChunkStream.cs
+++ /dev/null
@@ -1,385 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Net;
-using System.Text;
-
-namespace SocketHttpListener.Net
-{
- // Licensed to the .NET Foundation under one or more agreements.
- // See the LICENSE file in the project root for more information.
- //
- // System.Net.ResponseStream
- //
- // Author:
- // Gonzalo Paniagua Javier (gonzalo@novell.com)
- //
- // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
-
- internal sealed class ChunkStream
- {
- private enum State
- {
- None,
- PartialSize,
- Body,
- BodyFinished,
- Trailer
- }
-
- private class Chunk
- {
- public byte[] Bytes;
- public int Offset;
-
- public Chunk(byte[] chunk)
- {
- Bytes = chunk;
- }
-
- public int Read(byte[] buffer, int offset, int size)
- {
- int nread = (size > Bytes.Length - Offset) ? Bytes.Length - Offset : size;
- Buffer.BlockCopy(Bytes, Offset, buffer, offset, nread);
- Offset += nread;
- return nread;
- }
- }
-
- internal WebHeaderCollection _headers;
- private int _chunkSize;
- private int _chunkRead;
- private int _totalWritten;
- private State _state;
- private StringBuilder _saved;
- private bool _sawCR;
- private bool _gotit;
- private int _trailerState;
- private List<Chunk> _chunks;
-
- public ChunkStream(WebHeaderCollection headers)
- {
- _headers = headers;
- _saved = new StringBuilder();
- _chunks = new List<Chunk>();
- _chunkSize = -1;
- _totalWritten = 0;
- }
-
- public void ResetBuffer()
- {
- _chunkSize = -1;
- _chunkRead = 0;
- _totalWritten = 0;
- _chunks.Clear();
- }
-
- public int Read(byte[] buffer, int offset, int size)
- {
- return ReadFromChunks(buffer, offset, size);
- }
-
- private int ReadFromChunks(byte[] buffer, int offset, int size)
- {
- int count = _chunks.Count;
- int nread = 0;
-
- var chunksForRemoving = new List<Chunk>(count);
- for (int i = 0; i < count; i++)
- {
- var chunk = _chunks[i];
-
- if (chunk.Offset == chunk.Bytes.Length)
- {
- chunksForRemoving.Add(chunk);
- continue;
- }
-
- nread += chunk.Read(buffer, offset + nread, size - nread);
- if (nread == size)
- break;
- }
-
- foreach (var chunk in chunksForRemoving)
- _chunks.Remove(chunk);
-
- return nread;
- }
-
- public void Write(byte[] buffer, int offset, int size)
- {
- // Note, the logic here only works when offset is 0 here.
- // Otherwise, it would treat "size" as the end offset instead of an actual byte count from offset.
-
- if (offset < size)
- InternalWrite(buffer, ref offset, size);
- }
-
- private void InternalWrite(byte[] buffer, ref int offset, int size)
- {
- if (_state == State.None || _state == State.PartialSize)
- {
- _state = GetChunkSize(buffer, ref offset, size);
- if (_state == State.PartialSize)
- return;
-
- _saved.Length = 0;
- _sawCR = false;
- _gotit = false;
- }
-
- if (_state == State.Body && offset < size)
- {
- _state = ReadBody(buffer, ref offset, size);
- if (_state == State.Body)
- return;
- }
-
- if (_state == State.BodyFinished && offset < size)
- {
- _state = ReadCRLF(buffer, ref offset, size);
- if (_state == State.BodyFinished)
- return;
-
- _sawCR = false;
- }
-
- if (_state == State.Trailer && offset < size)
- {
- _state = ReadTrailer(buffer, ref offset, size);
- if (_state == State.Trailer)
- return;
-
- _saved.Length = 0;
- _sawCR = false;
- _gotit = false;
- }
-
- if (offset < size)
- InternalWrite(buffer, ref offset, size);
- }
-
- public bool WantMore => (_chunkRead != _chunkSize || _chunkSize != 0 || _state != State.None);
-
- public bool DataAvailable
- {
- get
- {
- int count = _chunks.Count;
- for (int i = 0; i < count; i++)
- {
- var ch = _chunks[i];
- if (ch == null || ch.Bytes == null)
- continue;
- if (ch.Bytes.Length > 0 && ch.Offset < ch.Bytes.Length)
- return (_state != State.Body);
- }
- return false;
- }
- }
-
- public int TotalDataSize => _totalWritten;
-
- public int ChunkLeft => _chunkSize - _chunkRead;
-
- private State ReadBody(byte[] buffer, ref int offset, int size)
- {
- if (_chunkSize == 0)
- return State.BodyFinished;
-
- int diff = size - offset;
- if (diff + _chunkRead > _chunkSize)
- diff = _chunkSize - _chunkRead;
-
- byte[] chunk = new byte[diff];
- Buffer.BlockCopy(buffer, offset, chunk, 0, diff);
- _chunks.Add(new Chunk(chunk));
- offset += diff;
- _chunkRead += diff;
- _totalWritten += diff;
-
- return (_chunkRead == _chunkSize) ? State.BodyFinished : State.Body;
- }
-
- private State GetChunkSize(byte[] buffer, ref int offset, int size)
- {
- _chunkRead = 0;
- _chunkSize = 0;
- char c = '\0';
- while (offset < size)
- {
- c = (char)buffer[offset++];
- if (c == '\r')
- {
- if (_sawCR)
- ThrowProtocolViolation("2 CR found");
-
- _sawCR = true;
- continue;
- }
-
- if (_sawCR && c == '\n')
- break;
-
- if (c == ' ')
- _gotit = true;
-
- if (!_gotit)
- _saved.Append(c);
-
- if (_saved.Length > 20)
- ThrowProtocolViolation("chunk size too long.");
- }
-
- if (!_sawCR || c != '\n')
- {
- if (offset < size)
- ThrowProtocolViolation("Missing \\n");
-
- try
- {
- if (_saved.Length > 0)
- {
- _chunkSize = int.Parse(RemoveChunkExtension(_saved.ToString()), NumberStyles.HexNumber);
- }
- }
- catch (Exception)
- {
- ThrowProtocolViolation("Cannot parse chunk size.");
- }
-
- return State.PartialSize;
- }
-
- _chunkRead = 0;
- try
- {
- _chunkSize = int.Parse(RemoveChunkExtension(_saved.ToString()), NumberStyles.HexNumber);
- }
- catch (Exception)
- {
- ThrowProtocolViolation("Cannot parse chunk size.");
- }
-
- if (_chunkSize == 0)
- {
- _trailerState = 2;
- return State.Trailer;
- }
-
- return State.Body;
- }
-
- private static string RemoveChunkExtension(string input)
- {
- int idx = input.IndexOf(';');
- if (idx == -1)
- return input;
- return input.Substring(0, idx);
- }
-
- private State ReadCRLF(byte[] buffer, ref int offset, int size)
- {
- if (!_sawCR)
- {
- if ((char)buffer[offset++] != '\r')
- ThrowProtocolViolation("Expecting \\r");
-
- _sawCR = true;
- if (offset == size)
- return State.BodyFinished;
- }
-
- if (_sawCR && (char)buffer[offset++] != '\n')
- ThrowProtocolViolation("Expecting \\n");
-
- return State.None;
- }
-
- private State ReadTrailer(byte[] buffer, ref int offset, int size)
- {
- char c = '\0';
-
- // short path
- if (_trailerState == 2 && (char)buffer[offset] == '\r' && _saved.Length == 0)
- {
- offset++;
- if (offset < size && (char)buffer[offset] == '\n')
- {
- offset++;
- return State.None;
- }
- offset--;
- }
-
- int st = _trailerState;
- string stString = "\r\n\r";
- while (offset < size && st < 4)
- {
- c = (char)buffer[offset++];
- if ((st == 0 || st == 2) && c == '\r')
- {
- st++;
- continue;
- }
-
- if ((st == 1 || st == 3) && c == '\n')
- {
- st++;
- continue;
- }
-
- if (st > 0)
- {
- _saved.Append(stString.Substring(0, _saved.Length == 0 ? st - 2 : st));
- st = 0;
- if (_saved.Length > 4196)
- ThrowProtocolViolation("Error reading trailer (too long).");
- }
- }
-
- if (st < 4)
- {
- _trailerState = st;
- if (offset < size)
- ThrowProtocolViolation("Error reading trailer.");
-
- return State.Trailer;
- }
-
- var reader = new StringReader(_saved.ToString());
- string line;
- while ((line = reader.ReadLine()) != null && line != "")
- _headers.Add(line);
-
- return State.None;
- }
-
- private static void ThrowProtocolViolation(string message)
- {
- var we = new WebException(message, null, WebExceptionStatus.ServerProtocolViolation, null);
- throw we;
- }
- }
-}
diff --git a/SocketHttpListener/Net/ChunkedInputStream.cs b/SocketHttpListener/Net/ChunkedInputStream.cs
deleted file mode 100644
index 7aa8529e3..000000000
--- a/SocketHttpListener/Net/ChunkedInputStream.cs
+++ /dev/null
@@ -1,178 +0,0 @@
-using System;
-using System.IO;
-using System.Net;
-
-namespace SocketHttpListener.Net
-{
- // Licensed to the .NET Foundation under one or more agreements.
- // See the LICENSE file in the project root for more information.
- //
- // System.Net.ResponseStream
- //
- // Author:
- // Gonzalo Paniagua Javier (gonzalo@novell.com)
- //
- // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
-
- internal sealed class ChunkedInputStream : HttpRequestStream
- {
- private ChunkStream _decoder;
- private readonly HttpListenerContext _context;
- private bool _no_more_data;
-
- private class ReadBufferState
- {
- public byte[] Buffer;
- public int Offset;
- public int Count;
- public int InitialCount;
- public HttpStreamAsyncResult Ares;
- public ReadBufferState(byte[] buffer, int offset, int count, HttpStreamAsyncResult ares)
- {
- Buffer = buffer;
- Offset = offset;
- Count = count;
- InitialCount = count;
- Ares = ares;
- }
- }
-
- public ChunkedInputStream(HttpListenerContext context, Stream stream, byte[] buffer, int offset, int length)
- : base(stream, buffer, offset, length)
- {
- _context = context;
- var coll = (WebHeaderCollection)context.Request.Headers;
- _decoder = new ChunkStream(coll);
- }
-
- public ChunkStream Decoder
- {
- get => _decoder;
- set => _decoder = value;
- }
-
- protected override int ReadCore(byte[] buffer, int offset, int count)
- {
- IAsyncResult ares = BeginReadCore(buffer, offset, count, null, null);
- return EndRead(ares);
- }
-
- protected override IAsyncResult BeginReadCore(byte[] buffer, int offset, int size, AsyncCallback cback, object state)
- {
- var ares = new HttpStreamAsyncResult(this);
- ares._callback = cback;
- ares._state = state;
- if (_no_more_data || size == 0 || _closed)
- {
- ares.Complete();
- return ares;
- }
- int nread = _decoder.Read(buffer, offset, size);
- offset += nread;
- size -= nread;
- if (size == 0)
- {
- // got all we wanted, no need to bother the decoder yet
- ares._count = nread;
- ares.Complete();
- return ares;
- }
- if (!_decoder.WantMore)
- {
- _no_more_data = nread == 0;
- ares._count = nread;
- ares.Complete();
- return ares;
- }
- ares._buffer = new byte[8192];
- ares._offset = 0;
- ares._count = 8192;
- var rb = new ReadBufferState(buffer, offset, size, ares);
- rb.InitialCount += nread;
- base.BeginReadCore(ares._buffer, ares._offset, ares._count, OnRead, rb);
- return ares;
- }
-
- private void OnRead(IAsyncResult base_ares)
- {
- ReadBufferState rb = (ReadBufferState)base_ares.AsyncState;
- var ares = rb.Ares;
- try
- {
- int nread = base.EndRead(base_ares);
- if (nread == 0)
- {
- _no_more_data = true;
- ares._count = rb.InitialCount - rb.Count;
- ares.Complete();
- return;
- }
-
- _decoder.Write(ares._buffer, ares._offset, nread);
- nread = _decoder.Read(rb.Buffer, rb.Offset, rb.Count);
- rb.Offset += nread;
- rb.Count -= nread;
- if (rb.Count == 0 || !_decoder.WantMore)
- {
- _no_more_data = !_decoder.WantMore && nread == 0;
- ares._count = rb.InitialCount - rb.Count;
- ares.Complete();
- return;
- }
- ares._offset = 0;
- ares._count = Math.Min(8192, _decoder.ChunkLeft + 6);
- base.BeginReadCore(ares._buffer, ares._offset, ares._count, OnRead, rb);
- }
- catch (Exception e)
- {
- _context.Connection.SendError(e.Message, 400);
- ares.Complete(e);
- }
- }
-
- public override int EndRead(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- throw new ArgumentNullException(nameof(asyncResult));
-
- var ares = asyncResult as HttpStreamAsyncResult;
- if (ares == null || !ReferenceEquals(this, ares._parent))
- {
- throw new ArgumentException("Invalid async result");
- }
- if (ares._endCalled)
- {
- throw new InvalidOperationException("Invalid end call");
- }
- ares._endCalled = true;
-
- if (!asyncResult.IsCompleted)
- asyncResult.AsyncWaitHandle.WaitOne();
-
- if (ares._error != null)
- throw new HttpListenerException((int)HttpStatusCode.BadRequest, "Operation aborted");
-
- return ares._count;
- }
- }
-}
diff --git a/SocketHttpListener/Net/CookieHelper.cs b/SocketHttpListener/Net/CookieHelper.cs
deleted file mode 100644
index 3ad76ff23..000000000
--- a/SocketHttpListener/Net/CookieHelper.cs
+++ /dev/null
@@ -1,141 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Net;
-using System.Text;
-
-namespace SocketHttpListener.Net
-{
- public static class CookieHelper
- {
- internal static CookieCollection Parse(string value, bool response)
- {
- return response
- ? parseResponse(value)
- : null;
- }
-
- private static string[] splitCookieHeaderValue(string value)
- {
- return new List<string>(value.SplitHeaderValue(',', ';')).ToArray();
- }
-
- private static CookieCollection parseResponse(string value)
- {
- var cookies = new CookieCollection();
-
- Cookie cookie = null;
- var pairs = splitCookieHeaderValue(value);
- for (int i = 0; i < pairs.Length; i++)
- {
- var pair = pairs[i].Trim();
- if (pair.Length == 0)
- continue;
-
- if (pair.StartsWith("version", StringComparison.OrdinalIgnoreCase))
- {
- if (cookie != null)
- cookie.Version = int.Parse(pair.GetValueInternal("=").Trim('"'));
- }
- else if (pair.StartsWith("expires", StringComparison.OrdinalIgnoreCase))
- {
- var buffer = new StringBuilder(pair.GetValueInternal("="), 32);
- if (i < pairs.Length - 1)
- buffer.AppendFormat(", {0}", pairs[++i].Trim());
-
- if (!DateTime.TryParseExact(
- buffer.ToString(),
- new[] { "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'", "r" },
- new CultureInfo("en-US"),
- DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal,
- out var expires))
- expires = DateTime.Now;
-
- if (cookie != null && cookie.Expires == DateTime.MinValue)
- cookie.Expires = expires.ToLocalTime();
- }
- else if (pair.StartsWith("max-age", StringComparison.OrdinalIgnoreCase))
- {
- var max = int.Parse(pair.GetValueInternal("=").Trim('"'));
- var expires = DateTime.Now.AddSeconds((double)max);
- if (cookie != null)
- cookie.Expires = expires;
- }
- else if (pair.StartsWith("path", StringComparison.OrdinalIgnoreCase))
- {
- if (cookie != null)
- cookie.Path = pair.GetValueInternal("=");
- }
- else if (pair.StartsWith("domain", StringComparison.OrdinalIgnoreCase))
- {
- if (cookie != null)
- cookie.Domain = pair.GetValueInternal("=");
- }
- else if (pair.StartsWith("port", StringComparison.OrdinalIgnoreCase))
- {
- var port = pair.Equals("port", StringComparison.OrdinalIgnoreCase)
- ? "\"\""
- : pair.GetValueInternal("=");
-
- if (cookie != null)
- cookie.Port = port;
- }
- else if (pair.StartsWith("comment", StringComparison.OrdinalIgnoreCase))
- {
- if (cookie != null)
- cookie.Comment = pair.GetValueInternal("=").UrlDecode();
- }
- else if (pair.StartsWith("commenturl", StringComparison.OrdinalIgnoreCase))
- {
- if (cookie != null)
- cookie.CommentUri = pair.GetValueInternal("=").Trim('"').ToUri();
- }
- else if (pair.StartsWith("discard", StringComparison.OrdinalIgnoreCase))
- {
- if (cookie != null)
- cookie.Discard = true;
- }
- else if (pair.StartsWith("secure", StringComparison.OrdinalIgnoreCase))
- {
- if (cookie != null)
- cookie.Secure = true;
- }
- else if (pair.StartsWith("httponly", StringComparison.OrdinalIgnoreCase))
- {
- if (cookie != null)
- cookie.HttpOnly = true;
- }
- else
- {
- if (cookie != null)
- cookies.Add(cookie);
-
- string name;
- string val = string.Empty;
-
- var pos = pair.IndexOf('=');
- if (pos == -1)
- {
- name = pair;
- }
- else if (pos == pair.Length - 1)
- {
- name = pair.Substring(0, pos).TrimEnd(' ');
- }
- else
- {
- name = pair.Substring(0, pos).TrimEnd(' ');
- val = pair.Substring(pos + 1).TrimStart(' ');
- }
-
- cookie = new Cookie(name, val);
- }
- }
-
- if (cookie != null)
- cookies.Add(cookie);
-
- return cookies;
- }
- }
-}
diff --git a/SocketHttpListener/Net/EntitySendFormat.cs b/SocketHttpListener/Net/EntitySendFormat.cs
deleted file mode 100644
index 3ed981084..000000000
--- a/SocketHttpListener/Net/EntitySendFormat.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace SocketHttpListener.Net
-{
- internal enum EntitySendFormat
- {
- ContentLength = 0, // Content-Length: XXX
- Chunked = 1, // Transfer-Encoding: chunked
- }
-}
diff --git a/SocketHttpListener/Net/HttpConnection.cs b/SocketHttpListener/Net/HttpConnection.cs
deleted file mode 100644
index e89f4ed9b..000000000
--- a/SocketHttpListener/Net/HttpConnection.cs
+++ /dev/null
@@ -1,528 +0,0 @@
-using System;
-using System.IO;
-using System.Net;
-using System.Net.Security;
-using System.Net.Sockets;
-using System.Security.Authentication;
-using System.Security.Cryptography.X509Certificates;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using MediaBrowser.Model.Cryptography;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.System;
-using Microsoft.Extensions.Logging;
-namespace SocketHttpListener.Net
-{
- sealed class HttpConnection
- {
- private static AsyncCallback s_onreadCallback = new AsyncCallback(OnRead);
- const int BufferSize = 8192;
- Socket _socket;
- Stream _stream;
- HttpEndPointListener _epl;
- MemoryStream _memoryStream;
- byte[] _buffer;
- HttpListenerContext _context;
- StringBuilder _currentLine;
- ListenerPrefix _prefix;
- HttpRequestStream _requestStream;
- HttpResponseStream _responseStream;
- bool _chunked;
- int _reuses;
- bool _contextBound;
- bool secure;
- IPEndPoint local_ep;
- HttpListener _lastListener;
- X509Certificate cert;
- SslStream ssl_stream;
-
- private readonly ILogger _logger;
- private readonly ICryptoProvider _cryptoProvider;
- private readonly IStreamHelper _streamHelper;
- private readonly IFileSystem _fileSystem;
- private readonly IEnvironmentInfo _environment;
-
- public HttpConnection(ILogger logger, Socket socket, HttpEndPointListener epl, bool secure,
- X509Certificate cert, ICryptoProvider cryptoProvider, IStreamHelper streamHelper, IFileSystem fileSystem,
- IEnvironmentInfo environment)
- {
- _logger = logger;
- this._socket = socket;
- this._epl = epl;
- this.secure = secure;
- this.cert = cert;
- _cryptoProvider = cryptoProvider;
- _streamHelper = streamHelper;
- _fileSystem = fileSystem;
- _environment = environment;
-
- if (secure == false)
- {
- _stream = new SocketStream(_socket, false);
- }
- else
- {
- ssl_stream = new SslStream(new SocketStream(_socket, false), false, (t, c, ch, e) =>
- {
- if (c == null)
- {
- return true;
- }
-
- //var c2 = c as X509Certificate2;
- //if (c2 == null)
- //{
- // c2 = new X509Certificate2(c.GetRawCertData());
- //}
-
- //_clientCert = c2;
- //_clientCertErrors = new int[] { (int)e };
- return true;
- });
-
- _stream = ssl_stream;
- }
- }
-
- public Stream Stream => _stream;
-
- public async Task Init()
- {
- if (ssl_stream != null)
- {
- var enableAsync = true;
- if (enableAsync)
- {
- await ssl_stream.AuthenticateAsServerAsync(cert, false, (SslProtocols)ServicePointManager.SecurityProtocol, false).ConfigureAwait(false);
- }
- else
- {
- ssl_stream.AuthenticateAsServer(cert, false, (SslProtocols)ServicePointManager.SecurityProtocol, false);
- }
- }
-
- InitInternal();
- }
-
- private void InitInternal()
- {
- _contextBound = false;
- _requestStream = null;
- _responseStream = null;
- _prefix = null;
- _chunked = false;
- _memoryStream = new MemoryStream();
- _position = 0;
- _inputState = InputState.RequestLine;
- _lineState = LineState.None;
- _context = new HttpListenerContext(this);
- }
-
- public bool IsClosed => (_socket == null);
-
- public int Reuses => _reuses;
-
- public IPEndPoint LocalEndPoint
- {
- get
- {
- if (local_ep != null)
- return local_ep;
-
- local_ep = (IPEndPoint)_socket.LocalEndPoint;
- return local_ep;
- }
- }
-
- public IPEndPoint RemoteEndPoint => _socket.RemoteEndPoint as IPEndPoint;
-
- public bool IsSecure => secure;
-
- public ListenerPrefix Prefix
- {
- get => _prefix;
- set => _prefix = value;
- }
-
- private void OnTimeout(object unused)
- {
- //_logger.LogInformation("HttpConnection timer fired");
- CloseSocket();
- Unbind();
- }
-
- public void BeginReadRequest()
- {
- if (_buffer == null)
- _buffer = new byte[BufferSize];
- try
- {
- _stream.BeginRead(_buffer, 0, BufferSize, s_onreadCallback, this);
- }
- catch
- {
- CloseSocket();
- Unbind();
- }
- }
-
- public HttpRequestStream GetRequestStream(bool chunked, long contentlength)
- {
- if (_requestStream == null)
- {
- byte[] buffer = _memoryStream.GetBuffer();
- int length = (int)_memoryStream.Length;
- _memoryStream = null;
- if (chunked)
- {
- _chunked = true;
- //_context.Response.SendChunked = true;
- _requestStream = new ChunkedInputStream(_context, _stream, buffer, _position, length - _position);
- }
- else
- {
- _requestStream = new HttpRequestStream(_stream, buffer, _position, length - _position, contentlength);
- }
- }
- return _requestStream;
- }
-
- public HttpResponseStream GetResponseStream(bool isExpect100Continue = false)
- {
- // TODO: can we get this _stream before reading the input?
- if (_responseStream == null)
- {
- var supportsDirectSocketAccess = !_context.Response.SendChunked && !isExpect100Continue && !secure;
-
- _responseStream = new HttpResponseStream(_stream, _context.Response, false, _streamHelper, _socket, supportsDirectSocketAccess, _environment, _fileSystem, _logger);
- }
- return _responseStream;
- }
-
- private static void OnRead(IAsyncResult ares)
- {
- var cnc = (HttpConnection)ares.AsyncState;
- cnc.OnReadInternal(ares);
- }
-
- private void OnReadInternal(IAsyncResult ares)
- {
- int nread = -1;
- try
- {
- nread = _stream.EndRead(ares);
- _memoryStream.Write(_buffer, 0, nread);
- if (_memoryStream.Length > 32768)
- {
- SendError("Bad Request", 400);
- Close(true);
- return;
- }
- }
- catch
- {
- if (_memoryStream != null && _memoryStream.Length > 0)
- SendError();
- if (_socket != null)
- {
- CloseSocket();
- Unbind();
- }
- return;
- }
-
- if (nread == 0)
- {
- CloseSocket();
- Unbind();
- return;
- }
-
- if (ProcessInput(_memoryStream))
- {
- if (!_context.HaveError)
- _context.Request.FinishInitialization();
-
- if (_context.HaveError)
- {
- SendError();
- Close(true);
- return;
- }
-
- if (!_epl.BindContext(_context))
- {
- const int NotFoundErrorCode = 404;
- SendError(HttpStatusDescription.Get(NotFoundErrorCode), NotFoundErrorCode);
- Close(true);
- return;
- }
- HttpListener listener = _epl.Listener;
- if (_lastListener != listener)
- {
- RemoveConnection();
- listener.AddConnection(this);
- _lastListener = listener;
- }
-
- _contextBound = true;
- listener.RegisterContext(_context);
- return;
- }
- _stream.BeginRead(_buffer, 0, BufferSize, s_onreadCallback, this);
- }
-
- private void RemoveConnection()
- {
- if (_lastListener == null)
- _epl.RemoveConnection(this);
- else
- _lastListener.RemoveConnection(this);
- }
-
- private enum InputState
- {
- RequestLine,
- Headers
- }
-
- private enum LineState
- {
- None,
- CR,
- LF
- }
-
- InputState _inputState = InputState.RequestLine;
- LineState _lineState = LineState.None;
- int _position;
-
- // true -> done processing
- // false -> need more input
- private bool ProcessInput(MemoryStream ms)
- {
- byte[] buffer = ms.GetBuffer();
- int len = (int)ms.Length;
- int used = 0;
- string line;
-
- while (true)
- {
- if (_context.HaveError)
- return true;
-
- if (_position >= len)
- break;
-
- try
- {
- line = ReadLine(buffer, _position, len - _position, ref used);
- _position += used;
- }
- catch
- {
- _context.ErrorMessage = "Bad request";
- _context.ErrorStatus = 400;
- return true;
- }
-
- if (line == null)
- break;
-
- if (line == "")
- {
- if (_inputState == InputState.RequestLine)
- continue;
- _currentLine = null;
- ms = null;
- return true;
- }
-
- if (_inputState == InputState.RequestLine)
- {
- _context.Request.SetRequestLine(line);
- _inputState = InputState.Headers;
- }
- else
- {
- try
- {
- _context.Request.AddHeader(line);
- }
- catch (Exception e)
- {
- _context.ErrorMessage = e.Message;
- _context.ErrorStatus = 400;
- return true;
- }
- }
- }
-
- if (used == len)
- {
- ms.SetLength(0);
- _position = 0;
- }
- return false;
- }
-
- private string ReadLine(byte[] buffer, int offset, int len, ref int used)
- {
- if (_currentLine == null)
- _currentLine = new StringBuilder(128);
- int last = offset + len;
- used = 0;
- for (int i = offset; i < last && _lineState != LineState.LF; i++)
- {
- used++;
- byte b = buffer[i];
- if (b == 13)
- {
- _lineState = LineState.CR;
- }
- else if (b == 10)
- {
- _lineState = LineState.LF;
- }
- else
- {
- _currentLine.Append((char)b);
- }
- }
-
- string result = null;
- if (_lineState == LineState.LF)
- {
- _lineState = LineState.None;
- result = _currentLine.ToString();
- _currentLine.Length = 0;
- }
-
- return result;
- }
-
- public void SendError(string msg, int status)
- {
- try
- {
- HttpListenerResponse response = _context.Response;
- response.StatusCode = status;
- response.ContentType = "text/html";
- string description = HttpStatusDescription.Get(status);
- string str;
- if (msg != null)
- str = string.Format("<h1>{0} ({1})</h1>", description, msg);
- else
- str = string.Format("<h1>{0}</h1>", description);
-
- byte[] error = Encoding.UTF8.GetBytes(str);
- response.Close(error, false);
- }
- catch
- {
- // response was already closed
- }
- }
-
- public void SendError()
- {
- SendError(_context.ErrorMessage, _context.ErrorStatus);
- }
-
- private void Unbind()
- {
- if (_contextBound)
- {
- _epl.UnbindContext(_context);
- _contextBound = false;
- }
- }
-
- public void Close()
- {
- Close(false);
- }
-
- private void CloseSocket()
- {
- if (_socket == null)
- return;
-
- try
- {
- _socket.Close();
- }
- catch { }
- finally
- {
- _socket = null;
- }
-
- RemoveConnection();
- }
-
- internal void Close(bool force)
- {
- if (_socket != null)
- {
- Stream st = GetResponseStream();
- if (st != null)
- st.Close();
-
- _responseStream = null;
- }
-
- if (_socket != null)
- {
- force |= !_context.Request.KeepAlive;
- if (!force)
- force = (string.Equals(_context.Response.Headers["connection"], "close", StringComparison.OrdinalIgnoreCase));
-
- if (!force && _context.Request.FlushInput())
- {
- if (_chunked && _context.Response.ForceCloseChunked == false)
- {
- // Don't close. Keep working.
- _reuses++;
- Unbind();
- InitInternal();
- BeginReadRequest();
- return;
- }
-
- _reuses++;
- Unbind();
- InitInternal();
- BeginReadRequest();
- return;
- }
-
- Socket s = _socket;
- _socket = null;
- try
- {
- if (s != null)
- s.Shutdown(SocketShutdown.Both);
- }
- catch
- {
- }
- finally
- {
- if (s != null)
- {
- try
- {
- s.Close();
- }
- catch { }
- }
- }
- Unbind();
- RemoveConnection();
- return;
- }
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpEndPointListener.cs b/SocketHttpListener/Net/HttpEndPointListener.cs
deleted file mode 100644
index 35d1af648..000000000
--- a/SocketHttpListener/Net/HttpEndPointListener.cs
+++ /dev/null
@@ -1,526 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Net;
-using System.Net.Sockets;
-using System.Security.Cryptography.X509Certificates;
-using System.Threading;
-using MediaBrowser.Model.Cryptography;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Net;
-using MediaBrowser.Model.System;
-using Microsoft.Extensions.Logging;
-
-namespace SocketHttpListener.Net
-{
- internal sealed class HttpEndPointListener
- {
- private HttpListener _listener;
- private IPEndPoint _endpoint;
- private Socket _socket;
- private Dictionary<ListenerPrefix, HttpListener> _prefixes;
- private List<ListenerPrefix> _unhandledPrefixes; // host = '*'
- private List<ListenerPrefix> _allPrefixes; // host = '+'
- private X509Certificate _cert;
- private bool _secure;
- private Dictionary<HttpConnection, HttpConnection> _unregisteredConnections;
-
- private readonly ILogger _logger;
- private bool _closed;
- private bool _enableDualMode;
- private readonly ICryptoProvider _cryptoProvider;
- private readonly ISocketFactory _socketFactory;
- private readonly IStreamHelper _streamHelper;
- private readonly IFileSystem _fileSystem;
- private readonly IEnvironmentInfo _environment;
-
- public HttpEndPointListener(HttpListener listener, IPAddress addr, int port, bool secure, X509Certificate cert,
- ILogger logger, ICryptoProvider cryptoProvider, ISocketFactory socketFactory, IStreamHelper streamHelper,
- IFileSystem fileSystem, IEnvironmentInfo environment)
- {
- this._listener = listener;
- _logger = logger;
- _cryptoProvider = cryptoProvider;
- _socketFactory = socketFactory;
- _streamHelper = streamHelper;
- _fileSystem = fileSystem;
- _environment = environment;
-
- this._secure = secure;
- this._cert = cert;
-
- _enableDualMode = addr.Equals(IPAddress.IPv6Any);
- _endpoint = new IPEndPoint(addr, port);
-
- _prefixes = new Dictionary<ListenerPrefix, HttpListener>();
- _unregisteredConnections = new Dictionary<HttpConnection, HttpConnection>();
-
- CreateSocket();
- }
-
- internal HttpListener Listener => _listener;
-
- private void CreateSocket()
- {
- try
- {
- _socket = CreateSocket(_endpoint.Address.AddressFamily, _enableDualMode);
- }
- catch (SocketCreateException ex)
- {
- if (_enableDualMode && _endpoint.Address.Equals(IPAddress.IPv6Any) &&
- (string.Equals(ex.ErrorCode, "AddressFamilyNotSupported", StringComparison.OrdinalIgnoreCase) ||
- // mono 4.8.1 and lower on bsd is throwing this
- string.Equals(ex.ErrorCode, "ProtocolNotSupported", StringComparison.OrdinalIgnoreCase) ||
- // mono 5.2 on bsd is throwing this
- string.Equals(ex.ErrorCode, "OperationNotSupported", StringComparison.OrdinalIgnoreCase)))
- {
- _endpoint = new IPEndPoint(IPAddress.Any, _endpoint.Port);
- _enableDualMode = false;
- _socket = CreateSocket(_endpoint.Address.AddressFamily, _enableDualMode);
- }
- else
- {
- throw;
- }
- }
-
- try
- {
- _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
- }
- catch (SocketException)
- {
- // This is not supported on all operating systems (qnap)
- }
-
- _socket.Bind(_endpoint);
-
- // This is the number TcpListener uses.
- _socket.Listen(2147483647);
-
- Accept();
-
- _closed = false;
- }
-
- private void Accept()
- {
- var acceptEventArg = new SocketAsyncEventArgs();
- acceptEventArg.UserToken = this;
- acceptEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(OnAccept);
-
- Accept(acceptEventArg);
- }
-
- private static void TryCloseAndDispose(Socket socket)
- {
- try
- {
- using (socket)
- {
- socket.Close();
- }
- }
- catch
- {
-
- }
- }
-
- private static void TryClose(Socket socket)
- {
- try
- {
- socket.Close();
- }
- catch
- {
-
- }
- }
-
- private void Accept(SocketAsyncEventArgs acceptEventArg)
- {
- // acceptSocket must be cleared since the context object is being reused
- acceptEventArg.AcceptSocket = null;
-
- try
- {
- bool willRaiseEvent = _socket.AcceptAsync(acceptEventArg);
-
- if (!willRaiseEvent)
- {
- ProcessAccept(acceptEventArg);
- }
- }
- catch (ObjectDisposedException)
- {
- // TODO Investigate or properly fix.
- }
- catch (Exception ex)
- {
- var epl = (HttpEndPointListener)acceptEventArg.UserToken;
-
- epl._logger.LogError(ex, "Error in socket.AcceptAsync");
- }
- }
-
- // This method is the callback method associated with Socket.AcceptAsync
- // operations and is invoked when an accept operation is complete
- //
- private static void OnAccept(object sender, SocketAsyncEventArgs e)
- {
- ProcessAccept(e);
- }
-
- private static async void ProcessAccept(SocketAsyncEventArgs args)
- {
- var epl = (HttpEndPointListener)args.UserToken;
-
- if (epl._closed)
- {
- return;
- }
-
- // http://msdn.microsoft.com/en-us/library/system.net.sockets.acceptSocket.acceptasync%28v=vs.110%29.aspx
- // Under certain conditions ConnectionReset can occur
- // Need to attept to re-accept
- var socketError = args.SocketError;
- var accepted = args.AcceptSocket;
-
- epl.Accept(args);
-
- if (socketError == SocketError.ConnectionReset)
- {
- epl._logger.LogError("SocketError.ConnectionReset reported. Attempting to re-accept.");
- return;
- }
-
- if (accepted == null)
- {
- return;
- }
-
- if (epl._secure && epl._cert == null)
- {
- TryClose(accepted);
- return;
- }
-
- try
- {
- var remoteEndPointString = accepted.RemoteEndPoint == null ? string.Empty : accepted.RemoteEndPoint.ToString();
- var localEndPointString = accepted.LocalEndPoint == null ? string.Empty : accepted.LocalEndPoint.ToString();
- //_logger.LogInformation("HttpEndPointListener Accepting connection from {0} to {1} secure connection requested: {2}", remoteEndPointString, localEndPointString, _secure);
-
- var conn = new HttpConnection(epl._logger, accepted, epl, epl._secure, epl._cert, epl._cryptoProvider, epl._streamHelper, epl._fileSystem, epl._environment);
-
- await conn.Init().ConfigureAwait(false);
-
- //_logger.LogDebug("Adding unregistered connection to {0}. Id: {1}", accepted.RemoteEndPoint, connectionId);
- lock (epl._unregisteredConnections)
- {
- epl._unregisteredConnections[conn] = conn;
- }
- conn.BeginReadRequest();
- }
- catch (Exception ex)
- {
- epl._logger.LogError(ex, "Error in ProcessAccept");
-
- TryClose(accepted);
- epl.Accept();
- return;
- }
- }
-
- private Socket CreateSocket(AddressFamily addressFamily, bool dualMode)
- {
- try
- {
- var socket = new Socket(addressFamily, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
-
- if (dualMode)
- {
- socket.DualMode = true;
- }
-
- return socket;
- }
- catch (SocketException ex)
- {
- throw new SocketCreateException(ex.SocketErrorCode.ToString(), ex);
- }
- catch (ArgumentException ex)
- {
- if (dualMode)
- {
- // Mono for BSD incorrectly throws ArgumentException instead of SocketException
- throw new SocketCreateException("AddressFamilyNotSupported", ex);
- }
- else
- {
- throw;
- }
- }
- }
-
- internal void RemoveConnection(HttpConnection conn)
- {
- lock (_unregisteredConnections)
- {
- _unregisteredConnections.Remove(conn);
- }
- }
-
- public bool BindContext(HttpListenerContext context)
- {
- var req = context.Request;
- HttpListener listener = SearchListener(req.Url, out var prefix);
- if (listener == null)
- return false;
-
- context.Connection.Prefix = prefix;
- return true;
- }
-
- public void UnbindContext(HttpListenerContext context)
- {
- if (context == null || context.Request == null)
- return;
-
- _listener.UnregisterContext(context);
- }
-
- private HttpListener SearchListener(Uri uri, out ListenerPrefix prefix)
- {
- prefix = null;
- if (uri == null)
- return null;
-
- string host = uri.Host;
- int port = uri.Port;
- string path = WebUtility.UrlDecode(uri.AbsolutePath);
- string pathSlash = path[path.Length - 1] == '/' ? path : path + "/";
-
- HttpListener bestMatch = null;
- int bestLength = -1;
-
- if (host != null && host != "")
- {
- Dictionary<ListenerPrefix, HttpListener> localPrefixes = _prefixes;
- foreach (var p in localPrefixes.Keys)
- {
- string ppath = p.Path;
- if (ppath.Length < bestLength)
- continue;
-
- if (p.Host != host || p.Port != port)
- continue;
-
- if (path.StartsWith(ppath) || pathSlash.StartsWith(ppath))
- {
- bestLength = ppath.Length;
- bestMatch = localPrefixes[p];
- prefix = p;
- }
- }
- if (bestLength != -1)
- return bestMatch;
- }
-
- List<ListenerPrefix> list = _unhandledPrefixes;
- bestMatch = MatchFromList(host, path, list, out prefix);
-
- if (path != pathSlash && bestMatch == null)
- bestMatch = MatchFromList(host, pathSlash, list, out prefix);
-
- if (bestMatch != null)
- return bestMatch;
-
- list = _allPrefixes;
- bestMatch = MatchFromList(host, path, list, out prefix);
-
- if (path != pathSlash && bestMatch == null)
- bestMatch = MatchFromList(host, pathSlash, list, out prefix);
-
- if (bestMatch != null)
- return bestMatch;
-
- return null;
- }
-
- private HttpListener MatchFromList(string host, string path, List<ListenerPrefix> list, out ListenerPrefix prefix)
- {
- prefix = null;
- if (list == null)
- return null;
-
- HttpListener bestMatch = null;
- int bestLength = -1;
-
- foreach (ListenerPrefix p in list)
- {
- string ppath = p.Path;
- if (ppath.Length < bestLength)
- continue;
-
- if (path.StartsWith(ppath))
- {
- bestLength = ppath.Length;
- bestMatch = p._listener;
- prefix = p;
- }
- }
-
- return bestMatch;
- }
-
- private void AddSpecial(List<ListenerPrefix> list, ListenerPrefix prefix)
- {
- if (list == null)
- return;
-
- foreach (ListenerPrefix p in list)
- {
- if (p.Path == prefix.Path)
- throw new Exception("net_listener_already");
- }
- list.Add(prefix);
- }
-
- private bool RemoveSpecial(List<ListenerPrefix> list, ListenerPrefix prefix)
- {
- if (list == null)
- return false;
-
- int c = list.Count;
- for (int i = 0; i < c; i++)
- {
- ListenerPrefix p = list[i];
- if (p.Path == prefix.Path)
- {
- list.RemoveAt(i);
- return true;
- }
- }
- return false;
- }
-
- private void CheckIfRemove()
- {
- if (_prefixes.Count > 0)
- return;
-
- List<ListenerPrefix> list = _unhandledPrefixes;
- if (list != null && list.Count > 0)
- return;
-
- list = _allPrefixes;
- if (list != null && list.Count > 0)
- return;
-
- HttpEndPointManager.RemoveEndPoint(this, _endpoint);
- }
-
- public void Close()
- {
- _closed = true;
- _socket.Close();
- lock (_unregisteredConnections)
- {
- // Clone the list because RemoveConnection can be called from Close
- var connections = new List<HttpConnection>(_unregisteredConnections.Keys);
-
- foreach (HttpConnection c in connections)
- c.Close(true);
- _unregisteredConnections.Clear();
- }
- }
-
- public void AddPrefix(ListenerPrefix prefix, HttpListener listener)
- {
- List<ListenerPrefix> current;
- List<ListenerPrefix> future;
- if (prefix.Host == "*")
- {
- do
- {
- current = _unhandledPrefixes;
- future = current != null ? new List<ListenerPrefix>(current) : new List<ListenerPrefix>();
- prefix._listener = listener;
- AddSpecial(future, prefix);
- } while (Interlocked.CompareExchange(ref _unhandledPrefixes, future, current) != current);
- return;
- }
-
- if (prefix.Host == "+")
- {
- do
- {
- current = _allPrefixes;
- future = current != null ? new List<ListenerPrefix>(current) : new List<ListenerPrefix>();
- prefix._listener = listener;
- AddSpecial(future, prefix);
- } while (Interlocked.CompareExchange(ref _allPrefixes, future, current) != current);
- return;
- }
-
- Dictionary<ListenerPrefix, HttpListener> prefs, p2;
- do
- {
- prefs = _prefixes;
- if (prefs.ContainsKey(prefix))
- {
- throw new Exception("net_listener_already");
- }
- p2 = new Dictionary<ListenerPrefix, HttpListener>(prefs);
- p2[prefix] = listener;
- } while (Interlocked.CompareExchange(ref _prefixes, p2, prefs) != prefs);
- }
-
- public void RemovePrefix(ListenerPrefix prefix, HttpListener listener)
- {
- List<ListenerPrefix> current;
- List<ListenerPrefix> future;
- if (prefix.Host == "*")
- {
- do
- {
- current = _unhandledPrefixes;
- future = current != null ? new List<ListenerPrefix>(current) : new List<ListenerPrefix>();
- if (!RemoveSpecial(future, prefix))
- break; // Prefix not found
- } while (Interlocked.CompareExchange(ref _unhandledPrefixes, future, current) != current);
-
- CheckIfRemove();
- return;
- }
-
- if (prefix.Host == "+")
- {
- do
- {
- current = _allPrefixes;
- future = current != null ? new List<ListenerPrefix>(current) : new List<ListenerPrefix>();
- if (!RemoveSpecial(future, prefix))
- break; // Prefix not found
- } while (Interlocked.CompareExchange(ref _allPrefixes, future, current) != current);
- CheckIfRemove();
- return;
- }
-
- Dictionary<ListenerPrefix, HttpListener> prefs, p2;
- do
- {
- prefs = _prefixes;
- if (!prefs.ContainsKey(prefix))
- break;
-
- p2 = new Dictionary<ListenerPrefix, HttpListener>(prefs);
- p2.Remove(prefix);
- } while (Interlocked.CompareExchange(ref _prefixes, p2, prefs) != prefs);
- CheckIfRemove();
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpEndPointManager.cs b/SocketHttpListener/Net/HttpEndPointManager.cs
deleted file mode 100644
index 27b4244a6..000000000
--- a/SocketHttpListener/Net/HttpEndPointManager.cs
+++ /dev/null
@@ -1,192 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Net;
-using System.Net.Sockets;
-using Microsoft.Extensions.Logging;
-
-namespace SocketHttpListener.Net
-{
- internal sealed class HttpEndPointManager
- {
- private static Dictionary<IPAddress, Dictionary<int, HttpEndPointListener>> s_ipEndPoints = new Dictionary<IPAddress, Dictionary<int, HttpEndPointListener>>();
-
- private HttpEndPointManager()
- {
- }
-
- public static void AddListener(ILogger logger, HttpListener listener)
- {
- var added = new List<string>();
- try
- {
- lock ((s_ipEndPoints as ICollection).SyncRoot)
- {
- foreach (string prefix in listener.Prefixes)
- {
- AddPrefixInternal(logger, prefix, listener);
- added.Add(prefix);
- }
- }
- }
- catch
- {
- foreach (string prefix in added)
- {
- RemovePrefix(logger, prefix, listener);
- }
- throw;
- }
- }
-
- public static void AddPrefix(ILogger logger, string prefix, HttpListener listener)
- {
- lock ((s_ipEndPoints as ICollection).SyncRoot)
- {
- AddPrefixInternal(logger, prefix, listener);
- }
- }
-
- private static void AddPrefixInternal(ILogger logger, string p, HttpListener listener)
- {
- int start = p.IndexOf(':') + 3;
- int colon = p.IndexOf(':', start);
- if (colon != -1)
- {
- // root can't be -1 here, since we've already checked for ending '/' in ListenerPrefix.
- int root = p.IndexOf('/', colon, p.Length - colon);
- string portString = p.Substring(colon + 1, root - colon - 1);
-
- if (!int.TryParse(portString, out var port) || port <= 0 || port >= 65536)
- {
- throw new HttpListenerException((int)HttpStatusCode.BadRequest, "net_invalid_port");
- }
- }
-
- var lp = new ListenerPrefix(p);
- if (lp.Host != "*" && lp.Host != "+" && Uri.CheckHostName(lp.Host) == UriHostNameType.Unknown)
- throw new HttpListenerException((int)HttpStatusCode.BadRequest, "net_listener_host");
-
- if (lp.Path.IndexOf('%') != -1)
- throw new HttpListenerException((int)HttpStatusCode.BadRequest, "net_invalid_path");
-
- if (lp.Path.IndexOf("//", StringComparison.Ordinal) != -1)
- throw new HttpListenerException((int)HttpStatusCode.BadRequest, "net_invalid_path");
-
- // listens on all the interfaces if host name cannot be parsed by IPAddress.
- HttpEndPointListener epl = GetEPListener(logger, lp.Host, lp.Port, listener, lp.Secure);
- epl.AddPrefix(lp, listener);
- }
-
- private static IPAddress GetIpAnyAddress(HttpListener listener)
- {
- return listener.EnableDualMode ? IPAddress.IPv6Any : IPAddress.Any;
- }
-
- private static HttpEndPointListener GetEPListener(ILogger logger, string host, int port, HttpListener listener, bool secure)
- {
- IPAddress addr;
- if (host == "*" || host == "+")
- {
- addr = GetIpAnyAddress(listener);
- }
- else
- {
- const int NotSupportedErrorCode = 50;
- try
- {
- addr = Dns.GetHostAddresses(host)[0];
- }
- catch
- {
- // Throw same error code as windows, request is not supported.
- throw new HttpListenerException(NotSupportedErrorCode, "net_listener_not_supported");
- }
-
- if (IPAddress.Any.Equals(addr))
- {
- // Don't support listening to 0.0.0.0, match windows behavior.
- throw new HttpListenerException(NotSupportedErrorCode, "net_listener_not_supported");
- }
- }
-
- Dictionary<int, HttpEndPointListener> p = null;
- if (s_ipEndPoints.ContainsKey(addr))
- {
- p = s_ipEndPoints[addr];
- }
- else
- {
- p = new Dictionary<int, HttpEndPointListener>();
- s_ipEndPoints[addr] = p;
- }
-
- HttpEndPointListener epl = null;
- if (p.ContainsKey(port))
- {
- epl = p[port];
- }
- else
- {
- try
- {
- epl = new HttpEndPointListener(listener, addr, port, secure, listener.Certificate, logger, listener.CryptoProvider, listener.SocketFactory, listener.StreamHelper, listener.FileSystem, listener.EnvironmentInfo);
- }
- catch (SocketException ex)
- {
- throw new HttpListenerException(ex.ErrorCode, ex.Message);
- }
- p[port] = epl;
- }
-
- return epl;
- }
-
- public static void RemoveEndPoint(HttpEndPointListener epl, IPEndPoint ep)
- {
- lock ((s_ipEndPoints as ICollection).SyncRoot)
- {
- Dictionary<int, HttpEndPointListener> p = null;
- p = s_ipEndPoints[ep.Address];
- p.Remove(ep.Port);
- if (p.Count == 0)
- {
- s_ipEndPoints.Remove(ep.Address);
- }
- epl.Close();
- }
- }
-
- public static void RemoveListener(ILogger logger, HttpListener listener)
- {
- lock ((s_ipEndPoints as ICollection).SyncRoot)
- {
- foreach (string prefix in listener.Prefixes)
- {
- RemovePrefixInternal(logger, prefix, listener);
- }
- }
- }
-
- public static void RemovePrefix(ILogger logger, string prefix, HttpListener listener)
- {
- lock ((s_ipEndPoints as ICollection).SyncRoot)
- {
- RemovePrefixInternal(logger, prefix, listener);
- }
- }
-
- private static void RemovePrefixInternal(ILogger logger, string prefix, HttpListener listener)
- {
- var lp = new ListenerPrefix(prefix);
- if (lp.Path.IndexOf('%') != -1)
- return;
-
- if (lp.Path.IndexOf("//", StringComparison.Ordinal) != -1)
- return;
-
- HttpEndPointListener epl = GetEPListener(logger, lp.Host, lp.Port, listener, lp.Secure);
- epl.RemovePrefix(lp, listener);
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpKnownHeaderNames.cs b/SocketHttpListener/Net/HttpKnownHeaderNames.cs
deleted file mode 100644
index dc6f2ce41..000000000
--- a/SocketHttpListener/Net/HttpKnownHeaderNames.cs
+++ /dev/null
@@ -1,91 +0,0 @@
-namespace SocketHttpListener.Net
-{
- internal static partial class HttpKnownHeaderNames
- {
- // When adding a new constant, add it to HttpKnownHeaderNames.TryGetHeaderName.cs as well.
-
- public const string Accept = "Accept";
- public const string AcceptCharset = "Accept-Charset";
- public const string AcceptEncoding = "Accept-Encoding";
- public const string AcceptLanguage = "Accept-Language";
- public const string AcceptPatch = "Accept-Patch";
- public const string AcceptRanges = "Accept-Ranges";
- public const string AccessControlAllowCredentials = "Access-Control-Allow-Credentials";
- public const string AccessControlAllowHeaders = "Access-Control-Allow-Headers";
- public const string AccessControlAllowMethods = "Access-Control-Allow-Methods";
- public const string AccessControlAllowOrigin = "Access-Control-Allow-Origin";
- public const string AccessControlExposeHeaders = "Access-Control-Expose-Headers";
- public const string AccessControlMaxAge = "Access-Control-Max-Age";
- public const string Age = "Age";
- public const string Allow = "Allow";
- public const string AltSvc = "Alt-Svc";
- public const string Authorization = "Authorization";
- public const string CacheControl = "Cache-Control";
- public const string Connection = "Connection";
- public const string ContentDisposition = "Content-Disposition";
- public const string ContentEncoding = "Content-Encoding";
- public const string ContentLanguage = "Content-Language";
- public const string ContentLength = "Content-Length";
- public const string ContentLocation = "Content-Location";
- public const string ContentMD5 = "Content-MD5";
- public const string ContentRange = "Content-Range";
- public const string ContentSecurityPolicy = "Content-Security-Policy";
- public const string ContentType = "Content-Type";
- public const string Cookie = "Cookie";
- public const string Cookie2 = "Cookie2";
- public const string Date = "Date";
- public const string ETag = "ETag";
- public const string Expect = "Expect";
- public const string Expires = "Expires";
- public const string From = "From";
- public const string Host = "Host";
- public const string IfMatch = "If-Match";
- public const string IfModifiedSince = "If-Modified-Since";
- public const string IfNoneMatch = "If-None-Match";
- public const string IfRange = "If-Range";
- public const string IfUnmodifiedSince = "If-Unmodified-Since";
- public const string KeepAlive = "Keep-Alive";
- public const string LastModified = "Last-Modified";
- public const string Link = "Link";
- public const string Location = "Location";
- public const string MaxForwards = "Max-Forwards";
- public const string Origin = "Origin";
- public const string P3P = "P3P";
- public const string Pragma = "Pragma";
- public const string ProxyAuthenticate = "Proxy-Authenticate";
- public const string ProxyAuthorization = "Proxy-Authorization";
- public const string ProxyConnection = "Proxy-Connection";
- public const string PublicKeyPins = "Public-Key-Pins";
- public const string Range = "Range";
- public const string Referer = "Referer"; // NB: The spelling-mistake "Referer" for "Referrer" must be matched.
- public const string RetryAfter = "Retry-After";
- public const string SecWebSocketAccept = "Sec-WebSocket-Accept";
- public const string SecWebSocketExtensions = "Sec-WebSocket-Extensions";
- public const string SecWebSocketKey = "Sec-WebSocket-Key";
- public const string SecWebSocketProtocol = "Sec-WebSocket-Protocol";
- public const string SecWebSocketVersion = "Sec-WebSocket-Version";
- public const string Server = "Server";
- public const string SetCookie = "Set-Cookie";
- public const string SetCookie2 = "Set-Cookie2";
- public const string StrictTransportSecurity = "Strict-Transport-Security";
- public const string TE = "TE";
- public const string TSV = "TSV";
- public const string Trailer = "Trailer";
- public const string TransferEncoding = "Transfer-Encoding";
- public const string Upgrade = "Upgrade";
- public const string UpgradeInsecureRequests = "Upgrade-Insecure-Requests";
- public const string UserAgent = "User-Agent";
- public const string Vary = "Vary";
- public const string Via = "Via";
- public const string WWWAuthenticate = "WWW-Authenticate";
- public const string Warning = "Warning";
- public const string XAspNetVersion = "X-AspNet-Version";
- public const string XContentDuration = "X-Content-Duration";
- public const string XContentTypeOptions = "X-Content-Type-Options";
- public const string XFrameOptions = "X-Frame-Options";
- public const string XMSEdgeRef = "X-MSEdge-Ref";
- public const string XPoweredBy = "X-Powered-By";
- public const string XRequestID = "X-Request-ID";
- public const string XUACompatible = "X-UA-Compatible";
- }
-}
diff --git a/SocketHttpListener/Net/HttpListener.cs b/SocketHttpListener/Net/HttpListener.cs
deleted file mode 100644
index b80180679..000000000
--- a/SocketHttpListener/Net/HttpListener.cs
+++ /dev/null
@@ -1,277 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Net;
-using System.Security.Cryptography.X509Certificates;
-using MediaBrowser.Common.Net;
-using MediaBrowser.Model.Cryptography;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Net;
-using MediaBrowser.Model.System;
-using Microsoft.Extensions.Logging;
-
-namespace SocketHttpListener.Net
-{
- public sealed class HttpListener : IDisposable
- {
- internal ICryptoProvider CryptoProvider { get; private set; }
- internal ISocketFactory SocketFactory { get; private set; }
- internal IFileSystem FileSystem { get; private set; }
- internal IStreamHelper StreamHelper { get; private set; }
- internal INetworkManager NetworkManager { get; private set; }
- internal IEnvironmentInfo EnvironmentInfo { get; private set; }
-
- public bool EnableDualMode { get; set; }
-
- AuthenticationSchemes auth_schemes;
- HttpListenerPrefixCollection prefixes;
- AuthenticationSchemeSelector auth_selector;
- string realm;
- bool unsafe_ntlm_auth;
- bool listening;
- bool disposed;
-
- Dictionary<HttpListenerContext, HttpListenerContext> registry; // Dictionary<HttpListenerContext,HttpListenerContext>
- Dictionary<HttpConnection, HttpConnection> connections;
- private ILogger _logger;
- private X509Certificate _certificate;
-
- public Action<HttpListenerContext> OnContext { get; set; }
-
- public HttpListener(ILogger logger, ICryptoProvider cryptoProvider, ISocketFactory socketFactory,
- INetworkManager networkManager, IStreamHelper streamHelper, IFileSystem fileSystem,
- IEnvironmentInfo environmentInfo)
- {
- _logger = logger;
- CryptoProvider = cryptoProvider;
- SocketFactory = socketFactory;
- NetworkManager = networkManager;
- StreamHelper = streamHelper;
- FileSystem = fileSystem;
- EnvironmentInfo = environmentInfo;
- prefixes = new HttpListenerPrefixCollection(logger, this);
- registry = new Dictionary<HttpListenerContext, HttpListenerContext>();
- connections = new Dictionary<HttpConnection, HttpConnection>();
- auth_schemes = AuthenticationSchemes.Anonymous;
- }
-
- public HttpListener(ILogger logger, X509Certificate certificate, ICryptoProvider cryptoProvider,
- ISocketFactory socketFactory, INetworkManager networkManager, IStreamHelper streamHelper,
- IFileSystem fileSystem, IEnvironmentInfo environmentInfo)
- : this(logger, cryptoProvider, socketFactory, networkManager, streamHelper, fileSystem, environmentInfo)
- {
- _certificate = certificate;
- }
-
- public void LoadCert(X509Certificate cert)
- {
- _certificate = cert;
- }
-
- // TODO: Digest, NTLM and Negotiate require ControlPrincipal
- public AuthenticationSchemes AuthenticationSchemes
- {
- get => auth_schemes;
- set
- {
- CheckDisposed();
- auth_schemes = value;
- }
- }
-
- public AuthenticationSchemeSelector AuthenticationSchemeSelectorDelegate
- {
- get => auth_selector;
- set
- {
- CheckDisposed();
- auth_selector = value;
- }
- }
-
- public bool IsListening => listening;
-
- public static bool IsSupported => true;
-
- public HttpListenerPrefixCollection Prefixes
- {
- get
- {
- CheckDisposed();
- return prefixes;
- }
- }
-
- // TODO: use this
- public string Realm
- {
- get => realm;
- set
- {
- CheckDisposed();
- realm = value;
- }
- }
-
- public bool UnsafeConnectionNtlmAuthentication
- {
- get => unsafe_ntlm_auth;
- set
- {
- CheckDisposed();
- unsafe_ntlm_auth = value;
- }
- }
-
- //internal IMonoSslStream CreateSslStream(Stream innerStream, bool ownsStream, MSI.MonoRemoteCertificateValidationCallback callback)
- //{
- // lock (registry)
- // {
- // if (tlsProvider == null)
- // tlsProvider = MonoTlsProviderFactory.GetProviderInternal();
- // if (tlsSettings == null)
- // tlsSettings = MSI.MonoTlsSettings.CopyDefaultSettings();
- // if (tlsSettings.RemoteCertificateValidationCallback == null)
- // tlsSettings.RemoteCertificateValidationCallback = callback;
- // return tlsProvider.CreateSslStream(innerStream, ownsStream, tlsSettings);
- // }
- //}
-
- internal X509Certificate Certificate => _certificate;
-
- public void Abort()
- {
- if (disposed)
- return;
-
- if (!listening)
- {
- return;
- }
-
- Close(true);
- }
-
- public void Close()
- {
- if (disposed)
- return;
-
- if (!listening)
- {
- disposed = true;
- return;
- }
-
- Close(true);
- disposed = true;
- }
-
- void Close(bool force)
- {
- CheckDisposed();
- HttpEndPointManager.RemoveListener(_logger, this);
- Cleanup(force);
- }
-
- void Cleanup(bool close_existing)
- {
- lock (registry)
- {
- if (close_existing)
- {
- // Need to copy this since closing will call UnregisterContext
- ICollection keys = registry.Keys;
- var all = new HttpListenerContext[keys.Count];
- keys.CopyTo(all, 0);
- registry.Clear();
- for (int i = all.Length - 1; i >= 0; i--)
- all[i].Connection.Close(true);
- }
-
- lock (connections)
- {
- ICollection keys = connections.Keys;
- var conns = new HttpConnection[keys.Count];
- keys.CopyTo(conns, 0);
- connections.Clear();
- for (int i = conns.Length - 1; i >= 0; i--)
- conns[i].Close(true);
- }
- }
- }
-
- internal AuthenticationSchemes SelectAuthenticationScheme(HttpListenerContext context)
- {
- if (AuthenticationSchemeSelectorDelegate != null)
- return AuthenticationSchemeSelectorDelegate(context.Request);
- else
- return auth_schemes;
- }
-
- public void Start()
- {
- CheckDisposed();
- if (listening)
- return;
-
- HttpEndPointManager.AddListener(_logger, this);
- listening = true;
- }
-
- public void Stop()
- {
- CheckDisposed();
- listening = false;
- Close(false);
- }
-
- void IDisposable.Dispose()
- {
- if (disposed)
- return;
-
- Close(true); //TODO: Should we force here or not?
- disposed = true;
- }
-
- internal void CheckDisposed()
- {
- if (disposed)
- throw new ObjectDisposedException(GetType().Name);
- }
-
- internal void RegisterContext(HttpListenerContext context)
- {
- if (OnContext != null && IsListening)
- {
- OnContext(context);
- }
-
- lock (registry)
- registry[context] = context;
- }
-
- internal void UnregisterContext(HttpListenerContext context)
- {
- lock (registry)
- registry.Remove(context);
- }
-
- internal void AddConnection(HttpConnection cnc)
- {
- lock (connections)
- {
- connections[cnc] = cnc;
- }
- }
-
- internal void RemoveConnection(HttpConnection cnc)
- {
- lock (connections)
- {
- connections.Remove(cnc);
- }
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpListenerBasicIdentity.cs b/SocketHttpListener/Net/HttpListenerBasicIdentity.cs
deleted file mode 100644
index 5f6ec44b9..000000000
--- a/SocketHttpListener/Net/HttpListenerBasicIdentity.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-using System.Security.Principal;
-
-namespace SocketHttpListener.Net
-{
- public class HttpListenerBasicIdentity : GenericIdentity
- {
- string password;
-
- public HttpListenerBasicIdentity(string username, string password)
- : base(username, "Basic")
- {
- this.password = password;
- }
-
- public virtual string Password => password;
- }
-
- public class GenericIdentity : IIdentity
- {
- private string m_name;
- private string m_type;
-
- public GenericIdentity(string name)
- {
- if (name == null)
- throw new System.ArgumentNullException(nameof(name));
-
- m_name = name;
- m_type = "";
- }
-
- public GenericIdentity(string name, string type)
- {
- if (name == null)
- throw new System.ArgumentNullException(nameof(name));
- if (type == null)
- throw new System.ArgumentNullException(nameof(type));
-
- m_name = name;
- m_type = type;
- }
-
- public virtual string Name => m_name;
-
- public virtual string AuthenticationType => m_type;
-
- public virtual bool IsAuthenticated => !m_name.Equals("");
- }
-}
diff --git a/SocketHttpListener/Net/HttpListenerContext.Managed.cs b/SocketHttpListener/Net/HttpListenerContext.Managed.cs
deleted file mode 100644
index 79742bf37..000000000
--- a/SocketHttpListener/Net/HttpListenerContext.Managed.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-using System;
-using System.ComponentModel;
-using System.Security.Principal;
-using System.Text;
-using System.Threading.Tasks;
-using SocketHttpListener.Net.WebSockets;
-
-namespace SocketHttpListener.Net
-{
- public sealed partial class HttpListenerContext
- {
- private HttpConnection _connection;
-
- internal HttpListenerContext(HttpConnection connection)
- {
- _connection = connection;
- _response = new HttpListenerResponse(this);
- Request = new HttpListenerRequest(this);
- ErrorStatus = 400;
- }
-
- internal int ErrorStatus { get; set; }
-
- internal string ErrorMessage { get; set; }
-
- internal bool HaveError => ErrorMessage != null;
-
- internal HttpConnection Connection => _connection;
-
- internal void ParseAuthentication(System.Net.AuthenticationSchemes expectedSchemes)
- {
- if (expectedSchemes == System.Net.AuthenticationSchemes.Anonymous)
- return;
-
- string header = Request.Headers["Authorization"];
- if (string.IsNullOrEmpty(header))
- return;
-
- if (IsBasicHeader(header))
- {
- _user = ParseBasicAuthentication(header.Substring(AuthenticationTypes.Basic.Length + 1));
- }
- }
-
- internal IPrincipal ParseBasicAuthentication(string authData) =>
- TryParseBasicAuth(authData, out HttpStatusCode errorCode, out string username, out string password) ?
- new GenericPrincipal(new HttpListenerBasicIdentity(username, password), Array.Empty<string>()) :
- null;
-
- internal static bool IsBasicHeader(string header) =>
- header.Length >= 6 &&
- header[5] == ' ' &&
- string.Compare(header, 0, AuthenticationTypes.Basic, 0, 5, StringComparison.OrdinalIgnoreCase) == 0;
-
- internal static bool TryParseBasicAuth(string headerValue, out HttpStatusCode errorCode, out string username, out string password)
- {
- errorCode = HttpStatusCode.OK;
- username = password = null;
- try
- {
- if (string.IsNullOrWhiteSpace(headerValue))
- {
- return false;
- }
-
- string authString = Encoding.UTF8.GetString(Convert.FromBase64String(headerValue));
- int colonPos = authString.IndexOf(':');
- if (colonPos < 0)
- {
- // username must be at least 1 char
- errorCode = HttpStatusCode.BadRequest;
- return false;
- }
-
- username = authString.Substring(0, colonPos);
- password = authString.Substring(colonPos + 1);
- return true;
- }
- catch
- {
- errorCode = HttpStatusCode.InternalServerError;
- return false;
- }
- }
-
- public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval)
- {
- return HttpWebSocket.AcceptWebSocketAsyncCore(this, subProtocol, receiveBufferSize, keepAliveInterval);
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment<byte> internalBuffer)
- {
- WebSocketValidate.ValidateArraySegment(internalBuffer, nameof(internalBuffer));
- HttpWebSocket.ValidateOptions(subProtocol, receiveBufferSize, HttpWebSocket.MinSendBufferSize, keepAliveInterval);
- return HttpWebSocket.AcceptWebSocketAsyncCore(this, subProtocol, receiveBufferSize, keepAliveInterval, internalBuffer);
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpListenerContext.cs b/SocketHttpListener/Net/HttpListenerContext.cs
deleted file mode 100644
index d84e2d1aa..000000000
--- a/SocketHttpListener/Net/HttpListenerContext.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-using System;
-using System.Net;
-using System.Security.Principal;
-using System.Threading.Tasks;
-using SocketHttpListener.Net.WebSockets;
-
-namespace SocketHttpListener.Net
-{
- public sealed partial class HttpListenerContext
- {
- private HttpListenerResponse _response;
- private IPrincipal _user;
-
- public HttpListenerRequest Request { get; }
-
- public IPrincipal User => _user;
-
- // This can be used to cache the results of HttpListener.AuthenticationSchemeSelectorDelegate.
- internal AuthenticationSchemes AuthenticationSchemes { get; set; }
-
- public HttpListenerResponse Response => _response;
-
- public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol)
- {
- return AcceptWebSocketAsync(subProtocol, HttpWebSocket.DefaultReceiveBufferSize, WebSocket.DefaultKeepAliveInterval);
- }
-
- public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, TimeSpan keepAliveInterval)
- {
- return AcceptWebSocketAsync(subProtocol, HttpWebSocket.DefaultReceiveBufferSize, keepAliveInterval);
- }
- }
-
- public class GenericPrincipal : IPrincipal
- {
- private IIdentity m_identity;
- private string[] m_roles;
-
- public GenericPrincipal(IIdentity identity, string[] roles)
- {
- if (identity == null)
- throw new ArgumentNullException(nameof(identity));
-
- m_identity = identity;
- if (roles != null)
- {
- m_roles = new string[roles.Length];
- for (int i = 0; i < roles.Length; ++i)
- {
- m_roles[i] = roles[i];
- }
- }
- else
- {
- m_roles = null;
- }
- }
-
- public virtual IIdentity Identity => m_identity;
-
- public virtual bool IsInRole(string role)
- {
- if (role == null || m_roles == null)
- return false;
-
- for (int i = 0; i < m_roles.Length; ++i)
- {
- if (m_roles[i] != null && string.Compare(m_roles[i], role, StringComparison.OrdinalIgnoreCase) == 0)
- return true;
- }
- return false;
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpListenerPrefixCollection.cs b/SocketHttpListener/Net/HttpListenerPrefixCollection.cs
deleted file mode 100644
index 97dc6797c..000000000
--- a/SocketHttpListener/Net/HttpListenerPrefixCollection.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using Microsoft.Extensions.Logging;
-
-namespace SocketHttpListener.Net
-{
- public class HttpListenerPrefixCollection : ICollection<string>, IEnumerable<string>, IEnumerable
- {
- List<string> prefixes = new List<string>();
- HttpListener listener;
-
- private ILogger _logger;
-
- internal HttpListenerPrefixCollection(ILogger logger, HttpListener listener)
- {
- _logger = logger;
- this.listener = listener;
- }
-
- public int Count => prefixes.Count;
-
- public bool IsReadOnly => false;
-
- public bool IsSynchronized => false;
-
- public void Add(string uriPrefix)
- {
- listener.CheckDisposed();
- //ListenerPrefix.CheckUri(uriPrefix);
- if (prefixes.Contains(uriPrefix))
- return;
-
- prefixes.Add(uriPrefix);
- if (listener.IsListening)
- HttpEndPointManager.AddPrefix(_logger, uriPrefix, listener);
- }
-
- public void Clear()
- {
- listener.CheckDisposed();
- prefixes.Clear();
- if (listener.IsListening)
- HttpEndPointManager.RemoveListener(_logger, listener);
- }
-
- public bool Contains(string uriPrefix)
- {
- listener.CheckDisposed();
- return prefixes.Contains(uriPrefix);
- }
-
- public void CopyTo(string[] array, int offset)
- {
- listener.CheckDisposed();
- prefixes.CopyTo(array, offset);
- }
-
- public void CopyTo(Array array, int offset)
- {
- listener.CheckDisposed();
- ((ICollection)prefixes).CopyTo(array, offset);
- }
-
- public IEnumerator<string> GetEnumerator()
- {
- return prefixes.GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return prefixes.GetEnumerator();
- }
-
- public bool Remove(string uriPrefix)
- {
- listener.CheckDisposed();
- if (uriPrefix == null)
- throw new ArgumentNullException(nameof(uriPrefix));
-
- bool result = prefixes.Remove(uriPrefix);
- if (result && listener.IsListening)
- HttpEndPointManager.RemovePrefix(_logger, uriPrefix, listener);
-
- return result;
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpListenerRequest.Managed.cs b/SocketHttpListener/Net/HttpListenerRequest.Managed.cs
deleted file mode 100644
index 3f9e32f08..000000000
--- a/SocketHttpListener/Net/HttpListenerRequest.Managed.cs
+++ /dev/null
@@ -1,325 +0,0 @@
-using System;
-using System.IO;
-using System.Text;
-using MediaBrowser.Model.Services;
-
-namespace SocketHttpListener.Net
-{
- public sealed partial class HttpListenerRequest
- {
- private long _contentLength;
- private bool _clSet;
- private WebHeaderCollection _headers;
- private string _method;
- private Stream _inputStream;
- private HttpListenerContext _context;
- private bool _isChunked;
-
- private static byte[] s_100continue = Encoding.ASCII.GetBytes("HTTP/1.1 100 Continue\r\n\r\n");
-
- internal HttpListenerRequest(HttpListenerContext context)
- {
- _context = context;
- _headers = new WebHeaderCollection();
- _version = HttpVersion.Version10;
- }
-
- private static readonly char[] s_separators = new char[] { ' ' };
-
- internal void SetRequestLine(string req)
- {
- string[] parts = req.Split(s_separators, 3);
- if (parts.Length != 3)
- {
- _context.ErrorMessage = "Invalid request line (parts).";
- return;
- }
-
- _method = parts[0];
- foreach (char c in _method)
- {
- int ic = (int)c;
-
- if ((ic >= 'A' && ic <= 'Z') ||
- (ic > 32 && c < 127 && c != '(' && c != ')' && c != '<' &&
- c != '<' && c != '>' && c != '@' && c != ',' && c != ';' &&
- c != ':' && c != '\\' && c != '"' && c != '/' && c != '[' &&
- c != ']' && c != '?' && c != '=' && c != '{' && c != '}'))
- continue;
-
- _context.ErrorMessage = "(Invalid verb)";
- return;
- }
-
- _rawUrl = parts[1];
- if (parts[2].Length != 8 || !parts[2].StartsWith("HTTP/"))
- {
- _context.ErrorMessage = "Invalid request line (version).";
- return;
- }
-
- try
- {
- _version = new Version(parts[2].Substring(5));
- }
- catch
- {
- _context.ErrorMessage = "Invalid request line (version).";
- return;
- }
-
- if (_version.Major < 1)
- {
- _context.ErrorMessage = "Invalid request line (version).";
- return;
- }
- if (_version.Major > 1)
- {
- _context.ErrorStatus = (int)HttpStatusCode.HttpVersionNotSupported;
- _context.ErrorMessage = HttpStatusDescription.Get(HttpStatusCode.HttpVersionNotSupported);
- return;
- }
- }
-
- private static bool MaybeUri(string s)
- {
- int p = s.IndexOf(':');
- if (p == -1)
- return false;
-
- if (p >= 10)
- return false;
-
- return IsPredefinedScheme(s.Substring(0, p));
- }
-
- private static bool IsPredefinedScheme(string scheme)
- {
- if (scheme == null || scheme.Length < 3)
- return false;
-
- char c = scheme[0];
- if (c == 'h')
- return (scheme == UriScheme.Http || scheme == UriScheme.Https);
- if (c == 'f')
- return (scheme == UriScheme.File || scheme == UriScheme.Ftp);
-
- if (c == 'n')
- {
- c = scheme[1];
- if (c == 'e')
- return (scheme == UriScheme.News || scheme == UriScheme.NetPipe || scheme == UriScheme.NetTcp);
- if (scheme == UriScheme.Nntp)
- return true;
- return false;
- }
- if ((c == 'g' && scheme == UriScheme.Gopher) || (c == 'm' && scheme == UriScheme.Mailto))
- return true;
-
- return false;
- }
-
- internal void FinishInitialization()
- {
- string host = UserHostName;
- if (_version > HttpVersion.Version10 && (host == null || host.Length == 0))
- {
- _context.ErrorMessage = "Invalid host name";
- return;
- }
-
- string path;
- Uri raw_uri = null;
- if (MaybeUri(_rawUrl.ToLowerInvariant()) && Uri.TryCreate(_rawUrl, UriKind.Absolute, out raw_uri))
- path = raw_uri.PathAndQuery;
- else
- path = _rawUrl;
-
- if ((host == null || host.Length == 0))
- host = UserHostAddress;
-
- if (raw_uri != null)
- host = raw_uri.Host;
-
- int colon = host.IndexOf(']') == -1 ? host.IndexOf(':') : host.LastIndexOf(':');
- if (colon >= 0)
- host = host.Substring(0, colon);
-
- string base_uri = string.Format("{0}://{1}:{2}", RequestScheme, host, LocalEndPoint.Port);
-
- if (!Uri.TryCreate(base_uri + path, UriKind.Absolute, out _requestUri))
- {
- _context.ErrorMessage = System.Net.WebUtility.HtmlEncode("Invalid url: " + base_uri + path);
- return;
- }
-
- _requestUri = HttpListenerRequestUriBuilder.GetRequestUri(_rawUrl, _requestUri.Scheme,
- _requestUri.Authority, _requestUri.LocalPath, _requestUri.Query);
-
- if (_version >= HttpVersion.Version11)
- {
- string t_encoding = Headers[HttpKnownHeaderNames.TransferEncoding];
- _isChunked = (t_encoding != null && string.Equals(t_encoding, "chunked", StringComparison.OrdinalIgnoreCase));
- // 'identity' is not valid!
- if (t_encoding != null && !_isChunked)
- {
- _context.Connection.SendError(null, 501);
- return;
- }
- }
-
- if (!_isChunked && !_clSet)
- {
- if (string.Equals(_method, "POST", StringComparison.OrdinalIgnoreCase) ||
- string.Equals(_method, "PUT", StringComparison.OrdinalIgnoreCase))
- {
- _context.Connection.SendError(null, 411);
- return;
- }
- }
-
- if (string.Compare(Headers[HttpKnownHeaderNames.Expect], "100-continue", StringComparison.OrdinalIgnoreCase) == 0)
- {
- HttpResponseStream output = _context.Connection.GetResponseStream();
- output.InternalWrite(s_100continue, 0, s_100continue.Length);
- }
- }
-
- internal static string Unquote(string str)
- {
- int start = str.IndexOf('\"');
- int end = str.LastIndexOf('\"');
- if (start >= 0 && end >= 0)
- str = str.Substring(start + 1, end - 1);
- return str.Trim();
- }
-
- internal void AddHeader(string header)
- {
- int colon = header.IndexOf(':');
- if (colon == -1 || colon == 0)
- {
- _context.ErrorMessage = HttpStatusDescription.Get(400);
- _context.ErrorStatus = 400;
- return;
- }
-
- string name = header.Substring(0, colon).Trim();
- string val = header.Substring(colon + 1).Trim();
- if (name.Equals("content-length", StringComparison.OrdinalIgnoreCase))
- {
- // To match Windows behavior:
- // Content lengths >= 0 and <= long.MaxValue are accepted as is.
- // Content lengths > long.MaxValue and <= ulong.MaxValue are treated as 0.
- // Content lengths < 0 cause the requests to fail.
- // Other input is a failure, too.
- long parsedContentLength =
- ulong.TryParse(val, out ulong parsedUlongContentLength) ? (parsedUlongContentLength <= long.MaxValue ? (long)parsedUlongContentLength : 0) :
- long.Parse(val);
- if (parsedContentLength < 0 || (_clSet && parsedContentLength != _contentLength))
- {
- _context.ErrorMessage = "Invalid Content-Length.";
- }
- else
- {
- _contentLength = parsedContentLength;
- _clSet = true;
- }
- }
- else if (name.Equals("transfer-encoding", StringComparison.OrdinalIgnoreCase))
- {
- if (Headers[HttpKnownHeaderNames.TransferEncoding] != null)
- {
- _context.ErrorStatus = (int)HttpStatusCode.NotImplemented;
- _context.ErrorMessage = HttpStatusDescription.Get(HttpStatusCode.NotImplemented);
- }
- }
-
- if (_context.ErrorMessage == null)
- {
- _headers.Set(name, val);
- }
- }
-
- // returns true is the stream could be reused.
- internal bool FlushInput()
- {
- if (!HasEntityBody)
- return true;
-
- int length = 2048;
- if (_contentLength > 0)
- length = (int)Math.Min(_contentLength, (long)length);
-
- byte[] bytes = new byte[length];
- while (true)
- {
- try
- {
- IAsyncResult ares = InputStream.BeginRead(bytes, 0, length, null, null);
- if (!ares.IsCompleted && !ares.AsyncWaitHandle.WaitOne(1000))
- return false;
- if (InputStream.EndRead(ares) <= 0)
- return true;
- }
- catch (ObjectDisposedException)
- {
- _inputStream = null;
- return true;
- }
- catch
- {
- return false;
- }
- }
- }
-
- public long ContentLength64
- {
- get
- {
- if (_isChunked)
- _contentLength = -1;
-
- return _contentLength;
- }
- }
-
- public bool HasEntityBody => (_contentLength > 0 || _isChunked);
-
- public QueryParamCollection Headers => _headers;
-
- public string HttpMethod => _method;
-
- public Stream InputStream
- {
- get
- {
- if (_inputStream == null)
- {
- if (_isChunked || _contentLength > 0)
- _inputStream = _context.Connection.GetRequestStream(_isChunked, _contentLength);
- else
- _inputStream = Stream.Null;
- }
-
- return _inputStream;
- }
- }
-
- public bool IsAuthenticated => false;
-
- public bool IsSecureConnection => _context.Connection.IsSecure;
-
- public System.Net.IPEndPoint LocalEndPoint => _context.Connection.LocalEndPoint;
-
- public System.Net.IPEndPoint RemoteEndPoint => _context.Connection.RemoteEndPoint;
-
- public Guid RequestTraceIdentifier { get; } = Guid.NewGuid();
-
- public string ServiceName => null;
-
- private Uri RequestUri => _requestUri;
- private bool SupportsWebSockets => true;
- }
-}
diff --git a/SocketHttpListener/Net/HttpListenerRequest.cs b/SocketHttpListener/Net/HttpListenerRequest.cs
deleted file mode 100644
index 667d58ea7..000000000
--- a/SocketHttpListener/Net/HttpListenerRequest.cs
+++ /dev/null
@@ -1,537 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Net;
-using System.Text;
-using MediaBrowser.Model.Services;
-using SocketHttpListener.Net.WebSockets;
-
-namespace SocketHttpListener.Net
-{
- public sealed partial class HttpListenerRequest
- {
- private CookieCollection _cookies;
- private bool? _keepAlive;
- private string _rawUrl;
- private Uri _requestUri;
- private Version _version;
-
- public string[] AcceptTypes => Helpers.ParseMultivalueHeader(Headers[HttpKnownHeaderNames.Accept]);
-
- public string[] UserLanguages => Helpers.ParseMultivalueHeader(Headers[HttpKnownHeaderNames.AcceptLanguage]);
-
- private static CookieCollection ParseCookies(Uri uri, string setCookieHeader)
- {
- var cookies = new CookieCollection();
- return cookies;
- }
-
- public CookieCollection Cookies
- {
- get
- {
- if (_cookies == null)
- {
- string cookieString = Headers[HttpKnownHeaderNames.Cookie];
- if (!string.IsNullOrEmpty(cookieString))
- {
- _cookies = ParseCookies(RequestUri, cookieString);
- }
- if (_cookies == null)
- {
- _cookies = new CookieCollection();
- }
- }
- return _cookies;
- }
- }
-
- public Encoding ContentEncoding
- {
- get
- {
- if (UserAgent != null && CultureInfo.InvariantCulture.CompareInfo.IsPrefix(UserAgent, "UP"))
- {
- string postDataCharset = Headers["x-up-devcap-post-charset"];
- if (postDataCharset != null && postDataCharset.Length > 0)
- {
- try
- {
- return Encoding.GetEncoding(postDataCharset);
- }
- catch (ArgumentException)
- {
- }
- }
- }
- if (HasEntityBody)
- {
- if (ContentType != null)
- {
- string charSet = Helpers.GetCharSetValueFromHeader(ContentType);
- if (charSet != null)
- {
- try
- {
- return Encoding.GetEncoding(charSet);
- }
- catch (ArgumentException)
- {
- }
- }
- }
- }
- return Encoding.UTF8;
- }
- }
-
- public string ContentType => Headers[HttpKnownHeaderNames.ContentType];
-
- public bool IsLocal => LocalEndPoint.Address.Equals(RemoteEndPoint.Address);
-
- public bool IsWebSocketRequest
- {
- get
- {
- if (!SupportsWebSockets)
- {
- return false;
- }
-
- bool foundConnectionUpgradeHeader = false;
- if (string.IsNullOrEmpty(Headers[HttpKnownHeaderNames.Connection]) || string.IsNullOrEmpty(Headers[HttpKnownHeaderNames.Upgrade]))
- {
- return false;
- }
-
- foreach (string connection in Headers.GetValues(HttpKnownHeaderNames.Connection))
- {
- if (string.Equals(connection, HttpKnownHeaderNames.Upgrade, StringComparison.OrdinalIgnoreCase))
- {
- foundConnectionUpgradeHeader = true;
- break;
- }
- }
-
- if (!foundConnectionUpgradeHeader)
- {
- return false;
- }
-
- foreach (string upgrade in Headers.GetValues(HttpKnownHeaderNames.Upgrade))
- {
- if (string.Equals(upgrade, HttpWebSocket.WebSocketUpgradeToken, StringComparison.OrdinalIgnoreCase))
- {
- return true;
- }
- }
-
- return false;
- }
- }
-
- public bool KeepAlive
- {
- get
- {
- if (!_keepAlive.HasValue)
- {
- string header = Headers[HttpKnownHeaderNames.ProxyConnection];
- if (string.IsNullOrEmpty(header))
- {
- header = Headers[HttpKnownHeaderNames.Connection];
- }
- if (string.IsNullOrEmpty(header))
- {
- if (ProtocolVersion >= HttpVersion.Version11)
- {
- _keepAlive = true;
- }
- else
- {
- header = Headers[HttpKnownHeaderNames.KeepAlive];
- _keepAlive = !string.IsNullOrEmpty(header);
- }
- }
- else
- {
- header = header.ToLowerInvariant();
- _keepAlive =
- header.IndexOf("close", StringComparison.OrdinalIgnoreCase) < 0 ||
- header.IndexOf("keep-alive", StringComparison.OrdinalIgnoreCase) >= 0;
- }
- }
-
- return _keepAlive.Value;
- }
- }
-
- public QueryParamCollection QueryString
- {
- get
- {
- var queryString = new QueryParamCollection();
- Helpers.FillFromString(queryString, Url.Query, true, ContentEncoding);
- return queryString;
- }
- }
-
- public string RawUrl => _rawUrl;
-
- private string RequestScheme => IsSecureConnection ? UriScheme.Https : UriScheme.Http;
-
- public string UserAgent => Headers[HttpKnownHeaderNames.UserAgent];
-
- public string UserHostAddress => LocalEndPoint.ToString();
-
- public string UserHostName => Headers[HttpKnownHeaderNames.Host];
-
- public Uri UrlReferrer
- {
- get
- {
- string referrer = Headers[HttpKnownHeaderNames.Referer];
- if (referrer == null)
- {
- return null;
- }
-
- bool success = Uri.TryCreate(referrer, UriKind.RelativeOrAbsolute, out var urlReferrer);
- return success ? urlReferrer : null;
- }
- }
-
- public Uri Url => RequestUri;
-
- public Version ProtocolVersion => _version;
-
- private static class Helpers
- {
- //
- // Get attribute off header value
- //
- internal static string GetCharSetValueFromHeader(string headerValue)
- {
- const string AttrName = "charset";
-
- if (headerValue == null)
- return null;
-
- int l = headerValue.Length;
- int k = AttrName.Length;
-
- // find properly separated attribute name
- int i = 1; // start searching from 1
-
- while (i < l)
- {
- i = CultureInfo.InvariantCulture.CompareInfo.IndexOf(headerValue, AttrName, i, CompareOptions.IgnoreCase);
- if (i < 0)
- break;
- if (i + k >= l)
- break;
-
- char chPrev = headerValue[i - 1];
- char chNext = headerValue[i + k];
- if ((chPrev == ';' || chPrev == ',' || char.IsWhiteSpace(chPrev)) && (chNext == '=' || char.IsWhiteSpace(chNext)))
- break;
-
- i += k;
- }
-
- if (i < 0 || i >= l)
- return null;
-
- // skip to '=' and the following whitespace
- i += k;
- while (i < l && char.IsWhiteSpace(headerValue[i]))
- i++;
- if (i >= l || headerValue[i] != '=')
- return null;
- i++;
- while (i < l && char.IsWhiteSpace(headerValue[i]))
- i++;
- if (i >= l)
- return null;
-
- // parse the value
- string attrValue = null;
-
- int j;
-
- if (i < l && headerValue[i] == '"')
- {
- if (i == l - 1)
- return null;
- j = headerValue.IndexOf('"', i + 1);
- if (j < 0 || j == i + 1)
- return null;
-
- attrValue = headerValue.Substring(i + 1, j - i - 1).Trim();
- }
- else
- {
- for (j = i; j < l; j++)
- {
- if (headerValue[j] == ';')
- break;
- }
-
- if (j == i)
- return null;
-
- attrValue = headerValue.Substring(i, j - i).Trim();
- }
-
- return attrValue;
- }
-
- internal static string[] ParseMultivalueHeader(string s)
- {
- if (s == null)
- return null;
-
- int l = s.Length;
-
- // collect comma-separated values into list
-
- var values = new List<string>();
- int i = 0;
-
- while (i < l)
- {
- // find next ,
- int ci = s.IndexOf(',', i);
- if (ci < 0)
- ci = l;
-
- // append corresponding server value
- values.Add(s.Substring(i, ci - i));
-
- // move to next
- i = ci + 1;
-
- // skip leading space
- if (i < l && s[i] == ' ')
- i++;
- }
-
- // return list as array of strings
-
- int n = values.Count;
- string[] strings;
-
- // if n is 0 that means s was empty string
-
- if (n == 0)
- {
- strings = new string[1];
- strings[0] = string.Empty;
- }
- else
- {
- strings = new string[n];
- values.CopyTo(0, strings, 0, n);
- }
- return strings;
- }
-
-
- private static string UrlDecodeStringFromStringInternal(string s, Encoding e)
- {
- int count = s.Length;
- var helper = new UrlDecoder(count, e);
-
- // go through the string's chars collapsing %XX and %uXXXX and
- // appending each char as char, with exception of %XX constructs
- // that are appended as bytes
-
- for (int pos = 0; pos < count; pos++)
- {
- char ch = s[pos];
-
- if (ch == '+')
- {
- ch = ' ';
- }
- else if (ch == '%' && pos < count - 2)
- {
- if (s[pos + 1] == 'u' && pos < count - 5)
- {
- int h1 = HexToInt(s[pos + 2]);
- int h2 = HexToInt(s[pos + 3]);
- int h3 = HexToInt(s[pos + 4]);
- int h4 = HexToInt(s[pos + 5]);
-
- if (h1 >= 0 && h2 >= 0 && h3 >= 0 && h4 >= 0)
- { // valid 4 hex chars
- ch = (char)((h1 << 12) | (h2 << 8) | (h3 << 4) | h4);
- pos += 5;
-
- // only add as char
- helper.AddChar(ch);
- continue;
- }
- }
- else
- {
- int h1 = HexToInt(s[pos + 1]);
- int h2 = HexToInt(s[pos + 2]);
-
- if (h1 >= 0 && h2 >= 0)
- { // valid 2 hex chars
- byte b = (byte)((h1 << 4) | h2);
- pos += 2;
-
- // don't add as char
- helper.AddByte(b);
- continue;
- }
- }
- }
-
- if ((ch & 0xFF80) == 0)
- helper.AddByte((byte)ch); // 7 bit have to go as bytes because of Unicode
- else
- helper.AddChar(ch);
- }
-
- return helper.GetString();
- }
-
- private static int HexToInt(char h)
- {
- return (h >= '0' && h <= '9') ? h - '0' :
- (h >= 'a' && h <= 'f') ? h - 'a' + 10 :
- (h >= 'A' && h <= 'F') ? h - 'A' + 10 :
- -1;
- }
-
- private class UrlDecoder
- {
- private int _bufferSize;
-
- // Accumulate characters in a special array
- private int _numChars;
- private char[] _charBuffer;
-
- // Accumulate bytes for decoding into characters in a special array
- private int _numBytes;
- private byte[] _byteBuffer;
-
- // Encoding to convert chars to bytes
- private Encoding _encoding;
-
- private void FlushBytes()
- {
- if (_numBytes > 0)
- {
- _numChars += _encoding.GetChars(_byteBuffer, 0, _numBytes, _charBuffer, _numChars);
- _numBytes = 0;
- }
- }
-
- internal UrlDecoder(int bufferSize, Encoding encoding)
- {
- _bufferSize = bufferSize;
- _encoding = encoding;
-
- _charBuffer = new char[bufferSize];
- // byte buffer created on demand
- }
-
- internal void AddChar(char ch)
- {
- if (_numBytes > 0)
- FlushBytes();
-
- _charBuffer[_numChars++] = ch;
- }
-
- internal void AddByte(byte b)
- {
- {
- if (_byteBuffer == null)
- _byteBuffer = new byte[_bufferSize];
-
- _byteBuffer[_numBytes++] = b;
- }
- }
-
- internal string GetString()
- {
- if (_numBytes > 0)
- FlushBytes();
-
- if (_numChars > 0)
- return new string(_charBuffer, 0, _numChars);
- else
- return string.Empty;
- }
- }
-
-
- internal static void FillFromString(QueryParamCollection nvc, string s, bool urlencoded, Encoding encoding)
- {
- int l = (s != null) ? s.Length : 0;
- int i = (s.Length > 0 && s[0] == '?') ? 1 : 0;
-
- while (i < l)
- {
- // find next & while noting first = on the way (and if there are more)
-
- int si = i;
- int ti = -1;
-
- while (i < l)
- {
- char ch = s[i];
-
- if (ch == '=')
- {
- if (ti < 0)
- ti = i;
- }
- else if (ch == '&')
- {
- break;
- }
-
- i++;
- }
-
- // extract the name / value pair
-
- string name = null;
- string value = null;
-
- if (ti >= 0)
- {
- name = s.Substring(si, ti - si);
- value = s.Substring(ti + 1, i - ti - 1);
- }
- else
- {
- value = s.Substring(si, i - si);
- }
-
- // add name / value pair to the collection
-
- if (urlencoded)
- nvc.Add(
- name == null ? null : UrlDecodeStringFromStringInternal(name, encoding),
- UrlDecodeStringFromStringInternal(value, encoding));
- else
- nvc.Add(name, value);
-
- // trailing '&'
-
- if (i == l - 1 && s[i] == '&')
- nvc.Add(null, "");
-
- i++;
- }
- }
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs b/SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs
deleted file mode 100644
index 7b4b619e6..000000000
--- a/SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs
+++ /dev/null
@@ -1,443 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.Text;
-
-namespace SocketHttpListener.Net
-{
- // We don't use the cooked URL because http.sys unescapes all percent-encoded values. However,
- // we also can't just use the raw Uri, since http.sys supports not only Utf-8, but also ANSI/DBCS and
- // Unicode code points. System.Uri only supports Utf-8.
- // The purpose of this class is to convert all ANSI, DBCS, and Unicode code points into percent encoded
- // Utf-8 characters.
- internal sealed class HttpListenerRequestUriBuilder
- {
- private static readonly Encoding s_utf8Encoding = new UTF8Encoding(false, true);
- private static readonly Encoding s_ansiEncoding = Encoding.GetEncoding(0, new EncoderExceptionFallback(), new DecoderExceptionFallback());
-
- private readonly string _rawUri;
- private readonly string _cookedUriScheme;
- private readonly string _cookedUriHost;
- private readonly string _cookedUriPath;
- private readonly string _cookedUriQuery;
-
- // This field is used to build the final request Uri string from the Uri parts passed to the ctor.
- private StringBuilder _requestUriString;
-
- // The raw path is parsed by looping through all characters from left to right. 'rawOctets'
- // is used to store consecutive percent encoded octets as actual byte values: e.g. for path /pa%C3%84th%2F/
- // rawOctets will be set to { 0xC3, 0x84 } when we reach character 't' and it will be { 0x2F } when
- // we reach the final '/'. I.e. after a sequence of percent encoded octets ends, we use rawOctets as
- // input to the encoding and percent encode the resulting string into UTF-8 octets.
- //
- // When parsing ANSI (Latin 1) encoded path '/pa%C4th/', %C4 will be added to rawOctets and when
- // we reach 't', the content of rawOctets { 0xC4 } will be fed into the ANSI encoding. The resulting
- // string 'Ä' will be percent encoded into UTF-8 octets and appended to requestUriString. The final
- // path will be '/pa%C3%84th/', where '%C3%84' is the UTF-8 percent encoded character 'Ä'.
- private List<byte> _rawOctets;
- private string _rawPath;
-
- // Holds the final request Uri.
- private Uri _requestUri;
-
- private HttpListenerRequestUriBuilder(string rawUri, string cookedUriScheme, string cookedUriHost,
- string cookedUriPath, string cookedUriQuery)
- {
- _rawUri = rawUri;
- _cookedUriScheme = cookedUriScheme;
- _cookedUriHost = cookedUriHost;
- _cookedUriPath = AddSlashToAsteriskOnlyPath(cookedUriPath);
- _cookedUriQuery = cookedUriQuery ?? string.Empty;
- }
-
- public static Uri GetRequestUri(string rawUri, string cookedUriScheme, string cookedUriHost,
- string cookedUriPath, string cookedUriQuery)
- {
- var builder = new HttpListenerRequestUriBuilder(rawUri,
- cookedUriScheme, cookedUriHost, cookedUriPath, cookedUriQuery);
-
- return builder.Build();
- }
-
- private Uri Build()
- {
- BuildRequestUriUsingRawPath();
-
- if (_requestUri == null)
- {
- BuildRequestUriUsingCookedPath();
- }
-
- return _requestUri;
- }
-
- private void BuildRequestUriUsingCookedPath()
- {
- bool isValid = Uri.TryCreate(_cookedUriScheme + Uri.SchemeDelimiter + _cookedUriHost + _cookedUriPath +
- _cookedUriQuery, UriKind.Absolute, out _requestUri);
-
- // Creating a Uri from the cooked Uri should really always work: If not, we log at least.
- if (!isValid)
- {
- //if (NetEventSource.IsEnabled)
- // NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_create_uri, _cookedUriScheme, _cookedUriHost, _cookedUriPath, _cookedUriQuery));
- }
- }
-
- private void BuildRequestUriUsingRawPath()
- {
- bool isValid = false;
-
- // Initialize 'rawPath' only if really needed; i.e. if we build the request Uri from the raw Uri.
- _rawPath = GetPath(_rawUri);
-
- // Try to check the raw path using first the primary encoding (according to http.sys settings);
- // if it fails try the secondary encoding.
- ParsingResult result = BuildRequestUriUsingRawPath(GetEncoding(EncodingType.Primary));
- if (result == ParsingResult.EncodingError)
- {
- Encoding secondaryEncoding = GetEncoding(EncodingType.Secondary);
- result = BuildRequestUriUsingRawPath(secondaryEncoding);
- }
- isValid = (result == ParsingResult.Success) ? true : false;
-
- // Log that we weren't able to create a Uri from the raw string.
- if (!isValid)
- {
- //if (NetEventSource.IsEnabled)
- // NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_create_uri, _cookedUriScheme, _cookedUriHost, _rawPath, _cookedUriQuery));
- }
- }
-
- private static Encoding GetEncoding(EncodingType type)
- {
- Debug.Assert((type == EncodingType.Primary) || (type == EncodingType.Secondary),
- "Unknown 'EncodingType' value: " + type.ToString());
-
- if (type == EncodingType.Secondary)
- {
- return s_ansiEncoding;
- }
- else
- {
- return s_utf8Encoding;
- }
- }
-
- private ParsingResult BuildRequestUriUsingRawPath(Encoding encoding)
- {
- Debug.Assert(encoding != null, "'encoding' must be assigned.");
- Debug.Assert(!string.IsNullOrEmpty(_rawPath), "'rawPath' must have at least one character.");
-
- _rawOctets = new List<byte>();
- _requestUriString = new StringBuilder();
- _requestUriString.Append(_cookedUriScheme);
- _requestUriString.Append(Uri.SchemeDelimiter);
- _requestUriString.Append(_cookedUriHost);
-
- ParsingResult result = ParseRawPath(encoding);
- if (result == ParsingResult.Success)
- {
- _requestUriString.Append(_cookedUriQuery);
-
- Debug.Assert(_rawOctets.Count == 0,
- "Still raw octets left. They must be added to the result path.");
-
- if (!Uri.TryCreate(_requestUriString.ToString(), UriKind.Absolute, out _requestUri))
- {
- // If we can't create a Uri from the string, this is an invalid string and it doesn't make
- // sense to try another encoding.
- result = ParsingResult.InvalidString;
- }
- }
-
- if (result != ParsingResult.Success)
- {
- //if (NetEventSource.IsEnabled)
- // NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_raw_path, _rawPath, encoding.EncodingName));
- }
-
- return result;
- }
-
- private ParsingResult ParseRawPath(Encoding encoding)
- {
- Debug.Assert(encoding != null, "'encoding' must be assigned.");
-
- int index = 0;
- char current = '\0';
- while (index < _rawPath.Length)
- {
- current = _rawPath[index];
- if (current == '%')
- {
- // Assert is enough, since http.sys accepted the request string already. This should never happen.
- Debug.Assert(index + 2 < _rawPath.Length, "Expected >=2 characters after '%' (e.g. %2F)");
-
- index++;
- current = _rawPath[index];
- if (current == 'u' || current == 'U')
- {
- // We found "%u" which means, we have a Unicode code point of the form "%uXXXX".
- Debug.Assert(index + 4 < _rawPath.Length, "Expected >=4 characters after '%u' (e.g. %u0062)");
-
- // Decode the content of rawOctets into percent encoded UTF-8 characters and append them
- // to requestUriString.
- if (!EmptyDecodeAndAppendRawOctetsList(encoding))
- {
- return ParsingResult.EncodingError;
- }
- if (!AppendUnicodeCodePointValuePercentEncoded(_rawPath.Substring(index + 1, 4)))
- {
- return ParsingResult.InvalidString;
- }
- index += 5;
- }
- else
- {
- // We found '%', but not followed by 'u', i.e. we have a percent encoded octed: %XX
- if (!AddPercentEncodedOctetToRawOctetsList(encoding, _rawPath.Substring(index, 2)))
- {
- return ParsingResult.InvalidString;
- }
- index += 2;
- }
- }
- else
- {
- // We found a non-'%' character: decode the content of rawOctets into percent encoded
- // UTF-8 characters and append it to the result.
- if (!EmptyDecodeAndAppendRawOctetsList(encoding))
- {
- return ParsingResult.EncodingError;
- }
- // Append the current character to the result.
- _requestUriString.Append(current);
- index++;
- }
- }
-
- // if the raw path ends with a sequence of percent encoded octets, make sure those get added to the
- // result (requestUriString).
- if (!EmptyDecodeAndAppendRawOctetsList(encoding))
- {
- return ParsingResult.EncodingError;
- }
-
- return ParsingResult.Success;
- }
-
- private bool AppendUnicodeCodePointValuePercentEncoded(string codePoint)
- {
- // http.sys only supports %uXXXX (4 hex-digits), even though unicode code points could have up to
- // 6 hex digits. Therefore we parse always 4 characters after %u and convert them to an int.
- if (!int.TryParse(codePoint, NumberStyles.HexNumber, null, out var codePointValue))
- {
- //if (NetEventSource.IsEnabled)
- // NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_percent_value, codePoint));
- return false;
- }
-
- string unicodeString = null;
- try
- {
- unicodeString = char.ConvertFromUtf32(codePointValue);
- AppendOctetsPercentEncoded(_requestUriString, s_utf8Encoding.GetBytes(unicodeString));
-
- return true;
- }
- catch (ArgumentOutOfRangeException)
- {
- //if (NetEventSource.IsEnabled)
- // NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_percent_value, codePoint));
- }
- catch (EncoderFallbackException)
- {
- // If utf8Encoding.GetBytes() fails
- //if (NetEventSource.IsEnabled) NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_to_utf8, unicodeString, e.Message));
- }
-
- return false;
- }
-
- private bool AddPercentEncodedOctetToRawOctetsList(Encoding encoding, string escapedCharacter)
- {
- if (!byte.TryParse(escapedCharacter, NumberStyles.HexNumber, null, out byte encodedValue))
- {
- //if (NetEventSource.IsEnabled) NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_percent_value, escapedCharacter));
- return false;
- }
-
- _rawOctets.Add(encodedValue);
-
- return true;
- }
-
- private bool EmptyDecodeAndAppendRawOctetsList(Encoding encoding)
- {
- if (_rawOctets.Count == 0)
- {
- return true;
- }
-
- string decodedString = null;
- try
- {
- // If the encoding can get a string out of the byte array, this is a valid string in the
- // 'encoding' encoding.
- decodedString = encoding.GetString(_rawOctets.ToArray());
-
- if (encoding == s_utf8Encoding)
- {
- AppendOctetsPercentEncoded(_requestUriString, _rawOctets.ToArray());
- }
- else
- {
- AppendOctetsPercentEncoded(_requestUriString, s_utf8Encoding.GetBytes(decodedString));
- }
-
- _rawOctets.Clear();
-
- return true;
- }
- catch (DecoderFallbackException)
- {
- //if (NetEventSource.IsEnabled) NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_bytes, GetOctetsAsString(_rawOctets), e.Message));
- }
- catch (EncoderFallbackException)
- {
- // If utf8Encoding.GetBytes() fails
- //if (NetEventSource.IsEnabled) NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_to_utf8, decodedString, e.Message));
- }
-
- return false;
- }
-
- private static void AppendOctetsPercentEncoded(StringBuilder target, IEnumerable<byte> octets)
- {
- foreach (byte octet in octets)
- {
- target.Append('%');
- target.Append(octet.ToString("X2", CultureInfo.InvariantCulture));
- }
- }
-
- private static string GetOctetsAsString(IEnumerable<byte> octets)
- {
- var octetString = new StringBuilder();
-
- bool first = true;
- foreach (byte octet in octets)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- octetString.Append(' ');
- }
- octetString.Append(octet.ToString("X2", CultureInfo.InvariantCulture));
- }
-
- return octetString.ToString();
- }
-
- private static string GetPath(string uriString)
- {
- Debug.Assert(uriString != null, "uriString must not be null");
- Debug.Assert(uriString.Length > 0, "uriString must not be empty");
-
- int pathStartIndex = 0;
-
- // Perf. improvement: nearly all strings are relative Uris. So just look if the
- // string starts with '/'. If so, we have a relative Uri and the path starts at position 0.
- // (http.sys already trimmed leading whitespaces)
- if (uriString[0] != '/')
- {
- // We can't check against cookedUriScheme, since http.sys allows for request http://myserver/ to
- // use a request line 'GET https://myserver/' (note http vs. https). Therefore check if the
- // Uri starts with either http:// or https://.
- int authorityStartIndex = 0;
- if (uriString.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
- {
- authorityStartIndex = 7;
- }
- else if (uriString.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
- {
- authorityStartIndex = 8;
- }
-
- if (authorityStartIndex > 0)
- {
- // we have an absolute Uri. Find out where the authority ends and the path begins.
- // Note that Uris like "http://server?query=value/1/2" are invalid according to RFC2616
- // and http.sys behavior: If the Uri contains a query, there must be at least one '/'
- // between the authority and the '?' character: It's safe to just look for the first
- // '/' after the authority to determine the beginning of the path.
- pathStartIndex = uriString.IndexOf('/', authorityStartIndex);
- if (pathStartIndex == -1)
- {
- // e.g. for request lines like: 'GET http://myserver' (no final '/')
- pathStartIndex = uriString.Length;
- }
- }
- else
- {
- // RFC2616: Request-URI = "*" | absoluteURI | abs_path | authority
- // 'authority' can only be used with CONNECT which is never received by HttpListener.
- // I.e. if we don't have an absolute path (must start with '/') and we don't have
- // an absolute Uri (must start with http:// or https://), then 'uriString' must be '*'.
- Debug.Assert((uriString.Length == 1) && (uriString[0] == '*'), "Unknown request Uri string format",
- "Request Uri string is not an absolute Uri, absolute path, or '*': {0}", uriString);
-
- // Should we ever get here, be consistent with 2.0/3.5 behavior: just add an initial
- // slash to the string and treat it as a path:
- uriString = "/" + uriString;
- }
- }
-
- // Find end of path: The path is terminated by
- // - the first '?' character
- // - the first '#' character: This is never the case here, since http.sys won't accept
- // Uris containing fragments. Also, RFC2616 doesn't allow fragments in request Uris.
- // - end of Uri string
- int queryIndex = uriString.IndexOf('?');
- if (queryIndex == -1)
- {
- queryIndex = uriString.Length;
- }
-
- // will always return a != null string.
- return AddSlashToAsteriskOnlyPath(uriString.Substring(pathStartIndex, queryIndex - pathStartIndex));
- }
-
- private static string AddSlashToAsteriskOnlyPath(string path)
- {
- Debug.Assert(path != null, "'path' must not be null");
-
- // If a request like "OPTIONS * HTTP/1.1" is sent to the listener, then the request Uri
- // should be "http[s]://server[:port]/*" to be compatible with pre-4.0 behavior.
- if ((path.Length == 1) && (path[0] == '*'))
- {
- return "/*";
- }
-
- return path;
- }
-
- private enum ParsingResult
- {
- Success,
- InvalidString,
- EncodingError
- }
-
- private enum EncodingType
- {
- Primary,
- Secondary
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpListenerResponse.Managed.cs b/SocketHttpListener/Net/HttpListenerResponse.Managed.cs
deleted file mode 100644
index f595fce7c..000000000
--- a/SocketHttpListener/Net/HttpListenerResponse.Managed.cs
+++ /dev/null
@@ -1,333 +0,0 @@
-using System;
-using System.Globalization;
-using System.IO;
-using System.Net;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using MediaBrowser.Model.IO;
-
-namespace SocketHttpListener.Net
-{
- public sealed partial class HttpListenerResponse : IDisposable
- {
- private long _contentLength;
- private Version _version = HttpVersion.Version11;
- private int _statusCode = 200;
- internal object _headersLock = new object();
- private bool _forceCloseChunked;
-
- internal HttpListenerResponse(HttpListenerContext context)
- {
- _httpContext = context;
- }
-
- internal bool ForceCloseChunked => _forceCloseChunked;
-
- private void EnsureResponseStream()
- {
- if (_responseStream == null)
- {
- _responseStream = _httpContext.Connection.GetResponseStream();
- }
- }
-
- public Version ProtocolVersion
- {
- get => _version;
- set
- {
- CheckDisposed();
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
- if (value.Major != 1 || (value.Minor != 0 && value.Minor != 1))
- {
- throw new ArgumentException("Wrong version");
- }
-
- _version = new Version(value.Major, value.Minor); // match Windows behavior, trimming to just Major.Minor
- }
- }
-
- public int StatusCode
- {
- get => _statusCode;
- set
- {
- CheckDisposed();
-
- if (value < 100 || value > 999)
- throw new ProtocolViolationException("Invalid status");
-
- _statusCode = value;
- }
- }
-
- private void Dispose()
- {
- Close(true);
- }
-
- public void Close()
- {
- if (Disposed)
- return;
-
- Close(false);
- }
-
- public void Abort()
- {
- if (Disposed)
- return;
-
- Close(true);
- }
-
- private void Close(bool force)
- {
- Disposed = true;
- _httpContext.Connection.Close(force);
- }
-
- public void Close(byte[] responseEntity, bool willBlock)
- {
- CheckDisposed();
-
- if (responseEntity == null)
- {
- throw new ArgumentNullException(nameof(responseEntity));
- }
-
- if (!SentHeaders && _boundaryType != BoundaryType.Chunked)
- {
- ContentLength64 = responseEntity.Length;
- }
-
- if (willBlock)
- {
- try
- {
- OutputStream.Write(responseEntity, 0, responseEntity.Length);
- }
- finally
- {
- Close(false);
- }
- }
- else
- {
- OutputStream.BeginWrite(responseEntity, 0, responseEntity.Length, iar =>
- {
- var thisRef = (HttpListenerResponse)iar.AsyncState;
- try
- {
- try
- {
- thisRef.OutputStream.EndWrite(iar);
- }
- finally
- {
- thisRef.Close(false);
- }
- }
- catch (Exception)
- {
- // In case response was disposed during this time
- }
- }, this);
- }
- }
-
- public void CopyFrom(HttpListenerResponse templateResponse)
- {
- _webHeaders.Clear();
- //_webHeaders.Add(templateResponse._webHeaders);
- _contentLength = templateResponse._contentLength;
- _statusCode = templateResponse._statusCode;
- _statusDescription = templateResponse._statusDescription;
- _keepAlive = templateResponse._keepAlive;
- _version = templateResponse._version;
- }
-
- internal void SendHeaders(bool closing, MemoryStream ms, bool isWebSocketHandshake = false)
- {
- if (!isWebSocketHandshake)
- {
- if (_webHeaders["Server"] == null)
- {
- _webHeaders.Set("Server", "Microsoft-NetCore/2.0");
- }
-
- if (_webHeaders["Date"] == null)
- {
- _webHeaders.Set("Date", DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture));
- }
-
- if (_boundaryType == BoundaryType.None)
- {
- if (HttpListenerRequest.ProtocolVersion <= HttpVersion.Version10)
- {
- _keepAlive = false;
- }
- else
- {
- _boundaryType = BoundaryType.Chunked;
- }
-
- if (CanSendResponseBody(_httpContext.Response.StatusCode))
- {
- _contentLength = -1;
- }
- else
- {
- _boundaryType = BoundaryType.ContentLength;
- _contentLength = 0;
- }
- }
-
- if (_boundaryType != BoundaryType.Chunked)
- {
- if (_boundaryType != BoundaryType.ContentLength && closing)
- {
- _contentLength = CanSendResponseBody(_httpContext.Response.StatusCode) ? -1 : 0;
- }
-
- if (_boundaryType == BoundaryType.ContentLength)
- {
- _webHeaders.Set("Content-Length", _contentLength.ToString("D", CultureInfo.InvariantCulture));
- }
- }
-
- /* Apache forces closing the connection for these status codes:
- * HttpStatusCode.BadRequest 400
- * HttpStatusCode.RequestTimeout 408
- * HttpStatusCode.LengthRequired 411
- * HttpStatusCode.RequestEntityTooLarge 413
- * HttpStatusCode.RequestUriTooLong 414
- * HttpStatusCode.InternalServerError 500
- * HttpStatusCode.ServiceUnavailable 503
- */
- bool conn_close = (_statusCode == (int)HttpStatusCode.BadRequest || _statusCode == (int)HttpStatusCode.RequestTimeout
- || _statusCode == (int)HttpStatusCode.LengthRequired || _statusCode == (int)HttpStatusCode.RequestEntityTooLarge
- || _statusCode == (int)HttpStatusCode.RequestUriTooLong || _statusCode == (int)HttpStatusCode.InternalServerError
- || _statusCode == (int)HttpStatusCode.ServiceUnavailable);
-
- if (!conn_close)
- {
- conn_close = !_httpContext.Request.KeepAlive;
- }
-
- // They sent both KeepAlive: true and Connection: close
- if (!_keepAlive || conn_close)
- {
- _webHeaders.Set("Connection", "Close");
- conn_close = true;
- }
-
- if (SendChunked)
- {
- _webHeaders.Set("Transfer-Encoding", "Chunked");
- }
-
- int reuses = _httpContext.Connection.Reuses;
- if (reuses >= 100)
- {
- _forceCloseChunked = true;
- if (!conn_close)
- {
- _webHeaders.Set("Connection", "Close");
- conn_close = true;
- }
- }
-
- if (HttpListenerRequest.ProtocolVersion <= HttpVersion.Version10)
- {
- if (_keepAlive)
- {
- Headers["Keep-Alive"] = "true";
- }
-
- if (!conn_close)
- {
- _webHeaders.Set("Connection", "Keep-Alive");
- }
- }
-
- ComputeCookies();
- }
-
- var encoding = Encoding.UTF8;
- var writer = new StreamWriter(ms, encoding, 256);
- writer.Write("HTTP/1.1 {0} ", _statusCode); // "1.1" matches Windows implementation, which ignores the response version
- writer.Flush();
- byte[] statusDescriptionBytes = WebHeaderEncoding.GetBytes(StatusDescription);
- ms.Write(statusDescriptionBytes, 0, statusDescriptionBytes.Length);
- writer.Write("\r\n");
-
- writer.Write(FormatHeaders(_webHeaders));
- writer.Flush();
- int preamble = encoding.GetPreamble().Length;
- EnsureResponseStream();
-
- /* Assumes that the ms was at position 0 */
- ms.Position = preamble;
- SentHeaders = !isWebSocketHandshake;
- }
-
- private static bool HeaderCanHaveEmptyValue(string name) =>
- !string.Equals(name, "Location", StringComparison.OrdinalIgnoreCase);
-
- private static string FormatHeaders(WebHeaderCollection headers)
- {
- var sb = new StringBuilder();
-
- for (int i = 0; i < headers.Count; i++)
- {
- string key = headers.GetKey(i);
- string[] values = headers.GetValues(i);
-
- int startingLength = sb.Length;
-
- sb.Append(key).Append(": ");
- bool anyValues = false;
- for (int j = 0; j < values.Length; j++)
- {
- string value = values[j];
- if (!string.IsNullOrWhiteSpace(value))
- {
- if (anyValues)
- {
- sb.Append(", ");
- }
- sb.Append(value);
- anyValues = true;
- }
- }
-
- if (anyValues || HeaderCanHaveEmptyValue(key))
- {
- // Complete the header
- sb.Append("\r\n");
- }
- else
- {
- // Empty header; remove it.
- sb.Length = startingLength;
- }
- }
-
- return sb.Append("\r\n").ToString();
- }
-
- private bool Disposed { get; set; }
- internal bool SentHeaders { get; set; }
-
- public Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken)
- {
- return ((HttpResponseStream)OutputStream).TransmitFile(path, offset, count, fileShareMode, cancellationToken);
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpListenerResponse.cs b/SocketHttpListener/Net/HttpListenerResponse.cs
deleted file mode 100644
index 66ef88564..000000000
--- a/SocketHttpListener/Net/HttpListenerResponse.cs
+++ /dev/null
@@ -1,294 +0,0 @@
-using System;
-using System.IO;
-using System.Net;
-using System.Text;
-
-namespace SocketHttpListener.Net
-{
- public sealed partial class HttpListenerResponse : IDisposable
- {
- private BoundaryType _boundaryType = BoundaryType.None;
- private CookieCollection _cookies;
- private HttpListenerContext _httpContext;
- private bool _keepAlive = true;
- private HttpResponseStream _responseStream;
- private string _statusDescription;
- private WebHeaderCollection _webHeaders = new WebHeaderCollection();
-
- public WebHeaderCollection Headers => _webHeaders;
-
- public Encoding ContentEncoding { get; set; }
-
- public string ContentType
- {
- get => Headers["Content-Type"];
- set
- {
- CheckDisposed();
- if (string.IsNullOrEmpty(value))
- {
- Headers.Remove("Content-Type");
- }
- else
- {
- Headers.Set("Content-Type", value);
- }
- }
- }
-
- private HttpListenerContext HttpListenerContext => _httpContext;
-
- private HttpListenerRequest HttpListenerRequest => HttpListenerContext.Request;
-
- internal EntitySendFormat EntitySendFormat
- {
- get => (EntitySendFormat)_boundaryType;
- set
- {
- CheckDisposed();
- CheckSentHeaders();
- if (value == EntitySendFormat.Chunked && HttpListenerRequest.ProtocolVersion.Minor == 0)
- {
- throw new ProtocolViolationException("net_nochunkuploadonhttp10");
- }
- _boundaryType = (BoundaryType)value;
- if (value != EntitySendFormat.ContentLength)
- {
- _contentLength = -1;
- }
- }
- }
-
- public bool SendChunked
- {
- get => EntitySendFormat == EntitySendFormat.Chunked;
- set => EntitySendFormat = value ? EntitySendFormat.Chunked : EntitySendFormat.ContentLength;
- }
-
- // We MUST NOT send message-body when we send responses with these Status codes
- private static readonly int[] s_noResponseBody = { 100, 101, 204, 205, 304 };
-
- private static bool CanSendResponseBody(int responseCode)
- {
- for (int i = 0; i < s_noResponseBody.Length; i++)
- {
- if (responseCode == s_noResponseBody[i])
- {
- return false;
- }
- }
- return true;
- }
-
- public long ContentLength64
- {
- get => _contentLength;
- set
- {
- CheckDisposed();
- CheckSentHeaders();
- if (value >= 0)
- {
- _contentLength = value;
- _boundaryType = BoundaryType.ContentLength;
- }
- else
- {
- throw new ArgumentOutOfRangeException(nameof(value));
- }
- }
- }
-
- public CookieCollection Cookies
- {
- get => _cookies ?? (_cookies = new CookieCollection());
- set => _cookies = value;
- }
-
- public bool KeepAlive
- {
- get => _keepAlive;
- set
- {
- CheckDisposed();
- _keepAlive = value;
- }
- }
-
- public Stream OutputStream
- {
- get
- {
- CheckDisposed();
- EnsureResponseStream();
- return _responseStream;
- }
- }
-
- public string RedirectLocation
- {
- get => Headers["Location"];
- set
- {
- // note that this doesn't set the status code to a redirect one
- CheckDisposed();
- if (string.IsNullOrEmpty(value))
- {
- Headers.Remove("Location");
- }
- else
- {
- Headers.Set("Location", value);
- }
- }
- }
-
- public string StatusDescription
- {
- get
- {
- if (_statusDescription == null)
- {
- // if the user hasn't set this, generated on the fly, if possible.
- // We know this one is safe, no need to verify it as in the setter.
- _statusDescription = HttpStatusDescription.Get(StatusCode);
- }
- if (_statusDescription == null)
- {
- _statusDescription = string.Empty;
- }
- return _statusDescription;
- }
- set
- {
- CheckDisposed();
- if (value == null)
- {
- throw new ArgumentNullException(nameof(value));
- }
-
- // Need to verify the status description doesn't contain any control characters except HT. We mask off the high
- // byte since that's how it's encoded.
- for (int i = 0; i < value.Length; i++)
- {
- char c = (char)(0x000000ff & (uint)value[i]);
- if ((c <= 31 && c != (byte)'\t') || c == 127)
- {
- throw new ArgumentException("net_WebHeaderInvalidControlChars");
- }
- }
-
- _statusDescription = value;
- }
- }
-
- public void AddHeader(string name, string value)
- {
- Headers.Set(name, value);
- }
-
- public void AppendHeader(string name, string value)
- {
- Headers.Add(name, value);
- }
-
- public void AppendCookie(Cookie cookie)
- {
- if (cookie == null)
- {
- throw new ArgumentNullException(nameof(cookie));
- }
- Cookies.Add(cookie);
- }
-
- private void ComputeCookies()
- {
- if (_cookies != null)
- {
- // now go through the collection, and concatenate all the cookies in per-variant strings
- //string setCookie2 = null, setCookie = null;
- //for (int index = 0; index < _cookies.Count; index++)
- //{
- // Cookie cookie = _cookies[index];
- // string cookieString = cookie.ToServerString();
- // if (cookieString == null || cookieString.Length == 0)
- // {
- // continue;
- // }
-
- // if (cookie.IsRfc2965Variant())
- // {
- // setCookie2 = setCookie2 == null ? cookieString : setCookie2 + ", " + cookieString;
- // }
- // else
- // {
- // setCookie = setCookie == null ? cookieString : setCookie + ", " + cookieString;
- // }
- //}
-
- //if (!string.IsNullOrEmpty(setCookie))
- //{
- // Headers.Set(HttpKnownHeaderNames.SetCookie, setCookie);
- // if (string.IsNullOrEmpty(setCookie2))
- // {
- // Headers.Remove(HttpKnownHeaderNames.SetCookie2);
- // }
- //}
-
- //if (!string.IsNullOrEmpty(setCookie2))
- //{
- // Headers.Set(HttpKnownHeaderNames.SetCookie2, setCookie2);
- // if (string.IsNullOrEmpty(setCookie))
- // {
- // Headers.Remove(HttpKnownHeaderNames.SetCookie);
- // }
- //}
- }
- }
-
- public void Redirect(string url)
- {
- Headers["Location"] = url;
- StatusCode = (int)HttpStatusCode.Redirect;
- StatusDescription = "Found";
- }
-
- public void SetCookie(Cookie cookie)
- {
- if (cookie == null)
- {
- throw new ArgumentNullException(nameof(cookie));
- }
-
- //Cookie newCookie = cookie.Clone();
- //int added = Cookies.InternalAdd(newCookie, true);
-
- //if (added != 1)
- //{
- // // The Cookie already existed and couldn't be replaced.
- // throw new ArgumentException("Cookie exists");
- //}
- }
-
- void IDisposable.Dispose()
- {
- Dispose();
- }
-
- private void CheckDisposed()
- {
- if (Disposed)
- {
- throw new ObjectDisposedException(GetType().FullName);
- }
- }
-
- private void CheckSentHeaders()
- {
- if (SentHeaders)
- {
- throw new InvalidOperationException();
- }
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpRequestStream.Managed.cs b/SocketHttpListener/Net/HttpRequestStream.Managed.cs
deleted file mode 100644
index 42fc4d97c..000000000
--- a/SocketHttpListener/Net/HttpRequestStream.Managed.cs
+++ /dev/null
@@ -1,210 +0,0 @@
-using System;
-using System.IO;
-
-namespace SocketHttpListener.Net
-{
- // Licensed to the .NET Foundation under one or more agreements.
- // See the LICENSE file in the project root for more information.
- //
- // System.Net.ResponseStream
- //
- // Author:
- // Gonzalo Paniagua Javier (gonzalo@novell.com)
- //
- // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
-
- internal partial class HttpRequestStream : Stream
- {
- private byte[] _buffer;
- private int _offset;
- private int _length;
- private long _remainingBody;
- protected bool _closed;
- private Stream _stream;
-
- internal HttpRequestStream(Stream stream, byte[] buffer, int offset, int length)
- : this(stream, buffer, offset, length, -1)
- {
- }
-
- internal HttpRequestStream(Stream stream, byte[] buffer, int offset, int length, long contentlength)
- {
- _stream = stream;
- _buffer = buffer;
- _offset = offset;
- _length = length;
- _remainingBody = contentlength;
- }
-
- // Returns 0 if we can keep reading from the base stream,
- // > 0 if we read something from the buffer.
- // -1 if we had a content length set and we finished reading that many bytes.
- private int FillFromBuffer(byte[] buffer, int offset, int count)
- {
- if (_remainingBody == 0)
- return -1;
-
- if (_length == 0)
- return 0;
-
- int size = Math.Min(_length, count);
- if (_remainingBody > 0)
- size = (int)Math.Min(size, _remainingBody);
-
- if (_offset > _buffer.Length - size)
- {
- size = Math.Min(size, _buffer.Length - _offset);
- }
- if (size == 0)
- return 0;
-
- Buffer.BlockCopy(_buffer, _offset, buffer, offset, size);
- _offset += size;
- _length -= size;
- if (_remainingBody > 0)
- _remainingBody -= size;
- return size;
- }
-
- protected virtual int ReadCore(byte[] buffer, int offset, int size)
- {
- // Call FillFromBuffer to check for buffer boundaries even when remaining_body is 0
- int nread = FillFromBuffer(buffer, offset, size);
- if (nread == -1)
- { // No more bytes available (Content-Length)
- return 0;
- }
- else if (nread > 0)
- {
- return nread;
- }
-
- if (_remainingBody > 0)
- {
- size = (int)Math.Min(_remainingBody, (long)size);
- }
-
- nread = _stream.Read(buffer, offset, size);
-
- if (_remainingBody > 0)
- {
- if (nread == 0)
- {
- throw new Exception("Bad request");
- }
-
- //Debug.Assert(nread <= _remainingBody);
- _remainingBody -= nread;
- }
-
- return nread;
- }
-
- protected virtual IAsyncResult BeginReadCore(byte[] buffer, int offset, int size, AsyncCallback cback, object state)
- {
- if (size == 0 || _closed)
- {
- var ares = new HttpStreamAsyncResult(this);
- ares._callback = cback;
- ares._state = state;
- ares.Complete();
- return ares;
- }
-
- int nread = FillFromBuffer(buffer, offset, size);
- if (nread > 0 || nread == -1)
- {
- var ares = new HttpStreamAsyncResult(this);
- ares._buffer = buffer;
- ares._offset = offset;
- ares._count = size;
- ares._callback = cback;
- ares._state = state;
- ares._synchRead = Math.Max(0, nread);
- ares.Complete();
- return ares;
- }
-
- // Avoid reading past the end of the request to allow
- // for HTTP pipelining
- if (_remainingBody >= 0 && size > _remainingBody)
- {
- size = (int)Math.Min(_remainingBody, (long)size);
- }
-
- return _stream.BeginRead(buffer, offset, size, cback, state);
- }
-
- public override int EndRead(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- throw new ArgumentNullException(nameof(asyncResult));
-
- var r = asyncResult as HttpStreamAsyncResult;
- if (r != null)
- {
- if (!ReferenceEquals(this, r._parent))
- {
- throw new ArgumentException("Invalid async result");
- }
- if (r._endCalled)
- {
- throw new InvalidOperationException("invalid end call");
- }
- r._endCalled = true;
-
- if (!asyncResult.IsCompleted)
- {
- asyncResult.AsyncWaitHandle.WaitOne();
- }
-
- return r._synchRead;
- }
-
- if (_closed)
- return 0;
-
- int nread = 0;
- try
- {
- nread = _stream.EndRead(asyncResult);
- }
- catch (IOException e) when (e.InnerException is ArgumentException || e.InnerException is InvalidOperationException)
- {
- throw e.InnerException;
- }
-
- if (_remainingBody > 0)
- {
- if (nread == 0)
- {
- throw new Exception("Bad request");
- }
-
- _remainingBody -= nread;
- }
-
- return nread;
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpRequestStream.cs b/SocketHttpListener/Net/HttpRequestStream.cs
deleted file mode 100644
index 1c554df20..000000000
--- a/SocketHttpListener/Net/HttpRequestStream.cs
+++ /dev/null
@@ -1,129 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace SocketHttpListener.Net
-{
- // Licensed to the .NET Foundation under one or more agreements.
- // See the LICENSE file in the project root for more information.
- //
- // System.Net.ResponseStream
- //
- // Author:
- // Gonzalo Paniagua Javier (gonzalo@novell.com)
- //
- // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
-
- internal partial class HttpRequestStream : Stream
- {
- public override bool CanSeek => false;
- public override bool CanWrite => false;
- public override bool CanRead => true;
-
- public override int Read(byte[] buffer, int offset, int size)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer));
- }
- if (offset < 0 || offset > buffer.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(offset));
- }
- if (size < 0 || size > buffer.Length - offset)
- {
- throw new ArgumentOutOfRangeException(nameof(size));
- }
- if (size == 0 || _closed)
- {
- return 0;
- }
-
- return ReadCore(buffer, offset, size);
- }
-
- public override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer));
- }
- if (offset < 0 || offset > buffer.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(offset));
- }
- if (size < 0 || size > buffer.Length - offset)
- {
- throw new ArgumentOutOfRangeException(nameof(size));
- }
-
- return BeginReadCore(buffer, offset, size, callback, state);
- }
-
- public override void Flush() { }
- public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask;
-
- public override long Length => throw new NotImplementedException();
-
- public override long Position
- {
- get => throw new NotImplementedException();
-
- set => throw new NotImplementedException();
- }
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotImplementedException();
- }
-
- public override void SetLength(long value)
- {
- throw new NotImplementedException();
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- throw new NotImplementedException();
- }
-
- public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
- {
- return base.BeginWrite(buffer, offset, count, callback, state);
- }
-
- public override void EndWrite(IAsyncResult asyncResult)
- {
- base.EndWrite(asyncResult);
- }
-
- internal bool Closed => _closed;
-
- protected override void Dispose(bool disposing)
- {
- _closed = true;
- base.Dispose(disposing);
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpResponseStream.Managed.cs b/SocketHttpListener/Net/HttpResponseStream.Managed.cs
deleted file mode 100644
index 5d02a9c95..000000000
--- a/SocketHttpListener/Net/HttpResponseStream.Managed.cs
+++ /dev/null
@@ -1,329 +0,0 @@
-using System;
-using System.IO;
-using System.Net;
-using System.Net.Sockets;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.System;
-using Microsoft.Extensions.Logging;
-
-namespace SocketHttpListener.Net
-{
- // Licensed to the .NET Foundation under one or more agreements.
- // See the LICENSE file in the project root for more information.
- //
- // System.Net.ResponseStream
- //
- // Author:
- // Gonzalo Paniagua Javier (gonzalo@novell.com)
- //
- // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
-
- internal partial class HttpResponseStream : Stream
- {
- private HttpListenerResponse _response;
- private bool _ignore_errors;
- private bool _trailer_sent;
- private Stream _stream;
- private readonly IStreamHelper _streamHelper;
- private readonly Socket _socket;
- private readonly bool _supportsDirectSocketAccess;
- private readonly IEnvironmentInfo _environment;
- private readonly IFileSystem _fileSystem;
- private readonly ILogger _logger;
-
- internal HttpResponseStream(Stream stream, HttpListenerResponse response, bool ignore_errors, IStreamHelper streamHelper, Socket socket, bool supportsDirectSocketAccess, IEnvironmentInfo environment, IFileSystem fileSystem, ILogger logger)
- {
- _response = response;
- _ignore_errors = ignore_errors;
- _streamHelper = streamHelper;
- _socket = socket;
- _supportsDirectSocketAccess = supportsDirectSocketAccess;
- _environment = environment;
- _fileSystem = fileSystem;
- _logger = logger;
- _stream = stream;
- }
-
- private void DisposeCore()
- {
- byte[] bytes = null;
- MemoryStream ms = GetHeaders(true);
- bool chunked = _response.SendChunked;
- if (_stream.CanWrite)
- {
- try
- {
- if (ms != null)
- {
- long start = ms.Position;
- if (chunked && !_trailer_sent)
- {
- bytes = GetChunkSizeBytes(0, true);
- ms.Position = ms.Length;
- ms.Write(bytes, 0, bytes.Length);
- }
- InternalWrite(ms.GetBuffer(), (int)start, (int)(ms.Length - start));
- _trailer_sent = true;
- }
- else if (chunked && !_trailer_sent)
- {
- bytes = GetChunkSizeBytes(0, true);
- InternalWrite(bytes, 0, bytes.Length);
- _trailer_sent = true;
- }
- }
- catch (HttpListenerException)
- {
- // Ignore error due to connection reset by peer
- }
- }
- _response.Close();
- }
-
- internal async Task WriteWebSocketHandshakeHeadersAsync()
- {
- if (_closed)
- throw new ObjectDisposedException(GetType().ToString());
-
- if (_stream.CanWrite)
- {
- MemoryStream ms = GetHeaders(closing: false, isWebSocketHandshake: true);
- bool chunked = _response.SendChunked;
-
- long start = ms.Position;
- if (chunked)
- {
- byte[] bytes = GetChunkSizeBytes(0, true);
- ms.Position = ms.Length;
- ms.Write(bytes, 0, bytes.Length);
- }
-
- await InternalWriteAsync(ms.GetBuffer(), (int)start, (int)(ms.Length - start)).ConfigureAwait(false);
- await _stream.FlushAsync().ConfigureAwait(false);
- }
- }
-
- private MemoryStream GetHeaders(bool closing, bool isWebSocketHandshake = false)
- {
- //// SendHeaders works on shared headers
- //lock (_response.headers_lock)
- //{
- // if (_response.HeadersSent)
- // return null;
- // var ms = CreateNew();
- // _response.SendHeaders(closing, ms);
- // return ms;
- //}
-
- // SendHeaders works on shared headers
- lock (_response._headersLock)
- {
- if (_response.SentHeaders)
- {
- return null;
- }
-
- MemoryStream ms = new MemoryStream();
- _response.SendHeaders(closing, ms, isWebSocketHandshake);
- return ms;
- }
- }
-
- private static byte[] s_crlf = new byte[] { 13, 10 };
- private static byte[] GetChunkSizeBytes(int size, bool final)
- {
- string str = string.Format("{0:x}\r\n{1}", size, final ? "\r\n" : "");
- return Encoding.ASCII.GetBytes(str);
- }
-
- internal void InternalWrite(byte[] buffer, int offset, int count)
- {
- if (_ignore_errors)
- {
- try
- {
- _stream.Write(buffer, offset, count);
- }
- catch { }
- }
- else
- {
- _stream.Write(buffer, offset, count);
- }
- }
-
- internal Task InternalWriteAsync(byte[] buffer, int offset, int count) =>
- _ignore_errors ? InternalWriteIgnoreErrorsAsync(buffer, offset, count) : _stream.WriteAsync(buffer, offset, count);
-
- private async Task InternalWriteIgnoreErrorsAsync(byte[] buffer, int offset, int count)
- {
- try { await _stream.WriteAsync(buffer, offset, count).ConfigureAwait(false); }
- catch { }
- }
-
- private void WriteCore(byte[] buffer, int offset, int size)
- {
- if (size == 0)
- return;
-
- byte[] bytes = null;
- MemoryStream ms = GetHeaders(false);
- bool chunked = _response.SendChunked;
- if (ms != null)
- {
- long start = ms.Position; // After the possible preamble for the encoding
- ms.Position = ms.Length;
- if (chunked)
- {
- bytes = GetChunkSizeBytes(size, false);
- ms.Write(bytes, 0, bytes.Length);
- }
-
- int new_count = Math.Min(size, 16384 - (int)ms.Position + (int)start);
- ms.Write(buffer, offset, new_count);
- size -= new_count;
- offset += new_count;
- InternalWrite(ms.GetBuffer(), (int)start, (int)(ms.Length - start));
- ms.SetLength(0);
- ms.Capacity = 0; // 'dispose' the buffer in ms.
- }
- else if (chunked)
- {
- bytes = GetChunkSizeBytes(size, false);
- InternalWrite(bytes, 0, bytes.Length);
- }
-
- if (size > 0)
- InternalWrite(buffer, offset, size);
- if (chunked)
- InternalWrite(s_crlf, 0, 2);
- }
-
- private IAsyncResult BeginWriteCore(byte[] buffer, int offset, int size, AsyncCallback cback, object state)
- {
- if (_closed)
- {
- var ares = new HttpStreamAsyncResult(this);
- ares._callback = cback;
- ares._state = state;
- ares.Complete();
- return ares;
- }
-
- byte[] bytes = null;
- MemoryStream ms = GetHeaders(false);
- bool chunked = _response.SendChunked;
- if (ms != null)
- {
- long start = ms.Position;
- ms.Position = ms.Length;
- if (chunked)
- {
- bytes = GetChunkSizeBytes(size, false);
- ms.Write(bytes, 0, bytes.Length);
- }
- ms.Write(buffer, offset, size);
- buffer = ms.GetBuffer();
- offset = (int)start;
- size = (int)(ms.Position - start);
- }
- else if (chunked)
- {
- bytes = GetChunkSizeBytes(size, false);
- InternalWrite(bytes, 0, bytes.Length);
- }
-
- return _stream.BeginWrite(buffer, offset, size, cback, state);
- }
-
- private void EndWriteCore(IAsyncResult asyncResult)
- {
- if (_closed)
- return;
-
- if (_ignore_errors)
- {
- try
- {
- _stream.EndWrite(asyncResult);
- if (_response.SendChunked)
- _stream.Write(s_crlf, 0, 2);
- }
- catch { }
- }
- else
- {
- _stream.EndWrite(asyncResult);
- if (_response.SendChunked)
- _stream.Write(s_crlf, 0, 2);
- }
- }
-
- public Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken)
- {
- return TransmitFileManaged(path, offset, count, fileShareMode, cancellationToken);
- }
-
- const int StreamCopyToBufferSize = 81920;
- private async Task TransmitFileManaged(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken)
- {
- var allowAsync = _environment.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows;
-
- //if (count <= 0)
- //{
- // allowAsync = true;
- //}
-
- var fileOpenOptions = FileOpenOptions.SequentialScan;
-
- if (allowAsync)
- {
- fileOpenOptions |= FileOpenOptions.Asynchronous;
- }
-
- // use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039
-
- using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Open, FileAccessMode.Read, fileShareMode, fileOpenOptions))
- {
- if (offset > 0)
- {
- fs.Position = offset;
- }
-
- var targetStream = this;
-
- if (count > 0)
- {
- await _streamHelper.CopyToAsync(fs, targetStream, count, cancellationToken).ConfigureAwait(false);
- }
- else
- {
- await fs.CopyToAsync(targetStream, StreamCopyToBufferSize, cancellationToken).ConfigureAwait(false);
- }
- }
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpResponseStream.cs b/SocketHttpListener/Net/HttpResponseStream.cs
deleted file mode 100644
index 085c2ad0c..000000000
--- a/SocketHttpListener/Net/HttpResponseStream.cs
+++ /dev/null
@@ -1,124 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace SocketHttpListener.Net
-{
- internal sealed partial class HttpResponseStream : Stream
- {
- private bool _closed;
- internal bool Closed => _closed;
-
- public override bool CanRead => false;
- public override bool CanSeek => false;
- public override bool CanWrite => true;
-
- public override void Flush() { }
- public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask;
-
- public override long Length => throw new NotImplementedException();
-
- public override long Position
- {
- get => throw new NotImplementedException();
-
- set => throw new NotImplementedException();
- }
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotImplementedException();
- }
-
- public override void SetLength(long value)
- {
- throw new NotImplementedException();
- }
-
- public override int Read(byte[] buffer, int offset, int count)
- {
- throw new NotImplementedException();
- }
-
- public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
- {
- return base.BeginRead(buffer, offset, count, callback, state);
- }
-
- public override int EndRead(IAsyncResult asyncResult)
- {
- return base.EndRead(asyncResult);
- }
-
- public override void Write(byte[] buffer, int offset, int size)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer));
- }
- if (offset < 0 || offset > buffer.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(offset));
- }
- if (size < 0 || size > buffer.Length - offset)
- {
- throw new ArgumentOutOfRangeException(nameof(size));
- }
- if (_closed)
- {
- return;
- }
-
- WriteCore(buffer, offset, size);
- }
-
- public override IAsyncResult BeginWrite(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer));
- }
- if (offset < 0 || offset > buffer.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(offset));
- }
- if (size < 0 || size > buffer.Length - offset)
- {
- throw new ArgumentOutOfRangeException(nameof(size));
- }
-
- return BeginWriteCore(buffer, offset, size, callback, state);
- }
-
- public override void EndWrite(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- {
- throw new ArgumentNullException(nameof(asyncResult));
- }
-
- EndWriteCore(asyncResult);
- }
-
- protected override void Dispose(bool disposing)
- {
- try
- {
- if (disposing)
- {
- if (_closed)
- {
- return;
- }
- _closed = true;
- DisposeCore();
- }
- }
- finally
- {
- base.Dispose(disposing);
- }
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpStatusCode.cs b/SocketHttpListener/Net/HttpStatusCode.cs
deleted file mode 100644
index d4bb61b8a..000000000
--- a/SocketHttpListener/Net/HttpStatusCode.cs
+++ /dev/null
@@ -1,321 +0,0 @@
-namespace SocketHttpListener.Net
-{
- /// <summary>
- /// Contains the values of the HTTP status codes.
- /// </summary>
- /// <remarks>
- /// The HttpStatusCode enumeration contains the values of the HTTP status codes defined in
- /// <see href="http://tools.ietf.org/html/rfc2616#section-10">RFC 2616</see> for HTTP 1.1.
- /// </remarks>
- public enum HttpStatusCode
- {
- /// <summary>
- /// Equivalent to status code 100.
- /// Indicates that the client should continue with its request.
- /// </summary>
- Continue = 100,
- /// <summary>
- /// Equivalent to status code 101.
- /// Indicates that the server is switching the HTTP version or protocol on the connection.
- /// </summary>
- SwitchingProtocols = 101,
- /// <summary>
- /// Equivalent to status code 200.
- /// Indicates that the client's request has succeeded.
- /// </summary>
- OK = 200,
- /// <summary>
- /// Equivalent to status code 201.
- /// Indicates that the client's request has been fulfilled and resulted in a new resource being
- /// created.
- /// </summary>
- Created = 201,
- /// <summary>
- /// Equivalent to status code 202.
- /// Indicates that the client's request has been accepted for processing, but the processing
- /// hasn't been completed.
- /// </summary>
- Accepted = 202,
- /// <summary>
- /// Equivalent to status code 203.
- /// Indicates that the returned metainformation is from a local or a third-party copy instead of
- /// the origin server.
- /// </summary>
- NonAuthoritativeInformation = 203,
- /// <summary>
- /// Equivalent to status code 204.
- /// Indicates that the server has fulfilled the client's request but doesn't need to return
- /// an entity-body.
- /// </summary>
- NoContent = 204,
- /// <summary>
- /// Equivalent to status code 205.
- /// Indicates that the server has fulfilled the client's request, and the user agent should
- /// reset the document view which caused the request to be sent.
- /// </summary>
- ResetContent = 205,
- /// <summary>
- /// Equivalent to status code 206.
- /// Indicates that the server has fulfilled the partial GET request for the resource.
- /// </summary>
- PartialContent = 206,
- /// <summary>
- /// <para>
- /// Equivalent to status code 300.
- /// Indicates that the requested resource corresponds to any of multiple representations.
- /// </para>
- /// <para>
- /// MultipleChoices is a synonym for Ambiguous.
- /// </para>
- /// </summary>
- MultipleChoices = 300,
- /// <summary>
- /// <para>
- /// Equivalent to status code 300.
- /// Indicates that the requested resource corresponds to any of multiple representations.
- /// </para>
- /// <para>
- /// Ambiguous is a synonym for MultipleChoices.
- /// </para>
- /// </summary>
- Ambiguous = 300,
- /// <summary>
- /// <para>
- /// Equivalent to status code 301.
- /// Indicates that the requested resource has been assigned a new permanent URI and
- /// any future references to this resource should use one of the returned URIs.
- /// </para>
- /// <para>
- /// MovedPermanently is a synonym for Moved.
- /// </para>
- /// </summary>
- MovedPermanently = 301,
- /// <summary>
- /// <para>
- /// Equivalent to status code 301.
- /// Indicates that the requested resource has been assigned a new permanent URI and
- /// any future references to this resource should use one of the returned URIs.
- /// </para>
- /// <para>
- /// Moved is a synonym for MovedPermanently.
- /// </para>
- /// </summary>
- Moved = 301,
- /// <summary>
- /// <para>
- /// Equivalent to status code 302.
- /// Indicates that the requested resource is located temporarily under a different URI.
- /// </para>
- /// <para>
- /// Found is a synonym for Redirect.
- /// </para>
- /// </summary>
- Found = 302,
- /// <summary>
- /// <para>
- /// Equivalent to status code 302.
- /// Indicates that the requested resource is located temporarily under a different URI.
- /// </para>
- /// <para>
- /// Redirect is a synonym for Found.
- /// </para>
- /// </summary>
- Redirect = 302,
- /// <summary>
- /// <para>
- /// Equivalent to status code 303.
- /// Indicates that the response to the request can be found under a different URI and
- /// should be retrieved using a GET method on that resource.
- /// </para>
- /// <para>
- /// SeeOther is a synonym for RedirectMethod.
- /// </para>
- /// </summary>
- SeeOther = 303,
- /// <summary>
- /// <para>
- /// Equivalent to status code 303.
- /// Indicates that the response to the request can be found under a different URI and
- /// should be retrieved using a GET method on that resource.
- /// </para>
- /// <para>
- /// RedirectMethod is a synonym for SeeOther.
- /// </para>
- /// </summary>
- RedirectMethod = 303,
- /// <summary>
- /// Equivalent to status code 304.
- /// Indicates that the client has performed a conditional GET request and access is allowed,
- /// but the document hasn't been modified.
- /// </summary>
- NotModified = 304,
- /// <summary>
- /// Equivalent to status code 305.
- /// Indicates that the requested resource must be accessed through the proxy given by
- /// the Location field.
- /// </summary>
- UseProxy = 305,
- /// <summary>
- /// Equivalent to status code 306.
- /// This status code was used in a previous version of the specification, is no longer used,
- /// and is reserved for future use.
- /// </summary>
- Unused = 306,
- /// <summary>
- /// <para>
- /// Equivalent to status code 307.
- /// Indicates that the requested resource is located temporarily under a different URI.
- /// </para>
- /// <para>
- /// TemporaryRedirect is a synonym for RedirectKeepVerb.
- /// </para>
- /// </summary>
- TemporaryRedirect = 307,
- /// <summary>
- /// <para>
- /// Equivalent to status code 307.
- /// Indicates that the requested resource is located temporarily under a different URI.
- /// </para>
- /// <para>
- /// RedirectKeepVerb is a synonym for TemporaryRedirect.
- /// </para>
- /// </summary>
- RedirectKeepVerb = 307,
- /// <summary>
- /// Equivalent to status code 400.
- /// Indicates that the client's request couldn't be understood by the server due to
- /// malformed syntax.
- /// </summary>
- BadRequest = 400,
- /// <summary>
- /// Equivalent to status code 401.
- /// Indicates that the client's request requires user authentication.
- /// </summary>
- Unauthorized = 401,
- /// <summary>
- /// Equivalent to status code 402.
- /// This status code is reserved for future use.
- /// </summary>
- PaymentRequired = 402,
- /// <summary>
- /// Equivalent to status code 403.
- /// Indicates that the server understood the client's request but is refusing to fulfill it.
- /// </summary>
- Forbidden = 403,
- /// <summary>
- /// Equivalent to status code 404.
- /// Indicates that the server hasn't found anything matching the request URI.
- /// </summary>
- NotFound = 404,
- /// <summary>
- /// Equivalent to status code 405.
- /// Indicates that the method specified in the request line isn't allowed for the resource
- /// identified by the request URI.
- /// </summary>
- MethodNotAllowed = 405,
- /// <summary>
- /// Equivalent to status code 406.
- /// Indicates that the server doesn't have the appropriate resource to respond to the Accept
- /// headers in the client's request.
- /// </summary>
- NotAcceptable = 406,
- /// <summary>
- /// Equivalent to status code 407.
- /// Indicates that the client must first authenticate itself with the proxy.
- /// </summary>
- ProxyAuthenticationRequired = 407,
- /// <summary>
- /// Equivalent to status code 408.
- /// Indicates that the client didn't produce a request within the time that the server was
- /// prepared to wait.
- /// </summary>
- RequestTimeout = 408,
- /// <summary>
- /// Equivalent to status code 409.
- /// Indicates that the client's request couldn't be completed due to a conflict on the server.
- /// </summary>
- Conflict = 409,
- /// <summary>
- /// Equivalent to status code 410.
- /// Indicates that the requested resource is no longer available at the server and
- /// no forwarding address is known.
- /// </summary>
- Gone = 410,
- /// <summary>
- /// Equivalent to status code 411.
- /// Indicates that the server refuses to accept the client's request without a defined
- /// Content-Length.
- /// </summary>
- LengthRequired = 411,
- /// <summary>
- /// Equivalent to status code 412.
- /// Indicates that the precondition given in one or more of the request headers evaluated to
- /// false when it was tested on the server.
- /// </summary>
- PreconditionFailed = 412,
- /// <summary>
- /// Equivalent to status code 413.
- /// Indicates that the entity of the client's request is larger than the server is willing or
- /// able to process.
- /// </summary>
- RequestEntityTooLarge = 413,
- /// <summary>
- /// Equivalent to status code 414.
- /// Indicates that the request URI is longer than the server is willing to interpret.
- /// </summary>
- RequestUriTooLong = 414,
- /// <summary>
- /// Equivalent to status code 415.
- /// Indicates that the entity of the client's request is in a format not supported by
- /// the requested resource for the requested method.
- /// </summary>
- UnsupportedMediaType = 415,
- /// <summary>
- /// Equivalent to status code 416.
- /// Indicates that none of the range specifier values in a Range request header overlap
- /// the current extent of the selected resource.
- /// </summary>
- RequestedRangeNotSatisfiable = 416,
- /// <summary>
- /// Equivalent to status code 417.
- /// Indicates that the expectation given in an Expect request header couldn't be met by
- /// the server.
- /// </summary>
- ExpectationFailed = 417,
- /// <summary>
- /// Equivalent to status code 500.
- /// Indicates that the server encountered an unexpected condition which prevented it from
- /// fulfilling the client's request.
- /// </summary>
- InternalServerError = 500,
- /// <summary>
- /// Equivalent to status code 501.
- /// Indicates that the server doesn't support the functionality required to fulfill the client's
- /// request.
- /// </summary>
- NotImplemented = 501,
- /// <summary>
- /// Equivalent to status code 502.
- /// Indicates that a gateway or proxy server received an invalid response from the upstream
- /// server.
- /// </summary>
- BadGateway = 502,
- /// <summary>
- /// Equivalent to status code 503.
- /// Indicates that the server is currently unable to handle the client's request due to
- /// a temporary overloading or maintenance of the server.
- /// </summary>
- ServiceUnavailable = 503,
- /// <summary>
- /// Equivalent to status code 504.
- /// Indicates that a gateway or proxy server didn't receive a timely response from the upstream
- /// server or some other auxiliary server.
- /// </summary>
- GatewayTimeout = 504,
- /// <summary>
- /// Equivalent to status code 505.
- /// Indicates that the server doesn't support the HTTP version used in the client's request.
- /// </summary>
- HttpVersionNotSupported = 505,
- }
-}
diff --git a/SocketHttpListener/Net/HttpStatusDescription.cs b/SocketHttpListener/Net/HttpStatusDescription.cs
deleted file mode 100644
index a4e42560b..000000000
--- a/SocketHttpListener/Net/HttpStatusDescription.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-namespace SocketHttpListener.Net
-{
- internal static class HttpStatusDescription
- {
- internal static string Get(HttpStatusCode code)
- {
- return Get((int)code);
- }
-
- internal static string Get(int code)
- {
- switch (code)
- {
- case 100: return "Continue";
- case 101: return "Switching Protocols";
- case 102: return "Processing";
-
- case 200: return "OK";
- case 201: return "Created";
- case 202: return "Accepted";
- case 203: return "Non-Authoritative Information";
- case 204: return "No Content";
- case 205: return "Reset Content";
- case 206: return "Partial Content";
- case 207: return "Multi-Status";
-
- case 300: return "Multiple Choices";
- case 301: return "Moved Permanently";
- case 302: return "Found";
- case 303: return "See Other";
- case 304: return "Not Modified";
- case 305: return "Use Proxy";
- case 307: return "Temporary Redirect";
-
- case 400: return "Bad Request";
- case 401: return "Unauthorized";
- case 402: return "Payment Required";
- case 403: return "Forbidden";
- case 404: return "Not Found";
- case 405: return "Method Not Allowed";
- case 406: return "Not Acceptable";
- case 407: return "Proxy Authentication Required";
- case 408: return "Request Timeout";
- case 409: return "Conflict";
- case 410: return "Gone";
- case 411: return "Length Required";
- case 412: return "Precondition Failed";
- case 413: return "Request Entity Too Large";
- case 414: return "Request-Uri Too Long";
- case 415: return "Unsupported Media Type";
- case 416: return "Requested Range Not Satisfiable";
- case 417: return "Expectation Failed";
- case 422: return "Unprocessable Entity";
- case 423: return "Locked";
- case 424: return "Failed Dependency";
- case 426: return "Upgrade Required"; // RFC 2817
-
- case 500: return "Internal Server Error";
- case 501: return "Not Implemented";
- case 502: return "Bad Gateway";
- case 503: return "Service Unavailable";
- case 504: return "Gateway Timeout";
- case 505: return "Http Version Not Supported";
- case 507: return "Insufficient Storage";
- }
- return null;
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpStreamAsyncResult.cs b/SocketHttpListener/Net/HttpStreamAsyncResult.cs
deleted file mode 100644
index 46944c624..000000000
--- a/SocketHttpListener/Net/HttpStreamAsyncResult.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace SocketHttpListener.Net
-{
- internal class HttpStreamAsyncResult : IAsyncResult
- {
- private object _locker = new object();
- private ManualResetEvent _handle;
- private bool _completed;
-
- internal readonly object _parent;
- internal byte[] _buffer;
- internal int _offset;
- internal int _count;
- internal AsyncCallback _callback;
- internal object _state;
- internal int _synchRead;
- internal Exception _error;
- internal bool _endCalled;
-
- internal HttpStreamAsyncResult(object parent)
- {
- _parent = parent;
- }
-
- public void Complete(Exception e)
- {
- _error = e;
- Complete();
- }
-
- public void Complete()
- {
- lock (_locker)
- {
- if (_completed)
- return;
-
- _completed = true;
- if (_handle != null)
- _handle.Set();
-
- if (_callback != null)
- Task.Run(() => _callback(this));
- }
- }
-
- public object AsyncState => _state;
-
- public WaitHandle AsyncWaitHandle
- {
- get
- {
- lock (_locker)
- {
- if (_handle == null)
- _handle = new ManualResetEvent(_completed);
- }
-
- return _handle;
- }
- }
-
- public bool CompletedSynchronously => false;
-
- public bool IsCompleted
- {
- get
- {
- lock (_locker)
- {
- return _completed;
- }
- }
- }
- }
-}
diff --git a/SocketHttpListener/Net/HttpVersion.cs b/SocketHttpListener/Net/HttpVersion.cs
deleted file mode 100644
index c0839b46d..000000000
--- a/SocketHttpListener/Net/HttpVersion.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System;
-
-namespace SocketHttpListener.Net
-{
- // <remarks>
- // </remarks>
- public class HttpVersion
- {
-
- public static readonly Version Version10 = new Version(1, 0);
- public static readonly Version Version11 = new Version(1, 1);
-
- // pretty useless..
- public HttpVersion() { }
- }
-}
diff --git a/SocketHttpListener/Net/ListenerPrefix.cs b/SocketHttpListener/Net/ListenerPrefix.cs
deleted file mode 100644
index edfcb8904..000000000
--- a/SocketHttpListener/Net/ListenerPrefix.cs
+++ /dev/null
@@ -1,89 +0,0 @@
-using System;
-using System.Net;
-
-namespace SocketHttpListener.Net
-{
- internal sealed class ListenerPrefix
- {
- private string _original;
- private string _host;
- private ushort _port;
- private string _path;
- private bool _secure;
- private IPAddress[] _addresses;
- internal HttpListener _listener;
-
- public ListenerPrefix(string prefix)
- {
- _original = prefix;
- Parse(prefix);
- }
-
- public override string ToString()
- {
- return _original;
- }
-
- public IPAddress[] Addresses
- {
- get => _addresses;
- set => _addresses = value;
- }
- public bool Secure => _secure;
-
- public string Host => _host;
-
- public int Port => _port;
-
- public string Path => _path;
-
- // Equals and GetHashCode are required to detect duplicates in HttpListenerPrefixCollection.
- public override bool Equals(object o)
- {
- var other = o as ListenerPrefix;
- if (other == null)
- return false;
-
- return (_original == other._original);
- }
-
- public override int GetHashCode()
- {
- return _original.GetHashCode();
- }
-
- private void Parse(string uri)
- {
- ushort default_port = 80;
- if (uri.StartsWith("https://"))
- {
- default_port = 443;
- _secure = true;
- }
-
- int length = uri.Length;
- int start_host = uri.IndexOf(':') + 3;
- if (start_host >= length)
- throw new ArgumentException("net_listener_host");
-
- int colon = uri.IndexOf(':', start_host, length - start_host);
- int root;
- if (colon > 0)
- {
- _host = uri.Substring(start_host, colon - start_host);
- root = uri.IndexOf('/', colon, length - colon);
- _port = (ushort)int.Parse(uri.Substring(colon + 1, root - colon - 1));
- _path = uri.Substring(root);
- }
- else
- {
- root = uri.IndexOf('/', start_host, length - start_host);
- _host = uri.Substring(start_host, root - start_host);
- _port = default_port;
- _path = uri.Substring(root);
- }
- if (_path.Length != 1)
- _path = _path.Substring(0, _path.Length - 1);
- }
- }
-}
diff --git a/SocketHttpListener/Net/UriScheme.cs b/SocketHttpListener/Net/UriScheme.cs
deleted file mode 100644
index 33d1f09db..000000000
--- a/SocketHttpListener/Net/UriScheme.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-namespace SocketHttpListener.Net
-{
- internal static class UriScheme
- {
- public const string File = "file";
- public const string Ftp = "ftp";
- public const string Gopher = "gopher";
- public const string Http = "http";
- public const string Https = "https";
- public const string News = "news";
- public const string NetPipe = "net.pipe";
- public const string NetTcp = "net.tcp";
- public const string Nntp = "nntp";
- public const string Mailto = "mailto";
- public const string Ws = "ws";
- public const string Wss = "wss";
-
- public const string SchemeDelimiter = "://";
- }
-}
diff --git a/SocketHttpListener/Net/WebHeaderCollection.cs b/SocketHttpListener/Net/WebHeaderCollection.cs
deleted file mode 100644
index 34fca808b..000000000
--- a/SocketHttpListener/Net/WebHeaderCollection.cs
+++ /dev/null
@@ -1,360 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Text;
-using MediaBrowser.Model.Services;
-
-namespace SocketHttpListener.Net
-{
- [ComVisible(true)]
- public class WebHeaderCollection : QueryParamCollection
- {
- [Flags]
- internal enum HeaderInfo
- {
- Request = 1,
- Response = 1 << 1,
- MultiValue = 1 << 10
- }
-
- static readonly bool[] allowed_chars = {
- false, false, false, false, false, false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, true, false, true, true, true, true, false, false, false, true,
- true, false, true, true, false, true, true, true, true, true, true, true, true, true, true, false,
- false, false, false, false, false, false, true, true, true, true, true, true, true, true, true,
- true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
- false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true,
- true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
- false, true, false
- };
-
- static readonly Dictionary<string, HeaderInfo> headers;
-
- static WebHeaderCollection()
- {
- headers = new Dictionary<string, HeaderInfo>(StringComparer.OrdinalIgnoreCase) {
- { "Allow", HeaderInfo.MultiValue },
- { "Accept", HeaderInfo.Request | HeaderInfo.MultiValue },
- { "Accept-Charset", HeaderInfo.MultiValue },
- { "Accept-Encoding", HeaderInfo.MultiValue },
- { "Accept-Language", HeaderInfo.MultiValue },
- { "Accept-Ranges", HeaderInfo.MultiValue },
- { "Age", HeaderInfo.Response },
- { "Authorization", HeaderInfo.MultiValue },
- { "Cache-Control", HeaderInfo.MultiValue },
- { "Cookie", HeaderInfo.MultiValue },
- { "Connection", HeaderInfo.Request | HeaderInfo.MultiValue },
- { "Content-Encoding", HeaderInfo.MultiValue },
- { "Content-Length", HeaderInfo.Request | HeaderInfo.Response },
- { "Content-Type", HeaderInfo.Request },
- { "Content-Language", HeaderInfo.MultiValue },
- { "Date", HeaderInfo.Request },
- { "Expect", HeaderInfo.Request | HeaderInfo.MultiValue},
- { "Host", HeaderInfo.Request },
- { "If-Match", HeaderInfo.MultiValue },
- { "If-Modified-Since", HeaderInfo.Request },
- { "If-None-Match", HeaderInfo.MultiValue },
- { "Keep-Alive", HeaderInfo.Response },
- { "Pragma", HeaderInfo.MultiValue },
- { "Proxy-Authenticate", HeaderInfo.MultiValue },
- { "Proxy-Authorization", HeaderInfo.MultiValue },
- { "Proxy-Connection", HeaderInfo.Request | HeaderInfo.MultiValue },
- { "Range", HeaderInfo.Request | HeaderInfo.MultiValue },
- { "Referer", HeaderInfo.Request },
- { "Set-Cookie", HeaderInfo.MultiValue },
- { "Set-Cookie2", HeaderInfo.MultiValue },
- { "Server", HeaderInfo.Response },
- { "TE", HeaderInfo.MultiValue },
- { "Trailer", HeaderInfo.MultiValue },
- { "Transfer-Encoding", HeaderInfo.Request | HeaderInfo.Response | HeaderInfo.MultiValue },
- { "Translate", HeaderInfo.Request | HeaderInfo.Response },
- { "Upgrade", HeaderInfo.MultiValue },
- { "User-Agent", HeaderInfo.Request },
- { "Vary", HeaderInfo.MultiValue },
- { "Via", HeaderInfo.MultiValue },
- { "Warning", HeaderInfo.MultiValue },
- { "WWW-Authenticate", HeaderInfo.Response | HeaderInfo. MultiValue },
- { "SecWebSocketAccept", HeaderInfo.Response },
- { "SecWebSocketExtensions", HeaderInfo.Request | HeaderInfo.Response | HeaderInfo. MultiValue },
- { "SecWebSocketKey", HeaderInfo.Request },
- { "Sec-WebSocket-Protocol", HeaderInfo.Request | HeaderInfo.Response | HeaderInfo. MultiValue },
- { "SecWebSocketVersion", HeaderInfo.Response | HeaderInfo. MultiValue }
- };
- }
-
- // Methods
-
- public void Add(string header)
- {
- if (header == null)
- throw new ArgumentNullException(nameof(header));
- int pos = header.IndexOf(':');
- if (pos == -1)
- throw new ArgumentException("no colon found", nameof(header));
-
- this.Add(header.Substring(0, pos), header.Substring(pos + 1));
- }
-
- public override void Add(string name, string value)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- this.AddWithoutValidate(name, value);
- }
-
- protected void AddWithoutValidate(string headerName, string headerValue)
- {
- if (!IsHeaderName(headerName))
- throw new ArgumentException("invalid header name: " + headerName, nameof(headerName));
- if (headerValue == null)
- headerValue = string.Empty;
- else
- headerValue = headerValue.Trim();
- if (!IsHeaderValue(headerValue))
- throw new ArgumentException("invalid header value: " + headerValue, nameof(headerValue));
-
- AddValue(headerName, headerValue);
- }
-
- internal void AddValue(string headerName, string headerValue)
- {
- base.Add(headerName, headerValue);
- }
-
- internal List<string> GetValues_internal(string header, bool split)
- {
- if (header == null)
- throw new ArgumentNullException(nameof(header));
-
- var values = base.GetValues(header);
- if (values == null || values.Count == 0)
- return null;
-
- if (split && IsMultiValue(header))
- {
- List<string> separated = null;
- foreach (var value in values)
- {
- if (value.IndexOf(',') < 0)
- {
- if (separated != null)
- separated.Add(value);
-
- continue;
- }
-
- if (separated == null)
- {
- separated = new List<string>(values.Count + 1);
- foreach (var v in values)
- {
- if (v == value)
- break;
-
- separated.Add(v);
- }
- }
-
- var slices = value.Split(',');
- var slices_length = slices.Length;
- if (value[value.Length - 1] == ',')
- --slices_length;
-
- for (int i = 0; i < slices_length; ++i)
- {
- separated.Add(slices[i].Trim());
- }
- }
-
- if (separated != null)
- return separated;
- }
-
- return values;
- }
-
- public override List<string> GetValues(string header)
- {
- return GetValues_internal(header, true);
- }
-
- public override string[] GetValues(int index)
- {
- string[] values = base.GetValues(index);
-
- if (values == null || values.Length == 0)
- {
- return null;
- }
-
- return values;
- }
-
- public static bool IsRestricted(string headerName)
- {
- return IsRestricted(headerName, false);
- }
-
- public static bool IsRestricted(string headerName, bool response)
- {
- if (headerName == null)
- throw new ArgumentNullException(nameof(headerName));
-
- if (headerName.Length == 0)
- throw new ArgumentException("empty string", nameof(headerName));
-
- if (!IsHeaderName(headerName))
- throw new ArgumentException("Invalid character in header");
-
- if (!headers.TryGetValue(headerName, out HeaderInfo info))
- return false;
-
- var flag = response ? HeaderInfo.Response : HeaderInfo.Request;
- return (info & flag) != 0;
- }
-
- public override void Set(string name, string value)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- if (!IsHeaderName(name))
- throw new ArgumentException("invalid header name");
- if (value == null)
- value = string.Empty;
- else
- value = value.Trim();
- if (!IsHeaderValue(value))
- throw new ArgumentException("invalid header value");
-
- base.Set(name, value);
- }
-
- internal string ToStringMultiValue()
- {
- var sb = new StringBuilder();
-
- int count = base.Count;
- for (int i = 0; i < count; i++)
- {
- string key = GetKey(i);
- if (IsMultiValue(key))
- {
- foreach (string v in GetValues(i))
- {
- sb.Append(key)
- .Append(": ")
- .Append(v)
- .Append("\r\n");
- }
- }
- else
- {
- sb.Append(key)
- .Append(": ")
- .Append(Get(i))
- .Append("\r\n");
- }
- }
- return sb.Append("\r\n").ToString();
- }
-
- public override string ToString()
- {
- var sb = new StringBuilder();
-
- int count = base.Count;
- for (int i = 0; i < count; i++)
- sb.Append(GetKey(i))
- .Append(": ")
- .Append(Get(i))
- .Append("\r\n");
-
- return sb.Append("\r\n").ToString();
- }
-
-
- // Internal Methods
-
- // With this we don't check for invalid characters in header. See bug #55994.
- internal void SetInternal(string header)
- {
- int pos = header.IndexOf(':');
- if (pos == -1)
- throw new ArgumentException("no colon found", nameof(header));
-
- SetInternal(header.Substring(0, pos), header.Substring(pos + 1));
- }
-
- internal void SetInternal(string name, string value)
- {
- if (value == null)
- value = string.Empty;
- else
- value = value.Trim();
- if (!IsHeaderValue(value))
- throw new ArgumentException("invalid header value");
-
- if (IsMultiValue(name))
- {
- base.Add(name, value);
- }
- else
- {
- base.Remove(name);
- base.Set(name, value);
- }
- }
-
- internal static bool IsMultiValue(string headerName)
- {
- if (headerName == null)
- return false;
-
- return headers.TryGetValue(headerName, out HeaderInfo info) && (info & HeaderInfo.MultiValue) != 0;
- }
-
- internal static bool IsHeaderValue(string value)
- {
- // TEXT any 8 bit value except CTL's (0-31 and 127)
- // but including \r\n space and \t
- // after a newline at least one space or \t must follow
- // certain header fields allow comments ()
-
- int len = value.Length;
- for (int i = 0; i < len; i++)
- {
- char c = value[i];
- if (c == 127)
- return false;
- if (c < 0x20 && (c != '\r' && c != '\n' && c != '\t'))
- return false;
- if (c == '\n' && ++i < len)
- {
- c = value[i];
- if (c != ' ' && c != '\t')
- return false;
- }
- }
-
- return true;
- }
-
- internal static bool IsHeaderName(string name)
- {
- if (name == null || name.Length == 0)
- return false;
-
- int len = name.Length;
- for (int i = 0; i < len; i++)
- {
- char c = name[i];
- if (c > 126 || !allowed_chars[c])
- return false;
- }
-
- return true;
- }
- }
-}
diff --git a/SocketHttpListener/Net/WebHeaderEncoding.cs b/SocketHttpListener/Net/WebHeaderEncoding.cs
deleted file mode 100644
index 96e0cc85d..000000000
--- a/SocketHttpListener/Net/WebHeaderEncoding.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-using System.Text;
-
-namespace SocketHttpListener.Net
-{
- // we use this static class as a helper class to encode/decode HTTP headers.
- // what we need is a 1-1 correspondence between a char in the range U+0000-U+00FF
- // and a byte in the range 0x00-0xFF (which is the range that can hit the network).
- // The Latin-1 encoding (ISO-88591-1) (GetEncoding(28591)) works for byte[] to string, but is a little slow.
- // It doesn't work for string -> byte[] because of best-fit-mapping problems.
- internal static class WebHeaderEncoding
- {
- // We don't want '?' replacement characters, just fail.
- private static readonly Encoding s_utf8Decoder = Encoding.GetEncoding("utf-8", EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);
-
- internal static unsafe string GetString(byte[] bytes, int byteIndex, int byteCount)
- {
- fixed (byte* pBytes = bytes)
- return GetString(pBytes + byteIndex, byteCount);
- }
-
- internal static unsafe string GetString(byte* pBytes, int byteCount)
- {
- if (byteCount < 1)
- return "";
-
- string s = new string('\0', byteCount);
-
- fixed (char* pStr = s)
- {
- char* pString = pStr;
- while (byteCount >= 8)
- {
- pString[0] = (char)pBytes[0];
- pString[1] = (char)pBytes[1];
- pString[2] = (char)pBytes[2];
- pString[3] = (char)pBytes[3];
- pString[4] = (char)pBytes[4];
- pString[5] = (char)pBytes[5];
- pString[6] = (char)pBytes[6];
- pString[7] = (char)pBytes[7];
- pString += 8;
- pBytes += 8;
- byteCount -= 8;
- }
- for (int i = 0; i < byteCount; i++)
- {
- pString[i] = (char)pBytes[i];
- }
- }
-
- return s;
- }
-
- internal static int GetByteCount(string myString)
- {
- return myString.Length;
- }
- internal static unsafe void GetBytes(string myString, int charIndex, int charCount, byte[] bytes, int byteIndex)
- {
- if (myString.Length == 0)
- {
- return;
- }
- fixed (byte* bufferPointer = bytes)
- {
- byte* newBufferPointer = bufferPointer + byteIndex;
- int finalIndex = charIndex + charCount;
- while (charIndex < finalIndex)
- {
- *newBufferPointer++ = (byte)myString[charIndex++];
- }
- }
- }
- internal static byte[] GetBytes(string myString)
- {
- byte[] bytes = new byte[myString.Length];
- if (myString.Length != 0)
- {
- GetBytes(myString, 0, myString.Length, bytes, 0);
- }
- return bytes;
- }
- }
-}
diff --git a/SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs b/SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs
deleted file mode 100644
index 5ed49ec47..000000000
--- a/SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Net;
-using System.Security.Principal;
-using MediaBrowser.Model.Services;
-
-namespace SocketHttpListener.Net.WebSockets
-{
- public class HttpListenerWebSocketContext : WebSocketContext
- {
- private readonly Uri _requestUri;
- private readonly QueryParamCollection _headers;
- private readonly CookieCollection _cookieCollection;
- private readonly IPrincipal _user;
- private readonly bool _isAuthenticated;
- private readonly bool _isLocal;
- private readonly bool _isSecureConnection;
-
- private readonly string _origin;
- private readonly IEnumerable<string> _secWebSocketProtocols;
- private readonly string _secWebSocketVersion;
- private readonly string _secWebSocketKey;
-
- private readonly WebSocket _webSocket;
-
- internal HttpListenerWebSocketContext(
- Uri requestUri,
- QueryParamCollection headers,
- CookieCollection cookieCollection,
- IPrincipal user,
- bool isAuthenticated,
- bool isLocal,
- bool isSecureConnection,
- string origin,
- IEnumerable<string> secWebSocketProtocols,
- string secWebSocketVersion,
- string secWebSocketKey,
- WebSocket webSocket)
- {
- _cookieCollection = new CookieCollection();
- _cookieCollection.Add(cookieCollection);
-
- //_headers = new NameValueCollection(headers);
- _headers = headers;
- _user = CopyPrincipal(user);
-
- _requestUri = requestUri;
- _isAuthenticated = isAuthenticated;
- _isLocal = isLocal;
- _isSecureConnection = isSecureConnection;
- _origin = origin;
- _secWebSocketProtocols = secWebSocketProtocols;
- _secWebSocketVersion = secWebSocketVersion;
- _secWebSocketKey = secWebSocketKey;
- _webSocket = webSocket;
- }
-
- public override Uri RequestUri => _requestUri;
-
- public override QueryParamCollection Headers => _headers;
-
- public override string Origin => _origin;
-
- public override IEnumerable<string> SecWebSocketProtocols => _secWebSocketProtocols;
-
- public override string SecWebSocketVersion => _secWebSocketVersion;
-
- public override string SecWebSocketKey => _secWebSocketKey;
-
- public override CookieCollection CookieCollection => _cookieCollection;
-
- public override IPrincipal User => _user;
-
- public override bool IsAuthenticated => _isAuthenticated;
-
- public override bool IsLocal => _isLocal;
-
- public override bool IsSecureConnection => _isSecureConnection;
-
- public override WebSocket WebSocket => _webSocket;
-
- private static IPrincipal CopyPrincipal(IPrincipal user)
- {
- if (user != null)
- {
- throw new NotImplementedException();
- }
-
- return null;
- }
- }
-}
diff --git a/SocketHttpListener/Net/WebSockets/HttpWebSocket.Managed.cs b/SocketHttpListener/Net/WebSockets/HttpWebSocket.Managed.cs
deleted file mode 100644
index 1cfd2dc90..000000000
--- a/SocketHttpListener/Net/WebSockets/HttpWebSocket.Managed.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-using System;
-using System.Threading.Tasks;
-
-namespace SocketHttpListener.Net.WebSockets
-{
- internal static partial class HttpWebSocket
- {
- private const string SupportedVersion = "13";
-
- internal static async Task<HttpListenerWebSocketContext> AcceptWebSocketAsyncCore(HttpListenerContext context,
- string subProtocol,
- int receiveBufferSize,
- TimeSpan keepAliveInterval,
- ArraySegment<byte>? internalBuffer = null)
- {
- ValidateOptions(subProtocol, receiveBufferSize, MinSendBufferSize, keepAliveInterval);
-
- // get property will create a new response if one doesn't exist.
- HttpListenerResponse response = context.Response;
- HttpListenerRequest request = context.Request;
- ValidateWebSocketHeaders(context);
-
- string secWebSocketVersion = request.Headers[HttpKnownHeaderNames.SecWebSocketVersion];
-
- // Optional for non-browser client
- string origin = request.Headers[HttpKnownHeaderNames.Origin];
-
- string[] secWebSocketProtocols = null;
- bool shouldSendSecWebSocketProtocolHeader =
- ProcessWebSocketProtocolHeader(
- request.Headers[HttpKnownHeaderNames.SecWebSocketProtocol],
- subProtocol,
- out var outgoingSecWebSocketProtocolString);
-
- if (shouldSendSecWebSocketProtocolHeader)
- {
- secWebSocketProtocols = new string[] { outgoingSecWebSocketProtocolString };
- response.Headers.Add(HttpKnownHeaderNames.SecWebSocketProtocol, outgoingSecWebSocketProtocolString);
- }
-
- // negotiate the websocket key return value
- string secWebSocketKey = request.Headers[HttpKnownHeaderNames.SecWebSocketKey];
- string secWebSocketAccept = HttpWebSocket.GetSecWebSocketAcceptString(secWebSocketKey);
-
- response.Headers.Add(HttpKnownHeaderNames.Connection, HttpKnownHeaderNames.Upgrade);
- response.Headers.Add(HttpKnownHeaderNames.Upgrade, WebSocketUpgradeToken);
- response.Headers.Add(HttpKnownHeaderNames.SecWebSocketAccept, secWebSocketAccept);
-
- response.StatusCode = (int)HttpStatusCode.SwitchingProtocols; // HTTP 101
- response.StatusDescription = HttpStatusDescription.Get(HttpStatusCode.SwitchingProtocols);
-
- var responseStream = response.OutputStream as HttpResponseStream;
-
- // Send websocket handshake headers
- await responseStream.WriteWebSocketHandshakeHeadersAsync().ConfigureAwait(false);
-
- //WebSocket webSocket = WebSocket.CreateFromStream(context.Connection.ConnectedStream, isServer: true, subProtocol, keepAliveInterval);
- var webSocket = new WebSocket(subProtocol);
-
- var webSocketContext = new HttpListenerWebSocketContext(
- request.Url,
- request.Headers,
- request.Cookies,
- context.User,
- request.IsAuthenticated,
- request.IsLocal,
- request.IsSecureConnection,
- origin,
- secWebSocketProtocols != null ? secWebSocketProtocols : Array.Empty<string>(),
- secWebSocketVersion,
- secWebSocketKey,
- webSocket);
-
- webSocket.SetContext(webSocketContext, context.Connection.Close, context.Connection.Stream);
-
- return webSocketContext;
- }
-
- private const bool WebSocketsSupported = true;
- }
-}
diff --git a/SocketHttpListener/Net/WebSockets/HttpWebSocket.cs b/SocketHttpListener/Net/WebSockets/HttpWebSocket.cs
deleted file mode 100644
index b346cc98e..000000000
--- a/SocketHttpListener/Net/WebSockets/HttpWebSocket.cs
+++ /dev/null
@@ -1,159 +0,0 @@
-using System;
-using System.Diagnostics.CodeAnalysis;
-using System.Security.Cryptography;
-using System.Text;
-using System.Threading;
-
-namespace SocketHttpListener.Net.WebSockets
-{
- internal static partial class HttpWebSocket
- {
- internal const string SecWebSocketKeyGuid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
- internal const string WebSocketUpgradeToken = "websocket";
- internal const int DefaultReceiveBufferSize = 16 * 1024;
- internal const int DefaultClientSendBufferSize = 16 * 1024;
-
- [SuppressMessage("Microsoft.Security", "CA5350", Justification = "SHA1 used only for hashing purposes, not for crypto.")]
- internal static string GetSecWebSocketAcceptString(string secWebSocketKey)
- {
- string retVal;
-
- // SHA1 used only for hashing purposes, not for crypto. Check here for FIPS compat.
- using (var sha1 = SHA1.Create())
- {
- string acceptString = string.Concat(secWebSocketKey, HttpWebSocket.SecWebSocketKeyGuid);
- byte[] toHash = Encoding.UTF8.GetBytes(acceptString);
- retVal = Convert.ToBase64String(sha1.ComputeHash(toHash));
- }
-
- return retVal;
- }
-
- // return value here signifies if a Sec-WebSocket-Protocol header should be returned by the server.
- internal static bool ProcessWebSocketProtocolHeader(string clientSecWebSocketProtocol,
- string subProtocol,
- out string acceptProtocol)
- {
- acceptProtocol = string.Empty;
- if (string.IsNullOrEmpty(clientSecWebSocketProtocol))
- {
- // client hasn't specified any Sec-WebSocket-Protocol header
- if (subProtocol != null)
- {
- // If the server specified _anything_ this isn't valid.
- throw new WebSocketException("UnsupportedProtocol");
- }
- // Treat empty and null from the server as the same thing here, server should not send headers.
- return false;
- }
-
- // here, we know the client specified something and it's non-empty.
-
- if (subProtocol == null)
- {
- // client specified some protocols, server specified 'null'. So server should send headers.
- return true;
- }
-
- // here, we know that the client has specified something, it's not empty
- // and the server has specified exactly one protocol
-
- string[] requestProtocols = clientSecWebSocketProtocol.Split(new char[] { ',' },
- StringSplitOptions.RemoveEmptyEntries);
- acceptProtocol = subProtocol;
-
- // client specified protocols, serverOptions has exactly 1 non-empty entry. Check that
- // this exists in the list the client specified.
- for (int i = 0; i < requestProtocols.Length; i++)
- {
- string currentRequestProtocol = requestProtocols[i].Trim();
- if (string.Equals(acceptProtocol, currentRequestProtocol, StringComparison.OrdinalIgnoreCase))
- {
- return true;
- }
- }
-
- throw new WebSocketException("net_WebSockets_AcceptUnsupportedProtocol");
- }
-
- internal static void ValidateOptions(string subProtocol, int receiveBufferSize, int sendBufferSize, TimeSpan keepAliveInterval)
- {
- if (subProtocol != null)
- {
- WebSocketValidate.ValidateSubprotocol(subProtocol);
- }
-
- if (receiveBufferSize < MinReceiveBufferSize)
- {
- throw new ArgumentOutOfRangeException(nameof(receiveBufferSize), "The receiveBufferSize was too small.");
- }
-
- if (sendBufferSize < MinSendBufferSize)
- {
- throw new ArgumentOutOfRangeException(nameof(sendBufferSize), "The sendBufferSize was too small.");
- }
-
- if (receiveBufferSize > MaxBufferSize)
- {
- throw new ArgumentOutOfRangeException(nameof(receiveBufferSize), "The receiveBufferSize was too large.");
- }
-
- if (sendBufferSize > MaxBufferSize)
- {
- throw new ArgumentOutOfRangeException(nameof(sendBufferSize), "The sendBufferSize was too large.");
- }
-
- if (keepAliveInterval < Timeout.InfiniteTimeSpan) // -1 millisecond
- {
- throw new ArgumentOutOfRangeException(nameof(keepAliveInterval), "The keepAliveInterval was too small.");
- }
- }
-
- internal const int MinSendBufferSize = 16;
- internal const int MinReceiveBufferSize = 256;
- internal const int MaxBufferSize = 64 * 1024;
-
- private static void ValidateWebSocketHeaders(HttpListenerContext context)
- {
- if (!WebSocketsSupported)
- {
- throw new PlatformNotSupportedException("net_WebSockets_UnsupportedPlatform");
- }
-
- if (!context.Request.IsWebSocketRequest)
- {
- throw new WebSocketException("net_WebSockets_AcceptNotAWebSocket");
- }
-
- string secWebSocketVersion = context.Request.Headers[HttpKnownHeaderNames.SecWebSocketVersion];
- if (string.IsNullOrEmpty(secWebSocketVersion))
- {
- throw new WebSocketException("net_WebSockets_AcceptHeaderNotFound");
- }
-
- if (!string.Equals(secWebSocketVersion, SupportedVersion, StringComparison.OrdinalIgnoreCase))
- {
- throw new WebSocketException("net_WebSockets_AcceptUnsupportedWebSocketVersion");
- }
-
- string secWebSocketKey = context.Request.Headers[HttpKnownHeaderNames.SecWebSocketKey];
- bool isSecWebSocketKeyInvalid = string.IsNullOrWhiteSpace(secWebSocketKey);
- if (!isSecWebSocketKeyInvalid)
- {
- try
- {
- // key must be 16 bytes then base64-encoded
- isSecWebSocketKeyInvalid = Convert.FromBase64String(secWebSocketKey).Length != 16;
- }
- catch
- {
- isSecWebSocketKeyInvalid = true;
- }
- }
- if (isSecWebSocketKeyInvalid)
- {
- throw new WebSocketException("net_WebSockets_AcceptHeaderNotFound");
- }
- }
- }
-}
diff --git a/SocketHttpListener/Net/WebSockets/WebSocketCloseStatus.cs b/SocketHttpListener/Net/WebSockets/WebSocketCloseStatus.cs
deleted file mode 100644
index 5ac89cf48..000000000
--- a/SocketHttpListener/Net/WebSockets/WebSocketCloseStatus.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-namespace SocketHttpListener.Net.WebSockets
-{
- public enum WebSocketCloseStatus
- {
- NormalClosure = 1000,
- EndpointUnavailable = 1001,
- ProtocolError = 1002,
- InvalidMessageType = 1003,
- Empty = 1005,
- // AbnormalClosure = 1006, // 1006 is reserved and should never be used by user
- InvalidPayloadData = 1007,
- PolicyViolation = 1008,
- MessageTooBig = 1009,
- MandatoryExtension = 1010,
- InternalServerError = 1011
- // TLSHandshakeFailed = 1015, // 1015 is reserved and should never be used by user
-
- // 0 - 999 Status codes in the range 0-999 are not used.
- // 1000 - 1999 Status codes in the range 1000-1999 are reserved for definition by this protocol.
- // 2000 - 2999 Status codes in the range 2000-2999 are reserved for use by extensions.
- // 3000 - 3999 Status codes in the range 3000-3999 MAY be used by libraries and frameworks. The
- // interpretation of these codes is undefined by this protocol. End applications MUST
- // NOT use status codes in this range.
- // 4000 - 4999 Status codes in the range 4000-4999 MAY be used by application code. The interpretation
- // of these codes is undefined by this protocol.
- }
-}
diff --git a/SocketHttpListener/Net/WebSockets/WebSocketContext.cs b/SocketHttpListener/Net/WebSockets/WebSocketContext.cs
deleted file mode 100644
index 10ad86439..000000000
--- a/SocketHttpListener/Net/WebSockets/WebSocketContext.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Net;
-using System.Security.Principal;
-using MediaBrowser.Model.Services;
-
-namespace SocketHttpListener.Net.WebSockets
-{
- public abstract class WebSocketContext
- {
- public abstract Uri RequestUri { get; }
- public abstract QueryParamCollection Headers { get; }
- public abstract string Origin { get; }
- public abstract IEnumerable<string> SecWebSocketProtocols { get; }
- public abstract string SecWebSocketVersion { get; }
- public abstract string SecWebSocketKey { get; }
- public abstract CookieCollection CookieCollection { get; }
- public abstract IPrincipal User { get; }
- public abstract bool IsAuthenticated { get; }
- public abstract bool IsLocal { get; }
- public abstract bool IsSecureConnection { get; }
- public abstract WebSocket WebSocket { get; }
- }
-}
diff --git a/SocketHttpListener/Net/WebSockets/WebSocketValidate.cs b/SocketHttpListener/Net/WebSockets/WebSocketValidate.cs
deleted file mode 100644
index 0469e3b6c..000000000
--- a/SocketHttpListener/Net/WebSockets/WebSocketValidate.cs
+++ /dev/null
@@ -1,141 +0,0 @@
-using System;
-using System.Globalization;
-using System.Text;
-using WebSocketState = System.Net.WebSockets.WebSocketState;
-
-namespace SocketHttpListener.Net.WebSockets
-{
- internal static partial class WebSocketValidate
- {
- internal const int MaxControlFramePayloadLength = 123;
- private const int CloseStatusCodeAbort = 1006;
- private const int CloseStatusCodeFailedTLSHandshake = 1015;
- private const int InvalidCloseStatusCodesFrom = 0;
- private const int InvalidCloseStatusCodesTo = 999;
- private const string Separators = "()<>@,;:\\\"/[]?={} ";
-
- internal static void ThrowIfInvalidState(WebSocketState currentState, bool isDisposed, WebSocketState[] validStates)
- {
- string validStatesText = string.Empty;
-
- if (validStates != null && validStates.Length > 0)
- {
- foreach (WebSocketState validState in validStates)
- {
- if (currentState == validState)
- {
- // Ordering is important to maintain .NET 4.5 WebSocket implementation exception behavior.
- if (isDisposed)
- {
- throw new ObjectDisposedException(nameof(WebSocket));
- }
-
- return;
- }
- }
-
- validStatesText = string.Join(", ", validStates);
- }
-
- throw new WebSocketException("net_WebSockets_InvalidState");
- }
-
- internal static void ValidateSubprotocol(string subProtocol)
- {
- if (string.IsNullOrWhiteSpace(subProtocol))
- {
- throw new ArgumentException("net_WebSockets_InvalidEmptySubProtocol");
- }
-
- string invalidChar = null;
- int i = 0;
- while (i < subProtocol.Length)
- {
- char ch = subProtocol[i];
- if (ch < 0x21 || ch > 0x7e)
- {
- invalidChar = string.Format(CultureInfo.InvariantCulture, "[{0}]", (int)ch);
- break;
- }
-
- if (!char.IsLetterOrDigit(ch) &&
- Separators.IndexOf(ch) >= 0)
- {
- invalidChar = ch.ToString();
- break;
- }
-
- i++;
- }
-
- if (invalidChar != null)
- {
- throw new ArgumentException("net_WebSockets_InvalidCharInProtocolString");
- }
- }
-
- internal static void ValidateCloseStatus(WebSocketCloseStatus closeStatus, string statusDescription)
- {
- if (closeStatus == WebSocketCloseStatus.Empty && !string.IsNullOrEmpty(statusDescription))
- {
- throw new ArgumentException("net_WebSockets_ReasonNotNull");
- }
-
- int closeStatusCode = (int)closeStatus;
-
- if ((closeStatusCode >= InvalidCloseStatusCodesFrom &&
- closeStatusCode <= InvalidCloseStatusCodesTo) ||
- closeStatusCode == CloseStatusCodeAbort ||
- closeStatusCode == CloseStatusCodeFailedTLSHandshake)
- {
- // CloseStatus 1006 means Aborted - this will never appear on the wire and is reflected by calling WebSocket.Abort
- throw new ArgumentException("net_WebSockets_InvalidCloseStatusCode");
- }
-
- int length = 0;
- if (!string.IsNullOrEmpty(statusDescription))
- {
- length = Encoding.UTF8.GetByteCount(statusDescription);
- }
-
- if (length > MaxControlFramePayloadLength)
- {
- throw new ArgumentException("net_WebSockets_InvalidCloseStatusDescription");
- }
- }
-
- internal static void ValidateArraySegment(ArraySegment<byte> arraySegment, string parameterName)
- {
- if (arraySegment.Array == null)
- {
- throw new ArgumentNullException(parameterName + "." + nameof(arraySegment.Array));
- }
- if (arraySegment.Offset < 0 || arraySegment.Offset > arraySegment.Array.Length)
- {
- throw new ArgumentOutOfRangeException(parameterName + "." + nameof(arraySegment.Offset));
- }
- if (arraySegment.Count < 0 || arraySegment.Count > (arraySegment.Array.Length - arraySegment.Offset))
- {
- throw new ArgumentOutOfRangeException(parameterName + "." + nameof(arraySegment.Count));
- }
- }
-
- internal static void ValidateBuffer(byte[] buffer, int offset, int count)
- {
- if (buffer == null)
- {
- throw new ArgumentNullException(nameof(buffer));
- }
-
- if (offset < 0 || offset > buffer.Length)
- {
- throw new ArgumentOutOfRangeException(nameof(offset));
- }
-
- if (count < 0 || count > (buffer.Length - offset))
- {
- throw new ArgumentOutOfRangeException(nameof(count));
- }
- }
- }
-}
diff --git a/SocketHttpListener/Opcode.cs b/SocketHttpListener/Opcode.cs
deleted file mode 100644
index 69cf3f372..000000000
--- a/SocketHttpListener/Opcode.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-namespace SocketHttpListener
-{
- /// <summary>
- /// Contains the values of the opcode that indicates the type of a WebSocket frame.
- /// </summary>
- /// <remarks>
- /// The values of the opcode are defined in
- /// <see href="http://tools.ietf.org/html/rfc6455#section-5.2">Section 5.2</see> of RFC 6455.
- /// </remarks>
- public enum Opcode : byte
- {
- /// <summary>
- /// Equivalent to numeric value 0.
- /// Indicates a continuation frame.
- /// </summary>
- Cont = 0x0,
- /// <summary>
- /// Equivalent to numeric value 1.
- /// Indicates a text frame.
- /// </summary>
- Text = 0x1,
- /// <summary>
- /// Equivalent to numeric value 2.
- /// Indicates a binary frame.
- /// </summary>
- Binary = 0x2,
- /// <summary>
- /// Equivalent to numeric value 8.
- /// Indicates a connection close frame.
- /// </summary>
- Close = 0x8,
- /// <summary>
- /// Equivalent to numeric value 9.
- /// Indicates a ping frame.
- /// </summary>
- Ping = 0x9,
- /// <summary>
- /// Equivalent to numeric value 10.
- /// Indicates a pong frame.
- /// </summary>
- Pong = 0xa
- }
-}
diff --git a/SocketHttpListener/PayloadData.cs b/SocketHttpListener/PayloadData.cs
deleted file mode 100644
index 6d15a6bcb..000000000
--- a/SocketHttpListener/PayloadData.cs
+++ /dev/null
@@ -1,130 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Text;
-
-namespace SocketHttpListener
-{
- internal class PayloadData : IEnumerable<byte>
- {
- #region Private Fields
-
- private byte[] _applicationData;
- private byte[] _extensionData;
- private bool _masked;
-
- #endregion
-
- #region Public Const Fields
-
- public const ulong MaxLength = long.MaxValue;
-
- #endregion
-
- #region Public Constructors
-
- public PayloadData()
- : this(new byte[0], new byte[0], false)
- {
- }
-
- public PayloadData(byte[] applicationData)
- : this(new byte[0], applicationData, false)
- {
- }
-
- public PayloadData(string applicationData)
- : this(new byte[0], Encoding.UTF8.GetBytes(applicationData), false)
- {
- }
-
- public PayloadData(byte[] applicationData, bool masked)
- : this(new byte[0], applicationData, masked)
- {
- }
-
- public PayloadData(byte[] extensionData, byte[] applicationData, bool masked)
- {
- _extensionData = extensionData;
- _applicationData = applicationData;
- _masked = masked;
- }
-
- #endregion
-
- #region Internal Properties
-
- internal bool ContainsReservedCloseStatusCode =>
- _applicationData.Length > 1 &&
- _applicationData.SubArray(0, 2).ToUInt16(ByteOrder.Big).IsReserved();
-
- #endregion
-
- #region Public Properties
-
- public byte[] ApplicationData => _applicationData;
-
- public byte[] ExtensionData => _extensionData;
-
- public bool IsMasked => _masked;
-
- public ulong Length => (ulong)(_extensionData.Length + _applicationData.Length);
-
- #endregion
-
- #region Private Methods
-
- private static void mask(byte[] src, byte[] key)
- {
- for (long i = 0; i < src.Length; i++)
- src[i] = (byte)(src[i] ^ key[i % 4]);
- }
-
- #endregion
-
- #region Public Methods
-
- public IEnumerator<byte> GetEnumerator()
- {
- foreach (byte b in _extensionData)
- yield return b;
-
- foreach (byte b in _applicationData)
- yield return b;
- }
-
- public void Mask(byte[] maskingKey)
- {
- if (_extensionData.Length > 0)
- mask(_extensionData, maskingKey);
-
- if (_applicationData.Length > 0)
- mask(_applicationData, maskingKey);
-
- _masked = !_masked;
- }
-
- public byte[] ToByteArray()
- {
- return _extensionData.Length > 0
- ? new List<byte>(this).ToArray()
- : _applicationData;
- }
-
- public override string ToString()
- {
- return BitConverter.ToString(ToByteArray());
- }
-
- #endregion
-
- #region Explicitly Implemented Interface Members
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- #endregion
- }
-}
diff --git a/SocketHttpListener/Properties/AssemblyInfo.cs b/SocketHttpListener/Properties/AssemblyInfo.cs
deleted file mode 100644
index a69bd176f..000000000
--- a/SocketHttpListener/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System.Reflection;
-using System.Resources;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("SocketHttpListener")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Jellyfin Project")]
-[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
-[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-[assembly: NeutralResourcesLanguage("en")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
diff --git a/SocketHttpListener/Rsv.cs b/SocketHttpListener/Rsv.cs
deleted file mode 100644
index 87283791e..000000000
--- a/SocketHttpListener/Rsv.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace SocketHttpListener
-{
- internal enum Rsv : byte
- {
- Off = 0x0,
- On = 0x1
- }
-}
diff --git a/SocketHttpListener/SocketHttpListener.csproj b/SocketHttpListener/SocketHttpListener.csproj
deleted file mode 100644
index e700540a9..000000000
--- a/SocketHttpListener/SocketHttpListener.csproj
+++ /dev/null
@@ -1,18 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
- <ItemGroup>
- <ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
- <ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
- </ItemGroup>
-
- <ItemGroup>
- <Compile Include="..\SharedVersion.cs" />
- </ItemGroup>
-
- <PropertyGroup>
- <TargetFramework>netstandard2.0</TargetFramework>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
- </PropertyGroup>
-
-</Project>
diff --git a/SocketHttpListener/SocketStream.cs b/SocketHttpListener/SocketStream.cs
deleted file mode 100644
index f51fde97e..000000000
--- a/SocketHttpListener/SocketStream.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-using System;
-using System.IO;
-using System.Net.Sockets;
-
-namespace SocketHttpListener
-{
- public class SocketStream : Stream
- {
- private readonly Socket _socket;
-
- public SocketStream(Socket socket, bool ownsSocket)
- {
- _socket = socket;
- }
-
- public override void Flush()
- {
- }
-
- public override bool CanRead => true;
-
- public override bool CanSeek => false;
-
- public override bool CanWrite => true;
-
- public override long Length => throw new NotImplementedException();
-
- public override long Position
- {
- get => throw new NotImplementedException();
- set => throw new NotImplementedException();
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- _socket.Send(buffer, offset, count, SocketFlags.None);
- }
-
- public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
- {
- return _socket.BeginSend(buffer, offset, count, SocketFlags.None, callback, state);
- }
-
- public override void EndWrite(IAsyncResult asyncResult)
- {
- _socket.EndSend(asyncResult);
- }
-
- public override void SetLength(long value)
- {
- throw new NotImplementedException();
- }
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotImplementedException();
- }
-
- public override int Read(byte[] buffer, int offset, int count)
- {
- return _socket.Receive(buffer, offset, count, SocketFlags.None);
- }
-
- public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
- {
- return _socket.BeginReceive(buffer, offset, count, SocketFlags.None, callback, state);
- }
-
- public override int EndRead(IAsyncResult asyncResult)
- {
- return _socket.EndReceive(asyncResult);
- }
- }
-}
diff --git a/SocketHttpListener/WebSocket.cs b/SocketHttpListener/WebSocket.cs
deleted file mode 100644
index 128bc8b97..000000000
--- a/SocketHttpListener/WebSocket.cs
+++ /dev/null
@@ -1,776 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.IO;
-using System.Net;
-using System.Net.Sockets;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using SocketHttpListener.Net.WebSockets;
-using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
-using WebSocketState = System.Net.WebSockets.WebSocketState;
-
-namespace SocketHttpListener
-{
- /// <summary>
- /// Implements the WebSocket interface.
- /// </summary>
- /// <remarks>
- /// The WebSocket class provides a set of methods and properties for two-way communication using
- /// the WebSocket protocol (<see href="http://tools.ietf.org/html/rfc6455">RFC 6455</see>).
- /// </remarks>
- public class WebSocket : IDisposable
- {
- #region Private Fields
-
- private Action _closeContext;
- private CompressionMethod _compression;
- private WebSocketContext _context;
- private CookieCollection _cookies;
- private AutoResetEvent _exitReceiving;
- private object _forConn;
- private object _forEvent;
- private object _forMessageEventQueue;
- private object _forSend;
- private const string _guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
- private Queue<MessageEventArgs> _messageEventQueue;
- private string _protocol;
- private volatile WebSocketState _readyState;
- private AutoResetEvent _receivePong;
- private bool _secure;
- private Stream _stream;
- private const string _version = "13";
-
- #endregion
-
- #region Internal Fields
-
- internal const int FragmentLength = 1016; // Max value is int.MaxValue - 14.
-
- #endregion
-
- #region Internal Constructors
-
- // As server
- internal WebSocket(string protocol)
- {
- _protocol = protocol;
- }
-
- public void SetContext(HttpListenerWebSocketContext context, Action closeContextFn, Stream stream)
- {
- _context = context;
-
- _closeContext = closeContextFn;
- _secure = context.IsSecureConnection;
- _stream = stream;
-
- init();
- }
-
- // In the .NET Framework, this pulls the value from a P/Invoke. Here we just hardcode it to a reasonable default.
- public static TimeSpan DefaultKeepAliveInterval => TimeSpan.FromSeconds(30);
-
- #endregion
-
- /// <summary>
- /// Gets the state of the WebSocket connection.
- /// </summary>
- /// <value>
- /// One of the <see cref="WebSocketState"/> enum values, indicates the state of the WebSocket
- /// connection. The default value is <see cref="WebSocketState.Connecting"/>.
- /// </value>
- public WebSocketState ReadyState => _readyState;
-
- #region Public Events
-
- /// <summary>
- /// Occurs when the WebSocket connection has been closed.
- /// </summary>
- public event EventHandler<CloseEventArgs> OnClose;
-
- /// <summary>
- /// Occurs when the <see cref="WebSocket"/> gets an error.
- /// </summary>
- public event EventHandler<ErrorEventArgs> OnError;
-
- /// <summary>
- /// Occurs when the <see cref="WebSocket"/> receives a message.
- /// </summary>
- public event EventHandler<MessageEventArgs> OnMessage;
-
- /// <summary>
- /// Occurs when the WebSocket connection has been established.
- /// </summary>
- public event EventHandler OnOpen;
-
- #endregion
-
- #region Private Methods
-
- private void close(CloseStatusCode code, string reason, bool wait)
- {
- close(new PayloadData(((ushort)code).Append(reason)), !code.IsReserved(), wait);
- }
-
- private void close(PayloadData payload, bool send, bool wait)
- {
- lock (_forConn)
- {
- if (_readyState == WebSocketState.CloseSent || _readyState == WebSocketState.Closed)
- {
- return;
- }
-
- _readyState = WebSocketState.CloseSent;
- }
-
- var e = new CloseEventArgs(payload);
- e.WasClean =
- closeHandshake(
- send ? WebSocketFrame.CreateCloseFrame(Mask.Unmask, payload).ToByteArray() : null,
- wait ? 1000 : 0);
-
- _readyState = WebSocketState.Closed;
- try
- {
- OnClose.Emit(this, e);
- }
- catch (Exception ex)
- {
- error("An exception has occurred while OnClose.", ex);
- }
- }
-
- private bool closeHandshake(byte[] frameAsBytes, int millisecondsTimeout)
- {
- var sent = frameAsBytes != null && writeBytes(frameAsBytes);
- var received =
- millisecondsTimeout == 0 ||
- (sent && _exitReceiving != null && _exitReceiving.WaitOne(millisecondsTimeout));
-
- closeServerResources();
-
- if (_receivePong != null)
- {
- _receivePong.Dispose();
- _receivePong = null;
- }
-
- if (_exitReceiving != null)
- {
- _exitReceiving.Dispose();
- _exitReceiving = null;
- }
-
- var result = sent && received;
-
- return result;
- }
-
- // As server
- private void closeServerResources()
- {
- if (_closeContext == null)
- return;
-
- try
- {
- _closeContext();
- }
- catch (SocketException)
- {
- // it could be unable to send the handshake response
- }
-
- _closeContext = null;
- _stream = null;
- _context = null;
- }
-
- private bool concatenateFragmentsInto(Stream dest)
- {
- while (true)
- {
- var frame = WebSocketFrame.Read(_stream, true);
- if (frame.IsFinal)
- {
- /* FINAL */
-
- // CONT
- if (frame.IsContinuation)
- {
- dest.WriteBytes(frame.PayloadData.ApplicationData);
- break;
- }
-
- // PING
- if (frame.IsPing)
- {
- processPingFrame(frame);
- continue;
- }
-
- // PONG
- if (frame.IsPong)
- {
- processPongFrame(frame);
- continue;
- }
-
- // CLOSE
- if (frame.IsClose)
- return processCloseFrame(frame);
- }
- else
- {
- /* MORE */
-
- // CONT
- if (frame.IsContinuation)
- {
- dest.WriteBytes(frame.PayloadData.ApplicationData);
- continue;
- }
- }
-
- // ?
- return processUnsupportedFrame(
- frame,
- CloseStatusCode.IncorrectData,
- "An incorrect data has been received while receiving fragmented data.");
- }
-
- return true;
- }
-
- // As server
- private HttpResponse createHandshakeCloseResponse(HttpStatusCode code)
- {
- var res = HttpResponse.CreateCloseResponse(code);
- res.Headers["Sec-WebSocket-Version"] = _version;
-
- return res;
- }
-
- private MessageEventArgs dequeueFromMessageEventQueue()
- {
- lock (_forMessageEventQueue)
- return _messageEventQueue.Count > 0
- ? _messageEventQueue.Dequeue()
- : null;
- }
-
- private void enqueueToMessageEventQueue(MessageEventArgs e)
- {
- lock (_forMessageEventQueue)
- _messageEventQueue.Enqueue(e);
- }
-
- private void error(string message, Exception exception)
- {
- try
- {
- if (exception != null)
- {
- message += ". Exception.Message: " + exception.Message;
- }
- OnError.Emit(this, new ErrorEventArgs(message));
- }
- catch (Exception)
- {
- }
- }
-
- private void error(string message)
- {
- try
- {
- OnError.Emit(this, new ErrorEventArgs(message));
- }
- catch (Exception)
- {
- }
- }
-
- private void init()
- {
- _compression = CompressionMethod.None;
- _cookies = new CookieCollection();
- _forConn = new object();
- _forEvent = new object();
- _forSend = new object();
- _messageEventQueue = new Queue<MessageEventArgs>();
- _forMessageEventQueue = ((ICollection)_messageEventQueue).SyncRoot;
- _readyState = WebSocketState.Connecting;
- }
-
- private void open()
- {
- try
- {
- startReceiving();
-
- lock (_forEvent)
- {
- try
- {
- if (OnOpen != null)
- {
- OnOpen(this, EventArgs.Empty);
- }
- }
- catch (Exception ex)
- {
- processException(ex, "An exception has occurred while OnOpen.");
- }
- }
- }
- catch (Exception ex)
- {
- processException(ex, "An exception has occurred while opening.");
- }
- }
-
- private bool processCloseFrame(WebSocketFrame frame)
- {
- var payload = frame.PayloadData;
- close(payload, !payload.ContainsReservedCloseStatusCode, false);
-
- return false;
- }
-
- private bool processDataFrame(WebSocketFrame frame)
- {
- var e = frame.IsCompressed
- ? new MessageEventArgs(
- frame.Opcode, frame.PayloadData.ApplicationData.Decompress(_compression))
- : new MessageEventArgs(frame.Opcode, frame.PayloadData);
-
- enqueueToMessageEventQueue(e);
- return true;
- }
-
- private void processException(Exception exception, string message)
- {
- var code = CloseStatusCode.Abnormal;
- var reason = message;
- if (exception is WebSocketException)
- {
- var wsex = (WebSocketException)exception;
- code = wsex.Code;
- reason = wsex.Message;
- }
-
- error(message ?? code.GetMessage(), exception);
- if (_readyState == WebSocketState.Connecting)
- Close(HttpStatusCode.BadRequest);
- else
- close(code, reason ?? code.GetMessage(), false);
- }
-
- private bool processFragmentedFrame(WebSocketFrame frame)
- {
- return frame.IsContinuation // Not first fragment
- ? true
- : processFragments(frame);
- }
-
- private bool processFragments(WebSocketFrame first)
- {
- using (var buff = new MemoryStream())
- {
- buff.WriteBytes(first.PayloadData.ApplicationData);
- if (!concatenateFragmentsInto(buff))
- return false;
-
- byte[] data;
- if (_compression != CompressionMethod.None)
- {
- data = buff.DecompressToArray(_compression);
- }
- else
- {
- data = buff.ToArray();
- }
-
- enqueueToMessageEventQueue(new MessageEventArgs(first.Opcode, data));
- return true;
- }
- }
-
- private bool processPingFrame(WebSocketFrame frame)
- {
- return true;
- }
-
- private bool processPongFrame(WebSocketFrame frame)
- {
- _receivePong.Set();
-
- return true;
- }
-
- private bool processUnsupportedFrame(WebSocketFrame frame, CloseStatusCode code, string reason)
- {
- processException(new WebSocketException(code, reason), null);
-
- return false;
- }
-
- private bool processWebSocketFrame(WebSocketFrame frame)
- {
- return frame.IsCompressed && _compression == CompressionMethod.None
- ? processUnsupportedFrame(
- frame,
- CloseStatusCode.IncorrectData,
- "A compressed data has been received without available decompression method.")
- : frame.IsFragmented
- ? processFragmentedFrame(frame)
- : frame.IsData
- ? processDataFrame(frame)
- : frame.IsPing
- ? processPingFrame(frame)
- : frame.IsPong
- ? processPongFrame(frame)
- : frame.IsClose
- ? processCloseFrame(frame)
- : processUnsupportedFrame(frame, CloseStatusCode.PolicyViolation, null);
- }
-
- private bool send(Opcode opcode, Stream stream)
- {
- lock (_forSend)
- {
- var src = stream;
- var compressed = false;
- var sent = false;
- try
- {
- if (_compression != CompressionMethod.None)
- {
- stream = stream.Compress(_compression);
- compressed = true;
- }
-
- sent = send(opcode, Mask.Unmask, stream, compressed);
- if (!sent)
- error("Sending a data has been interrupted.");
- }
- catch (Exception ex)
- {
- error("An exception has occurred while sending a data.", ex);
- }
- finally
- {
- if (compressed)
- stream.Dispose();
-
- src.Dispose();
- }
-
- return sent;
- }
- }
-
- private bool send(Opcode opcode, Mask mask, Stream stream, bool compressed)
- {
- var len = stream.Length;
-
- /* Not fragmented */
-
- if (len == 0)
- return send(Fin.Final, opcode, mask, new byte[0], compressed);
-
- var quo = len / FragmentLength;
- var rem = (int)(len % FragmentLength);
-
- byte[] buff = null;
- if (quo == 0)
- {
- buff = new byte[rem];
- return stream.Read(buff, 0, rem) == rem &&
- send(Fin.Final, opcode, mask, buff, compressed);
- }
-
- buff = new byte[FragmentLength];
- if (quo == 1 && rem == 0)
- return stream.Read(buff, 0, FragmentLength) == FragmentLength &&
- send(Fin.Final, opcode, mask, buff, compressed);
-
- /* Send fragmented */
-
- // Begin
- if (stream.Read(buff, 0, FragmentLength) != FragmentLength ||
- !send(Fin.More, opcode, mask, buff, compressed))
- return false;
-
- var n = rem == 0 ? quo - 2 : quo - 1;
- for (long i = 0; i < n; i++)
- if (stream.Read(buff, 0, FragmentLength) != FragmentLength ||
- !send(Fin.More, Opcode.Cont, mask, buff, compressed))
- return false;
-
- // End
- if (rem == 0)
- rem = FragmentLength;
- else
- buff = new byte[rem];
-
- return stream.Read(buff, 0, rem) == rem &&
- send(Fin.Final, Opcode.Cont, mask, buff, compressed);
- }
-
- private bool send(Fin fin, Opcode opcode, Mask mask, byte[] data, bool compressed)
- {
- lock (_forConn)
- {
- if (_readyState != WebSocketState.Open)
- {
- return false;
- }
-
- return writeBytes(
- WebSocketFrame.CreateWebSocketFrame(fin, opcode, mask, data, compressed).ToByteArray());
- }
- }
-
- private Task sendAsync(Opcode opcode, Stream stream)
- {
- var completionSource = new TaskCompletionSource<bool>();
- Task.Run(() =>
- {
- try
- {
- send(opcode, stream);
- completionSource.TrySetResult(true);
- }
- catch (Exception ex)
- {
- completionSource.TrySetException(ex);
- }
- });
- return completionSource.Task;
- }
-
- // As server
- private bool sendHttpResponse(HttpResponse response)
- {
- return writeBytes(response.ToByteArray());
- }
-
- private void startReceiving()
- {
- if (_messageEventQueue.Count > 0)
- _messageEventQueue.Clear();
-
- _exitReceiving = new AutoResetEvent(false);
- _receivePong = new AutoResetEvent(false);
-
- Action receive = null;
- receive = () => WebSocketFrame.ReadAsync(
- _stream,
- true,
- frame =>
- {
- if (processWebSocketFrame(frame) && _readyState != WebSocketState.Closed)
- {
- receive();
-
- if (!frame.IsData)
- return;
-
- lock (_forEvent)
- {
- try
- {
- var e = dequeueFromMessageEventQueue();
- if (e != null && _readyState == WebSocketState.Open)
- OnMessage.Emit(this, e);
- }
- catch (Exception ex)
- {
- processException(ex, "An exception has occurred while OnMessage.");
- }
- }
- }
- else if (_exitReceiving != null)
- {
- _exitReceiving.Set();
- }
- },
- ex => processException(ex, "An exception has occurred while receiving a message."));
-
- receive();
- }
-
- private bool writeBytes(byte[] data)
- {
- try
- {
- _stream.Write(data, 0, data.Length);
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
-
- #endregion
-
- #region Internal Methods
-
- // As server
- internal void Close(HttpResponse response)
- {
- _readyState = WebSocketState.CloseSent;
- sendHttpResponse(response);
-
- closeServerResources();
-
- _readyState = WebSocketState.Closed;
- }
-
- // As server
- internal void Close(HttpStatusCode code)
- {
- Close(createHandshakeCloseResponse(code));
- }
-
- // As server
- public void ConnectAsServer()
- {
- try
- {
- _readyState = WebSocketState.Open;
- open();
- }
- catch (Exception ex)
- {
- processException(ex, "An exception has occurred while connecting.");
- }
- }
-
- #endregion
-
- #region Public Methods
-
- /// <summary>
- /// Closes the WebSocket connection, and releases all associated resources.
- /// </summary>
- public void Close()
- {
- var msg = _readyState.CheckIfClosable();
- if (msg != null)
- {
- error(msg);
-
- return;
- }
-
- var send = _readyState == WebSocketState.Open;
- close(new PayloadData(), send, send);
- }
-
- /// <summary>
- /// Closes the WebSocket connection with the specified <see cref="CloseStatusCode"/>
- /// and <see cref="string"/>, and releases all associated resources.
- /// </summary>
- /// <remarks>
- /// This method emits a <see cref="OnError"/> event if the size
- /// of <paramref name="reason"/> is greater than 123 bytes.
- /// </remarks>
- /// <param name="code">
- /// One of the <see cref="CloseStatusCode"/> enum values, represents the status code
- /// indicating the reason for the close.
- /// </param>
- /// <param name="reason">
- /// A <see cref="string"/> that represents the reason for the close.
- /// </param>
- public void Close(CloseStatusCode code, string reason)
- {
- byte[] data = null;
- var msg = _readyState.CheckIfClosable() ??
- (data = ((ushort)code).Append(reason)).CheckIfValidControlData("reason");
-
- if (msg != null)
- {
- error(msg);
-
- return;
- }
-
- var send = _readyState == WebSocketState.Open && !code.IsReserved();
- close(new PayloadData(data), send, send);
- }
-
- /// <summary>
- /// Sends a binary <paramref name="data"/> asynchronously using the WebSocket connection.
- /// </summary>
- /// <remarks>
- /// This method doesn't wait for the send to be complete.
- /// </remarks>
- /// <param name="data">
- /// An array of <see cref="byte"/> that represents the binary data to send.
- /// </param>
- public Task SendAsync(byte[] data)
- {
- if (data == null)
- {
- throw new ArgumentNullException(nameof(data));
- }
-
- var msg = _readyState.CheckIfOpen();
- if (msg != null)
- {
- throw new Exception(msg);
- }
-
- return sendAsync(Opcode.Binary, new MemoryStream(data));
- }
-
- /// <summary>
- /// Sends a text <paramref name="data"/> asynchronously using the WebSocket connection.
- /// </summary>
- /// <remarks>
- /// This method doesn't wait for the send to be complete.
- /// </remarks>
- /// <param name="data">
- /// A <see cref="string"/> that represents the text data to send.
- /// </param>
- public Task SendAsync(string data)
- {
- if (data == null)
- {
- throw new ArgumentNullException(nameof(data));
- }
-
- var msg = _readyState.CheckIfOpen();
- if (msg != null)
- {
- throw new Exception(msg);
- }
-
- return sendAsync(Opcode.Text, new MemoryStream(Encoding.UTF8.GetBytes(data)));
- }
-
- #endregion
-
- #region Explicit Interface Implementation
-
- /// <summary>
- /// Closes the WebSocket connection, and releases all associated resources.
- /// </summary>
- /// <remarks>
- /// This method closes the WebSocket connection with <see cref="CloseStatusCode.Away"/>.
- /// </remarks>
- void IDisposable.Dispose()
- {
- Close(CloseStatusCode.Away, null);
- }
-
- #endregion
- }
-}
diff --git a/SocketHttpListener/WebSocketException.cs b/SocketHttpListener/WebSocketException.cs
deleted file mode 100644
index e86c46d0f..000000000
--- a/SocketHttpListener/WebSocketException.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using System;
-
-namespace SocketHttpListener
-{
- /// <summary>
- /// The exception that is thrown when a <see cref="WebSocket"/> gets a fatal error.
- /// </summary>
- public class WebSocketException : Exception
- {
- #region Internal Constructors
-
- internal WebSocketException()
- : this(CloseStatusCode.Abnormal, null, null)
- {
- }
-
- internal WebSocketException(string message)
- : this(CloseStatusCode.Abnormal, message, null)
- {
- }
-
- internal WebSocketException(CloseStatusCode code)
- : this(code, null, null)
- {
- }
-
- internal WebSocketException(string message, Exception innerException)
- : this(CloseStatusCode.Abnormal, message, innerException)
- {
- }
-
- internal WebSocketException(CloseStatusCode code, string message)
- : this(code, message, null)
- {
- }
-
- internal WebSocketException(CloseStatusCode code, string message, Exception innerException)
- : base(message ?? code.GetMessage(), innerException)
- {
- Code = code;
- }
-
- #endregion
-
- #region Public Properties
-
- /// <summary>
- /// Gets the status code indicating the cause for the exception.
- /// </summary>
- /// <value>
- /// One of the <see cref="CloseStatusCode"/> enum values, represents the status code indicating
- /// the cause for the exception.
- /// </value>
- public CloseStatusCode Code
- {
- get; private set;
- }
-
- #endregion
- }
-}
diff --git a/SocketHttpListener/WebSocketFrame.cs b/SocketHttpListener/WebSocketFrame.cs
deleted file mode 100644
index 74ed23c45..000000000
--- a/SocketHttpListener/WebSocketFrame.cs
+++ /dev/null
@@ -1,433 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.IO;
-
-namespace SocketHttpListener
-{
- internal class WebSocketFrame : IEnumerable<byte>
- {
- #region Private Fields
-
- private byte[] _extPayloadLength;
- private Fin _fin;
- private Mask _mask;
- private byte[] _maskingKey;
- private Opcode _opcode;
- private PayloadData _payloadData;
- private byte _payloadLength;
- private Rsv _rsv1;
- private Rsv _rsv2;
- private Rsv _rsv3;
-
- #endregion
-
- #region Internal Fields
-
- internal static readonly byte[] EmptyUnmaskPingData;
-
- #endregion
-
- #region Static Constructor
-
- static WebSocketFrame()
- {
- EmptyUnmaskPingData = CreatePingFrame(Mask.Unmask).ToByteArray();
- }
-
- #endregion
-
- #region Private Constructors
-
- private WebSocketFrame()
- {
- }
-
- #endregion
-
- #region Internal Constructors
-
- internal WebSocketFrame(Opcode opcode, PayloadData payload)
- : this(Fin.Final, opcode, Mask.Mask, payload, false)
- {
- }
-
- internal WebSocketFrame(Opcode opcode, Mask mask, PayloadData payload)
- : this(Fin.Final, opcode, mask, payload, false)
- {
- }
-
- internal WebSocketFrame(Fin fin, Opcode opcode, Mask mask, PayloadData payload)
- : this(fin, opcode, mask, payload, false)
- {
- }
-
- internal WebSocketFrame(
- Fin fin, Opcode opcode, Mask mask, PayloadData payload, bool compressed)
- {
- _fin = fin;
- _rsv1 = isData(opcode) && compressed ? Rsv.On : Rsv.Off;
- _rsv2 = Rsv.Off;
- _rsv3 = Rsv.Off;
- _opcode = opcode;
- _mask = mask;
-
- var len = payload.Length;
- if (len < 126)
- {
- _payloadLength = (byte)len;
- _extPayloadLength = new byte[0];
- }
- else if (len < 0x010000)
- {
- _payloadLength = (byte)126;
- _extPayloadLength = ((ushort)len).ToByteArrayInternally(ByteOrder.Big);
- }
- else
- {
- _payloadLength = (byte)127;
- _extPayloadLength = len.ToByteArrayInternally(ByteOrder.Big);
- }
-
- if (mask == Mask.Mask)
- {
- _maskingKey = createMaskingKey();
- payload.Mask(_maskingKey);
- }
- else
- {
- _maskingKey = new byte[0];
- }
-
- _payloadData = payload;
- }
-
- #endregion
-
- #region Public Properties
-
- public byte[] ExtendedPayloadLength => _extPayloadLength;
-
- public Fin Fin => _fin;
-
- public bool IsBinary => _opcode == Opcode.Binary;
-
- public bool IsClose => _opcode == Opcode.Close;
-
- public bool IsCompressed => _rsv1 == Rsv.On;
-
- public bool IsContinuation => _opcode == Opcode.Cont;
-
- public bool IsControl => _opcode == Opcode.Close || _opcode == Opcode.Ping || _opcode == Opcode.Pong;
-
- public bool IsData => _opcode == Opcode.Binary || _opcode == Opcode.Text;
-
- public bool IsFinal => _fin == Fin.Final;
-
- public bool IsFragmented => _fin == Fin.More || _opcode == Opcode.Cont;
-
- public bool IsMasked => _mask == Mask.Mask;
-
- public bool IsPerMessageCompressed => (_opcode == Opcode.Binary || _opcode == Opcode.Text) && _rsv1 == Rsv.On;
-
- public bool IsPing => _opcode == Opcode.Ping;
-
- public bool IsPong => _opcode == Opcode.Pong;
-
- public bool IsText => _opcode == Opcode.Text;
-
- public ulong Length => 2 + (ulong)(_extPayloadLength.Length + _maskingKey.Length) + _payloadData.Length;
-
- public Mask Mask => _mask;
-
- public byte[] MaskingKey => _maskingKey;
-
- public Opcode Opcode => _opcode;
-
- public PayloadData PayloadData => _payloadData;
-
- public byte PayloadLength => _payloadLength;
-
- public Rsv Rsv1 => _rsv1;
-
- public Rsv Rsv2 => _rsv2;
-
- public Rsv Rsv3 => _rsv3;
-
- #endregion
-
- #region Private Methods
-
- private byte[] createMaskingKey()
- {
- var key = new byte[4];
- var rand = new Random();
- rand.NextBytes(key);
-
- return key;
- }
-
- private static bool isControl(Opcode opcode)
- {
- return opcode == Opcode.Close || opcode == Opcode.Ping || opcode == Opcode.Pong;
- }
-
- private static bool isData(Opcode opcode)
- {
- return opcode == Opcode.Text || opcode == Opcode.Binary;
- }
-
- private static WebSocketFrame read(byte[] header, Stream stream, bool unmask)
- {
- /* Header */
-
- // FIN
- var fin = (header[0] & 0x80) == 0x80 ? Fin.Final : Fin.More;
- // RSV1
- var rsv1 = (header[0] & 0x40) == 0x40 ? Rsv.On : Rsv.Off;
- // RSV2
- var rsv2 = (header[0] & 0x20) == 0x20 ? Rsv.On : Rsv.Off;
- // RSV3
- var rsv3 = (header[0] & 0x10) == 0x10 ? Rsv.On : Rsv.Off;
- // Opcode
- var opcode = (Opcode)(header[0] & 0x0f);
- // MASK
- var mask = (header[1] & 0x80) == 0x80 ? Mask.Mask : Mask.Unmask;
- // Payload Length
- var payloadLen = (byte)(header[1] & 0x7f);
-
- // Check if correct frame.
- var incorrect = isControl(opcode) && fin == Fin.More
- ? "A control frame is fragmented."
- : !isData(opcode) && rsv1 == Rsv.On
- ? "A non data frame is compressed."
- : null;
-
- if (incorrect != null)
- throw new WebSocketException(CloseStatusCode.IncorrectData, incorrect);
-
- // Check if consistent frame.
- if (isControl(opcode) && payloadLen > 125)
- throw new WebSocketException(
- CloseStatusCode.InconsistentData,
- "The length of payload data of a control frame is greater than 125 bytes.");
-
- var frame = new WebSocketFrame();
- frame._fin = fin;
- frame._rsv1 = rsv1;
- frame._rsv2 = rsv2;
- frame._rsv3 = rsv3;
- frame._opcode = opcode;
- frame._mask = mask;
- frame._payloadLength = payloadLen;
-
- /* Extended Payload Length */
-
- var size = payloadLen < 126
- ? 0
- : payloadLen == 126
- ? 2
- : 8;
-
- var extPayloadLen = size > 0 ? stream.ReadBytes(size) : new byte[0];
- if (size > 0 && extPayloadLen.Length != size)
- throw new WebSocketException(
- "The 'Extended Payload Length' of a frame cannot be read from the data source.");
-
- frame._extPayloadLength = extPayloadLen;
-
- /* Masking Key */
-
- var masked = mask == Mask.Mask;
- var maskingKey = masked ? stream.ReadBytes(4) : new byte[0];
- if (masked && maskingKey.Length != 4)
- throw new WebSocketException(
- "The 'Masking Key' of a frame cannot be read from the data source.");
-
- frame._maskingKey = maskingKey;
-
- /* Payload Data */
-
- ulong len = payloadLen < 126
- ? payloadLen
- : payloadLen == 126
- ? extPayloadLen.ToUInt16(ByteOrder.Big)
- : extPayloadLen.ToUInt64(ByteOrder.Big);
-
- byte[] data = null;
- if (len > 0)
- {
- // Check if allowable payload data length.
- if (payloadLen > 126 && len > PayloadData.MaxLength)
- throw new WebSocketException(
- CloseStatusCode.TooBig,
- "The length of 'Payload Data' of a frame is greater than the allowable length.");
-
- data = payloadLen > 126
- ? stream.ReadBytes((long)len, 1024)
- : stream.ReadBytes((int)len);
-
- //if (data.LongLength != (long)len)
- // throw new WebSocketException(
- // "The 'Payload Data' of a frame cannot be read from the data source.");
- }
- else
- {
- data = new byte[0];
- }
-
- var payload = new PayloadData(data, masked);
- if (masked && unmask)
- {
- payload.Mask(maskingKey);
- frame._mask = Mask.Unmask;
- frame._maskingKey = new byte[0];
- }
-
- frame._payloadData = payload;
- return frame;
- }
-
- #endregion
-
- #region Internal Methods
-
- internal static WebSocketFrame CreateCloseFrame(Mask mask, byte[] data)
- {
- return new WebSocketFrame(Opcode.Close, mask, new PayloadData(data));
- }
-
- internal static WebSocketFrame CreateCloseFrame(Mask mask, PayloadData payload)
- {
- return new WebSocketFrame(Opcode.Close, mask, payload);
- }
-
- internal static WebSocketFrame CreateCloseFrame(Mask mask, CloseStatusCode code, string reason)
- {
- return new WebSocketFrame(
- Opcode.Close, mask, new PayloadData(((ushort)code).Append(reason)));
- }
-
- internal static WebSocketFrame CreatePingFrame(Mask mask)
- {
- return new WebSocketFrame(Opcode.Ping, mask, new PayloadData());
- }
-
- internal static WebSocketFrame CreatePingFrame(Mask mask, byte[] data)
- {
- return new WebSocketFrame(Opcode.Ping, mask, new PayloadData(data));
- }
-
- internal static WebSocketFrame CreatePongFrame(Mask mask, PayloadData payload)
- {
- return new WebSocketFrame(Opcode.Pong, mask, payload);
- }
-
- internal static WebSocketFrame CreateWebSocketFrame(
- Fin fin, Opcode opcode, Mask mask, byte[] data, bool compressed)
- {
- return new WebSocketFrame(fin, opcode, mask, new PayloadData(data), compressed);
- }
-
- internal static WebSocketFrame Read(Stream stream)
- {
- return Read(stream, true);
- }
-
- internal static WebSocketFrame Read(Stream stream, bool unmask)
- {
- var header = stream.ReadBytes(2);
- if (header.Length != 2)
- throw new WebSocketException(
- "The header part of a frame cannot be read from the data source.");
-
- return read(header, stream, unmask);
- }
-
- internal static async void ReadAsync(
- Stream stream, bool unmask, Action<WebSocketFrame> completed, Action<Exception> error)
- {
- try
- {
- var header = await stream.ReadBytesAsync(2).ConfigureAwait(false);
- if (header.Length != 2)
- throw new WebSocketException(
- "The header part of a frame cannot be read from the data source.");
-
- var frame = read(header, stream, unmask);
- if (completed != null)
- completed(frame);
- }
- catch (Exception ex)
- {
- if (error != null)
- {
- error(ex);
- }
- }
- }
-
- #endregion
-
- #region Public Methods
-
- public IEnumerator<byte> GetEnumerator()
- {
- foreach (var b in ToByteArray())
- yield return b;
- }
-
- public void Print(bool dumped)
- {
- //Console.WriteLine(dumped ? dump(this) : print(this));
- }
-
- public byte[] ToByteArray()
- {
- using (var buff = new MemoryStream())
- {
- var header = (int)_fin;
- header = (header << 1) + (int)_rsv1;
- header = (header << 1) + (int)_rsv2;
- header = (header << 1) + (int)_rsv3;
- header = (header << 4) + (int)_opcode;
- header = (header << 1) + (int)_mask;
- header = (header << 7) + (int)_payloadLength;
- buff.Write(((ushort)header).ToByteArrayInternally(ByteOrder.Big), 0, 2);
-
- if (_payloadLength > 125)
- buff.Write(_extPayloadLength, 0, _extPayloadLength.Length);
-
- if (_mask == Mask.Mask)
- buff.Write(_maskingKey, 0, _maskingKey.Length);
-
- if (_payloadLength > 0)
- {
- var payload = _payloadData.ToByteArray();
- if (_payloadLength < 127)
- buff.Write(payload, 0, payload.Length);
- else
- buff.WriteBytes(payload);
- }
-
- return buff.ToArray();
- }
- }
-
- public override string ToString()
- {
- return BitConverter.ToString(ToByteArray());
- }
-
- #endregion
-
- #region Explicitly Implemented Interface Members
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- #endregion
- }
-}
diff --git a/build b/build
index 3b4167dae..51d4b79a2 100755
--- a/build
+++ b/build
@@ -26,7 +26,7 @@ usage() {
echo -e " $ build [-k/--keep-artifacts] [-b/--web-branch <web_branch>] <platform> <action>"
echo -e ""
echo -e "The 'keep-artifacts' option preserves build artifacts, e.g. Docker images for system package builds."
- echo -e "The web_branch defaults to the same branch name as the current main branch."
+ echo -e "The web_branch defaults to the same branch name as the current main branch or can be 'local' to not touch the submodule branching."
echo -e "To build all platforms, use 'all'."
echo -e "To perform all build actions, use 'all'."
echo -e "Build output files are collected at '../jellyfin-build/<platform>'."
@@ -164,37 +164,39 @@ for target_platform in ${platform[@]}; do
fi
done
-# Initialize submodules
-git submodule update --init --recursive
+if [[ ${web_branch} != 'local' ]]; then
+ # Initialize submodules
+ git submodule update --init --recursive
-# configure branch
-pushd MediaBrowser.WebDashboard/jellyfin-web
+ # configure branch
+ pushd MediaBrowser.WebDashboard/jellyfin-web
-if ! git diff-index --quiet HEAD --; then
- popd
- echo
- echo "ERROR: Your 'jellyfin-web' submodule working directory is not clean!"
- echo "This script will overwrite your unstaged and unpushed changes."
- echo "Please do development on 'jellyfin-web' outside of the submodule."
- exit 1
-fi
-
-git fetch --all
-# If this is an official branch name, fetch it from origin
-official_branches_regex="^master$|^dev$|^release-.*$|^hotfix-.*$"
-if [[ ${web_branch} =~ ${official_branches_regex} ]]; then
- git checkout origin/${web_branch} || {
- echo "ERROR: 'jellyfin-web' branch 'origin/${web_branch}' is invalid."
+ if ! git diff-index --quiet HEAD --; then
+ popd
+ echo
+ echo "ERROR: Your 'jellyfin-web' submodule working directory is not clean!"
+ echo "This script will overwrite your unstaged and unpushed changes."
+ echo "Please do development on 'jellyfin-web' outside of the submodule."
exit 1
- }
-# Otherwise, just check out the local branch (for testing, etc.)
-else
- git checkout ${web_branch} || {
- echo "ERROR: 'jellyfin-web' branch '${web_branch}' is invalid."
- exit 1
- }
+ fi
+
+ git fetch --all
+ # If this is an official branch name, fetch it from origin
+ official_branches_regex="^master$|^dev$|^release-.*$|^hotfix-.*$"
+ if [[ ${web_branch} =~ ${official_branches_regex} ]]; then
+ git checkout origin/${web_branch} || {
+ echo "ERROR: 'jellyfin-web' branch 'origin/${web_branch}' is invalid."
+ exit 1
+ }
+ # Otherwise, just check out the local branch (for testing, etc.)
+ else
+ git checkout ${web_branch} || {
+ echo "ERROR: 'jellyfin-web' branch '${web_branch}' is invalid."
+ exit 1
+ }
+ fi
+ popd
fi
-popd
# Execute each platform and action in order, if said action is enabled
pushd deployment/
@@ -217,7 +219,7 @@ for target_platform in ${platform[@]}; do
done
if [[ -d pkg-dist/ ]]; then
echo -e ">> Collecting build artifacts"
- target_dir="../../../jellyfin-build/${target_platform}"
+ target_dir="../../../bin/${target_platform}"
mkdir -p ${target_dir}
mv pkg-dist/* ${target_dir}/
fi
diff --git a/build.yaml b/build.yaml
new file mode 100644
index 000000000..b0d2502d5
--- /dev/null
+++ b/build.yaml
@@ -0,0 +1,15 @@
+---
+# We just wrap `build` so this is really it
+name: "jellyfin"
+version: "10.2.2"
+packages:
+ - debian-package-x64
+ - debian-package-armhf
+ - ubuntu-package-x64
+ - fedora-package-x64
+ - centos-package-x64
+ - linux-x64
+ - macos
+ - portable
+ - win-x64
+ - win-x86
diff --git a/deployment/common.build.sh b/deployment/common.build.sh
index c191ec2a1..d028e3a66 100755
--- a/deployment/common.build.sh
+++ b/deployment/common.build.sh
@@ -15,7 +15,6 @@ DEFAULT_CONFIG="Release"
DEFAULT_OUTPUT_DIR="dist/jellyfin-git"
DEFAULT_PKG_DIR="pkg-dist"
DEFAULT_DOCKERFILE="Dockerfile"
-DEFAULT_IMAGE_TAG="jellyfin:"`git rev-parse --abbrev-ref HEAD`
DEFAULT_ARCHIVE_CMD="tar -xvzf"
# Parse the version from the AssemblyVersion
@@ -36,9 +35,9 @@ build_jellyfin()
echo -e "${CYAN}Building jellyfin in '${ROOT}' for ${DOTNETRUNTIME} with configuration ${CONFIG} and output directory '${OUTPUT_DIR}'.${NC}"
if [[ $DOTNETRUNTIME == 'framework' ]]; then
- dotnet publish "${ROOT}" --configuration "${CONFIG}" --output="${OUTPUT_DIR}"
+ dotnet publish "${ROOT}" --configuration "${CONFIG}" --output="${OUTPUT_DIR}" "-p:GenerateDocumentationFile=false;DebugSymbols=false;DebugType=none"
else
- dotnet publish "${ROOT}" --configuration "${CONFIG}" --output="${OUTPUT_DIR}" --self-contained --runtime ${DOTNETRUNTIME}
+ dotnet publish "${ROOT}" --configuration "${CONFIG}" --output="${OUTPUT_DIR}" --self-contained --runtime ${DOTNETRUNTIME} "-p:GenerateDocumentationFile=false;DebugSymbols=false;DebugType=none"
fi
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
@@ -53,7 +52,7 @@ build_jellyfin_docker()
(
BUILD_CONTEXT=${1-$DEFAULT_BUILD_CONTEXT}
DOCKERFILE=${2-$DEFAULT_DOCKERFILE}
- IMAGE_TAG=${3-$DEFAULT_IMAGE_TAG}
+ IMAGE_TAG=${3-"jellyfin:$(git rev-parse --abbrev-ref HEAD)"}
echo -e "${CYAN}Building jellyfin docker image in '${BUILD_CONTEXT}' with Dockerfile '${DOCKERFILE}' and tag '${IMAGE_TAG}'.${NC}"
docker build -t ${IMAGE_TAG} -f ${DOCKERFILE} ${BUILD_CONTEXT}
diff --git a/deployment/debian-package-armhf/Dockerfile.amd64 b/deployment/debian-package-armhf/Dockerfile.amd64
new file mode 100644
index 000000000..0d62352e0
--- /dev/null
+++ b/deployment/debian-package-armhf/Dockerfile.amd64
@@ -0,0 +1,42 @@
+FROM debian:9
+# Docker build arguments
+ARG SOURCE_DIR=/jellyfin
+ARG PLATFORM_DIR=/jellyfin/deployment/debian-package-armhf
+ARG ARTIFACT_DIR=/dist
+ARG SDK_VERSION=2.2
+# Docker run environment
+ENV SOURCE_DIR=/jellyfin
+ENV ARTIFACT_DIR=/dist
+ENV DEB_BUILD_OPTIONS=noddebs
+ENV ARCH=amd64
+
+# Prepare Debian build environment
+RUN apt-get update \
+ && apt-get install -y apt-transport-https debhelper gnupg wget devscripts mmv
+
+# Install dotnet repository
+# https://dotnet.microsoft.com/download/linux-package-manager/debian9/sdk-current
+RUN wget https://download.visualstudio.microsoft.com/download/pr/69937b49-a877-4ced-81e6-286620b390ab/8ab938cf6f5e83b2221630354160ef21/dotnet-sdk-2.2.104-linux-x64.tar.gz -O dotnet-sdk.tar.gz \
+ && mkdir -p dotnet-sdk \
+ && tar -xzf dotnet-sdk.tar.gz -C dotnet-sdk \
+ && ln -s $( pwd )/dotnet-sdk/dotnet /usr/bin/dotnet
+
+# Prepare the cross-toolchain
+RUN dpkg --add-architecture armhf \
+ && apt-get update \
+ && apt-get install -y cross-gcc-dev \
+ && TARGET_LIST="armhf" cross-gcc-gensource 6 \
+ && cd cross-gcc-packages-amd64/cross-gcc-6-armhf \
+ && apt-get install -y gcc-6-source libstdc++6-armhf-cross binutils-arm-linux-gnueabihf bison flex libtool gdb sharutils netbase libcloog-isl-dev libmpc-dev libmpfr-dev libgmp-dev systemtap-sdt-dev autogen expect chrpath zlib1g-dev zip libc6-dev:armhf linux-libc-dev:armhf libgcc1:armhf libcurl4-openssl-dev:armhf libfontconfig1-dev:armhf libfreetype6-dev:armhf liblttng-ust0:armhf libstdc++6:armhf
+
+# Link to docker-build script
+RUN ln -sf ${PLATFORM_DIR}/docker-build.sh /docker-build.sh
+
+# Link to Debian source dir; mkdir needed or it fails, can't force dest
+RUN mkdir -p ${SOURCE_DIR} && ln -sf ${PLATFORM_DIR}/pkg-src ${SOURCE_DIR}/debian
+
+VOLUME ${ARTIFACT_DIR}/
+
+COPY . ${SOURCE_DIR}/
+
+ENTRYPOINT ["/docker-build.sh"]
diff --git a/deployment/debian-package-armhf/Dockerfile.armhf b/deployment/debian-package-armhf/Dockerfile.armhf
new file mode 100644
index 000000000..eb4152116
--- /dev/null
+++ b/deployment/debian-package-armhf/Dockerfile.armhf
@@ -0,0 +1,34 @@
+FROM debian:9
+# Docker build arguments
+ARG SOURCE_DIR=/jellyfin
+ARG PLATFORM_DIR=/jellyfin/deployment/debian-package-armhf
+ARG ARTIFACT_DIR=/dist
+ARG SDK_VERSION=2.2
+# Docker run environment
+ENV SOURCE_DIR=/jellyfin
+ENV ARTIFACT_DIR=/dist
+ENV DEB_BUILD_OPTIONS=noddebs
+ENV ARCH=armhf
+
+# Prepare Debian build environment
+RUN apt-get update \
+ && apt-get install -y apt-transport-https debhelper gnupg wget devscripts mmv libc6-dev libcurl4-openssl-dev libfontconfig1-dev libfreetype6-dev liblttng-ust0
+
+# Install dotnet repository
+# https://dotnet.microsoft.com/download/linux-package-manager/debian9/sdk-current
+RUN wget https://download.visualstudio.microsoft.com/download/pr/d9f37b73-df8d-4dfa-a905-b7648d3401d0/6312573ac13d7a8ddc16e4058f7d7dc5/dotnet-sdk-2.2.104-linux-arm.tar.gz -O dotnet-sdk.tar.gz \
+ && mkdir -p dotnet-sdk \
+ && tar -xzf dotnet-sdk.tar.gz -C dotnet-sdk \
+ && ln -s $( pwd )/dotnet-sdk/dotnet /usr/bin/dotnet
+
+# Link to docker-build script
+RUN ln -sf ${PLATFORM_DIR}/docker-build.sh /docker-build.sh
+
+# Link to Debian source dir; mkdir needed or it fails, can't force dest
+RUN mkdir -p ${SOURCE_DIR} && ln -sf ${PLATFORM_DIR}/pkg-src ${SOURCE_DIR}/debian
+
+VOLUME ${ARTIFACT_DIR}/
+
+COPY . ${SOURCE_DIR}/
+
+ENTRYPOINT ["/docker-build.sh"]
diff --git a/deployment/debian-package-armhf/clean.sh b/deployment/debian-package-armhf/clean.sh
new file mode 100755
index 000000000..3898110af
--- /dev/null
+++ b/deployment/debian-package-armhf/clean.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+
+source ../common.build.sh
+
+keep_artifacts="${1}"
+
+WORKDIR="$( pwd )"
+
+package_temporary_dir="${WORKDIR}/pkg-dist-tmp"
+output_dir="${WORKDIR}/pkg-dist"
+current_user="$( whoami )"
+image_name="jellyfin-debian_armhf-build"
+
+rm -rf "${package_temporary_dir}" &>/dev/null \
+ || sudo rm -rf "${package_temporary_dir}" &>/dev/null
+
+rm -rf "${output_dir}" &>/dev/null \
+ || sudo rm -rf "${output_dir}" &>/dev/null
+
+if [[ ${keep_artifacts} == 'n' ]]; then
+ docker_sudo=""
+ if [[ ! -z $(id -Gn | grep -q 'docker') ]] \
+ && [[ ! ${EUID:-1000} -eq 0 ]] \
+ && [[ ! ${USER} == "root" ]] \
+ && [[ ! -z $( echo "${OSTYPE}" | grep -q "darwin" ) ]]; then
+ docker_sudo=sudo
+ fi
+ ${docker_sudo} docker image rm ${image_name} --force
+fi
diff --git a/deployment/debian-package-armhf/dependencies.txt b/deployment/debian-package-armhf/dependencies.txt
new file mode 100644
index 000000000..bdb967096
--- /dev/null
+++ b/deployment/debian-package-armhf/dependencies.txt
@@ -0,0 +1 @@
+docker
diff --git a/deployment/debian-package-armhf/docker-build.sh b/deployment/debian-package-armhf/docker-build.sh
new file mode 100755
index 000000000..45e68f0c6
--- /dev/null
+++ b/deployment/debian-package-armhf/docker-build.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Builds the DEB inside the Docker container
+
+set -o errexit
+set -o xtrace
+
+# Move to source directory
+pushd ${SOURCE_DIR}
+
+# Remove build-dep for dotnet-sdk-2.2, since it's not a package in this image
+sed -i '/dotnet-sdk-2.2,/d' debian/control
+
+# Build DEB
+export CONFIG_SITE=/etc/dpkg-cross/cross-config.${ARCH}
+dpkg-buildpackage -us -uc -aarmhf
+
+# Move the artifacts out
+mkdir -p ${ARTIFACT_DIR}/deb
+mv /jellyfin_* ${ARTIFACT_DIR}/deb/
diff --git a/deployment/debian-package-armhf/package.sh b/deployment/debian-package-armhf/package.sh
new file mode 100755
index 000000000..0ec0dc95c
--- /dev/null
+++ b/deployment/debian-package-armhf/package.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+
+source ../common.build.sh
+
+ARCH="$( arch )"
+WORKDIR="$( pwd )"
+
+package_temporary_dir="${WORKDIR}/pkg-dist-tmp"
+output_dir="${WORKDIR}/pkg-dist"
+current_user="$( whoami )"
+image_name="jellyfin-debian_armhf-build"
+
+# Determine if sudo should be used for Docker
+if [[ ! -z $(id -Gn | grep -q 'docker') ]] \
+ && [[ ! ${EUID:-1000} -eq 0 ]] \
+ && [[ ! ${USER} == "root" ]] \
+ && [[ ! -z $( echo "${OSTYPE}" | grep -q "darwin" ) ]]; then
+ docker_sudo="sudo"
+else
+ docker_sudo=""
+fi
+
+# Determine which Dockerfile to use
+case $ARCH in
+ 'x86_64')
+ DOCKERFILE="Dockerfile.amd64"
+ ;;
+ 'armv7l')
+ DOCKERFILE="Dockerfile.armhf"
+ ;;
+esac
+
+# Set up the build environment Docker image
+${docker_sudo} docker build ../.. -t "${image_name}" -f ./${DOCKERFILE}
+# Build the DEBs and copy out to ${package_temporary_dir}
+${docker_sudo} docker run --rm -v "${package_temporary_dir}:/dist" "${image_name}"
+# Correct ownership on the DEBs (as current user, then as root if that fails)
+chown -R "${current_user}" "${package_temporary_dir}" &>/dev/null \
+ || sudo chown -R "${current_user}" "${package_temporary_dir}" &>/dev/null
+# Move the DEBs to the output directory
+mkdir -p "${output_dir}"
+mv "${package_temporary_dir}"/deb/* "${output_dir}"
diff --git a/deployment/debian-package-armhf/pkg-src b/deployment/debian-package-armhf/pkg-src
new file mode 120000
index 000000000..4c695fea1
--- /dev/null
+++ b/deployment/debian-package-armhf/pkg-src
@@ -0,0 +1 @@
+../debian-package-x64/pkg-src \ No newline at end of file
diff --git a/deployment/debian-package-x64/pkg-src/changelog b/deployment/debian-package-x64/pkg-src/changelog
index 869dc4a5e..349e8787f 100644
--- a/deployment/debian-package-x64/pkg-src/changelog
+++ b/deployment/debian-package-x64/pkg-src/changelog
@@ -1,3 +1,36 @@
+jellyfin (10.2.2-1) unstable; urgency=medium
+
+ * jellyfin:
+ * PR968 Release 10.2.z copr autobuild
+ * PR964 Install the dotnet runtime package in Fedora build
+ * PR979 Build Package releases without debug turned on
+ * PR990 Fix slow local image validation
+ * PR991 Fix the ffmpeg compatibility
+ * PR992 Add Debian armhf (Raspberry Pi) build plus crossbuild
+ * PR998 Set EnableRaisingEvents to true for processes that require it
+ * PR1017 Set ffmpeg+ffprobe paths in Docker container
+ * jellyfin-web:
+ * PR152 Go back on Media stop
+ * PR156 Fix volume slider not working on nowplayingbar
+
+ -- Jellyfin Packaging Team <packaging@jellyfin.org> Thu, 28 Feb 2019 15:32:16 -0500
+
+jellyfin (10.2.1-1) unstable; urgency=medium
+
+ * jellyfin:
+ * PR920 Fix cachedir missing from Docker container
+ * PR924 Use the movie name instead of folder name
+ * PR933 Semi-revert to prefer old movie grouping behaviour
+ * PR948 Revert movie matching (supercedes PR933, PR924, PR739)
+ * PR960 Use jellyfin/ffmpeg image
+ * jellyfin-web:
+ * PR136 Re-add OpenSubtitles configuration page
+ * PR137 Replace HeaderEmbyServer with HeaderJellyfinServer on plugincatalog
+ * PR138 Remove left-over JS for Customize Home Screen
+ * PR141 Exit fullscreen automatically after video playback ends
+
+ -- Jellyfin Packaging Team <packaging@jellyfin.org> Wed, 20 Feb 2019 11:36:16 -0500
+
jellyfin (10.2.0-2) unstable; urgency=medium
* jellyfin:
diff --git a/deployment/debian-package-x64/pkg-src/conf/jellyfin b/deployment/debian-package-x64/pkg-src/conf/jellyfin
index b052b2ec6..bc00c37e2 100644
--- a/deployment/debian-package-x64/pkg-src/conf/jellyfin
+++ b/deployment/debian-package-x64/pkg-src/conf/jellyfin
@@ -13,17 +13,16 @@
#
# Program directories
-JELLYFIN_DATA_DIRECTORY="/var/lib/jellyfin"
-JELLYFIN_CONFIG_DIRECTORY="/etc/jellyfin"
-JELLYFIN_LOG_DIRECTORY="/var/log/jellyfin"
-JELLYFIN_CACHE_DIRECTORY="/var/cache/jellyfin"
+JELLYFIN_DATA_DIR="/var/lib/jellyfin"
+JELLYFIN_CONFIG_DIR="/etc/jellyfin"
+JELLYFIN_LOG_DIR="/var/log/jellyfin"
+JELLYFIN_CACHE_DIR="/var/cache/jellyfin"
# Restart script for in-app server control
JELLYFIN_RESTART_OPT="--restartpath=/usr/lib/jellyfin/restart.sh"
-# [OPTIONAL] ffmpeg binary paths, overriding the UI-configured values
-#JELLYFIN_FFMPEG_OPT="--ffmpeg=/usr/bin/ffmpeg"
-#JELLYFIN_FFPROBE_OPT="--ffprobe=/usr/bin/ffprobe"
+# ffmpeg binary paths, overriding the system values
+JELLYFIN_FFMPEG_OPT="--ffmpeg=/usr/share/jellyfin-ffmpeg/ffmpeg"
# [OPTIONAL] run Jellyfin as a headless service
#JELLYFIN_SERVICE_OPT="--service"
@@ -38,4 +37,4 @@ JELLYFIN_RESTART_OPT="--restartpath=/usr/lib/jellyfin/restart.sh"
# Application username
JELLYFIN_USER="jellyfin"
# Full application command
-JELLYFIN_ARGS="--datadir=$JELLYFIN_DATA_DIRECTORY --configdir=$JELLYFIN_CONFIG_DIRECTORY --logdir=$JELLYFIN_LOG_DIRECTORY --cachedir=$JELLYFIN_CACHE_DIRECTORY $JELLYFIN_RESTART_OPT $JELLYFIN_FFMPEG_OPT $JELLYFIN_FFPROBE_OPT $JELLYFIN_SERVICE_OPT $JELLFIN_NOWEBAPP_OPT"
+JELLYFIN_ARGS="$JELLYFIN_RESTART_OPT $JELLYFIN_FFMPEG_OPT $JELLYFIN_SERVICE_OPT $JELLFIN_NOWEBAPP_OPT"
diff --git a/deployment/debian-package-x64/pkg-src/control b/deployment/debian-package-x64/pkg-src/control
index 88d10438b..d96660590 100644
--- a/deployment/debian-package-x64/pkg-src/control
+++ b/deployment/debian-package-x64/pkg-src/control
@@ -20,7 +20,7 @@ Conflicts: mediabrowser, emby, emby-server-beta, jellyfin-dev, emby-server
Architecture: any
Depends: at,
libsqlite3-0,
- ffmpeg (<7:4.1) | jellyfin-ffmpeg,
+ jellyfin-ffmpeg,
libfontconfig1,
libfreetype6,
libssl1.0.0 | libssl1.0.2
diff --git a/deployment/debian-package-x64/pkg-src/jellyfin.init b/deployment/debian-package-x64/pkg-src/jellyfin.init
index d103fb0f1..7f5642bac 100644
--- a/deployment/debian-package-x64/pkg-src/jellyfin.init
+++ b/deployment/debian-package-x64/pkg-src/jellyfin.init
@@ -8,42 +8,54 @@
# Description: Runs Jellyfin Server
### END INIT INFO
+set -e
+
# Carry out specific functions when asked to by the system
-pidfile="/var/run/jellyfin.pid"
-pid=`cat $pidfile`
+if test -f /etc/default/jellyfin; then
+ . /etc/default/jellyfin
+fi
+
+. /lib/lsb/init-functions
+
+PIDFILE="/run/jellyfin.pid"
case "$1" in
start)
- if [ "$pid" == "" ]; then
- echo "Starting Jellyfin..."
- . /etc/default/jellyfin
- nohup su -u $JELLYFIN_USER -c /usr/bin/jellyfin $JELLYFIN_ARGS
- echo ?? > $pidfile
- else
- echo "Jellyfin already running"
- fi
+ log_daemon_msg "Starting Jellyfin Media Server" "jellyfin" || true
+
+ if start-stop-daemon --start --quiet --oknodo --background --pidfile $PIDFILE --make-pidfile --user $JELLYFIN_USER --chuid $JELLYFIN_USER --exec /usr/bin/jellyfin -- $JELLYFIN_ARGS; then
+ log_end_msg 0 || true
+ else
+ log_end_msg 1 || true
+ fi
;;
+
stop)
- if [ "$pid" != "" ]; then
- echo "Stopping Jellyfin..."
- kill $pid
- sleep 2
- rm -f $pidfile
- else
- echo "Jellyfin not running"
- fi
+ log_daemon_msg "Stopping Jellyfin Media Server" "jellyfin" || true
+ if start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --remove-pidfile; then
+ log_end_msg 0 || true
+ else
+ log_end_msg 1 || true
+ fi
;;
+
+ restart)
+ log_daemon_msg "Restarting Jellyfin Media Server" "jellyfin" || true
+ start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE --remove-pidfile
+ if start-stop-daemon --start --quiet --oknodo --background --pidfile $PIDFILE --make-pidfile --user $JELLYFIN_USER --chuid $JELLYFIN_USER --exec /usr/bin/jellyfin -- $JELLYFIN_ARGS; then
+ log_end_msg 0 || true
+ else
+ log_end_msg 1 || true
+ fi
+ ;;
+
status)
- if [ "$pid" != "" ]; then
- echo "Jellyfin running as $pid"
- ps -f $pid
- else
- echo "Jellyfin is not running"
- fi
+ status_of_proc -p $PIDFILE /usr/bin/jellyfin jellyfin && exit 0 || exit $?
;;
+
*)
- echo "Usage: $0 {start|stop}"
+ echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
diff --git a/deployment/debian-package-x64/pkg-src/jellyfin.service b/deployment/debian-package-x64/pkg-src/jellyfin.service
index 9c6c6667f..1305e238b 100644
--- a/deployment/debian-package-x64/pkg-src/jellyfin.service
+++ b/deployment/debian-package-x64/pkg-src/jellyfin.service
@@ -6,7 +6,7 @@ After = network.target
Type = simple
EnvironmentFile = /etc/default/jellyfin
User = jellyfin
-ExecStart = /usr/bin/jellyfin --datadir=${JELLYFIN_DATA_DIRECTORY} --configdir=${JELLYFIN_CONFIG_DIRECTORY} --logdir=${JELLYFIN_LOG_DIRECTORY} --cachedir=${JELLYFIN_CACHE_DIRECTORY} ${JELLYFIN_RESTART_OPT} ${JELLYFIN_FFMPEG_OPT} ${JELLYFIN_FFPROBE_OPT} ${JELLYFIN_SERVICE_OPT} ${JELLYFIN_NOWEBAPP_OPT}
+ExecStart = /usr/bin/jellyfin ${JELLYFIN_RESTART_OPT} ${JELLYFIN_FFMPEG_OPT} ${JELLYFIN_SERVICE_OPT} ${JELLYFIN_NOWEBAPP_OPT}
Restart = on-failure
TimeoutSec = 15
diff --git a/deployment/debian-package-x64/pkg-src/rules b/deployment/debian-package-x64/pkg-src/rules
index ce98cb8f8..62f75bc6b 100644
--- a/deployment/debian-package-x64/pkg-src/rules
+++ b/deployment/debian-package-x64/pkg-src/rules
@@ -2,7 +2,23 @@
CONFIG := Release
TERM := xterm
SHELL := /bin/bash
-DOTNETRUNTIME := debian-x64
+
+HOST_ARCH := $(shell arch)
+BUILD_ARCH := ${DEB_HOST_MULTIARCH}
+ifeq ($(HOST_ARCH),x86_64)
+ ifeq ($(BUILD_ARCH),arm-linux-gnueabihf)
+ # Cross-building ARM on AMD64
+ DOTNETRUNTIME := debian-arm
+ else
+ # Building AMD64
+ DOTNETRUNTIME := debian-x64
+ endif
+endif
+ifeq ($(HOST_ARCH),armv7l)
+ # Building ARM
+ DOTNETRUNTIME := debian-arm
+endif
+
export DH_VERBOSE=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
@@ -16,7 +32,8 @@ override_dh_auto_test:
override_dh_clistrip:
override_dh_auto_build:
- dotnet publish --configuration $(CONFIG) --output='$(CURDIR)/usr/lib/jellyfin/bin' --self-contained --runtime $(DOTNETRUNTIME) Jellyfin.Server
+ dotnet publish --configuration $(CONFIG) --output='$(CURDIR)/usr/lib/jellyfin/bin' --self-contained --runtime $(DOTNETRUNTIME) \
+ "-p:GenerateDocumentationFile=false;DebugSymbols=false;DebugType=none" Jellyfin.Server
override_dh_auto_clean:
dotnet clean -maxcpucount:1 --configuration $(CONFIG) Jellyfin.Server || true
diff --git a/deployment/debian-x64/build.sh b/deployment/debian-x64/build.sh
deleted file mode 100755
index 47cfb5327..000000000
--- a/deployment/debian-x64/build.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env bash
-
-source ../common.build.sh
-
-VERSION=`get_version ../..`
-
-build_jellyfin ../../Jellyfin.Server Release debian-x64 `pwd`/dist/jellyfin_${VERSION}
diff --git a/deployment/fedora-package-x64/Dockerfile b/deployment/fedora-package-x64/Dockerfile
index 8bb1d527d..397c944ea 100644
--- a/deployment/fedora-package-x64/Dockerfile
+++ b/deployment/fedora-package-x64/Dockerfile
@@ -13,7 +13,7 @@ RUN dnf update -y \
&& dnf install -y @buildsys-build rpmdevtools dnf-plugins-core libcurl-devel fontconfig-devel freetype-devel openssl-devel glibc-devel libicu-devel \
&& dnf copr enable -y @dotnet-sig/dotnet \
&& rpmdev-setuptree \
- && dnf install -y dotnet-sdk-${SDK_VERSION} \
+ && dnf install -y dotnet-sdk-${SDK_VERSION} dotnet-runtime-${SDK_VERSION} \
&& ln -sf ${PLATFORM_DIR}/docker-build.sh /docker-build.sh \
&& mkdir -p ${SOURCE_DIR}/SPECS \
&& ln -s ${PLATFORM_DIR}/pkg-src/jellyfin.spec ${SOURCE_DIR}/SPECS/jellyfin.spec \
diff --git a/deployment/fedora-package-x64/pkg-src/jellyfin.env b/deployment/fedora-package-x64/pkg-src/jellyfin.env
index abfa670e4..de48f13af 100644
--- a/deployment/fedora-package-x64/pkg-src/jellyfin.env
+++ b/deployment/fedora-package-x64/pkg-src/jellyfin.env
@@ -15,17 +15,16 @@
#
# Program directories
-JELLYFIN_DATA_DIRECTORY="/var/lib/jellyfin"
-JELLYFIN_CONFIG_DIRECTORY="/etc/jellyfin"
-JELLYFIN_LOG_DIRECTORY="/var/log/jellyfin"
-JELLYFIN_CACHE_DIRECTORY="/var/cache/jellyfin"
+JELLYFIN_DATA_DIR="/var/lib/jellyfin"
+JELLYFIN_CONFIG_DIR="/etc/jellyfin"
+JELLYFIN_LOG_DIR="/var/log/jellyfin"
+JELLYFIN_CACHE_DIR="/var/cache/jellyfin"
# In-App service control
JELLYFIN_RESTART_OPT="--restartpath=/usr/libexec/jellyfin/restart.sh"
# [OPTIONAL] ffmpeg binary paths, overriding the UI-configured values
#JELLYFIN_FFMPEG_OPT="--ffmpeg=/usr/bin/ffmpeg"
-#JELLYFIN_FFPROBE_OPT="--ffprobe=/usr/bin/ffprobe"
# [OPTIONAL] run Jellyfin as a headless service
#JELLYFIN_SERVICE_OPT="--service"
diff --git a/deployment/fedora-package-x64/pkg-src/jellyfin.service b/deployment/fedora-package-x64/pkg-src/jellyfin.service
index d58df9d94..f3dc594b1 100644
--- a/deployment/fedora-package-x64/pkg-src/jellyfin.service
+++ b/deployment/fedora-package-x64/pkg-src/jellyfin.service
@@ -5,7 +5,7 @@ Description=Jellyfin is a free software media system that puts you in control of
[Service]
EnvironmentFile=/etc/sysconfig/jellyfin
WorkingDirectory=/var/lib/jellyfin
-ExecStart=/usr/bin/jellyfin --datadir=${JELLYFIN_DATA_DIRECTORY} --configdir=${JELLYFIN_CONFIG_DIRECTORY} --logdir=${JELLYFIN_LOG_DIRECTORY} --cachedir=${JELLYFIN_CACHE_DIRECTORY} ${JELLYFIN_RESTART_OPT} ${JELLYFIN_FFMPEG_OPT} ${JELLYFIN_FFPROBE_OPT} ${JELLYFIN_SERVICE_OPT} ${JELLYFIN_NOWEBAPP_OPT}
+ExecStart=/usr/bin/jellyfin ${JELLYFIN_RESTART_OPT} ${JELLYFIN_FFMPEG_OPT} ${JELLYFIN_SERVICE_OPT} ${JELLYFIN_NOWEBAPP_OPT}
TimeoutSec=15
Restart=on-failure
User=jellyfin
diff --git a/deployment/fedora-package-x64/pkg-src/jellyfin.spec b/deployment/fedora-package-x64/pkg-src/jellyfin.spec
index 75821cb17..e24bd2fcb 100644
--- a/deployment/fedora-package-x64/pkg-src/jellyfin.spec
+++ b/deployment/fedora-package-x64/pkg-src/jellyfin.spec
@@ -7,8 +7,8 @@
%endif
Name: jellyfin
-Version: 10.2.0
-Release: 2%{?dist}
+Version: 10.2.2
+Release: 1%{?dist}
Summary: The Free Software Media Browser
License: GPLv2
URL: https://jellyfin.media
@@ -27,7 +27,7 @@ BuildRequires: libcurl-devel, fontconfig-devel, freetype-devel, openssl-devel,
Requires: libcurl, fontconfig, freetype, openssl, glibc libicu
# Requirements not packaged in main repos
# COPR @dotnet-sig/dotnet
-BuildRequires: dotnet-sdk-2.2
+BuildRequires: dotnet-runtime-2.2, dotnet-sdk-2.2
# RPMfusion free
Requires: ffmpeg
@@ -49,7 +49,8 @@ Jellyfin is a free software media system that puts you in control of managing an
%install
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
-dotnet publish --configuration Release --output='%{buildroot}%{_libdir}/jellyfin' --self-contained --runtime %{dotnet_runtime} Jellyfin.Server
+dotnet publish --configuration Release --output='%{buildroot}%{_libdir}/jellyfin' --self-contained --runtime %{dotnet_runtime} \
+ "-p:GenerateDocumentationFile=false;DebugSymbols=false;DebugType=none" Jellyfin.Server
%{__install} -D -m 0644 LICENSE %{buildroot}%{_datadir}/licenses/%{name}/LICENSE
%{__install} -D -m 0644 %{SOURCE5} %{buildroot}%{_sysconfdir}/systemd/system/%{name}.service.d/override.conf
%{__install} -D -m 0644 Jellyfin.Server/Resources/Configuration/logging.json %{buildroot}%{_sysconfdir}/%{name}/logging.json
@@ -73,7 +74,6 @@ EOF
%{_libdir}/%{name}/jellyfin-web/*
%attr(755,root,root) %{_bindir}/%{name}
%{_libdir}/%{name}/*.json
-%{_libdir}/%{name}/*.pdb
%{_libdir}/%{name}/*.dll
%{_libdir}/%{name}/*.so
%{_libdir}/%{name}/*.a
@@ -140,6 +140,31 @@ fi
%systemd_postun_with_restart jellyfin.service
%changelog
+* Thu Feb 28 2019 Jellyfin Packaging Team <packaging@jellyfin.org>
+- jellyfin:
+- PR968 Release 10.2.z copr autobuild
+- PR964 Install the dotnet runtime package in Fedora build
+- PR979 Build Package releases without debug turned on
+- PR990 Fix slow local image validation
+- PR991 Fix the ffmpeg compatibility
+- PR992 Add Debian armhf (Raspberry Pi) build plus crossbuild
+- PR998 Set EnableRaisingEvents to true for processes that require it
+- PR1017 Set ffmpeg+ffprobe paths in Docker container
+- jellyfin-web:
+- PR152 Go back on Media stop
+- PR156 Fix volume slider not working on nowplayingbar
+* Wed Feb 20 2019 Jellyfin Packaging Team <packaging@jellyfin.org>
+- jellyfin:
+- PR920 Fix cachedir missing from Docker container
+- PR924 Use the movie name instead of folder name
+- PR933 Semi-revert to prefer old movie grouping behaviour
+- PR948 Revert movie matching (supercedes PR933, PR924, PR739)
+- PR960 Use jellyfin/ffmpeg image
+- jellyfin-web:
+- PR136 Re-add OpenSubtitles configuration page
+- PR137 Replace HeaderEmbyServer with HeaderJellyfinServer on plugincatalog
+- PR138 Remove left-over JS for Customize Home Screen
+- PR141 Exit fullscreen automatically after video playback ends
* Fri Feb 15 2019 Jellyfin Packaging Team <packaging@jellyfin.org>
- jellyfin:
- PR452 Use EF Core for Activity database
diff --git a/deployment/osx-x64/build.sh b/deployment/macos/build.sh
index d6bfb9f5e..d6bfb9f5e 100755
--- a/deployment/osx-x64/build.sh
+++ b/deployment/macos/build.sh
diff --git a/deployment/debian-x64/clean.sh b/deployment/macos/clean.sh
index 3df2d7796..3df2d7796 100755
--- a/deployment/debian-x64/clean.sh
+++ b/deployment/macos/clean.sh
diff --git a/deployment/debian-x64/dependencies.txt b/deployment/macos/dependencies.txt
index 3d25d1bdf..3d25d1bdf 100644
--- a/deployment/debian-x64/dependencies.txt
+++ b/deployment/macos/dependencies.txt
diff --git a/deployment/debian-x64/package.sh b/deployment/macos/package.sh
index 13b943ea8..13b943ea8 100755
--- a/deployment/debian-x64/package.sh
+++ b/deployment/macos/package.sh
diff --git a/deployment/osx-x64/clean.sh b/deployment/osx-x64/clean.sh
deleted file mode 100755
index 3df2d7796..000000000
--- a/deployment/osx-x64/clean.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env bash
-
-source ../common.build.sh
-
-VERSION=`get_version ../..`
-
-clean_jellyfin ../.. Release `pwd`/dist/jellyfin_${VERSION}
diff --git a/deployment/osx-x64/package.sh b/deployment/osx-x64/package.sh
deleted file mode 100755
index 13b943ea8..000000000
--- a/deployment/osx-x64/package.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env bash
-
-source ../common.build.sh
-
-VERSION=`get_version ../..`
-
-package_portable ../.. `pwd`/dist/jellyfin_${VERSION}
diff --git a/deployment/framework/build.sh b/deployment/portable/build.sh
index 4f2e6363e..4f2e6363e 100755
--- a/deployment/framework/build.sh
+++ b/deployment/portable/build.sh
diff --git a/deployment/framework/clean.sh b/deployment/portable/clean.sh
index 3df2d7796..3df2d7796 100755
--- a/deployment/framework/clean.sh
+++ b/deployment/portable/clean.sh
diff --git a/deployment/framework/package.sh b/deployment/portable/package.sh
index 13b943ea8..13b943ea8 100755
--- a/deployment/framework/package.sh
+++ b/deployment/portable/package.sh
diff --git a/deployment/ubuntu-x64/build.sh b/deployment/ubuntu-x64/build.sh
deleted file mode 100755
index 870bac780..000000000
--- a/deployment/ubuntu-x64/build.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env bash
-
-source ../common.build.sh
-
-VERSION=`get_version ../..`
-
-build_jellyfin ../../Jellyfin.Server Release ubuntu-x64 `pwd`/dist/jellyfin_${VERSION}
diff --git a/deployment/ubuntu-x64/clean.sh b/deployment/ubuntu-x64/clean.sh
deleted file mode 100755
index 3df2d7796..000000000
--- a/deployment/ubuntu-x64/clean.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env bash
-
-source ../common.build.sh
-
-VERSION=`get_version ../..`
-
-clean_jellyfin ../.. Release `pwd`/dist/jellyfin_${VERSION}
diff --git a/deployment/ubuntu-x64/dependencies.txt b/deployment/ubuntu-x64/dependencies.txt
deleted file mode 100644
index 3d25d1bdf..000000000
--- a/deployment/ubuntu-x64/dependencies.txt
+++ /dev/null
@@ -1 +0,0 @@
-dotnet
diff --git a/deployment/ubuntu-x64/package.sh b/deployment/ubuntu-x64/package.sh
deleted file mode 100755
index 13b943ea8..000000000
--- a/deployment/ubuntu-x64/package.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env bash
-
-source ../common.build.sh
-
-VERSION=`get_version ../..`
-
-package_portable ../.. `pwd`/dist/jellyfin_${VERSION}
diff --git a/deployment/win-generic/dependencies.txt b/deployment/win-generic/dependencies.txt
deleted file mode 100644
index 3d25d1bdf..000000000
--- a/deployment/win-generic/dependencies.txt
+++ /dev/null
@@ -1 +0,0 @@
-dotnet
diff --git a/deployment/win-x64/package.sh b/deployment/win-x64/package.sh
index d21e3b532..b438c28e4 100755
--- a/deployment/win-x64/package.sh
+++ b/deployment/win-x64/package.sh
@@ -21,8 +21,8 @@ package_win64() (
cp ${TEMP_DIR}/${FFMPEG_VERSION}/bin/ffmpeg.exe ${OUTPUT_DIR}/ffmpeg.exe
cp ${TEMP_DIR}/${FFMPEG_VERSION}/bin/ffprobe.exe ${OUTPUT_DIR}/ffprobe.exe
rm -r ${TEMP_DIR}
- cp ${ROOT}/deployment/win-generic/install-jellyfin.ps1 ${OUTPUT_DIR}/install-jellyfin.ps1
- cp ${ROOT}/deployment/win-generic/install.bat ${OUTPUT_DIR}/install.bat
+ cp ${ROOT}/deployment/windows/install-jellyfin.ps1 ${OUTPUT_DIR}/install-jellyfin.ps1
+ cp ${ROOT}/deployment/windows/install.bat ${OUTPUT_DIR}/install.bat
mkdir -p ${PKG_DIR}
pushd ${OUTPUT_DIR}
${ARCHIVE_CMD} ${ROOT}/${PKG_DIR}/`basename "${OUTPUT_DIR}"`.zip .
diff --git a/deployment/win-x86/package.sh b/deployment/win-x86/package.sh
index 3cc4eb623..8752d92a8 100755
--- a/deployment/win-x86/package.sh
+++ b/deployment/win-x86/package.sh
@@ -20,8 +20,8 @@ package_win32() (
cp ${TEMP_DIR}/${FFMPEG_VERSION}/bin/ffmpeg.exe ${OUTPUT_DIR}/ffmpeg.exe
cp ${TEMP_DIR}/${FFMPEG_VERSION}/bin/ffprobe.exe ${OUTPUT_DIR}/ffprobe.exe
rm -r ${TEMP_DIR}
- cp ${ROOT}/deployment/win-generic/install-jellyfin.ps1 ${OUTPUT_DIR}/install-jellyfin.ps1
- cp ${ROOT}/deployment/win-generic/install.bat ${OUTPUT_DIR}/install.bat
+ cp ${ROOT}/deployment/windows/install-jellyfin.ps1 ${OUTPUT_DIR}/install-jellyfin.ps1
+ cp ${ROOT}/deployment/windows/install.bat ${OUTPUT_DIR}/install.bat
mkdir -p ${PKG_DIR}
pushd ${OUTPUT_DIR}
${ARCHIVE_CMD} ${ROOT}/${PKG_DIR}/`basename "${OUTPUT_DIR}"`.zip .
diff --git a/deployment/win-generic/build-jellyfin.ps1 b/deployment/windows/build-jellyfin.ps1
index 1121c3398..2c83f264c 100644
--- a/deployment/win-generic/build-jellyfin.ps1
+++ b/deployment/windows/build-jellyfin.ps1
@@ -102,8 +102,8 @@ if($InstallNSSM.IsPresent -or ($InstallNSSM -eq $true)){
Write-Verbose "Starting NSSM Install"
Install-NSSM $InstallLocation $Architecture
}
-Copy-Item .\deployment\win-generic\install-jellyfin.ps1 $InstallLocation\install-jellyfin.ps1
-Copy-Item .\deployment\win-generic\install.bat $InstallLocation\install.bat
+Copy-Item .\deployment\windows\install-jellyfin.ps1 $InstallLocation\install-jellyfin.ps1
+Copy-Item .\deployment\windows\install.bat $InstallLocation\install.bat
if($GenerateZip.IsPresent -or ($GenerateZip -eq $true)){
Compress-Archive -Path $InstallLocation -DestinationPath "$InstallLocation/jellyfin.zip" -Force
}
diff --git a/deployment/osx-x64/dependencies.txt b/deployment/windows/dependencies.txt
index 3d25d1bdf..3d25d1bdf 100644
--- a/deployment/osx-x64/dependencies.txt
+++ b/deployment/windows/dependencies.txt
diff --git a/deployment/win-generic/install-jellyfin.ps1 b/deployment/windows/install-jellyfin.ps1
index b6e00e056..b6e00e056 100644
--- a/deployment/win-generic/install-jellyfin.ps1
+++ b/deployment/windows/install-jellyfin.ps1
diff --git a/deployment/win-generic/install.bat b/deployment/windows/install.bat
index e21479a79..e21479a79 100644
--- a/deployment/win-generic/install.bat
+++ b/deployment/windows/install.bat
diff --git a/jellyfin.ruleset b/jellyfin.ruleset
index 4381349ca..262121a32 100644
--- a/jellyfin.ruleset
+++ b/jellyfin.ruleset
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Rules for Jellyfin.Server" Description="Code analysis rules for Jellyfin.Server.csproj" ToolsVersion="14.0">
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
+ <!-- disable warning SA1202: 'public' members must come before 'private' members -->
+ <Rule Id="SA1202" Action="Info" />
+ <!-- disable warning SA1204: Static members must appear before non-static members -->
+ <Rule Id="SA1204" Action="Info" />
+
<!-- disable warning SA1101: Prefix local calls with 'this.' -->
<Rule Id="SA1101" Action="None" />
<!-- disable warning SA1130: Use lambda syntax -->
@@ -15,6 +20,9 @@
<Rule Id="SA1633" Action="None" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.FxCopAnalyzers" RuleNamespace="Microsoft.Design">
+ <!-- disable warning CA1822: Member does not access instance data and can be marked as static -->
+ <Rule Id="CA1822" Action="Info" />
+
<!-- disable warning CA1054: Change the type of parameter url from string to System.Uri -->
<Rule Id="CA1054" Action="None" />
</Rules>
diff --git a/new-file-header.txt b/new-file-header.txt
deleted file mode 100644
index 4247a8e24..000000000
--- a/new-file-header.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-### This header should be used to start new files.
-### It provides an explicit per-file license reference that should be present on all new files.
-### To use this header, delete these lines and the following empty line, modify <filename> to
-### the proper full path, and then add new code following the header and a single empty line.
-
-// <filename>
-// Part of the Jellyfin project (https://jellyfin.media)
-//
-// All copyright belongs to the Jellyfin contributors; a full list can
-// be found in the file CONTRIBUTORS.md
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <https://www.gnu.org/licenses/>.