Browse Source

try to filter videos by length

Mike L 3 years ago
parent
commit
14ed7907cb
2 changed files with 20 additions and 4 deletions
  1. 9 1
      dist/twitter.js
  2. 11 3
      src/twitter.ts

+ 9 - 1
dist/twitter.js

@@ -253,7 +253,15 @@ class default_1 {
                                     if (!fullName && node.accessibility_caption) {
                                         fullName = node.accessibility_caption.replace(/^Photo by (.+) on \w+ \d+, \d+\..*/, '$1');
                                     }
-                                    if (node.__typename === 'GraphVideo' && node.product_type === 'igtv')
+                                    const isVideoTooLong = (info) => {
+                                        let manifest;
+                                        if (info && (manifest = info.video_dash_manifest)) {
+                                            const match = /mediaPresentationDuration="PT(?:(\d+)H)?(?:(\d+)M)?\d+.\d+S"/.exec(manifest);
+                                            return Number(match[1]) > 0 || Number(match[2]) > 10;
+                                        }
+                                        return false;
+                                    };
+                                    if (node.__typename === 'GraphVideo' && isVideoTooLong(node.dash_info))
                                         continue;
                                     if (node.id && utils_1.BigNumOps.compare(node.id, targetId) > 0)
                                         nodes.push(node);

+ 11 - 3
src/twitter.ts

@@ -224,7 +224,7 @@ type IgGraphQLTimelineBaseNode = {
   {__typename: 'GraphSidecar', edge_sidecar_to_children: {
     edges: {node: (IgGraphQLTimelineBaseNode & {__typename: 'GraphImage' | 'GraphVideo'})}[],
   }} |
-  {__typename: 'GraphVideo', video_url: string, product_type?: 'igtv'}
+  {__typename: 'GraphVideo', video_url: string, product_type?: 'igtv', dash_info?: {video_dash_manifest?: string}}
 );
 
 export type IgGraphQLUser = {
@@ -499,8 +499,16 @@ export default class {
                     if (!fullName && node.accessibility_caption) {
                       fullName = node.accessibility_caption.replace(/^Photo by (.+) on \w+ \d+, \d+\..*/, '$1');
                     }
-                    // exclude IGTV
-                    if (node.__typename === 'GraphVideo' && node.product_type === 'igtv') continue;
+                    // exclude long videos
+                    const isVideoTooLong = (info) => {
+                      let manifest: string;
+                      if (info && (manifest = info.video_dash_manifest)) {
+                        const match = /mediaPresentationDuration="PT(?:(\d+)H)?(?:(\d+)M)?\d+.\d+S"/.exec(manifest);
+                        return Number(match[1]) > 0 || Number(match[2]) > 10;
+                      }
+                      return false;
+                    }
+                    if (node.__typename === 'GraphVideo' && isVideoTooLong(node.dash_info)) continue;
                     // add post if ID is greater than target
                     if (node.id && BigNumOps.compare(node.id, targetId) > 0) nodes.push(node);
                     // return of ID is equal to or smaller than target