I made a youtube video download Manager. It download a video but i am facing one issue when i download same video, it doesn't download it again. how can i download it again with same title like pic.png and send pic1.png. How can i do that?
def Download(self):
video_url = self.lineEdit.text()
save_location = self.lineEdit_2.text()
if video_url == '' or save_location == '':
QMessageBox.warning(self, "Data Error", "Provide a Valid Video URL or save Location")
else:
video = pafy.new(video_url)
video_stream = video.streams
video_quality = self.comboBox.currentIndex()
download = video_stream[video_quality].download(filepath=save_location, callback=self.Handel_Progress, )
Ok, this one is interesting.
The real problem begins here.
Here, you are calling
download
function ofvideo_stream
object which takesfilepath
as an argument for file location but does not take the filename, because, obviously, the file would be saved with the actual name.Root Cause of your problem:
Now comes the part, how do you make sure it downloads, no matter what:
There are two things you need to do:
Check if a file with same name exists or not, and if does, then add
1
in the end of the file name just before the extension. So ifabc.mp4
exists, then saveabc1.mp4
. [I will tell you how to handle the scenario whenabc.mp4
,abc1.mp4
and so on exists, but for now, let's get back to the problem.]How to pass the file name (
abc1.mp4
) to the download method?Following piece of code would handle both. I have added comments for your understanding.
Let me know if you face any issues.