Quellcode durchsuchen

Merge pull request #640 from singulart/tooling/video-bot

Adopted Giza testnet Query node API changes
mochet vor 3 Jahren
Ursprung
Commit
75380719a3

+ 3 - 2
scripts/joystreamvideobot/config.ts

@@ -1,6 +1,7 @@
-export const channelId = "851363091543097364";
-export const hydraLocation = "https://hydra.joystream.org/graphql";
+export const channelId = "938526399801729024";
+export const hydraLocation = "https://orion.joystream.org/graphql";
 export const waitFor = 60;
 export const waitTimeUnit = 'seconds';
 export const createdAgo = 30;
 export const createdAgoUnit = 'minutes';
+export const storageServer = 'https://storage-1.joystream.org/argus/api/v1/assets/'

+ 11 - 13
scripts/joystreamvideobot/src/bot.ts

@@ -1,4 +1,4 @@
-import { channelId, hydraLocation, waitFor, waitTimeUnit, createdAgo, createdAgoUnit } from "../config";
+import { channelId, hydraLocation, waitFor, waitTimeUnit, createdAgo, createdAgoUnit, storageServer } from "../config";
 import { readFileSync } from 'fs';
 import axios from 'axios';
 import {IVideoResponse, LooseObject}  from './types';
@@ -37,13 +37,13 @@ const main = async () => {
     console.log(`Checking for new videos uploaded since ${formattedDate}`);
 
     await axios
-      .post(hydraLocation, httpRequestBody.replace('__DATE_AFTER__', formattedDate), {headers: {'Content-Type': 'application/json'}})
+      .post(hydraLocation, JSON.parse(httpRequestBody.replace('__DATE_AFTER__', formattedDate)))
       .then((res: any) => {
         let response: IVideoResponse = <IVideoResponse>res.data;
         if(response.data.videosConnection) {
           console.log(`${response.data.videosConnection.edges.length} new videos uploaded`)
           for (let edge of response.data.videosConnection.edges) {   
-            if (!edge.node.thumbnailPhotoDataObject) {
+            if (!edge.node.thumbnailPhoto) {
               continue; // metadata for this video is not yet ready. Video will be announced in next iterations.
             }
             if (lookup(ids, edge.node.id)) {
@@ -61,23 +61,20 @@ const main = async () => {
                   { name: 'Category', value: edge.node.category.name, inline: true},
                   { name: 'Duration', value: durationFormat(edge.node.duration), inline: true },
                   { name: 'Language', value: edge.node.language.iso, inline: true },
-                  { name: 'Size', value: humanFileSize(edge.node.mediaDataObject.size), inline: true },
+                  { name: 'Size', value: humanFileSize(edge.node.media.size), inline: true },
                   { name: 'License', value: licenses[licenseKey], inline: true },
                 )
                 .setTimestamp();
-                const uploaderTitle = `${edge.node.channel.title} (${edge.node.channel.ownerMember.rootAccount})`
-                const avatarObj = edge.node.channel.avatarPhotoDataObject?.liaison
-                if(avatarObj && (avatarObj.metadata.startsWith('http://') || avatarObj.metadata.startsWith('https://'))) {
+                const uploaderTitle = `${edge.node.channel.title} (${edge.node.channel.ownerMember.controllerAccount})`
+                const avatarObj = edge.node.channel.avatarPhoto?.id
+                if(avatarObj) {
                   const avatar = 
-                        `${avatarObj.metadata}asset/v0/${edge.node.channel.avatarPhotoDataObject.joystreamContentId}`;
+                        `${storageServer}/${avatarObj}`;
                   exampleEmbed.setAuthor(uploaderTitle, avatar, `https://play.joystream.org/channel/${edge.node.channel.id}`);
                 } else {
                   exampleEmbed.setAuthor(uploaderTitle, null, `https://play.joystream.org/channel/${edge.node.channel.id}`);
                 }
-                const liaison = edge.node.thumbnailPhotoDataObject?.liaison
-                if(liaison && (liaison.metadata.startsWith('http://') || liaison.metadata.startsWith('https://')) ) {
-                  exampleEmbed.setImage(`${liaison.metadata}asset/v0/${edge.node.thumbnailPhotoDataObject.joystreamContentId}`)
-                }
+                exampleEmbed.setImage(`${storageServer}/${edge.node.thumbnailPhoto.id}`)
               channel.send(exampleEmbed);
               ids.push({id: edge.node.id, createdAt: Date.parse(edge.node.createdAt)});
             }
@@ -86,8 +83,9 @@ const main = async () => {
         }
       })
       .catch((error: any) => {
+        console.log(error)
         const {response} = error
-        console.error(response.data.errors);
+        console.error(response.data);
       });
 
       // waiting... 

+ 5 - 6
scripts/joystreamvideobot/src/types.ts

@@ -19,12 +19,12 @@ export interface INode {
     description: string,
     duration: number,
     id: string,
-    thumbnailPhotoDataObject: IThumb,
+    thumbnailPhoto: IThumb,
     channel: IChannel,
     category: ICategory,
     language: ILanguage,
     license: ILicense,
-    mediaDataObject: IMediaDataObject,
+    media: IMediaDataObject,
     createdAt: string
 }
 
@@ -37,8 +37,7 @@ export interface ILicense {
 }
 
 export interface IThumb {
-    liaison: ILiaison,
-    joystreamContentId: string
+    id: number
 }
 
 export interface ILiaison {
@@ -49,12 +48,12 @@ export interface IChannel {
     title: string,
     id: string,
     ownerMember: IOwnerMember,
-    avatarPhotoDataObject: IThumb,
+    avatarPhoto: IThumb,
     createdById: string;
 }
 
 export interface IOwnerMember {
-    rootAccount: string;
+    controllerAccount: string;
 }
 
 export interface ICategory {

+ 37 - 52
scripts/joystreamvideobot/videos_query.graphql

@@ -1,15 +1,5 @@
-query GetVideosConnection(
-  $first: Int
-  $after: String
-  $_v0_where: VideoWhereInput
-  $_v0_orderBy: [VideoOrderByInput!]
-) {
-  videosConnection(
-    first: $first
-    after: $after
-    where: $_v0_where
-    orderBy: $_v0_orderBy
-  ) {
+query GetVideosConnection($first: Int, $after: String, $_v0_where: VideoWhereInput, $_v0_orderBy: [VideoOrderByInput!]) {
+  videosConnection(first: $first, after: $after, where: $_v0_where, orderBy: $_v0_orderBy) {
     edges {
       cursor
       node {
@@ -27,6 +17,7 @@ query GetVideosConnection(
     __typename
   }
 }
+
 fragment VideoFields on Video {
   id
   title
@@ -36,6 +27,7 @@ fragment VideoFields on Video {
     name
     __typename
   }
+  views
   duration
   createdAt
   isPublic
@@ -52,16 +44,12 @@ fragment VideoFields on Video {
     ...VideoMediaMetadataFields
     __typename
   }
-  mediaUrls
-  mediaAvailability
-  mediaDataObject {
-    ...DataObjectFields
+  media {
+    ...StorageDataObjectFields
     __typename
   }
-  thumbnailPhotoUrls
-  thumbnailPhotoAvailability
-  thumbnailPhotoDataObject {
-    ...DataObjectFields
+  thumbnailPhoto {
+    ...StorageDataObjectFields
     __typename
   }
   channel {
@@ -74,53 +62,50 @@ fragment VideoFields on Video {
   }
   __typename
 }
-fragment LicenseFields on License {
+
+fragment VideoMediaMetadataFields on VideoMediaMetadata {
   id
-  code
-  attribution
-  customText
+  pixelHeight
+  pixelWidth
   __typename
 }
-fragment BasicChannelFields on Channel {
+
+fragment StorageDataObjectFields on StorageDataObject {
   id
-  title
-  ownerMember {
-    rootAccount
-  }
   createdAt
-  createdById
-  avatarPhotoUrls
-  avatarPhotoAvailability
-  avatarPhotoDataObject {
-    ...DataObjectFields
+  size
+  isAccepted
+  ipfsHash
+  storageBag {
+    id
+    __typename
+  }
+  type {
     __typename
   }
   __typename
 }
-fragment DataObjectFields on DataObject {
+
+fragment BasicChannelFields on Channel {
   id
+  title
   createdAt
-  size
-  liaison {
-    ...BasicWorkerFields
+  views
+  follows
+  avatarPhoto {
+    ...StorageDataObjectFields
     __typename
   }
-  liaisonJudgement
-  ipfsContentId
-  joystreamContentId
-  __typename
-}
-fragment BasicWorkerFields on Worker {
-  id
-  workerId
-  metadata
-  isActive
-  type
+  ownerMember {
+    controllerAccount
+  }  
   __typename
 }
-fragment VideoMediaMetadataFields on VideoMediaMetadata {
+
+fragment LicenseFields on License {
   id
-  pixelHeight
-  pixelWidth
+  code
+  attribution
+  customText
   __typename
 }