Skip to content

Instantly share code, notes, and snippets.

@ranfysvalle02
Created February 14, 2024 01:25
Show Gist options
  • Save ranfysvalle02/7f810f3aef45188cb7f6970a2c6e6e2c to your computer and use it in GitHub Desktop.
Save ranfysvalle02/7f810f3aef45188cb7f6970a2c6e6e2c to your computer and use it in GitHub Desktop.
Mendable<>YT_USER
import requests
import scrapetube
import json
def get_video_urls_from_channel_or_playlist(id, type):
if type == 'channel':
videos = scrapetube.get_channel(channel_username=id)
elif type == 'playlist':
videos = scrapetube.get_playlist(id)
else:
raise ValueError('Invalid type. Please choose "channel" or "playlist".')
video_urls = ['https://www.youtube.com/watch?v=' + video['videoId'] for video in videos]
return video_urls
def ingest_urls(api_key, urls):
url = 'https://api.mendable.ai/v1/ingestData'
headers = {'Content-Type': 'application/json'}
for video_url in urls:
data = {
'api_key': api_key,
'url': video_url,
'type': 'youtube'
}
print(f'Payload: {data}...')
response = requests.post(url, headers=headers, data=json.dumps(data))
print(f'Ingested {video_url}. Status code: {response.status_code}')
if response.status_code != 200:
print(f'Failed to ingest {video_url}. Status code: {response.status_code}')
# Example usage
urls = get_video_urls_from_channel_or_playlist('MathwithMrJ', 'channel')
print(urls)
print("Ingesting URLs...")
ingest_urls('SERVERSIDE_API_KEY', urls)
@Svsjgwjv
Copy link

Bscjsjeh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment