switch to yt-dlp with required library updates, resolves #145

This commit is contained in:
meeb
2021-09-20 16:49:03 +10:00
parent ced6314a62
commit 837b6c3107
8 changed files with 24 additions and 22 deletions

View File

@@ -1,10 +1,10 @@
from django.conf import settings
from .third_party_versions import youtube_dl_version, ffmpeg_version
from .third_party_versions import yt_dlp_version, ffmpeg_version
def app_details(request):
return {
'app_version': str(settings.VERSION),
'youtube_dl_version': youtube_dl_version,
'yt_dlp_version': yt_dlp_version,
'ffmpeg_version': ffmpeg_version,
}

View File

@@ -57,7 +57,7 @@
</p>
<p>
<a href="https://github.com/meeb/tubesync" class="nowrap" target="_blank"><i class="fab fa-github"></i> TubeSync</a> version <strong>{{ app_version }}</strong> with
<a href="https://yt-dl.org/" class="nowrap" target="_blank"><i class="fas fa-link"></i> youtube-dl</a> version <strong>{{ youtube_dl_version }}</strong> and
<a href="https://github.com/yt-dlp/yt-dlp" class="nowrap" target="_blank"><i class="fas fa-link"></i> yt-dlp</a> version <strong>{{ yt_dlp_version }}</strong> and
<a href="https://ffmpeg.org/" class="nowrap" target="_blank"><i class="fas fa-link"></i> FFmpeg</a> version <strong>{{ ffmpeg_version }}</strong>.
</p>
</div>

View File

@@ -1,7 +1,7 @@
from youtube_dl import version as yt_version
from yt_dlp import version as yt_dlp_version
youtube_dl_version = str(yt_version.__version__)
yt_dlp_version = str(yt_dlp_version.__version__)
ffmpeg_version = '(shared install)'

View File

@@ -1,4 +1,6 @@
from datetime import datetime
from urllib.parse import urlunsplit, urlencode, urlparse
from yt_dlp.utils import LazyList
from .errors import DatabaseConnectionError
@@ -113,3 +115,11 @@ def clean_filename(filename):
filename = filename.replace(char, '')
filename = ''.join([c for c in filename if ord(c) > 30])
return ' '.join(filename.split())
def json_serial(obj):
if isinstance(obj, datetime):
return obj.isoformat()
if isinstance(obj, LazyList):
return list(obj)
raise TypeError(f'Type {type(obj)} is not json_serial()-able')

View File

@@ -22,6 +22,7 @@ from background_task import background
from background_task.models import Task, CompletedTask
from common.logger import log
from common.errors import NoMediaException, DownloadFailedException
from common.utils import json_serial
from .models import Source, Media, MediaServer
from .utils import (get_remote_image, resize_image_to_height, delete_file,
write_text_file)
@@ -224,7 +225,7 @@ def download_media_metadata(media_id):
return
source = media.source
metadata = media.index_metadata()
media.metadata = json.dumps(metadata)
media.metadata = json.dumps(metadata, default=json_serial)
upload_date = media.upload_date
# Media must have a valid upload date
if upload_date:

View File

@@ -8,7 +8,7 @@ import os
from django.conf import settings
from copy import copy
from common.logger import log
import youtube_dl
import yt_dlp
_youtubedl_cachedir = getattr(settings, 'YOUTUBE_DL_CACHEDIR', None)
@@ -19,7 +19,7 @@ if _youtubedl_cachedir:
class YouTubeError(youtube_dl.utils.DownloadError):
class YouTubeError(yt_dlp.utils.DownloadError):
'''
Generic wrapped error for all errors that could be raised by youtube-dl.
'''
@@ -41,10 +41,10 @@ def get_media_info(url):
'extract_flat': True,
})
response = {}
with youtube_dl.YoutubeDL(opts) as y:
with yt_dlp.YoutubeDL(opts) as y:
try:
response = y.extract_info(url, download=False)
except youtube_dl.utils.DownloadError as e:
except yt_dlp.utils.DownloadError as e:
raise YouTubeError(f'Failed to extract_info for "{url}": {e}') from e
if not response:
raise YouTubeError(f'Failed to extract_info for "{url}": No metadata was '
@@ -99,9 +99,9 @@ def download_media(url, media_format, extension, output_file):
'quiet': True,
'progress_hooks': [hook],
})
with youtube_dl.YoutubeDL(opts) as y:
with yt_dlp.YoutubeDL(opts) as y:
try:
return y.download([url])
except youtube_dl.utils.DownloadError as e:
except yt_dlp.utils.DownloadError as e:
raise YouTubeError(f'Failed to download for "{url}": {e}') from e
return False