Skip to content

Instantly share code, notes, and snippets.

@neelabalan
Created July 23, 2021 05:37
Show Gist options
  • Save neelabalan/4d4471c3eb8268ecc35bee53f2c376af to your computer and use it in GitHub Desktop.
Save neelabalan/4d4471c3eb8268ecc35bee53f2c376af to your computer and use it in GitHub Desktop.
youtube -> markdown
youtube-dl --skip-download --write-info-json <>
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