diff --git a/tubearchivist/home/config.json b/tubearchivist/home/config.json
index aa1580d..82c76f4 100644
--- a/tubearchivist/home/config.json
+++ b/tubearchivist/home/config.json
@@ -31,7 +31,8 @@
"cache_dir": "/cache",
"videos": "/youtube",
"file_template": "%(id)s_%(title)s.mp4",
- "colors": "dark"
+ "colors": "dark",
+ "enable_cast": false
},
"scheduler": {
"update_subscribed": false,
diff --git a/tubearchivist/home/forms.py b/tubearchivist/home/forms.py
index 1aa3235..86b1884 100644
--- a/tubearchivist/home/forms.py
+++ b/tubearchivist/home/forms.py
@@ -62,6 +62,12 @@ class ApplicationSettingsForm(forms.Form):
("1", "enable ryd integration"),
]
+ CAST_CHOICES = [
+ ("", "-- change Cast integration --"),
+ ("0", "disable Cast"),
+ ("1", "enable Cast"),
+ ]
+
subscriptions_channel_size = forms.IntegerField(required=False)
downloads_limit_count = forms.IntegerField(required=False)
downloads_limit_speed = forms.IntegerField(required=False)
@@ -78,6 +84,9 @@ class ApplicationSettingsForm(forms.Form):
downloads_integrate_ryd = forms.ChoiceField(
widget=forms.Select, choices=RYD_CHOICES, required=False
)
+ application_enable_cast = forms.ChoiceField(
+ widget=forms.Select, choices=CAST_CHOICES, required=False
+ )
class SchedulerSettingsForm(forms.Form):
diff --git a/tubearchivist/home/templates/home/base.html b/tubearchivist/home/templates/home/base.html
index 88b1028..ab10b1e 100644
--- a/tubearchivist/home/templates/home/base.html
+++ b/tubearchivist/home/templates/home/base.html
@@ -28,6 +28,17 @@
{% endif %}
+ {% if cast %}
+
+
+
+ {% endif %}
diff --git a/tubearchivist/home/templates/home/settings.html b/tubearchivist/home/templates/home/settings.html
index 6e728ea..f18a578 100644
--- a/tubearchivist/home/templates/home/settings.html
+++ b/tubearchivist/home/templates/home/settings.html
@@ -102,6 +102,11 @@
Before activating that, make sure you have a scraping sleep interval of at least 3 secs set to avoid ratelimiting issues.
{{ app_form.downloads_integrate_ryd }}
+
{{ video.title }}
+ {% if cast %}
+ Start Cast
+ Stop Cast
+ {% endif %}
diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py
index ff48714..5dbfdb7 100644
--- a/tubearchivist/home/views.py
+++ b/tubearchivist/home/views.py
@@ -590,10 +590,9 @@ class VideoView(View):
def get(self, request, video_id):
"""get single video"""
- es_url, colors = self.read_config(user_id=request.user.id)
+ es_url, colors, cast = self.read_config(user_id=request.user.id)
url = f"{es_url}/ta_video/_doc/{video_id}"
- data = None
- look_up = SearchHandler(url, data)
+ look_up = SearchHandler(url, None)
video_hit = look_up.get_data()
video_data = video_hit[0]["source"]
try:
@@ -614,6 +613,7 @@ class VideoView(View):
"playlist_nav": playlist_nav,
"title": video_title,
"colors": colors,
+ "cast": cast,
}
return render(request, "home/video.html", context)
@@ -635,8 +635,9 @@ class VideoView(View):
"""read config file"""
config_handler = AppConfig(user_id)
es_url = config_handler.config["application"]["es_url"]
+ cast = config_handler.config["application"]["enable_cast"]
colors = config_handler.colors
- return es_url, colors
+ return es_url, colors, cast
@staticmethod
def star_creator(rating):
diff --git a/tubearchivist/static/cast-videos.js b/tubearchivist/static/cast-videos.js
new file mode 100644
index 0000000..1d6c9fd
--- /dev/null
+++ b/tubearchivist/static/cast-videos.js
@@ -0,0 +1,91 @@
+var session = null;
+
+function initializeCastApi() {
+ var applicationID = chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID;
+ var sessionRequest = new chrome.cast.SessionRequest(applicationID);
+ var apiConfig = new chrome.cast.ApiConfig(sessionRequest,
+ sessionListener,
+ receiverListener);
+ chrome.cast.initialize(apiConfig, onInitSuccess, onInitError);
+};
+
+function sessionListener(e) {
+ session = e;
+ console.log('New session');
+ if (session.media.length != 0) {
+ console.log('Found ' + session.media.length + ' sessions.');
+ }
+}
+
+function receiverListener(e) {
+ if( e === 'available' ) {
+ console.log("Chromecast was found on the network.");
+ }
+ else {
+ console.log("There are no Chromecasts available.");
+ }
+}
+
+function onInitSuccess() {
+ console.log("Initialization succeeded");
+}
+
+function onInitError() {
+ console.log("Initialization failed");
+}
+
+function startCast() {
+ console.log("Starting cast...");
+ chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);
+}
+
+function onRequestSessionSuccess(e) {
+ console.log("Successfully created session: " + e.sessionId);
+ session = e;
+}
+
+function onLaunchError() {
+ console.log("Error connecting to the Chromecast.");
+}
+
+function onRequestSessionSuccess(e) {
+ console.log("Successfully created session: " + e.sessionId);
+ session = e;
+ loadMedia();
+}
+
+function loadMedia() {
+ if (!session) {
+ console.log("No session.");
+ return;
+ }
+
+ var videoSrc = document.getElementById("video-item").src;
+ var mediaInfo = new chrome.cast.media.MediaInfo(videoSrc);
+ mediaInfo.contentType = 'video/mp4';
+
+ var request = new chrome.cast.media.LoadRequest(mediaInfo);
+ request.autoplay = true;
+
+ session.loadMedia(request, onLoadSuccess, onLoadError);
+}
+
+function onLoadSuccess() {
+ console.log('Successfully loaded video.');
+}
+
+function onLoadError() {
+ console.log('Failed to load video.');
+}
+
+function stopCast() {
+ session.stop(onStopCastSuccess, onStopCastError);
+}
+
+function onStopCastSuccess() {
+ console.log('Successfully stopped casting.');
+}
+
+function onStopCastError() {
+ console.log('Error stopping cast.');
+}