2 ms·
Example: Turning the YouTube JSON into a TSV table using UNIX utilities. The initial YouTube web search returns a JSON schema that differs from one that is ret
by 1vuio0pswjnm7 5y ago
Example: Turning the YouTube JSON into a TSV table using UNIX utilities.
The initial YouTube web search returns a JSON schema that differs from one that is returned from a continuation search.
2.sh 0 is for the first 15 results
2.sh 1 is for the rest of the results
#!/bin/sh
# 2.sh
# usage: 2.sh 0 < query.yts
# usage: 2.sh 1 < query.yts
x=$(echo x|tr x '\34');
tr -cd '[ -~\12]' \
|sed -n "
/\"text\": \"YouTube Home\"/d;
/canonicalBaseUrl/p;
s/\\\\.//g;
s/.*videoId/$x{ \"videoId/;/thumbnail/{/videoId/p;};
/\"text\"/p;
/simpleText/{/views/p;
}" \
|tr -d '\12'|tr '\34' '\12' \
|case $1 in :)
;;0)cut -d\" -f4,22,28,42,64,174
;;1)cut -d\" -f4,10,14,24,32,36
esac \
|tr '\42' '\11' \
|sed 's/snippetText$/0 seconds/;/primaryContents/d;/canonicalBaseUrl/d;/commandMetadata/d'
TODO: 2.sh does not handle entries for "YouTube Movies" correctly.