Exemple #1
0
 def thumbList(mov_cls, movieidlist):
     moviemasterlist = BackendApi.get_model_list(
         model_mgr, mov_cls, movieidlist, using=settings.DB_READONLY)
     dest = []
     for mov in moviemasterlist:
         if isinstance(mov, PcMoviePlayList):
             url = Media.movie_pc_thumbnail(mov.filename)
         else:
             url = Media.movie_thumbnail(mov.filename)
         dest.append((self.makeAppLinkUrlMedia(url), 151, 88))
     return dest
Exemple #2
0
        def makeList(masterlist, masterdict, another_env_movies):
            movielist = []
            for master in masterlist:
                data = another_env_movies.get(master.filename)
                is_pc = isinstance(master, PcMoviePlayList)
                if is_pc:
                    thumbUrl = self.makeAppLinkUrlMedia(
                        Media.movie_pc_thumbnail(master.filename))
                else:
                    thumbUrl = self.makeAppLinkUrlMedia(
                        Media.movie_thumbnail(master.filename))
                movielist.append({
                    'id':
                    master.id,
                    'name':
                    master.name,
                    'filename':
                    master.filename,
                    'data':
                    getattr(master, 'data', ''),
                    'is_old':
                    data and (master.edittime < data['utime']),
                    'thumbUrl':
                    thumbUrl,
                    'is_pc':
                    is_pc,
                    'stgonly':
                    False,
                })

            for filename in list(
                    set(another_env_movies.keys()) - set(masterdict.keys())):
                data = another_env_movies.get(filename)
                movielist.append({
                    'id': data['id'],
                    'name': data['name'],
                    'filename': filename,
                    'data': '',
                    'is_old': True,
                    'thumbUrl': data['thumbUrl'],
                    'is_pc': data.get('is_pc'),
                    'stgonly': True,
                })
            return movielist
Exemple #3
0
    def __proc_listget(self):
        """動画一覧.
        """
        dirpath = settings_sub.MEDIA_DOC_ROOT
        if not os.path.exists(dirpath):
            os.mkdir(dirpath)

        model_mgr = self.getModelMgr()
        masterlist = BackendApi.get_movieplaylist_all(
            model_mgr, using=settings.DB_READONLY)
        pcmasterlist = BackendApi.get_pcmovieplaylist_all(
            model_mgr, using=settings.DB_READONLY)

        movielist = []
        for master in masterlist:
            thumbUrl = self.makeAppLinkUrlMedia(
                Media.movie_thumbnail(master.filename))
            movielist.append({
                'id': master.id,
                'name': master.name,
                'filename': master.filename,
                'thumbUrl': thumbUrl,
                'utime': master.edittime,
                'is_pc': False,
            })
        for master in pcmasterlist:
            thumbUrl = self.makeAppLinkUrlMedia(
                Media.movie_pc_thumbnail(master.filename))
            movielist.append({
                'id': master.id,
                'name': master.name,
                'filename': master.filename,
                'thumbUrl': thumbUrl,
                'utime': master.edittime,
                'is_pc': True,
            })
        self.json_result_param['movielist'] = movielist
        self.writeAppJson()
