Compare commits

..

2 commits

Author SHA1 Message Date
caefa4dd37 Bump version: 0.1.0 → 0.1.1
All checks were successful
continuous-integration/drone/push Build is passing
2022-06-27 02:14:31 +02:00
580075e140 add cache folder 2022-06-27 02:14:19 +02:00
6 changed files with 19 additions and 6 deletions

View file

@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.0
current_version = 0.1.1
commit = True
tag = True

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "ucast"
version = "0.1.0"
version = "0.1.1"
description = "YouTube to Podcast converter"
authors = ["Theta-Dev <t.testboy@gmail.com>"]
packages = [

View file

@ -1,4 +1,4 @@
__version__ = "0.1.0"
__version__ = "0.1.1"
def template_context(request):

View file

@ -1,4 +1,5 @@
import os
import tempfile
from pathlib import Path
from django.conf import settings
@ -62,3 +63,13 @@ class Storage:
if not cf.does_exist():
cf.create()
return cf
class Cache:
def __init__(self):
self.dir_cache = settings.CACHE_ROOT
self.dir_ytdlp_cache = self.dir_cache / "yt_dlp"
os.makedirs(self.dir_ytdlp_cache, exist_ok=True)
def create_tmpdir(self, prefix="dld") -> tempfile.TemporaryDirectory:
return tempfile.TemporaryDirectory(prefix=prefix + "_", dir=self.dir_cache)

View file

@ -2,7 +2,6 @@ import datetime
import logging
import re
import shutil
import tempfile
from dataclasses import dataclass
from operator import itemgetter
from pathlib import Path
@ -12,7 +11,7 @@ import feedparser
import requests
from yt_dlp import YoutubeDL
from ucast.service import scrapetube, util
from ucast.service import scrapetube, storage, util
CHANID_REGEX = re.compile(r"""[-_a-zA-Z\d]{24}""")
@ -142,7 +141,8 @@ def download_audio(
:param sponsorblock: Enable Sponsorblock
:return: VideoDetails
"""
tmpdir = tempfile.TemporaryDirectory(prefix="ucast_")
cache = storage.Cache()
tmpdir = cache.create_tmpdir()
tmp_dld_file = Path(tmpdir.name) / "audio.mp3"
ydl_params = {
@ -151,6 +151,7 @@ def download_audio(
{"key": "FFmpegExtractAudio", "preferredcodec": "mp3"},
],
"outtmpl": str(tmp_dld_file),
"cachedir": str(cache.dir_ytdlp_cache),
}
if sponsorblock:

View file

@ -208,6 +208,7 @@ USE_TZ = True
STATIC_URL = "static/"
STATIC_ROOT = get_env_path("STATIC_ROOT", BASE_DIR / "static")
DOWNLOAD_ROOT = get_env_path("DOWNLOAD_ROOT", BASE_DIR / "data")
CACHE_ROOT = get_env_path("CACHE_ROOT", BASE_DIR / "cache")
STATICFILES_DIRS = [resources.path("ucast", "static")]