Skip to content

Commit

Permalink
Facelift:
Browse files Browse the repository at this point in the history
- Windows Server 2019
- .NET 4.7.2
- PackageReference
- Remove caching
- .sln files to root
  • Loading branch information
i3arnon committed Jul 12, 2019
1 parent 31c09b9 commit 5d5c489
Show file tree
Hide file tree
Showing 20 changed files with 179 additions and 127 deletions.
4 changes: 2 additions & 2 deletions src/YouCast.sln → YouCast.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YouCast", "YouCast\YouCast.csproj", "{46E83745-F19D-4EB1-BB72-699726DDEA70}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YouCast", "src\YouCast\YouCast.csproj", "{46E83745-F19D-4EB1-BB72-699726DDEA70}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Service", "Service\Service.csproj", "{9D512757-C17F-45AA-B0F0-5702AEB7A437}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Service", "src\Service\Service.csproj", "{9D512757-C17F-45AA-B0F0-5702AEB7A437}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/YouCastCloud.sln → YouCastCloud.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YouCast", "YouCast\YouCast.csproj", "{46E83745-F19D-4EB1-BB72-699726DDEA70}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YouCast", "src\YouCast\YouCast.csproj", "{46E83745-F19D-4EB1-BB72-699726DDEA70}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Service", "Service\Service.csproj", "{9D512757-C17F-45AA-B0F0-5702AEB7A437}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Service", "src\Service\Service.csproj", "{9D512757-C17F-45AA-B0F0-5702AEB7A437}"
EndProject
Project("{CC5FD16D-436D-48AD-A40C-5A424C6E3E79}") = "CloudService", "CloudService\CloudService.ccproj", "{F8838154-F8B8-4FE4-A900-9829D048B46E}"
Project("{CC5FD16D-436D-48AD-A40C-5A424C6E3E79}") = "CloudService", "src\CloudService\CloudService.ccproj", "{F8838154-F8B8-4FE4-A900-9829D048B46E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceWorkerRole", "ServiceWorkerRole\ServiceWorkerRole.csproj", "{FDFDA77F-0FD4-4858-9638-90FCD5F92BFE}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceWorkerRole", "src\ServiceWorkerRole\ServiceWorkerRole.csproj", "{FDFDA77F-0FD4-4858-9638-90FCD5F92BFE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
Expand Down
2 changes: 1 addition & 1 deletion src/CloudService/ServiceConfiguration.Cloud.cscfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="CloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">
<ServiceConfiguration serviceName="CloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="6" osVersion="*" schemaVersion="2015-04.2.6">
<Role name="ServiceWorkerRole">
<Instances count="1" />
<ConfigurationSettings></ConfigurationSettings>
Expand Down
2 changes: 1 addition & 1 deletion src/CloudService/ServiceConfiguration.Local.cscfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="CloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">
<ServiceConfiguration serviceName="CloudService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="6" osVersion="*" schemaVersion="2015-04.2.6">
<Role name="ServiceWorkerRole">
<Instances count="1" />
<ConfigurationSettings></ConfigurationSettings>
Expand Down
2 changes: 1 addition & 1 deletion src/Service/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
</configuration>
9 changes: 7 additions & 2 deletions src/Service/Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<AssemblyName>Service</AssemblyName>
<ProjectTypeGuids>{3D9AD99F-2412-4246-B90B-4EAA41C64699};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<StartArguments>"/client:iexplore.exe" "/clientArgs:http://localhost:8733/Design_Time_Addresses/Service/Feed1/"</StartArguments>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<WcfConfigValidationEnabled>True</WcfConfigValidationEnabled>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
Expand Down Expand Up @@ -48,12 +48,17 @@
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Google.Apis.YouTube.v3" Version="[1.40.2.1593]" />
<PackageReference Include="morelinq" Version="[2.9.0]" />
<PackageReference Include="Newtonsoft.Json" Version="[12.0.2]" />
<PackageReference Include="YoutubeExplode" Version="[4.7.6]" />
</ItemGroup>
<ItemGroup>
<Compile Include="**\*.cs" Exclude="obj\**" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="project.json" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
Expand Down
94 changes: 26 additions & 68 deletions src/Service/YoutubeFeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.ServiceModel.Web;
using System.Threading.Tasks;
using System.Xml.Linq;
using VideoLibrary;
using YoutubeExplode;
using YoutubeExplode.Models.MediaStreams;
using Video = Google.Apis.YouTube.v3.Data.Video;
Expand All @@ -31,7 +30,7 @@ public sealed class YoutubeFeed : IYoutubeFeed

