fix: runtime errors
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2024-05-15 13:16:11 +02:00
parent ac6c513d56
commit bedd0fe819
12 changed files with 65 additions and 196 deletions

View File

@@ -1,4 +1,5 @@
from dataclasses import dataclass, field
from typing import Set
from ..utils.config import main_settings
from ..utils.enums.album import AlbumType

View File

@@ -2,6 +2,7 @@ from typing import Tuple, Type, Dict, Set, Optional, List
from collections import defaultdict
from pathlib import Path
import re
import logging
from . import FetchOptions, DownloadOptions
from .results import SearchResults
@@ -17,6 +18,7 @@ from ..objects import (
Label,
)
from ..audio import write_metadata_to_target, correct_codec
from ..utils import output, BColors
from ..utils.string_processing import fit_to_file_system
from ..utils.config import youtube_settings, main_settings
from ..utils.path_manager import LOCATIONS
@@ -69,6 +71,8 @@ if DEBUG_PAGES:
class Pages:
def __init__(self, exclude_pages: Set[Type[Page]] = None, exclude_shady: bool = False, download_options: DownloadOptions = None, fetch_options: FetchOptions = None):
self.LOGGER = logging.getLogger("download")
self.download_options: DownloadOptions = download_options or DownloadOptions()
self.fetch_options: FetchOptions = fetch_options or FetchOptions()
@@ -118,7 +122,9 @@ class Pages:
return data_object
source: Source
for source in data_object.source_collection.get_sources():
for source in data_object.source_collection.get_sources(source_type_sorting={
"only_with_page": True,
}):
new_data_object = self.fetch_from_source(source=source, stop_at_level=stop_at_level)
if new_data_object is not None:
data_object.merge(new_data_object)
@@ -129,10 +135,15 @@ class Pages:
if not source.has_page:
return None
func = getattr(source.page, fetch_map[source_type])(source=source, **kwargs)
source_type = source.page.get_source_type(source=source)
if source_type is None:
self.LOGGER.debug(f"Could not determine source type for {source}.")
return None
func = getattr(source.page, fetch_map[source_type])
# fetching the data object and marking it as fetched
data_object: DataObject = func(source=source)
data_object: DataObject = func(source=source, **kwargs)
data_object.mark_as_fetched(source.hash_url)
return data_object
@@ -175,7 +186,7 @@ class Pages:
# download all children
download_result: DownloadResult = DownloadResult()
for c in data_object.get_children():
for c in data_object.get_child_collections():
for d in c:
if self._skip_object(d):
continue
@@ -209,7 +220,7 @@ class Pages:
path_template = path_template.replace(f"{{{field}}}", naming[field][0])
return possible_parts
return path_template
def _download_song(self, song: Song, naming: dict) -> DownloadOptions:
"""
@@ -235,7 +246,7 @@ class Pages:
# removing duplicates from the naming, and process the strings
for key, value in naming.items():
# https://stackoverflow.com/a/17016257
naming[key] = list(dict.fromkeys(items))
naming[key] = list(dict.fromkeys(value))
# manage the targets
tmp: Target = Target.temp(file_extension=main_settings["audio_format"])
@@ -248,14 +259,14 @@ class Pages:
)
))
for target in song.target_collection:
if target.exists():
if target.exists:
output(f'- {target.file_path} {BColors.OKGREEN.value}[already exists]', color=BColors.GREY)
r.found_on_disk += 1
if self.download_options.download_again_if_found:
target.copy_content(tmp)
else:
target.create_parent_directories()
target.create_path()
output(f'- {target.file_path}', color=BColors.GREY)
# this streams from every available source until something succeeds, setting the skip intervals to the values of the according source
@@ -294,7 +305,7 @@ class Pages:
if used_source is not None:
used_source.page.post_process_hook(song=song, temp_target=tmp)
if not found_on_disc or self.download_options.process_metadata_if_found:
if not found_on_disk or self.download_options.process_metadata_if_found:
write_metadata_to_target(metadata=song.metadata, target=tmp, song=song)
tmp.delete()

View File

@@ -2,7 +2,6 @@ from typing import Tuple, Type, Dict, List, Generator, Union
from dataclasses import dataclass
from ..objects import DatabaseObject
from ..utils.enums.source import SourceType
from ..pages import Page, EncyclopaediaMetallum, Musify