|
from playwright.sync_api import Playwright, sync_playwright, expect |
|
from time import sleep |
|
from shutil import copyfile |
|
|
|
# from ffmpeg import FFmpeg |
|
|
|
|
|
# Function to run the audio enhancement process using Adobe Podcast |
|
def run(playwright: Playwright, FILE) -> None: |
|
# Launch the chromium browser |
|
browser = playwright.chromium.launch(headless=False) |
|
|
|
# Create a new context with saved authentication information |
|
# For first-time users, sign in manually and save the session and cookies using the command: |
|
# playwright codegen --save-storage=auth.json https://podcast.adobe.com/enhance# |
|
# More details: https://playwright.dev/python/docs/cli#preserve-authenticated-state |
|
context = browser.new_context(storage_state="auth.json") |
|
page = context.new_page() |
|
# Go to the Adobe Podcast enhance page |
|
page.goto("https://podcast.adobe.com/enhance#") |
|
# Upload the audio file |
|
# page.get_by_role("button", name="Choose files").set_input_files(FILE) |
|
sleep(5) |
|
page.query_selector("#enhance-file-upload").set_input_files(FILE) |
|
print("Reached this") |
|
# Wait for the "Download" button to become available |
|
page.get_by_role("button", name="Download").wait_for(timeout=600000) |
|
|
|
print("Downloading the enhanced file") |
|
# Triggers the download of the enhanced file and gets its info |
|
with page.expect_download() as download_info: |
|
# Perform the action that initiates download |
|
page.get_by_role("button", name="Download").click() |
|
download = download_info.value |
|
# Waits for the download process to complete |
|
print(download.path()) |
|
# Converts the enhanced audio from WAV to MP3 using FFmpeg |
|
print("doint the ffmpeg thing") |
|
# ffmpeg = FFmpeg().input(.output(FILE[:-4] + " (enhanced).mp3", acodec="mp3") |
|
# ffmpeg.execute() |
|
|
|
# copy file from download.path() into same directory as this script |
|
copyfile(download.path(), "output.mp3") |
|
|
|
# --------------------- |
|
# Closes the context and browser instance |
|
context.close() |
|
browser.close() |
|
|
|
|
|
with sync_playwright() as playwright: |
|
# Prompts the user for the audio file to enhance |
|
# FILE = input("Which file would you like to enhance? ") |
|
run(playwright, "thingy.mp3") |
Loving this