i'm trying sort output of youtube-dl -f  resolution , assign format code of highest res result variable download file using youtube-dl -f  . i'm able sort output of first step youtube-dl -f https://www.youtube.com/watch\?v\=yknxef4kmsy | sort -b -r -k3
with example, format code highest video res 43. how assign value variable , use further in script writing?
you can format code using command:
format_code=$(youtube-dl -f https://www.youtube.com/watch\?v\=yknxef4kmsy | sort -b -r -k3 -n | head -1 | cut -d" " -f1) this sort sort output based on 3rd field (resolution), take first line using head command , gets first field (format code) using cut
$ echo $format_code > 43 to desired output in python:
from subprocess import check_output  output = check_output("youtube-dl -f https://www.youtube.com/watch?v=yknxef4kmsy | sort -b -r -k3 -n | head -1 | cut -d' ' -f1", shell=true)  format_code = output.strip() # remove trailing '\n' # or format_code = int(output) if want integer and format_code variable have desired value 43 in case.
Comments
Post a Comment