Compare commits

...

63 Commits

Author SHA1 Message Date
5e67654b12 Merge pull request 'fix: ajustes de bypass novamente...' (#29) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m30s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/29
2025-05-28 05:05:43 +00:00
Ricardo Carneiro
8bffb37ced fix: ajustes de bypass novamente... 2025-05-28 02:04:00 -03:00
5ba7161063 Merge pull request 'fix: argumentos yt-dlp' (#28) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m31s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/28
2025-05-28 04:55:32 +00:00
Ricardo Carneiro
f2b61e9e76 fix: argumentos yt-dlp 2025-05-28 01:55:04 -03:00
15b6e72f51 Merge pull request 'fix: nova tentativa prod' (#27) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m28s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/27
2025-05-28 04:43:42 +00:00
Ricardo Carneiro
b741b26e24 fix: nova tentativa prod 2025-05-28 01:43:14 -03:00
8caf8b53a6 Merge pull request 'fix: tentar sem replicaset' (#26) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m30s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/26
2025-05-28 03:23:06 +00:00
Ricardo Carneiro
f8e7abd7d8 fix: tentar sem replicaset 2025-05-28 00:22:33 -03:00
21f8ddfe33 Merge pull request 'fix: tesntar conectar pelo ip do mongo' (#25) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m29s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/25
2025-05-28 02:57:18 +00:00
Ricardo Carneiro
bb9a47f828 fix: tesntar conectar pelo ip do mongo 2025-05-27 23:56:51 -03:00
332764d415 Merge pull request 'fix: tentando com docker internal' (#24) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m37s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/24
2025-05-28 02:53:10 +00:00
Ricardo Carneiro
850f6670ef fix: tentando com docker internal 2025-05-27 23:52:46 -03:00
79716452ff Merge pull request 'fix: tentar conectar via host' (#23) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 48s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/23
2025-05-28 02:47:51 +00:00
Ricardo Carneiro
e961bd6994 fix: tentar conectar via host 2025-05-27 23:43:38 -03:00
2573698256 Merge pull request 'fix: conexão local por IPV4' (#22) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m30s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/22
2025-05-28 02:35:57 +00:00
Ricardo Carneiro
4f88830c8c fix: conexão local por IPV4 2025-05-27 23:35:31 -03:00
5cf7136bc7 Merge pull request 'fix: change db name' (#21) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m26s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/21
2025-05-28 02:17:27 +00:00
Ricardo Carneiro
bb9a1b17dc fix: change db name 2025-05-27 23:17:02 -03:00
84a572af68 Merge pull request 'fix: ajustes para tentar rodar' (#20) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m30s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/20
2025-05-28 02:13:15 +00:00
Ricardo Carneiro
a906fe5f95 fix: ajustes para tentar rodar 2025-05-27 23:12:50 -03:00
65f681a35a Merge pull request 'fix: ajustar porta' (#19) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 53s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/19
2025-05-28 02:00:35 +00:00
Ricardo Carneiro
dffae34b28 fix: ajustar porta 2025-05-27 23:00:07 -03:00
ef53dae1b1 Merge pull request 'fix: porta 8080 em prod após deploy' (#18) from release/V1.0.0 into main
Some checks failed
Build and Deploy ASP.NET API / build-and-deploy (push) Failing after 46s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/18
2025-05-28 01:57:33 +00:00
Ricardo Carneiro
4f5777d6c1 fix: porta 8080 em prod após deploy 2025-05-27 22:56:59 -03:00
dcaafa36b7 Merge pull request 'fix: tentar logar no console quando houver problema no Seq' (#17) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m31s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/17
2025-05-28 01:46:12 +00:00
Ricardo Carneiro
5b67989599 fix: tentar logar no console quando houver problema no Seq 2025-05-27 22:45:45 -03:00
3b13014d4d Merge pull request 'fix: exibir stacktrace' (#16) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m36s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/16
2025-05-28 01:41:09 +00:00
Ricardo Carneiro
74c1e1472b fix: exibir stacktrace 2025-05-27 22:40:36 -03:00
42d937f1af Merge pull request 'fix: timeout Seq' (#15) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m37s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/15
2025-05-28 01:36:29 +00:00
Ricardo Carneiro
390494c606 fix: timeout Seq 2025-05-27 22:36:03 -03:00
5867a882c6 Merge pull request 'fix: ajuste de porta' (#14) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m29s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/14
2025-05-28 01:19:06 +00:00
Ricardo Carneiro
2784b6f2e2 fix: ajuste de porta 2025-05-27 22:18:33 -03:00
6a86d8b7c6 Merge pull request 'fix: logs' (#13) from release/V1.0.0 into main
Some checks failed
Build and Deploy ASP.NET API / build-and-deploy (push) Has been cancelled
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/13
2025-05-28 01:17:33 +00:00
Ricardo Carneiro
3a1497cdf5 fix: logs 2025-05-27 22:16:55 -03:00
092ea916b9 Merge pull request 'fix: seq disponivel eventualmente.' (#12) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 1m25s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/12
2025-05-27 13:54:42 +00:00
Ricardo Carneiro
8fd4a3633f fix: seq disponivel eventualmente. 2025-05-27 10:46:39 -03:00
c5f41ab396 Merge pull request 'build arm64' (#11) from release/V1.0.0 into main
All checks were successful
Build and Deploy ASP.NET API / build-and-deploy (push) Successful in 3m21s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/11
2025-05-27 13:20:17 +00:00
Ricardo Carneiro
50c9786452 fix: build direto no vps 2025-05-27 10:19:50 -03:00
eaca6748b3 Merge pull request 'fix: build para arm64' (#10) from release/V1.0.0 into main
Some checks failed
Build and Deploy ASP.NET API / build-and-deploy (push) Failing after 15s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/10
2025-05-27 13:07:21 +00:00
Ricardo Carneiro
99062b78ec fix: build para arm64 2025-05-27 10:06:33 -03:00
3d26277381 Merge pull request 'release/V1.0.0' (#9) from release/V1.0.0 into main
Some checks failed
Build and Deploy ASP.NET API / build-and-deploy (push) Failing after 3m4s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/9
2025-05-27 12:55:08 +00:00
Ricardo Carneiro
b2bd5aaca4 fix: docker build 2025-05-27 09:54:45 -03:00
Ricardo Carneiro
ae5a32afaa fix: novo dockerfile 2025-05-27 09:54:09 -03:00
ca438c9016 Merge pull request 'fix: build do docker. Tentando indicar o arquivo.' (#8) from release/V1.0.0 into main
Some checks failed
Build and Deploy ASP.NET API / build-and-deploy (push) Failing after 1m27s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/8
2025-05-27 12:40:07 +00:00
Ricardo Carneiro
7b3aba06ac fix: build do docker. Tentando indicar o arquivo. 2025-05-27 09:39:16 -03:00
f1c07cea8e Merge pull request 'fix: misturar versãoes' (#7) from release/V1.0.0 into main
Some checks failed
Build and Deploy ASP.NET API / build-and-deploy (push) Failing after 0s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/7
2025-05-27 04:03:58 +00:00
Ricardo Carneiro
7fb00d3efc fix: misturar versãoes 2025-05-27 01:03:29 -03:00
ab01f8e7fb Merge pull request 'fix: enviar arquivos' (#6) from release/V1.0.0 into main
Some checks failed
Build and Deploy ASP.NET API / build-and-deploy (push) Failing after 0s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/6
2025-05-27 03:57:18 +00:00
Ricardo Carneiro
3112fe12de fix: enviar arquivos 2025-05-27 00:56:52 -03:00
0ed6a475ad Merge pull request 'fix: novo ajuste no pipeline' (#5) from release/V1.0.0 into main
Some checks failed
Build and Deploy ASP.NET API / build-and-deploy (push) Failing after 0s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/5
2025-05-27 03:54:30 +00:00
Ricardo Carneiro
e289ab4e7f fix: novo ajuste no pipeline 2025-05-27 00:54:03 -03:00
84902d211e Merge pull request 'fix: pipeline' (#4) from release/V1.0.0 into main
Some checks failed
Build and Deploy ASP.NET API / build-and-deploy (push) Failing after 0s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/4
2025-05-27 03:51:31 +00:00
Ricardo Carneiro
df22460df7 fix: pipeline 2025-05-27 00:50:56 -03:00
75523a50d0 Merge pull request 'release/V1.0.0' (#3) from release/V1.0.0 into main
Some checks failed
Build and Deploy ASP.NET API / build-and-deploy (push) Failing after 35s
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/3
2025-05-27 03:39:23 +00:00
Ricardo Carneiro
4fa52762ee fix: publish 2025-05-27 00:38:15 -03:00
Ricardo Carneiro
314e61eef7 fix: runner name
Some checks failed
CI/CD Pipeline para YTExtractor / build (push) Failing after 1m19s
CI/CD Pipeline para YTExtractor / deploy-localACDC (push) Has been skipped
CI/CD Pipeline para YTExtractor / deploy-pi2Zero (push) Has been skipped
2025-05-05 21:24:48 -03:00
ce2aed7347 Merge pull request 'release/V1.0.0' (#2) from release/V1.0.0 into main
Some checks failed
CI/CD Pipeline para YTExtractor / build (push) Has been cancelled
CI/CD Pipeline para YTExtractor / deploy-localACDC (push) Has been cancelled
CI/CD Pipeline para YTExtractor / deploy-pi2Zero (push) Has been cancelled
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/2
2025-05-06 00:21:17 +00:00
Ricardo Carneiro
3d297b2055 fix: foldername
Some checks failed
CI/CD Pipeline para YTExtractor / build (push) Has been cancelled
CI/CD Pipeline para YTExtractor / build (pull_request) Has been cancelled
CI/CD Pipeline para YTExtractor / deploy-localACDC (push) Has been cancelled
CI/CD Pipeline para YTExtractor / deploy-pi2Zero (push) Has been cancelled
CI/CD Pipeline para YTExtractor / deploy-localACDC (pull_request) Has been cancelled
CI/CD Pipeline para YTExtractor / deploy-pi2Zero (pull_request) Has been cancelled
2025-05-05 21:15:40 -03:00
Ricardo Carneiro
253d098144 fix: s da pasta workflows 2025-05-05 21:11:15 -03:00
df2dcb124a Merge pull request 'release/V1.0.0' (#1) from release/V1.0.0 into main
Reviewed-on: http://git.carneiro.ddnsfree.com/ricardo/YTExtractor/pulls/1
2025-05-06 00:03:53 +00:00
Ricardo Carneiro
0652bff092 fix: rename pipelne file com yaml 2025-05-05 20:56:26 -03:00
Ricardo Carneiro
f8d1e16500 fix: run pipeline 2025-05-05 20:54:26 -03:00
Ricardo Carneiro
61f7cebe2f fix: pipeline na raiz 2025-05-05 20:47:06 -03:00
14 changed files with 305 additions and 125 deletions

114
.gitea/workflows/deploy.yml Normal file
View File

@ -0,0 +1,114 @@
name: Build and Deploy ASP.NET API
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: localACDC
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x' # ou sua versão
- name: Restore dependencies
run: dotnet restore
- name: Build application
run: dotnet build --configuration Release --no-restore
- name: Run tests (opcional)
run: dotnet test --no-build --verbosity normal
- name: Publish application
run: dotnet publish --configuration Release --output ./publish
# - name: Build Docker image for ARM64
# run: |
# # Criar builder se não existir
# docker buildx create --name arm-builder --use --platform linux/arm64 || docker buildx use arm-builder
# # Build específico para ARM64
# docker buildx build \
# --platform linux/arm64 \
# --tag registry.redecarneir.us/ytextractor:latest \
# --tag registry.redecarneir.us/ytextractor:${{ github.sha }} \
# -f YTExtractor/Dockerfile \
# --push .
# - name: Build Docker image 1
# run: |
# docker build -t ytextractor:${{ github.sha }} -f YTExtractor/Dockerfile .
# docker tag ytextractor:${{ github.sha }} registry.redecarneir.us/ytextractor:latest
# docker tag ytextractor:${{ github.sha }} registry.redecarneir.us/ytextractor:${{ github.sha }}
# - name: Push to registry
# run: |
# COMMIT_SHA=$(git rev-parse --short HEAD)
# docker push registry.redecarneir.us/ytextractor:latest
# docker push registry.redecarneir.us/ytextractor:${{ github.sha }}
# - name: Deploy to remote VPS
# run: |
# ssh -o StrictHostKeyChecking=no ubuntu@137.131.63.61 << 'EOF'
# # Pull da nova imagem
# docker pull registry.redecarneir.us/ytextractor:latest
# # Parar container atual se existir
# docker stop ytextractor-api || true
# docker rm ytextractor-api || true
# # Rodar novo container em produção
# # Porta 80 interna (do container) mapeada para 5000 externa
# docker run -d \
# --name ytextractor-api \
# --restart unless-stopped \
# -p 5000:80 \
# -e ASPNETCORE_ENVIRONMENT=Production \
# -v /tmp/ytextractor:/app/temp \
# registry.redecarneir.us/ytextractor:latest
# # Verificar se está rodando
# sleep 5
# docker ps | grep ytextractor-api
# # Limpeza de imagens antigas (opcional)
# docker image prune -f
# EOF
- name: Deploy and build on VPS
run: |
# Enviar código para VPS
rsync -avz --delete \
--exclude '.git' \
--exclude 'bin' \
--exclude 'obj' \
./ ubuntu@137.131.63.61:~/ytextractor/
# Build no VPS (que já é ARM64)
ssh ubuntu@137.131.63.61 << 'EOF'
cd ~/ytextractor
docker build -t registry.redecarneir.us/ytextractor:latest -f YTExtractor/Dockerfile .
docker stop ytextractor-api || true
docker rm ytextractor-api || true
docker run -d \
--name ytextractor-api \
--restart unless-stopped \
-p 8082:8080 \
--add-host="k3sw2:172.17.0.1" \
--add-host="k3ss1:172.17.0.1" \
-e ASPNETCORE_ENVIRONMENT=Production \
-v /tmp/ytextractor:/app/temp \
registry.redecarneir.us/ytextractor:latest
EOF
- name: Verify deployment
run: |
ssh ubuntu@137.131.63.61 'docker ps | grep ytextractor-api'
echo "✅ Deploy completed successfully!"

View File

@ -5,6 +5,11 @@ VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YTExtractor", "YTExtractor\YTExtractor.csproj", "{7DA7D783-153F-42EF-87E4-239DEC80F91A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "pipeline", "pipeline", "{5F17A7E6-48F5-4970-B8F6-310BBF9A3C50}"
ProjectSection(SolutionItems) = preProject
.gitea\workflows\deploy.yml = .gitea\workflows\deploy.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

View File

@ -1,99 +0,0 @@
name: CI/CD Pipeline para YTExtractor
on:
push:
branches: [ main, 'release/*' ]
pull_request:
branches: [ main, 'release/*' ]
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: .
push: false
load: true
tags: ytextractor:${{ github.sha }}
platforms: linux/amd64,linux/arm64
- name: Save Docker image
run: docker save ytextractor:${{ github.sha }} > ytextractor-image.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: docker-image
path: ytextractor-image.tar
deploy-localACDC:
needs: build
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/main'
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: docker-image
- name: Deploy to localACDC
run: |
echo "Implantando no servidor localACDC"
scp ytextractor-image.tar user@localACDC:/tmp/
ssh user@localACDC "docker load < /tmp/ytextractor-image.tar && \
docker stop ytextractor || true && \
docker rm ytextractor || true && \
docker run -d --name ytextractor -p 80:80 ytextractor:${{ github.sha }}"
deploy-pi2Zero:
needs: build
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/heads/release/')
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: docker-image
- name: Deploy to pi2Zero (Orange Pi Zero)
run: |
echo "Implantando no Orange Pi Zero (recursos limitados)"
# Transfere a imagem para o servidor
scp ytextractor-image.tar user@pi2Zero:/tmp/
# Comandos específicos para o Orange Pi Zero (otimizados para baixa memória)
ssh user@pi2Zero "
# Limpar recursos não utilizados
docker system prune -f
# Parar e remover contêiner existente
docker stop ytextractor || true
docker rm ytextractor || true
# Carregar a nova imagem
docker load < /tmp/ytextractor-image.tar
# Iniciar o serviço com limites de memória
docker run -d --name ytextractor -p 80:80 --memory=300m --memory-swap=600m ytextractor:${{ github.sha }}
"

View File

@ -7,11 +7,15 @@ namespace YTExtractor.Data
private readonly IMongoDatabase _database;
private readonly IMongoCollection<VideoData> _collection;
public MongoDBConnector(IConfiguration configuration)
public MongoDBConnector(IConfiguration configuration, Serilog.ILogger logger)
{
var connectionString = configuration.GetSection("MongoDbConnection").Value;
var databaseName = configuration.GetSection("MongoDbDatabase").Value;
logger.Information($"ConnString: {connectionString}");
logger.Information($"DbName: {databaseName}");
var client = new MongoClient(connectionString);
_database = client.GetDatabase("YTExtractor");
_database = client.GetDatabase(databaseName);
_collection = _database.GetCollection<VideoData>("videos");
}

View File

@ -1,16 +1,19 @@
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore
RUN dotnet publish -c Release -o /app
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app .
# Install yt-dlp with --break-system-packages flag (necessário no Debian 12)
RUN apt-get update && \
apt-get install -y python3-pip && \
pip3 install yt-dlp && \
pip3 install --break-system-packages yt-dlp && \
mkdir /app/temp && \
chmod 777 /app/temp && \
which yt-dlp || (echo "yt-dlp not found" && exit 1)

View File

@ -7,24 +7,119 @@ namespace YTExtractor.Logging.Configuration
{
public static class SerilogConfiguration
{
public static LoggerConfiguration SetLoggerConfiguration(this WebApplicationBuilder builder, LoggerConfiguration config, IServiceProvider services, IConfiguration configuration)
public static LoggerConfiguration SetLoggerConfiguration(
this WebApplicationBuilder builder,
LoggerConfiguration config,
IServiceProvider services,
IConfiguration configuration)
{
var workspace = configuration["Serilog:Properties:Workspace"];
var seqServer = configuration.GetValue<string>("Serilog:WriteTo:2:Args:serverUrl"); ;
var seqServer = configuration.GetValue<string>("Serilog:WriteTo:2:Args:serverUrl");
config
.ReadFrom.Configuration(configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.Enrich.WithEnvironmentName()
//.Enrich.WithMachineName()
.Enrich.WithProperty("Application", "SumaTube")
.Enrich.WithProperty("Workspace", workspace)
.WriteTo.Seq(seqServer)
;
try
{
// Usa a configuração do appsettings.json (mais elegante)
config
.ReadFrom.Configuration(configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.Enrich.WithEnvironmentName()
//.Enrich.WithMachineName()
.Enrich.WithProperty("Application", "YTExtractor")
.Enrich.WithProperty("Workspace", workspace)
.WriteTo.Console();
return config;
// Testa a conectividade com o Seq se estiver configurado
if (!string.IsNullOrEmpty(seqServer))
{
TestSeqConnectivity(seqServer);
}
Console.WriteLine("✅ Serilog configurado com sucesso a partir do appsettings.json");
if (!string.IsNullOrEmpty(seqServer))
{
Console.WriteLine($"✅ Seq configurado: {seqServer}");
}
return config;
}
catch (Exception ex)
{
Console.WriteLine($"❌ ERRO ao configurar Serilog: {ex.Message}");
Console.WriteLine("🔄 Tentando configuração de fallback...");
// Configuração de fallback se a configuração principal falhar
return CreateFallbackConfiguration(config, workspace, seqServer);
}
}
private static LoggerConfiguration CreateFallbackConfiguration(
LoggerConfiguration config,
string workspace,
string seqServer)
{
try
{
config
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
.Enrich.FromLogContext()
.Enrich.WithEnvironmentName()
.Enrich.WithProperty("Application", "YTExtractor")
.Enrich.WithProperty("Workspace", workspace ?? "Unknown")
.WriteTo.Console()
.WriteTo.File("logs/fallback-app-.log", rollingInterval: RollingInterval.Day);
// Tenta adicionar o Seq apenas se a URL estiver disponível
if (!string.IsNullOrEmpty(seqServer))
{
try
{
config.WriteTo.Seq(seqServer);
Console.WriteLine($"✅ Seq configurado no fallback: {seqServer}");
}
catch (Exception seqEx)
{
Console.WriteLine($"⚠️ AVISO: Seq não pôde ser configurado no fallback: {seqEx.Message}");
Console.WriteLine("📝 Continuando apenas com console e arquivo de log");
}
}
Console.WriteLine("✅ Configuração de fallback aplicada com sucesso");
return config;
}
catch (Exception fallbackEx)
{
Console.WriteLine($"❌ ERRO CRÍTICO: Falha na configuração de fallback: {fallbackEx.Message}");
throw; // Re-throw porque se o fallback falhar, temos um problema sério
}
}
private static void TestSeqConnectivity(string seqUrl)
{
try
{
using var httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(10);
var response = httpClient.GetAsync($"{seqUrl}/api").Result;
if (response.IsSuccessStatusCode)
{
Console.WriteLine($"🌐 Conectividade com Seq OK: {seqUrl}");
}
else
{
Console.WriteLine($"⚠️ Seq configurado mas pode não estar respondendo: {response.StatusCode}");
}
}
catch (Exception ex)
{
Console.WriteLine($"⚠️ Seq configurado mas conexão falhou: {ex.Message}");
Console.WriteLine($" StackTrace: {ex.StackTrace}");
Console.WriteLine($"💡 Dica: Verifique se o Seq está rodando em {seqUrl}");
throw new Exception("Erro ao configurar Seq. Configurar console.", ex);
}
}
}
}

View File

@ -42,9 +42,11 @@ app.MapPost("/api/video-info", async (VideoRequest request, MongoDBConnector mon
{
try
{
Log.Information("Requisição recebida");
if (!youtubeService.IsValidYouTubeUrl(request.Url))
return Results.BadRequest("Invalid YouTube URL");
Log.Information("Obtendo pasta atual");
var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempDir);
@ -52,9 +54,11 @@ app.MapPost("/api/video-info", async (VideoRequest request, MongoDBConnector mon
{
Log.Information($"Obtendo dados do video: {request.Url}");
var service = new ConvertTranscriptService();
Log.Information("Obtendo dados da url no mongo");
var videoExists = await mongo.GetVideoByUrl(request.Url);
if (videoExists != null)
{
Log.Information($"Retorno via mongo db da url: {request.Url}");
return Results.Ok(new VideoInfo(
videoExists.Url,
videoExists.Titulo,
@ -63,9 +67,11 @@ app.MapPost("/api/video-info", async (VideoRequest request, MongoDBConnector mon
));
}
Log.Information("Obtendo dados da url na api do youtube");
var info = await youtubeService.GetVideoInfo(request.Url, tempDir);
var subtitles = service.ExtractPlainText(await youtubeService.GetSubtitles(request.Url, request.Language, tempDir));
Log.Information("Guardar no mongodb");
await mongo.InsertVideo(new VideoData
{
Id = Guid.NewGuid().ToString(),

View File

@ -21,10 +21,24 @@ namespace YTExtractor.Services.Handlers
{
_logger.LogInformation("Getting video info using yt-dlp for {Url}", url);
var arguments = $"--dump-json " +
$"--user-agent \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\" " +
$"--add-header \"Accept-Language:pt-BR,pt;q=0.9,en;q=0.8\" " +
$"--add-header \"Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\" " +
$"--add-header \"Accept-Encoding:gzip, deflate, br\" " +
$"--add-header \"DNT:1\" " +
$"--add-header \"Connection:keep-alive\" " +
$"--add-header \"Upgrade-Insecure-Requests:1\" " +
$"--no-check-certificate " +
$"--extractor-retries 3 " +
$"--socket-timeout 30 " +
$"{url}";
var startInfo = new ProcessStartInfo
{
FileName = "yt-dlp",
Arguments = $"--dump-json {url}",
//Arguments = $"--dump-json {url}",
Arguments = arguments,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,

View File

@ -16,8 +16,12 @@ namespace YTExtractor.Services.YoutubeExplode
public YoutubeExplodeClient(ILogger<YoutubeExplodeClient> logger)
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");
httpClient.DefaultRequestHeaders.Add("Accept-Language", "pt-BR,pt;q=0.9,en;q=0.8");
_logger = logger;
_youtube = new YoutubeClient();
_youtube = new YoutubeClient(httpClient);
}
/// <summary>

View File

@ -10,6 +10,10 @@
<Compile Remove="Services\Handlers\YouExposeHandler.cs" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="appsettings.Production.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.69.0.3707" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.12" />

View File

@ -23,5 +23,7 @@
"Workspace": "Dev",
"Application": "YTExtractor"
}
}
},
"MongoDbConnection": "mongodb://admin:c4rn31r0@192.168.0.82:27017,192.168.0.81:27017/?replicaSet=rs0",
"MongoDbDatabase": "YTExtractor"
}

View File

@ -0,0 +1,31 @@
{
"Serilog": {
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "logs/prod-app-.log",
"rollingInterval": "Day"
}
},
{
"Name": "Seq",
"Args": {
"serverUrl": "http://localhost:5341",
"compact": true,
"batchPostingLimit": 100
}
}
],
"Properties": {
"Environment": "Production",
"Workspace": "VPS",
"Application": "YTExtractor"
}
},
"AllowedHosts": "*",
//"MongoDbConnection": "mongodb://admin:c4rn31r0@172.17.0.1:27017,172.17.0.1:27018/?replicaSet=rs0",
"MongoDbConnection": "mongodb://admin:c4rn31r0@k3sw2:27017,k3ss1:27018/?replicaSet=rs0",
"MongoDbDatabase": "YTExtractor-Prod"
}

View File

@ -20,8 +20,5 @@
},
"AllowedHosts": "*",
"MongoDbConnection": "mongodb://admin:c4rn31r0@192.168.0.82:27017,192.168.0.81:27017/?replicaSet=rs0",
"YouExpose": {
"ApiKey": "sua-chave-api-aqui",
"ApiUrl": "https://api.youexpose.com/"
}
"MongoDbDatabase": "YTExtractor"
}