the Package how do I skip a private video with this code I tried the optons (rejecttitle ignore-errors) I looked at YoutubeDL.py at github for option and i have no access to the video is of a Playlist
JavaScript
x
117
117
1
from __future__ import unicode_literals
2
3
from datetime import datetime
4
import os
5
import shutil
6
import sys
7
import time
8
import traceback
9
from os import system, name
10
11
import yt_dlp as yb
12
13
with open("location.txt", 'w+t') as s:
14
s.write(input("path to save files: "))
15
s.seek(0)
16
data = s.read()
17
print("thumbnails will be moved to " + data + "\thumbnail")
18
19
20
def run():
21
while True:
22
video_url = input("nplease enter youtube video url: ")
23
video_info = yb.YoutubeDL().extract_info(
24
url=video_url, download=False)
25
filename = f"{video_info['title']}"
26
27
ydl_opts = {
28
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio/best',
29
'download_archive': 'downloaded_songs.txt',
30
'windowsfilenames': True,
31
'outtmpl': data + '/%(title)s.%(ext)s',
32
'writesubtitles': True,
33
'subtitleslangs': ['en', '-live_chat'],
34
'writethumbnail': True,
35
'embedthumbnail': True,
36
'abort_on_unavailable_fragments': False,
37
'ignoreerrors': True,
38
'verbose': True,
39
'postprocessors': [
40
{'key': 'FFmpegMetadata',
41
'add_metadata': True, },
42
{'key': 'FFmpegEmbedSubtitle'},
43
{'key': 'EmbedThumbnail',
44
'already_have_thumbnail': True,
45
},
46
]
47
}
48
49
with yb.YoutubeDL(ydl_opts) as ydl:
50
ydl.download([video_info['webpage_url']])
51
print("nDownload complete... {}".format(filename))
52
thumbnail_path()
53
clear()
54
55
56
def thumbnail_path():
57
start_time = datetime.now()
58
sourcepath = data
59
sourcefiles = os.listdir(sourcepath)
60
destinationpath = data + '/thumbnail'
61
thumbnail = os.path.exists(destinationpath)
62
if not thumbnail:
63
os.makedirs(destinationpath)
64
for file in sourcefiles:
65
if file.endswith('.webp'):
66
shutil.move(os.path.join(sourcepath, file), os.path.join(destinationpath, file))
67
end_time = datetime.now()
68
print('Duration: {}'.format(end_time - start_time))
69
70
71
def close():
72
time.sleep(0)
73
print('nBye')
74
time.sleep(1)
75
sys.exit()
76
77
78
def clear():
79
while True:
80
ans = input("nDo you want to start again? (y/n) ")
81
if ans.lower() == "y":
82
if name == "nt":
83
system('cls')
84
time.sleep(0)
85
run()
86
87
else:
88
system('clear')
89
time.sleep(0)
90
run()
91
92
elif ans.lower() == 'n':
93
if name == 'nt':
94
system('cls')
95
close()
96
97
else:
98
system('clear')
99
close()
100
else:
101
print("Please respond with 'Yes' or 'No'n")
102
103
104
if __name__ == '__main__':
105
try:
106
run()
107
except KeyboardInterrupt:
108
print('nInterrupted')
109
while True:
110
clear()
111
except Exception:
112
with open("log.txt", "w") as log:
113
traceback.print_exc(file=log)
114
print('nError is printed to log.txt')
115
close()
116
117
ERROR: [youtube] FvnQJZnnXXo: Private video. Sign in if you’ve been granted access to this video
Output from log,txt
JavaScript
1
38
38
1
Traceback (most recent call last):
2
File "C:UsersUserPycharmProjectsYouTube-venvlibsite-packagesyt_dlpextractorcommon.py", line 640, in extract
3
ie_result = self._real_extract(url)
4
File "C:UsersUserPycharmProjectsYouTube-venvlibsite-packagesyt_dlpextractoryoutube.py", line 3477, in _real_extract
5
self.raise_no_formats(reason, expected=True)
6
File "C:UsersUserPycharmProjectsYouTube-venvlibsite-packagesyt_dlpextractorcommon.py", line 1124, in raise_no_formats
7
raise ExtractorError(msg, expected=expected, video_id=video_id)
8
yt_dlp.utils.ExtractorError: Private video. Sign in if you've been granted access to this video
9
10
During handling of the above exception, another exception occurred:
11
12
Traceback (most recent call last):
13
File "C:UsersUserPycharmProjectsYouTube-venvlibsite-packagesyt_dlpYoutubeDL.py", line 1420, in wrapper
14
return func(self, *args, **kwargs)
15
File "C:UsersUserPycharmProjectsYouTube-venvlibsite-packagesyt_dlpYoutubeDL.py", line 1490, in __extract_info
16
ie_result = ie.extract(url)
17
File "C:UsersUserPycharmProjectsYouTube-venvlibsite-packagesyt_dlpextractorcommon.py", line 666, in extract
18
raise type(e)(e.orig_msg, **kwargs)
19
yt_dlp.utils.ExtractorError: [youtube] FvnQJZnnXXo: Private video. Sign in if you've been granted access to this video
20
21
During handling of the above exception, another exception occurred:
22
23
Traceback (most recent call last):
24
File "C:UsersUserPycharmProjectsYouTube-YouMain.py", line 105, in <module>
25
run()
26
File "C:UsersUserPycharmProjectsYouTube-YouMain.py", line 23, in run
27
video_info = yb.YoutubeDL().extract_info(
28
File "C:UsersUserPycharmProjectsYouTube-venvlibsite-packagesyt_dlpYoutubeDL.py", line 1411, in extract_info
29
return self.__extract_info(url, self.get_info_extractor(ie_key), download, extra_info, process)
30
File "C:UsersUserPycharmProjectsYouTube-venvlibsite-packagesyt_dlpYoutubeDL.py", line 1438, in wrapper
31
self.report_error(str(e), e.format_traceback())
32
File "C:UsersUserPycharmProjectsYouTube-venvlibsite-packagesyt_dlpYoutubeDL.py", line 962, in report_error
33
self.trouble(f'{self._format_err("ERROR:", self.Styles.ERROR)} {message}', *args, **kwargs)
34
File "C:UsersUserPycharmProjectsYouTube-venvlibsite-packagesyt_dlpYoutubeDL.py", line 905, in trouble
35
raise DownloadError(message, exc_info)
36
yt_dlp.utils.DownloadError: ERROR: [youtube] FvnQJZnnXXo: Private video. Sign in if you've been granted access to this video
37
38
Advertisement
Answer
I have fixed the problem. The solution was to change a part of the code, the change is in the def run part from
JavaScript
1
35
35
1
def run():
2
while True:
3
video_url = input("nplease enter youtube video url: ")
4
video_info = yb.YoutubeDL().extract_info(
5
url=video_url, download=False)
6
filename = f"{video_info['title']}"
7
8
ydl_opts = {
9
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio/best',
10
'download_archive': 'downloaded_songs.txt',
11
'windowsfilenames': True,
12
'outtmpl': data + '/%(title)s.%(ext)s',
13
'writesubtitles': True,
14
'subtitleslangs': ['en', '-live_chat'],
15
'writethumbnail': True,
16
'embedthumbnail': True,
17
'abort_on_unavailable_fragments': False,
18
'ignoreerrors': True,
19
'verbose': True,
20
'postprocessors': [
21
{'key': 'FFmpegMetadata',
22
'add_metadata': True, },
23
{'key': 'FFmpegEmbedSubtitle'},
24
{'key': 'EmbedThumbnail',
25
'already_have_thumbnail': True,
26
},
27
]
28
}
29
30
with yb.YoutubeDL(ydl_opts) as ydl:
31
ydl.download([video_info['webpage_url']])
32
print("nDownload complete... {}".format(filename))
33
thumbnail_path()
34
clear()
35
to
JavaScript
1
32
32
1
def run():
2
while True:
3
video_url = input("nplease enter youtube video url: ")
4
ydl_opts = {
5
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio/best',
6
'download_archive': 'downloaded_songs.txt',
7
'windowsfilenames': True,
8
'outtmpl': data + '/%(title)s.%(ext)s',
9
'writesubtitles': True,
10
'subtitleslangs': ['en', '-live_chat'],
11
'writethumbnail': True,
12
'embedthumbnail': True,
13
'ignoreerrors': True,
14
'postprocessors': [
15
{'key': 'FFmpegMetadata',
16
'add_metadata': True, },
17
{'key': 'FFmpegEmbedSubtitle'},
18
{'key': 'EmbedThumbnail',
19
'already_have_thumbnail': True,
20
},
21
],
22
}
23
24
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
25
error_code = ydl.download([video_url])
26
video_info = ydl.extract_info(url=video_url, download=False)
27
filename = f"{video_info['title']}"
28
print('Some videos failed to download {}'.format(filename) if error_code
29
else "nDownload complete... {}".format(filename))
30
thumbnail_path()
31
clear()
32
the problem come from
JavaScript
1
2
1
video_info = yb.YoutubeDL().extract_info(url=video_url, download=False)
2
It would try to get the video info