Esempio n. 1
0
    def test_videos_ordered_by_id(self):
        v1 = Video(embed_url="test1")
        db.session.add(v1)
        db.session.commit()
        v2 = Video(embed_url="test2")
        db.session.add(v2)
        db.session.commit()

        response = self.app.get('/videos')
        v1 = Video.query.get(1)
        v2 = Video.query.get(2)
        v1Index = response.data.find(b'test1')
        v2Index = response.data.find(b'test2')
        self.assertLess(v1Index, v2Index)

        v1.id = -1
        v2.id = -2
        db.session.commit()
        v1.id = 2
        v2.id = 1
        db.session.commit()

        response = self.app.get('/videos')
        v1Index = response.data.find(b'test1')
        v2Index = response.data.find(b'test2')
        self.assertLess(v2Index, v1Index)
Esempio n. 2
0
def handle_video_upload(id):
    vid = request.files['video']
    size = request.form['size']
    if vid:
        content = vid.content_type
        if int(size) < (10 * 1024 * 1024):
            try:
                filename = secure_filename(vid.filename)
                s3.Bucket(BUCKET_NAME).put_object(Body=vid,
                                                  Key=filename,
                                                  ContentType=content,
                                                  ACL='public-read')
                newVideo = Video(
                    content=f'https://bbscouting.s3.amazonaws.com/{filename}',
                    content_type=content,
                    player_id=id)
                db.session.add(newVideo)
                db.session.commit()
                return jsonify({
                    'video_url':
                    f'https://bbscouting.s3.amazonaws.com/{filename}',
                    'type': content
                })
            except:
                return jsonify({'upload': False})
        else:
            try:
                filename = secure_filename(vid.filename)
                s3.Object(BUCKET_NAME,
                          filename).upload_fileobj(vid,
                                                   ExtraArgs={
                                                       'ContentType': content,
                                                       'ACL': 'public-read'
                                                   },
                                                   Config=multi_config)
                newVideo = Video(
                    content=f'https://bbscouting.s3.amazonaws.com/{filename}',
                    content_type=content,
                    player_id=id)
                db.session.add(newVideo)
                db.session.commit()
                return jsonify({
                    'video_url':
                    f'https://bbscouting.s3.amazonaws.com/{filename}',
                    'type': content
                })
            except:
                return jsonify({'upload': False})
Esempio n. 3
0
def postVideoId():

    video_id = request.form['videoid']
    msg = request.form['msg-txt']
    ip = str(get_ip())

    try:
        video = pafy.new(video_id)
    except (OSError, ValueError) as e:
        return jsonify(result='404', error=e)

    post = Video(videoId=video.videoid,
                 length=video.length // 60,
                 message=msg,
                 title=video.title,
                 timestamp=datetime.utcnow())  # add a Post db obj

    # check for user in db
    user = User.query.filter_by(ip=ip).first()

    if user == None or user.ip != ip:  #if user do not exist
        new_user = User(ip=ip)

        db.session.add(new_user)
        new_user.videos.append(post)

    else:  #user already exist in db
        user.videos.append(post)

    db.session.commit()

    return jsonify(result='saved successfully')
Esempio n. 4
0
def subscribe():
    form = SubscribeForm()
    if form.validate_on_submit():
        videos = get_channel_videos(form.channel.data)

        if not videos:
            raise DownloadError('Channel \'{}\' not found'.format(
                form.channel.data))

        channel = Channel(name=videos[0]['uploader_id'],
                          channel_id=videos[0]['channel_id'])
        db.session.add(channel)
        db.session.commit()

        for v in videos:
            if v and 'id' in v:
                video = Video(video_id=v['id'],
                              title=v['title'],
                              channel_id=channel.id,
                              description=v['description'],
                              thumbnail_url=v['thumbnail'],
                              duration=v['duration'],
                              upload_date=datetime.strptime(
                                  v['upload_date'], '%Y%m%d'),
                              view_count=v['view_count'])
                db.session.add(video)
        db.session.commit()

    return redirect('/channels')
