tvguide-refresh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. # Copyright © 2013 Alex Kost
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. #### HELP MESSAGE ##############################################
  14. hlp='Usage: tvguide-refresh
  15. Download TV guide and put it into a right place.'
  16. if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  17. echo "$hlp"
  18. exit 0
  19. fi
  20. ################################################################
  21. guide_url='http://www.teleguide.info/download/new3/xmltv.xml.gz'
  22. backup_dir="$HOME/.tvtime/tvguide"
  23. guide_full="${backup_dir}/current_full.xml"
  24. guide_short="${backup_dir}/current_short.xml"
  25. # Day of Monday of the current week.
  26. date_part=$(date --date="$([ 1 -ne $(date +%u) ] && echo last) Monday" '+%Y-%m-%d')
  27. guide_name="xmltv_${date_part}.xml.gz"
  28. guide_path="${backup_dir}/${guide_name}"
  29. if [ -f "$guide_path" ]; then
  30. echo "File '$guide_path' exists. Update has not been made."
  31. exit 0
  32. fi
  33. wget -O "$guide_path" "$guide_url"
  34. gunzip --stdout "$guide_path" > "$guide_full"
  35. tvguide.py "$guide_full" "$guide_short"