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.config import write_config, main_settings
from ..utils.regex import URL_PATTERN from ..utils.regex import URL_PATTERN
from ..utils.string_processing import fit_to_file_system 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 ..utils.exception.download import UrlNotFoundException
from ..download.results import Results, Option, PageResults from ..download.results import Results, Option, PageResults
from ..download.page_attributes import Pages from ..download.page_attributes import Pages

View File

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

View File

@ -5,7 +5,8 @@ from ..objects import DatabaseObject, Source
from ..utils.config import youtube_settings from ..utils.config import youtube_settings
from ..utils.enums.source import SourcePages 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.exception.download import UrlNotFoundException
from ..utils.shared import DEBUG_PAGES 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 collections import defaultdict
from .parents import DatabaseObject from .parents import DatabaseObject
from ..utils.functions import replace_all_refs from ..utils.support_classes.hacking import MetaClass
T = TypeVar('T', bound=DatabaseObject) T = TypeVar('T', bound=DatabaseObject)
class Collection(Generic[T]): class Collection(Generic[T], metaclass=MetaClass):
_data: List[T] _data: List[T]
_indexed_values: Dict[str, set] _indexed_values: Dict[str, set]
@ -109,7 +109,7 @@ class Collection(Generic[T]):
# now the ugly part # now the ugly part
# replace all refs of the other element with this one # 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"): def contain_collection_inside(self, sub_collection: "Collection"):

View File

@ -7,7 +7,7 @@ from .metadata import Metadata
from .option import Options from .option import Options
from ..utils.shared import HIGHEST_ID from ..utils.shared import HIGHEST_ID
from ..utils.config import main_settings, logging_settings 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"] LOGGER = logging_settings["object_logger"]
@ -43,7 +43,7 @@ class Attribute(Generic[P]):
class DatabaseObject: class DatabaseObject(metaclass=MetaClass):
COLLECTION_STRING_ATTRIBUTES: tuple = tuple() COLLECTION_STRING_ATTRIBUTES: tuple = tuple()
SIMPLE_STRING_ATTRIBUTES: dict = dict() SIMPLE_STRING_ATTRIBUTES: dict = dict()
@ -170,7 +170,7 @@ class DatabaseObject:
setattr(self, simple_attribute, getattr(other, simple_attribute)) setattr(self, simple_attribute, getattr(other, simple_attribute))
if replace_all_refs: if replace_all_refs:
replace_all_refs(self, other) self.merge(other)
def strip_details(self): def strip_details(self):
for collection in type(self).DOWNWARDS_COLLECTION_STRING_ATTRIBUTES: 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 ..utils.enums.album import AlbumType
from ..audio import write_metadata_to_target, correct_codec from ..audio import write_metadata_to_target, correct_codec
from ..utils.config import main_settings 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 from ..utils.string_processing import fit_to_file_system

View File

@ -21,7 +21,7 @@ from ..objects import (
FormattedText FormattedText
) )
from ..connection import Connection 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.config import main_settings, logging_settings
from ..utils.shared import DEBUG from ..utils.shared import DEBUG
if DEBUG: if DEBUG:

View File

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

View File

@ -25,7 +25,8 @@ from ..objects import (
) )
from ..utils.config import logging_settings from ..utils.config import logging_settings
from ..utils import string_processing, shared 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 https://musify.club/artist/ghost-bath-280348?_pjax=#bodyContent

View File

@ -15,7 +15,8 @@ from ..objects import (
Target Target
) )
from ..connection import Connection 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): class Preset(Page):
# CHANGE # CHANGE

View File

@ -20,7 +20,7 @@ from ..objects import (
) )
from ..connection import Connection from ..connection import Connection
from ..utils.string_processing import clean_song_title 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 ..utils.config import youtube_settings, main_settings, logging_settings
from .youtube_music.super_youtube import SuperYouTube, YouTubeUrl, get_invidious_url, YouTubeUrlType from .youtube_music.super_youtube import SuperYouTube, YouTubeUrl, get_invidious_url, YouTubeUrlType

View File

@ -19,7 +19,7 @@ from ...objects import (
ID3Timestamp ID3Timestamp
) )
from ...connection import Connection 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 from ...utils.config import youtube_settings, logging_settings, main_settings

View File

@ -25,7 +25,7 @@ from ...objects import (
Target Target
) )
from ...connection import Connection 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 ._list_render import parse_renderer
from .super_youtube import SuperYouTube from .super_youtube import SuperYouTube

View File

@ -1,25 +1,5 @@
import os import os
from datetime import datetime 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(): def clear_console():

View File

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