tidying up
This commit is contained in:
@@ -3,7 +3,7 @@ ytmnd
|
|||||||
|
|
||||||
ytmnd scraper
|
ytmnd scraper
|
||||||
|
|
||||||
`python ./ytmnd.py [-u username] [--media-only] [--no-web-audio] [--json] [domain]`
|
`python ./ytmnd.py [--media-only] [--no-web-audio] [--json] [-u username] [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.
|
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.
|
||||||
|
|
||||||
|
|||||||
8
ytmnd.js
8
ytmnd.js
@@ -2,14 +2,12 @@
|
|||||||
var hasWebKit = ('webkitAudioContext' in window) && !('chrome' in window)
|
var hasWebKit = ('webkitAudioContext' in window) && !('chrome' in window)
|
||||||
var context = new webkitAudioContext()
|
var context = new webkitAudioContext()
|
||||||
var request = new XMLHttpRequest()
|
var request = new XMLHttpRequest()
|
||||||
|
var source
|
||||||
request.open('GET', url, true)
|
request.open('GET', url, true)
|
||||||
request.responseType = 'arraybuffer'
|
request.responseType = 'arraybuffer'
|
||||||
request.onload = function() {
|
request.onload = function() {
|
||||||
context.decodeAudioData(request.response, function(response) {
|
context.decodeAudioData(request.response, function(response) {
|
||||||
// source.loop = true
|
(function loop(){
|
||||||
loop()
|
|
||||||
var source
|
|
||||||
function loop(){
|
|
||||||
if (source) {
|
if (source) {
|
||||||
source.start(0)
|
source.start(0)
|
||||||
setTimeout(loop, source.buffer.duration * 1000 - (source.buffer.duration < 2 ? 0 : 60) )
|
setTimeout(loop, source.buffer.duration * 1000 - (source.buffer.duration < 2 ? 0 : 60) )
|
||||||
@@ -20,7 +18,7 @@
|
|||||||
source = context.createBufferSource()
|
source = context.createBufferSource()
|
||||||
source.connect(context.destination)
|
source.connect(context.destination)
|
||||||
source.buffer = response
|
source.buffer = response
|
||||||
}
|
})()
|
||||||
}, function () { console.error('The request failed.') } )
|
}, function () { console.error('The request failed.') } )
|
||||||
}
|
}
|
||||||
request.send()
|
request.send()
|
||||||
|
|||||||
12
ytmnd.py
12
ytmnd.py
@@ -15,12 +15,12 @@ class YTMND:
|
|||||||
self.no_web_audio = False
|
self.no_web_audio = False
|
||||||
self.json = False
|
self.json = False
|
||||||
|
|
||||||
|
# Scrapes sites from the profile page, then fetches them
|
||||||
def fetch_user(self, user):
|
def fetch_user(self, user):
|
||||||
if user == "":
|
if user == "":
|
||||||
print("expecting one ytmnd name, got "+str(sys.argv))
|
print("expecting one ytmnd name, got "+str(sys.argv))
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get the url of the sound and foreground
|
|
||||||
ytmnd_name = user
|
ytmnd_name = user
|
||||||
ytmnd_html = urllib2.urlopen("http://ytmnd.com/users/" + ytmnd_name + "/sites").readlines()
|
ytmnd_html = urllib2.urlopen("http://ytmnd.com/users/" + ytmnd_name + "/sites").readlines()
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@ class YTMND:
|
|||||||
ytmnd.fetch_ytmnd( domain )
|
ytmnd.fetch_ytmnd( domain )
|
||||||
os.chdir("..")
|
os.chdir("..")
|
||||||
|
|
||||||
|
# Fetches a single subdomain
|
||||||
def fetch_ytmnd(self, domain):
|
def fetch_ytmnd(self, domain):
|
||||||
|
|
||||||
if domain == "":
|
if domain == "":
|
||||||
@@ -65,6 +66,7 @@ class YTMND:
|
|||||||
if not ytmnd.media_only:
|
if not ytmnd.media_only:
|
||||||
ytmnd.write_index(ytmnd_info)
|
ytmnd.write_index(ytmnd_info)
|
||||||
|
|
||||||
|
# Fetches the gif and mp3 for a post
|
||||||
def fetch_media(self, ytmnd_info):
|
def fetch_media(self, ytmnd_info):
|
||||||
# Assign full url names for the sound and foreground
|
# Assign full url names for the sound and foreground
|
||||||
domain = ytmnd_info['site']['domain']
|
domain = ytmnd_info['site']['domain']
|
||||||
@@ -84,6 +86,7 @@ class YTMND:
|
|||||||
os.system("wget --quiet -O %s %s" % (domain + "." + gif_type, original_gif))
|
os.system("wget --quiet -O %s %s" % (domain + "." + gif_type, original_gif))
|
||||||
os.system("wget --quiet -O %s %s" % (domain + "." + wav_type, original_wav))
|
os.system("wget --quiet -O %s %s" % (domain + "." + wav_type, original_wav))
|
||||||
|
|
||||||
|
# Writes an html file emulating the ytmnd format
|
||||||
def write_index(self, ytmnd_info):
|
def write_index(self, ytmnd_info):
|
||||||
|
|
||||||
# print simplejson.dumps(ytmnd_info)
|
# print simplejson.dumps(ytmnd_info)
|
||||||
@@ -132,10 +135,12 @@ class YTMND:
|
|||||||
|
|
||||||
fn.close()
|
fn.close()
|
||||||
|
|
||||||
|
# Copies the looping audio JS into place
|
||||||
def copy_ytmnd_js (self):
|
def copy_ytmnd_js (self):
|
||||||
if not os.path.isfile("ytmnd.js"):
|
if not os.path.isfile("ytmnd.js"):
|
||||||
os.system("cp ../ytmnd.js .")
|
os.system("cp ../ytmnd.js .")
|
||||||
|
|
||||||
|
# Writes site JSON to a file
|
||||||
def write_json (self, ytmnd_info):
|
def write_json (self, ytmnd_info):
|
||||||
domain = ytmnd_info['site']['domain']
|
domain = ytmnd_info['site']['domain']
|
||||||
|
|
||||||
@@ -148,8 +153,8 @@ if __name__ == '__main__':
|
|||||||
parser = OptionParser()
|
parser = OptionParser()
|
||||||
|
|
||||||
parser.add_option("-u", "--user", action="store_true")
|
parser.add_option("-u", "--user", action="store_true")
|
||||||
parser.add_option("--media-only", action="store_true")
|
parser.add_option("-m", "--media-only", action="store_true")
|
||||||
parser.add_option("--no-web-audio", action="store_true")
|
parser.add_option("-w", "--no-web-audio", action="store_true")
|
||||||
parser.add_option("-j", "--json", action="store_true")
|
parser.add_option("-j", "--json", action="store_true")
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
@@ -170,3 +175,4 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
name = args[0].replace("http://","").replace(".ytmnsfw.com","").replace(".ytmnd.com","").replace("/","")
|
name = args[0].replace("http://","").replace(".ytmnsfw.com","").replace(".ytmnd.com","").replace("/","")
|
||||||
ytmnd.fetch_ytmnd( name )
|
ytmnd.fetch_ytmnd( name )
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user