fix: merging and replacing instances

This commit is contained in:
Hazel 2023-10-23 16:21:44 +02:00
parent a6cea55eb2
commit cae2ecffcb
15 changed files with 22 additions and 39 deletions

View File

@ -8,7 +8,8 @@ from .options.first_config import initial_config
from ..utils.config import write_config, main_settings
from ..utils.regex import URL_PATTERN
from ..utils.string_processing import fit_to_file_system
from ..utils.support_classes import Query, DownloadResult
from ..utils.support_classes.query import Query
from ..utils.support_classes.download_result import DownloadResult
from ..utils.exception.download import UrlNotFoundException
from ..download.results import Results, Option, PageResults
from ..download.page_attributes import Pages

View File

@ -9,7 +9,7 @@ from tqdm import tqdm
from .rotating import RotatingProxy
from ..utils.config import main_settings
from ..utils.support_classes import DownloadResult
from ..utils.support_classes.download_result import DownloadResult
from ..objects import Target

View File

@ -5,7 +5,8 @@ from ..objects import DatabaseObject, Source
from ..utils.config import youtube_settings
from ..utils.enums.source import SourcePages
from ..utils.support_classes import Query, DownloadResult
from ..utils.support_classes.download_result import DownloadResult
from ..utils.support_classes.query import Query
from ..utils.exception.download import UrlNotFoundException
from ..utils.shared import DEBUG_PAGES

View File

@ -2,13 +2,13 @@ from typing import List, Iterable, Iterator, Optional, TypeVar, Generic, Dict, T
from collections import defaultdict
from .parents import DatabaseObject
from ..utils.functions import replace_all_refs
from ..utils.support_classes.hacking import MetaClass
T = TypeVar('T', bound=DatabaseObject)
class Collection(Generic[T]):
class Collection(Generic[T], metaclass=MetaClass):
_data: List[T]
_indexed_values: Dict[str, set]
@ -109,7 +109,7 @@ class Collection(Generic[T]):
# now the ugly part
# replace all refs of the other element with this one
replace_all_refs(self, equal_collection)
self.merge(equal_collection)
def contain_collection_inside(self, sub_collection: "Collection"):

View File

@ -7,7 +7,7 @@ from .metadata import Metadata
from .option import Options
from ..utils.shared import HIGHEST_ID
from ..utils.config import main_settings, logging_settings
from ..utils.functions import replace_all_refs
from ..utils.support_classes.hacking import MetaClass
LOGGER = logging_settings["object_logger"]
@ -43,7 +43,7 @@ class Attribute(Generic[P]):
class DatabaseObject:
class DatabaseObject(metaclass=MetaClass):
COLLECTION_STRING_ATTRIBUTES: tuple = tuple()
SIMPLE_STRING_ATTRIBUTES: dict = dict()
@ -170,7 +170,7 @@ class DatabaseObject:
setattr(self, simple_attribute, getattr(other, simple_attribute))
if replace_all_refs:
replace_all_refs(self, other)
self.merge(other)
def strip_details(self):
for collection in type(self).DOWNWARDS_COLLECTION_STRING_ATTRIBUTES:

View File

@ -23,7 +23,8 @@ from ..utils.enums.source import SourcePages
from ..utils.enums.album import AlbumType
from ..audio import write_metadata_to_target, correct_codec
from ..utils.config import main_settings
from ..utils.support_classes import Query, DownloadResult
from ..utils.support_classes.query import Query
from ..utils.support_classes.download_result import DownloadResult
from ..utils.string_processing import fit_to_file_system

View File

@ -21,7 +21,7 @@ from ..objects import (
FormattedText
)
from ..connection import Connection
from ..utils.support_classes import DownloadResult
from ..utils.support_classes.download_result import DownloadResult
from ..utils.config import main_settings, logging_settings
from ..utils.shared import DEBUG
if DEBUG:

View File

@ -9,7 +9,7 @@ from ..utils.config import logging_settings
from .abstract import Page
from ..utils.enums.source import SourcePages
from ..utils.enums.album import AlbumType
from ..utils.support_classes import Query
from ..utils.support_classes.query import Query
from ..objects import (
Lyrics,
Artist,

View File

@ -25,7 +25,8 @@ from ..objects import (
)
from ..utils.config import logging_settings
from ..utils import string_processing, shared
from ..utils.support_classes import DownloadResult, Query
from ..utils.support_classes.query import Query
from ..utils.support_classes.download_result import DownloadResult
"""
https://musify.club/artist/ghost-bath-280348?_pjax=#bodyContent

View File

@ -15,7 +15,8 @@ from ..objects import (
Target
)
from ..connection import Connection
from ..utils.support_classes import DownloadResult
from ..utils.support_classes.query import Query
from ..utils.support_classes.download_result import DownloadResult
class Preset(Page):
# CHANGE

View File

@ -20,7 +20,7 @@ from ..objects import (
)
from ..connection import Connection
from ..utils.string_processing import clean_song_title
from ..utils.support_classes import DownloadResult
from ..utils.support_classes.download_result import DownloadResult
from ..utils.config import youtube_settings, main_settings, logging_settings
from .youtube_music.super_youtube import SuperYouTube, YouTubeUrl, get_invidious_url, YouTubeUrlType

View File

@ -19,7 +19,7 @@ from ...objects import (
ID3Timestamp
)
from ...connection import Connection
from ...utils.support_classes import DownloadResult
from ...utils.support_classes.download_result import DownloadResult
from ...utils.config import youtube_settings, logging_settings, main_settings

View File

@ -25,7 +25,7 @@ from ...objects import (
Target
)
from ...connection import Connection
from ...utils.support_classes import DownloadResult
from ...utils.support_classes.download_result import DownloadResult
from ._list_render import parse_renderer
from .super_youtube import SuperYouTube

View File

@ -1,25 +1,5 @@
import os
from datetime import datetime
import guppy
from guppy.heapy import Path
hp = guppy.hpy()
def replace_all_refs(replace_with, replace):
"""
NO
I have a very good reason to use this here
DONT use this anywhere else...
This replaces **ALL** references to replace with a reference to replace_with.
https://benkurtovic.com/2015/01/28/python-object-replacement.html
"""
for path in hp.iso(replace).pathsin:
relation = path.path[1]
if isinstance(relation, Path.R_INDEXVAL):
path.src.theone[relation.r] = replace_with
def clear_console():

View File

@ -1,3 +1 @@
from .download_result import DownloadResult
from .query import Query
from .thread_classes import EndThread, FinishedSearch