コード例 #1
0
    def download_by_id(self, video_id):
        video = Video.select().where(Video.id == video_id).first()
        play = PlayList.select().where(
            PlayList.id == video.play_list_id).first()

        print("开始下载" + video.title + ",视频集:" + play.title)
        download_path = Bilibili.download_path + '/' + play.title
        if os.path.exists(download_path) is False:
            os.mkdir(download_path)
        self.get_url(video.cid, video.title, download_path)
コード例 #2
0
def play(play_id):
    play_list = PlayList.select().where(PlayList.id == play_id).first()

    videos = Video.select().where(Video.play_list_id == play_id)
    video_dict = models_to_dict(videos)
    client = Bilibili()
    for video in video_dict:
        file = Bilibili.download_path + '/' + play_list.title + "/" + video[
            'title'] + '.mp4'

        if video['size'] == 0:
            html = client.get_response_by_cid(video['cid'])
            if 'durl' in html.keys() and len(html['durl']) == 1:
                # 如果只有一个链接,则表示单视频
                print(html['durl'][0])
                Video.update(size=html['durl'][0]['size']).where(
                    Video.cid == video['cid']).execute()
            print(html)

        if os.path.exists(file) is True:
            video['file_size'] = os.path.getsize(file)
        else:
            video['file_size'] = 0
    return render_template("play.html", play=play_list, videos=video_dict)