Skip to content

Commit

Permalink
Complete Generator PlayList
Browse files Browse the repository at this point in the history
  • Loading branch information
MaKrotos committed Sep 26, 2024
1 parent 0ecf411 commit 565fc6f
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 146 deletions.
2 changes: 1 addition & 1 deletion VK UI3/Controls/PlaylistControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<MenuFlyoutItem
x:Name="GenerateAlbum"
Click="GenerateAlbum_Click"
Text="Сгенерировать альбом">
Text="Сгенерировать плейлист">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xEB44;" />
</MenuFlyoutItem.Icon>
Expand Down
8 changes: 2 additions & 6 deletions VK UI3/Controls/PlaylistControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,8 @@ private async void DeleteAlbum_Click(object sender, RoutedEventArgs e)

private async void GenerateAlbum_Click(object sender, RoutedEventArgs e)
{

var pla = await VK.vkService.GetPlaylistAsync(1000, _PlayList.Id, _PlayList.AccessKey, _PlayList.OwnerId);

List<Audio> track_playlist = new List<VkNet.Model.Attachments.Audio>(pla.Audios.Cast<VkNet.Model.Attachments.Audio>().ToList());
var Generator = new Services.GeneratorAlbumVK(track_playlist, _PlayList.Id.ToString());
Generator.GenerateAsync();
MainView.mainView.openGenerator(_PlayList, unicID: $"playlist_{_PlayList.OwnerId}_{_PlayList.Id}", genBy: $"genBy {_PlayList.Title}");


}
}
Expand Down
2 changes: 0 additions & 2 deletions VK UI3/Controls/RecommsPlaylist.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,7 @@ private void editAlbum_Click(object sender, RoutedEventArgs e)
{
ContentDialog dialog = new CustomDialog();

// XamlRoot must be set in the case of a ContentDialog running in a Desktop app
dialog.XamlRoot = this.XamlRoot;
// Add transitions (e.g., PopupThemeTransition)
dialog.Transitions = new TransitionCollection
{
new PopupThemeTransition()
Expand Down
99 changes: 9 additions & 90 deletions VK UI3/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Animation;
using Microsoft.UI.Xaml.Navigation;
using MusicX.Core.Models;
using SetupLib;
using System;
using System.Collections.Generic;
Expand All @@ -21,10 +22,13 @@
using VK_UI3.DownloadTrack;
using VK_UI3.Views;
using VK_UI3.Views.LoginWindow;
using VK_UI3.Views.ModalsPages;
using VK_UI3.Views.Upload;
using VK_UI3.VKs;
using VK_UI3.VKs.IVK;
using Windows.ApplicationModel;
using Windows.Foundation;
using Windows.Media.Playlists;
using Windows.UI.ViewManagement;
using Windows.Win32;
using Windows.Win32.Foundation;
Expand Down Expand Up @@ -170,64 +174,7 @@ private void ResizeTabBar()
SetRegionsForCustomTitleBar();
}

public void AnimateButtonShow(Button button)
{
DoubleAnimation widthAnimation = new DoubleAnimation
{
From = 0,
To = 35,
Duration = new Duration(TimeSpan.FromSeconds(0.1))
};

DoubleAnimation heightAnimation = new DoubleAnimation
{
From = 0,
To = 35,
Duration = new Duration(TimeSpan.FromSeconds(0.1))
};

Storyboard.SetTarget(widthAnimation, button);
Storyboard.SetTargetProperty(widthAnimation, "Width");

Storyboard.SetTarget(heightAnimation, button);
Storyboard.SetTargetProperty(heightAnimation, "Height");

Storyboard storyboard = new Storyboard();
storyboard.Children.Add(widthAnimation);
storyboard.Children.Add(heightAnimation);

storyboard.Begin();
}

public void AnimateButtonHide(Button button)
{
DoubleAnimation widthAnimation = new DoubleAnimation
{
From = 0,
To = button.ActualWidth,
Duration = new Duration(TimeSpan.FromSeconds(0.1))
};

DoubleAnimation heightAnimation = new DoubleAnimation
{
From = 0,
To = button.ActualHeight,
Duration = new Duration(TimeSpan.FromSeconds(0.1))
};

Storyboard.SetTarget(widthAnimation, button);
Storyboard.SetTargetProperty(widthAnimation, "Width");

Storyboard.SetTarget(heightAnimation, button);
Storyboard.SetTargetProperty(heightAnimation, "Height");

Storyboard storyboard = new Storyboard();
storyboard.Children.Add(widthAnimation);
storyboard.Children.Add(heightAnimation);

storyboard.Begin();
}





Expand Down Expand Up @@ -428,38 +375,7 @@ private void SetRegionsForCustomTitleBar()
}


