Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MonoLoad/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def change_theme_mode(e):
title=ft.Text('MonoLoad'),
center_title=False,
actions=[
ft.IconButton(ft.icons.WB_SUNNY_OUTLINED,
ft.IconButton(ft.Icons.WB_SUNNY_OUTLINED,
on_click=change_theme_mode),
ft.PopupMenuButton(
items=[
Expand Down
10 changes: 7 additions & 3 deletions MonoLoad/src/MonoDownloads/audio_dowload_gui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pytube import YouTube
from pytubefix import YouTube
from typing import Optional
from os import getcwd
from os import getcwd, path
from re import sub


Expand All @@ -22,7 +22,11 @@
def download_audio(video: YouTube,
resolution: Optional[str] = '128kbps',
video_title: Optional[str] = '',
out_path: Optional[str] = f'{cwd}/downloads/audios') -> str:
out_path: Optional[str] = None) -> str:
"""Download audio from YouTube video"""
if out_path is None:
out_path = path.join(cwd, 'downloads', 'audios')

quality = audioTagsQuality.get(resolution)
try:
stream = video.streams.get_by_itag(quality)
Expand Down
14 changes: 6 additions & 8 deletions MonoLoad/src/MonoDownloads/audio_download.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pytube import YouTube, streams, StreamQuery, Stream
from pytubefix import YouTube, streams, StreamQuery, Stream
from colorama import init, Fore
from .itags import audio_itags_quality
from os import getcwd, rename, listdir, path
Expand All @@ -7,15 +7,13 @@

init(autoreset=True)

def download(url: Required[str], out_path: Optional[str] = f"{getcwd()}/downloads/audios") -> NoReturn:
def download(url: Required[str], out_path: Optional[str] = None) -> NoReturn:
if out_path is None:
out_path = path.join(getcwd(), "downloads", "audios")

def get_resolution(streams_data: StreamQuery) -> list[str]:
resolutions = list()

for stream in streams_data:
resolutions.append(stream.abr)

return resolutions
"""Extract available resolutions from streams"""
return [stream.abr for stream in streams_data]

def audio_quality_download(resolutions: Required[list[str]], video) -> str:
print(f"\n video title: {Fore.RED + video.title} \n {Fore.WHITE} \n qualities: {resolutions}")
Expand Down
55 changes: 34 additions & 21 deletions MonoLoad/src/MonoDownloads/video_download.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
from os import getcwd
from os import getcwd, path
from tqdm import tqdm
from time import sleep

from pytube import YouTube, streams
from pytubefix import YouTube, streams
from .itags import videos_itags_resolution as video_itags
from colorama import init, Fore


init(autoreset=True)

def download(url, out_path=f"{getcwd()}/downloads/videos"):
def download(url, out_path=None):
if out_path is None:
out_path = path.join(getcwd(), "downloads", "videos")

def progress(stream, data_chunk, bytes_remaing ):
bar_format = '{l_bar}{bar}| {n_fmt}/{total_fmt} {postfix}'
bar = tqdm(total=stream.filesize, bar_format=bar_format)
bar.update(stream.filesize - bytes_remaing)

def dowload_by_resolution(resolutions, video):
# Progress bar state
progress_bar = {'bar': None}

def progress(stream, data_chunk, bytes_remaining):
"""Callback for download progress"""
# Create progress bar on first call
if progress_bar['bar'] is None:
total_size = stream.filesize
progress_bar['bar'] = tqdm(total=total_size, unit='B', unit_scale=True,
desc='Downloading', bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt}')

# Update with the size of the chunk just downloaded
progress_bar['bar'].update(len(data_chunk))

def download_by_resolution(resolutions, video):
print(f"\n video title: {Fore.RED + video.title} \n {Fore.WHITE} \n qualities: {resolutions}")

video_quality_dowload = input("\n Type the quality: ")
return video_quality_dowload
video_quality_download = input("\n Type the quality: ")
return video_quality_download

def get_resolutions(stream_data):
resolutions = list()
resolutions = set()

for data in stream_data:
resolutions.append(data.resolution)
if data.resolution:
resolutions.add(data.resolution)

resolutions = list(filter(lambda x: x is not None, set(resolutions)))
return resolutions
return sorted(list(resolutions))



video = YouTube(url)
video = YouTube(url, on_progress_callback=progress)
stream_data = video.streams.filter(file_extension="mp4")
resolutions = get_resolutions(stream_data)

video_quality_to_dowload = dowload_by_resolution(resolutions=resolutions, video=video)
video_quality_to_download = download_by_resolution(resolutions=resolutions, video=video)

stream = video.streams.get_by_itag(video_itags.get(video_quality_to_dowload))
stream.download(output_path=out_path)
stream = video.streams.get_by_itag(video_itags.get(video_quality_to_download))
stream.download(output_path=out_path)

# Close progress bar if it exists
if progress_bar['bar'] is not None:
progress_bar['bar'].close()
9 changes: 5 additions & 4 deletions MonoLoad/src/MultiDownloads/audio_downloads.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os import getcwd, listdir, rename
from os import getcwd, listdir, path
from .itags import audio_itags_quality
from pytube import YouTube, streams
from pytubefix import YouTube, streams
from colorama import Fore, init
from concurrent.futures import ThreadPoolExecutor
from typing import Required, Optional
Expand All @@ -17,7 +17,7 @@ def multi_download(url: Required[str], quality: Required[str] , out_path: Requir


def download(audios_url: Required[list], quality: Optional[str]="128kbps", threads: Optional[int]=2, out_path: Optional[
str] = f"{getcwd()}/downloads/audios") -> list[str]:
str] = None) -> list[str]:
"""
Variables
---------
Expand All @@ -30,7 +30,8 @@ def download(audios_url: Required[list], quality: Optional[str]="128kbps", threa
* out_path (str): In this variable, the proportional folder is searched for where the download folder with the audios is to be stored.

"""

if out_path is None:
out_path = path.join(getcwd(), "downloads", "audios")

with ThreadPoolExecutor(max_workers=threads) as executor:
for url in audios_url:
Expand Down
10 changes: 7 additions & 3 deletions MonoLoad/src/MultiDownloads/video_downloads.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os import getcwd
from os import getcwd, path
from .itags import videos_itags_resolution
from pytube import YouTube, streams
from pytubefix import YouTube, streams
from colorama import init, Fore
from concurrent.futures import ThreadPoolExecutor

Expand All @@ -17,7 +17,11 @@ def multi_download(url: str, quality:str ,out_path: str) -> None:



def download(videos_url: list, threads: int , quality: str , filename: str ,out_path=f"{getcwd()}/downloads/videos") -> None:
def download(videos_url: list, threads: int , quality: str , filename: str ,out_path=None) -> None:
"""Download multiple videos concurrently"""
if out_path is None:
out_path = path.join(getcwd(), "downloads", "videos")

# Send in a pool Threads the videos url to download
with ThreadPoolExecutor(threads) as executor:
for url in videos_url:
Expand Down
9 changes: 4 additions & 5 deletions MonoLoad/src/Routes/pages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import flet as ft
from time import sleep
from MonoLoad.src.MonoDownloads.audio_dowload_gui import get_audio_resolution, download_audio


def HomeComponent(page):
Expand Down Expand Up @@ -26,9 +28,6 @@ def HomeComponent(page):


def DowloadAudioComponent(page):
from time import sleep
from MonoLoad.src.MonoDownloads.audio_dowload_gui import get_audio_resolution, download_audio

qualities = ft.Row(alignment=ft.MainAxisAlignment.CENTER,
spacing=40, scroll=ft.ScrollMode.AUTO)
NameTextField = ft.TextField(label='Name')
Expand All @@ -53,8 +52,8 @@ def close_banner(e):
except Exception as e:
print(e)
page.banner = ft.Banner(
leading=ft.Icon(ft.icons.WARNING_AMBER_ROUNDED,
color=ft.colors.AMBER, size=40),
leading=ft.Icon(ft.Icons.WARNING_AMBER_ROUNDED,
color=ft.Colors.AMBER, size=40),
content=ft.Text(
"It seems that you have used an incorrect or invalid url, please check it and try again."
),
Expand Down
53 changes: 35 additions & 18 deletions MonoLoad/src/transformations.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
from os import getcwd
from typing import Optional, Union
from os import getcwd, path
from typing import Optional


def transform_config_to_dict(config_path: Optional[str] = getcwd()+"/src/page.config") -> dict:
def transform_config_to_dict(config_path: Optional[str] = None) -> dict:
"""
Transform a configuration file into a dictionary.

Args:
config_path: Path to the configuration file. Defaults to src/page.config

Returns:
Dictionary with configuration keys and values
"""
if config_path is None:
# Get the directory of this file, then navigate to page.config
base_dir = path.dirname(path.abspath(__file__))
config_path = path.join(base_dir, "page.config")

with open(config_path, "r+") as f:
lineas: list = list(f.readlines())

listas_limpia: list[str] = [linea.strip() for linea in lineas]

lista_valores_tupla: list[tuple[Union[str, int]]] = []

for elemento in listas_limpia:
clave, valor = elemento.split("=")
if valor.isdigit():
lista_valores_tupla.append((clave, int(valor)))
elif isinstance(eval(valor), bool):
lista_valores_tupla.append((clave, eval(valor)))
config_dict = {}

with open(config_path, "r") as f:
for line in f:
line = line.strip()
if not line or "=" not in line:
continue

key, value = line.split("=", 1)
key = key.strip()
value = value.strip()

# Parse value type without using eval()
if value.lstrip('-').isdigit():
config_dict[key] = int(value)
elif value.lower() in ("true", "false"):
config_dict[key] = value.lower() == "true"
else:
lista_valores_tupla.append((clave, valor))
config_dict[key] = value

return dict(lista_valores_tupla)
return config_dict
6 changes: 2 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
cookiecutter==2.5.0
flet==0.17.0
flet-core==0.17.0
flet-runtime==0.17.0
flet==0.28.3
h11==0.14.0
httpcore==0.17.3
httpx==0.24.1
Expand All @@ -27,7 +25,7 @@ pypng==0.20220715.0
pytest==7.4.0
python-dateutil==2.8.2
python-slugify==8.0.1
pytube==15.0.0
pytubefix==10.3.5
PyYAML==6.0.1
qrcode==7.4.2
repath==0.9.0
Expand Down