From 46e71750a4955b3bb72bb7bc88f39d80c3fece96 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 9 Jul 2015 03:06:01 -0400 Subject: [PATCH] v0.1 --- .gitignore | 2 + ytmnd.js | 27 +++++++++ ytmnd.py | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 .gitignore create mode 100644 ytmnd.js create mode 100644 ytmnd.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..538c8c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +*~ diff --git a/ytmnd.js b/ytmnd.js new file mode 100644 index 0000000..c467d27 --- /dev/null +++ b/ytmnd.js @@ -0,0 +1,27 @@ +(function(){ + var hasWebKit = ('webkitAudioContext' in window) && !('chrome' in window) + var context = new webkitAudioContext() + var request = new XMLHttpRequest() + request.open('GET', url, true) + request.responseType = 'arraybuffer' + request.onload = function() { + context.decodeAudioData(request.response, function(response) { + // source.loop = true + loop() + var source + function loop(){ + if (source) { + source.start(0) + setTimeout(loop, source.buffer.duration * 1000 - 60) + } + else { + setTimeout(loop, 0) + } + source = context.createBufferSource() + source.connect(context.destination) + source.buffer = response + } + }, function () { console.error('The request failed.') } ) + } + request.send() +})() diff --git a/ytmnd.py b/ytmnd.py new file mode 100644 index 0000000..2ede9d2 --- /dev/null +++ b/ytmnd.py @@ -0,0 +1,164 @@ +#!/usr/bin/python + +import sys +import aifc +import os +import os.path +import re +import urllib2 +import simplejson +import random +from optparse import OptionParser + +ytmnd_js = """ +(function(){ + var hasWebKit = ('webkitAudioContext' in window) && !('chrome' in window) + var context = new webkitAudioContext() + var request = new XMLHttpRequest() + request.open('GET', url, true) + request.responseType = 'arraybuffer' + request.onload = function() { + context.decodeAudioData(request.response, function(response) { + // source.loop = true + loop() + var source + function loop(){ + if (source) { + source.start(0) + setTimeout(loop, source.buffer.duration * 1000 - 60) + } + else { + setTimeout(loop, 0) + } + source = context.createBufferSource() + source.connect(context.destination) + source.buffer = response + } + }, function () { console.error('The request failed.') } ) + } + request.send() +})() +""" + + +class YTMND: + + def fetch_user(self, user): + if user == "": + print("expecting one ytmnd name, got "+str(sys.argv)) + return + + # Get the url of the sound and foreground + ytmnd_name = user + ytmnd_html = urllib2.urlopen("http://ytmnd.com/users/" + ytmnd_name + "/sites").readlines() + + domains = [] + + for line in ytmnd_html: + if 'profile_link' in line: + + expr = r"href=\"http://(\S+).ytmnd.com\"" + domain = re.search(expr,line).group(1) + domains.append(domain) + + print ">> found %d domains" % len( domains ) + os.system("mkdir %s" % user) + os.chdir(user) + self.write_ytmnd_js() + for domain in domains: + ytmnd_info = ytmnd.fetch_ytmnd( domain ) + ytmnd.fetch_media(ytmnd_info) + ytmnd.write_index(ytmnd_info) + os.chdir("..") + + return ytmnd_info + + def fetch_ytmnd(self, domain): + + if domain == "": + print("expecting one ytmnd name, got "+str(sys.argv)) + return + + print "fetching %s" % domain + + # Get the url of the sound and foreground + ytmnd_name = domain + ytmnd_html = urllib2.urlopen("http://" + domain + ".ytmnd.com").read() + expr = r"ytmnd.site_id = (\d+);" + ytmnd_id = re.search(expr,ytmnd_html).group(1) + ytmnd_info = simplejson.load(urllib2.urlopen("http://" + domain + ".ytmnd.com/info/" + ytmnd_id + "/json")) + + return ytmnd_info + + def fetch_media(self, ytmnd_info): + # Assign full url names for the sound and foreground + domain = ytmnd_info['site']['domain'] + original_gif = ytmnd_info['site']['foreground']['url'] + original_wav = ytmnd_info['site']['sound']['url'] + + # download files + os.system("wget --quiet -O %s %s" % (domain + ".gif", original_gif)) + os.system("wget --quiet -O %s %s" % (domain + ".mp3", original_wav)) + + def write_index(self, ytmnd_info): + + # print simplejson.dumps(ytmnd_info) + domain = ytmnd_info['site']['domain'] + bgcolor = ytmnd_info['site']['background']['color'] + + fn = open(domain + ".html", 'w') + fn.write("") + fn.write("") +# fn.write("