Skip to content

Commit

Permalink
Move to yt-dlp from youtube-dl since it's not maintained anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30 committed Jan 30, 2022
2 parents f74ce60 + 7e282fc commit 0eb0cb8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 3 additions & 2 deletions bin/ytmdl
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,10 @@ def extract_data():
args.SONG_NAME = []

# Iterate and work on the data.
url_base = "https://www.youtube.com/watch?v="
# NOTE: song["url"] will contain the URL all right, it won't be just

This comment has been minimized.

Copy link
@pukkandan

pukkandan Jan 30, 2022

What is returned here is a URL that yt-dlp/youtube-dl can understand - not necessarily the actual webpage URL. For youtube, what that means is that it can either be the full URL or just the id.

In yt-dlp, I try to return the actual URL whenever possible (it's always possible for youtube, but may not be for other sites). But internally, there is no real reason to do this. So to maintain compatibility with youtube-dl as well as any future changes, it is best to look for either possibility. Eg:

args.url = song["url"]
if '/' not in args.url:
    args.url = f"https://www.youtube.com/watch?v={args.url}"

This comment has been minimized.

Copy link
@deepjyoti30

deepjyoti30 Feb 2, 2022

Author Owner

@pukkandan Thanks for the heads up, I can put a check for this!

# the href.
for song in songs:
args.url = url_base + song["url"]
args.url = song["url"]
main(args)
else:
main(args)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
exec(open("ytmdl/__version__.py").read())

req_pkgs = [
'youtube_dl',
'yt-dlp',
'mutagen',
'itunespy',
'requests',
Expand Down
16 changes: 10 additions & 6 deletions ytmdl/yt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import requests
import os
from urllib.parse import urlparse, parse_qs
import youtube_dl
from youtube_dl.utils import DownloadError
import yt_dlp
from yt_dlp.utils import DownloadError
from re import match
from ytmdl import defaults, utility, stringutils
from downloader_cli.download import Download
Expand Down Expand Up @@ -88,6 +88,7 @@ def dw_using_yt(link, proxy, song_name, datatype, no_progress=False):

ydl_opts = {
'quiet': True,
'no_warnings': True,
'outtmpl': song_name,
'format': format_,
'nocheckcertificate': True,
Expand All @@ -102,7 +103,7 @@ def dw_using_yt(link, proxy, song_name, datatype, no_progress=False):
if proxy is not None:
ydl_opts['proxy'] = proxy

ydl = youtube_dl.YoutubeDL(ydl_opts)
ydl = yt_dlp.YoutubeDL(ydl_opts)

try:
ydl.download([link])
Expand Down Expand Up @@ -285,6 +286,7 @@ def get_playlist(
"""
ydl_opts = {
'quiet': True,
'no_warnings': True,
'format': 'bestaudio/best',
'nocheckcertificate': True,
'dump_single_json': True,
Expand All @@ -301,7 +303,7 @@ def get_playlist(
ydl_opts['playlist_items'] = playlist_items

# Extract the info now
songs = youtube_dl.YoutubeDL(ydl_opts).extract_info(url, False)
songs = yt_dlp.YoutubeDL(ydl_opts).extract_info(url, False)

# Put another check to see if the passed URL is a playlist
try:
Expand All @@ -327,13 +329,14 @@ def __get_title_from_yt(url):
"""
ydl_opts = {
"quiet": True,
'no_warnings': True,
'nocheckcertificate': True,
'source_address': '0.0.0.0'
}

logger.debug(url)

ydl = youtube_dl.YoutubeDL(ydl_opts)
ydl = yt_dlp.YoutubeDL(ydl_opts)

try:
data = ydl.extract_info(url, False)
Expand Down Expand Up @@ -387,11 +390,12 @@ def get_chapters(url):
"""
ydl_opts = {
"quiet": True,
'no_warnings': True,
'nocheckcertificate': True,
'source_address': '0.0.0.0'
}

info = youtube_dl.YoutubeDL(ydl_opts).extract_info(url, False)
info = yt_dlp.YoutubeDL(ydl_opts).extract_info(url, False)

return info.get("chapters", None)

Expand Down

0 comments on commit 0eb0cb8

Please sign in to comment.