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

@ -14,7 +14,6 @@ whitenoise = "*"
gunicorn = "*" gunicorn = "*"
django-compressor = "*" django-compressor = "*"
httptools = "*" httptools = "*"
youtube-dl = "*"
django-background-tasks = "*" django-background-tasks = "*"
requests = "*" requests = "*"
django-basicauth = "*" django-basicauth = "*"

10
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "d56605e509bb3a227050e182c835196c2889ba79c8e8a56cf0b61a6a57c5fe08" "sha256": "ac12e45a1719945b2e19d4a12b03136225f1f5e81affd1adf44a7b3c8dd36b8a"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -403,14 +403,6 @@
"index": "pypi", "index": "pypi",
"version": "==5.3.0" "version": "==5.3.0"
}, },
"youtube-dl": {
"hashes": [
"sha256:263e04d53fb8ba3dfbd246ad09b7d388e896c132a20cc770c26ee7684de050ac",
"sha256:cb2d3ee002158ede783e97a82c95f3817594df54367ea6a77ce5ceea4772f0ab"
],
"index": "pypi",
"version": "==2021.6.6"
},
"yt-dlp": { "yt-dlp": {
"hashes": [ "hashes": [
"sha256:c97716a715261657345176ab8190a19efa51db0e5b174a6629956548750245e1", "sha256:c97716a715261657345176ab8190a19efa51db0e5b174a6629956548750245e1",

View File

@ -1,10 +1,10 @@
from django.conf import settings 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): def app_details(request):
return { return {
'app_version': str(settings.VERSION), 'app_version': str(settings.VERSION),
'youtube_dl_version': youtube_dl_version, 'yt_dlp_version': yt_dlp_version,
'ffmpeg_version': ffmpeg_version, 'ffmpeg_version': ffmpeg_version,
} }

View File

@ -57,7 +57,7 @@
</p> </p>
<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://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>. <a href="https://ffmpeg.org/" class="nowrap" target="_blank"><i class="fas fa-link"></i> FFmpeg</a> version <strong>{{ ffmpeg_version }}</strong>.
</p> </p>
</div> </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)' ffmpeg_version = '(shared install)'

View File

@ -1,4 +1,6 @@
from datetime import datetime
from urllib.parse import urlunsplit, urlencode, urlparse from urllib.parse import urlunsplit, urlencode, urlparse
from yt_dlp.utils import LazyList
from .errors import DatabaseConnectionError from .errors import DatabaseConnectionError
@ -113,3 +115,11 @@ def clean_filename(filename):
filename = filename.replace(char, '') filename = filename.replace(char, '')
filename = ''.join([c for c in filename if ord(c) > 30]) filename = ''.join([c for c in filename if ord(c) > 30])
return ' '.join(filename.split()) 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 background_task.models import Task, CompletedTask
from common.logger import log from common.logger import log
from common.errors import NoMediaException, DownloadFailedException from common.errors import NoMediaException, DownloadFailedException
from common.utils import json_serial
from .models import Source, Media, MediaServer from .models import Source, Media, MediaServer
from .utils import (get_remote_image, resize_image_to_height, delete_file, from .utils import (get_remote_image, resize_image_to_height, delete_file,
write_text_file) write_text_file)
@ -224,7 +225,7 @@ def download_media_metadata(media_id):
return return
source = media.source source = media.source
metadata = media.index_metadata() metadata = media.index_metadata()
media.metadata = json.dumps(metadata) media.metadata = json.dumps(metadata, default=json_serial)
upload_date = media.upload_date upload_date = media.upload_date
# Media must have a valid upload date # Media must have a valid upload date
if upload_date: if upload_date:

View File

@ -8,7 +8,7 @@ import os
from django.conf import settings from django.conf import settings
from copy import copy from copy import copy
from common.logger import log from common.logger import log
import youtube_dl import yt_dlp
_youtubedl_cachedir = getattr(settings, 'YOUTUBE_DL_CACHEDIR', None) _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. 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, 'extract_flat': True,
}) })
response = {} response = {}
with youtube_dl.YoutubeDL(opts) as y: with yt_dlp.YoutubeDL(opts) as y:
try: try:
response = y.extract_info(url, download=False) 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 raise YouTubeError(f'Failed to extract_info for "{url}": {e}') from e
if not response: if not response:
raise YouTubeError(f'Failed to extract_info for "{url}": No metadata was ' 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, 'quiet': True,
'progress_hooks': [hook], 'progress_hooks': [hook],
}) })
with youtube_dl.YoutubeDL(opts) as y: with yt_dlp.YoutubeDL(opts) as y:
try: try:
return y.download([url]) 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 raise YouTubeError(f'Failed to download for "{url}": {e}') from e
return False return False