added preset

This commit is contained in:
Hellow2 2023-05-24 10:12:03 +02:00
parent dd0708eef0
commit 19af808d16
6 changed files with 69 additions and 90 deletions

View File

@ -13,8 +13,6 @@ from .utils.shared import MUSIC_DIR, MODIFY_GC, NOT_A_GENRE_REGEX, get_random_me
from .utils.string_processing import fit_to_file_system
import sys; sys.setrecursionlimit(100)
if MODIFY_GC:
"""
At the start I modify the garbage collector to run a bit fewer times.

View File

@ -1,32 +1,18 @@
from ..utils.enums import album
from .option import Options
from . import (
song,
metadata,
source,
parents,
formatted_text,
option,
collection
from .parents import DatabaseObject
from .metadata import Metadata, Mapping as ID3Mapping, ID3Timestamp
from .source import Source, SourcePages, SourceTypes
from .song import (
Song,
Album,
Artist,
Target,
Lyrics,
Label
)
DatabaseObject = parents.DatabaseObject
Metadata = metadata.Metadata
ID3Mapping = metadata.Mapping
ID3Timestamp = metadata.ID3Timestamp
Source = source.Source
Song = song.Song
Artist = song.Artist
Source = source.Source
Target = song.Target
Lyrics = song.Lyrics
Label = song.Label
Album = song.Album
FormattedText = formatted_text.FormattedText
Collection = collection.Collection
from .formatted_text import FormattedText
from .collection import Collection

View File

@ -65,6 +65,9 @@ class DatabaseObject:
return list()
def merge(self, other, override: bool = False):
if other is None:
return
if self is other:
return

View File

@ -117,7 +117,7 @@ class Page(threading.Thread):
def run(self) -> None:
pass
def get_source_type(self, source: Source) -> Optional[INDEPENDENT_DB_TYPES]:
def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]:
return None
def get_soup_from_response(self, r: requests.Response) -> BeautifulSoup:
@ -186,7 +186,13 @@ class Page(threading.Thread):
source: Source
for source in music_object.source_collection.get_sources_from_page(self.SOURCE_TYPE):
new_music_object.merge(
self.fetch_object_from_source(source=source, enforce_type=type(music_object), stop_at_level=stop_at_level, post_process=False))
self.fetch_object_from_source(
source=source,
enforce_type=type(music_object),
stop_at_level=stop_at_level,
post_process=False
)
)
return merge_together(music_object, new_music_object)

View File

@ -1,13 +1,9 @@
from collections import defaultdict
from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Type, Union
from typing import List, Optional, Type
from urllib.parse import urlparse
import logging
import pycountry
import requests
from bs4 import BeautifulSoup
from music_kraken.objects import Source, DatabaseObject
from .abstract import Page
from ..objects import (
Artist,
@ -15,61 +11,49 @@ from ..objects import (
SourcePages,
Song,
Album,
ID3Timestamp,
FormattedText,
Label,
Options,
AlbumType,
AlbumStatus,
Target
)
from ..utils import string_processing, shared
from .support_classes.download_result import DownloadResult
from ..connection import Connection
class Preset(Page):
# CHANGE
SOURCE_TYPE = SourcePages.PRESET
LOGGER = logging.getLogger("preset")
class YouTube(Page):
API_SESSION: requests.Session = requests.Session()
API_SESSION.headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:106.0) Gecko/20100101 Firefox/106.0",
"Connection": "keep-alive",
"Referer": "https://www.youtube.com/"
}
API_SESSION.proxies = shared.proxies
TIMEOUT = 7
POST_TIMEOUT = 15
TRIES = 5
HOST = "https://www.youtube.com"
def __init__(self):
self.connection: Connection = Connection(
host="https://www.preset.cum/",
logger=self.LOGGER
)
SOURCE_TYPE = SourcePages.YOUTUBE
super().__init__()
LOGGER = shared.YOUTUBE_LOGGER
def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]:
return super().get_source_type(source)
def general_search(self, search_query: str) -> List[DatabaseObject]:
return []
@classmethod
def _raw_search(cls, query: str) -> Options:
return Options()
def label_search(self, label: Label) -> List[Label]:
return []
@classmethod
def plaintext_search(cls, query: str) -> Options:
search_results = []
def artist_search(self, artist: Artist) -> List[Artist]:
return []
return Options(search_results)
def album_search(self, album: Album) -> List[Album]:
return []
@classmethod
def _fetch_artist_from_source(cls, source: Source, stop_at_level: int = 1) -> Artist:
artist: Artist = Artist(source_list=[source])
def song_search(self, song: Song) -> List[Song]:
return []
return artist
def fetch_song(self, source: Source, stop_at_level: int = 1) -> Song:
return Song()
@classmethod
def _fetch_album_from_source(cls, source: Source, stop_at_level: int = 1) -> Album:
album: Album = Album(source_list=[source])
return album
def fetch_album(self, source: Source, stop_at_level: int = 1) -> Album:
return Album()
@classmethod
def _get_type_of_url(cls, url: str) -> Optional[Union[Type[Song], Type[Album], Type[Artist], Type[Label]]]:
return None
def fetch_artist(self, source: Source, stop_at_level: int = 1) -> Artist:
return Artist()
@classmethod
def _download_song_to_targets(cls, source: Source, target: Target, desc: str = None) -> DownloadResult:
return DownloadResult()
def fetch_label(self, source: Source, stop_at_level: int = 1) -> Label:
return Label()

View File

@ -27,6 +27,8 @@ class SourcePages(Enum):
MANUAL = "manual"
PRESET = "preset"
@classmethod
def get_homepage(cls, attribute) -> str:
homepage_map = {