Created
May 9, 2022 13:07
-
-
Save yzAlvin/13426630e7b05e7bb2b9919bd55c0121 to your computer and use it in GitHub Desktop.
SlipySlidy Playlist Scraper
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 re | |
from pytube import Playlist | |
from pytube import YouTube | |
import jsonpickle | |
from dataclasses import dataclass | |
@dataclass | |
class Metadata: | |
albumArtist: str | |
artist: str | |
title: str | |
year: str | |
@dataclass | |
class Source: | |
client: str | |
date: str | |
structure: str | |
version: str | |
@dataclass | |
class Song: | |
description: str | |
filename: str | |
mark: str | |
metadata: Metadata | |
source: Source | |
youtube: str | |
url = "https://www.youtube.com/playlist?list=PLARr36qkoiWbhGZEZDvgv6F5vfRMR79_q" | |
playlist = Playlist(url) | |
playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)") | |
f = open("Bgm_MapleStory2.json", "a") | |
for url in playlist.video_urls: | |
youtube = url.split("https://www.youtube.com/watch?v=")[1] | |
yt = YouTube(url) | |
description = yt.title.split("[MapleStory 2 BGM] ")[1] | |
filename = "".join(description.split()) | |
mark = filename | |
date = yt.publish_date.date() | |
metadata = Metadata("Wizet", "StudioEIM", description, f'{date.year}') | |
source = Source("MS2", date, "Bgm_MapleStory2", "1.0") | |
song = Song(description, filename, mark, metadata, source, youtube) | |
songJson = jsonpickle.encode(song, unpicklable=False) | |
print(songJson) | |
f.write(f'{songJson},') | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
scrape https://www.youtube.com/user/SlipySlidy playlist and write to json format in https://github.com/maplestory-music/maplebgm-db
need to do some manual work to make it a json array and format nicely 😅