# install: google-auth, google-auth-oauthlib, google-api-python-client, pandas from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build import pandas as pd SCOPES = ['https://www.googleapis.com/auth/youtube.readonly'] flow = InstalledAppFlow.from_client_secrets_file('client_secret.json', SCOPES) creds = flow.run_console() youtube = build('youtube', 'v3', credentials=creds) # Example: get items from "Liked videos" playlist (special playlist ID "LL" for liked) playlist_id = 'LL' items = [] next_page = None while True: resp = youtube.playlistItems().list(part='snippet,contentDetails', playlistId=playlist_id, maxResults=50, pageToken=next_page).execute() items += resp['items'] next_page = resp.get('nextPageToken') if not next_page: break rows = [] for it in items: snippet = it['snippet'] rows.append({ 'title': snippet['title'], 'videoId': snippet['resourceId']['videoId'], 'channel': snippet['videoOwnerChannelTitle'] if 'videoOwnerChannelTitle' in snippet else snippet.get('channelTitle'), 'publishedAt': snippet['publishedAt'], 'url': f"https://youtu.be/{snippet['resourceId']['videoId']}" }) df = pd.DataFrame(rows) df.to_csv('liked_videos.csv', index=False)
Pros:
- Fully customizable and repeatable.
- Can pull rich metadata. Cons:
- Requires API setup and OAuth consent.
- Rate limits apply.
Quick Manual Method: Page Scraping (Fast, but Fragile)
For a one-off quick export, you can manually scrape the playlist page or the “Liked videos” page using the browser console or a simple scraper.
Browser-console snippet (copy/paste into Developer Tools > Console while on a playlist page):
let items = Array.from(document.querySelectorAll('ytd-playlist-video-renderer,ytd-grid-video-renderer')); let rows = items.map(it => { let a = it.querySelector('a#video-title'); let title = a ? a.textContent.trim() : ''; let url = a ? a.href : ''; let channel = it.querySelector('#byline-container') ? it.querySelector('#byline-container').innerText.trim() : ''; return {title, url, channel}; }); console.log(JSON.stringify(rows));
Copy the console output and save as JSON, or paste into a spreadsheet after converting to CSV.
Caveats:
- HTML structure changes may break the script.
- Will only work for pages that show the full list (may need scrolling to load lazy content).
Converting and Cleaning Exports
- JSON to CSV: Use a small script (Python with pandas) or an online converter.
- Normalize URLs: Convert full watch URLs to short youtu.be links if needed.
- Add metadata: Use video IDs to call videos.list for extra fields like duration, view count, description.
Example CSV fields to keep:
- title, videoId, url, channel, publishedAt, duration, viewCount
Privacy & Safety Checklist
- Prefer Google Takeout or API OAuth over granting broad third-party permissions.
- Don’t share exported files if they contain private playlists or watch history.
- If using an extension, read its privacy policy and permissions.
- Revoke OAuth tokens/permissions after the task if you used a third-party app you no longer need.
Troubleshooting Common Problems
- Export missing items: Check whether the playlist is private (Takeout/API can access private items when authorized; extensions cannot).
- Export truncated: For large playlists, use API or Takeout — browser scraping may fail due to lazy loading.
- OAuth errors: Ensure your credentials are correct and the OAuth consent screen is configured for the scopes you request.
Quick Decision Guide
- Need a full, official archive of everything? Use Google Takeout.
- Need a fast export of a single playlist or liked videos? Use a reputable browser extension or the page-scraping console trick.
- Want automation or integration with other tools? Use the YouTube Data API.
- Don’t trust third parties and need simple export? Use Takeout or write a local script using the API.
Example Use Cases
- Content creators migrating liked resources into a research spreadsheet.
- Researchers collecting a reproducible list of videos for analysis.
- Users backing up playlists before deleting an account.
- Marketers exporting inspirations to populate a content tracking sheet.
Final Notes
Exporting YouTube favorites is straightforward once you pick the right tool for your needs — Google Takeout for completeness, API for automation, and lightweight extensions or scraping for quick jobs. Keep privacy, permissions, and data formatting in mind, and your export will be fast and reliable.
Leave a Reply