mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-10-26 00:02:44 -04:00 
			
		
		
		
	Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Conflicts: MediaBrowser.Common/Kernel/ResourcePool.cs
This commit is contained in:
		
						commit
						a11e00b8d5
					
				| @ -78,7 +78,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager | |||||||
|             { |             { | ||||||
|                 var handler = new WebRequestHandler |                 var handler = new WebRequestHandler | ||||||
|                 { |                 { | ||||||
|                     AutomaticDecompression = DecompressionMethods.Deflate, |                     //AutomaticDecompression = DecompressionMethods.Deflate, | ||||||
|                     CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate) |                     CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate) | ||||||
|                 }; |                 }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										84
									
								
								MediaBrowser.Common/Kernel/ResourcePool.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								MediaBrowser.Common/Kernel/ResourcePool.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,84 @@ | |||||||
|  | using System; | ||||||
|  | using System.Threading; | ||||||
|  | 
 | ||||||
|  | namespace MediaBrowser.Common.Kernel | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// This is just a collection of semaphores to control the number of concurrent executions of various resources | ||||||
|  |     /// </summary> | ||||||
|  |     public class ResourcePool : IDisposable | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// You tube | ||||||
|  |         /// </summary> | ||||||
|  |         public readonly SemaphoreSlim YouTube = new SemaphoreSlim(5, 5); | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// The trakt | ||||||
|  |         /// </summary> | ||||||
|  |         public readonly SemaphoreSlim Trakt = new SemaphoreSlim(5, 5); | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// The tv db | ||||||
|  |         /// </summary> | ||||||
|  |         public readonly SemaphoreSlim TvDb = new SemaphoreSlim(5, 5); | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// The movie db | ||||||
|  |         /// </summary> | ||||||
|  |         public readonly SemaphoreSlim MovieDb = new SemaphoreSlim(5, 5); | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// The fan art | ||||||
|  |         /// </summary> | ||||||
|  |         public readonly SemaphoreSlim FanArt = new SemaphoreSlim(5, 5); | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// The mb | ||||||
|  |         /// </summary> | ||||||
|  |         public readonly SemaphoreSlim Mb = new SemaphoreSlim(5, 5); | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// The mb | ||||||
|  |         /// </summary> | ||||||
|  |         public readonly SemaphoreSlim Lastfm = new SemaphoreSlim(5, 5); | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// Apple doesn't seem to like too many simulataneous requests. | ||||||
|  |         /// </summary> | ||||||
|  |         public readonly SemaphoreSlim AppleTrailerVideos = new SemaphoreSlim(1, 1); | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// The apple trailer images | ||||||
|  |         /// </summary> | ||||||
|  |         public readonly SemaphoreSlim AppleTrailerImages = new SemaphoreSlim(1, 1); | ||||||
|  |          | ||||||
|  |         /// <summary> | ||||||
|  |         /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. | ||||||
|  |         /// </summary> | ||||||
|  |         public void Dispose() | ||||||
|  |         { | ||||||
|  |             Dispose(true); | ||||||
|  |             GC.SuppressFinalize(this); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// Releases unmanaged and - optionally - managed resources. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <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 (dispose) | ||||||
|  |             { | ||||||
|  |                 YouTube.Dispose(); | ||||||
|  |                 Trakt.Dispose(); | ||||||
|  |                 TvDb.Dispose(); | ||||||
|  |                 MovieDb.Dispose(); | ||||||
|  |                 FanArt.Dispose(); | ||||||
|  |                 Mb.Dispose(); | ||||||
|  |                 AppleTrailerVideos.Dispose(); | ||||||
|  |                 AppleTrailerImages.Dispose(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -108,6 +108,8 @@ | |||||||
|     <Compile Include="IServerApplicationPaths.cs" /> |     <Compile Include="IServerApplicationPaths.cs" /> | ||||||
|     <Compile Include="Library\ChildrenChangedEventArgs.cs" /> |     <Compile Include="Library\ChildrenChangedEventArgs.cs" /> | ||||||
|     <Compile Include="Library\DtoBuilder.cs" /> |     <Compile Include="Library\DtoBuilder.cs" /> | ||||||
|  |     <Compile Include="Providers\Music\LastfmArtistProvider.cs" /> | ||||||
|  |     <Compile Include="Providers\Music\LastfmBaseArtistProvider.cs" /> | ||||||
|     <Compile Include="Resolvers\BaseItemResolver.cs" /> |     <Compile Include="Resolvers\BaseItemResolver.cs" /> | ||||||
|     <Compile Include="Resolvers\BaseVideoResolver.cs" /> |     <Compile Include="Resolvers\BaseVideoResolver.cs" /> | ||||||
|     <Compile Include="Resolvers\IItemResolver.cs" /> |     <Compile Include="Resolvers\IItemResolver.cs" /> | ||||||
|  | |||||||
| @ -0,0 +1,84 @@ | |||||||
|  | using System; | ||||||
|  | using System.Collections.Generic; | ||||||
|  | using System.Linq; | ||||||
|  | using System.Net; | ||||||
|  | using System.Text; | ||||||
|  | using System.Threading; | ||||||
|  | using System.Threading.Tasks; | ||||||
|  | using MediaBrowser.Common.Net; | ||||||
|  | using MediaBrowser.Controller.Entities; | ||||||
|  | using MediaBrowser.Controller.Entities.Audio; | ||||||
|  | using MediaBrowser.Model.Logging; | ||||||
|  | using MediaBrowser.Model.Net; | ||||||
|  | using MediaBrowser.Model.Serialization; | ||||||
|  | 
 | ||||||
|  | namespace MediaBrowser.Controller.Providers.Music | ||||||
|  | { | ||||||
|  |     public class LastfmArtistProvider : LastfmBaseArtistProvider | ||||||
|  |     { | ||||||
|  |         public LastfmArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager)  | ||||||
|  |             : base(jsonSerializer, httpClient, logManager) | ||||||
|  |         { | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         protected override async Task<string> FindId(Entities.BaseItem item, System.Threading.CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             //Execute the Artist search against our name and assume first one is the one we want | ||||||
|  |             var url = RootUrl + string.Format("method=artist.search&artist={0}&api_key={1}&format=json", UrlEncode(item.Name), ApiKey); | ||||||
|  | 
 | ||||||
|  |             LastfmArtistSearchResults searchResult = null; | ||||||
|  | 
 | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) | ||||||
|  |                 { | ||||||
|  |                     searchResult = JsonSerializer.DeserializeFromStream<LastfmArtistSearchResults>(json); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             catch (HttpException e) | ||||||
|  |             { | ||||||
|  |                 if (e.StatusCode == HttpStatusCode.NotFound) | ||||||
|  |                 { | ||||||
|  |                     return null; | ||||||
|  |                 } | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             if (searchResult != null && searchResult.results != null && searchResult.results.artistmatches != null && searchResult.results.artistmatches.artist.Any()) | ||||||
|  |             { | ||||||
|  |                 return searchResult.results.artistmatches.artist.First().mbid; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         protected override async Task FetchLastfmData(BaseItem item, string id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             // Get artist info with provided id | ||||||
|  |             var url = RootUrl + string.Format("method=artist.getInfo&mbid={0}&api_key={1}&format=json", UrlEncode(id), ApiKey); | ||||||
|  | 
 | ||||||
|  |             LastfmGetArtistResult result = null; | ||||||
|  | 
 | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.Lastfm, cancellationToken).ConfigureAwait(false)) | ||||||
|  |                 { | ||||||
|  |                     result = JsonSerializer.DeserializeFromStream<LastfmGetArtistResult>(json); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             catch (HttpException e) | ||||||
|  |             { | ||||||
|  |                 if (e.StatusCode == HttpStatusCode.NotFound) | ||||||
|  |                 { | ||||||
|  |                     throw new LastfmProviderException(string.Format("Unable to retrieve artist info for {0} with id {0}", item.Name, id)); | ||||||
|  |                 } | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             if (result != null && result.artist != null) | ||||||
|  |             { | ||||||
|  |                 ProcessArtistData(item as MusicArtist, result.artist); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,107 @@ | |||||||
|  | using System; | ||||||
|  | using System.Collections.Generic; | ||||||
|  | using System.Linq; | ||||||
|  | using System.Net; | ||||||
|  | using System.Text; | ||||||
|  | using System.Threading.Tasks; | ||||||
|  | using MediaBrowser.Common.Net; | ||||||
|  | using MediaBrowser.Controller.Entities.Audio; | ||||||
|  | using MediaBrowser.Model.Logging; | ||||||
|  | using MediaBrowser.Model.Net; | ||||||
|  | using MediaBrowser.Model.Serialization; | ||||||
|  | 
 | ||||||
|  | namespace MediaBrowser.Controller.Providers.Music | ||||||
|  | { | ||||||
|  |     public abstract class LastfmBaseArtistProvider : LastfmBaseProvider | ||||||
|  |     { | ||||||
|  |         protected LastfmBaseArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager) | ||||||
|  |             : base(jsonSerializer, httpClient, logManager) | ||||||
|  |         { | ||||||
|  |             LocalMetaFileName = "MBArtist.json"; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public override bool Supports(Entities.BaseItem item) | ||||||
|  |         { | ||||||
|  |             return item is MusicArtist; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         protected void ProcessArtistData(MusicArtist artist, LastfmArtist data) | ||||||
|  |         { | ||||||
|  |             artist.Overview = data.bio.summary; | ||||||
|  |             foreach (var tag in data.tags.tag) | ||||||
|  |             { | ||||||
|  |                 artist.AddGenre(tag.name); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     #region Result Objects | ||||||
|  | 
 | ||||||
|  |     public class LastfmStats | ||||||
|  |     { | ||||||
|  |         public string listeners { get; set; } | ||||||
|  |         public string playcount { get; set; } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public class LastfmTag | ||||||
|  |     { | ||||||
|  |         public string name { get; set; } | ||||||
|  |         public string url { get; set; } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public class LastfmTags | ||||||
|  |     { | ||||||
|  |         public List<LastfmTag> tag  { get; set; } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public class LastfmFormationInfo | ||||||
|  |     { | ||||||
|  |         public string yearfrom { get; set; } | ||||||
|  |         public string yearto { get; set; } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public class LastFmBio | ||||||
|  |     { | ||||||
|  |         public string published { get; set; } | ||||||
|  |         public string summary { get; set; } | ||||||
|  |         public string content { get; set; } | ||||||
|  |         public string placeformed { get; set; } | ||||||
|  |         public string yearformed { get; set; } | ||||||
|  |         public List<LastfmFormationInfo> formationlist { get; set; } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public class LastfmArtist | ||||||
|  |     { | ||||||
|  |         public string name { get; set; } | ||||||
|  |         public string mbid { get; set; } | ||||||
|  |         public string url { get; set; } | ||||||
|  |         public string streamable { get; set; } | ||||||
|  |         public string ontour { get; set; } | ||||||
|  |         public LastfmStats stats { get; set; } | ||||||
|  |         public List<LastfmArtist> similar { get; set; } | ||||||
|  |         public LastfmTags tags { get; set; } | ||||||
|  |         public LastFmBio bio { get; set; } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public class LastfmGetArtistResult | ||||||
|  |     { | ||||||
|  |         public LastfmArtist artist { get; set; } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public class Artistmatches | ||||||
|  |     { | ||||||
|  |         public List<LastfmArtist> artist { get; set; } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public class LastfmArtistSearchResult | ||||||
|  |     { | ||||||
|  |         public Artistmatches artistmatches { get; set; } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public class LastfmArtistSearchResults | ||||||
|  |     { | ||||||
|  |         public LastfmArtistSearchResult results { get; set; } | ||||||
|  |     } | ||||||
|  |     #endregion | ||||||
|  | } | ||||||
| @ -96,7 +96,7 @@ namespace MediaBrowser.Controller.Providers.Music | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         protected const string RootUrl = @"http://ws.audioscrobbler.com/2.0/"; |         protected const string RootUrl = @"http://ws.audioscrobbler.com/2.0/?"; | ||||||
|         protected static string ApiKey = "7b76553c3eb1d341d642755aecc40a33"; |         protected static string ApiKey = "7b76553c3eb1d341d642755aecc40a33"; | ||||||
| 
 | 
 | ||||||
|         protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo) |         protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo) | ||||||
| @ -188,7 +188,27 @@ namespace MediaBrowser.Controller.Providers.Music | |||||||
|         /// <param name="item">The item.</param> |         /// <param name="item">The item.</param> | ||||||
|         /// <param name="cancellationToken"></param> |         /// <param name="cancellationToken"></param> | ||||||
|         /// <returns>Task.</returns> |         /// <returns>Task.</returns> | ||||||
|         protected abstract Task FetchData(BaseItem item, CancellationToken cancellationToken); |         protected async Task FetchData(BaseItem item, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var id = item.GetProviderId(MetadataProviders.Musicbrainz) ?? await FindId(item, cancellationToken).ConfigureAwait(false); | ||||||
|  |             if (id != null) | ||||||
|  |             { | ||||||
|  |                 Logger.Debug("LastfmProvider - getting info with id: " + id); | ||||||
|  | 
 | ||||||
|  |                 cancellationToken.ThrowIfCancellationRequested(); | ||||||
|  | 
 | ||||||
|  |                 await FetchLastfmData(item, id, cancellationToken).ConfigureAwait(false); | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                 Logger.Info("LastfmProvider could not find " + item.Name + ". Check name on Last.fm."); | ||||||
|  |             } | ||||||
|  |              | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         protected abstract Task<string> FindId(BaseItem item, CancellationToken cancellationToken); | ||||||
|  | 
 | ||||||
|  |         protected abstract Task FetchLastfmData(BaseItem item, string id, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Encodes an URL. |         /// Encodes an URL. | ||||||
|  | |||||||
| @ -15,7 +15,7 @@ | |||||||
|     <add key="ProgramDataFolderName" value="MediaBrowser-Server" /> |     <add key="ProgramDataFolderName" value="MediaBrowser-Server" /> | ||||||
|     <add key="ClientSettingsProvider.ServiceUri" value="" /> |     <add key="ClientSettingsProvider.ServiceUri" value="" /> | ||||||
|   </appSettings> |   </appSettings> | ||||||
|   <startup> |   <startup useLegacyV2RuntimeActivationPolicy="true"> | ||||||
|     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> |     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||||||
|   </startup> |   </startup> | ||||||
|   <runtime> |   <runtime> | ||||||
|  | |||||||
| @ -43,6 +43,7 @@ namespace MediaBrowser.ServerApplication | |||||||
|         { |         { | ||||||
|             _logger = logger; |             _logger = logger; | ||||||
|             _jsonSerializer = jsonSerializer; |             _jsonSerializer = jsonSerializer; | ||||||
|  |             _libraryManager = libraryManager; | ||||||
| 
 | 
 | ||||||
|             InitializeComponent(); |             InitializeComponent(); | ||||||
|             lblVersion.Content = "Version: " + appHost.ApplicationVersion; |             lblVersion.Content = "Version: " + appHost.ApplicationVersion; | ||||||
| @ -52,7 +53,6 @@ namespace MediaBrowser.ServerApplication | |||||||
|             ddlProfile.SelectedIndex = 0; |             ddlProfile.SelectedIndex = 0; | ||||||
|             ddlIndexBy.Visibility = ddlSortBy.Visibility = lblIndexBy.Visibility = lblSortBy.Visibility = Visibility.Hidden; |             ddlIndexBy.Visibility = ddlSortBy.Visibility = lblIndexBy.Visibility = lblSortBy.Visibility = Visibility.Hidden; | ||||||
| 
 | 
 | ||||||
|             _libraryManager = libraryManager; |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user