Exemple #4
0
    def procMemories(self, filter_json, page):
        """思い出画像確認.
        """
        PAGE_CONTENT_NUM = 50
        offset = page * PAGE_CONTENT_NUM

        cardmasterlist = CardMasterView.fetchValues(filters=filter_json,
                                                    order_by='id',
                                                    limit=PAGE_CONTENT_NUM,
                                                    offset=offset,
                                                    using=settings.DB_READONLY)
        cardidlist = [cardmaster.id for cardmaster in cardmasterlist]

        filters = {
            'cardid__in': cardidlist,
        }
        nummax = MemoriesMaster.count(filters, using=settings.DB_READONLY)
        pagemax = int((nummax + PAGE_CONTENT_NUM - 1) / PAGE_CONTENT_NUM)

        titles = (
            u'ID',
            u'名前',
            u'サムネイル',
            u'コンテンツ',
        )
        memoriesmasterlist = MemoriesMaster.fetchValues(
            filters=filters,
            order_by='id',
            limit=PAGE_CONTENT_NUM,
            offset=offset,
            using=settings.DB_READONLY)

        datalist = []
        for memoriesmaster in memoriesmasterlist:
            thumb = ''
            content = ''
            if memoriesmaster.contenttype == Defines.MemoryContentType.IMAGE:
                thumb = (self.makeAppImgUrl(memoriesmaster.thumb), 78, 88)
                content = (self.makeAppImgUrl(memoriesmaster.contentdata), 320,
                           400)
            elif memoriesmaster.contenttype == Defines.MemoryContentType.MOVIE:
                moviemaster = BackendApi.get_movieplaylist_master(
                    self.getModelMgr(),
                    int(memoriesmaster.contentdata),
                    using=settings.DB_READONLY)
                if moviemaster:
                    thumb = (self.makeAppLinkUrlMedia(
                        Media.movie_thumbnail(moviemaster.filename)), 151, 88)
                    content = self.makeAppLinkUrlMedia(
                        Media.movie_m3u8(moviemaster.filename))
            elif memoriesmaster.contenttype == Defines.MemoryContentType.VOICE:
                thumb = (self.makeAppImgUrl(memoriesmaster.thumb), 'auto', 88)
                voicemaster = BackendApi.get_voiceplaylist_master(
                    self.getModelMgr(),
                    int(memoriesmaster.contentdata),
                    using=settings.DB_READONLY)
                if voicemaster:
                    content = self.makeAppLinkUrlMedia(
                        Media.voice_aac(moviemaster.filename))

            row = [
                memoriesmaster.id,
                memoriesmaster.name,
                thumb,
                content,
            ]
            datalist.append(row)
        self.putData(titles, datalist)

        url = OSAUtil.addQuery(UrlMaker.view_images(), '_target', 'Memories')
        url = OSAUtil.addQuery(url, '_filter',
                               urllib.quote(self.html_param['_filter'], ''))
        self.putPagenationData(url, page, pagemax)
