now it download videos without youtube api using yt-dlp fixed #1

Esse commit está contido em:
Talha Asghar
2022-02-08 13:06:42 +05:00
commit c9c5f2745b
6 arquivos alterados com 90 adições e 79 exclusões
+1 -1
Ver Arquivo
@@ -1,3 +1,3 @@
# This file is used by clients to check for updates
version 1.1.2
version 1.1.3
+2 -2
Ver Arquivo
@@ -1,5 +1,5 @@
__version__ = "1.1.1"
__notes__ = "released on 06 Feb 2022"
__version__ = "1.1.3"
__notes__ = "released on 08 Feb 2022"
__author__ = "iamtalhaasghar"
__license__ = "GPLv3"
__url__ = "https://github.com/iamtalhaasghar/yewtube"
+74 -72
Ver Arquivo
@@ -8,7 +8,7 @@ import subprocess
from urllib.request import urlopen
from urllib.error import HTTPError
from .. import g, c, screen, streams, content, config, util
from .. import g, c, screen, streams, content, config, util, pafy
from . import command, PL
from .search import yt_url, user_pls
from .songlist import dump, plist
@@ -39,87 +39,89 @@ def download(dltype, num):
screen.writestatus("Fetching video info...")
song = (g.model[int(num) - 1])
best = dltype.startswith("dv") or dltype.startswith("da")
if not best:
try:
# user prompt for download stream
url, ext, url_au, ext_au = prompt_dl(song)
except KeyboardInterrupt:
g.message = c.r + "Download aborted!" + c.w
g.content = content.generate_songlist_display()
return
if not url or ext_au == "abort":
# abort on invalid stream selection
g.content = content.generate_songlist_display()
g.message = "%sNo download selected / invalid input%s" % (c.y, c.w)
return
else:
# download user selected stream(s)
filename = _make_fname(song, ext)
args = (song, filename, url)
if url_au and ext_au:
# downloading video and audio stream for muxing
audio = False
filename_au = _make_fname(song, ext_au)
args_au = (song, filename_au, url_au)
else:
audio = ext in ("m4a", "ogg")
kwargs = dict(audio=audio)
elif best:
# set updownload without prompt
url_au = None
av = "audio" if dltype.startswith("da") else "video"
audio = av == "audio"
filename = _make_fname(song, None, av=av)
args = (song, filename)
kwargs = dict(url=None, audio=audio)
# best = dltype.startswith("dv") or dltype.startswith("da")
#
# if not best:
#
# try:
# # user prompt for download stream
# url, ext, url_au, ext_au = prompt_dl(song)
#
# except KeyboardInterrupt:
# g.message = c.r + "Download aborted!" + c.w
# g.content = content.generate_songlist_display()
# return
#
# if not url or ext_au == "abort":
# # abort on invalid stream selection
# g.content = content.generate_songlist_display()
# g.message = "%sNo download selected / invalid input%s" % (c.y, c.w)
# return
#
# else:
# # download user selected stream(s)
# filename = _make_fname(song, ext)
# args = (song, filename, url)
#
# if url_au and ext_au:
# # downloading video and audio stream for muxing
# audio = False
# filename_au = _make_fname(song, ext_au)
# args_au = (song, filename_au, url_au)
#
# else:
# audio = ext in ("m4a", "ogg")
#
# kwargs = dict(audio=audio)
#
# elif best:
# # set updownload without prompt
# url_au = None
# av = "audio" if dltype.startswith("da") else "video"
# audio = av == "audio"
# filename = _make_fname(song, None, av=av)
# args = (song, filename)
# kwargs = dict(url=None, audio=audio)
try:
# perform download(s)
dl_filenames = [args[1]]
f = _download(*args, **kwargs)
if f:
g.message = "Saved to " + c.g + f + c.w
# dl_filenames = [args[1]]
# f = _download(*args, **kwargs)
success = pafy.download_video(song.ytid, config.DDIR.get)
if success:
g.message = "Saved \'" + song.title + "\' to " + c.g + config.DDIR.get + c.w
if url_au:
dl_filenames += [args_au[1]]
_download(*args_au, allow_transcode=False, **kwargs)
# if url_au:
# dl_filenames += [args_au[1]]
# _download(*args_au, allow_transcode=False, **kwargs)
except KeyboardInterrupt:
g.message = c.r + "Download halted!" + c.w
try:
for downloaded in dl_filenames:
os.remove(downloaded)
# try:
# for downloaded in dl_filenames:
# os.remove(downloaded)
#
# except IOError:
# pass
except IOError:
pass
if url_au:
# multiplex
name, ext = os.path.splitext(args[1])
tmpvideoname = name + '.' +str(random.randint(10000, 99999)) + ext
os.rename(args[1], tmpvideoname)
mux_cmd = [g.muxapp, "-i", tmpvideoname, "-i", args_au[1], "-c",
"copy", name + ".mp4"]
try:
subprocess.call(mux_cmd)
g.message = "Saved to :" + c.g + mux_cmd[7] + c.w
os.remove(tmpvideoname)
os.remove(args_au[1])
except KeyboardInterrupt:
g.message = "Audio/Video multiplex aborted!"
# if url_au:
# # multiplex
# name, ext = os.path.splitext(args[1])
# tmpvideoname = name + '.' +str(random.randint(10000, 99999)) + ext
# os.rename(args[1], tmpvideoname)
# mux_cmd = [g.muxapp, "-i", tmpvideoname, "-i", args_au[1], "-c",
# "copy", name + ".mp4"]
#
# try:
# subprocess.call(mux_cmd)
# g.message = "Saved to :" + c.g + mux_cmd[7] + c.w
# os.remove(tmpvideoname)
# os.remove(args_au[1])
#
# except KeyboardInterrupt:
# g.message = "Audio/Video multiplex aborted!"
g.content = content.generate_songlist_display()
+2 -2
Ver Arquivo
@@ -324,8 +324,8 @@ class _Config:
ConfigItem("columns", ""),
ConfigItem("ddir", paths.get_default_ddir(), check_fn=check_ddir),
ConfigItem("overwrite", True),
ConfigItem("show_video", False),
ConfigItem("search_music", True),
ConfigItem("show_video", True),
ConfigItem("search_music", False),
ConfigItem("window_pos", "", check_fn=check_win_pos,
require_known_player=True),
ConfigItem("window_size", "",
+10 -1
Ver Arquivo
@@ -1,5 +1,5 @@
from youtubesearchpython import VideosSearch, ChannelsSearch, PlaylistsSearch, Suggestions, Playlist
import yt_dlp, random
import yt_dlp, random, os
class MyLogger:
def debug(self, msg):
@@ -25,6 +25,15 @@ def get_video_streams(ytid):
info_dict = ydl.extract_info(ytid, download=False)
return [i for i in info_dict['formats'] if i.get('format_note') != 'storyboard']
def download_video(ytid, folder):
ytdl_format_options = {
'outtmpl': os.path.join(folder, '%(title)s-%(id)s.%(ext)s')
}
with yt_dlp.YoutubeDL(ytdl_format_options) as ydl:
ydl.download('https://www.youtube.com/watch?v=%s' % ytid)
return True
def video_search(query):
videosSearch = VideosSearch(query, limit=50)
wdata = videosSearch.result()['result']
+1 -1
Ver Arquivo
@@ -9,7 +9,7 @@ def get_default_ddir():
join, exists = os.path.join, os.path.exists
if mswin:
return join(user_home, "Downloads", "mps")
return join(user_home, "Downloads", "yewtube")
USER_DIRS = join(user_home, ".config", "user-dirs.dirs")
DOWNLOAD_HOME = join(user_home, "Downloads")