コード例 #1
0
def admin():
    if "loggedin" in session:
        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']
            youtubeid = data['id']

            new_video = Video(title=title,
                              thumbnail=thumbnail,
                              views=views,
                              youtubeid=youtubeid,
                              link=link)
            new_video.save()

            return redirect(url_for('admin'))
    else:
        return "Yêu cầu đăng nhập !!!"
コード例 #2
0
def admin():
    if "loggedin" in session:

        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"]
            new_video = Video(title=title,
                              thumbnail=thumbnail,
                              views=views,
                              link=link,
                              youtube_id=youtube_id)
            new_video.save()

            return redirect(url_for("admin"))
    else:
        return redirect(url_for("login"))
コード例 #3
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")
    else:
        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"]
        link = data["webpage_url"]
        youtubeid = data["id"]

        new_video = Video(title=title,
                          thumbnail=thumbnail,
                          views=views,
                          link=link,
                          youtubeid=youtubeid)
        new_video.save()

        return render_template("admin.html")
コード例 #4
0
ファイル: app.py プロジェクト: dinhtienn/C4E20
def admin():
    if "loggedin" in session:
        if session['loggedin'] == True:
            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']
                views = data['view_count']
                thumbnail = data['thumbnail']
                youtube_id = data['id']

                video = Video(title=title,
                              views=views,
                              thumbnail=thumbnail,
                              youtube_id=youtube_id,
                              link=link)

                video.save()

                return redirect(url_for('admin'))
        else:
            return "Đăng nhập chưa mà đòi"
    else:
        return "Đăng nhập chưa mà đòi"
コード例 #5
0
ファイル: app.py プロジェクト: manhmeu1211/Web
def admin():
    if "loggedin" in session:
        if request.method =="GET":
            videos = Video.objects()
            print(videos)
            return render_template('admin.html', videos = videos)
        elif request.method =="POST":
            form = request.form
            link = form['link']
            ydl_opts = {
                'nocheckcertificate' : True,
            }
            ydl = YoutubeDL()
            data = ydl.extract_info(link, download = False)
            print(data)
            title = data['title']
            thumbnail = data['thumbnail']
            views = data['view_count']
            youtube_id = data['id']
            uploader = data['uploader']
            new_video = Video(  title = title, 
                                thumbnail = thumbnail, 
                                views = views, 
                                link = link, 
                                youtube_id = youtube_id, 
                                uploader = uploader)
            new_video.save()
            return redirect(url_for('admin'))
    else:
        return "Yêu cầu đăng nhập"
コード例 #6
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']
        ydl = YoutubeDL()
        data = ydl.extract_info(link, download=False)
        title = data['title']
        thumbnail = data['thumbnail']
        views = data['view_count']
        link = data['webpage_url']
        youtubeid = data['id']

        new_video = Video(title=title,
                          thumbnail=thumbnail,
                          views=views,
                          link=link,
                          youtubeid=youtubeid)
        new_video.save()
        return redirect(url_for('admin'))
コード例 #7
0
def admin():
    user = session.get('username')
    if user is None:
        return redirect(url_for('login'))
    else:
        total_vegetablesAndFruits = Vegetablesfruits.objects()
        total_animals = Animals.objects()
        total_food = Food.objects()
        total_actions = Actions.objects()
        x = len(total_vegetablesAndFruits)
        y = len(total_animals)
        z = len(total_food)
        if request.method == 'GET':
            videos = Video.objects()
            return render_template(
                "admin.html",
                total_vegetablesAndFruits=total_vegetablesAndFruits,
                total_animals=total_animals,
                total_food=total_food,
                total_actions=total_actions,
                x=x,
                y=y,
                z=z,
                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']
            link = link
            video = Video(
                title=title,
                thumbnail=thumbnail,
                views=views,
                youtube_id=youtube_id,
                link=link,
            )
            video.save()
            return redirect(url_for('admin'))
コード例 #8
0
def index():
    if request.method == 'GET':  #Get de lay du lieu
        return render_template('index.html')
    elif request.method == 'POST': #Post de tao tai nguyen
        isRight = False
        form = request.form
        link = form['link_yt']
        dl = youtube_dl.YoutubeDL()

        # Check link
        ies = youtube_dl.extractor.gen_extractors()
        for ie in ies:
            if ie.suitable(link) and ie.IE_NAME != 'generic':
                isRight = True
        
        if isRight == True:
            try:
                data = dl.extract_info(link, download=False)
                title = data['title']
                views = data['view_count']
                likes = data['like_count']
                dislikes = data['dislike_count']
                youtube_id = data['id']

                video = Video(
                    title=title,
                    views=views,
                    likes=likes,
                    dislikes=dislikes,
                    youtube_id=youtube_id,
                    link=link,
                    time=datetime.now()
                )

                video.save()
                return render_template('index.html', video=video, template=1)
            except Exception as e:
                return render_template('link-fail.html')
        elif isRight == False:
            return render_template('link-fail.html')
コード例 #9
0
def publish_video(video_payload: VideoType, channel_id: str, request: Request,
                  response: Response):

    video = Video()
    video.name = video_payload.name
    video.summary = video_payload.summary
    video.tags = video_payload.tags
    video.path = video_payload.path
    video.filename = video_payload.filename
    video.channel = channel_id

    # Thumbnail
    thumbnail = Photo()
    thumbnail._id = uuid.uuid4()
    thumbnail.path = video_payload.thumbnail.path
    thumbnail.filename = video_payload.thumbnail.filename
    video.thumbnail = thumbnail

    # Save vide
    video.save()

    return {"msg": "publishing videos!"}
コード例 #10
0
def create():
    from main import mongo
    from models.video import Video

    if request.method == 'POST':
        data = request.get_json()

        video = Video(
            data.get('nome'),
            data.get('slug'),
            data.get('data'),
            data.get('url'),
            data.get('categoria_id'),
            data.get('descricao'),
            data.get('hashtags'),
            data.get('metadados'),
            data.get('autores')
        )
        
        video.save()

    return jsonify(video.as_dict())