Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@oxguy3
Last active March 8, 2017 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oxguy3/61b8900f183545490284183349f3c842 to your computer and use it in GitHub Desktop.
Save oxguy3/61b8900f183545490284183349f3c842 to your computer and use it in GitHub Desktop.
Commands for downloading and managing TV/movies/etc

youtube-dl

Crunchyroll

youtube-dl --netrc -f best --write-sub --sub-lang enUS --write-thumbnail -o '%(series)s - s01e%(episode_number)s - %(episode)s.%(ext)s' http://www.crunchyroll.com/relife
mmv "*s01e? -*" "#1s01e0#2 -#3"
mmv "*.enUS.ass" "#1.en.ass"

alt version since crunchyroll login is broken rn:

youtube-dl --cookies ~/crunchyroll-cookies.txt -f best --write-sub --sub-lang enUS --write-thumbnail -o '%(series)s - s01e%(episode_number)s - %(episode)s.%(ext)s' http://www.crunchyroll.com/relife
mmv "*s01e? -*" "#1s01e0#2 -#3"
mmv "*.enUS.ass" "#1.en.ass"

Crackle, CWTV, etc

For services that provide show name, season number, episode number, and episode title

youtube-dl -f best -o '%(series)s - s%(season_number)se%(episode_number)s - %(title)s.%(ext)s' -a urls.txt
mmv "* - s?e? - *" "#1 - s0#2e0#3 - #4"
mmv "* - s??e? - *" "#1 - s#2#3e0#4 - #5"
mmv "* - s?e?? - *" "#1 - s0#2e#3#4 - #5"

TruTV

youtube-dl -f best -o '%(title)s.%(ext)s' --ap-mso Comcast_SSO --netrc -a urls.txt

Viewster, etc

For services that provide nothing but the episode title

youtube-dl -f best -o 'SHOWTITLE - s01e%(autonumber)s - %(title)s.%(ext)s' -a urls.txt
mmv "* - s01e000*" "#1 - s01e#2"

YouTube

For download the best possible quality from YouTube

youtube-dl -f bestvideo+bestaudio --merge-output-format mkv --cookies ~/youtube-cookies.txt

Comedy Central full episodes download script (ccdl.sh)

To be able to download locked videos, you need to sign in to cc.com with your TV provider, then export your cookies.txt file and save it at ~/.ccdl-cookies.

#!/bin/bash
# example usage: ccdl http://www.cc.com/full-episodes/31m324/the-daily-show-with-trevor-noah-december-6--2016---john-legend-season-22-ep-22033 "The Daily Show December 6 2016"

# get arguments
url=$1
name="${@:2}"

# create and enter temp directory
mkdir "$name"
cd "$name"

# download the video, which will come in parts
youtube-dl --cookies ~/.ccdl-cookies -f best $url

