fix: runtime errors
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -8,6 +8,7 @@ from typing import Optional, Dict, Tuple, List, Type, Generic, Any, TypeVar, Set
|
||||
from pathlib import Path
|
||||
import inspect
|
||||
|
||||
from .source import SourceCollection
|
||||
from .metadata import Metadata
|
||||
from ..utils import get_unix_time, object_trace, generate_id
|
||||
from ..utils.config import logging_settings, main_settings
|
||||
|
||||
@@ -20,13 +20,11 @@ from dataclasses import dataclass, field
|
||||
from functools import cached_property
|
||||
|
||||
from ..utils import generate_id
|
||||
from ..utils.enums import SourceType
|
||||
from ..utils.enums import SourceType, ALL_SOURCE_TYPES
|
||||
from ..utils.config import youtube_settings
|
||||
from ..utils.string_processing import hash_url, shorten_display_url
|
||||
|
||||
from .metadata import Mapping, Metadata
|
||||
from .parents import OuterProxy
|
||||
from .collection import Collection
|
||||
if TYPE_CHECKING:
|
||||
from ..pages.abstract import Page
|
||||
|
||||
@@ -54,38 +52,38 @@ class Source:
|
||||
url = parsed_url.geturl()
|
||||
|
||||
if "musify" in parsed_url.netloc:
|
||||
return cls(SourceType.MUSIFY, url, referrer_page=referrer_page)
|
||||
return cls(ALL_SOURCE_TYPES.MUSIFY, url, referrer_page=referrer_page)
|
||||
|
||||
if parsed_url.netloc in [_url.netloc for _url in youtube_settings['youtube_url']]:
|
||||
return cls(SourceType.YOUTUBE, url, referrer_page=referrer_page)
|
||||
return cls(ALL_SOURCE_TYPES.YOUTUBE, url, referrer_page=referrer_page)
|
||||
|
||||
if url.startswith("https://www.deezer"):
|
||||
return cls(SourceType.DEEZER, url, referrer_page=referrer_page)
|
||||
return cls(ALL_SOURCE_TYPES.DEEZER, url, referrer_page=referrer_page)
|
||||
|
||||
if url.startswith("https://open.spotify.com"):
|
||||
return cls(SourceType.SPOTIFY, url, referrer_page=referrer_page)
|
||||
return cls(ALL_SOURCE_TYPES.SPOTIFY, url, referrer_page=referrer_page)
|
||||
|
||||
if "bandcamp" in url:
|
||||
return cls(SourceType.BANDCAMP, url, referrer_page=referrer_page)
|
||||
return cls(ALL_SOURCE_TYPES.BANDCAMP, url, referrer_page=referrer_page)
|
||||
|
||||
if "wikipedia" in parsed_url.netloc:
|
||||
return cls(SourceType.WIKIPEDIA, url, referrer_page=referrer_page)
|
||||
return cls(ALL_SOURCE_TYPES.WIKIPEDIA, url, referrer_page=referrer_page)
|
||||
|
||||
if url.startswith("https://www.metal-archives.com/"):
|
||||
return cls(SourceType.ENCYCLOPAEDIA_METALLUM, url, referrer_page=referrer_page)
|
||||
return cls(ALL_SOURCE_TYPES.ENCYCLOPAEDIA_METALLUM, url, referrer_page=referrer_page)
|
||||
|
||||
# the less important once
|
||||
if url.startswith("https://www.facebook"):
|
||||
return cls(SourceType.FACEBOOK, url, referrer_page=referrer_page)
|
||||
return cls(ALL_SOURCE_TYPES.FACEBOOK, url, referrer_page=referrer_page)
|
||||
|
||||
if url.startswith("https://www.instagram"):
|
||||
return cls(SourceType.INSTAGRAM, url, referrer_page=referrer_page)
|
||||
return cls(ALL_SOURCE_TYPES.INSTAGRAM, url, referrer_page=referrer_page)
|
||||
|
||||
if url.startswith("https://twitter"):
|
||||
return cls(SourceType.TWITTER, url, referrer_page=referrer_page)
|
||||
return cls(ALL_SOURCE_TYPES.TWITTER, url, referrer_page=referrer_page)
|
||||
|
||||
if url.startswith("https://myspace.com"):
|
||||
return cls(SourceType.MYSPACE, url, referrer_page=referrer_page)
|
||||
return cls(ALL_SOURCE_TYPES.MYSPACE, url, referrer_page=referrer_page)
|
||||
|
||||
@property
|
||||
def has_page(self) -> bool:
|
||||
@@ -134,7 +132,7 @@ class SourceCollection:
|
||||
_sources_by_type: Dict[SourceType, List[Source]]
|
||||
|
||||
def __init__(self, data: Optional[Iterable[Source]] = None, **kwargs):
|
||||
self._page_to_source_list = defaultdict(list)
|
||||
self._sources_by_type = defaultdict(list)
|
||||
self._indexed_sources = {}
|
||||
|
||||
self.extend(data or [])
|
||||
@@ -157,7 +155,7 @@ class SourceCollection:
|
||||
Iterable[SourceType]: A list of source types.
|
||||
"""
|
||||
|
||||
source_types: List[SourceType] = self._page_to_source_list.keys()
|
||||
source_types: List[SourceType] = self._sources_by_type.keys()
|
||||
if only_with_page:
|
||||
source_types = filter(lambda st: st.has_page, source_types)
|
||||
|
||||
@@ -186,7 +184,7 @@ class SourceCollection:
|
||||
source_types = self.source_types(**source_type_sorting)
|
||||
|
||||
for source_type in source_types:
|
||||
yield from self._page_to_source_list[source_type]
|
||||
yield from self._sources_by_type[source_type]
|
||||
|
||||
def append(self, source: Source):
|
||||
if source is None:
|
||||
@@ -202,7 +200,7 @@ class SourceCollection:
|
||||
existing_source.__merge__(source)
|
||||
source = existing_source
|
||||
else:
|
||||
self._page_to_source_list[source.source_type].append(source)
|
||||
self._sources_by_type[source.source_type].append(source)
|
||||
|
||||
changed = False
|
||||
for key in source.indexing_values:
|
||||
|
||||
Reference in New Issue
Block a user