Skip to content

Commit

Permalink
fix: finding uploaded audio link
Browse files Browse the repository at this point in the history
  • Loading branch information
onur-yildiz committed Aug 8, 2022
1 parent e63f1d1 commit b85581b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Puppeteer/Puppet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public static async Task<string> CutAndUploadAudio(string name, string url, stri
var client = await page.Target.CreateCDPSessionAsync();
var mouse = new Mouse(client, page.Keyboard);

var uniqueName = name + Guid.NewGuid().ToString();

Console.Clear();
await Login(page);
await Upload(page, name);
return await ExtractURL(page);
await Upload(page, uniqueName);
return await ExtractURL(page, uniqueName);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -63,7 +65,7 @@ static async Task Login(Page page)
static async Task Upload(Page page, string name)
{
Console.WriteLine("Uploading audio...");
await page.TypeAsync("#id_name", name + Guid.NewGuid().ToString());
await page.TypeAsync("#id_name", name);
var fileChooserDialogTask = page.WaitForFileChooserAsync();
await Task.WhenAll(fileChooserDialogTask, page.ClickAsync("input[name=sound]"));
var fileChooser = await fileChooserDialogTask;
Expand All @@ -78,14 +80,15 @@ static async Task Upload(Page page, string name)
Console.WriteLine("Uploaded Audio.");
}

static async Task<string> ExtractURL(Page page)
static async Task<string> ExtractURL(Page page, string name)
{
Console.WriteLine("Navigating to the audio page...");
await page.EvaluateFunctionAsync(@"
() => {
const audioList = document.querySelectorAll('a.instant-link');
audioList[audioList.length -1].click();
}
await page.EvaluateFunctionAsync($@"
() => {{
const audioList = document.querySelectorAll('a.instant-link');
const link = Array.from(audioList).find(a => a.innerText === '{name}')
link.click();
}}
");

//await page.WaitForNavigationAsync();
Expand Down

0 comments on commit b85581b

Please sign in to comment.