Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #encoding=utf-8
  2. import requests
  3. import json
  4. import wget
  5. import os
  6. import time
  7.  
  8.  
  9. def borra():
  10. #borra block anterior flac
  11.  
  12. dir = "/home/volumio/flac_in/"
  13. lista_ficheros = os.listdir(dir)
  14.  
  15. for fichero in lista_ficheros:
  16. if fichero.endswith(".flac"):
  17. os.remove(dir + fichero)
  18.  
  19.  
  20. def RP():
  21. #Principal
  22.  
  23. r = requests.get("https://api.radioparadise.com/api/get_block?bitrate=4&info=true&chan=1")
  24.  
  25.  
  26. #lee url
  27. data = json.loads(r.text)["url"]
  28.  
  29. #lee lenght
  30. time_t =json.loads(r.text)["length"]
  31. time_t_seg = int(float(time_t))
  32.  
  33.  
  34. print (" ")
  35. print (" ")
  36. print (">Descargando block flac...")
  37.  
  38. borra()
  39.  
  40. out_dir = "/home/volumio/flac_in/"
  41.  
  42.  
  43. #block = wget.download(data, out=out_dir)
  44.  
  45. block = wget.download(data,out_dir)
  46.  
  47.  
  48. os.system ("mpc clear")
  49. os.system ("mpc add /home/volumio/flac_in/*.flac")
  50. os.system ("mpc play")
  51.  
  52.  
  53. print ">Reproduciendo block ", "Duración: ", time_t_seg, "seg."
  54.  
  55. for t in range(0,time_t_seg):
  56. time.sleep(1)
  57. t=t+1
  58.  
  59. #print ("sleep:",t)
  60.  
  61. borra()
  62. os.system ("mpc clear")
  63. #Termina RP()
  64.  
  65.  
  66. for n in range(1,100):
  67.  
  68. print (" ")
  69. print ("*****RADIOPARADISE MELLOW FLAC*****")
  70. print (" ")
  71. print ("<<<<<NO CIERRE ESTA PANTALLA>>>>>")
  72.  
  73. RP()
  74. n = n + 1
  75.  
  76.  
  77. #print (">>> SE CUMPLIERON" ,n, "LOOPS <<<")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement