remove kontor-cli.backup

This commit is contained in:
Thomas Peetz
2025-01-21 09:42:33 +01:00
parent 65288a53a1
commit 4c330a1138
40 changed files with 196 additions and 889 deletions
+47 -5
View File
@@ -1,21 +1,63 @@
import re
import subprocess
from pathlib import Path
import requests
from bs4 import BeautifulSoup
class VideoLink:
def __init__(self, url: str, log):
def __init__(self, url: str, dl_tool: str, table: str):
self.file_name = None
self.url = url
self.title = None
self.log = log
self.dl_tool = dl_tool
self.table = table
def get_title(self):
def get_title(self) -> str:
try:
r = requests.get(self.url)
soup = BeautifulSoup(r.content, "html.parser")
title = soup.title.string
except:
self.log.info("Sorry, could not retrieve title")
title = None
return title
def download(self, download_dir=None):
self.log.info(f"download {self.url} to {download_dir}")
if download_dir is None:
download_dir = Path.cwd()
result = subprocess.run([self.dl_tool, self.url], cwd=download_dir, capture_output=True, text=True)
if result.returncode == 0:
output = result.stdout
output = re.sub(' +', ' ', output)
lines_list = output.splitlines()
return self.__parse_output__(lines_list)
else:
return None
def __parse_output__(self, lines_list):
self.file_name = ""
for line in lines_list:
if 'has already been downloaded' in line:
end_len = len(' has already been downloaded')
self.file_name = line[11:-end_len]
if 'Destination' in line:
line_len = len(line)
start_len = len('[download] Destination: ')
file_len = line_len - start_len
self.file_name = line[-file_len:]
return self.file_name
class MediaFile(VideoLink):
def __init__(self, url: str, dl_tool='yt-dlp'):
super().__init__(url, dl_tool, 'media_file')
class MediaVideo(VideoLink):
def __init__(self, url: str, dl_tool='yt-dlp'):
super().__init__(url, dl_tool, 'media_video')