Skip to content

Commit

Permalink
Merge pull request #55 from pavel-zhur/feature/photos-instant
Browse files Browse the repository at this point in the history
Feature/photos instant
  • Loading branch information
pavel-zhur authored Sep 29, 2024
2 parents 26c997a + ac743c9 commit ac5e64b
Show file tree
Hide file tree
Showing 103 changed files with 31,915 additions and 407 deletions.
24 changes: 17 additions & 7 deletions OneShelf.Videos/OneShelf.Videos.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@
using Microsoft.Extensions.Hosting;
using OneShelf.Videos.BusinessLogic;
using OneShelf.Videos.BusinessLogic.Services;
using OneShelf.Videos.BusinessLogic.Services.Live;
using OneShelf.Videos.Database;

var builder = Host.CreateApplicationBuilder();
builder.Configuration.AddJsonFile("appsettings.Secrets.json");
builder.Services
.AddVideosBusinessLogic(builder.Configuration);
var host = builder.Build();
using var host = builder.Build();

var service1 = host.Services.GetRequiredService<Service1>();
var service2 = host.Services.GetRequiredService<Service2>();
var service3 = host.Services.GetRequiredService<Service3>();

var liveDownloader = host.Services.GetRequiredService<LiveDownloader>();
await using var videosDatabase = host.Services.GetRequiredService<VideosDatabase>();
await videosDatabase.Database.MigrateAsync();

//await videosDatabase.CreateMissingTopics();
//await videosDatabase.UpdateMessagesTopics();
//await videosDatabase.Database.MigrateAsync();

await service2.SaveInventory();
await liveDownloader.UpdateLive(true);
await videosDatabase.AppendTopics();
await videosDatabase.AppendMediae();
await videosDatabase.UpdateMediaTopics();
await service2.UploadPhotos(await service1.GetExportLivePhoto());
await service2.UploadVideos(await service1.GetExportLiveVideo());


//await videosDatabase.CreateMissingStaticTopics();
//await videosDatabase.UpdateStaticMessagesTopics();

//return;

Expand All @@ -40,4 +50,4 @@

//await service2.UploadPhotos((await service1.GetExport1()).OrderBy(_ => Random.Shared.NextDouble()).ToList());
//await service2.UploadVideos((await service1.GetExport2()).OrderBy(_ => Random.Shared.NextDouble()).ToList());
await service2.CreateAlbums(await service1.GetAlbums());
//await service2.CreateAlbums(await service1.GetAlbums());
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
public record VideosOptions
{
public required string BasePath { get; init; }

public required string TelegramAuthPath { get; init; }
public required string TelegramApiId { get; init; }
public required string TelegramApiHash { get; init; }
public required string TelegramPhoneNumber { get; init; }
public required IReadOnlyList<long> TelegramChatIds { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<PackageReference Include="CasCap.Apis.GooglePhotos" Version="3.0.1" />
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="ExifLibNet" Version="2.1.4" />
<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.1.2" />
<PackageReference Include="WTelegramClient" Version="4.1.9" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Options;
using OneShelf.Videos.BusinessLogic.Models;
using OneShelf.Videos.BusinessLogic.Services;
using OneShelf.Videos.BusinessLogic.Services.Live;
using OneShelf.Videos.Database;
using Polly;

Expand All @@ -19,7 +20,10 @@ public static IServiceCollection AddVideosBusinessLogic(this IServiceCollection
.Configure<VideosOptions>(o => configuration.GetSection(nameof(VideosOptions)).Bind(o))
.AddScoped<Service1>()
.AddScoped<Service2>()
.AddScoped<Service3>()
.AddScoped<ExifService>()
.AddScoped<LiveDownloader>()
.AddSingleton<TelegramLoggerInitializer>()
.AddSingleton<Paths>()
.AddScoped<VideosDatabaseOperations>()
.AddMyGooglePhotos();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using ExifLibrary;

namespace OneShelf.Videos.BusinessLogic.Services;

public class ExifService
{
public async Task<bool> SetExifTimestamp(string path, string tempFileName, DateTime timestamp)
{
var image = await ImageFile.FromFileAsync(path);
if (image.Errors.Any()) throw new($"Some image errors, {path}.");
if (image.Properties.Contains(ExifTag.DateTime))
{
File.Copy(path, tempFileName);
return false;
}

image.Properties.Set(ExifTag.DateTime, timestamp);
await image.SaveAsync(tempFileName);

return true;
}
}
Loading

0 comments on commit ac5e64b

Please sign in to comment.