public YoutubeFeed()
{
_youtubeClient= new YoutubeClient();
_youtubeClient = new YoutubeClient();
_youtubeService =
new YouTubeService(
new BaseClientService.Initializer
Expand Down Expand Up @@ -69,11 +68,6 @@ public async Task<SyndicationFeedFormatter> GetUserFeedAsync(
encoding,
maxLength,
isPopular);
var cachedFeed = GetFromCache(arguments);
if (cachedFeed != null)
{
return cachedFeed;
}

var feed = new ItunesFeed(
GetTitle(channel.Snippet.Title, arguments),
Expand All @@ -87,7 +81,7 @@ public async Task<SyndicationFeedFormatter> GetUserFeedAsync(
arguments),
};

return SetCache(arguments, GetFormatter(feed));
return GetFormatter(feed);
}

public async Task<SyndicationFeedFormatter> GetPlaylistFeedAsync(
Expand All @@ -109,11 +103,6 @@ public async Task<SyndicationFeedFormatter> GetPlaylistFeedAsync(
playlistRequest.MaxResults = 1;

var playlist = (await playlistRequest.ExecuteAsync()).Items.First();
var cachedFeed = GetFromCache(arguments);
if (cachedFeed != null)
{
return cachedFeed;
}

var feed = new ItunesFeed(
GetTitle(playlist.Snippet.Title, arguments),
Expand All @@ -127,37 +116,40 @@ public async Task<SyndicationFeedFormatter> GetPlaylistFeedAsync(
arguments),
};

return SetCache(arguments, GetFormatter(feed));
return GetFormatter(feed);
}

public async Task GetVideoAsync(string videoId, string encoding)
{
var context = WebOperationContext.Current;
var resolution = int.Parse(encoding.Remove(encoding.Length - 1).Substring(startIndex: 4));
var tasks = new []

var resolution = 720;
try
{
GetYoutubeExplodeUriAsync(videoId, resolution),
GetLibVideoUriAsync(videoId, resolution)
};
resolution = int.Parse(encoding.Remove(encoding.Length - 1).Substring(startIndex: 4));
}
catch
{
}

foreach (var task in tasks)
try
{
try
{
var redirectUri = await task;
if (redirectUri == null)
{
continue;
}
var streamInfoSet = await _youtubeClient.GetVideoMediaStreamInfosAsync(videoId);
var muxedStreamInfo =
streamInfoSet.Muxed.FirstOrDefault(_ => _.VideoQuality.GetResolution() == resolution) ??
streamInfoSet.Muxed.WithHighestVideoQuality();

var redirectUri = muxedStreamInfo?.Url;
if (redirectUri != null)
{
context.OutgoingResponse.StatusCode = HttpStatusCode.Redirect;
context.OutgoingResponse.Headers["Location"] = redirectUri;
return;
}
catch (Exception exception)
{
ExceptionHandler.Handle(exception);
}
}
catch (Exception exception)
{
ExceptionHandler.Handle(exception);
}

context.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
Expand All @@ -167,13 +159,11 @@ public async Task GetAudioAsync(string videoId)
{
var context = WebOperationContext.Current;

var videos = await YouTube.Default.GetAllVideosAsync(string.Format(_videoUrlFormat, videoId));
var audios = videos.
Where(_ => _.AudioFormat == AudioFormat.Aac && _.AdaptiveKind == AdaptiveKind.Audio).
ToList();
var streamInfoSet = await _youtubeClient.GetVideoMediaStreamInfosAsync(videoId);
var audios = streamInfoSet.Audio.Where(audio => audio.AudioEncoding == AudioEncoding.Aac).ToList();
if (audios.Count > 0)
{
var redirectUri = await audios.MaxBy(_ => _.AudioBitrate).GetUriAsync();
var redirectUri = audios.MaxBy(audio => audio.Bitrate).Url;
context.OutgoingResponse.StatusCode = HttpStatusCode.Redirect;
context.OutgoingResponse.Headers["Location"] = redirectUri;
}
Expand Down Expand Up @@ -287,27 +277,6 @@ private async Task<IEnumerable<Video>> GetVideoBatchAsync(IEnumerable<string> vi
return (await statisticsRequest.ExecuteAsync()).Items;
}

private async Task<string> GetYoutubeExplodeUriAsync(string videoId, int resolution)
{
var streamInfoSet = await _youtubeClient.GetVideoMediaStreamInfosAsync(videoId);
var muxedStreamInfo =
streamInfoSet.Muxed.FirstOrDefault(_ => _.VideoQuality.GetResolution() == resolution) ??
streamInfoSet.Muxed.WithHighestVideoQuality();

return muxedStreamInfo?.Url;
}

private async Task<string> GetLibVideoUriAsync(string videoId, int resolution)
{
var videos = await YouTube.Default.GetAllVideosAsync(string.Format(_videoUrlFormat, videoId));
var nonAdaptiveVideos = videos.Where(_ => _.Format == VideoFormat.Mp4 && !_.IsAdaptive).ToList();
var nonAdaptiveVideo =
nonAdaptiveVideos.FirstOrDefault(_ => _.Resolution == resolution) ??
nonAdaptiveVideos.MaxBy(_ => _.Resolution);

return nonAdaptiveVideo == null ? null : await nonAdaptiveVideo.GetUriAsync();
}

private static string GetTitle(string title, Arguments arguments) =>
arguments.IsPopular ? $"{title} (By Popularity)" : title;

Expand All @@ -319,16 +288,5 @@ private static string GetBaseAddress()
var transportAddress = OperationContext.Current.IncomingMessageProperties.Via;
return $"http://{transportAddress.DnsSafeHost}:{transportAddress.Port}/FeedService";
}

private static SyndicationFeedFormatter SetCache(Arguments arguments, SyndicationFeedFormatter formattedFeed)
{
MemoryCache.Default.Add(
new CacheItem(arguments.ToString(), formattedFeed),
new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(1) });
return formattedFeed;
}

private static SyndicationFeedFormatter GetFromCache(Arguments arguments) =>
MemoryCache.Default.Get(arguments.ToString()) as SyndicationFeedFormatter;
}
}
14 changes: 0 additions & 14 deletions src/Service/project.json

This file was deleted.

7 changes: 5 additions & 2 deletions src/ServiceWorkerRole/ServiceWorkerRole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ServiceWorkerRole</RootNamespace>
<AssemblyName>ServiceWorkerRole</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<RoleType>Worker</RoleType>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
Expand Down Expand Up @@ -45,12 +45,15 @@
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAzure.ConfigurationManager" Version="[3.2.1]" />
<PackageReference Include="WindowsAzure.Storage" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="**\*.cs" Exclude="obj\**" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Service\Service.csproj">
Expand Down
10 changes: 9 additions & 1 deletion src/ServiceWorkerRole/app.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
12 changes: 0 additions & 12 deletions src/ServiceWorkerRole/project.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/YouCast/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<userSettings>
<YouCast.Properties.Settings>
Expand All @@ -30,4 +30,4 @@
</setting>
</YouCast.Properties.Settings>
</userSettings>
</configuration>
</configuration>
5 changes: 3 additions & 2 deletions src/YouCast/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<Weavers>
<Costura/>
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>
Loading

0 comments on commit 5d5c489

Please sign in to comment.