222 lines
12 KiB
Text
222 lines
12 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "TK6pOEjtZCFB"
|
|
},
|
|
"source": [
|
|
"# Kpop'minal\n",
|
|
"Watch k-pop music videos in an ASCII format. \n",
|
|
"\n",
|
|
"_Uses [`video-to-ascii` by joelibaceta](https://github.com/joelibaceta/video-to-ascii)_. "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"cellView": "form",
|
|
"id": "NKYqnAEwCPYG"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# KPOP'MINAL\n",
|
|
"# Watch k-pop music videos in an ASCII format. \n",
|
|
"\n",
|
|
"import os; import subprocess\n",
|
|
"from google.colab import files; from google.colab import output\n",
|
|
"from IPython.display import Audio\n",
|
|
"\n",
|
|
"# selections\n",
|
|
"class selection: \n",
|
|
" artist = \"Twice\" #@param [\"Twice\"]\n",
|
|
" video = \"MORE & MORE\" #@param {type:\"string\"}\n",
|
|
" video = (video.strip()).lower()\n",
|
|
" videoURL = ''\n",
|
|
"\n",
|
|
"class configs: \n",
|
|
" #@markdown ## Configuration\n",
|
|
" method = \"ascii-color\" #@param [\"filled-ascii\", \"ascii-color\", \"just-ascii\"]\n",
|
|
"\n",
|
|
"# Set screen formatting. \n",
|
|
"class formatting:\n",
|
|
" clear = '\\033[0m'\n",
|
|
" class color: \n",
|
|
" purple = '\\033[95m'\n",
|
|
" cyan = '\\033[96m'\n",
|
|
" cyan_dark = '\\033[36m'\n",
|
|
" blue = '\\033[94m'\n",
|
|
" green = '\\033[92m'\n",
|
|
" yellow = '\\033[93m'\n",
|
|
" red = '\\033[91m'\n",
|
|
" class font:\n",
|
|
" bold = '\\033[1m'\n",
|
|
" underline = '\\033[4m'\n",
|
|
"\n",
|
|
"class info: # screen messages\n",
|
|
" def status(message):\n",
|
|
" print(formatting.font.bold + 'Status: \\t' + formatting.clear + message)\n",
|
|
" def err(message):\n",
|
|
" print(formatting.font.bold + formatting.color.red + 'Error: \\t\\t' + formatting.clear + formatting.clear + message)\n",
|
|
" def warning(message):\n",
|
|
" print(formatting.font.bold + formatting.color.yellow + 'Warning: \\t' + formatting.clear + formatting.clear + message)\n",
|
|
" def success(message):\n",
|
|
" print(formatting.font.bold + formatting.color.green + 'Success: \\t' + formatting.clear + formatting.clear + message)\n",
|
|
"\n",
|
|
"# Install apt programs and python modules. \n",
|
|
"def get_dependencies(): \n",
|
|
" import subprocess\n",
|
|
"\n",
|
|
" def install_dependencies_apt(): \n",
|
|
" return os.system('apt update && apt install -y ffmpeg libasound-dev portaudio19-dev libportaudiocpp0 libportaudio2 python-pyaudio python3-pyaudio && apt clean && apt autoremove -y')\n",
|
|
"\n",
|
|
" def install_dependencies_pip():\n",
|
|
" return os.system('pip install \"video-to-ascii==1.2.8\" && pip install pyaudio')\n",
|
|
"\n",
|
|
" def install_dependencies_other(): \n",
|
|
" return os.system('cd /tmp && git clone https://people.csail.mit.edu/hubert/git/pyaudio.git && cd pyaudio && ipython setup.py install') # install pyaudio\n",
|
|
"\n",
|
|
" info.status('Setting up the environment…')\n",
|
|
"\n",
|
|
" install_dependencies_apt()\n",
|
|
" install_dependencies_pip()\n",
|
|
" install_dependencies_other()\n",
|
|
"\n",
|
|
" info.success('The environment has been set up. ')\n",
|
|
" output.clear()\n",
|
|
"\n",
|
|
"def download_video(): \n",
|
|
" musicvideos = {\n",
|
|
" # Download links for the music videos. Good thing it's available in archive.org. \n",
|
|
" # should all be in lower case\n",
|
|
" \"Twice\": {\n",
|
|
" # Download links available here: https://archive.org/details/twuniverse\n",
|
|
" \"like ooh-ahh\": \"https://ia804501.us.archive.org/7/items/twuniverse/Like%20Oohahhoohahh.ia.mp4\",\n",
|
|
" \"cheer up\": \"https://ia904501.us.archive.org/7/items/twuniverse/Cheer%20Up%20.ia.mp4\",\n",
|
|
" \"tt\": \"https://ia804501.us.archive.org/7/items/twuniverse/Tt%20.ia.mp4\",\n",
|
|
" \"knock knock\": \"https://ia904501.us.archive.org/7/items/twuniverse/Knock%20Knock%20.ia.mp4\",\n",
|
|
" \"signal\": \"https://ia804501.us.archive.org/7/items/twuniverse/Signal%20.ia.mp4\",\n",
|
|
" \"one more time\": \"https://ia804501.us.archive.org/7/items/twuniverse/One%20More%20Time.ia.mp4\",\n",
|
|
" \"likey\": \"https://ia904501.us.archive.org/7/items/twuniverse/Likey%20.ia.mp4\",\n",
|
|
" \"merry & happy\": \"https://ia904501.us.archive.org/7/items/twuniverse/Merry%20%20Happy%20.ia.mp4\",\n",
|
|
" \"candy pop\": \"https://ia804501.us.archive.org/7/items/twuniverse/Candy%20Pop.ia.mp4\",\n",
|
|
" \"what is love?\": \"https://ia804501.us.archive.org/7/items/twuniverse/What%20Is%20Love%20.ia.mp4\",\n",
|
|
" \"wake me up\": \"https://ia804501.us.archive.org/7/items/twuniverse/Wake%20Me%20Up.ia.mp4\",\n",
|
|
" \"i want you back\": \"https://ia804501.us.archive.org/7/items/twuniverse/I%20Want%20You%20Back.ia.mp4\",\n",
|
|
" \"dance the night away\": \"https://ia904501.us.archive.org/7/items/twuniverse/Dance%20The%20Night%20Away%20.ia.mp4\",\n",
|
|
" \"bdz\": \"https://ia904501.us.archive.org/7/items/twuniverse/Bdz.ia.mp4\",\n",
|
|
" \"yes or yes\": \"https://ia804501.us.archive.org/7/items/twuniverse/Yes%20Or%20Yes%20.ia.mp4\",\n",
|
|
" \"the best thing i ever did\": \"https://ia804501.us.archive.org/7/items/twuniverse/The%20Best%20Thing%20I%20Ever%20Did.ia.mp4\",\n",
|
|
" \"fancy\": \"https://ia904501.us.archive.org/7/items/twuniverse/Fancy%20.ia.mp4\",\n",
|
|
" \"breakthrough\": \"https://ia804501.us.archive.org/7/items/twuniverse/Breakthrough.ia.mp4\",\n",
|
|
" \"happy happy\": \"https://ia904501.us.archive.org/7/items/twuniverse/Happy%20Happy.ia.mp4\",\n",
|
|
" \"feel special\": \"https://ia904501.us.archive.org/7/items/twuniverse/Feel%20Special%20.ia.mp4\",\n",
|
|
" \"fake & true\": \"https://ia804501.us.archive.org/7/items/twuniverse/Fake%20%20True%20.ia.mp4\",\n",
|
|
" \"more & more\": \"https://ia804501.us.archive.org/7/items/twuniverse/More%20%20More%20.ia.mp4\",\n",
|
|
" \"fanfare\": \"https://ia904501.us.archive.org/7/items/twuniverse/Fanfare.ia.mp4\",\n",
|
|
" \"i can't stop me\": \"https://ia804501.us.archive.org/7/items/twuniverse/I%20Cant%20Stop%20Me%20.ia.mp4\",\n",
|
|
" \"better\": \"https://ia804501.us.archive.org/7/items/twuniverse/Better%20.ia.mp4\",\n",
|
|
" \"kura kura\": \"https://ia804501.us.archive.org/7/items/twuniverse/Kura%20Kura%20.ia.mp4\",\n",
|
|
" \"alcohol-free\": \"https://ia804501.us.archive.org/7/items/twuniverse/Alcoholfree%20.ia.mp4\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
"\n",
|
|
" def check_valid_input():\n",
|
|
" try:\n",
|
|
" # It should raise an exception if the person did not type the correct music video name. \n",
|
|
" if musicvideos[selection.artist][selection.video]: \n",
|
|
" selection.videoURL = musicvideos[selection.artist][selection.video]\n",
|
|
" \n",
|
|
" except:\n",
|
|
" info.err(formatting.font.bold + 'The video that you are looking for does not exist. ' + formatting.clear + 'Make sure you have typed it properly. If you did, you can safely assume that this script is not updated. ')\n",
|
|
" os.kill(os.getpid(), 1)\n",
|
|
" \n",
|
|
" def start_download():\n",
|
|
" def check_exists(which=\"new\"):\n",
|
|
" if which == \"old\": return os.system(\"cat video.old.mp4\") == 0\n",
|
|
" else: return os.system(\"cat video.mp4\") == 0\n",
|
|
"\n",
|
|
" # Start downloading the video. \n",
|
|
" \n",
|
|
" os.system('rm -rf sample_data -v')\n",
|
|
" if check_exists(): os.system('rm -rf video.old.mp4 -v && mv video.mp4 video.old.mp4 -v')\n",
|
|
"\n",
|
|
" info.status('Downloading the music video…')\n",
|
|
"\n",
|
|
" if os.system('curl ' + selection.videoURL + ' -o video.mp4') > 0:\n",
|
|
" info.err(formatting.font.bold + 'The download has failed, ' + formatting.clear + 'please re-run this script again. Kindly check the log for more details.'); os.system('rm -rf video.mp4 -v')\n",
|
|
" if check_exists(\"old\"): os.system('mv video.old.mp4 video.mp4 -v')\n",
|
|
" os.kill(os.getpid(), 1)\n",
|
|
" else:\n",
|
|
" info.success('The video was successfully downloaded.')\n",
|
|
" \n",
|
|
" check_valid_input()\n",
|
|
" start_download()\n",
|
|
"\n",
|
|
"\n",
|
|
"def render(): \n",
|
|
" def check_file_exists(which=\"new\"):\n",
|
|
" if which == \"old\": return (os.system('cat output.old.sh') == 0)\n",
|
|
" else: return (os.system('cat output.sh') == 0)\n",
|
|
"\n",
|
|
" def attemptReplace():\n",
|
|
" if check_file_exists(): os.system('rm -rf output.old.sh && mv output.sh output.old.sh -v')\n",
|
|
"\n",
|
|
" def process():\n",
|
|
" info.status('Processing the video. This will take some while.')\n",
|
|
" !video-to-ascii -f video.mp4 -o output.sh --strategy {configs.method}\n",
|
|
" \n",
|
|
" def check_success():\n",
|
|
" if check_file_exists():\n",
|
|
" output.clear()\n",
|
|
" info.success('The music video has been successfully processed. ')\n",
|
|
" else:\n",
|
|
" if check_file_exists(\"old\"): os.system('mv output.old.sh output.sh -v')\n",
|
|
" info.err('Unfortunately, an error may have ocurred during processing. Kindly check the log for full details.')\n",
|
|
" os.kill(os.getpid(), 1)\n",
|
|
"\n",
|
|
" attemptReplace()\n",
|
|
" process()\n",
|
|
" check_success()\n",
|
|
"\n",
|
|
"def download_results():\n",
|
|
" info.status('Downloading the output…')\n",
|
|
" try:\n",
|
|
" files.download('output.sh')\n",
|
|
" except:\n",
|
|
" info.err('The file could not be downloaded, but it is available for manual downloading at the files view in the sidebar.')\n",
|
|
" else:\n",
|
|
" info.success('The file was succesfully downloaded.')\n",
|
|
"\n",
|
|
"def main():\n",
|
|
" get_dependencies()\n",
|
|
" download_video()\n",
|
|
" render()\n",
|
|
" download_results()\n",
|
|
"\n",
|
|
"main()"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"accelerator": "GPU",
|
|
"colab": {
|
|
"authorship_tag": "ABX9TyOKzpUDluOXYqmRr/JITg5H",
|
|
"collapsed_sections": [],
|
|
"include_colab_link": true,
|
|
"name": "Kpop'minal.ipynb",
|
|
"private_outputs": true,
|
|
"provenance": []
|
|
},
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"name": "python"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0
|
|
}
|