@@ -22,6 +22,7 @@ module.exports = class Instagram
2222 this . timeoutForCounter = 300
2323 this . timeoutForCounterValue = 30000
2424 this . receivePromises = { }
25+ this . searchTypes = [ 'location' , 'hashtag' ]
2526 }
2627
2728 /**
@@ -50,6 +51,7 @@ module.exports = class Instagram
5051
5152 /**
5253 * User followers list
54+ * Bench - 1k followers/1 min
5355 * @param {Int } userId
5456 * @param {String } command
5557 * @param {String } Params
@@ -410,6 +412,7 @@ module.exports = class Instagram
410412 */
411413 getUserMedia ( userId , cursor , mediaCounter )
412414 {
415+ cursor = cursor ? cursor : '0'
413416 mediaCounter = mediaCounter ? mediaCounter : 12
414417 let form = new formData ( )
415418 form . append ( 'q' , 'ig_user(' + userId + ') { media.after(' + cursor + ', ' + mediaCounter + ') {\
@@ -452,4 +455,87 @@ module.exports = class Instagram
452455 body : form
453456 } ) . then ( r => r . text ( ) . then ( t => t ) )
454457 }
458+
459+ /**
460+ * End cursor - t.entry_data.TagPage[0].tag.media.page_info['end_cursor']
461+ * Media(nodes) - t.entry_data.TagPage[0].tag.media['nodes']
462+ * @param {String } searchBy - location, hashtag
463+ * @param {String } q - location id, or hashtag
464+ * @param {String } cursor pagination cursor
465+ * @param {Int } mediaCounter
466+ * @return {Object } Promise
467+ */
468+ searchBy ( searchBy , q , cursor , mediaCounter )
469+ {
470+ if ( this . searchTypes . indexOf ( searchBy ) === false )
471+ throw 'search type ' + searchBy + ' is not found'
472+
473+ //exclusion for hashtag if not cursor
474+ if ( searchBy == 'hashtag' && ! cursor )
475+ {
476+ return fetch ( 'https://www.instagram.com/explore/tags/' + q + '/' ,
477+ {
478+ headers : this . getHeaders ( ) ,
479+ } ) . then ( t => t . text ( ) . then ( r => JSON . parse ( r . match ( / \< s c r i p t t y p e = \" t e x t \/ j a v a s c r i p t \" > w i n d o w \. _ s h a r e d D a t a \= ( .* ) \; < \/ / ) [ 1 ] ) ) )
480+ }
481+
482+ let form = new formData ( )
483+ mediaCounter = mediaCounter ? mediaCounter : 12
484+ form . append ( 'q' , 'ig_' + searchBy + '(' + q + ') { media.after(' + cursor + ', ' + mediaCounter + ') {\
485+ count,\
486+ nodes {\
487+ __typename,\
488+ caption,\
489+ code,\
490+ comments {\
491+ count\
492+ },\
493+ comments_disabled,\
494+ date,\
495+ dimensions {\
496+ height,\
497+ width\
498+ },\
499+ display_src,\
500+ id,\
501+ is_video,\
502+ likes {\
503+ count\
504+ },\
505+ owner {\
506+ id\
507+ },\
508+ thumbnail_src,\
509+ video_views\
510+ },\
511+ page_info\
512+ }\
513+ }' )
514+
515+ form . append ( 'ref' , 'locations::show' )
516+ form . append ( 'query_id' , '' ) //empty
517+
518+
519+ return fetch ( 'https://www.instagram.com/query/' ,
520+ {
521+ headers : this . getHeaders ( ) ,
522+ method : 'post' ,
523+ body : form
524+ } ) . then ( t => t . json ( ) . then ( r => r ) )
525+ }
526+
527+ /**
528+ * Place id path - r.places[0].place.location['pk'], r.places[1].place.location['pk'], ...
529+ * Common search returned locations, hashtags and users
530+ * @param {String } q
531+ * @return {Object } Promise
532+ */
533+ commonSearch ( q , rankToken )
534+ {
535+ rankToken = rankToken ? rankToken : ''
536+ return fetch ( 'https://www.instagram.com/web/search/topsearch/?context=blended&query=' + q + '&rank_token=' + rankToken ,
537+ {
538+ headers : this . getHeaders ( ) // no required
539+ } ) . then ( t => t . json ( ) . then ( r => r ) )
540+ }
455541}
0 commit comments