Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
Fixed downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Klemm committed Jul 26, 2017
1 parent 6b5c928 commit afa9478
Show file tree
Hide file tree
Showing 34 changed files with 2,132 additions and 25 deletions.
20 changes: 17 additions & 3 deletions src/YTMusicDownloader.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YTMusicDownloaderLibTest",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YTMusicDownloaderUpdater", "YTMusicDownloaderUpdater\YTMusicDownloaderUpdater.csproj", "{CFDE5EE8-68EF-43CD-A0E9-EE5A399F5E03}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libvideo", "libvideo\libvideo.csproj", "{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -87,14 +89,26 @@ Global
{CFDE5EE8-68EF-43CD-A0E9-EE5A399F5E03}.Release|x64.Build.0 = Release|Any CPU
{CFDE5EE8-68EF-43CD-A0E9-EE5A399F5E03}.Release|x86.ActiveCfg = Release|Any CPU
{CFDE5EE8-68EF-43CD-A0E9-EE5A399F5E03}.Release|x86.Build.0 = Release|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Debug|x64.ActiveCfg = Debug|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Debug|x64.Build.0 = Debug|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Debug|x86.ActiveCfg = Debug|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Debug|x86.Build.0 = Debug|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Release|Any CPU.Build.0 = Release|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Release|x64.ActiveCfg = Release|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Release|x64.Build.0 = Release|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Release|x86.ActiveCfg = Release|Any CPU
{4DFEDF29-6CB3-4369-8ED9-104A34B8A045}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
RESX_SaveFilesImmediatelyUponChange = True
RESX_SortFileContentOnSave = True
RESX_ResXSortingComparison = OrdinalIgnoreCase
RESX_AutoCreateNewLanguageFiles = False
RESX_ResXSortingComparison = OrdinalIgnoreCase
RESX_SortFileContentOnSave = True
RESX_SaveFilesImmediatelyUponChange = True
EndGlobalSection
EndGlobal
10 changes: 5 additions & 5 deletions src/YTMusicDownloader/YTMusicDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@
<HintPath>..\external\Interop.iTunesLib.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="MahApps.Metro, Version=1.4.1.0, Culture=neutral, PublicKeyToken=f4fb5a3c4d1e5b4f, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.4.1\lib\net45\MahApps.Metro.dll</HintPath>
<Reference Include="MahApps.Metro, Version=1.5.0.23, Culture=neutral, PublicKeyToken=f4fb5a3c4d1e5b4f, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MahApps.Metro.IconPacks.Material, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.IconPacks.Material.1.6.0\lib\net45\MahApps.Metro.IconPacks.Material.dll</HintPath>
<Reference Include="MahApps.Metro.IconPacks.Material, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.IconPacks.Material.1.9.0\lib\net45\MahApps.Metro.IconPacks.Material.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand All @@ -94,7 +94,7 @@
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.4.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
<HintPath>..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml" />
Expand Down
4 changes: 2 additions & 2 deletions src/YTMusicDownloader/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonServiceLocator" version="1.3" targetFramework="net452" />
<package id="MahApps.Metro" version="1.4.1" targetFramework="net452" />
<package id="MahApps.Metro.IconPacks.Material" version="1.6.0" targetFramework="net452" />
<package id="MahApps.Metro" version="1.5.0" targetFramework="net452" />
<package id="MahApps.Metro.IconPacks.Material" version="1.9.0" targetFramework="net452" />
<package id="MvvmLight" version="5.3.0.0" targetFramework="net452" />
<package id="MvvmLightLibs" version="5.3.0.0" targetFramework="net452" />
<package id="NLog" version="5.0.0-beta04" targetFramework="net452" />
Expand Down
22 changes: 11 additions & 11 deletions src/YTMusicDownloaderLib/YTMusicDownloaderLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,16 @@
<HintPath>..\external\Interop.iTunesLib.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="libvideo, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VideoLibrary.1.3.4\lib\portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\libvideo.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="log4net, Version=2.0.7.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.7\lib\net45-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MahApps.Metro, Version=1.4.1.0, Culture=neutral, PublicKeyToken=f4fb5a3c4d1e5b4f, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.4.1\lib\net45\MahApps.Metro.dll</HintPath>
<Reference Include="MahApps.Metro, Version=1.5.0.23, Culture=neutral, PublicKeyToken=f4fb5a3c4d1e5b4f, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NAudio, Version=1.8.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.8.0\lib\net35\NAudio.dll</HintPath>
<Reference Include="NAudio, Version=1.8.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.8.1\lib\net35\NAudio.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Expand All @@ -102,8 +98,8 @@
<HintPath>..\packages\NLog.5.0.0-beta04\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Octokit, Version=0.23.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Octokit.0.23.0\lib\net45\Octokit.dll</HintPath>
<Reference Include="Octokit, Version=0.24.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Octokit.0.24.0\lib\net45\Octokit.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="policy.2.0.taglib-sharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
Expand All @@ -127,7 +123,7 @@
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.4.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
<HintPath>..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xaml" />
Expand Down Expand Up @@ -198,6 +194,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\libvideo\libvideo.csproj">
<Project>{4dfedf29-6cb3-4369-8ed9-104a34b8a045}</Project>
<Name>libvideo</Name>
</ProjectReference>
<ProjectReference Include="..\YTMusicDownloaderLibShared\YTMusicDownloaderLibShared.csproj">
<Project>{a3d1e290-5a41-4d58-9190-71702cd2095a}</Project>
<Name>YTMusicDownloaderLibShared</Name>
Expand Down
7 changes: 3 additions & 4 deletions src/YTMusicDownloaderLib/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
<package id="Google.Apis.Auth" version="1.20.0" targetFramework="net452" />
<package id="Google.Apis.Core" version="1.20.0" targetFramework="net452" />
<package id="log4net" version="2.0.7" targetFramework="net452" />
<package id="MahApps.Metro" version="1.4.1" targetFramework="net452" />
<package id="NAudio" version="1.8.0" targetFramework="net452" />
<package id="MahApps.Metro" version="1.5.0" targetFramework="net452" />
<package id="NAudio" version="1.8.1" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
<package id="NLog" version="5.0.0-beta04" targetFramework="net452" />
<package id="Octokit" version="0.23.0" targetFramework="net452" />
<package id="Octokit" version="0.24.0" targetFramework="net452" />
<package id="RestSharp" version="105.2.3" targetFramework="net452" />
<package id="taglib" version="2.1.0.0" targetFramework="net452" />
<package id="VideoLibrary" version="1.3.4" targetFramework="net452" />
<package id="Zlib.Portable.Signed" version="1.11.0" targetFramework="net452" />
</packages>
15 changes: 15 additions & 0 deletions src/libvideo/AdaptiveKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VideoLibrary
{
public enum AdaptiveKind
{
None,
Audio,
Video
}
}
16 changes: 16 additions & 0 deletions src/libvideo/AudioFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VideoLibrary
{
public enum AudioFormat
{
Mp3,
Aac,
Vorbis,
Unknown
}
}
76 changes: 76 additions & 0 deletions src/libvideo/Client.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using VideoLibrary.Helpers;

namespace VideoLibrary
{
public static class Client
{
public static Client<T> For<T>(ServiceBase<T> baseService)
where T : Video => new Client<T>(baseService);
}

public class Client<T> : IService<T>, IAsyncService<T>, IDisposable
where T : Video
{
private bool disposed = false;
private readonly ServiceBase<T> baseService;
private readonly HttpClient client;

private Task<string> SourceFactory(string address) =>
client.GetStringAsync(address);

internal Client(ServiceBase<T> baseService)
{
Require.NotNull(baseService, nameof(baseService));

this.baseService = baseService;
this.client = baseService.MakeClient();
}

#region IDisposable

~Client()
{
Dispose(false);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposed)
return;
disposed = true;

if (disposing)
{
if (client != null)
client.Dispose();
}
}

#endregion

public T GetVideo(string videoUri) =>
baseService.GetVideo(videoUri, SourceFactory);

public IEnumerable<T> GetAllVideos(string videoUri) =>
baseService.GetAllVideos(videoUri, SourceFactory);

public Task<T> GetVideoAsync(string videoUri) =>
baseService.GetVideoAsync(videoUri, SourceFactory);

public Task<IEnumerable<T>> GetAllVideosAsync(string videoUri) =>
baseService.GetAllVideosAsync(videoUri, SourceFactory);
}
}
112 changes: 112 additions & 0 deletions src/libvideo/DelegatingClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace VideoLibrary
{
public class DelegatingClient : IDisposable
{
private bool disposed = false;
private readonly HttpClient client;

public DelegatingClient()
{
this.client = MakeClient();
}

#region IDisposable

~DelegatingClient()
{
Dispose(false);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposed)
return;

disposed = true;

if (disposing)
{
if (client != null)
client.Dispose();
}
}

#endregion

#region MakeClient/MakeHandler

private HttpClient MakeClient() =>
MakeClient(MakeHandler());

protected virtual HttpMessageHandler MakeHandler()
{
var handler = new HttpClientHandler();

if (handler.SupportsAutomaticDecompression)
{
handler.AutomaticDecompression =
DecompressionMethods.GZip |
DecompressionMethods.Deflate;
}

return handler;
}

protected virtual HttpClient MakeClient(HttpMessageHandler handler)
{
return new HttpClient(handler);
}

#endregion

#region Synchronous wrappers

public HttpResponseMessage Get(string uri) =>
GetAsync(uri).GetAwaiter().GetResult();

public byte[] GetByteArray(string uri) =>
GetByteArrayAsync(uri).GetAwaiter().GetResult();

public Stream GetStream(string uri) =>
GetStreamAsync(uri).GetAwaiter().GetResult();

public string GetString(string uri) =>
GetStringAsync(uri).GetAwaiter().GetResult();

#endregion

#region HttpClient wrappers

// TODO: Support other kinds of HTTP requests,
// such as PUT, POST, DELETE, etc.

public Task<HttpResponseMessage> GetAsync(string uri) =>
client.GetAsync(uri);

public Task<byte[]> GetByteArrayAsync(string uri) =>
client.GetByteArrayAsync(uri);

public Task<Stream> GetStreamAsync(string uri) =>
client.GetStreamAsync(uri);

public Task<string> GetStringAsync(string uri) =>
client.GetStringAsync(uri);

#endregion
}
}
23 changes: 23 additions & 0 deletions src/libvideo/Exceptions/BadQueryException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VideoLibrary.Exceptions
{
internal class BadQueryException : Exception
{
public BadQueryException()
: base()
{ }

public BadQueryException(string message)
: base(message)
{ }

public BadQueryException(string message, Exception innerException)
: base(message, innerException)
{ }
}
}
Loading

0 comments on commit afa9478

Please sign in to comment.