Stranck

Raiplay downloader

Nov 5th, 2020 (edited)
463
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None
  1. # www.stranck.ovh
  2.  
  3. import youtube_dl
  4. import requests
  5. from guizero import App, Text, TextBox, PushButton
  6. from threading import Thread
  7.  
  8. app = App(title="raiplay downloader", height=100)
  9. text = Text(app, text="Inserisci link del video su raiplay!")
  10. wpTBox = TextBox(app, width="fill")
  11. ready = True
  12.  
  13. class DwnThread (Thread):
  14.     def __init__(self, wpLink):
  15.         Thread.__init__(self)
  16.         self.wpLink = wpLink
  17.  
  18.     def run(self):
  19.         try:
  20.             wpLink = self.wpLink
  21.             print("Ottenendo link m3u8... ", end="")
  22.             text.value = "Ottenendo link m3u8..."
  23.  
  24.             jsonLink = wpLink.replace("html", "json")
  25.             json = requests.get(jsonLink).json()
  26.             m3u8Link = json["video"]["content_url"]
  27.  
  28.             print(m3u8Link, "Scaricando il video nella directory corrente", sep="\n")
  29.             text.value = "Scaricando il video nella directory corrente..."
  30.             options = {
  31.                 'format':   'best',
  32.                 'outtmpl':  remove_chars(json["episode_title"], "*.\"\\/[]:;|,<>?") + ".mp4"
  33.             }
  34.             with youtube_dl.YoutubeDL(options) as ydl:
  35.                 ydl.download([m3u8Link])
  36.             print("Scaricato!")
  37.             text.value = "Scaricato! Inserisci un altro link di raiplay"
  38.         except Exception as e:
  39.             print(e)
  40.             text.value = "Si è verificato un errore!"
  41.         wpTBox.value = ""
  42.         global ready
  43.         ready = True
  44.  
  45. def remove_chars(input_string, removable):
  46.     return ''.join([_ for _ in input_string if _ not in removable])
  47.  
  48. def download():
  49.     global ready
  50.     if(ready):
  51.         ready = False #nice race condition
  52.         dwn = DwnThread(wpTBox.value)
  53.         dwn.start()
  54.  
  55. PushButton(app, text="Scarica!", command=download)
  56. app.display()
  57.  
RAW Paste Data Copied