Skip to content
Open
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
1 change: 1 addition & 0 deletions lab2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

24 changes: 24 additions & 0 deletions lab2/_init_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

from .downloader import MusicDownloader
from .iterator import FileIterator
from .config import GENRES, DEFAULT_CONFIG
from .utils import (
parse_duration,
get_duration_from_url,
create_safe_filename,
random_urls,
distribute_files_by_genre
)


__all__ = [
'MusicDownloader',
'FileIterator',
'GENRES',
'DEFAULT_CONFIG',
'parse_duration',
'get_duration_from_url',
'create_safe_filename',
'random_urls',
'distribute_files_by_genre'
]
29 changes: 29 additions & 0 deletions lab2/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Конфигурация и константы для загрузчика музыки."""

# Жанры для скачивания
GENRES = ['country', 'funk', 'classical']

# Настройки по умолчанию
DEFAULT_CONFIG = {
'min_files': 50,
'max_files': 100,
'max_pages': 3,
'csv_path': 'music_annotation.csv',
'retry_attempts': 3,
'request_timeout': 10,
'download_timeout': 30,
'min_delay': 0.5,
'max_delay': 2.0,
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}

# Шаблоны регулярных выражений
REGEX_PATTERNS = {
'mp3_url': r'https://assets\.mixkit\.co/[^\s"\']+\.mp3',
'duration_sec': r'(\d+)[_-]?sec',
'duration_min_sec': r'(\d+)[_-]?min[_-]?(\d+)',
'safe_filename': r'[^\w\-.]'
}

# Заголовки CSV файла
CSV_HEADERS = ["genre", "abs_path", "rel_path", "url", "filename", "duration"]
Loading