getdata.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. # This shell script generates data.h, a C header file containing fixed data
  3. # for use in TubeMan. It includes an array of common user agent strings, and
  4. # the default configuration. Running this script requires curl, grep and sed.
  5. printf " Generating data.h... "
  6. url="https://techblog.willshouse.com/2012/01/03/most-common-user-agents/"
  7. list=$(curl -s "$url" | grep "Mozilla/" | sed -e "s/.*>//g" -e "/^$/d")
  8. html=$(curl -sA "$(echo $list | head -n1)" "https://www.youtube.com/")
  9. clientname=$(echo "$html" | grep -Eo "CLIENT_NAME\":[^,}]+[,}]" | \
  10. sed -e 's/CLIENT_.*\"://g' -e 's/,//g')
  11. clientver=$(echo "$html" | grep -Eo "CLIENT_VERSION\":\"[^\"]+\"" | \
  12. sed -e 's/CLIENT_.*\":\"//g' -e 's/\"//g')
  13. #shellcheck disable=SC2016
  14. prog=$(autoconf -t 'AC_INIT:$1')
  15. cat <<EOF > src/data.h
  16. /*
  17. Copyright $(date +%Y) Oliver Galvin <odg@riseup.net>
  18. This file is part of $prog.
  19. $prog is free software: you can redistribute it and/or modify
  20. it under the terms of the GNU General Public License as published by
  21. the Free Software Foundation, either version 3 of the License, or
  22. (at your option) any later version.
  23. $prog is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. GNU General Public License for more details.
  27. You should have received a copy of the GNU General Public License
  28. along with $prog. If not, see <http://www.gnu.org/licenses/>.
  29. This file was generated by $0 on $(date +%F).
  30. */
  31. #define MAXUANUM $(echo "$list" | wc -l)
  32. #define YTCLIENTNAME "${clientname}"
  33. #define YTCLIENTVER "${clientver}"
  34. const char *useragents[] = {
  35. $(echo "$list" | sed -e 's/^/\t\"/' -e 's/$/\",/')
  36. ""
  37. };
  38. const char *defaultconfig[] = {
  39. $(sed -e 's/^/\t\"/g' -e 's/$/\\n\",/g' docs/config)
  40. ""
  41. };
  42. EOF
  43. echo "done."