x32x01
  • by x32x01 ||
Youtube Playlist Downloader Script
Requirements
  • requests (pip install requests)
  • pytube (pip install pytube)
  • youtube-dl (pip install youtube-dl)
Python:
#!python3
# Usage -
# 1. open cmd
# 2. cd to the folder where these files are present
# 3. type - python ytdown.py
# the script will start working

import os
import subprocess
from pytube import YouTube
import random
import requests
import re
import string

#imp functions

def foldertitle(url):

    try:
        res = requests.get(url)
    except:
        print('no internet')
        return False

    plain_text = res.text

    if 'list=' in url:
        eq = url.rfind('=') + 1
        cPL = url[eq:]

    else:
        print('Incorrect attempt.')
        return False

    return cPL

def link_snatcher(url):
    our_links = []
    try:
        res = requests.get(url)
    except:
        print('no internet')
        return False

    plain_text = res.text

    if 'list=' in url:
        eq = url.rfind('=') + 1
        cPL = url[eq:]
    else:
        print('Incorrect Playlist.')
        return False

    tmp_mat = re.compile(r'watch\?v=\S+?list=' + cPL)
    mat = re.findall(tmp_mat, plain_text)

    for m in mat:
        new_m = m.replace('&', '&')
        work_m = 'https://youtube.com/' + new_m
        # print(work_m)
        if work_m not in our_links:
            our_links.append(work_m)

    return our_links

BASE_DIR = os.getcwd()

print('WELCOME TO PLAYLIST DOWNLOADER - iTabCode.Net')

url = str(input("\nspecify you playlist url\n"))

print('\nCHOOSE ANY ONE - TYPE 360P OR 720P\n')
user_res = str(input()).lower()

print('...You choosed ' + user_res + ' resolution\n.')

our_links = link_snatcher(url)

os.chdir(BASE_DIR)

new_folder_name = foldertitle(url)
print(new_folder_name[:7])

try:
    os.mkdir(new_folder_name[:7])
except:
    print('folder already exists')

os.chdir(new_folder_name[:7])
SAVEPATH = os.getcwd()
print(f'\n files will be saved to {SAVEPATH}')

x=[]
for root, dirs, files in os.walk(".", topdown=False):
    for name in files:
        pathh = os.path.join(root, name)

        if os.path.getsize(pathh) < 1:
            os.remove(pathh)
        else:
            x.append(str(name))

print('\nconnecting . . .\n')

print()

for link in our_links:
    try:
        yt = YouTube(link)
        main_title = yt.title
        main_title = main_title + '.mp4'
        main_title = main_title.replace('|', '')
    
    except:
        print('connection problem..unable to fetch video info')
        break

    if main_title not in x:

        if user_res == '360p' or user_res == '720p':
            vid = yt.streams.filter(progressive=True, file_extension='mp4', res=user_res).first()
            print('Downloading. . . ' + vid.default_filename + ' and its file size -> ' + str(round(vid.filesize / (1024 * 1024), 2)) + ' MB.')
            vid.download(SAVEPATH)
            print('Video Downloaded')
        else:
            print('something is wrong.. please rerun the script')

    else:
        print(f'\n skipping "{main_title}" video \n')

print(' downloading finished')
print(f'\n all your videos are saved at --> {SAVEPATH}')
 

Similar Threads

x32x01
Replies
0
Views
92
x32x01
x32x01
x32x01
Replies
0
Views
167
x32x01
x32x01
x32x01
Replies
0
Views
591
x32x01
x32x01
x32x01
Replies
0
Views
210
x32x01
x32x01
x32x01
  • x32x01
Replies
0
Views
235
x32x01
x32x01
TAGs: Tags
download youtube videos python script

Register & Login Faster

Forgot your password?

Latest Resources

Forum Statistics

Threads
517
Messages
518
Members
45
Latest Member
Tacola
Back
Top