Esempio n. 5
0
    def search(name):
        """搜索接口2"""
        logger.info(f'引擎 {__name__} 正在搜索: {name}')
        result = []
        search_api = 'http://service-agbhuggw-1259251677.gz.apigw.tencentcs.com/android/search'
        info_api = 'http://service-agbhuggw-1259251677.gz.apigw.tencentcs.com/android/video/list_ios'

        req = Engine.post(search_api, data={'userid': '', 'key': name})
        if req.status_code != 200 or req.json().get('errorCode') != 0:
            return result
        video_id_list = [int(v['videoId']) for v in req.json().get('data')]  # 搜索结果: 视频 id
        for vid in video_id_list:
            req = Engine.get(info_api, {'userid': '', 'videoId': vid})
            if req.status_code != 200 or req.json().get('errorCode') != 0:
                continue
            info = req.json().get('data')  # 视频详情信息
            video_list = VideoList()
            video_list.engine = __name__
            video_list.title = info['videoName']
            video_list.cover = info['videoImg']
            video_list.desc = info['videoDoc'] or '视频简介弄丢了 (/▽\)'
            video_list.cat = info['videoClass'].split('/')
            logger.info(f"引擎 {__name__} 正在处理: {video_list.title}")
            for video in info['videoSets'][0]['list']:
                name = f"第 {video['ji']} 集"
                video_list.add_video(Video(name, raw_url=video['playid'], handler=PlayIdHandler))  # playid: xxx-x-x
            result.append(video_list)
        return result
Esempio n. 6
0
def upload_video():
    if current_user.email not in current_app.config['ADMINS']:
        flash("You are not authorized to access this page.")
        return redirect(url_for('main.index'))

    form = UploadVideoForm()
    if form.validate_on_submit():
        f = form.upload.data

        if not allowed_video_file(f.filename):
            flash("Invalid file type")
            return redirect(url_for('media.upload_video'))

        filename = secure_filename(f.filename)
        f.save(
            os.path.join(current_app.config['UPLOAD_FOLDER'], 'videos',
                         filename))
        video = Video(title=form.title.data,
                      description=form.description.data,
                      filename=filename)

        db.session.add(video)
        db.session.commit()
        flash("Video uploaded successfully.")
        return redirect(url_for('media.video', video_id=video.id))

    return render_template('media/upload_video.html',
                           title="Upload Video",
                           form=form)
Esempio n. 7
0
 def test_job_zencoder(self):
     self.video = Video(formato = 'webm', file = "%stestes/video_teste.mp4" % settings.MEDIA_URL)
     self.video.save()
     self.job = self.video.schedule_zencoder_job()
     self.assertNotEqual(self.job.body['id'], 0)
     self.assertEqual(self.job.code, 201)
     self.assertEqual(self.job.body['outputs'][0]['url'], "http://nandotorres.s3.amazonaws.com/video_teste.mp4.webm")        
Esempio n. 8
0
def eyewitness():
    form = UploadForm()

    if form.validate_on_submit():

        f = form.upload.data
        if not allowed_video_file(f.filename):
            flash("Invalid file type")
            return redirect(url_for('eyewitness'))

        filename = secure_filename(f.filename)
        f.save(os.path.join(app.config['UPLOAD_FOLDER'], 'video', filename))

        video = Video(title=form.title.data, description=form.description.data, filename=filename, author=current_user)
        db.session.add(video)
        db.session.commit()
        flash("Video successfully uploaded.")
        return redirect(url_for('eyewitness'))

    page = request.args.get('page', 1, type=int)
    videos = current_user.followed_videos().paginate(
        page, app.config['VIDEOS_PER_PAGE'], False)

    next_url = url_for('eyewitness', page=videos.next_num) if videos.has_next else None
    prev_url = url_for('eyewitness', page=videos.prev_num) if videos.has_prev else None

    return render_template('eyewitness.html', title="The Frontlines", form=form, videos=videos.items, next_url=next_url, prev_url=prev_url)
Esempio n. 9
0
def add_video():
    new_video = Video(name=request.form['name'],
                      embed_url=request.form['embedurl'])
    db.session.add(new_video)
    db.session.commit()
    flash('success')
    return redirect(url_for('videos'))
Esempio n. 10
0
def add_video():
    form = AddVideoForm()
    form.classname.choices = [(_classroom.id, _classroom.name)
                              for _classroom in Classroom.query.filter_by(
                                  creator_id=current_user.id).all()]
    if form.validate_on_submit():
        id = db.session.query(func.max(Video.id)).scalar()
        if id is None:
            id = 0
        id += 1
        file_name = 'file' + str(id)
        data = request.files[form.video.name].read()
        open(os.path.join(current_app.config['UPLOAD_PATH'], file_name),
             'wb').write(data)

        classroom = Classroom.query.filter_by(
            id=int(form.classname.data)).first_or_404()
        video = Video(file=file_name,
                      name=form.name.data,
                      creator_id=current_user.id)
        video.classes.append(classroom)

        db.session.add(video)
        db.session.commit()
        flash('Your new video has been saved.')
        return redirect(url_for('main.index'))
    return render_template('video/add_video.html',
                           title='Add Video',
                           form=form)
Esempio n. 11
0
def upload(request):

    feedback = {}  #sera usado para o retorno da acao

    if request.is_ajax() or request.method == 'POST':
        form = VideoForm(request.POST, request.FILES)
        video = Video(file=request.FILES['file'])
        video.formato = request.POST['formato']
        video.save()
        job = video.schedule_zencoder_job()

        if job.code == 201:
            feedback["status"] = "201"
            feedback["job_id"] = job.body['id']
            feedback["video_id"] = video.id
            video.job_id = job.body['id']
            video.save()
        else:
            feedback["status"] = "422"
            feedback["job_id"] = "0"

        return HttpResponse(simplejson.dumps(feedback),
                            mimetype="application/json")
    else:
        form = VideoForm()

    feedback["status"] = "nok"
    feedback["job_id"] = "0"

    return HttpResponse(simplejson.dumps(feedback),
                        mimetype="application/json")
Esempio n. 12
0
def add_video():
    form = VideoForm()
    if form.validate_on_submit():
        video = Video(description=form.description.data, url=form.url.data)
        video.save()
        return redirect(url_for('main.videos'))
    return render_template('admin/add_video.html', form=form)
Esempio n. 13
0
def upload(request):
    if request.method == "POST":
        uf = VideoForm(request.POST, request.FILES)
        if uf.is_valid():  # if valid
            videoname = uf.cleaned_data['videoname']
            Frame = uf.cleaned_data['Frame']
            File = uf.cleaned_data['File']
            # save file
            video = Video()
            video.videoname = videoname
            video.Frame = Frame
            video.File = File
            result = video
            result.save()
            x = requests.post(url,data={"videoname":videoname},files=request.FILES)
            with open(os.path.join("app/static/video", videoname+".mp4"),"wb") as f:
                f.write(x.content)
            with open(os.path.join("app/static/headers", videoname+".json"),"w") as f:
                f.write(json.dumps(dict(x.headers)))
            v = os.path.join("/static/video", videoname+".mp4")
            h = os.path.join("/static/headers", videoname + ".json")
            x={"v":v,"h":h}
            return render_to_response('video.html',x)
    else:
        uf = VideoForm()

    return render_to_response('upload.html',{'uf':uf})
Esempio n. 14
0
    def parserVideo(self):

        url = 'http://v8.ccut.edu.cn/article.php?/%s' % self.v_index
        print url

        try:
            html = urllib2.urlopen(url).read().decode("gb2312")

            patName = re.compile(r'<font class=bigfont><b>(.*)</b>')
            patURL = re.compile(r'href="(.*\.rmvb|.*\.mp4)"')
            patList = re.compile(
                r'<a href="http://v8\.ccut\.edu\.cn/sort\.php\?/\d*">(.*?)</a>'
            )

            resName = re.findall(patName, html)[0]
            resURL = re.findall(patURL, html)[0]
            resList = re.findall(patList, html)

            video = Video(id=self.v_index,
                          title=resName,
                          url=resURL,
                          leve1=resList[0],
                          leve2=resList[1])
            db.session.add(video)
            db.session.commit()

            print("Success save to database --- %s" % resName)
        except Exception, e:
            print("Error:%s" % e)
            db.session.rollback()
            self.v_index += 1

            return
Esempio n. 15
0
def scrape_channel(channel_id):
    for videoId in get_channel_videos(channel_id):
        videoData = get_video_data(videoId)
        video = db.session.query(Video).filter_by(videoId=videoId).first()
        if video:
            pass
        else:
            video = Video(videoId=videoId,
                          title=videoData['title'],
                          channelId=channel_id,
                          publishedAt=videoData['publishedAt'],
                          description=videoData['description'],
                          thumbnail=videoData['thumbnail'])
            db.session.add(video)
            db.session.commit()
            if videoData['tags']:
                for tag in videoData['tags']:
                    video.tags.append(get_or_create_tag(tag))
                    db.session.commit()

        stats = Stats(videoId=video.id,
                      viewCount=videoData['viewCount'],
                      commentCount=videoData['commentCount'],
                      likeCount=videoData['likeCount'],
                      dislikeCount=videoData['dislikeCount'],
                      favoriteCount=videoData['favoriteCount'])
        db.session.add(stats)
        db.session.commit()
Esempio n. 16
0
    def test_adding_video_adds_to_video_page(self):
        v = Video(embed_url="test/embed/test")
        db.session.add(v)
        db.session.commit()

        response = self.app.get('/videos')
        v = Video.query.get(1)
        self.assertIn(bytes(v.embed_url, 'utf-8'), response.data)
Esempio n. 17
0
    def search_one_page(name, page) -> list:
        """处理一页的数据"""
        logger.info(f'引擎 {__name__} 正在搜索: {name} (第 {page} 页)')
        result = []
        search_api = 'http://59.110.16.198/app.php/XyySearch/get_search_data'
        data = {'keyword': name, 'uid': 0, 'page': page, 'type': 1}
        resp = Engine.post(search_api, data)
        if resp.status_code != 200:
            return result
        if resp.text.startswith(u'\ufeff'):  # 解决 UTF-8 BOM 编码的问题
            resp = resp.text.encode('utf8')[3:].decode('utf8')
        resp = json.loads(resp)

        if not resp['data']:
            return result

        for item in resp['data']:
            video_list = VideoList()
            is_rubbish_flag = False  # 有些视频是有问题的,应该抛弃
            if not item['video_lists']:  # 有可能出现视频列表为空的情况
                continue
            video_list.engine = __name__
            video_list.title = item['video_subject'].strip()
            video_list.cover = item['video_image']
            video_list.desc = item['video_describe'] or '视频简介弄丢了 (/▽\)'

            logger.info(f"引擎 {__name__} 正在处理: {video_list.title}")
            if item['video_type']:
                video_list.cat = [
                    cat['video_type_name'] for cat in item['video_type']
                ]
            else:
                video_list.cat = ['默认']
            for video in item['video_lists']:
                url = video['vod_id']  # 有可能出现 URL 有误的情况(迷)
                if not url.startswith('http'):
                    is_rubbish_flag = True  # 有问题的视频,标记起来

                if 'www.iqiyi.com' in url:
                    is_rubbish_flag = True  # 爱奇艺的加密算法太麻烦,暂时不解析
                elif 'youku.com' in url:
                    is_rubbish_flag = True  # 优酷视频,暂时不解析
                elif 'dilidili' in url:
                    is_rubbish_flag = True  # 嘀哩嘀哩已挂

                name = f"第 {video['video_number']} 集"
                video_type = 'mp4'
                handler = None
                if url.endswith('m3u8'):
                    handler = M3U8Handler
                    video_type = 'hls'  # m3u8 格式类型为 hls(播放器要求)
                elif 'bilibili' in url:
                    handler = BilibiliHandler
                    video_type = 'mp4'
                video_list.add(Video(name, url, video_type, handler))
            if not is_rubbish_flag:
                result.append(video_list)
        return result
