Last active
June 3, 2019 02:40
-
-
Save infowolfe/ea0817f34f3dac8cd4fd76195a2ef59f to your computer and use it in GitHub Desktop.
shit script to scrape monstercat and update discord musicbot autoplaylist.txt and php script to display now playing... these are for https://github.com/Just-Some-Bots/MusicBot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from pprint import pprint | |
import json | |
import requests | |
import time | |
mc = "https://connect.monstercat.com/api" | |
licensed = set() | |
unlicensed = set() | |
yturls = set() | |
# TODO catalogue paging | |
# TODO list comparisons | |
def getjson(args): | |
#print("Getting: "+ mc + '/catalog' + args) | |
r = requests.get(mc + '/catalog' + args) | |
return json.loads(r.text) | |
totals = getjson('/browse/') | |
pagesize = totals['limit'] | |
pagestart = totals['skip'] | |
pagelen = totals['total'] | |
def getlists(args): | |
list = getjson('/browse/' + args) | |
limit, skip, total = list['limit'], list['skip'], list['total'] | |
for result in list['results']: | |
try: | |
catid = result['release']['catalogId'] | |
except: | |
continue | |
if result['licensable'] is True: | |
licensed.add(catid) | |
for urls in result['release']['urls']: | |
if urls['platform'] == 'youtube': | |
yt = urls['original'].split('&')[0] | |
yturls.add(yt) | |
elif result['licensable'] is False: | |
unlicensed.add(catid) | |
else: | |
print(catid + " No information present") | |
#pprint(list) | |
print("limit: " + str(limit) + " skip: " + str(skip) + " total: " + str(total)) | |
while pagestart < (pagelen + pagesize): | |
args = "?skip=" + str(pagestart) | |
getlists(args) | |
time.sleep(.1) | |
pagestart = pagestart + pagesize | |
#print("Licensed: ") ; pprint(licensed) | |
#print("Unlicensed:") ; pprint(unlicensed) | |
print(yturls) | |
print(len(licensed)) | |
print(len(unlicensed)) | |
with open('autoplaylist.txt', 'w') as f: | |
for item in yturls: | |
f.write("{}\n".format(item)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html><head><link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet"><style> | |
body { | |
background: rgba(0,0,0,0); | |
color: #fff; | |
font-size: 48px; | |
font-family: 'Raleway', sans-serif; | |
text-shadow: | |
-1px -1px 0 #000, | |
1px -1px 0 #000, | |
-1px 1px 0 #000, | |
1px 1px 0 #000; | |
} | |
</style><meta http-equiv="refresh" content="2"></head><body> | |
<?php | |
if ( $_GET["name"] == "changethis" ){ | |
$file = file_get_contents('/path/to/musicbot/data/discordid/current.txt'); | |
} | |
$out = preg_replace('/^\[\w+( \w+)?\]/', '', $file); | |
$out = preg_replace('/^( - )?/', '', $out); | |
//$out = preg_replace('/^\[Glitch.*\]/', '', $out); | |
$out = preg_replace('/\[Monstercat.*\].*$/', '', $out); | |
$out = preg_replace('/\[Official.*\]/', '', $out); | |
$out = preg_replace('/\[(Glitch|Drumstep).*\]/', '', $out); | |
$out = preg_replace('/^ ?(:|-)? ?/', '', $out); | |
$out = preg_replace('/\(.*\)/', '', $out); | |
echo $out . "\n"; | |
?> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment