Example #1
0
def thead_list(play_list_id):
    play = PlayList.get_by_id(play_list_id)
    while True:
        first_video = play.videos\
            .where(Video.is_progress == 0) \
            .where(Video.is_completed == 0) \
            .first()

        if first_video is None:
            break
        updated = Video.update(is_progress=1) \
            .where(Video.is_progress == 0) \
            .where(Video.id == first_video.id).execute()
        if updated == 1:
            client = Bilibili()
            client.download_by_id(first_video.id)
            Video.update(is_completed=True).where(
                Video.id == first_video.id).execute()
Example #2
0
 def get_url(self, cid, filename, path):
     """获取每个链接并下载"""
     html = self.get_response_by_cid(cid=cid)
     print(html)
     video_list = []
     if len(html['durl']) == 1:
         # 如果只有一个链接,则表示单视频
         print(html['durl'][0])
         Video.update(size=html['durl'][0]['size']).where(
             Video.cid == cid).execute()
         self.download(html['durl'][0]['url'],
                       path + '/' + filename + '.mp4', self.next_headers)
     else:
         # 否则是列表
         temps = []
         for i in html['durl']:
             print(i)
             exit()
             temp = path + '/' + filename + '.tmp'
             temps.append(temp)
             self.download(i['url'], temp, self.next_headers)
     return video_list
Example #3
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)
Example #4
0
def thead(video_id):
    client = Bilibili()
    client.download_by_id(video_id)
    Video.update(is_completed=True).where(Video.id == video_id).execute()