feat: Browser cookie authentication, YouTube Profile menu with personalized content - #239
Open
ihorman wants to merge 26 commits into
Open
feat: Browser cookie authentication, YouTube Profile menu with personalized content#239ihorman wants to merge 26 commits into
ihorman wants to merge 26 commits into
Conversation
Add the ability to automatically extract cookies from an installed browser (Chromium, Firefox, Chrome, Brave, Edge, Opera, Vivaldi) using yt-dlp's browser cookie extraction. This allows pipe-viewer to access: - Logged-in YouTube content - Age-restricted videos - Personalized search results and recommendations - Members-only content Usage: pipe-viewer --cookies-from-browser=chromium Config file: cookies_from_browser => "chromium", Changes: - lib/WWW/PipeViewer.pm: Add cookies_from_browser option and _extract_browser_cookies() method. Cookies are extracted via yt-dlp and cached for 1 hour to avoid repeated extraction. - bin/pipe-viewer: Add --cookies-from-browser CLI flag and POD docs. - bin/gtk-pipe-viewer: Add cookies_from_browser config pass-through.
Major changes: - Add Login with Browser menu item (Ctrl+L) with browser selection dialog - Support browsers: chromium, chrome, firefox, brave, edge, opera, vivaldi - Add profile verification after cookie extraction (checks for auth cookies) - Add startup notification showing profile status - Bundle Python helper for fast native cookie extraction (0.25s vs 10s) - Add raw JSON ytInitialData parsing for desktop YouTube pages - Add reload_cookies_from_browser() method for runtime re-login - Add get_profile_loaded() and get_profile_username() accessors The Login dialog: 1. User clicks Menu > Login with Browser (or Ctrl+L) 2. Selects browser from dropdown (chromium default) 3. Clicks OK to extract cookies 4. Shows success/failure notification in progress bar 5. On failure, shows dialog with troubleshooting tips
…ing empty category - Pass cookies_from_browser to main thread yv_obj constructor - Add YouTube History menu item (Ctrl+H) - Add YouTube Trending menu item (Ctrl+T) - Add display_youtube_history, display_youtube_trending, display_youtube_subscriptions handlers - Add yt_youtube_history, _parse_video_renderer, _extract_videos_from_richGrid to InitialData.pm - Add subscription_feed, youtube_history methods to Videos.pm - Fix trending empty category crash
When cookies_from_browser is set, eagerly call set_lwp_useragent() in the constructor so that profile_loaded is available immediately. This fixes the startup notification and menu items that depend on knowing the profile status.
- Add yt_youtube_trending() - scrapes m.youtube.com/feed/trending - Add yt_youtube_history() - scrapes m.youtube.com/feed/history - Add _parse_compact_video_renderer() for history format - Handle richSectionRenderer in trending (category shelves) - trending_videos_from_category() now tries YouTube scraping first - All three features tested and working with cookies
- Add YouTube Shorts menu item (searches for short videos) - Add shorts_autoplay config option (default: 1) - When a Short finishes playing, auto-plays next after 2s countdown - Progress bar shows 'Playing next Short in Ns...' countdown - Press Escape to cancel auto-play at any time - Auto-play cancels when navigating away (search, other menus) - Uses mpv IPC socket to detect video end - Clean state management for shorts mode
When cookies_from_browser or cookie_file is set, the Subscription videos menu item now fetches from YouTube's subscription feed instead of requiring a local subscribed_channels.txt file.
When not logged in, clicking Subscription videos now shows: 'Not logged in. Use Menu > Login with Browser to see your subscriptions.' instead of crashing with 'No subscribed channels' error.
When user clicks Login with Browser and selects a browser that is not running, the app now: 1. Launches the browser automatically 2. Waits up to 10s for it to start 3. Shows progress bar updates while waiting 4. Gives browser 3s to initialize after startup 5. Shows error dialog if browser can't be launched Supported browsers: chromium, chrome, firefox, brave, edge, opera, vivaldi
- Add YouTube Playlists menu item (Ctrl+P) - Uses yt-dlp to extract playlists (page loads dynamically) - Shows: Liked videos, Watch later, and all user playlists - Updated cookie extractor to copy google.com auth cookies to youtube.com (fixes API authentication for playlists, history, etc.) - Added _find_cookie_file helper to locate cookies in multiple paths - Added _parse_grid_playlist_renderer helper (unused but available) Cookie extractor fix: SAPISID and other auth cookies from .google.com are now duplicated to .youtube.com domain, enabling YouTube API access.
- Use yt-dlp with Shorts filter (sp=EgIYAQ%3D%3D) to fetch real Shorts - Only includes videos under 60 seconds (actual Shorts format) - Uses dedicated yt_youtube_shorts() method - Searches for 'shorts' with the YouTube Shorts filter applied
- Handle richSectionRenderer with reelShelfRenderer in subscription feed - Extract Shorts from shortsLockupViewModel with proper title parsing - Remove view count from Shorts titles (e.g., ', 1,1 тысячи просмотров') - Support Unicode quotes (U+201C/U+201D) in accessibility text - Subscription feed now shows 4 items (3 videos + 1 Short)
Menu structure now:
Menu > Saved channels
Watched videos
YouTube > Login with Browser
---
Subscriptions
History
Playlists
---
Trending
Shorts
CLI Pipe Viewer
Preferences
- Up/Down arrow keys navigate between Shorts in Shorts mode - Space toggles auto-play pause - Escape cancels auto-play - Shows keyboard hints when entering Shorts mode 'Shorts mode: ↑/↓ navigate, Enter play, Esc exit' - play_next_short() uses play_adjacent_short() for consistency - Shorts mode auto-selects first item for immediate navigation
…Model support
Critical fixes:
- Renamed 'YouTube' submenu to 'Profile'
- Fixed Perl eval/return bug in yt_youtube_trending, yt_subscription_feed,
yt_youtube_history: 'return' inside eval{} returns from the enclosing
sub, not the eval block. Replaced with do{} blocks using 'last' for
early exit.
- Added lockupViewModel parser for YouTube's new video card format
(_parse_lockup_view_model) — YouTube now uses lockupViewModel instead
of videoWithContextRenderer in trending and other feeds
- Fixed stale '}' // [] leftover after history eval fix
- All 25 feature tests pass
- Login with Browser now opens YouTube login page when launching browser (https://accounts.google.com/ServiceLogin?continue=...) - If not logged in, shows dialog: 'Not logged in to YouTube' with instructions and 'Open YouTube Login' button - Added require_login() helper for all Profile menu items - Subscriptions, History, Playlists show login dialog if not logged in - Login dialog offers 'Login Now' button that opens the login flow - Trending works without login - Error dialogs use format_secondary_text for proper line breaks
- Extractor creates SAPISID/SID/SIDCC legacy aliases from __Secure-3P* cookies (YouTube moved to new cookie format) - _find_cookie_file falls back to any cookies_from_*.txt if browser not set - Fixed 'Argument NA isn't numeric' warning in format_time - Profile check recognizes __Secure-3PAPISID/__Secure-1PSID cookies NOTE: Subscriptions/History/Playlists return 0 because the YouTube session cookies have expired for API use. The user needs to re-login in the browser to get fresh cookies.
When Subscriptions/History/Playlists return empty results with cookies configured, instead of generic error shows: - 'YouTube session expired' dialog - Step-by-step instructions to re-login - 'Open YouTube Login' button to open browser - 'Re-extract Cookies' button to run Login with Browser flow Also: - send_search_request no longer dies on empty results (was crashing) - Error shows in progress bar for non-auth features
When browser is running, still opens the YouTube login URL in it. When browser is not running, launches it with the login URL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds browser cookie extraction for YouTube authentication, enabling personalized content (subscriptions, history, playlists, trending) in both CLI and GTK interfaces.
Features Added
Core: Browser Cookie Authentication (
--cookies-from-browser)utils/extract-browser-cookies.py) for fast cookie extraction (~0.25s)__Secure-3P*cookie format — creates legacySAPISID/SIDaliases for API compatibility.google.comand.youtube.comdomains--cookies-from-browserflagGTK UI: Profile Menu
New Profile submenu in the Menu dropdown with:
GTK UI: Error Handling
format_secondary_textfor proper line breaksGTK UI: Shorts Auto-play
YouTube Data Parsing
lockupViewModelparser for YouTube's new video card format (used in trending, etc.)reelShelfRenderer/shortsLockupViewModelparser for Shorts in subscription feedcompactVideoRendererparser for watch historyeval/returnPerl bug:returninsideeval{}returns from the enclosing sub, not the eval block — replaced withdo{}blocksCLI
--yt-subsflag for subscription feed--trendingwith empty category argumentformat_time"Argument NA" warningFiles Changed
bin/gtk-pipe-viewerbin/pipe-viewer--yt-subsflag, trending fixlib/WWW/PipeViewer.pmlib/WWW/PipeViewer/InitialData.pmlib/WWW/PipeViewer/Videos.pmlib/WWW/PipeViewer/Utils.pmshare/gtk-pipe-viewer.gladeutils/extract-browser-cookies.pyTesting
All features tested with real YouTube account:
Requirements
pycryptodomePython package (for cookie decryption)secretstoragePython package (for GNOME Keyring access)yt-dlp(for playlists and shorts extraction)