Skip to content

Commit

Permalink
Override display/order/etc values per path
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikescher committed Sep 28, 2020
1 parent 6f02d0e commit bf88f77
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 13 deletions.
25 changes: 21 additions & 4 deletions DataDirSpec.cs
Expand Up @@ -13,7 +13,12 @@ public class DataDirSpec
public readonly int RecursionDepth;
public readonly string FilenameFilter;
public readonly string OrderFilename;
public readonly string HTMLTitle;
public readonly string HTMLTitle;

public readonly int? DisplayOverride;
public readonly int? WidthOverride;
public readonly int? OrderOverride;
public readonly int? VideomodeOverride;

public string FullOrderFilename
{
Expand All @@ -24,7 +29,9 @@ public string FullOrderFilename
}
}

public DataDirSpec(string path, string name, bool useFilenameAsTitle, int recursionDepth, string filenameFilter, string orderFilename, string htmltitle)
public DataDirSpec(string path, string name,
bool useFilenameAsTitle, int recursionDepth, string filenameFilter, string orderFilename, string htmltitle,
int? display_override, int? width_override, int? order_override, int? videomode_override)
{
Path = path;
Name = name;
Expand All @@ -33,6 +40,11 @@ public DataDirSpec(string path, string name, bool useFilenameAsTitle, int recurs
FilenameFilter = filenameFilter;
OrderFilename = orderFilename;
HTMLTitle = htmltitle;

DisplayOverride = display_override;
WidthOverride = width_override;
OrderOverride = order_override;
VideomodeOverride = videomode_override;
}

public static DataDirSpec Parse(string spec)
Expand All @@ -53,16 +65,21 @@ public static DataDirSpec Parse(string spec)
var filter = json.Value<string>("filter") ?? "*";

var order = json.GetValue("ext_order")?.Value<string>();

var ovr_display = json.GetValue("display")?.Value<int>();
var ovr_width = json.GetValue("width")?.Value<int>();
var ovr_order = json.GetValue("order")?.Value<int>();
var ovr_videomode = json.GetValue("videomode")?.Value<int>();

var htmltitle = json.GetValue("htmltitle")?.Value<string>();
if (htmltitle != null) htmltitle = htmltitle.Replace("{version}", Program.Version);

return new DataDirSpec(path, name, useFilename, recDepth, filter, order, htmltitle);
return new DataDirSpec(path, name, useFilename, recDepth, filter, order, htmltitle, ovr_display, ovr_width, ovr_order, ovr_videomode);
}

public static DataDirSpec FromPath(string dir)
{
return new DataDirSpec(dir, dir, false, 0, "*", null, null);
return new DataDirSpec(dir, dir, false, 0, "*", null, null, null, null, null, null);
}
}
}
7 changes: 6 additions & 1 deletion Jobs/Impl/DataCollectJob.cs
Expand Up @@ -326,7 +326,12 @@ protected override void Run()
new JProperty("has_ext_order", orderIndizes != null),
new JProperty("count_total", filesInfo.Count + filesVideo.Count),
new JProperty("count_info", filesInfo.Count),
new JProperty("count_raw", filesVideo.Count)
new JProperty("count_raw", filesVideo.Count),

new JProperty("display_override", ddir.DisplayOverride),
new JProperty("width_override", ddir.WidthOverride),
new JProperty("order_override", ddir.OrderOverride),
new JProperty("videomode_override", ddir.VideomodeOverride)
)),
new JProperty("videos", resultVideos),
new JProperty("missing", new JArray(datafiles.Except(processedFiles).ToArray<object>()))
Expand Down
2 changes: 1 addition & 1 deletion Program.cs
Expand Up @@ -26,7 +26,7 @@ public static class Program

public static Timer CronTimer;

public static string Version => "0.20";
public static string Version => "0.21";

// DataCache := Dictionary< DataDirIndex => (json, obj) >
// json := full json for dir, aka: { "videos": [ ... ], "missing": [ ... ] }
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -220,7 +220,7 @@ Load the currently visible thumbnails in parallel *and* pre-load non-visible thu
By specifying one (or more) `--path` arguments you can set the directori(es) where the program looks for video files.
But instead of a simple directory-path you can also supply a json object in the `--path` argument for more fine-tuning, eg: `--path="{path:'/home/me/videos', name:'My Videos'}"`.

