readme
This commit is contained in:
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
ytmnd
|
||||||
|
=====
|
||||||
|
|
||||||
|
ytmnd scraper
|
||||||
|
|
||||||
|
`./ytmnd.py [-u username] [domain]`
|
||||||
|
|
||||||
35
ytmnd.py
35
ytmnd.py
@@ -20,9 +20,9 @@ ytmnd_js = """
|
|||||||
request.onload = function() {
|
request.onload = function() {
|
||||||
context.decodeAudioData(request.response, function(response) {
|
context.decodeAudioData(request.response, function(response) {
|
||||||
// source.loop = true
|
// source.loop = true
|
||||||
loop()
|
loop()
|
||||||
var source
|
var source
|
||||||
function loop(){
|
function loop(){
|
||||||
if (source) {
|
if (source) {
|
||||||
source.start(0)
|
source.start(0)
|
||||||
setTimeout(loop, source.buffer.duration * 1000 - 60)
|
setTimeout(loop, source.buffer.duration * 1000 - 60)
|
||||||
@@ -33,7 +33,7 @@ ytmnd_js = """
|
|||||||
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()
|
||||||
@@ -43,6 +43,9 @@ ytmnd_js = """
|
|||||||
|
|
||||||
class YTMND:
|
class YTMND:
|
||||||
|
|
||||||
|
def __init__ (self):
|
||||||
|
self.media_only = False
|
||||||
|
|
||||||
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))
|
||||||
@@ -68,7 +71,8 @@ class YTMND:
|
|||||||
for domain in domains:
|
for domain in domains:
|
||||||
ytmnd_info = ytmnd.fetch_ytmnd( domain )
|
ytmnd_info = ytmnd.fetch_ytmnd( domain )
|
||||||
ytmnd.fetch_media(ytmnd_info)
|
ytmnd.fetch_media(ytmnd_info)
|
||||||
ytmnd.write_index(ytmnd_info)
|
if get_media:
|
||||||
|
ytmnd.write_index(ytmnd_info)
|
||||||
os.chdir("..")
|
os.chdir("..")
|
||||||
|
|
||||||
return ytmnd_info
|
return ytmnd_info
|
||||||
@@ -88,6 +92,10 @@ class YTMND:
|
|||||||
ytmnd_id = re.search(expr,ytmnd_html).group(1)
|
ytmnd_id = re.search(expr,ytmnd_html).group(1)
|
||||||
ytmnd_info = simplejson.load(urllib2.urlopen("http://" + domain + ".ytmnd.com/info/" + ytmnd_id + "/json"))
|
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
|
return ytmnd_info
|
||||||
|
|
||||||
def fetch_media(self, ytmnd_info):
|
def fetch_media(self, ytmnd_info):
|
||||||
@@ -114,10 +122,11 @@ class YTMND:
|
|||||||
fn.write("background-position: center center; background-repeat: no-repeat;}")
|
fn.write("background-position: center center; background-repeat: no-repeat;}")
|
||||||
fn.write("</style>")
|
fn.write("</style>")
|
||||||
fn.write("<body></body>")
|
fn.write("<body></body>")
|
||||||
# fn.write("<body><audio src=%s.mp3 loop autoplay></body>" % domain)
|
fn.write("<script type='application/json'>")
|
||||||
# fn.write("<script>")
|
fn.write( simplejson.dumps(ytmnd_info, sort_keys=True, indent=4 * ' ') )
|
||||||
# fn.write( simplejson.dumps(ytmnd_info, sort_keys=True, indent=4 * ' ') )
|
fn.write("</script>")
|
||||||
# fn.write("</script>")
|
|
||||||
|
# fn.write("<body><audio src=%s.mp3 loop autoplay></body>" % domain)
|
||||||
fn.write("<script>var url = '%s.mp3'</script>" % domain)
|
fn.write("<script>var url = '%s.mp3'</script>" % domain)
|
||||||
|
|
||||||
fn.write("<script src='ytmnd.js'></script>")
|
fn.write("<script src='ytmnd.js'></script>")
|
||||||
@@ -144,12 +153,12 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
print "usage: ./ytmnd.py [-u username] [--media] [domain]"
|
print "usage: ./ytmnd.py [-u username] [--media] [domain]"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
ytmnd = YTMND ()
|
ytmnd = YTMND ()
|
||||||
|
ytmnd.media_only = options.media
|
||||||
|
|
||||||
if options.user:
|
if options.user:
|
||||||
user = args[0]
|
user = args[0]
|
||||||
@@ -157,8 +166,4 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
name = args[0]
|
name = args[0]
|
||||||
ytmnd_info = ytmnd.fetch_ytmnd( name )
|
ytmnd.fetch_ytmnd( name )
|
||||||
ytmnd.fetch_media(ytmnd_info)
|
|
||||||
if not options.media:
|
|
||||||
self.write_ytmnd_js()
|
|
||||||
ytmnd.write_index(ytmnd_info)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user