mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-05-24 02:02:29 -04:00
Weather updates
This commit is contained in:
parent
b6bc22ae63
commit
3c47375229
@ -573,9 +573,9 @@ namespace MediaBrowser.ApiInteraction
|
|||||||
{
|
{
|
||||||
string url = ApiUrl + "/ServerConfiguration";
|
string url = ApiUrl + "/ServerConfiguration";
|
||||||
|
|
||||||
using (Stream stream = await GetSerializedStreamAsync(url).ConfigureAwait(false))
|
using (Stream stream = await GetSerializedStreamAsync(url, ApiInteraction.SerializationFormat.Json).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
return DeserializeFromStream<ServerConfiguration>(stream);
|
return DeserializeFromStream<ServerConfiguration>(stream, ApiInteraction.SerializationFormat.Json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,19 +622,27 @@ namespace MediaBrowser.ApiInteraction
|
|||||||
/// This is a helper around getting a stream from the server that contains serialized data
|
/// This is a helper around getting a stream from the server that contains serialized data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Task<Stream> GetSerializedStreamAsync(string url)
|
private Task<Stream> GetSerializedStreamAsync(string url)
|
||||||
|
{
|
||||||
|
return GetSerializedStreamAsync(url, SerializationFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This is a helper around getting a stream from the server that contains serialized data
|
||||||
|
/// </summary>
|
||||||
|
private Task<Stream> GetSerializedStreamAsync(string url, SerializationFormat serializationFormat)
|
||||||
{
|
{
|
||||||
if (url.IndexOf('?') == -1)
|
if (url.IndexOf('?') == -1)
|
||||||
{
|
{
|
||||||
url += "?dataformat=" + SerializationFormat.ToString().ToLower();
|
url += "?dataformat=" + serializationFormat.ToString().ToLower();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
url += "&dataformat=" + SerializationFormat.ToString().ToLower();
|
url += "&dataformat=" + serializationFormat.ToString().ToLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetStreamAsync(url);
|
return GetStreamAsync(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
private T DeserializeFromStream<T>(Stream stream)
|
private T DeserializeFromStream<T>(Stream stream)
|
||||||
{
|
{
|
||||||
return DeserializeFromStream<T>(stream, SerializationFormat);
|
return DeserializeFromStream<T>(stream, SerializationFormat);
|
||||||
|
@ -41,6 +41,14 @@ namespace MediaBrowser.Common.Kernel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public HttpServer HttpServer { get; private set; }
|
public HttpServer HttpServer { get; private set; }
|
||||||
|
|
||||||
|
protected virtual string HttpServerUrlPrefix
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the kernel context. The UI kernel will have to override this.
|
/// Gets the kernel context. The UI kernel will have to override this.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -181,7 +189,7 @@ namespace MediaBrowser.Common.Kernel
|
|||||||
{
|
{
|
||||||
DisposeHttpServer();
|
DisposeHttpServer();
|
||||||
|
|
||||||
HttpServer = new HttpServer("http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/");
|
HttpServer = new HttpServer(HttpServerUrlPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -62,7 +62,7 @@ namespace MediaBrowser.Common.Net.Handlers
|
|||||||
|
|
||||||
protected async override Task WriteResponseToOutputStream(Stream stream)
|
protected async override Task WriteResponseToOutputStream(Stream stream)
|
||||||
{
|
{
|
||||||
await EnsureObjectToSerialize();
|
await EnsureObjectToSerialize().ConfigureAwait(false);
|
||||||
|
|
||||||
switch (SerializationFormat)
|
switch (SerializationFormat)
|
||||||
{
|
{
|
||||||
|
@ -53,12 +53,18 @@ namespace MediaBrowser.Controller.Weather
|
|||||||
{
|
{
|
||||||
WeatherInfo info = new WeatherInfo();
|
WeatherInfo info = new WeatherInfo();
|
||||||
|
|
||||||
if (data.current_condition.Any())
|
if (data.current_condition != null)
|
||||||
{
|
{
|
||||||
info.CurrentWeather = data.current_condition.First().ToWeatherStatus();
|
if (data.current_condition.Any())
|
||||||
|
{
|
||||||
|
info.CurrentWeather = data.current_condition.First().ToWeatherStatus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info.Forecasts = data.weather.Select(w => w.ToWeatherForecast()).ToArray();
|
if (data.weather != null)
|
||||||
|
{
|
||||||
|
info.Forecasts = data.weather.Select(w => w.ToWeatherForecast()).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
|
using MediaBrowser.Model.Weather;
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Configuration
|
namespace MediaBrowser.Model.Configuration
|
||||||
{
|
{
|
||||||
public class ServerConfiguration : BaseApplicationConfiguration
|
public class ServerConfiguration : BaseApplicationConfiguration
|
||||||
{
|
{
|
||||||
public bool EnableInternetProviders { get; set; }
|
public bool EnableInternetProviders { get; set; }
|
||||||
public string WeatherZipCode { get; set; }
|
|
||||||
public bool EnableUserProfiles { get; set; }
|
public bool EnableUserProfiles { get; set; }
|
||||||
|
|
||||||
|
public string WeatherZipCode { get; set; }
|
||||||
|
public WeatherUnits WeatherUnit { get; set; }
|
||||||
|
|
||||||
public ServerConfiguration()
|
public ServerConfiguration()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
EnableUserProfiles = true;
|
EnableUserProfiles = true;
|
||||||
WeatherZipCode = "02116";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
<Compile Include="Weather\WeatherForecast.cs" />
|
<Compile Include="Weather\WeatherForecast.cs" />
|
||||||
<Compile Include="Weather\WeatherInfo.cs" />
|
<Compile Include="Weather\WeatherInfo.cs" />
|
||||||
<Compile Include="Weather\WeatherStatus.cs" />
|
<Compile Include="Weather\WeatherStatus.cs" />
|
||||||
|
<Compile Include="Weather\WeatherUnits.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="protobuf-net">
|
<Reference Include="protobuf-net">
|
||||||
|
9
MediaBrowser.Model/Weather/WeatherUnits.cs
Normal file
9
MediaBrowser.Model/Weather/WeatherUnits.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
namespace MediaBrowser.Model.Weather
|
||||||
|
{
|
||||||
|
public enum WeatherUnits
|
||||||
|
{
|
||||||
|
Fahrenheit,
|
||||||
|
Celsius
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user