SourceCode -- That Domain
Program and Script SourceCode
I do a little programming in my free time using python, and it's nice and pretty enjoyable. I put together some applications and command line utilities to serve my needs or just to do something creative, and the code is below. Enjoy.
Projects I'm Working On
DescribeMe
A small utility which you can enter an image path to and have a program return you a description of it, using the Google Teseract Engine library. Useful if you're blind. Currently, it doesn't work, but here is what I have so far.
Third-Party Dependencies
Show Code
import PIL
import pytesseract
import tkinter as tk
from tkinter import filedialog
import pyperclip
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
open_image = image.open(file_path)
image_description = pytesseract.image_to_string(open_image)
pyperclip.copy(image_description)
print(image_description)
Last Updated on April 22, 2020
MergeUtil
This is actually a fully completed utility that allows you to merge an audio track of choice to a video track of choice. It needs some work before I can compile it into a Windows executable, but for now it works just fine as a python script
Third Party Dependencies
- MoviePY
Show Code>
from moviepy.editor import *
import tkinter as tk
from tkinter import filedialog
from time import sleep
from os import getlogin
from sys import exit
import msvcrt
def main():
root = tk.Tk()
videopath = filedialog.askopenfilename(title="select your video track")
audiopath = filedialog.askopenfilename(title="Select your audio track of filetype WAV, MP3, or OGG")
root.withdraw()
exportname = input("Enter Name Of File To Save To")
extention = ".mp4"
exportname = "/music/" + exportname + extention
user = getlogin()
fullpath = "c:/users/" + user + exportname
print("Merging tracks...")
videotrack = VideoFileClip(videopath)
audiotrack = AudioFileClip(audiopath)
merged = videotrack.set_audio(audiotrack)
merged.write_videofile(fullpath, temp_audiofile="c:/users/public/gay.mp3")
sleep(5)
print("Merge complete. This file has been saved in your Music folder")
sleep(2)
main()
print("Press Q to quit or M to merge more tracks")
while True:
if msvcrt.kbhit():
close = msvcrt.getch()
if close == b'q':
exit()
elif close == b'm':
main()
Last Update Date: April 22, 2020
Save For Later
This is actually a very cool program. It's a service that I wrote because I do a lot of web surfing on my phone, and a lot of the time I come across links that I want to download, but obviously doing it on mobile is kinda not the way to go. So instead, I developed this script, which runs in the background on your PC and checks for new downloads, which you can send to it via a serverside php page. It works well, but is not without its flaws. For instance, anyone in the world could go to that page and post links to the script, and download anything they wanted to your machine: viruses, malware, etc. Protecting the page with http o auth or similar is up to you as a user. This script also cannot download from links that redirect to files, yet, which is a feature I plan to add. Check it all out below.
Third-Party Dependancies:
Notes:
- For testing purposes, all program data is saved to c:\users\public\saveforlater so as to cause the least amount of errors when debugging file creation
Show Code (Client)
import datetime
import os
import requests
from time import sleep
from win10toast import ToastNotifier
#Define a function to be run at program execution
def initialize():
#Check For the current link
url = 'https://www.that-domain.com/saveforlater/links.linkdata'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
filecontent = requests.get(url, headers=headers)
#write it to link 0, which will always be the link last retrieved
global link0
link0 = filecontent.content.decode()
print(link0)
#Now open up the file that had the last link retrieved before the program shut down in it
try:
os.mkdir("c:/users/public/saveforlater")
except FileExistsError:
pass
try:
f = open("c:/users/public/SaveForLater/lastlink.txt", "x")
except FileExistsError:
pass
f = open("c:/users/public/SaveForLater/lastlink.txt", "r")
saved_url = f.read()
f.close()
#compare link 0, the current link, to the link we got from the file
if link0 == saved_url:
pass
else:
#since our download function downloads the url in the link1 variable, set link 0 to link1
global link1
link1 = 0
link1 = link0
download()
#now that we've checked to make sure we got the most recent link downloaded, define the function to check for new urls which we'll run later
def check_for_new():
#access the file with links in it and append the last one to link one
print("checking for new URL's")
url = 'https://www.that-domain.com/saveforlater/links.linkdata'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
filecontent = requests.get(url, headers=headers)
global link1
link1 = filecontent.content.decode()
global link0
#compare link 0, our last link to link1, the link we just got
if link0 == link1:
pass
else:
download()
save()
def log(err):
current = datetime.datetime.now()
global link1
logmessage = f"On {current}, there was an error while attempting to download the file found at\n{link1}\nThe program error was: \n{err}"
try:
f = open("c:/users/public/SaveForLater/saveforlater.log", "x")
except FileExistsError:
pass
f = open("c:/users/public/SaveForLater/saveforlater.log", "a")
f.write(logmessage)
f.close()
def download():
global link1
if link1.find('/'):
filename = link1.rsplit('/', 1)[1]
filepath = 'c:/users/mason/downloads/'
location = filepath + filename
filename_message = f"Now downloading {filename}"
toaster = ToastNotifier()
toaster.show_toast("New Download Detected!",filename_message)
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
dl = open(location,'wb')
try:
r = requests.get(link1, headers=headers, stream=True)
except Exception as err:
log(err)
toaster.show_toast("Error downloading!","Unfortunately, there was an error while attempting to download this file. Please consult the \"SaveForLater\" program log found at: \"c:\\users\\public\\saveforlater\\saveforlater.log\" for more details.")
return
for chunk in r.iter_content(1024):
dl.write(chunk)
dl.close
toaster.show_toast("Your download has finished!","SaveForLater has finished downloading your file")
def save():
global link0
global link1
f = open("c:/users/public/SaveForLater/lastlink.txt", "w")
f.write(link1)
f.close()
link0 = link1
initialize()
while True:
check_for_new()
sleep(30)
Show Code (Server)
New Download -- Save For Later