public async Task AnimateButtonSize(Button button, double newWidth, double newHeight, TimeSpan duration)
{
// Сохраните исходные размеры кнопки
double originalWidth = button.Width;
double originalHeight = button.Height;

// Вычислите шаги изменения размера
double widthStep = (newWidth - originalWidth) / duration.TotalMilliseconds;
double heightStep = (newHeight - originalHeight) / duration.TotalMilliseconds;

// Создайте таймер для анимации
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();

while (stopwatch.Elapsed < duration)
{
// Вычислите новые размеры
double elapsedMilliseconds = stopwatch.Elapsed.TotalMilliseconds;
button.Width = originalWidth + widthStep * elapsedMilliseconds;
button.Height = originalHeight + heightStep * elapsedMilliseconds;

// Обновите интерфейс
await Task.Delay(1);
}

// Установите окончательные размеры
button.Width = newWidth;
button.Height = newHeight;

stopwatch.Stop();
}


private Windows.Graphics.RectInt32 GetRect(Rect bounds, double scale)
{
return new Windows.Graphics.RectInt32(
Expand Down Expand Up @@ -707,6 +623,9 @@ private void DownLoadBTN_Click(object sender, RoutedEventArgs e)

onDownloadClicked?.RaiseEvent(this, EventArgs.Empty);
}




internal async Task requstDownloadFFMpegAsync()
{
Expand Down
43 changes: 30 additions & 13 deletions VK UI3/Services/GeneratorAlbumVK.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using MusicX.Core.Models.Genius;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using VK_UI3.DB;
using VK_UI3.Views;
using VK_UI3.Views.Tasks;
using VK_UI3.VKs;
Expand All @@ -23,26 +25,42 @@ public class GeneratorAlbumVK : TaskAction
private bool isPaused = false;
private object pauseLock = new object();
private int deepGen = 1;
private string description;

public GeneratorAlbumVK(List<Audio> audios, string unicId, int count = 1000, string name = null, int deepGen = 1) : base(audios.Count, "Генерация плейлиста", unicId, name)
public string CoverPath { get; private set; }

public GeneratorAlbumVK(List<Audio> audios, string unicId = null, int count = 1000, string name = null, int deepGen = 1, string description = null, bool noDiscover = true, string CoverPath = null) : base(audios.Count, "Генерация плейлиста", unicId, name)
{
this.audios = audios;
base.total = audios.Count();
this.count = count;
this.name = name;
this.deepGen = deepGen;
this.description = description;
this.CoverPath = CoverPath;
}

public GeneratorAlbumVK(IVKGetAudio audios, string unicId, int count = 1000, string name = null, int deepGen = 1) : base((int?) (audios.countTracks) ?? 0, "Генерация плейлиста", unicId, name)
public GeneratorAlbumVK(IVKGetAudio audios, string unicId = null, string name = null, int deepGen = 1, string description = null, bool noDiscover = true, string CoverPath = null) : base((int?) (audios.countTracks) ?? 0, "Генерация плейлиста", unicId, name)
{
this.iVKGetAudio = audios;
base.total = (int?) (iVKGetAudio.countTracks) ?? 0;
this.count = count;
base.total = (int?)(iVKGetAudio.countTracks) ?? 0;
this.name = name;
this.deepGen = deepGen;
this.description = description;
this.CoverPath = CoverPath;
}

private async Task UploadCoverPlaylist()
{
if (!string.IsNullOrEmpty(CoverPath))
{
var uploadServer = await VK.vkService.GetPlaylistCoverUploadServerAsync(AccountsDB.activeAccount.id, audioPlaylist.Id);

var image = await VK.vkService.UploadPlaylistCoverAsync(uploadServer, CoverPath);

await VK.vkService.SetPlaylistCoverAsync(audioPlaylist.OwnerId, audioPlaylist.Id, image.Hash, image.Photo);
}
}

public async Task GenerateAsync()
{
Expand All @@ -62,7 +80,7 @@ private async Task getedListAsync()
{
var need = CalculateTracksToLoad(deepGen, (int) iVKGetAudio.countTracks);

while (iVKGetAudio.listAudio.Count > need && !iVKGetAudio.itsAll)
while (iVKGetAudio.listAudio.Count < need && !iVKGetAudio.itsAll)
{
await CheckForPauseAsync();
var tcs = new TaskCompletionSource<bool>();
Expand All @@ -77,8 +95,9 @@ private async Task getedListAsync()
iVKGetAudio.GetTracks();
await tcs.Task;
}
audios = new List<Audio>();
audios.AddRange(iVKGetAudio.listAudio.Select(item => item.audio));

total = audios.Count();
this.genByList();
}

Expand All @@ -93,11 +112,7 @@ private int CalculateTracksToLoad(int deepGen, int iVKGetAudioCount)
iVKGetAudioCount = maxTracks;
}

// Если total не задан, используем минимум
if (total == -1)
{
total = minTracks;
}


// Рассчитываем количество треков для подгрузки
int tracksToLoad = Math.Min(total, iVKGetAudioCount);
Expand All @@ -116,6 +131,7 @@ public async Task genByList()
{
try
{
if (total == 0) Cancel();
var mapRecs = new Dictionary<string, int>();

foreach (var item in audios)
Expand Down Expand Up @@ -160,7 +176,8 @@ public async Task genByList()
var sortedMapRecs = mapRecs.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
IEnumerable<string> top1000Tracks = sortedMapRecs.Keys.Take(this.count);

audioPlaylist = await VK.api.Audio.CreatePlaylistAsync(DB.AccountsDB.activeAccount.id, name ?? "Сгенерированный", audioIds: top1000Tracks);
audioPlaylist = await VK.api.Audio.CreatePlaylistAsync(DB.AccountsDB.activeAccount.id, name ?? "Сгенерированный", audioIds: top1000Tracks, description: description);
await UploadCoverPlaylist();
base.Status = Statuses.Completed;
}
else
Expand Down
57 changes: 55 additions & 2 deletions VK UI3/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.UI.Xaml.Navigation;
using MusicX.Core.Models;
using MusicX.Core.Services;
using Newtonsoft.Json.Bson;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -20,9 +19,11 @@
using VK_UI3.DB;
using VK_UI3.Helpers.Animations;
using VK_UI3.Services;
using VK_UI3.Views.ModalsPages;
using VK_UI3.VKs;
using VK_UI3.VKs.IVK;
using VkNet.Model.Attachments;
using Windows.Media.Playlists;
using static VK_UI3.DB.AccountsDB;
using static VK_UI3.Views.SectionView;

Expand Down Expand Up @@ -93,6 +94,58 @@ private void MainView_KeyDown(object sender, KeyRoutedEventArgs e)
}


public void openGenerator(IVKGetAudio iVKGetAudio , string unicID, string genBy = "genBy")
{
var a = new CreatePlayList(iVKGetAudio, genBy, unicID);
OpenGenerator(a);

}
public void openGenerator(AudioPlaylist playList, string unicID, string genBy = null)
{
var a = new CreatePlayList(playList, true, genBy, unicID);
OpenGenerator(a);
}
private void OpenGenerator(CreatePlayList createPlayList)
{

ContentDialog dialog = new CustomDialog();

dialog.XamlRoot = this.XamlRoot;
dialog.Transitions = new TransitionCollection
{
new PopupThemeTransition()
};



dialog.Content = createPlayList;
dialog.Background = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.Transparent);
EventHandler cancelPressedHandler = null;
cancelPressedHandler = (s, e) =>
{
try
{
if (dialog != null)
dialog.Hide();
dialog = null;
}
catch
{

}
finally
{
createPlayList.cancelPressed -= cancelPressedHandler;
}
};

createPlayList.cancelPressed += cancelPressedHandler;


dialog.ShowAsync();

}


private static DispatcherQueue dispatcherQueue = null;
private void MainView_Loaded(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -468,7 +521,7 @@ public static void OpenPlayList(long AlbumID, long AlbumOwnerID, string AlbumAcc
{
var sectionView = new WaitParameters();
sectionView.sectionType = SectionType.PlayList;
Playlist playlist = new Playlist();
MusicX.Core.Models.Playlist playlist = new MusicX.Core.Models.Playlist();
playlist.Id = AlbumID;
playlist.OwnerId = AlbumOwnerID;
playlist.AccessKey = AlbumAccessKey;
Expand Down
Loading

0 comments on commit 565fc6f

Please sign in to comment.