-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Console App #12
base: main
Are you sure you want to change the base?
New Console App #12
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the generic builder pattern like: var host = Host.CreateDefaultBuilder(args);
... Please refer to: https://learn.microsoft.com/dotnet/core/extensions/generic-host |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
using Aliencube.YouTubeSubtitlesExtractor; | ||
using Aliencube.YouTubeSubtitlesExtractor.Models; | ||
|
||
|
||
//Url with some subtitles (testing purposes) | ||
//https://www.youtube.com/watch?v=KLe7Rxkrj94 | ||
|
||
Console.WriteLine("Input youtube url: "); | ||
string? youtubeUrl = Console.ReadLine(); | ||
|
||
if ( string.IsNullOrWhiteSpace( youtubeUrl) ) | ||
{ | ||
Console.WriteLine("Error, youtube url empty"); | ||
return; | ||
} | ||
|
||
var http = new HttpClient(); | ||
var youtube = new YouTubeVideo(http); | ||
|
||
var details = await youtube.ExtractVideoDetailsAsync(youtubeUrl); | ||
|
||
if (details is not null) | ||
{ | ||
|
||
Console.WriteLine("AvailableLanguageCodes: "); | ||
for (var i = 0; i < details.AvaiableLanguageCodes.Count; i++) | ||
{ | ||
Console.WriteLine(details.AvaiableLanguageCodes[i]); | ||
} | ||
|
||
Console.WriteLine("Input language code: "); | ||
string? langCode = Console.ReadLine(); | ||
if (string.IsNullOrWhiteSpace(langCode)) | ||
{ | ||
Console.WriteLine("Error, language code empty"); | ||
return; | ||
} | ||
|
||
|
||
var videoSubs = await youtube.ExtractSubtitleAsync(youtubeUrl, langCode); | ||
if (videoSubs is not null && videoSubs.Content is not null) | ||
{ | ||
string colSep = "\t"; | ||
Console.WriteLine($"Start {colSep} End {colSep} Subtitle"); | ||
for (var i = 0; i < videoSubs.Content.Count; i++) | ||
{ | ||
var subsContent = videoSubs.Content[i]; | ||
|
||
string substart = "-", subend = "-"; | ||
string subtext = subsContent.Text ?? "-"; | ||
|
||
if (subsContent.Start.HasValue) | ||
{ | ||
float start_ms = subsContent.Start ?? 0; | ||
start_ms = start_ms * 1000; | ||
|
||
TimeSpan start_ts = TimeSpan.FromMilliseconds(start_ms); | ||
substart = start_ts.ToString(@"hh\:mm\:ss"); | ||
|
||
if (subsContent.Duration.HasValue) | ||
{ | ||
float duration_ms = subsContent.Duration ?? 0; | ||
duration_ms = duration_ms * 1000; | ||
|
||
TimeSpan duration_ts = TimeSpan.FromMilliseconds(duration_ms); | ||
subend = start_ts.Add(duration_ts).ToString(@"hh\:mm\:ss"); | ||
} | ||
} | ||
|
||
Console.WriteLine($"{substart} {colSep} {subend} {colSep} {subtext}"); | ||
|
||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Error Extracting Subtitles"); | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As .NET 8 is around the corner, I'd like to target this app to |
||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\YouTubeSubtitlesExtractor\YouTubeSubtitlesExtractor.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The console app should be under the
samples
directory, instead ofconsoleapp