Python Code to Download MP3 from a YouTube URL

Nerd Stuff

Wrote a Python program to take a YouTube URL, extract and convert the audio to a MP3 file. It has a minimalist GUI. It requires tkinter, youtube-dl (a Linux command line tool), and ffmpeg.

import os
import subprocess

import tkinter as tk
from tkinter import filedialog

# Create the GUI window
window = tk.Tk()
window.title("YouTube Downloader")

# Create a function to be called when the user clicks the "Download" button
def download_video():
  # Get the URL of the YouTube video from the user's input
  url = url_entry.get()
  # Download the video using youtube-dl
  subprocess.run(["youtube-dl", url])
  # Get the filename of the video from youtube-dl's output
  video_filename = subprocess.run(["youtube-dl", "--get-filename", url], capture_output=True).stdout.strip().decode("utf-8")
  # Prompt the user to select a location and filename for the MP3 file
  mp3_filename = filedialog.asksaveasfilename(defaultextension=".mp3")
  # Convert the video to an MP3 file using ffmpeg
  subprocess.run(["ffmpeg", "-i", video_filename, mp3_filename])

# Create a label and text entry field for the URL
url_label = tk.Label(text="Enter the URL of the YouTube video:")
url_entry = tk.Entry()

# Create a button to start the download
download_button = tk.Button(text="Download", command=download_video)

# Place the widgets in the GUI window
url_label.pack()
url_entry.pack()
download_button.pack()

# Run the GUI event loop
window.mainloop()

Comments



Remove dots in filename

Nerd Stuff

I wrote a Bash Script to remove excess periods in a filename. For example, if you had a file named “some.words.in.your.filename.txt”, this script will assist in renaming it to “some words in your filename.txt”. Of course, this only works in Linux. You need to save the file below as a .sh and make it executable via the chmod command. Click “Read More” to see the code.

Read more: Remove dots in filename
#!/bin/bash

# Get the filename argument
filename="$1"

# Get the extension of the filename
extension="${filename##*.}"

# Remove the extension from the filename
filename="${filename%.*}"

# Replace all dots in the filename with spaces
new_filename="${filename//./ }.$extension"

# Print the suggested new filename
echo "Suggested new filename: $new_filename"

# Prompt the user for confirmation
read -p "Do you want to rename the file? (y/n) " choice

if [[ $choice == "y" || $choice == "Y" ]]; then
    # Rename the file
    mv "$1" "$new_filename"
    echo "File renamed to $new_filename"
else
    echo "File not renamed"
fi
Read more: Remove dots in filename

Comments



Laser Cutting Coffee Mugs

Laser Cutting, Nerd Stuff

Cut some coffee mugs to be given out as Christmas presents for my wife. Figured I’d post some videos of the rough process. Some of the videos (unedited) drag out. Feel free to fast forward, or skip.

I’m using a fairly heavily modified (and contraption-ed) K-40 laser cutter.

   
 

  
  

  
  

  
  
  
  
  

  
  
  
  
 



Comments



Ammo Can Raspberry Pi Media Center

Nerd Stuff

I’ve been asked by a few people to post pictures and give a parts list for my media center.

This is the device I plug into my TV so I can watch movies and TV shows on it. I just select the movie/TV show I want, and wha-la. It does a good job of automatically downloading cover art from the internet and giving brief plot summaries.
Read the rest of this entry »

Comments



Sous-Vide

Nerd Stuff

I finally finished my Sous-Vide setup back in 2011.
Read the rest of this entry »

Comments off



Harkers Island, NC to Pax River (Lexington Park), MD Time Lapse

Nerd Stuff, Pictures

Here’s the time lapse from Harkers Island, NC to Lexington Park, MD. Was a drive up for work.

Created with a cheap webcam (moved up to a cheap HP webcam) connected to a MacBook running Gawker. The mount consisted of a wooden spoon held to the rearview mirror using a clamp and zip-ties.

Comments off



2010-05-06 Time Lapse of Sunset at Shell Point

Nerd Stuff, Pictures

Was taken with a Canon Digital Rebel with a programmable trigger, mounted on a tripod. Individual frames then combined in Quicktime.

Comments off



2010-02-12 Time Lapse of Snow Fall.

Nerd Stuff, Pictures

Comments off



Time Lapse video from Dayton, OH to Harkers Island NC.

Nerd Stuff, Pictures

Time lapse video taken from Dayton, Ohio to Harkers Island, North Carolina. Less than 30 mins total about 12 hours drive time. The sun rises about four minutes into the video (if the night is unbearable, fast forward 4:00). You can see it set about 15 minutes later. A whole day of driving compressed into less than 20 minutes.

The route was out of Ohio, through West Virginia, Virginia, than through NC. A large portion of it was though the Appalachian Mountains. If you look carefully at the video you can see it starting to sleet, then snow for a period.

Click “The Read the Rest of the Entry” to see.

 

image_map image_map image_map

Created with a cheap webcam (Dynex® – 1.3MP Webcam) connected to a MacBook running Gawker. Created two iterations of custom mounts. The first was created out of PVC with holes cut so the head rest of the car’s seat could pass though it. The second was a wooden spoon held to the rearview mirror using a clamp and zip-ties.

Comments off



Nerd Paper

Nerd Stuff

Misc. engineering paper just right for printing…

Comments off