Esempio n. 18
0
def add_video():
    form = AddVideoForm()
    form.classname.choices = [(_classroom.id, _classroom.name)
                              for _classroom in Classroom.query.filter_by(
                                  creator_id=current_user.id).all()]
    if form.validate_on_submit():
        id = db.session.query(func.max(Video.id)).scalar()
        if id is None:
            id = 0
        id += 1
        file_name = 'file' + str(id)
        data = request.files[form.video.name].read()
        upload_path = os.path.join(current_app.config['UPLOAD_PATH'],
                                   file_name)
        open(upload_path, 'wb').write(data)

        audio_path = os.path.join(current_app.config['AUDIO_PATH'],
                                  'audio.wav')
        command = "ffmpeg -i " + upload_path + " -ab 160k -ac 2 -ar 44100 -vn -y " + audio_path
        subprocess.call(command, shell=True)

        model = current_app.config['model']
        utils = current_app.config['utils']
        device = current_app.config['device']
        args = current_app.config['args']
        predictor = current_app.config['predictor']
        segmenter = current_app.config['segmenter']
        decoder = current_app.config['decoder']
        (read_batch, split_into_batches, read_audio,
         prepare_model_input) = utils

        test_files = glob(audio_path)
        batches = split_into_batches(test_files, batch_size=10)
        input = prepare_model_input(read_batch(batches[0]), device=device)

        output = model(input)
        for example in output:
            data = decoder(example.cpu())
            summary, _ = get_summary(args, data, device, predictor)

        classroom = Classroom.query.filter_by(
            id=int(form.classname.data)).first_or_404()
        video = Video(file=file_name,
                      name=form.name.data,
                      creator_id=current_user.id,
                      original_text=data,
                      summary=summary)
        video.classes.append(classroom)

        db.session.add(video)
        db.session.commit()
        flash('Your new video has been saved.')
        return redirect(url_for('main.index'))
    return render_template('video/add_video.html',
                           title='Add Video',
                           form=form)
Esempio n. 19
0
 def test_ajax_edit_video_details(self):
     db.session.add(Video(name="testvid", embed_url="testurl.com"))
     db.session.commit()
     self.app.post('/update/videos/details',
                   data=dict(oldurl="testurl.com",
                             name="newvid",
                             embedurl="newvidurl.com"))
     v = Video.query.get(1)
     self.assertEqual(v.name, 'newvid')
     self.assertEqual(v.embed_url, 'newvidurl.com')
Esempio n. 20
0
def seed_video(title, thumbnail, channel_id, game_id, created_at, video_path):
    title = title[0:49]
    video = Video(title=title,
                  image_path=thumbnail,
                  channel_id=channel_id,
                  game_id=game_id,
                  created_at=created_at,
                  video_path=video_path)
    db.session.add(video)
    db.session.commit()
Esempio n. 21
0
    def test_video_insertion(self):
        db.session.add(
            Video(file='url/for/my/file.mp4',
                  crop_bool=True,
                  crop_start=datetime.time(10, 10, 10),
                  crop_end=datetime.time(10, 10, 10)))

        db.session.commit()
        video = Video.query.all()
        self.assertEqual(len(video), 1)
Esempio n. 22
0
def add_video(video_name, video_url) -> Video:
    """Function to add video data to database"""

    new_video = Video(name=video_name,
                      url=video_url,
                      fps=cv2.VideoCapture(video_name).get(cv2.CAP_PROP_FPS))

    db.session.add(new_video)
    db.session.commit()

    return new_video
Esempio n. 23
0
def add_video():
    title = request.form["title"]
    genre = request.form["genre"]
    songs = request.form["songs"]
    if not title:
        return "Error"

    video = Video(title=title, genre=genre, songs=songs)
    db.session.add(video)
    db.session.commit()
    return redirect("/")
Esempio n. 24
0
def store_url(id):
    data = request.get_json()
    try:
        url = data['data']['Location']
        content_type = data['type']
        new_media = Video(content=url, content_type=content_type, player_id=id)
        db.session.add(new_media)
        db.session.commit()
        return jsonify({url: url})
    except:
        return jsonify({'imageurl': False})