Exemple #5
0
    def __proc_update_pc(self):
        """動画更新(PC).
        本番環境のみ.
        ステージングから指定した動画を受け取って本番Wowzaサーバに配付する.
        サムネイル画像は各メディアサーバに配付する.
        """
        if not settings_sub.IS_LOCAL and settings_sub_props.ENVIRONMENT_TYPE != settings_sub_props.EnvironmentType.MANAGER:
            self.response.set_status(404)
            return
        zf = None
        try:
            # ダウンロードするマスターデータ.
            try:
                filename = self.request.get('_name')
            except:
                self.response.set_status(400)
                return

            # ダウンロード元.
            url = settings_sub.MEDIA_DOWNLOAD_FROM + 'cabaret/mgr/movie/'
            headers = {
                "Content-type": "application/x-www-form-urlencoded",
            }
            body = urllib.urlencode({
                '_name': filename,
                '_proc': 'packagepc',
            })

            try:
                response = self.osa_util.httpopen(url, body, 'POST', headers)
                data = response.read()
            except:
                raise

            def writeFile(filepath, data):
                f = None
                try:
                    f = open(filepath, 'w')
                    f.write(data)
                    f.close()
                    f = None
                except:
                    if f:
                        f.close()
                        f = None
                    raise

            io = StringIO(data)
            zf = ZipFile(io, 'r')

            # 動画ファイル.
            namelist = zf.namelist()[:]

            # マスターデータ.
            jsonfile = zf.open('master.json')
            obj_master = Json.decode(jsonfile.read())
            namelist.remove('master.json')

            master = PcMoviePlayList.getValues(filters={'filename': filename})
            if master:
                obj_master['id'] = master.id
            mid = obj_master['id']

            mediadir = os.path.join(settings_sub.MEDIA_DOC_ROOT, filename)
            if not os.path.exists(mediadir):
                os.mkdir(mediadir)

            # 動画ファイル.
            mp4filename = Media.movie_mp4(filename)
            mp4data = zf.open(mp4filename).read()
            filepath = os.path.join(settings_sub.MEDIA_DOC_ROOT, mp4filename)
            writeFile(filepath, mp4data)
            namelist.remove(mp4filename)

            # サムネイル画像.
            dirpath = settings_sub.MEDIA_DOC_ROOT
            if not os.path.exists(dirpath):
                os.mkdir(dirpath)

            name = Media.movie_pc_thumbnail(filename)
            filepath = os.path.join(dirpath, name)
            data = zf.open(name).read()
            writeFile(filepath, data)
            zf.close()
            zf = None

            # マスターデータ書き込み.
            # 上書き.
            def tr(data):
                model_mgr = ModelRequestMgr()

                def forUpdate(model, inserted):
                    for k, v in data.items():
                        setattr(model, k, v)

                model_mgr.add_forupdate_task(PcMoviePlayList, mid, forUpdate)
                model_mgr.write_all()
                return model_mgr

            tmp = db_util.run_in_transaction(tr, obj_master)
            tmp.write_end()

            # 配布.
            weblist = self.getMediaWebList()
            if weblist:
                # TODO
                errlog = MovieUtil.distribute_pc(filename, weblist,
                                                 settings_sub.SERVER_PASS)
                if errlog:
                    raise CabaretError(errlog)

            # 本番環境ではステージングと同じ動画を見るので配付する必要がない.
            if settings_sub.IS_DEV:
                errlog = MovieUtil.distribute_wowza(filename)
                if errlog:
                    raise CabaretError(errlog)

            # とり直しておく.
            model_mgr = self.getModelMgr()
            model_mgr.get_mastermodel_all(PcMoviePlayList,
                                          fetch_deleted=True,
                                          using=settings.DB_DEFAULT,
                                          reflesh=True)
        except:
            if zf:
                zf.close()
                zf = None
            raise

        self.putAlertToHtmlParam(u'動画を更新しました:name=%s' % filename,
                                 AlertCode.SUCCESS)
Exemple #6
0
    def __proc_update(self):
        """動画更新.
        本番環境のみ.
        ステージングから指定した動画を受け取って各メディアサーバに配付する.
        """
        if not settings_sub.IS_LOCAL and settings_sub_props.ENVIRONMENT_TYPE != settings_sub_props.EnvironmentType.MANAGER:
            self.response.set_status(404)
            return
        zf = None
        try:
            # ダウンロードするマスターデータ.
            try:
                filename = self.request.get('_name')
            except:
                self.response.set_status(400)
                return

            # ダウンロード元.
            url = settings_sub.MEDIA_DOWNLOAD_FROM + 'cabaret/mgr/movie/'
            headers = {
                "Content-type": "application/x-www-form-urlencoded",
            }
            body = urllib.urlencode({
                '_name': filename,
                '_proc': 'package',
            })

            try:
                response = self.osa_util.httpopen(url, body, 'POST', headers)
                data = response.read()
            except:
                raise

            def writeFile(filepath, data):
                f = None
                try:
                    f = open(filepath, 'w')
                    f.write(data)
                    f.close()
                    f = None
                except:
                    if f:
                        f.close()
                        f = None
                    raise

            io = StringIO(data)
            zf = ZipFile(io, 'r')

            # 動画ファイル.
            namelist = zf.namelist()[:]

            # マスターデータ.
            jsonfile = zf.open('master.json')
            obj_master = Json.decode(jsonfile.read())
            namelist.remove('master.json')

            master = MoviePlayList.getValues(filters={'filename': filename})
            if master:
                obj_master['id'] = master.id
            mid = obj_master['id']

            # プレイリスト.
            m3u8filename = Media.movie_m3u8(filename)
            m3u8file = zf.open(m3u8filename)
            m3u8lines = []
            for line in m3u8file.readlines():
                s = line.rstrip('\n').rstrip('\r')
                if line.startswith('#EXT-X-KEY:METHOD=AES-128'):
                    diff = len(line) - len(s)
                    postfix = ''
                    if 0 < diff:
                        postfix = line[-diff:]
                    url = self.makeAppLinkWebGrobalUrl(
                        UrlMaker.movie_keyget(mid))
                    line = '#EXT-X-KEY:METHOD=AES-128,URI="%s"%s' % (url,
                                                                     postfix)
                m3u8lines.append(line)
            m3u8data = ''.join(m3u8lines)
            writeFile(os.path.join(settings_sub.MEDIA_DOC_ROOT, m3u8filename),
                      m3u8data)
            namelist.remove(m3u8filename)

            # その他動画ファイル.
            dirpath = os.path.join(settings_sub.MEDIA_DOC_ROOT, filename)
            if not os.path.exists(dirpath):
                os.mkdir(dirpath)

            for name in namelist:
                outname = name
                if name == 'stream.ts':
                    if settings_sub.IS_LOCAL:
                        outname = filename + name
                    else:
                        continue
                filepath = os.path.join(dirpath, outname)
                data = zf.open(name).read()
                writeFile(filepath, data)
            zf.close()
            zf = None

            # マスターデータ書き込み.
            # 上書き.
            def tr(data):
                model_mgr = ModelRequestMgr()

                def forUpdate(model, inserted):
                    for k, v in data.items():
                        setattr(model, k, v)

                model_mgr.add_forupdate_task(MoviePlayList, mid, forUpdate)
                model_mgr.write_all()
                return model_mgr

            tmp = db_util.run_in_transaction(tr, obj_master)
            tmp.write_end()

            # 配布.
            weblist = self.getMediaWebList()
            if weblist:
                errlog = MovieUtil.distribute(filename, weblist,
                                              settings_sub.SERVER_PASS)
                if errlog:
                    raise CabaretError(errlog)

            # とり直しておく.
            model_mgr = self.getModelMgr()
            model_mgr.get_mastermodel_all(MoviePlayList,
                                          fetch_deleted=True,
                                          using=settings.DB_DEFAULT,
                                          reflesh=True)
        except:
            if zf:
                zf.close()
                zf = None
            raise

        self.putAlertToHtmlParam(u'動画を更新しました:name=%s' % filename,
                                 AlertCode.SUCCESS)
Exemple #7
0
    def __proc_package_pc(self):
        """動画パッケージ(PC).
        """
        zf = None
        zipdata = None
        try:
            name = self.request.get('_name')
            master = PcMoviePlayList.getValues(filters={'filename': name})

            io = StringIO()
            zf = ZipFile(io, 'w')

            # マスターデータ.
            dic = {}
            columnnames = PcMoviePlayList.get_column_names()
            for columnname in columnnames:
                dic[columnname] = getattr(master, columnname)
            zf.writestr('master.json', Json.encode(dic))

            def getData(filepath):
                f = None
                try:
                    f = open(filepath, 'r')
                    data = f.read()
                    f.close()
                    f = None
                except:
                    if f:
                        f.close()
                        f = None
                    raise
                return data

            # サムネイル画像.
            dirpath = settings_sub.MEDIA_DOC_ROOT
            name = Media.movie_pc_thumbnail(master.filename)
            filepath = os.path.join(dirpath, name)
            data = getData(filepath)
            zf.writestr(name, data)

            # 動画ファイル.
            filename = Media.movie_mp4(master.filename)
            zf.writestr(
                filename,
                getData(os.path.join(settings_sub.MEDIA_DOC_ROOT, filename)))

            err = zf.testzip()
            if err:
                raise CabaretError(err)

            zf.close()

            io.seek(0)
            zipdata = io.read()

            zf = None
        except:
            if zf:
                zf.close()
                zf = None
            if settings_sub.IS_LOCAL:
                raise
            self.response.set_status(500)
            raise

        f = open(os.path.join(settings_sub.TMP_DOC_ROOT, 'abc.zip'), 'w')
        f.write(zipdata)
        f.close()

        if zipdata:
            self.osa_util.write_zip(zipdata, 'movie')
        else:
            self.response.set_status(404)
            self.response.end()
            return