From b73e16477abae56ec26f566ca725fb5087d10fb3 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 9 Jul 2015 03:44:04 -0400 Subject: [PATCH] adding options --- .gitignore | 5 +++++ README.md | 8 +++++++- ytmnd.py | 49 +++++++++++++++++++++++++++++-------------------- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 538c8c5..8756f34 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ .DS_Store *~ +typogra +klasky +alas +ROY4L +directory diff --git a/README.md b/README.md index 13fd918..6de21c4 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,11 @@ ytmnd ytmnd scraper -`python ./ytmnd.py [-u username] [domain]` +`python ./ytmnd.py [-u username] [--media-only] [--no-web-audio] [--json] [domain]` + +html files use web audio api in an attempt to get (almost) seamless looping. to load these files run an http server from the directory, e.g. + +`python -m SimpleHTTPServer 8000` + +and navigate to http://lvh.me:8000/ diff --git a/ytmnd.py b/ytmnd.py index fbf9552..e34d120 100755 --- a/ytmnd.py +++ b/ytmnd.py @@ -43,6 +43,8 @@ class YTMND: def __init__ (self): self.media_only = False + self.no_web_audio = False + self.json = False def fetch_user(self, user): if user == "": @@ -63,18 +65,14 @@ class YTMND: domains.append(domain) print ">> found %d domains" % len( domains ) - os.system("mkdir %s" % user) + os.system("mkdir -p %s" % user) os.chdir(user) - self.write_ytmnd_js() + if not self.no_web_audio: + self.write_ytmnd_js() for domain in domains: - ytmnd_info = ytmnd.fetch_ytmnd( domain ) - ytmnd.fetch_media(ytmnd_info) - if get_media: - ytmnd.write_index(ytmnd_info) + ytmnd.fetch_ytmnd( domain ) os.chdir("..") - return ytmnd_info - def fetch_ytmnd(self, domain): if domain == "": @@ -90,17 +88,22 @@ class YTMND: ytmnd_id = re.search(expr,ytmnd_html).group(1) ytmnd_info = simplejson.load(urllib2.urlopen("http://" + domain + ".ytmnd.com/info/" + ytmnd_id + "/json")) - ytmnd.fetch_media(ytmnd_info) - if not ytmnd.media_only: - ytmnd.write_index(ytmnd_info) - - return ytmnd_info + if ytmnd.json: + ytmnd.write_json(ytmnd_info) + else: + ytmnd.fetch_media(ytmnd_info) + if not ytmnd.media_only: + ytmnd.write_index(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'] + + if 'alternates' in ytmnd_info['site']['sound']: + key, value = ytmnd_info['site']['sound']['alternates'].popitem() + original_wav = value['file_url'] # download files os.system("wget --quiet -O %s %s" % (domain + ".gif", original_gif)) @@ -124,10 +127,12 @@ class YTMND: fn.write( simplejson.dumps(ytmnd_info, sort_keys=True, indent=4 * ' ') ) fn.write("") - # fn.write("