Пример #1
0
    def get_video_comments(self):
        logger.info("Fetching data")
        url_response = json.loads(openURL(YOUTUBE_COMMENT_URL, self.params))
        nextPageToken = url_response.get("nextPageToken")
        try:
            if "error" in url_response:
                logger.error(f"{url_response['error']['message']}")
                raise Exception("The request cannot be completed!")
        except Exception as e:
            logger.error(e)
            return False
        self.load_comments(url_response)

        if nextPageToken:
            logger.info("Found paginated response")
            logger.info("Fetching paginated response & parsing")
            while nextPageToken:
                self.params.update({"pageToken": nextPageToken})
                url_response = json.loads(
                    openURL(YOUTUBE_COMMENT_URL, self.params))
                nextPageToken = url_response.get("nextPageToken")
                self.load_comments(url_response)
        logger.info(f"Saving data as CSV at {self.save_path}")
        self.save_data()
        logger.info("Saved data successfully")
    def get_channel_videos(self):
        url_response = json.loads(openURL(YOUTUBE_SEARCH_URL, self.params))
        nextPageToken = url_response.get("nextPageToken")
        self.load_search_res(url_response)

        while nextPageToken:
            self.params.update({'pageToken': nextPageToken})
            url_response = json.loads(openURL(YOUTUBE_SEARCH_URL, self.params))
            nextPageToken = url_response.get("nextPageToken")
            self.load_search_res(url_response)
        self.create_df()
    def get_video_comments(self):
        url_response = json.loads(openURL(YOUTUBE_COMMENT_URL, self.params))
        nextPageToken = url_response.get("nextPageToken")
        self.load_comments(url_response)

        while nextPageToken:
            self.params.update({'pageToken': nextPageToken})
            url_response = json.loads(openURL(YOUTUBE_COMMENT_URL,
                                              self.params))
            nextPageToken = url_response.get("nextPageToken")
            self.load_comments(url_response)
        self.create_df()
    def get_video_comments(self):
        url_response = json.loads(
            openURL("https://www.googleapis.com/youtube/v3/commentThreads",
                    self.commentParams))
        nextPageToken = url_response.get("nextPageToken")
        self.load_comments(url_response)

        while nextPageToken:
            self.commentParams.update({'pageToken': nextPageToken})
            url_response = json.loads(
                openURL("https://www.googleapis.com/youtube/v3/commentThreads",
                        self.commentParams))
            nextPageToken = url_response.get("nextPageToken")
            self.load_comments(url_response)
        self.get_video_metadata()
    def get_video_metadata(self):
        url_response = json.loads(
            openURL("https://www.googleapis.com/youtube/v3/videos",
                    self.metaDataParams))
        nextPageToken = url_response.get("nextPageToken")
        self.load_metadata(url_response)

        while nextPageToken:
            self.metaDataParams.update({'pageToken': nextPageToken})
            url_response = json.loads(
                openURL("https://www.googleapis.com/youtube/v3/videos",
                        self.metaDataParams))
            nextPageToken = url_response.get("nextPageToken")
            self.load_metadata(url_response)
        self.create_final_df()
 def get_video_comments(self):
     commentPage = 0 
     url_response = json.loads(openURL(YOUTUBE_COMMENT_URL, self.params))
     nextPageToken = url_response.get("nextPageToken")
     next_move = self.load_comments(url_response,commentPage)
     commentPage += 1
     if (commentPage > (commentMaxPages - 1)):
         while nextPageToken:
             self.params.update({'pageToken': nextPageToken})
             url_response = json.loads(openURL(YOUTUBE_COMMENT_URL, self.params))
             nextPageToken = url_response.get("nextPageToken")
             next_move = self.load_comments(url_response, commentPage)
             commentPage += 1
             if (commentPage > (commentMaxPages - 1)):
                 break
     return (next_move)
    def get_video_replies(self, parentid):
        self.repliesParams = {
            'part': 'snippet',
            'maxResults': 100,
            'parentId': parentid,
            'textFormat': 'plainText',
            'key': self.key
        }
        url_response = json.loads(
            openURL("https://www.googleapis.com/youtube/v3/comments",
                    self.repliesParams))
        nextPageToken = url_response.get("nextPageToken")
        self.load_replies(url_response)

        while nextPageToken:
            self.metaDataParams.update({'pageToken': nextPageToken})
            url_response = json.loads(
                openURL("https://www.googleapis.com/youtube/v3/comments",
                        self.repliesParams))
            nextPageToken = url_response.get("nextPageToken")
            self.load_replies(url_response)