Advertisement
Rnery

Canais de TV no terminal..

Mar 24th, 2022 (edited)
1,290
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.88 KB | Source Code | 1 0
  1. #!/usr/bin/env bash
  2.  
  3. # Dependencies:
  4. # sudo apt install golang whiptail
  5. # export GOPATH=$HOME/go
  6. # export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
  7. # go get github.com/ericchiang/pup
  8.  
  9. install_whiptail() {
  10.   if [ -f /etc/apt/sources.list ]; then
  11.     sudo apt install whiptail
  12.   fi
  13. }
  14.  
  15. check_dependencies() {
  16.   if ! dpkg-query -W --showformat='${db:Status-Status}' whiptail 2>&1 | grep -q installed; then
  17.     whiptail --title "Dependência não instalada" --yesno "Uma dependência não está instalada.\nDeseja instalá-la?" 8 40
  18.     if [ $? -eq 0 ]; then
  19.       install_whiptail
  20.     else
  21.       exit 0
  22.     fi
  23.   fi
  24. }
  25.  
  26. get_channel() {
  27.   CANAL=$(whiptail --inputbox "Digite o canal com letras minúsculas:" --title "Qual o canal?" 8 40 3>&1 1>&2 2>&3)
  28.  
  29.   # Use a map to match channel names to URLs
  30.   channel_map=(
  31.     ["globo"]="https://meuguia.tv/programacao/canal/GRD"
  32.     ["band"]="https://meuguia.tv/programacao/canal/BAN"
  33.     ["mtv"]="https://meuguia.tv/programacao/canal/MTV"
  34.     ["record"]="https://meuguia.tv/programacao/canal/REC"
  35.     ["redetv"]="https://meuguia.tv/programacao/canal/RTV"
  36.     # ...
  37.   )
  38.  
  39.   # Get the corresponding URL for the provided channel name
  40.   if [[ -z "${channel_map[$CANAL]}" ]]; then
  41.     whiptail --title "Erro" --msgbox "Canal não cadastrado ou escrito com letras maiúsculas." 8 40
  42.     exit 0
  43.   fi
  44.   CANAL="${channel_map[$CANAL]}"
  45. }
  46.  
  47. set_txt() {
  48.   # Use curl and pup to extract data from the specified URL
  49.   curl -s "$CANAL" | pup '.lileft text{}' > horarios.txt
  50.   curl -s "$CANAL" | pup 'h2 text{}' > filmes.txt
  51.  
  52.   paste horarios.txt filmes.txt > horarios_filmes.txt
  53.  
  54.   # Clean up temporary files
  55.   rm -rf horarios.txt filmes.txt
  56.  
  57.   # Report success if the file was created
  58.   if [ -f horarios_filmes.txt ]; then
  59.     whiptail --title "Sucesso" --msgbox "Arquivo criado com sucesso." 8 40
  60.   fi
  61. }
  62.  
  63. check_dependencies
  64. get_channel
  65. set_txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement