Created
July 23, 2021 05:37
-
-
Save neelabalan/4d4471c3eb8268ecc35bee53f2c376af to your computer and use it in GitHub Desktop.
youtube -> markdown
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
youtube-dl --skip-download --write-info-json <> |
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 json | |
from os import listdir | |
from pytablewriter import MarkdownTableWriter | |
# directory to find the JSON file from youtube-dl output | |
place_to_find = '<dir>' | |
def run(): | |
files = listdir(place_to_find) | |
value_matrix = list() | |
for file in files: | |
print(file) | |
doc = json.load(open(place_to_find + file, 'r')) | |
value_matrix.append([ | |
'[{}]({})'.format(doc['title'], doc['webpage_url']), | |
doc['description'], | |
int(doc['upload_date']) | |
]) | |
# sort based on date (ascending) | |
value_matrix.sort(key=lambda x: x[2]) | |
writer = MarkdownTableWriter( | |
table_name = 'youtube channel videos', | |
headers= ['title', 'description', 'upload_date'], | |
value_matrix = value_matrix | |
) | |
writer.dump('table.md') | |
if __name__ == '__main__': | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment