Skip to content

Instantly share code, notes, and snippets.

@blha303
blha303 / song2video.py
Last active February 5, 2018 14:49
A script to generate videos from a directory of songs
#!/usr/bin/env python3
# A script to generate videos for MP3s
from moviepy.editor import *
import numpy as np
from PIL import Image
from glob import glob
from mutagen.mp3 import MP3
from io import BytesIO
#points
@blha303
blha303 / howl-fm_download.js
Last active June 10, 2017 17:06
howl.fm playlist downloader. I just don't like paywalls, sorry
a = document.getElementsByTagName("a");
out = "";
for (var i=0;i<a.length;i++) {
if (a[i].hasAttribute("data-stream-url")) {
out = out + " '" + a[i].getAttribute("data-stream-url") + "'"
}
};
prompt("urls:", out)
//then use that with something like wget. you'll get a bunch of long filenames. use the below script to fix the filenames
@blha303
blha303 / bc_col.py
Created May 24, 2017 15:02
A tool to load a Bandcamp collection and print the urls for all included albums and tracks
#!/usr/bin/env python3
# A tool to load a Bandcamp collection and print the urls for all included albums and tracks
import requests
import click
import json
def get_data(user):
data = requests.get("https://bandcamp.com/{}".format(user)).text
if " item_details" not in data:
return False
@blha303
blha303 / radio.py
Created May 5, 2017 20:36
Generates a shuffled playlist of files in a subdirectory, pops the first item from the playlist, then re-generates a new playlist when the current one is run down. Intended for use with ices
#!/usr/bin/env python2
from __future__ import print_function
import sys
from glob import glob
from random import shuffle
import os.path
def playdir(directory):
def get_playlist():
playlist = glob("{}/*.ogg".format(directory))
@blha303
blha303 / localport.js
Created May 1, 2017 05:57
A bookmarklet to redirect to a web service running on the lan interface
// I wanted a bookmarklet to take me to the local instance of Plex running on my desktop, so Chromecast would function correctly
// (if I used localhost it wouldn't send the correct uri)
// For this I had to get the local ethernet interface IP
// I initiate a connection to 0.0.0.0, then use the data on the connection object to get the interface IP used for that connection
// May not work on the most popular web browser
var path = prompt("Enter uri (e.g http://{}:32400/web)");
// var path = "http://{}:32400/web";
var RTCPeerConnection = window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
RTCPeerConnection && function() {
function c(ip) {
#!/usr/bin/env python3.6
import fire # pypi.python.org/pypi/fire
class Example:
def hello(self, name="world"):
"""Testing"""
return f"Hello {name}!"
def main():
fire.Fire(Example)
@blha303
blha303 / fib.py
Created April 9, 2017 07:38
gotcha fibonacci right here m8
from __future__ import print_function
from sys import stdout
def fib(x,y,f=stdout):
print(x,file=f)
z = x + y
return y,z
def main():
n = (0,1)
@blha303
blha303 / unread.py
Last active March 9, 2017 18:17
Unread, a python script that can be set up in a scheduler to show desktop notifications for Reddit messages. Cross platform!
#!/usr/bin/env python3
c = {
"client_id": "",
"client_secret": "",
"refresh_token": "" # obtained after running script for first time
}
import os
import sys
import time
@blha303
blha303 / hbget.py
Last active January 1, 2024 04:28
Humble Bundle: save all torrents
# pypi:humblebundle has to deal with captchas. I can't be bothered.
import requests
import json
import subprocess
keys = [k["gamekey"] for k in json.loads(""" #paste contents of https://www.humblebundle.com/api/v1/user/order here
""")
# Open your browser's Network console while going to the above url, find the headers, paste them below
headers = {"Cookie": "", "User-Agent": ""}
@blha303
blha303 / deluge-downloading.py
Created February 9, 2017 12:53
A script that lists currently downloading torrents in Deluge. Uses deluge-client and hurry.filesize from pypi
#!/usr/bin/env python3
def sec(s):
m,s = divmod(int(s), 60)
h,m = divmod(m,60)
return "%d:%02d:%02d" % (h,m,s)
def convert(data):
if isinstance(data, bytes): return data.decode('ascii')
if isinstance(data, dict): return dict(map(convert, data.items()))
if isinstance(data, tuple): return map(convert, data)