Created
August 3, 2019 09:53
-
-
Save xSke/500bbb95cd72fbe809024aeab9e8926c to your computer and use it in GitHub Desktop.
Monstercat Gold music dumper (aria2)
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
import asyncio | |
import aiohttp | |
import aiofiles | |
import re | |
import urllib.parse as urlparse | |
sess = None | |
output_file = None | |
token = "PUT YOUR SESSION TOKEN HERE (log in, devtools, find cookie 'connect.sid')" | |
def fix_filename_ntfs(filename): | |
return re.sub("\s+", " ", re.sub(r'[<>:"/\|?*]', "", filename)) | |
async def queue_download_release(download_id, filename): | |
download_url = "https://connect.monstercat.com/api/release/{}/download?method=download&type=flac".format(download_id) | |
await output_file.write("{}\n out={}\n header=Cookie:connect.sid={}\n continue\n".format(download_url, fix_filename_ntfs(filename), token)) | |
async def queue_release_data(data): | |
if data["downloadable"]: | |
await queue_download_release(data["_id"], "[{}] {} - {}.zip".format(data["catalogId"], data["renderedArtists"], data["title"])) | |
async def fetch_release(release_id): | |
print("Fetching {}".format(release_id), flush=True) | |
async with sess.get("https://connect.monstercat.com/api/catalog/release/{}".format(release_id)) as r: | |
await queue_release_data(await r.json()) | |
async def fetch_all_releases(filter_type="", filter_id=""): | |
skip = 0 | |
seen_releases = set() | |
while True: | |
async with sess.get("https://connect.monstercat.com/api/catalog/browse/?types={}&limit=50&skip={}".format(filter_type, skip)) as r: | |
data = await r.json() | |
for result in data["results"]: | |
if "catalogId" not in result["release"]: | |
continue | |
release_id = result["release"]["catalogId"] | |
if re.match(filter_id, release_id) and release_id not in seen_releases: | |
seen_releases.add(release_id) | |
await fetch_release(release_id) | |
if len(data["results"]) != 50: | |
break | |
skip += len(data["results"]) | |
async def main(): | |
global sess, output_file | |
async with aiohttp.ClientSession(cookies={"connect.sid": token}) as sess: | |
async with aiofiles.open("download_list.txt", mode="w") as output_file: | |
await fetch_all_releases(filter_id="MC(EP|LP|UV|IV|RL|X)?\d{1,3}X?$") | |
asyncio.get_event_loop().run_until_complete(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment