Skip to content

Instantly share code, notes, and snippets.

View Mxhmovd's full-sized avatar
👋

Mahmoud Hamdi Mxhmovd

👋
View GitHub Profile
@Mxhmovd
Mxhmovd / yt_video_sorter.py
Created July 6, 2022 16:23
Order/sort videos in YouTube playlist by views/popularity
#change KEY_PATH, API_KEY, LIST_ID
#API_KEY https://blog.hubspot.com/website/how-to-get-youtube-api-key
#KEY_PATH https://cloud.google.com/docs/authentication/getting-started
#LIST_ID for ex. list_id in https://www.youtube.com/watch?v=fjYptQjF1Tw&list=RDfjYptQjF1Tw&start_radio=1 is "RDfjYptQjF1Tw"
import os
from googleapiclient.discovery import build
credential_path = "KEY_PATH"
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credential_path
@Mxhmovd
Mxhmovd / cap.py
Created October 22, 2018 20:36
Read Youtube videos with OpenCV without downloading it locally.
#pip install pafy
#sudo pip install --upgrade youtube_dl
import cv2, pafy
url = "https://www.youtube.com/watch______"
video = pafy.new(url)
best = video.getbest(preftype="webm")
#documentation: https://pypi.org/project/pafy/
capture = cv2.VideoCapture(best.url)