Every path json object *must* have a `path` property, and can have the following optional peroperties:
Every path json object *must* have a `path` property, and can have the following optional properties:
- `name`: The display string, used eg in the top-left dropwdown menu. (default = use value of `path`)
- `use_filename_as_title`: Use the filename as the video title instead of value in the info.json file (default = **false**)
- `recursion`: The maximum recursion depth when searching for videos (default = 0, aka "do not recurse into subfolders")
Expand All @@ -230,6 +230,10 @@ Every path json object *must* have a `path` property, and can have the following
If some files are not found in the file they are appended at the end (This can useful in combination with the background autorefresh feature).
(!) You *can* simply use the youtube-dl archive file here, but be aware that ytdl-viewer can edit the file and youtube-dl does not guarantee any order in the file.
- `htmltitle`: Specify a custom title for the webpage when this path is selected
- `display`: Override the default display value (from `--display=<v>`) for this path
- `width`: Override the default display value (from `--width=<v>`) for this path
- `order`: Override the default order (from `--order=<v>`) for this path
- `videomode`: Override the default playback mode (from `--videomode=<v>`) for this path

> **[!] Note**
> Under windows (and linux if there are any) do not forget to escape your backslashes:
Expand Down
79 changes: 73 additions & 6 deletions staticfiles/script.js
Expand Up @@ -158,26 +158,93 @@ async function loadDataFromServer(initial)

const json = JSON.parse(DATA.data);

let currentOrder = parseInt($attr('.btn-order', 'data-mode'));
if (!json.meta.has_ext_order)
// OVERRIDE ORDER
{
if (currentOrder === 7 || currentOrder === 8)
let order_updated = false;
let currentOrder = parseInt($attr('.btn-order', 'data-mode'));
if (json.meta.order_override !== null && json.meta.order_override !== currentOrder)
{
currentOrder = parseInt($attr('.btn-order', 'data-initial'));
currentOrder = json.meta.order_override;
$('.btn-order').setAttribute('data-mode', currentOrder.toString());
order_updated = true;
}

if (!json.meta.has_ext_order)
{
order_updated = true;

if (currentOrder === 7 || currentOrder === 8)
{
currentOrder = 0;
currentOrder = parseInt($attr('.btn-order', 'data-initial'));
$('.btn-order').setAttribute('data-mode', currentOrder.toString());
}

if (currentOrder === 7 || currentOrder === 8)
{
currentOrder = 0;
$('.btn-order').setAttribute('data-mode', currentOrder.toString());
}
}
}
if (order_updated)
{
const options = JSON.parse($attr('.btn-order', 'data-options'));
showToast(options[currentOrder]);
updateLocationHash();
}
}

// OVERRIDE DISPLAY
{
let currentDisplay = parseInt($attr('.btn-display', 'data-mode'));
if (json.meta.display_override !== null && json.meta.display_override !== currentDisplay)
{
currentDisplay = json.meta.display_override;
$('.btn-display').setAttribute('data-mode', currentDisplay.toString());

const options = JSON.parse($attr('.btn-display', 'data-options'));
showToast(options[currentDisplay]);
updateLocationHash();

updateDisplaymodeClass(true);

loadThumbnails();
}
}

// OVERRIDE WIDTH
{
let currentWidth = parseInt($attr('.btn-width', 'data-mode'));
if (json.meta.width_override !== null && json.meta.width_override !== currentWidth)
{
currentWidth = json.meta.width_override;
$('.btn-width').setAttribute('data-mode', currentWidth.toString());

const options = JSON.parse($attr('.btn-width', 'data-options'));
showToast(options[currentWidth]);
updateLocationHash();

updateDisplaywidthClass(true);

loadThumbnails();
}
}

// OVERRIDE PLAYBACK
{
let currentVideomode = parseInt($attr('.btn-videomode', 'data-mode'));
if (json.meta.videomode_override !== null && json.meta.videomode_override !== currentVideomode)
{
currentVideomode = json.meta.videomode_override;
$('.btn-videomode').setAttribute('data-mode', currentVideomode.toString());

const options = JSON.parse($attr('.btn-videomode', 'data-options'));
showToast(options[currentVideomode]);
updateLocationHash();

updateVideomodeClass();
}
}

initData(json);
if (initial) initButtons();
if (initial) initEvents();
Expand Down

0 comments on commit bf88f77

Please sign in to comment.