Difference between revisions of "Youtube: Download Video dengan pytube"

From OnnoWiki
Jump to navigation Jump to search
(Created page with "Sumber: https://github.com/pytube/pytube sudo su apt install git python3 -m pip install git+https://github.com/pytube/pytube Penggunaan pytube https://youtube.com/watc...")
 
 
(2 intermediate revisions by the same user not shown)
Line 10: Line 10:
 
  pytube https://youtube.com/watch?v=2lAe1cqCOXo
 
  pytube https://youtube.com/watch?v=2lAe1cqCOXo
 
  pytube https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n
 
  pytube https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n
 +
 +
 +
List URL di playlist
 +
 +
from pytube import Playlist
 +
playlist = Playlist('https://www.youtube.com/playlist?list=PLXHnX-wg99aweNBbJAhNkgiIFLxhWjTS-')
 +
playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)")
 +
print(len(playlist.video_urls))
 +
for url in playlist.video_urls:
 +
  print(url)
 +
<enter>
 +
 +
import re
 +
from pytube import Playlist
 +
playlist = Playlist('https://www.youtube.com/playlist?list=PLXHnX-wg99aweNBbJAhNkgiIFLxhWjTS-') 
 +
DOWNLOAD_DIR = '/mnt/data/library-4/multimedia/SCREEN-RECORDING-OWP/INTERNET-DESA'
 +
playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)")   
 +
print(len(playlist.video_urls))   
 +
for url in playlist.video_urls:
 +
print(url)   
 +
for video in playlist.videos:
 +
print('downloading : {} with url : {}'.format(video.title, video.watch_url))
 +
video.streams.\
 +
filter(type='video', progressive=True, file_extension='mp4').\
 +
order_by('resolution').\
 +
        desc().\
 +
        first().\
 +
        download(DOWNLOAD_DIR)

Latest revision as of 12:49, 4 May 2024

Sumber: https://github.com/pytube/pytube


sudo su
apt install git
python3 -m pip install git+https://github.com/pytube/pytube

Penggunaan

pytube https://youtube.com/watch?v=2lAe1cqCOXo
pytube https://www.youtube.com/playlist?list=PLS1QulWo1RIaJECMeUT4LFwJ-ghgoSH6n


List URL di playlist

from pytube import Playlist
playlist = Playlist('https://www.youtube.com/playlist?list=PLXHnX-wg99aweNBbJAhNkgiIFLxhWjTS-')
playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)")
print(len(playlist.video_urls))
for url in playlist.video_urls:
  print(url)
<enter>
import re
from pytube import Playlist
playlist = Playlist('https://www.youtube.com/playlist?list=PLXHnX-wg99aweNBbJAhNkgiIFLxhWjTS-')   
DOWNLOAD_DIR = '/mnt/data/library-4/multimedia/SCREEN-RECORDING-OWP/INTERNET-DESA'
playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)")    
print(len(playlist.video_urls))    
for url in playlist.video_urls:
	print(url)    
for video in playlist.videos: 
	print('downloading : {} with url : {}'.format(video.title, video.watch_url))
	video.streams.\ 
	filter(type='video', progressive=True, file_extension='mp4').\
	order_by('resolution').\
        desc().\
        first().\
        download(DOWNLOAD_DIR)