Exemple #1
0
 def download_video(self, video_id):
     self.logger.info('start downloading {0}'.format(video_id))
     cookie = nicopy.login(self.config.get_user(),
                           self.config.get_password())
     video_info = nicopy.get_video_info(video_id)
     video_type = video_info['movie_type']
     flv = nicopy.get_flv(video_id, cookie)
     result = (flv, video_info)
     self.logger.info('finished downloading {0}'.format(video_id))
     return result
Exemple #2
0
    def pull(self):
        if not os.path.exists(self.dot_gazeru):
            self.create_dot_gazeru()
            self.logger.info('create {0}'.format(self.dot_gazeru))

        existed = self.get_existed()
        uploaded_mylist_info = self.get_uploaded_mylist_info()
        # uploaded_mylist_info にあって existed にないものを列挙する
        downloading = {}
        for mylist in uploaded_mylist_info.values():
            creator = self.escape(mylist['creator'])
            mylist_title = self.escape(mylist['title'])
            if creator not in downloading:
                downloading[creator] = {}
            if mylist_title not in downloading[creator]:
                downloading[creator][mylist_title] = []

            for video in mylist['items']:
                video_title = self.escape(video['title'])
                if creator not in existed \
                   or mylist_title not in existed[creator] \
                   or video_title not in [self.remove_extension(video) for video in existed[creator][mylist_title]]:
                    downloading[creator][mylist_title].append(video)

        self.logger.info('downloading {0}'.format(downloading))
        download_directory = self.config.get_directory()
        for creator, mylists in downloading.items():
            for mylist_title, video_infos in mylists.items():
                for video_info in video_infos:
                    print('downloading {0}'.format(video_info['title']))
                    try:
                        video, video_type = self.download_video(
                            video_info['id'])
                        sound, sound_type = self.extract_sound(
                            video, video_type)
                        sound_file_directory = '{0}/{1}/{2}'.format(
                            download_directory, self.escape(creator), self.escape(mylist_title))
                        os.makedirs(sound_file_directory, exist_ok=True)
                        sound_file_path = '{0}/{1}.{2}'.format(
                            sound_file_directory, self.escape(video_info['title']), sound_type)
                        with open(sound_file_path, 'wb') as file:
                            file.write(sound)

                        video_info_detail = nicopy.get_video_info(
                            video_info['id'])
                        self.edit_id3(sound_file_path,
                                      mylist_title,
                                      video_info_detail['user_nickname'],
                                      video_info_detail['title'],
                                      video_info['position'],
                                      requests.get(video_info_detail['thumbnail_url']).content)
                    except nicopy.ResponseFailError:
                        print('{0} is skipped'.format(video_info['title']))
        return downloading
Exemple #3
0
def videoType(vidId):
    return nicopy.get_video_info(vidId)['movie_type']