Hello I am working on making a youtube video downloader, and a video converter to practice python language. With the video converter, I am trying to convert an mp4 file to a mp3 file. I want the user to input the specified path without having to open the text editor to do so. My issue is this. I am having trouble trying to figure out how I can possibly, if it is possible, to convert the file using the user's input. Can someone help me with this?
Here is the code I have so far:
import moviepy.editor as mp
#ask the user for the location of the file
loca = (input("Please input the location of the video file you wish to convert: "))
# Insert Local Video File Path
clip = mp.VideoFileClip(r'loca')
# Insert Local Audio File Path
clip.audio.write_audiofile(r'loca')
Just type extension to the file
If you can't imagine here's what's look like.
import moviepy.editor as mp
#ask the user for the location of the file
loca = (input("Please input the location of the video file you wish to convert: "))
filename = input("File name. : ")
# Insert Local Video File Path
clip = mp.VideoFileClip(loca)
# Insert Local Audio File Path
clip.audio.write_audiofile(filename)
Related
Good Afternoon. I'm beginner in python. So, I was trying to make YouTube Video/Audio Downloader with PyTube (For Educational Purpose only). I have seen many videos on youtube and I was trying to make this tool better. So I have added video/audio choosing option and resulation/quality choosing option. The Good thing is I have successfully made Video downloader. But I got a problem in the Audio Downloader. The problem is, PyTube downloads the audio file in MP4 format. I have searched on google and youtube. But I could not find any solution. I want to rename the from mp4 to mp3 (cause the file is OK, but the format is wrong). as a beginner, I don't know how to save a downloading file in somewhere else (temporary folder), and rename it then transfer it to output folder. I tried to add filename=link.title+'mp3'. But It returns this error: OSError: [Errno 22] Invalid argument: 'G:/Downloaded Videos/Latest English Ringtone | Turkish Bgm Ringtone 2021 | Bad Boy | Attitude Tone | Villain Ringtone.mp3'
here is my Code:
from pytube import YouTube
link='https://www.youtube.com/watch?v=KrhPrPK2owA'
link=YouTube(link)
print('Title:',link.title+'\n'+'Views:',link.views)
streams=link.streams.filter(type='audio')
kbps_list=[]
itag_list=[]
print('Available Kbps: ',end='')
for s in streams:
i=s.itag
s=s.abr
if s not in kbps_list:
kbps_list.append(s)
itag_list.append(i)
print(s,end=' ')
reso=input('\nEnter Kbps to download: ')
if reso not in kbps_list:
print('This Kbps is not available')
from sys import exit
exit()
reso=kbps_list.index(reso)
final=streams.get_by_itag(itag_list[reso])
print('Downloading...')
final.download('G:/Downloaded Videos/')
# final.download('G:/Downloaded Videos/', filename=link.title+'mp3')======================
# if I add custom filename, It returns the error ========================================
print('Successfully Downloaded!')
Need to set the file name and can download in mp3 as you tried but it will still be in the mp4a codec. Not sure if that matters to you.
Your title is all weird and it includes the file path. Probably why link.title is not working. Try the below code to strip the title and the file path.
import os
head tail = os.path.split(link.title)
final=streams.get_by_itag(itag_list[reso]).download(filename=tail.strip(" | ") + ".mp3")
You can also set output directory by passing the argument output_path="some location".
It would look like:
final=streams.get_by_itag(itag_list[reso]).download(output_path="some location", filename=tail.strip(" | ") + ".mp3")
I know the title is really vague but anyways, I have a script for downloading the subtitles of a series or movie once the torrent is done downloading. The Input needs to be the filepath of the downloaded file. Conveniently uTorrent has a support for running the script once a torrent finishes downloading and has the filepath as one of its "parameters". I tried running the script with
C:\python\subtitles.py %D
where %D is the supported utorrent parameter for the filepath. This did not work as the script loaded then prompted for user input.Any help on how to automate this would be helpful.
from datetime import timedelta
from babelfish import Language
from subliminal import download_best_subtitles, region, save_subtitles, scan_videos
import os
# configure the cache
region.configure('dogpile.cache.dbm', arguments={'filename': 'cachefile.dbm'})
path = str(input("enter filepath:"))
# scan for videos newer than 1 week and their existing subtitles in a folder
videos = scan_videos(path, age=timedelta(days=7))
print("scan success")
# download best subtitles
subtitles = download_best_subtitles(videos, {Language('eng')})
print("downloads done")
# save them to disk, next to the video
for v in videos:
save_subtitles(v, subtitles[v])
That's because you're trying to get the "parameters" from stdin while your bittorrent client is passing the path as a command-line argument.
Replace path = str(input("enter filepath:")) with
import sys
path = sys.argv[1]
and it'll work.
I want to use video Capturing in Opencv with providing video path or camera path from a text file,
is their any possibility to Provide Video Source From a Text File in Open CV Python
cap = cv2.VideoCapture(open('file.txt').read())
In text file just write your : -
Video file name with extn. : - Video.mp4
or
Camera path : - rtsp://User_Name:Password#127.0.0.1/Streaming/Channels/501
So I used the pafy library to download an audio file directly from youtube, but I don't know at what location the file is saved.
import pafy
video = pafy.new("dQw4w9WgXcQ")
bestaudio = video.getbestaudio()
bestaudio.download()
This is the code I used. The song was downloaded but I don't know where.
the file saved in the current working directory, you can know it using this code
import os
print(os.cwd())
and to change the current working directory use:
os.chdir(r"type your own path")
I want to convert any audio file (flac, wav,...) to mp3 with python
I am a noob , I tried pydub but I didn't found out how to make ffmpeg work with it, and If I'm right it can't convert flac file.
The idea of my project is to :
Make musicBee send the path of the 'now playing' track (by pressing the assigned shortcut) to my python file which would convert the music if it is not in mp3 and send it to a folder. (Everything in background so I don't have to leave what I'm doing to make the operation)
You can use the following the code:
from pydub import AudioSegment
wav_audio = AudioSegment.from_file("audio.wav", format="wav")
raw_audio = AudioSegment.from_file("audio.wav", format="raw",
frame_rate=44100, channels=2, sample_width=2)
wav_audio.export("audio1.mp3", format="mp3")
raw_audio.export("audio2.mp3", format="mp3")
You can also look here for more options.
flac_audio = AudioSegment.from_file("sample.flac", "flac")
flac_audio.export("sampleMp3.mp3", format="mp3")