{ "metadata": { "celltoolbar": "Slideshow", "name": "", "signature": "sha256:f680c951a63a707f21d5cfae680c94683fa9f2d9fe29b3e27e94f549bc1a242a" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Ich fange ja an ipython mehr und mehr zu lieben. Noch vor kurzer Zeit war mir garnicht bewusst wof\u00fcr ich es pers\u00f6hnlich einsetzen kann. Dann habe ich es einfach mal in [Pelican](http://blog.getpelican.com/) eingebunden. Und nun frage ich mich wie es vorher ohne ging. Dazu kommt die M\u00f6glichkeit aus einem Notebook auch eine Pr\u00e4sentation zu generieren. Bis jetzt hatte ich nie eine Art und Weise gefunden die mich inspiriert hat mich wirklich mit Pr\u00e4sentationen auseinander zu setzen. Nun alles mit Python, und ich bin an Board. Aber erstmal m\u00f6chte ich schauen wie man ein Video einbindet. ipython bindet das meiste in base64 codiert ein. Also muss man sich nicht mit statischen Files auseinandersetzen. W\u00e4re nat\u00fcrlich sch\u00f6n wenn das auch mit Video geht.\n", "\n", "Hier mal einer meiner ersten Spielerein mit den Notebooks:" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Erstmal schauen welche Formate downloadbar sind:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "!youtube-dl https://www.youtube.com/watch?v=a1Y73sPHKxw -F" ], "language": "python", "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[youtube] Confirming age\r\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "[youtube] a1Y73sPHKxw: Downloading webpage\r\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "[youtube] a1Y73sPHKxw: Downloading video info webpage\r\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "[youtube] a1Y73sPHKxw: Extracting video information\r\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "[youtube] a1Y73sPHKxw: Downloading DASH manifest\r\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "[info] Available formats for a1Y73sPHKxw:\r\n", "format code extension resolution note \r\n", "139 m4a audio only DASH audio 49k , audio@ 48k (22050Hz), 33.76KiB (worst)\r\n", "171 webm audio only DASH audio 71k , audio@128k (44100Hz), 48.10KiB\r\n", "140 m4a audio only DASH audio 97k , audio@128k (44100Hz), 65.90KiB\r\n", "172 webm audio only DASH audio 111k , audio@256k (44100Hz), 74.59KiB\r\n", "141 m4a audio only DASH audio 193k , audio@256k (44100Hz), 130.48KiB\r\n", "160 mp4 192x144 DASH video 111k , video only, 72.08KiB\r\n", "242 webm 320x240 DASH video 141k , video only, 90.97KiB\r\n", "133 mp4 320x240 DASH video 246k , video only, 159.20KiB\r\n", "243 webm 320x360 DASH video 229k , video only, 147.65KiB\r\n", "17 3gp 176x144 \r\n", "36 3gp 320x240 \r\n", "5 flv 400x240 \r\n", "43 webm 640x360 \r\n", "18 mp4 640x360 (best)\r\n" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Ich entscheide mich f\u00fcr die `webm`-Version. Und gebe das `youtube-dl` mit:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "!youtube-dl https://www.youtube.com/watch?v=a1Y73sPHKxw -f '43'" ], "language": "python", "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "[youtube] Confirming age\r\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "[youtube] a1Y73sPHKxw: Downloading webpage\r\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "[youtube] a1Y73sPHKxw: Downloading video info webpage\r\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "[youtube] a1Y73sPHKxw: Extracting video information\r\n", "[youtube] a1Y73sPHKxw: Downloading DASH manifest\r\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "[download] Destination: Dramatic Chipmunk-a1Y73sPHKxw.webm\r\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\r", "\u001b[K[download] 0.5% of 212.45KiB at 33.50KiB/s ETA 00:06\r", "\u001b[K[download] 1.4% of 212.45KiB at 50.67KiB/s ETA 00:04\r", "\u001b[K[download] 3.3% of 212.45KiB at 117.68KiB/s ETA 00:01\r", "\u001b[K[download] 7.1% of 212.45KiB at 250.71KiB/s ETA 00:00\r", "\u001b[K[download] 14.6% of 212.45KiB at 497.65KiB/s ETA 00:00" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\r", "\u001b[K[download] 29.7% of 212.45KiB at 767.40KiB/s ETA 00:00\r", "\u001b[K[download] 59.8% of 212.45KiB at 1.03MiB/s ETA 00:00" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\r", "\u001b[K[download] 100.0% of 212.45KiB at 1.32MiB/s ETA 00:00\r", "\u001b[K[download] 100% of 212.45KiB in 00:00\r\n" ] } ], "prompt_number": 2 }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Nun legen wir eine kleine Helper-Funktion an. Diese schnappt sich das Video und encoded es in base64 und baut ein HTML Object zusammen welches in ipython einbindbar ist." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.display import HTML\n", "from base64 import b64encode\n", "\n", "\n", "def video(fname, mimetype):\n", " video_encoded = open(fname, \"rb\").read().encode(\"base64\")\n", " video_tag = '