|
1 | | -from yt_dlp import YoutubeDL |
| 1 | +from pytube import YouTube |
2 | 2 |
|
3 | 3 |
|
4 | 4 | print(f" ==========================\n Python YouTube Downloader \n==========================\n") |
5 | 5 |
|
6 | | -videoURL = str(input("Enter Video Link : ")) |
7 | | -# videoURL = 'https://www.youtube.com/watch?v=5cCaU6T1yFE' |
8 | | - |
9 | | -# Progress bar shows when a video is downloading |
10 | | -def download_loading_bar(d): |
11 | | - if d['status'] == 'downloading': |
12 | | - # Get the download percentage as a float |
13 | | - percentage = float(d['_percent_str'].replace('%', '')) |
14 | | - # Calculate how many # symbols to print |
15 | | - num_symbols = int(percentage / 5) |
16 | | - # Print the loading bar with the percentage and ETA, using \r and end='' |
17 | | - print(f"\rLoading: [{'#' * num_symbols}{'-' * (20 - num_symbols)}] {d['_percent_str']} {d['_eta_str']}", end='') |
18 | | - |
19 | | - |
20 | | -ydl_opts = { |
21 | | - "quiet": True, |
22 | | - 'outtmpl': "%(title)s_%(id)s.%(ext)s", |
23 | | - # "format": "bestvideo+bestaudio/best", |
24 | | - |
25 | | - 'progress_hooks': [download_loading_bar], |
26 | | - 'no_color': True, |
27 | | -} |
| 6 | +# videoURL = str(input("Enter Video Link : ")) |
| 7 | +videoURL = 'https://www.youtube.com/watch?v=5cCaU6T1yFE' |
| 8 | + |
| 9 | +yt = YouTube(videoURL) |
| 10 | +print(yt.title) |
28 | 11 |
|
29 | | -print("Fetching the info...") |
| 12 | +# print("Fetching the info...") |
30 | 13 |
|
31 | | -with YoutubeDL( ydl_opts ) as ydl: |
32 | | - vidInfo = ydl.extract_info(videoURL, download=False) |
| 14 | + # vidTitle = |
| 15 | + # vidDuration = |
| 16 | + # vidSize = |
33 | 17 |
|
34 | | - vidTitle = vidInfo.get('title', None) |
35 | | - vidDuration = vidInfo.get('duration', None) |
36 | | - vidSize = vidInfo.get('filesize_approx', None) // 1048576 |
| 18 | + # print("\n= Title:", vidTitle) |
| 19 | + # print("= Duration:", vidDuration) |
| 20 | + # print("= Size:", vidSize , "MB") |
37 | 21 |
|
38 | | - print("\n🔹 Title:", vidTitle) |
39 | | - print("🔹 Duration:", vidDuration) |
40 | | - print("🔹 Size:", vidSize , "MB") |
| 22 | +# print("\nDownloading...") |
41 | 23 |
|
42 | | -print("\nDownloading...") |
43 | 24 |
|
44 | | -ydl.download(['https://www.youtube.com/watch?v=BxUS1K7xu30']) |
45 | 25 |
|
46 | | -print("Downloaded Successfully! \n ") |
| 26 | +# print("Downloaded Successfully! \n ") |
47 | 27 |
|
48 | 28 |
|
49 | 29 |
|
|
0 commit comments