예제 #1
0
def admin():
    if request.method == "GET":
        videos = Video.objects()
        return render_template('admin.html', videos = videos)

    elif request.method == "POST":
        form = request.form
        link = form['link']

        ydl = YoutubeDL()

        data = ydl.extract_info(link, download = False)

        title = data['title']
        thumbnail = data['thumbnail']
        views = data ['view_count']
        youtube_id = data['id']

        video = Video(title = title,
                    thumbnail = thumbnail,
                    views = views,
                    youtube_id = youtube_id,
                    link = link)
        video.save()
        return redirect(url_for("admin"))
예제 #2
0
def doCron(videos):
    raw_data = http.getHttp("https://gdata.youtube.com/feeds/api/standardfeeds/on_the_web")
    soup = BeautifulSoup(raw_data, selfClosingTags=['category'])
    entries=soup.findAll('entry')
    for entry in entries:
        if len(entry('title'))>0:
            mykey=entry('title')[0].text if len(entry('title'))>0 else None
            if mykey and not getVideo(videos, mykey):
                video=Video()
                video.title=entry('title')[0].text
                video.mykey=mykey
                video.text=entry('content')[0].text if len(entry('content'))>0 else ''
                links=entry(lambda tag: tag.name=='link' and tag.attrs[2][0]=='href' and '/watch?' in tag.attrs[2][1])
                if len(links)==0:
                    continue
                video.link=links[0].attrs[2][1]
                imgs=entry('media:thumbnail',  height="90", width="120")
                if len(imgs)==0:
                    continue
                video.img=imgs[0].attrs[0][1] 
                imgsBig=entry('media:thumbnail',  height='360', width='480')
                if len(imgsBig)==0:
                    continue
                video.imgBig=imgsBig[0].attrs[0][1]
                video.tags=getTags(entry)
                video.categories=getCategories(entry)
                video.save();
def admin():
    if 'logged_in' in session:
        if request.method == 'GET':
            all_video = Video.objects()
            return render_template('admin.html', all_video=all_video)
        elif request.method == 'POST':
            form = request.form
            link = form['link']
            ydl = YoutubeDL()
            data = ydl.extract_info(link, download=False)

            new_video = Video(title=data['title'],
                              thumbnail=data['thumbnail'],
                              view=data['view_count'],
                              youtubeid=data['id'])
            new_video.save()
            return redirect(url_for('admin'))
    else:
        return "Đi chỗ khác chơi"
예제 #4
0
def admin():
    if request.method == 'GET':
        if "logged_in" in session:
            videos = Video.objects()
            return render_template('admin.html', videos=videos)
        else:
            return render_template("error.html")
    elif request.method == 'POST':
        form = request.form
        link = form['link']
        data = ydl.extract_info(link, download=False)
        title = data['title']
        thumbnail = data['thumbnail']
        views = data['view_count']
        youtubeid = data['id']
        new_video = Video(title=title,
                          thumbnail=thumbnail,
                          views=views,
                          link=link,
                          youtubeid=youtubeid)
        new_video.save()

        return redirect(url_for('admin'))