<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dheeraj-programmer</title>
    <description>The latest articles on DEV Community by Dheeraj-programmer (@dheerajprogrammer).</description>
    <link>https://dev.to/dheerajprogrammer</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F763163%2F2a80af66-53e0-4e6a-ba3c-9ea8bac84753.png</url>
      <title>DEV Community: Dheeraj-programmer</title>
      <link>https://dev.to/dheerajprogrammer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dheerajprogrammer"/>
    <language>en</language>
    <item>
      <title>Mp4 to Mp3 converter in Python</title>
      <dc:creator>Dheeraj-programmer</dc:creator>
      <pubDate>Sat, 25 Dec 2021 08:49:44 +0000</pubDate>
      <link>https://dev.to/dheerajprogrammer/mp4-to-mp3-converter-in-python-5eba</link>
      <guid>https://dev.to/dheerajprogrammer/mp4-to-mp3-converter-in-python-5eba</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;You can convert any Mp4 to Mp3 using this app.I use tkinter to select file and a for GUI interface.If you don't want to use tkinter so don't use. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I didn't not add error handling code&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;tkinter which is pre installed with python&lt;br&gt;
&lt;code&gt;pip install moviepy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Moviepy:&lt;/strong&gt; MoviePy (full &lt;a href="https://zulko.github.io/moviepy/"&gt;documentation&lt;/a&gt;) is a Python library for video editing: cutting, concatenations, title insertions, video compositing (a.k.a. non-linear editing), video processing, and creation of custom effects. See the &lt;a href="https://zulko.github.io/moviepy/gallery.html"&gt;gallery&lt;/a&gt; for some examples of use.&lt;br&gt;
MoviePy can read and write all the most common audio and video formats, including GIF, and runs on Windows/Mac/Linux, with Python 2.7+ and 3 (or only Python 3.4+ from v.1.0).&lt;/p&gt;
&lt;h2&gt;
  
  
  Let's code
&lt;/h2&gt;

&lt;p&gt;First, You need to add these import statements&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import tkinter as tk
from tkinter.filedialog import askopenfile
from tkinter.messagebox import showinfo
from moviepy.editor import VideoFileClip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I am using class you can use function. Create a class Converter inherit the tkinter class, make a constructor, set the window height and width, create a label, create a button to select the mp4 file and give a function to run on pressing the button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get more tkinter projects ideas &lt;a href="https://amzn.to/30TUp7Q"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Converter(tk.Tk):
    def __init__(self):
        super().__init__()
        self.geometry("500x250")
        convert_label = tk.Label(self, text="Convert to mp3:", font="lucida 40")
        convert_label.pack()

        select_mp3 = tk.Button(self, text="Select", font="lucida 15", command=self.convert_to_mp3)
        select_mp3.pack()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create the function which convert the file mp4 to mp3. askopenfile function is used to open a popup window to select the file in reading mode and store the file name using .name and replace the mp4 to mp3 in string to save the file as mp3&lt;/p&gt;

&lt;p&gt;Give the mp4 file name in VideoFileClip and store the audio in audio variable and now use the write_audiofile function by giving the mp3 file name then close the video, audio and use the showinfo to display a message when the file is converted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def convert_to_mp3(self):
        file = askopenfile(mode="r", filetypes=[('mp4 file', '*.mp4')])
        mp4_file = file.name
        mp3_file = mp4_file.replace("mp4", "mp3")

        video = VideoFileClip(mp4_file)
        audio = video.audio
        audio.write_audiofile(mp3_file)

        audio.close()
        video.close()
        showinfo(title="Done", message="Your mp4 file has been converted to mp3\nCheck your directory")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now finally create the class instace and run the mainloop function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;convert = Converter()
convert.mainloop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The all code look like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("Importing...")
import tkinter as tk
from tkinter.filedialog import askopenfile
from tkinter.messagebox import showinfo
from moviepy.editor import VideoFileClip
print("Working...")


class Converter(tk.Tk):
    def __init__(self):
        super().__init__()
        self.geometry("500x250")
        convert_label = tk.Label(self, text="Convert to mp3:", font="lucida 40")
        convert_label.pack()

        select_mp3 = tk.Button(self, text="Select", font="lucida 15", command=self.convert_to_mp3)
        select_mp3.pack()

    def convert_to_mp3(self):
        file = askopenfile(mode="r", filetypes=[('mp4 file', '*.mp4')])
        mp4_file = file.name
        mp3_file = mp4_file.replace("mp4", "mp3")

        video = VideoFileClip(mp4_file)
        audio = video.audio
        audio.write_audiofile(mp3_file)

        audio.close()
        video.close()
        showinfo(title="Done", message="Your mp4 file has been converted to mp3\nCheck your directory")

convert = Converter()
convert.mainloop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;If you are still reading here please like my content&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  For more projects subscribe to &lt;a href="https://www.youtube.com/channel/UCKTATjpJ8uzVDbtaMpwlMbA"&gt;channel&lt;/a&gt; and
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Get more Python projects &lt;a href="https://amzn.to/3Fq3sMX"&gt;here&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;AFFILIATE DISCLOSER:&lt;/strong&gt; This post includes affiliate links.I may receive compensation if you purchase products or services from the different links provided in this article.&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>project</category>
      <category>node</category>
    </item>
    <item>
      <title>How to download You Tube video using Python</title>
      <dc:creator>Dheeraj-programmer</dc:creator>
      <pubDate>Wed, 22 Dec 2021 11:21:02 +0000</pubDate>
      <link>https://dev.to/dheerajprogrammer/how-to-download-you-tube-video-using-python-52mp</link>
      <guid>https://dev.to/dheerajprogrammer/how-to-download-you-tube-video-using-python-52mp</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;In this post you know about how to download youtube vidoes very easily in only in only four lines of code!!&lt;/p&gt;

&lt;h2&gt;
  
  
  Save your time watch video!
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://youtu.be/2Wb2313oHxc"&gt;Watch now&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirments
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;pip install pytube&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pytube:&lt;/strong&gt; Pytube is a very serious, lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos. If You want to know more about pytube take a look of &lt;a href="//pytube.io"&gt;documentaion&lt;/a&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Let's code
&lt;/h2&gt;

&lt;p&gt;First import youtube from pytube&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from pytube import YouTube
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Get more tkinter projects ideas &lt;a href="https://amzn.to/30TUp7Q"&gt;here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Make a variable and paste the web url link of any video don't use the link which you get click on share button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;youtube = YouTube('https://www.youtube.com/watch?v=2Wb2313oHxc')
video = youtube.streams.first()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The streams function is fetch video description, title, thumbnail and all these things but only for download video use first() with streams&lt;/p&gt;

&lt;p&gt;Then finally use the download function to download the video and give the directory path where you want to download video&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;video.download('C:/Users/96650/Desktop/')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The all code look like this!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from pytube import YouTube
youtube = YouTube('https://www.youtube.com/watch?v=2Wb2313oHxc')
video = youtube.streams.first()
video.download('C:/Users/96650/Desktop/')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;If you still reading here please like my content&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  For more projects subscribe to &lt;a href="https://www.youtube.com/channel/UCKTATjpJ8uzVDbtaMpwlMbA"&gt;channel&lt;/a&gt; and
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Get more Python projects &lt;a href="https://amzn.to/3Fq3sMX"&gt;here&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;*&lt;em&gt;AFFILIATE DISCLOSER: *&lt;/em&gt; This post includes affiliate links.I may receive compensation if you purchase products or services from the different links provided in this article.&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
      <category>projectbenatar</category>
    </item>
  </channel>
</rss>
