@@ -246,6 +246,8 @@ def explore(self):
246
246
return self ._sendrequest ('discover/explore/' )
247
247
248
248
def expose (self ):
249
+ # TODO: This might be deprecated.
250
+ # http://instagram-private-api.readthedocs.io/en/latest/_modules/instagram_private_api/endpoints/misc.html
249
251
data = json .dumps ({
250
252
'_uuid' : self ._uuid ,
251
253
'_uid' : self ._loggedinuserid ,
@@ -282,8 +284,9 @@ def get_hashtag_feed(self, hashtagString, maxid=''):
282
284
'feed/tag/' + hashtagString + '/?max_id=' + str (maxid ) +
283
285
'&rank_token=' + self ._ranktoken + '&ranked_content=true&' )
284
286
285
- def get_liked_media (self , maxid = '' ):
286
- return self ._sendrequest ('feed/liked/?max_id=' + str (maxid ))
287
+ def get_liked_media (self , maxid = None ):
288
+ max_id_param = '?max_id=' + str (maxid ) if maxid else ""
289
+ return self ._sendrequest ('feed/liked/' + max_id_param )
287
290
288
291
def get_location_feed (self , locationId , maxid = '' ):
289
292
return self ._sendrequest (
@@ -516,17 +519,20 @@ def unlike(self, mediaId):
516
519
def upload_photo (self , photo , caption = None , upload_id = None ):
517
520
if upload_id is None :
518
521
upload_id = str (int (time .time () * 1000 ))
519
- data = {
520
- 'upload_id' : upload_id ,
521
- '_uuid' : self ._uuid ,
522
- '_csrftoken' : self ._csrftoken ,
523
- 'image_compression' : '{"lib_name":"jt","lib_version":"1.3.0","quality":"87"}' ,
524
- 'photo' : (
525
- 'pending_media_%s.jpg' % upload_id ,
526
- open (photo , 'rb' ),
527
- 'application/octet-stream' ,
528
- {'Content-Transfer-Encoding' : 'binary' })
529
- }
522
+
523
+ with open (photo , 'rb' ) as photo_file :
524
+ data = {
525
+ 'upload_id' : upload_id ,
526
+ '_uuid' : self ._uuid ,
527
+ '_csrftoken' : self ._csrftoken ,
528
+ 'image_compression' : '{"lib_name":"jt","lib_version":"1.3.0","quality":"87"}' ,
529
+ 'photo' : (
530
+ 'pending_media_%s.jpg' % upload_id ,
531
+ photo_file .read (),
532
+ 'application/octet-stream' ,
533
+ {'Content-Transfer-Encoding' : 'binary' })
534
+ }
535
+
530
536
m = MultipartEncoder (data , boundary = self ._uuid )
531
537
headers = {
532
538
'X-IG-Capabilities' : '3Q4=' ,
@@ -537,6 +543,8 @@ def upload_photo(self, photo, caption=None, upload_id=None):
537
543
'Content-type' : m .content_type ,
538
544
'Connection' : 'close' ,
539
545
'User-Agent' : self .USER_AGENT }
546
+ self ._sendrequest ("upload/photo/" , post = m .to_string (), headers = headers )
547
+
540
548
self ._session .post (self .API_URL + "upload/photo/" ,
541
549
data = m .to_string (), headers = headers )
542
550
if self .configure (upload_id , photo , caption ):
@@ -571,8 +579,8 @@ def upload_video(self, video, thumbnail, caption=None, upload_id=None):
571
579
upload_url = body ['video_upload_urls' ][3 ]['url' ]
572
580
upload_job = body ['video_upload_urls' ][3 ]['job' ]
573
581
574
- video_data = open (video , 'rb' ). read ()
575
- # solve issue #85 TypeError: slice indices must be integers or None or have an __index__ method
582
+ with open (video , 'rb' ) as videofile :
583
+ videoData = videofile . read ()
576
584
request_size = int (math .floor (len (video_data ) / 4 ))
577
585
last_request_extra = (len (video_data ) - (request_size * 3 ))
578
586
@@ -602,13 +610,17 @@ def upload_video(self, video, thumbnail, caption=None, upload_id=None):
602
610
603
611
self ._session .headers .update (
604
612
{'Content-Length' : str (end - start ), 'Content-Range' : content_range , })
613
+ LOGGER .info ("Starting to upload %d bytes of video data" , len (video_data ))
605
614
response = self ._session .post (
606
615
upload_url , data = video_data [start :start + length ])
607
616
self ._session .headers = headers
608
617
609
618
if response .status_code == 200 :
610
619
if self .configure_video (upload_id , video , thumbnail , caption ):
620
+ LOGGER .info ("Video configuration complete. Exposing." )
611
621
self .expose ()
622
+ LOGGER .info ("Video upload complete." )
623
+
612
624
return False
613
625
614
626
def user_friendship (self , userId ):
0 commit comments