0

This code downloads the video and convert it to mp3 file. However, the mp3 audio will become 2 times longer than normal video. How can I solve this problem?

import pafy
import os
import moviepy.editor as mp


print "[+] Welcome to Youtube downloader."
download_url = raw_input("URL :")

video = pafy.new(download_url)
best = video.streams
file_name = video.streams[0]
print file_name

directory = "downloaded-music"
if not os.path.exists(directory):
    os.makedirs(directory)
x = file_name.download(filepath = directory)

clip = mp.VideoFileClip(x)
print clip.size
clip.audio.write_audiofile(x + ".mp3")

os.remove(x)
Anil_M
  • 10,893
  • 6
  • 47
  • 74
Less-Owl-4025
  • 33
  • 1
  • 8
  • 1
    If you just want to download video from youtube and convert it to mp3, you could just use youtube-dl Python lib or command line tool. It's pretty easy: ``youtube-dl --extract-audio --audio-format mp3 https://www.youtube.com/watch\?v\=BkB5-8IFYek`` – Kane Blueriver Aug 08 '16 at 11:00

1 Answers1

-1

It's the value "clip.size" that is twice bigger than the real one, or it's the real lenght of the file ?

Amperclock
  • 379
  • 2
  • 16