Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

import os
import shutil
from pytube import YouTube
import random
import string
import uuid
import time
from datetime import date
from datetime import datetime
from time import gmtime, strftime
from moviepy.editor import VideoFileClip, VideoClip, AudioFileClip, AudioClip
import tkinter as tk
from tkinter import filedialog
import random

yt = YouTube
print ('What youtube video would you like too download and convert to .mp3?(Insert Link)')
ytv = input()

try:
    lol = yt(ytv).streams.first().download()
except:
    print ('That is not a YouTube link')
    exit()

today = strftime('%Y-%m-%d', gmtime())

video1 = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Videos')

title = yt(ytv).streams[0].default_filename

title1 = '\' + yt(ytv).streams[0].default_filename

random = uuid.uuid4().hex.upper()[0:6]

name = random + '-' + today + '.mp4'

current = os.getcwd()

os.rename(current + title1, name)
shutil.move(current + '\' + name, video1)

random = random = uuid.uuid4().hex.upper()[0:6]

video = VideoFileClip(video1 + '\' + name)

print ('The audio file will be in your downloads folder')
save = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Downloads')

video.audio.write_audiofile(save + '\' + random + '.mp3')

This whole script just downloads a youtube video, sends it to a folder, that runs an api that converts that downloaded video to an mp3 file. Right here I want to remove that file so the user just has a .mp3 but it has some sort of lock on it that I can't unlock/figure out.

os.remove(video1 + '\' + name)
question from:https://stackoverflow.com/questions/65621465/how-to-delete-a-file-getting-used-in-a-python-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
142 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...