# use ffmpeg to combine the parts into one file
for f in ./*.mp4; do
       	#escapedf=`echo $f | sed "s/'/\\\'/g"`
       	echo "file '$f'" >> parts.txt
done
ffmpeg -f concat -i parts.txt -c copy "../$name.mp4"

# exit and delete the temp directory
cd ..
rm -rf "$name"

The Daily Show (cc.com) easy download script

(this is just a variant of the ccdl script specifically for The Daily Show)

#!/bin/bash
# example usage: ./ezdl.sh 2016-12-06 http://www.cc.com/full-episodes/31m324/the-daily-show-with-trevor-noah-december-6--2016---john-legend-season-22-ep-22033

# get arguments
date=$1
url="${@:2}"

# create and enter temp directory
mkdir ccdl
cd ccdl

# download the video, which will come in parts
youtube-dl -f best $url

# use ffmpeg to combine the parts into one file
for f in ./*.mp4; do echo "file '$f'" >> mylist.txt; done
ffmpeg -f concat -i mylist.txt -c copy "../The Daily Show - $date.mp4"

# exit and delete the temp directory
cd ..
rm -rf ccdl

ffmpeg

LINKS: docs listffmpeg man pagewiki

Simple: encode to MP4 at superb quality

This is my base command for encoding Blu-rays for storage (because Blu-ray rips are insanely large).

ffmpeg -i 00000.m2ts -c:v libx264 -crf 21 -preset fast -c:a aac -b:a 320k -c:s copy -map 0 out.mp4

Let's break down what this command is doing:

  • -i 00000.m2ts is just the name of the input file
  • -c:v libx264 means encode the video using h.264 (which is like the most common/standard video encoding, used particularly with mp4 files)
  • -crf 21 is the quality factor. We are encoding at a variable bitrate for a constant quality (meaning video quality will be the same throughout the video, but the filesize might vary wildly) You can use any value from 0 (lossless) to 51 (absolute shit), but realistically you shouldn't deviate far from the default (23). For a slightly smaller file, increase to 22 or 23 (wouldn't go higher than like 26 maybe? or it'll look like crap). If you're seeing quality issues at 21, you can decrease it a bit (I highly doubt you'll see any defects at 21 though. definitely don't go any lower than 18, which should be virtually perfect).
  • -preset fast defines how quickly the file will be encoded. The slower you encode, the smaller the filesize, but I don't have the patience for much slower than "fast". Valid options: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo (don't use placebo).
  • -c:a aac means we're encoding the audio with AAC (a very common audio format).
  • -b:a 320k means we're encoding the audio at a 320kbps bitrate, which is very high quality. If you're not a complete audiophile, you might drop this down to like 192k for a smaller file, and you probably won't notice the difference (I wouldn't drop any lower than like 128k though).
  • -c:s copy means we're copying the subtitles over without re-encoding them or anything.
  • -map 0 means that we're mapping all input streams to the first output stream. Ffmpeg can do fancy stuff with multiple input/output files, but we just want everything from the input file to go to the output file, so we do -map 0.
  • out.mp4 is the output file name. We're using a .mp4 file since MP4 supports h.264+AAC no problem. If you're using other audio/video formats, you might need a different output type (when in doubt, use .mkv -- Matroska can hold just about anything). Click here for more info about which audio formats can go in which file types.

Further reference: H.264 Encoding Guide

Convert 16:9 to 4:3

ffmpeg -i in.mp4 -filter:v "crop=3/4*in_w:in_h" -c:a copy out.mp4

misc crap

ffmpeg -i 00004.m2ts -c:v libx264 -crf 21 -preset fast -metadata:s:a:0 language=jpn -metadata:s:a:1 language=eng -metadata:s:s:0 language=eng -metadata:s:s:1 language=spa -c:a aac -b:a 320k -c:s copy -map 0 cowboybebopmovie.mkv

ffmpeg -i 00000.m2ts -c:v libx264 -crf 21 -preset fast -metadata:s:a:0 language=eng -metadata:s:a:1 language=jpn -metadata:s:s:0 language=eng -c:a:0 copy -c:a:1 aac -b:a:1 320k -c:s copy -map 0 -map -0:s:1 ghostintheshell.mkv

ffmpeg -i 00014.m2ts -c:v libx264 -crf 21 -preset fast -metadata:s:a:0 language=eng -metadata:s:a:1 language=eng -metadata:s:a:2 language=jpn -metadata:s:a:3 language=jpn -metadata:s:a:4 language=eng -metadata:s:a:5 language=eng -metadata:s:s:0 language=eng -metadata:s:s:1 language=eng -disposition:a:0 dub -disposition:a:1 dub -disposition:a:2 original -disposition:a:3 original -disposition:a:4 comment -disposition:a:5 comment -disposition:s:0 original -disposition:s:1 dub -metadata:s:a:4 title="Commentary" -metadata:s:a:5 title="Commentary" -c:a copy -c:s copy -map 0 "The Devil Is a Part-Timer - s01e01 - The Devil Arrives in Sasazuka.mkv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment