def Downloaderffmpeg( self, audio_stream: Stream, video_stream: Stream, target: str )-> str: video_unique_name = fileUnique( helpers.safe_filename(video_stream.title), video_stream.subtype, "video", target=target, ) audio_unique_name = fileUnique( helpers.safe_filename(video_stream.title), audio_stream.subtype, "audio", target=target, ) clidownload(stream=video_stream, target=target, filename=video_unique_name) clidownload(stream=audio_stream, target=target, filename=audio_unique_name) video_path = os.path.join( target, f"{video_unique_name}.{video_stream.subtype}" ) audio_path = os.path.join( target, f"{audio_unique_name}.{audio_stream.subtype}" ) final_path = os.path.join( # target, f"{helpers.safe_filename(video_stream.title)}.{video_stream.subtype}" target, f"{helpers.safe_filename(video_stream.title)}.mp4" ) try: subprocess.run( [ "ffmpeg", "-i", video_path, "-i", audio_path, "-codec", "copy", final_path, "-loglevel", "quiet" ] ) except: print("Ada kesalahan saat menggabungkan video") sleep(0.5) print("Tapi tenang, file video dan audio masih ada") finally: print(s("%s" % prGreen("Success"))) print(s("File disimpan di %s" % prGreen(final_path))) os.unlink(video_path) os.unlink(audio_path) return final_path return None
def gantiPath(self): try: pilih = (input(s("Apakah ingin menggantinya ? opsi (y/t) "))) if pilih == 'y' or pilih == 'Y': self.simpanPath() except Exception as Pesan: print(s("Error: %s" % (prRed(Pesan)))) self.gantiPath()
def run(self): # print(s("Running..") self.cek() if (self._isValidPath): print(s("Lokasi penyimpanan ditemukan di: ")) print(s("%s" % (prGreen(self._path)))) print("") self.gantiPath() else: self.simpanPath()
def simpanPath(self): pilih = (input("Masukkan folder tempat menaruh hasil download : ")) if not os.path.isdir(pilih): raise Exception("{0} Bukanlah sebuah folder".format(pilih)) config = configparser.ConfigParser() config.read(self._lokasiconfig) config.set('DEFAULT', 'path', pilih) with open(self._lokasiconfig, 'w') as configfile: config.write(configfile) print(s("Default Lokasi download sudah diganti ke ")) print(s(prGreen(pilih)))
def run(self): """ Fungsi awal saat program dijalankan """ if (self._isDebug): print(s("Mode Debug Active")) if self._link is None: self.tanyaLink() cls() B = Banner() B.cetakbanner() cetakgaris("Pilih Resolusi Video") self._YT = YouTube(self._link) self._YT.check_availability self.infoVideo() print("") time.sleep(3) pilihan = self.resolusi() cek = Logs() if (not cek.cek()): print(s("%s" % prRed("Lokasi penyimpanan belum diset "))) cek.gantiPath() self._savePath = cek._path cls() B.cetakbanner() cetakgaris("Please Wait.. Downloading") try: if pilihan == 'video': super(DownloadYT, self).Downloaderffmpeg(self._Audio, self._Video, self._savePath) elif (pilihan == 'audio'): super(DownloadYT, self).DownloadMP3(self._Audio, self._savePath) else: raise ValueError("Error") except: print(s("Terjadi kesalahan!")) return sys.exit(prCyan("Terima kasih! ;) "))
def cek(self) -> bool: config = configparser.ConfigParser() try: if not os.path.exists(self._lokasiconfig): raise Exception("Config.ini tidak ditemukan") config.read(self._lokasiconfig) self._config = config['DEFAULT'] if not (config['DEFAULT']['path']): raise Exception("Default Path Config tidak ditemukan") if not os.path.isdir(config['DEFAULT']['path']): raise Exception("Lokasi penyimpanan belum ditentukan ") return False self._path = config['DEFAULT']['path'] self._isValidPath = True except Exception as Pesan: print(s("Error: %s" % (prRed(Pesan)))) self._isValidPath = False return False return True
def get_score(self, genres): entry = self.Raw_Genre_Database.get(s(genres)) if entry == None: return None else: if len(entry) < 3: entry += [0] * (3 - len(entry)) return round(sum(entry) / len(entry), 2)
def tanyaLink(self): """ Cek apakah link valid atau tidak """ try: if self._isDebug: self._link = 'https://www.youtube.com/watch?v=8uy7G2JXVSA' return tanya = input((s("Paste Link Youtube: "))) link = urlparse(tanya) if not link.scheme: raise ValueError("Link Tidak Valid") if not (link.netloc == 'www.youtube.com' or link.netloc == 'youtube.com' or link.netlock == 'm.youtube.com'): raise ValueError("Bukan Link Youtube") self._link = tanya except ValueError as pesan: print(s(pesan)) self.tanyaLink()
def get_super_score(self, genres): # If we have a super score for this genre group if s(genres) in self.Super_Scores.keys(): # print("found") return self.Super_Scores[s(genres)] # Get the score for this genre group raw_score = self.get_score(genres) if raw_score != None: Scores = [raw_score] * int(math.pow(2, len(genres) + 1)) else: Scores = [] # For every child, add on their super scores for child in self.get_children_genres(genres): # print('child') Scores += self.get_super_score(child) # save the super score self.Super_Scores[s(genres)] = Scores return Scores
def resolusi(self): yts = self._YT.streams yt_video = yts.filter(type='video') yt_audio = yts.get_audio_only() jumlahpilihan = len(yt_video) + 1 print(s("{0:3} {1:15} {2}".format('No', 'Resolusi', 'Size'))) print(garis()) for i, data in enumerate(yt_video, start=1): resolusi = data.resolution print( s("{0:3} {1:15} {2}".format( i, resolusi, ceksize(data.filesize + yt_audio.filesize)))) print( s("{0:3} {1:15} {2}".format( len(yt_video) + 1, "Audio MP3", ceksize(yt_audio.filesize)))) print(garis()) strpilih = (s( prYellow("Pilih Nomor 1 sampai {0} : ".format( str(jumlahpilihan))))) pilih = pilihAngka(strpilih) if ((pilih) > jumlahpilihan): print(s("Pilihan Tidak Valid")) self.resolusi() self._Audio = yt_audio if ((pilih) == jumlahpilihan): return "audio" self._Video = yt_video[pilih - 1] return "video"
def infoVideo(self): """Menampilkan Informasi Video""" print(s("{0:8}: {1}".format('Judul', prCyan(self._YT.title[0:30])))) print(s("{0:8}: {1}".format('Chanel', self._YT.author))) print("") print(s("{0:8}: {1}".format('Views', self._YT.views))) print(s("{0:8}: {1}".format('Rating', self._YT.rating))) print(s("{0:8}: {1}".format('Publish', self._YT.publish_date))) print(s("{0:8}: {1:.1f} Menit".format('Durasi', self._YT.length / 60)))
def get_display(self, genres): entry = self.Raw_Genre_Database.get(s(genres)) if entry == None: return False else: return len(entry) > self.COUNT * self.CUTOFF_PERCENT
def add(self, genres, rating, id, MAL_score): score = (((rating - self.average_difference) / MAL_score) - 1) * 100 self.COUNT += 1 for combo in helpers.get_Combinations(genres, lowest=1): self.Raw_Genre_Database[s(combo)] = self.Raw_Genre_Database.get( s(combo), []) + [score]