From 439d7d3a50f82b5b340ed5408324b3279ab5e744 Mon Sep 17 00:00:00 2001 From: Hansly Saw <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sat, 30 Apr 2022 18:54:49 +0800 Subject: [PATCH] Added the auto-play feature. --- Kpop'minal.ipynb | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Kpop'minal.ipynb b/Kpop'minal.ipynb index 4f6cc2e..0670829 100644 --- a/Kpop'minal.ipynb +++ b/Kpop'minal.ipynb @@ -16,7 +16,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "cellView": "form", "id": "NKYqnAEwCPYG" }, "outputs": [], @@ -25,7 +24,6 @@ "# 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", @@ -38,6 +36,7 @@ "class configs: \n", " #@markdown ## Configuration\n", " method = \"ascii-color\" #@param [\"filled-ascii\", \"ascii-color\", \"just-ascii\"]\n", + " action = \"download\" #@param [\"run\", \"download\"]\n", "\n", "# Set screen formatting. \n", "class formatting:\n", @@ -64,6 +63,12 @@ " def success(message):\n", " print(formatting.font.bold + formatting.color.green + 'Success: \\t' + formatting.clear + formatting.clear + message)\n", "\n", + "try: \n", + " from google.colab import files; from google.colab import output\n", + "except: \n", + " info.err(formatting.font.bold + 'You are not using this in Google CoLab. ' + formatting.clear + 'For this to work, please do so. ')\n", + " os.kill(os.getpid(), 1)\n", + "\n", "# Install apt programs and python modules. \n", "def get_dependencies(): \n", " import subprocess\n", @@ -129,7 +134,7 @@ " 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", + " 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, it was not possibly included. Check out the GitHub discussions for that.')\n", " os.kill(os.getpid(), 1)\n", " \n", " def start_download():\n", @@ -164,9 +169,13 @@ " 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", + " if configs.action == \"download\":\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", + " else:\n", + " info.status('Processing the video. After some while, the video will play.')\n", + " !video-to-ascii -f video.mp4 --strategy {configs.method}\n", + "\n", " def check_success():\n", " if check_file_exists():\n", " output.clear()\n", @@ -178,7 +187,8 @@ "\n", " attemptReplace()\n", " process()\n", - " check_success()\n", + " if configs.action == \"download\":\n", + " check_success()\n", "\n", "def download_results():\n", " info.status('Downloading the output…')\n", @@ -193,7 +203,8 @@ " get_dependencies()\n", " download_video()\n", " render()\n", - " download_results()\n", + " if configs.action == \"download\":\n", + " download_results()\n", "\n", "main()" ] @@ -202,9 +213,7 @@ "metadata": { "accelerator": "GPU", "colab": { - "authorship_tag": "ABX9TyOKzpUDluOXYqmRr/JITg5H", "collapsed_sections": [], - "include_colab_link": true, "name": "Kpop'minal.ipynb", "private_outputs": true, "provenance": [] @@ -219,4 +228,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file