Esempio n. 25
0
    def setUp(self):
        super(EntryResourceTest, self).setUp()

        self.album1 = Album(title='test_title_1', order_num=1)
        self.album1.save()
        self.album2 = Album(title='test_title_2', order_num=1)
        self.album2.save()

        self.foto1 = Foto(album=self.album1,
                          title='foto1',
                          image='test_image_1.jpg')
        self.foto2 = Foto(album=self.album1,
                          title='foto2',
                          image='test_image_2.jpg')

        self.video1 = Video(album=self.album2,
                            title='video1',
                            video_link='test_video_link2')
        self.video2 = Video(album=self.album2,
                            title='video2',
                            video_link='test_video_link2')
Esempio n. 26
0
def videoinfo(id):
    video = Video.query.filter_by(id=id).first()
    if video is None:
        response = youtube_request(id)
        statistics = parse_statistics(response)
        dislikeCount = statistics.get('dislikeCount')
        likeCount = statistics.get('likeCount')

        video = Video(id=id, likes=likeCount, dislikes=dislikeCount)
        db.session.add(video)
        db.session.commit()
    return f"{video}"
Esempio n. 27
0
def upload_video():
    form = Video_upload_form()
    if request.method == 'POST':
        url = request.form['url']
        title = request.form['title']
        if url and title:
            newFile = Video(url=url, title=title)
            db.session.add(newFile)
            db.session.commit()
            return redirect(url_for('main.upload_mainpage'))
        return redirect(url_for('main.upload_video'))
    return render_template('video.html', form=form)
Esempio n. 28
0
def upload_video():
    if request.method == "UPDATE":
        duration = request.values.get('duration')
        v_id = request.values.get('v_id')
        video = Video.query.get(v_id)
        if video:
            video.duration = duration
            db.session.add(video)
            db.session.commit()
            video.course.update_duration()
            for uv in video.u_videos:
                uv.update_duration()
            return jsonify({
                'resCode': 'ok',
                'msg': '时长更新完毕!'
            })
    file = request.files.get('file')
    c_id = request.values.get('c_id')
    course = Course.query.get_or_404(c_id)
    filename = file.filename
    title = filename.split('.')[0] if isinstance(filename, str) else 'None'
    video = Video(title=title)
    video.course = course
    db.session.add(video)
    db.session.commit()
    v_id = video.id
    base_path = 'app/static/videos/'
    base_name = 'course{}-{}'.format(c_id, v_id)
    _filename = '{}.{}'.format(base_name, filename.split('.')[1])
    path = '/static/videos/' + _filename
    try:
        file.save(base_path + _filename)
        video.video_src = path
        db.session.add(video)

        choices = course.choices.all()
        users = [choice.user for choice in choices]
        for user in users:
            uv = UserVideo.create(user, video)

    except Exception as e:
        print(e)
        db.session.delete(video)

    return jsonify({
        'id': v_id,
        'duration': video.duration or '-',
        'order': video.order,
        'resCode': 'ok',
        'msg': 'ok',
        'filename': video.get_filename()
    })
def enqueue_video():
    key = request.args.get('key', default=None, type=str)
    question_id = request.args.get('question_id', default=None, type=int)
    submission_id = request.args.get('submission_id', default=None, type=int)

    v = Video(applicant=current_user._get_current_object(),
              question=Question.query.get(question_id),
              s3_key=key,
              user_agent=UserAgentSchema().dump(request.user_agent).data,
              submission=Submission.query.get(submission_id))
    db.session.add(v)
    db.session.commit()
    return jsonify(v.to_dict())
Esempio n. 30
0
def initiate_video():
    if request.method == 'POST':
        data = request.form
        if 'video_name' not in data or 'video_url' not in data:
            raise InvalidUsage('Data must contain video_name and video_url')
        video = Video(name=data['video_name'], url=data['video_url'])
        db.session.add(video)
        db.session.commit()
        task = split_video.delay(video.id)
        job = Job(desc=SPLIT_JOB_DESC, celery_id=task.id, video=video)
        db.session.add(job)
        db.session.commit()
        return redirect(url_for('jobs', video_id=video.id))
    return render_template('submit_job.html')