Esempio n. 1
0
    def __init__(self, log, parentframe, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)
        if kwargs.has_key('parent'):  self.parent = kwargs['parent']
        else:  self.parent = args[0]
        self.running = False
        self.stop = False

        #
        self.various = Various.nicoDL_Various(log=log, libraryfilepath=_LIBRARYFILEPATH, libraryfilename=_LIBRARYFILENAME)
        FORMATS.load()
        self.frame = parentframe

        # Wigets
        self.log = log
        self.btn = wx.Button(self, label='Start')
        self.cb = wx.CheckBox(self, label=u'完了メール送信 , ', pos=(-1, 5))
        self.cb.SetValue(True)
        self.st_title = wx.StaticText(self, label=u'')
        self.st_time = wx.StaticText(self, label=u'')

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.btn, 0, border=3, flag=wx.EXPAND|wx.WEST)
        sizer.Add(self.cb, 0, border=3, flag=wx.EXPAND|wx.WEST)
        sizer.Add(self.st_title, 0, border=3, flag=wx.EXPAND|wx.WEST|wx.TOP)
        sizer.Add(wx.StaticText(self, label=u' , '), 0, border=3, flag=wx.EXPAND|wx.WEST|wx.TOP)
        sizer.Add(self.st_time, 0, border=3, flag=wx.EXPAND|wx.TOP)
        self.SetSizerAndFit(sizer)

        self.Bind(wx.EVT_BUTTON, self.OnButton, self.btn)

        self.call()
    def __init__(self, parent, libfilepath):
        wx.Panel.__init__(self, parent=parent, style=wx.WANTS_CHARS)
        self.Bind(wx.EVT_SIZE, self.OnSize)
        
        various = Various.nicoDL_Various(libfilepath)

        """TreeCtrl"""
        self.tree = MyTreeCtrl(self)

        isz = (16,16)
        il = wx.ImageList(isz[0], isz[1])
        fldridx     = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER,      wx.ART_OTHER, isz))
        fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN,   wx.ART_OTHER, isz))
        fileidx     = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz))

        self.tree.SetImageList(il)
        self.il = il
        
        self.root = self.tree.AddRoot("Library")
        self.tree.SetPyData(self.root, None)
        self.tree.SetItemImage(self.root, fldridx, wx.TreeItemIcon_Normal)
        self.tree.SetItemImage(self.root, fldropenidx, wx.TreeItemIcon_Expanded)

        
        for x in various.getmylistIDs():
            child = self.tree.AppendItem(self.root, various.pickup(mylist_id=x, choice='mylist_name'))
            self.tree.SetPyData(child, None)
            self.tree.SetItemImage(child, fldridx, wx.TreeItemIcon_Normal)
            self.tree.SetItemImage(child, fldropenidx, wx.TreeItemIcon_Expanded)

            for y in various.pickup(mylist_id=x, choice='downloaded'):
                last = self.tree.AppendItem(child, u'%s %s'%(y, various.pickup(movie_id=y,  choice='movie_name')))
                self.tree.SetPyData(last, None)
                self.tree.SetItemImage(last, fileidx, wx.TreeItemIcon_Normal)
                self.tree.SetItemImage(last, fileidx, wx.TreeItemIcon_Expanded)

        for x in various.getmovieIDs():
            child = self.tree.AppendItem(self.root,  u'%s %s'%(x, various.pickup(movie_id=x,  choice='movie_name')))
            self.tree.SetPyData(child, None)
            self.tree.SetItemImage(child, fileidx, wx.TreeItemIcon_Normal)
            self.tree.SetItemImage(child, fileidx, wx.TreeItemIcon_Expanded)

        self.tree.Expand(self.root)
        """
Esempio n. 3
0
    def download(self):
        u"""
        *ダウンロードの全体を統括する関数.
        *一通り終わったら、ループせずにself.running=Falseにする
        """
        self.DLstart()

        nicodl = DL.nicoDL_DL(self.infofile_dir)
        various = Various.nicoDL_Various(self.libfile_dir)
        while True:
            try:
                print u'Gmailにアクセスしています...'
                myformat = nicodl.geturl()  # Gmailチェック
                self.SetStatusText(u'Gmailにログイン')
                break
            except:
                self.SetStatusText(u'Gmailにログインできませんでした...')
                myformat = False
                break
        #print "myformat:", myformat
        if myformat == False: pass # Gamilが空
        else:
            # library_ALL.ndl に追加
            various.write_library(myformat)

        while True:
            if self.checkdir(self.savedir): 
                self.savedir = self.checkdir(self.savedir) 
                break 
            else:
                # 空き容量不足でループをリセット
                print u"空き容量不足:\n ->%s" % self.savedir
                time.sleep(3)
                self.DLstop()
                if not self.running:
                    return
                continue

        print self.savedir, u"に保存"
        if not self.running:  return

        # RSS
        print u"RSSチェック中..."
        self.SetStatusText(u"RSSチェック中...")
        various.rsscheck()
        self.SetStatusText(u"RSSチェック完了")
        print u"RSSチェック完了!"

        """DL部分"""
        # 動画IDが保存されていない
        if various.getmovieIDs() == []:
            self.DLstop()
            wx.PostEvent(self, self.startevt)
            return
        # DL対象を決定
        movies = []
        for item in various.getmovieIDs():
            if not (various.pickup(movie_id=item, choice='state')):
                movies.append(item)

        for movie in movies:
            if not self.running:  return

            movie_obj = various.pickup(movie_id=movie)  # obj

            if movie_obj.mylist_id != False:
                # マイリスから
                mylistflag = movie_obj.mylist_id
                nico = Nicovideo.Nicovideo(movie_id=movie_obj.movie_id,
                                           mylist_id=movie_obj.mylist_id)
            else:
                # マイリスからじゃない
                mylistflag = False
                nico = Nicovideo.Nicovideo(movie_id=movie_obj.movie_id)

            # 情報取得
            if movie_obj.movie_name: title = movie_obj.movie_name
            else: title = nico.get_movie_title()
            self.movie_name_st.SetLabel(title)  # 動画名セット
            description = nico.get_movie_description()  #
            self.myprint(movie_obj.movie_id, title)
            # 終了時間計算
            length = nico.get_movie_length()
            minute = int(length.split(':')[0])
            second = int(length.split(':')[1])
            now = datetime.datetime.now()
            end = now + datetime.timedelta(minutes=minute, seconds=second)
            end = end.strftime(u'%m/%d %H:%M')
            self.myprint(movie_obj.movie_id, "".join([end, u"頃終了します."]))
            # サムネ保存
            self.myprint(movie_obj.movie_id, u" サムネイル取得中...")
            self.SetStatusText(u'サムネイル取得中...')
            thumbnail = nico.save_thumbnail(os.path.join(self.cwd, "data\\thumbnail"))
            # 動画保存
            self.myprint(movie_obj.movie_id, u" 動画取得中...")
            self.SetStatusText(u'動画取得中...')
            self.SetTitle(u'%s - %s - %s' % (self.windowtitle, movie_obj.movie_id, end))
            try:  movie_path = self.movie_dl(myformat=movie_obj, mylist_id=mylistflag)
            except DownloadInterraptionException:
                print 'download() raise DLExcept'
                self.DLstop()
                return
            self.myprint(movie_obj.movie_id, "".join([u" 動画取得完了!"]))#, "\n =>", movie_path]))
            # コメント保存
            self.myprint(movie_obj.movie_id, u" コメント取得中...")
            self.SetStatusText(u'コメント取得中...')
            ff = open(os.path.splitext(movie_path)[0] + '.xml', 'w')
            ff.write(nico.get_comment(self.nico_id, self.nico_pw, 1000))
            ff.close()
            # 情報書き換え
            self.myprint(movie_obj.movie_id, u"情報を更新します...")
            various.rewrite_library(factor="thumbnail", value=thumbnail, movie_id=movie_obj.movie_id)
            various.rewrite_library(factor="state", value=True, movie_id=movie_obj.movie_id)
            various.rewrite_library(factor="movie_path", value=movie_path, movie_id=movie_obj.movie_id)
            # マイリスが登録されていたらそのマイリスのDL済みに追加
            if movie_obj.mylist_id != False:
                ed = various.pickup(mylist_id=movie_obj.mylist_id, choice='downloaded')
                if not(movie_obj.movie_id in ed):  # 入ってないとき
                    various.rewrite_library(factor="downloaded", value=movie_obj.movie_id, mylist_id=movie_obj.mylist_id)
            # メール送信
            if self.mailcheck:
                self.myprint(movie_obj.movie_id, u" 完了メール送信")
                mail = SendMail.nicodl_sendmail(self.gmail_id, self.gmail_pw, self.toaddr)
                mail.main("".join([title, "\n\n", description]), movie_obj.movie_id)
            #nicodl.extention()  # 拡張
            #break
            print u"次..."
            time.sleep(3)
        self.DLstop()
        print u'1セット終了'
        for i in xrange(300, 0):
            self.SetStatusText(u'待機中...残り%i秒' % i)
            time.sleep(1)
        wx.PostEvent(self, self.finishevt)
        wx.PostEvent(self, self.startevt)
Esempio n. 4
0
    def movie_dl(self, myformat, mylist_id=False):
        u"""
        *動画を保存する関数.
        myformat: 動画IDを渡したmyformatオブジェクト
        mylist_id: mylist ID
        """
        buffer_size = 8 * 1024

        # ログイン
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
        req = urllib2.Request("https://secure.nicovideo.jp/secure/login")
        req.add_data(urllib.urlencode({"mail":self.nico_id, "password":self.nico_pw}))
        res = opener.open(req)
        # 動画配信場所取得(getflv)
        res = opener.open("http://flapi.nicovideo.jp/api/getflv/"+myformat.movie_id).read()
        videoURL = cgi.parse_qs(res)["url"][0]
        # 動画のダウンロード
        opener.open("http://www.nicovideo.jp/watch/"+myformat.movie_id)  # 必要
        res = opener.open(videoURL)
        ext = res.info().getsubtype()
        # 動画名決定
        if myformat.movie_name:
            title = myformat.movie_name
        else:
            nicoapi = Nicovideo.Nicovideo(movie_id=myformat.movie_id)
            title = nicoapi.get_movie_title()
        various = Various.nicoDL_Various()
        title = various.filenamecheck(title);  del various
        # フォルダ名決定
        if mylist_id:
            # マイリスから
            various = Various.nicoDL_Various(self.libfile_dir)
            mylistname = various.pickup(mylist_id=mylist_id, choice='mylist_name')
            if mylistname == False:
                """マイリス名を取得していない場合"""
                nicoapi = Nicovideo.Nicovideo(mylist_id=mylist_id)
                # マイリス名取得
                mylistname = nicoapi.get_mylist_name()
                # ライブラリ書き換え
                various.rewrite_library(factor='mylist_name', value=mylistname,  mylist_id=mylist_id)
            """ファイルに使用不可な文字列を除外し、パス生成"""
            savedir = os.path.join(self.savedir, 
                                   various.filenamecheck(mylistname))
            if not os.path.exists(savedir):
                # フォルダが無ければ作成
                os.makedirs(savedir)
            #print savedir
            #print title
            filename = os.path.join(savedir, title+"."+ext)
        else:  filename = os.path.join(self.savedir, title+"."+ext)
        # 動画サイズ
        nicoapi = Nicovideo.Nicovideo(movie_id=myformat.movie_id)
        if videoURL.find('low') == -1:  # 画質high
            size = nicoapi.get_movie_size_high()
        elif videoURL.find('low') > -1:  # 画質low
            size = nicoapi.get_movie_size_low()
        else:  raise DownloadInterraptionException()
        # 書き込み
        ofh = open(filename,"wb", buffer_size)
        try:
            while int(ofh.tell()) < size:
                # ファイルに書き込み
                ofh.write(res.read(buffer_size))
                par = (float(ofh.tell())/float(size))*100
                # ゲージ塗りつぶし
                self.PGfill(self.gauge, par)
                # statusbar
                self.SetStatusText(u"Finish: %s/%s" % (str(ofh.tell()), size))
                # %書き換え
                self.par_tt.SetLabel(u'%i%%' % par)
                if self.running == False:
                    ofh.close()
                    os.remove(filename)
                    raise DownloadInterraptionException()
        except DownloadInterraptionException:
            raise DownloadInterraptionException()
        finally:
            #print 'File close'
            if ofh.closed == False:  ofh.close()

        return filename
    def __init__(self, parent, liblocate):
        wx.Panel.__init__(self, parent)
        self.Bind(wx.EVT_SIZE, self.OnSize)

        self.tree = gizmos.TreeListCtrl(self, id=-1, style=wx.TR_DEFAULT_STYLE|wx.TR_FULL_ROW_HIGHLIGHT)

        isz = (16,16)
        il = wx.ImageList(isz[0], isz[1])
        self.fldridx     = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER,      wx.ART_OTHER, isz))
        self.fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN,   wx.ART_OTHER, isz))
        self.fileidx     = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz))

        self.tree.SetImageList(il)
        self.il = il

        self.tree.AddColumn(u'名前')
        self.tree.AddColumn(u'状態')
        self.tree.AddColumn(u'ID')
        self.tree.AddColumn(u'form')
        self.tree.SetMainColumn(0)
        self.tree.SetColumnWidth(0, 170)
        """ライブラリデータセット"""
        # 既存のライブラリ
        #data = Various.nicoDL_Various(liblocate, 'Library.ndl')
        #data = data.libopen()
        # ビュワー用
        #self.various = Various.nicoDL_Various(liblocate, '_Library.ndl')
        #self.various.libopen()
        #self.various.save(data)
        """"""
        ###########
        self.various = Various.nicoDL_Various(liblocate, 'Library.ndl')
        self.mylists = self.various.getmylistIDs()
        self.movies = self.various.getmovieIDs()
        # root
        self.root = self.tree.AddRoot('LibraryFile')
        self.tree.SetItemText(self.root, '',  1)
        self.tree.SetItemText(self.root, '',  2)
        self.tree.SetItemText(self.root, '',  3)
        self.tree.SetItemImage(self.root, self.fldridx, which = wx.TreeItemIcon_Normal)
        self.tree.SetItemImage(self.root, self.fldropenidx, which = wx.TreeItemIcon_Expanded)
        # MOVIE
        self.child_movie = self.tree.AppendItem(self.root, u'動画')
        self.tree.SetItemText(self.child_movie, '', 1)
        self.tree.SetItemText(self.child_movie, '', 2)
        self.tree.SetItemText(self.child_movie, '', 3)
        self.tree.SetItemImage(self.child_movie, self.fldridx, which = wx.TreeItemIcon_Normal)
        self.tree.SetItemImage(self.child_movie, self.fldropenidx, which = wx.TreeItemIcon_Expanded)
        for item in self.various.getmovieIDs():
            try:
                last = self.tree.AppendItem(self.child_movie, str(self.various.pickup(movie_id=item, choice='movie_name')))
                self.tree.SetItemText(last, str(self.various.pickup(movie_id=item, choice='state')), 1)
                self.tree.SetItemText(last, self.various.pickup(movie_id=item, choice='movie_id'), 2)
                self.tree.SetItemText(last, self.various.pickup(movie_id=item, choice='form'), 3)
                self.tree.SetItemImage(last, self.fileidx, which = wx.TreeItemIcon_Normal)
                self.tree.SetItemImage(last, self.fileidx, which = wx.TreeItemIcon_Expanded)
            except ValueError, mess:  print mess
        # MYLIST
        self.child_mylist = self.tree.AppendItem(self.root, u'マイリスト')
        self.tree.SetItemText(self.child_mylist, '', 1)
        self.tree.SetItemText(self.child_mylist, '', 2)
        self.tree.SetItemText(self.child_mylist, '', 3)
        self.tree.SetItemImage(self.child_mylist, self.fldridx, which = wx.TreeItemIcon_Normal)
        self.tree.SetItemImage(self.child_mylist, self.fldropenidx, which = wx.TreeItemIcon_Expanded)
        for item in self.various.getmylistIDs():
            if not self.various.pickup(mylist_id=item, choice='mylist_name'):
                mylistname = u'不明'
            else: mylistname = self.various.pickup(mylist_id=item, choice='mylist_name')
            last = self.tree.AppendItem(self.child_mylist, mylistname)
            self.tree.SetItemText(last, str(self.various.pickup(mylist_id=item, choice='rss')), 1)
            self.tree.SetItemText(last, self.various.pickup(mylist_id=item, choice='mylist_id'), 2)
            self.tree.SetItemText(last, self.various.pickup(mylist_id=item, choice='form'), 3)
            self.tree.SetItemImage(last, self.fldridx, which = wx.TreeItemIcon_Normal)
            self.tree.SetItemImage(last, self.fldropenidx, which = wx.TreeItemIcon_Expanded)
            for i in self.various.pickup(mylist_id=item, choice='downloaded'):
                child = self.tree.AppendItem(last, str(self.various.pickup(movie_id=i, choice='movie_name')))
                self.tree.SetItemText(child, str(self.various.pickup(movie_id=i, choice='state')), 1)
                self.tree.SetItemText(child, self.various.pickup(movie_id=i, choice='movie_id'), 2)
                self.tree.SetItemText(child, self.various.pickup(movie_id=i, choice='form'), 3)
                self.tree.SetItemImage(child, self.fileidx, which = wx.TreeItemIcon_Normal)
                self.tree.SetItemImage(child, self.fileidx, which = wx.TreeItemIcon_Expanded)

        self.tree.Expand(self.root)
        
        self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
Esempio n. 6
0
import modules.nicodl_various as Various

various = Various.nicoDL_Various(r'.\data')

data = various.libopen()

for index in xrange(0,10):
    for item in data['MOVIE'][index]:
        if item.mylist_id == '30309865':
            print 'http://www.nicovideo.jp/watch/'+item.movie_id
            various.rewrite_library(factor='state', value=True, movie_id=item.movie_id)
            
            
            
            
Esempio n. 7
0
# coding: utf-8

import modules.nicovideoAPI as nicoAPI
import modules.nicodl_various as Various

various = Various.nicoDL_Various("data")
nicovideo_id = "*****@*****.**"
nicovideo_pw = "kusounkobaka"

movieids = various.getmovieIDs()

for movieid in movieids:
    movieform = various.pickup(movieid)
    if movieform.movie_name == False:
        nicoapi = nicoAPI.Nicovideo(movie_id=movieid)
        various.rewrite_library(factor="movie_name", value=nicoapi.get_movie_title(), movie_id=movieid)
    if movieform.state == True:
        movie_name = various.pickup(movie_id=movieid, choice="movie_name")
        print movie_name
        nicoapi = nicoAPI.Nicovideo(movie_id=movieid)
        comm = nicoapi.get_comment(nicovideo_id, nicovideo_pw, 1000)
        ff = open(movie_name + ".xml", "w")
        ff.write(comm)
        ff.close()