mirror of
https://github.com/chibicitiberiu/ytsm.git
synced 2024-02-24 05:43:31 +00:00
Began refactoring javascript code
This commit is contained in:
47
app/YtManagerApp/providers/dummy_video_provider.py
Normal file
47
app/YtManagerApp/providers/dummy_video_provider.py
Normal file
@ -0,0 +1,47 @@
|
||||
from typing import Dict, Optional, Any, Iterable, List
|
||||
|
||||
from django import forms
|
||||
from external.pytaw.pytaw import youtube as yt
|
||||
from external.pytaw.pytaw.utils import iterate_chunks
|
||||
|
||||
from YtManagerApp.models import Subscription, Video
|
||||
from YtManagerApp.providers.video_provider import VideoProvider, InvalidURLError, ProviderValidationError
|
||||
|
||||
|
||||
class DummyVideoProvider(VideoProvider):
|
||||
id = "Dummy"
|
||||
name = "Dummy Videos"
|
||||
description = "Won't really do anything, it's here just for testing."
|
||||
settings = {
|
||||
"api_key": forms.CharField(label="Dummy API Key"),
|
||||
"number_of_something": forms.IntegerField(label="Number of stuff")
|
||||
}
|
||||
|
||||
def configure(self, configuration: Dict[str, Any]) -> None:
|
||||
print(configuration)
|
||||
|
||||
def validate_configuration(self, configuration: Dict[str, Any]):
|
||||
print("Validating...")
|
||||
if configuration["number_of_something"] >= 10:
|
||||
raise ProviderValidationError(
|
||||
field_messages={'number_of_something': "Number too large, try something smaller!"})
|
||||
pass
|
||||
|
||||
def get_subscription_url(self, subscription: Subscription):
|
||||
return f"https://dummy/playlist/{subscription.playlist_id}"
|
||||
|
||||
def validate_subscription_url(self, url: str) -> None:
|
||||
if not url.startswith('https://dummy/'):
|
||||
raise InvalidURLError("URL not valid")
|
||||
|
||||
def fetch_subscription(self, url: str) -> Subscription:
|
||||
raise ValueError('No such subscription (note: dummy plugin, nothing will work)!')
|
||||
|
||||
def get_video_url(self, video: Video) -> str:
|
||||
return f"https://dummy/video/{video.video_id}"
|
||||
|
||||
def fetch_videos(self, subscription: Subscription) -> Iterable[Video]:
|
||||
return []
|
||||
|
||||
def update_videos(self, videos: List[Video], update_metadata=False, update_statistics=False) -> None:
|
||||
pass
|
@ -6,7 +6,7 @@ from django.forms import Field
|
||||
from YtManagerApp.models import Subscription, Video
|
||||
|
||||
|
||||
class ConfigurationValidationError(ValueError):
|
||||
class ProviderValidationError(ValueError):
|
||||
"""
|
||||
Exception type thrown when validating configurations.
|
||||
"""
|
||||
@ -27,7 +27,21 @@ class InvalidURLError(ValueError):
|
||||
|
||||
|
||||
class VideoProvider(ABC):
|
||||
"""
|
||||
Identifier
|
||||
"""
|
||||
id: str = ""
|
||||
"""
|
||||
Display name, shown to users
|
||||
"""
|
||||
name: str = ""
|
||||
"""
|
||||
Description, shown to users
|
||||
"""
|
||||
description: str = ""
|
||||
"""
|
||||
Dictionary containing fields necessary for configuring
|
||||
"""
|
||||
settings: Dict[str, Field] = {}
|
||||
|
||||
@abstractmethod
|
||||
|
@ -9,7 +9,9 @@ from YtManagerApp.providers.video_provider import VideoProvider, InvalidURLError
|
||||
|
||||
|
||||
class YouTubeApiVideoProvider(VideoProvider):
|
||||
name = "YtAPI"
|
||||
id = "YtAPI"
|
||||
name = "YouTube API"
|
||||
description = "Allows communication with YouTube using the YouTube API."
|
||||
settings = {
|
||||
"api_key": forms.CharField(label="YouTube API Key:")
|
||||
}
|
||||
@ -44,7 +46,7 @@ class YouTubeApiVideoProvider(VideoProvider):
|
||||
|
||||
def fetch_subscription(self, url: str) -> Subscription:
|
||||
sub = Subscription()
|
||||
sub.provider_id = self.name
|
||||
sub.provider_id = self.id
|
||||
|
||||
self.validate_subscription_url(url)
|
||||
url_parsed = self.__api.parse_url(url)
|
||||
|
Reference in New Issue
Block a user