Skip to content

Commit

Permalink
Major updates analyze and add download and models and UI. (#32)
Browse files Browse the repository at this point in the history
* Major Update analyze and add download codes and models.

* Update packages and project version.

* Minor ui changes.
  • Loading branch information
manusoft authored Jul 14, 2024
1 parent 69fa331 commit 72a44f0
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 39 deletions.
4 changes: 2 additions & 2 deletions TubeSync/Models/DownloadItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ public class DownloadItem : ObservableObject
public string Id { get; set; }
public string Title { get; set; }
public string Duration { get; set; }
public string AudioCodec { get; set; }
public string Bitrate { get; set; }
public string FileSize { get; set; }
public string FileFormat { get; set; }
public string VideoCodec { get; set; }
public string VideoInfo { get; set; }
public bool IsAudioOnly { get; set; }
public string RemoteUrl { get; set; }
public string LocalPath { get; set; }
public string ImageUrl { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion TubeSync/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Identity
Name="c9673203-bd37-46b7-ab37-1d645e27c760"
Publisher="CN=manojbabu.in"
Version="1.0.1.0" />
Version="1.1.0.0" />

<mp:PhoneIdentity PhoneProductId="c9673203-bd37-46b7-ab37-1d645e27c760" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
15 changes: 9 additions & 6 deletions TubeSync/TubeSync.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>TubeSync</RootNamespace>
<ApplicationIcon>Assets/WindowIcon.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;arm64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &gt;= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &gt;= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>Properties\PublishProfiles\win10-$(Platform).pubxml</PublishProfile>
<Version>1.0.0</Version>
<Version>1.2.0</Version>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWinUI>true</UseWinUI>
Expand All @@ -36,11 +38,12 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240627000" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="WinUIEx" Version="2.3.4" />
<PackageReference Include="YoutubeExplode" Version="6.3.13" />
<PackageReference Include="YoutubeExplode" Version="6.3.16" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
Expand Down
73 changes: 46 additions & 27 deletions TubeSync/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using AngleSharp.Common;
using System.Net;

namespace TubeSync.ViewModels;

Expand Down Expand Up @@ -66,14 +67,23 @@ public async Task AnalyzeVideoLinkAsync()
var video = await youtube.Videos.GetAsync(VideoLink);
var streamManifest = await youtube.Videos.Streams.GetManifestAsync(VideoLink);

StreamInfo = streamManifest.Streams;

// Get highest quality muxed stream
StreamInfo = streamManifest.GetMuxedStreams();
//StreamInfo = streamManifest.GetMuxedStreams();


//var highQ = StreamInfo.GetWithHighestVideoQuality();

var highQ = StreamInfo.GetWithHighestVideoQuality();
//foreach (var item in streams)
//{
// Qualities.Add(item.VideoQuality.Label);
//}

foreach (var item in StreamInfo.ToList())
foreach (var item in StreamInfo)
{
Qualities.Add(item.VideoQuality.Label);
if(!Qualities.Contains(item.ToString()!))
Qualities.Add(item.ToString()!);
}

ThumbnailUrl = video.Thumbnails.LastOrDefault()!.Url;
Expand All @@ -84,7 +94,7 @@ public async Task AnalyzeVideoLinkAsync()
VideoTitle = video.Title;
VideoDuration = video.Duration!.Value.ToString();
VideoThumbnail = bitmap;
SelectedQuality = Qualities.LastOrDefault()!.ToString();
SelectedQuality = StreamInfo.TryGetWithHighestBitrate()!.ToString()!;
IsAnalyzed = true;
}
catch (Exception ex)
Expand All @@ -110,26 +120,35 @@ private async Task AddDownloadItem()

try
{
var videoPlayerStream = StreamInfo!.First(video => video.VideoQuality.Label == SelectedQuality);

DownloadItem downloadItem = new DownloadItem()
if(StreamInfo != null)
{
Id = VideoId,
Title = VideoTitle,
Duration = VideoDuration,
ImageUrl = ThumbnailUrl,
AudioCodec = videoPlayerStream.AudioCodec,
FileFormat = videoPlayerStream.Container.Name,
FileSize = $"{Math.Round(videoPlayerStream.Size.MegaBytes, 1)}MB",
VideoCodec = videoPlayerStream.VideoCodec,
VideoInfo = $"{videoPlayerStream.VideoResolution.Width}x{videoPlayerStream.VideoResolution.Height} {videoPlayerStream.VideoQuality.Framerate}fps",
RemoteUrl = videoPlayerStream.Url,
LocalPath = AppContants.DownloadPath,
CreatedAt = DateTime.Now,
CancellationTokenSource = new CancellationTokenSource(),
};

DownloadItems.Insert(0, downloadItem); //Add(downloadItem);
foreach (var item in StreamInfo)
{

if(item.ToString() == SelectedQuality)
{
DownloadItem downloadItem = new DownloadItem()
{
Id = VideoId,
Title = VideoTitle,
Duration = VideoDuration,
ImageUrl = ThumbnailUrl,
Bitrate = item.Bitrate.ToString(),
FileFormat = item.Container.Name,
FileSize = $"{Math.Round(item.Size.MegaBytes, 1)}MB",
IsAudioOnly = item.Container.IsAudioOnly,
VideoInfo = SelectedQuality,
RemoteUrl = item.Url,
LocalPath = AppContants.DownloadPath,
CreatedAt = DateTime.Now,
CancellationTokenSource = new CancellationTokenSource(),
};

if (!DownloadItems.Any(x => x.Id == VideoId))
DownloadItems.Insert(0, downloadItem); //Add(downloadItem);
}
}
}

SaveDownloadList();

Expand Down Expand Up @@ -231,7 +250,7 @@ private async Task DownloadItemAsync(DownloadItem download, CancellationToken ca

var saveFileName = PathExtension.ConvertToValidFileName(download.Title);

var destinationFilePath = $"{AppContants.DownloadPath}\\{saveFileName}.mp4";
var destinationFilePath = $"{AppContants.DownloadPath}\\{saveFileName}.{download.FileFormat}";

download.LocalPath = destinationFilePath;

Expand Down Expand Up @@ -496,7 +515,7 @@ private async Task GetCookiesAsync()
private string videoDuration = string.Empty;

[ObservableProperty]
private IEnumerable<MuxedStreamInfo>? streamInfo;
private IEnumerable<IStreamInfo>? streamInfo;

[ObservableProperty]
private string selectedQuality = "720p";
Expand Down
2 changes: 1 addition & 1 deletion TubeSync/Views/AnalyzeDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</Grid>
<ComboBox
Header="Video Quality:"
Width="150"
Width="250"
ItemsSource="{x:Bind ViewModel.Qualities, Mode=OneWay}"
SelectedItem="{x:Bind ViewModel.SelectedQuality, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Text="(If left blank, the highest quality will be selected automatically)" Foreground="Gray"/>
Expand Down
8 changes: 6 additions & 2 deletions TubeSync/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,13 @@
</Viewbox>
<TextBlock Text="{x:Bind VideoInfo}" VerticalAlignment="Center" Foreground="Gray"/>
<Viewbox Width="14" Height="14">
<SymbolIcon Symbol="Audio"/>
<SymbolIcon Symbol="Volume"/>
</Viewbox>
<TextBlock Text="{x:Bind AudioCodec}" VerticalAlignment="Center" Foreground="Gray"/>
<TextBlock Text="{x:Bind IsAudioOnly}" VerticalAlignment="Center" Foreground="Gray"/>
<Viewbox Width="14" Height="14">
<SymbolIcon Symbol="Camera"/>
</Viewbox>
<TextBlock Text="{x:Bind Bitrate}" VerticalAlignment="Center" Foreground="Gray"/>
<Viewbox Width="14" Height="14">
<SymbolIcon Symbol="Download"/>
</Viewbox>
Expand Down

0 comments on commit 72a44f0

Please sign in to comment.