Copy videos from any YouTube playlist to your own playlist with Python and YouTube API

PHOTO EMBED

Mon Feb 07 2022 18:24:23 GMT+0000 (Coordinated Universal Time)

Saved by @mdfaizi

from Google import Create_Service
import pandas as pd

CLIENT_SECRET_FILE  =  '<Your client secret file (JSON)>'
API_NAME  =  'youtube'
API_VERSION  =  'v3'
SCOPES  = ['https://www.googleapis.com/auth/youtube']

service =  Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)


playlistId_Source = '<Source YouTube Playlist>'
playlistId_Target = '<Your YouTube Playlist>'

response = service.playlistItems().list(
    part='contentDetails',
    playlistId=playlistId_Source,
    maxResults=50
).execute()

playlistItems = response['items']
nextPageToken = response.get('nextPageToken')

while nextPageToken:
    response = service.playlistItems().list(
        part='contentDetails',
        playlistId=playlistId_Source,
        maxResults=50,
        pageToken=nextPageToken
    ).execute()

    playlistItems.extend(response['items'])
    nextPageToken = response.get('nextPageToken')

for video in playlistItems:    
    request_body = {
        'snippet': {
            'playlistId': playlistId_Target,
            'resourceId': {
                'kind': 'youtube#video',
                'videoId': video['contentDetails']['videoId']
            }
        }
    }

    service.playlistItems().insert(
        part='snippet',
        body=request_body
    ).execute()
	
content_copyCOPY

https://learndataanalysis.org/copy-videos-from-any-youtube-playlist-to-your-own-playlist-with-python-and-youtube-api/