Skip to main content

Adding YouTube watch?v= links to auto-download

The linked chunk of Python does the job well... but leaves a .flv file with a crypto-looking name. This chunk of shell script ($1 is the full YouTube URL, as in http://www.youtube.com/watch?v=XYZZY123abc or whatever) hauls out the video title:

wget $1 -O /tmp/fetched_from_youtube.data
name=$(gawk '/<.title>/ { x=0; } x > 0 { if($1 == "-" && $2 != "") { sub ("^[^A-Z]*",""); sub("\\(.*\\).*$",""); gsub("[[:punct:]]",""); sub(" +$",""); gsub(" +","_"); print $0; } } // { x=2; }' /tmp/fetched_from_youtube.data)
rm -f /tmp/fetched_from_youtube.data


The title is savagely pruned to exclude most things which would fail as part of a filename. Experiments will happen tomorrow AM, but I’m guessing that something like this would do the appropriate conversion/renaming:

arg=$(echo $1 | sed -e 's/^.*v=//')
ffmpeg -i ${arg} -ab 56 -ar 22050 -b 500 -s 320x240 ${name}.mpg


That results in a plain MPEG file which should convert losslessly to a .vob for burning onto a standard video DVD. If you use .mp4 instead, you wind up with a smaller video file for playing using smplayer, xine or whatever you have to hand.

Comments

Bruce said…
Have you tried fetching videos with youtube-dl?
Leon RJ Brooks said…
Ta, Bruce.

Doing that now. It doesn’t rename or process the Flash video file, but the script above does that handily.

Popular posts from this blog

new life for an old (FTX) PSU, improved life for one human

the LEDs on this 5m strip happen to emit light centred on a red that does unexpectedly helpful things to (and surprisingly deeply within) a human routinely exposed to it. it has been soldered to a Molex connector, plugged into a TFX power supply from a (retired: the MoBo is cactus) Small Form Factor PC, the assorted PSU connectors (and loose end from the strip) have been taped over. the LED strip cost $10.24 including postage, the rest cost $0, the PSU is running at 12½% of capacity, consumes less power than a laptop plug-pack despite running a fan. trial runs begin today.

every-application-is-part-of-a-toolkit at work

I have a LibreOffice Impress slideshow that I wish to turn into a narrated video. 1. export the slideshow as PNG images (if that is partially broken — as at now — at higher resolutions, Export Directly as PDF then use ‘pdftoppm’ (from the poppler-utils package) to do the same). 2. write a small C program (63 lines including comments) to display those images one at a time, writing a config file entry for Imagination (default transition: ‘cross fade’) based on when the image-viewer application (‘display,’ from the GraphicsMagick suite) is closed on each one; run that, read each image aloud, then close each image in turn. 3. run ‘Imagination’ over the config file to produce a silent MP4 video with the correct timings. 4. run ‘Audacity’ to record speech while using ‘SMPlayer’ to display the silent video, then export that recording as a WAV file. 4a. optionally, use ‘TiMIDIty’ to convert a non-copyright-encumbered MIDI tune to WAV, then import that and blend it with the speech (as a quiet b...

boundaries

pushing the actual boundaries of the physical (not extremes, the boundaries themselves) can often remove barriers not otherwise perceived. one can then often resolve an issue itself, rather than merely stonewalling at the physical consequences of the issue.