diff --git a/readme.md b/readme.md index 34a8aa2..4236b1a 100644 --- a/readme.md +++ b/readme.md @@ -201,8 +201,8 @@ Worker files older than approximately **30 minutes** are cleaned up when relevan 1. Install the updated `requirements.txt` (or rebuild the Docker containers). 2. In Google Cloud Console, enable **YouTube Data API v3**, configure the OAuth consent screen and, while the app is in testing, add your Google account as a test user. Download an **OAuth client secret JSON** file. 3. Open **Video Studio → YouTube upload**, choose the JSON file, and click **Connect Google / YouTube**. Approve access to the desired channel. -4. Set a YouTube title (or leave it empty to use the video headline), description, comma-separated tags, visibility, and the made-for-kids setting. -5. Enable **Automatically upload after rendering**, then render. AutoMap uploads the resulting MP4 in the background and shows progress and a YouTube link. You can also click **Upload rendered video to YouTube** after rendering. Visibility defaults to **Private**; automatic upload must be enabled again on each visit. +4. The YouTube title follows the video topic by default (up to 100 characters). Disable **Use the video topic as the YouTube title** to enter a custom title. Set the description, comma-separated tags, visibility, and the made-for-kids setting. +5. Enable **Automatically upload after rendering**, then render. AutoMap uploads the resulting MP4 in the background and shows progress and a YouTube link. You can also click **Upload rendered video to YouTube** after rendering. Visibility defaults to **Private**. Metadata, custom title, title mode, and the automatic upload setting are saved in this browser and restored when you return. AutoMap renders vertical 9:16 videos lasting up to 30 seconds, which meet the [YouTube Shorts format requirements](https://support.google.com/youtube/answer/15424877?hl=en). @@ -225,8 +225,9 @@ Google tokens and client secrets are never sent back to the browser, saved in localStorage, or forwarded to the media worker. A signed browser session selects its own credentials and upload jobs. Sharing a browser profile shares this connection; clearing cookies, logging out, or changing the web login requires -connecting again. **Disconnect** deletes that browser's saved credentials; it +connecting again. **Sign out of YouTube** deletes that browser's saved credentials; it does not cancel an upload already started or revoke the grant in Google Account. +Sign in again to choose a different Google account. For persistent server storage, retain the `automap-session` Docker volume (it already mounts `/app/instance`). For native deployment, back up `instance/` and diff --git a/static/youtube-upload.js b/static/youtube-upload.js index 939448b..eaf6c52 100644 --- a/static/youtube-upload.js +++ b/static/youtube-upload.js @@ -2,10 +2,27 @@ let youtubeCsrf = ''; let youtubeConnected = false; let youtubePolling = 0; -const youtubeFields = ['youtubeTitle', 'youtubeDescription', 'youtubeTags', 'youtubePrivacy', 'youtubeKids']; +const youtubeFields = ['youtubeTitle', 'youtubeDescription', 'youtubeTags', 'youtubePrivacy', 'youtubeKids', 'youtubeAuto', 'youtubeUseTopic']; +let youtubeCustomTitle = ''; const ytElement = id => document.getElementById(id); +function syncYouTubeTitle() { + const input = ytElement('youtubeTitle'); + const useTopic = ytElement('youtubeUseTopic').checked; + input.readOnly = useTopic; + input.value = useTopic ? ytElement('videoTitleInput').value.replace(/\s+/g, ' ').trim().slice(0, 100) : youtubeCustomTitle; +} + +function saveYouTubeSettings() { + const settings = Object.fromEntries(youtubeFields.map(id => { + const input = ytElement(id); + return [id, id === 'youtubeTitle' ? youtubeCustomTitle : input.type === 'checkbox' ? input.checked : input.value]; + })); + try { localStorage.setItem('automap-youtube-settings', JSON.stringify(settings)); } catch {} +} + function youtubeSettings() { + syncYouTubeTitle(); const settings = { title: ytElement('youtubeTitle').value.trim() || ytElement('videoTitleInput').value.trim(), description: ytElement('youtubeDescription').value, @@ -29,13 +46,20 @@ async function loadYouTubeConnection() { if (!response.ok) throw new Error(result.error || 'Could not check YouTube connection.'); youtubeCsrf = result.csrf_token; youtubeConnected = result.connected; - ytElement('youtubeConnection').textContent = result.connected ? 'YouTube account connected.' : 'YouTube account not connected.'; + ytElement('youtubeSignOut').disabled = !result.connected; + const label = result.connected ? 'Signed in to YouTube' : 'Not signed in to YouTube'; + ytElement('youtubeConnection').textContent = label; + const badge = ytElement('youtubeConnectionBadge'); + badge.textContent = label; + badge.className = `ml-2 text-xs font-normal ${result.connected ? 'text-emerald-400' : 'text-amber-300'}`; ytElement('youtubeRedirect').textContent = result.redirect_uri; return result; })(); try { return await youtubeConnectionRequest; } catch (error) { ytElement('youtubeConnection').textContent = error.message; + ytElement('youtubeConnectionBadge').textContent = 'YouTube sign-in status unavailable'; + ytElement('youtubeConnectionBadge').className = 'ml-2 text-xs font-normal text-slate-400'; throw error; } finally { youtubeConnectionRequest = null; } } @@ -83,7 +107,9 @@ async function disconnectYouTube() { try { await youtubeRequest('/api/youtube/disconnect', {method: 'POST'}); ytElement('youtubeAuto').checked = false; + saveYouTubeSettings(); await loadYouTubeConnection(); + showToast('Signed out of YouTube. Sign in again to choose another Google account.', 'info'); } catch (error) { showToast(error.message, 'error'); } } @@ -135,17 +161,24 @@ document.addEventListener('DOMContentLoaded', () => { try { const saved = JSON.parse(localStorage.getItem('automap-youtube-settings') || '{}'); for (const id of youtubeFields) { - if (id === 'youtubeKids') ytElement(id).checked = saved[id] === true; - else if (typeof saved[id] === 'string') ytElement(id).value = saved[id]; + const input = ytElement(id); + if (input.type === 'checkbox') { + if (typeof saved[id] === 'boolean') input.checked = saved[id]; + } else if (typeof saved[id] === 'string') input.value = saved[id]; } const job = sessionStorage.getItem('automap-youtube-job'); if (job) watchYouTubeUpload(job); } catch {} - for (const id of youtubeFields) ytElement(id).addEventListener('input', () => { - const settings = Object.fromEntries(youtubeFields.map(key => [key, key === 'youtubeKids' ? ytElement(key).checked : ytElement(key).value])); - try { localStorage.setItem('automap-youtube-settings', JSON.stringify(settings)); } catch {} - }); - // Automatic upload is an explicit choice for each visit. + youtubeCustomTitle = ytElement('youtubeTitle').value; + syncYouTubeTitle(); + document.addEventListener('automap:video-topic-changed', syncYouTubeTitle); + for (const id of youtubeFields) { + for (const event of ['input', 'change']) ytElement(id).addEventListener(event, () => { + if (id === 'youtubeTitle') youtubeCustomTitle = ytElement(id).value; + if (id === 'youtubeUseTopic') syncYouTubeTitle(); + saveYouTubeSettings(); + }); + } const outcome = new URLSearchParams(location.search).get('youtube'); if (outcome) { ytElement('youtubePanel').open = true; diff --git a/templates/index.html b/templates/index.html index 48271f0..c5de43a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -424,6 +424,8 @@

Your last topic is saved. New ideas are generated only when you click Generate idea.

+
@@ -2280,9 +2282,10 @@

syncGsm(base + delta); } - // Keep synchronous storage and preview DOM work out of keyboard input events. + // Save the topic immediately; debounce the more expensive preview work. let topicPreviewTimer; function scheduleTopicPreview(event) { + saveBrowserValue(MAP_TOPIC_STORAGE_KEY, document.getElementById('topicInput').value); clearTimeout(topicPreviewTimer); if (event && event.isComposing) return; topicPreviewTimer = setTimeout(flushTopicPreview, 250); diff --git a/templates/video.html b/templates/video.html index 2acacfa..821cd5e 100644 --- a/templates/video.html +++ b/templates/video.html @@ -1393,7 +1393,7 @@

- YouTube upload + YouTube upload Checking sign-in…

Connect your channel once, then upload automatically after rendering. Credentials stay on the server.

Rendered videos are vertical 9:16 and up to 30 seconds long, ready for Shorts. YouTube classifies them automatically after processing.

@@ -1403,12 +1403,13 @@

Web application redirect URI: Loading…. Desktop app files work on localhost.

- +

Checking connection…

-