Improve debug messages for file operations

This commit is contained in:
Rafał Dzięgiel
2021-04-01 20:20:42 +02:00
parent d04297620b
commit 295af9fd24
2 changed files with 22 additions and 8 deletions

View File

@@ -14,6 +14,8 @@ function generateDash(info)
) )
return null; return null;
debug('generating dash');
/* TODO: Options in prefs to set preferred video formats for adaptive streaming */ /* TODO: Options in prefs to set preferred video formats for adaptive streaming */
const videoStream = info.streamingData.adaptiveFormats.find(stream => { const videoStream = info.streamingData.adaptiveFormats.find(stream => {
return (stream.mimeType.startsWith('video/mp4') && stream.quality === 'hd1080'); return (stream.mimeType.startsWith('video/mp4') && stream.quality === 'hd1080');
@@ -27,7 +29,7 @@ function generateDash(info)
const bufferSec = Math.min(4, info.videoDetails.lengthSeconds); const bufferSec = Math.min(4, info.videoDetails.lengthSeconds);
return [ const dash = [
`<?xml version="1.0" encoding="UTF-8"?>`, `<?xml version="1.0" encoding="UTF-8"?>`,
`<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"`, `<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"`,
` xmlns="urn:mpeg:dash:schema:mpd:2011"`, ` xmlns="urn:mpeg:dash:schema:mpd:2011"`,
@@ -42,6 +44,10 @@ function generateDash(info)
` </Period>`, ` </Period>`,
`</MPD>` `</MPD>`
].join('\n'); ].join('\n');
debug('dash generated');
return dash;
} }
function saveDashPromise(dash) function saveDashPromise(dash)

View File

@@ -284,6 +284,8 @@ var YouTubeClient = GObject.registerClass({
this.emit('info-resolved', true); this.emit('info-resolved', true);
this.downloadingVideoId = null; this.downloadingVideoId = null;
debug('video info is ready to use');
return resolve(info); return resolve(info);
} }
@@ -643,11 +645,14 @@ var YouTubeClient = GObject.registerClass({
async _createSubdirFileAsync(place, folderName, fileName, data) async _createSubdirFileAsync(place, folderName, fileName, data)
{ {
const destDir = Gio.File.new_for_path([ const destPath = [
GLib[`get_${place}_dir`](), GLib[`get_${place}_dir`](),
Misc.appId, Misc.appId,
folderName folderName
].join('/')); ].join('/');
const destDir = Gio.File.new_for_path(destPath);
debug(`saving file: ${destPath}`);
for(let dir of [destDir.get_parent(), destDir]) { for(let dir of [destDir.get_parent(), destDir]) {
const createdDir = await FileOps.createDirPromise(dir).catch(debug); const createdDir = await FileOps.createDirPromise(dir).catch(debug);
@@ -662,21 +667,22 @@ var YouTubeClient = GObject.registerClass({
Gio.FileCreateFlags.NONE, Gio.FileCreateFlags.NONE,
null null
) )
.then(() => debug(`saved file: ${destFile.get_path()}`)) .then(() => debug(`saved file: ${destPath}`))
.catch(debug); .catch(debug);
} }
_getFileContentsPromise(place, folderName, fileName) _getFileContentsPromise(place, folderName, fileName)
{ {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
debug(`reading data from ${place} file`); const destPath = [
const file = Gio.File.new_for_path([
GLib[`get_${place}_dir`](), GLib[`get_${place}_dir`](),
Misc.appId, Misc.appId,
folderName, folderName,
fileName fileName
].join('/')); ].join('/');
const file = Gio.File.new_for_path(destPath);
debug(`reading data from: ${destPath}`);
if(!file.query_exists(null)) { if(!file.query_exists(null)) {
debug(`no such file: ${file.get_path()}`); debug(`no such file: ${file.get_path()}`);
@@ -689,6 +695,8 @@ var YouTubeClient = GObject.registerClass({
if(!data || !data.length) if(!data || !data.length)
return reject(new Error('source file is empty')); return reject(new Error('source file is empty'));
debug(`read data from: ${destPath}`);
if(data instanceof Uint8Array) if(data instanceof Uint8Array)
resolve(ByteArray.toString(data)); resolve(ByteArray.toString(data));
else else