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 from .utils.string_processing import fit_to_file_system
import sys; sys.setrecursionlimit(100)
if MODIFY_GC: if MODIFY_GC:
""" """
At the start I modify the garbage collector to run a bit fewer times. 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 .option import Options
from . import ( from .parents import DatabaseObject
song,
metadata, from .metadata import Metadata, Mapping as ID3Mapping, ID3Timestamp
source,
parents, from .source import Source, SourcePages, SourceTypes
formatted_text,
option, from .song import (
collection Song,
Album,
Artist,
Target,
Lyrics,
Label
) )
DatabaseObject = parents.DatabaseObject from .formatted_text import FormattedText
from .collection import Collection
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

View File

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

View File

@ -117,7 +117,7 @@ class Page(threading.Thread):
def run(self) -> None: def run(self) -> None:
pass pass
def get_source_type(self, source: Source) -> Optional[INDEPENDENT_DB_TYPES]: def get_source_type(self, source: Source) -> Optional[Type[DatabaseObject]]:
return None return None
def get_soup_from_response(self, r: requests.Response) -> BeautifulSoup: def get_soup_from_response(self, r: requests.Response) -> BeautifulSoup:
@ -186,7 +186,13 @@ class Page(threading.Thread):
source: Source source: Source
for source in music_object.source_collection.get_sources_from_page(self.SOURCE_TYPE): for source in music_object.source_collection.get_sources_from_page(self.SOURCE_TYPE):
new_music_object.merge( 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) return merge_together(music_object, new_music_object)

View File

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

View File

@ -26,6 +26,8 @@ class SourcePages(Enum):
MYSPACE = "myspace" # Yes somehow this ancient site is linked EVERYWHERE MYSPACE = "myspace" # Yes somehow this ancient site is linked EVERYWHERE
MANUAL = "manual" MANUAL = "manual"
PRESET = "preset"
@classmethod @classmethod
def get_homepage(cls, attribute) -> str: def get_homepage(cls, attribute) -> str: