This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4585a62
commit fdb1890
Showing
20 changed files
with
261 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.1.17' | ||
__version__ = '1.1.18' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import logging | ||
import json | ||
import time | ||
|
||
from bs4 import BeautifulSoup | ||
from json.decoder import JSONDecodeError | ||
|
||
from .. import constants | ||
from .. import actions | ||
|
||
logger = logging.getLogger('__name__') | ||
|
||
|
||
class GetVidSrcUrl(actions.Action): | ||
def __init__(self, scraper, post_id, is_multiple, post_index=0): | ||
super().__init__(scraper) | ||
self.__post_id = post_id | ||
self.__is_multiple = is_multiple | ||
self.__post_index = post_index | ||
|
||
def do(self): | ||
""" Get the video source url """ | ||
|
||
# Open new tab and load the link | ||
link = constants.INSTAGRAM_POST_INFO.format(self.__post_id) | ||
self._web_driver.execute_script("window.open('" + link + "','_blank');") | ||
first_tab_handle = self._web_driver.current_window_handle | ||
|
||
# Switch to the new tab | ||
self._web_driver.switch_to.window(self._web_driver.window_handles[1]) | ||
time.sleep(2) | ||
|
||
# Get data | ||
result = self._scraper.web_driver.page_source | ||
soup = BeautifulSoup(result, 'html.parser') | ||
|
||
# Close the the new tab | ||
self._web_driver.close() | ||
self._web_driver.switch_to.window(first_tab_handle) | ||
time.sleep(2) | ||
|
||
try: | ||
post_info = json.loads(soup.text) | ||
if self.__is_multiple: | ||
vid_url = post_info['graphql']['shortcode_media']['edge_sidecar_to_children']['edges'][ | ||
self.__post_index]['node']['video_url'] | ||
return vid_url | ||
else: | ||
vid_url = post_info['graphql']['shortcode_media']['video_url'] | ||
return vid_url | ||
except (JSONDecodeError, KeyError) as err: | ||
logger.error('Unable to get video source url: %s' % str(err)) | ||
|
||
def on_fail(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.