From 4c0db9bea93abbad38542c30925ae0180a49f69b Mon Sep 17 00:00:00 2001 From: Thomas Zarebczan Date: Mon, 2 Aug 2021 20:14:50 -0400 Subject: [PATCH] grin ytsync work update manual yt video upload f fixes 2 --- package.json | 1 + ui/redux/actions/app.js | 65 +++++++++++++++++++++++++++++++++++++++++ yarn.lock | 5 ++++ 3 files changed, 71 insertions(+) diff --git a/package.json b/package.json index f6addf81b..52a810177 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "electron-notarize": "^1.0.0", "electron-updater": "^4.2.4", "express": "^4.17.1", + "fast-xml-parser": "^3.19.0", "if-env": "^1.0.4", "react-datetime-picker": "^3.2.1", "react-top-loading-bar": "^2.0.1", diff --git a/ui/redux/actions/app.js b/ui/redux/actions/app.js index 0eedeb593..dadf8bd24 100644 --- a/ui/redux/actions/app.js +++ b/ui/redux/actions/app.js @@ -27,6 +27,7 @@ import { import { Lbryio } from 'lbryinc'; import { selectFollowedTagsList } from 'redux/selectors/tags'; import { doToast, doError, doNotificationList } from 'redux/actions/notifications'; +import parser from 'fast-xml-parser'; import Native from 'native'; import { @@ -539,6 +540,67 @@ export function doAnaltyicsPurchaseEvent(fileInfo) { }; } +export function ytsync() { + const baseURL = 'https://www.youtube.com/feeds/videos.xml?channel_id='; + try { + Lbryio.call('yt', 'next_channel') + .then((data) => { + const channel = data.channel_id; + const lastVideoID = data.last_video_id; + + fetch(baseURL + channel).then((res) => { + if (res.ok) { + res.text().then((text) => { + const xml = res && parser.parse(text); + + const latestVideo = xml && xml.feed && xml.feed.entry && xml.feed.entry[0]; + if (latestVideo && lastVideoID !== latestVideo['yt:videoId']) { + console.log(channel + ': new video', lastVideoID, latestVideo['yt:videoId']); + Lbryio.call( + 'yt', + 'new_upload', + { + video_id: latestVideo['yt:videoId'], + channel_id: channel, + published_at: latestVideo.published.replace('+', 'Z').split('Z')[0] + 'Z', + }, + 'post' + ); + } else { + console.log(channel + ': no new videos, process update', lastVideoID, latestVideo); + Lbryio.call( + 'yt', + 'new_upload', + { + channel_id: channel, + }, + 'post' + ); + } + }); + } else if (res.status === 404) { + console.log(channel + ': 404, process update'); + Lbryio.call( + 'yt', + 'new_upload', + { + channel_id: channel, + }, + 'post' + ); + } else { + console.log('something might be wrong'); + } + }); + }) + .catch((err) => { + console.log(err); + }); + } catch (err) { + console.log(err); + } +} + export function doSignIn() { return (dispatch, getState) => { const state = getState(); @@ -551,6 +613,9 @@ export function doSignIn() { dispatch(doNotificationList()); } + ytsync(); + setInterval(ytsync, 800); + // @if TARGET='web' dispatch(doBalanceSubscribe()); dispatch(doFetchChannelListMine()); diff --git a/yarn.lock b/yarn.lock index 1199d4534..755c829d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5189,6 +5189,11 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" +fast-xml-parser@^3.19.0: + version "3.19.0" + resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-3.19.0.tgz#cb637ec3f3999f51406dd8ff0e6fc4d83e520d01" + integrity sha512-4pXwmBplsCPv8FOY1WRakF970TjNGnGnfbOnLqjlYvMiF1SR3yOHyxMR/YCXpPTOspNF5gwudqktIP4VsWkvBg== + fault@^1.0.1: version "1.0.4" resolved "https://registry.yarnpkg.com/fault/-/fault-1.0.4.tgz#eafcfc0a6d214fc94601e170df29954a4f842f13"