Skip to content

Commit

Permalink
feat: consider quality setting
Browse files Browse the repository at this point in the history
  • Loading branch information
pinbraerts committed Jan 8, 2025
1 parent 23f58d9 commit 7a2d1d3
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,18 @@ const NasaApodIndicator = GObject.registerClass({
_parseData(json) {
let parsed = JSON.parse(json);

const resolution_setting = this._network_monitor.get_network_metered()
? 'image-resolution-metered'
: 'image-resolution'
;
const use_hd = this._settings.get_string(resolution_setting) === 'hd';

if (parsed['media_type'] === 'video' && this._settings.get_boolean('use-thumbnail') ) {
const match = parsed['url'].match(/\/embed\/([a-zA-Z0-9_-]+)/);
if (match) {
const video_id = match[1];
parsed['url'] = `https://i.ytimg.com/vi/${video_id}/maxresdefault.jpg`;
const thumbnail_resolution = use_hd ? 'maxres' : 'hq';
parsed['url'] = `https://i.ytimg.com/vi/${video_id}/${thumbnail_resolution}default.jpg`;
parsed['media_type'] = 'image';
Utils.ext_log(`Replaced video (id=${video_id}) with thumbnail: ${parsed['url']}`);
}
Expand All @@ -448,13 +455,8 @@ const NasaApodIndicator = GObject.registerClass({
let filename = GLib.build_filenamev([NasaApodDir, `${date}-${title}.${extension}`]);

let url = parsed['url'];
if ('hdurl' in parsed) {
if (this._network_monitor.get_network_metered()) {
if (this._settings.get_string('image-resolution-metered') === 'hd')
url = parsed['hdurl'];
} else if (this._settings.get_string('image-resolution') === 'hd') {
url = parsed['hdurl'];
}
if (use_hd && 'hdurl' in parsed) {
url = parsed['hdurl'];
}
this.data = {
'title': parsed['title'],
Expand Down

0 comments on commit 7a2d1d3

Please sign in to comment.