Пример #1
0
    def main(self):
        """
        call each daemons
        """
        db = Database(self.databasePath)
        db.ctTable()
        db.close()

        daemon = (self.daemonRss,
                  self.daemonScan,
                  self.daemonLoad,
                  )
        for func in daemon:
            th = threading.Thread(target=func)
            th.daemon = True
            th.start()
            time.sleep(3)
Пример #2
0
    def _scanning(self):
        """
        scanning the database
        add to queue videos id unloaded
        should be called at regular intervals

        retunrn: added movieid num in queue
        """
        num = 0
        self.logging("scanning")
        db = Database(self.databasePath)
        for movieid in db.getMovieState0():
            self.queue.add(movieid)
            self.logging("AddQueue: %s" % movieid)
            num += 1
        db.close()
        return num
Пример #3
0
 def _rss(self):
     """
     check new movieid from include mylistid
     register in database to the new movieid
     """
     self.logging("rss")
     db = Database(self.databasePath)
     for mylistid in db.getMylistAll():
         if db.getMylistRss(mylistid):
             self.logging("RSS: %s" % mylistid)
             hitNum = 0
             apiMylist = NicovideoAPI.Nicovideo(mylistid=mylistid)
             for movieid in apiMylist.get_mylist_movies():
                 if not(movieid in db.getMylistHasMovieFromMylistId(mylistid)):
                     self.logging("RSS: Hit: %s" % movieTitle)
                     db.addMylistHasMovie(mylistid, movieid)
                     self.register(movieid)
                     db.setMovieTitle(movieid, movieTitle)
                     hitNum += 1
             self.logging("RSS: %s: %2dhit" % (mylistid, hitNum))
     db.close()
Пример #4
0
    def __init__(self, log, status, ):#databaseObj):
        """
        log: modules.nicoLoad_base.Log()
        """
        self.log = log
        self.status = status
        self.db = Database()#databaseObj

        if not(self.db.extMovieTable() and self.db.extMylistTable() and self.db.extMylistHasMovieTable()):
            self.db.ctTable()
        self.queue = Queue()

        self.__loading = False  # 動画を保存しているか is storing movie or not
        self.waitTime = 1

         # self.movieLoadLoop()  # 保存用の無限ループ
        movieLoadThread = threading.Thread(target=self.movieLoadLoop)
        movieLoadThread.daemon = True
        movieLoadThread.start()
Пример #5
0
 def load(self, movieid):
     """
     load movieid
     """
     movieid = movieid
     self.logging("load: %s" % movieid)
     # 各データの取得
     db = Database(self.databasePath)
     sdb = SystemDatabase(self.systemDatabasePath)
     nicoid = sdb.getNicoid()
     nicopw = sdb.getNicopw()
     savedir = sdb.getSavedir()
     sdb.close()
     api = NicovideoAPI(movie_id=movieid)
     title = api.get_movie_title()
     moviePath = api.save_movie(nicoid, nicopw, savedir)  # 保存専用のクラスを定義する。一時停止可能なもの
     # 登録
     db.setMoviePath(movieid, moviePath)
     db.setMovieState(movieid, 1)
     self.queue.done()
     db.close()
     return True
Пример #6
0
class NicoLoad_Load():
    def __init__(self, log, status, ):#databaseObj):
        """
        log: modules.nicoLoad_base.Log()
        """
        self.log = log
        self.status = status
        self.db = Database()#databaseObj

        if not(self.db.extMovieTable() and self.db.extMylistTable() and self.db.extMylistHasMovieTable()):
            self.db.ctTable()
        self.queue = Queue()

        self.__loading = False  # 動画を保存しているか is storing movie or not
        self.waitTime = 1

         # self.movieLoadLoop()  # 保存用の無限ループ
        movieLoadThread = threading.Thread(target=self.movieLoadLoop)
        movieLoadThread.daemon = True
        movieLoadThread.start()

    def movieLoadLoop(self):
        """
        保存用ループ
        loop for strage
        """
        # 既に動いていたら  if already running
        while True:
            try:
                movieid = self.movieQueueGet()
                self.status.setLoadingMovieid(movieid)
                self.movieLoad()
            except QueueEmptyError:
                self.status.setLoadingMovieid(u"waiting")
                time.sleep(self.waitTime)

    # まとめ系
    def nicoLoad_Load(self, *args):
        """
        load全般まとめ関数
        General Summary of load function
        コマンドから実行する関数を振り分ける
        Distributes the function to be executed from the command
        """
        option = args[1]
        if option.has_key(args[0]):
            # 引数付き
            url = option[args[0]]
            self.movieLoad(url)
        else:
            # 引数なし
            self.movieLoadAll()

    def rss(self, *args):
        """
        rss
         -id mylistid_1, mylistid_2, ...
        """
        option = args[1]
        del option[args[0]]
        if len(args) == 0:
            self.rssAll()
        else:
            for mylistid in option["-id"]:
                self.rssOne(mylistid)

    def movieLoadAll(self):
        """
        すべての動画を保存
        save all videos
        """
        for movieid in self.db.getMovieState0():
            self.movieQueueAdd(movieid)

    def regNicoInfo(self, *args):
        """
        ニコニコID,PW保存
        save niconico ID & PW
        """
        print u"ニコニコ動画のIDを入力してください"
        nicoid = raw_input(">>> ")
        print u"ニコニコ動画のPWを入力してください"
        nicopw = raw_input(">>> ")
        self.db.svNicoid(nicoid)
        self.db.svNicopw(nicopw)
        return True
    def regGmailInfo(self, *args):
        """
        GmailID,PWを保存
        save Gmail ID & PW
        """
        gmailid = raw_input(u"GmailのIDを入力してください\n>>> ")
        gmailpw = raw_input(u"GmailのPWを入力してください\n>>> ")
        self.db.svGmailid(gmailid)
        self.db.svGmailpw(gmailpw)
    def regSavedir(self, *args):
        """
        保存フォルダを保存
        save the folder for saving
        """
        flag = False
        while True:
            savedir = raw_input(u"保存フォルダを入力してください\n>>> ")
            flag = os.path.exists(os.path.abspath(savedir))
            if flag:
                break
            else:
                print u"入力されたフォルダは存在しません"

        self.db.svSavedir(savedir)
        return True

    def getNicoInfo(self):
        """return (nicoid, nicopw)"""
        return (self.db.getNicoid(), self.db.getNicopw())
    def getGmailInfo(self):
        """return (gmailid, gmailpw)"""
        return (self.db.getGmailid(), self.db.getGmailpw())
    def getSavedir(self):
        """return savedir"""
        return self.db.getSavedir()

    def movieQueueAdd(self, movieid):
        """
        保存キューに追加
        add to the queue for string
        """
        print "addQueue: %s" % movieid
        self.queue.add(movieid)
    def movieQueueAddFront(self, movieid):
        """
        保存キューの先頭に追加
        added to the top of the queue for string
        """
        print "addQueue: %s" % movieid
        self.queue.addFromnt(movieid)
    def movieQueueaddNext(self, movieid):
        """
        保存キューの次に追加
        added to the queue for string the second
        """
        print "addQueue: %s" % movieid
        self.queue.addNext(movieid)
    def movieQueueGet(self):
        """
        キューから取得
        retrived from the queue
        """
        return self.queue.get()
    def movieLoadDone(self):
        """
        タスクの終了を伝える 
        convey the completetion of the task
        タスクを実行したら呼び出す
        call to perform the task
        
        """
        self.queue.done()
        self.__loading = False
        self.status.chLoadingMovie()

    def movieLoad(self, movieid):
        """
        動画を保存
        save videos
        """
        if self.db.extMovieidInTable(movieid):
            # already resists
            self.db.setMovieState(movieid, 0)
        else:
            self.db.addMovie(movieid)  # resists for database
        api = NicovideoAPI(movie_id=movieid)
        title = api.get_movie_title()
        # ext = api.get_movie_type()
        nicoid = self.db.getNicoid()
        nicopw = self.db.getNicopw()
        savedir = getSavedir()
        self.__loading = True
        self.status.chLoadingMovie(self.__loading)
        self.db.setMovieTitle(movieid, title)
        self.db.setMovieDescription(movieid, api.get_movie_description())
        self.db.setMovieLength(movieid, api.get_movie_length())
        self.status.setLoadingMovieid(movieid)
        moviePath = api.save_movie(nicoid, nicopw, savedir)
        self.db.setMoviePath(movieid, moviePath)
        self.db.setMovieThumbnail(movieid, api.save_thumbnail(savedir))
        self.db.setMovieComment(movieid, api.save_comment(nicoid, nicopw, savedir, title))
        self.db.setMovieState(movieid, 1)
        self.movieLoadDone()
        return True

    def rssOne(self, mylistid):
        """
        マイリスRSS
        RSS for mylist
        """
        various = Various(self.db)
        for movieid in  various.rsscheck(mylistid):
            self.movieQueueAdd(movieid)

    def rssAll(self):
        """
        マイリスRSS
        RSS for mylist
        """
        various = Various(self.db)
        for mylistid in self.db.getMylistAll():
            for movieid in various.rsscheck(mylistid):
                self.movieQueueAdd(movieid)

    def setWaitTime(self, minute):
        """
        chenge wait time when load queue is empty
        """
        self.WaitTime = minute

    def exit(self):
        """
        Exit
        """
        pass
Пример #7
0
    def __init__(self, *args, **kwds):
        Log.__init__(self)
        self.__queueList = []
        self.__queueDict = {}
        if platform.system().lower() == "windows":
            # win用に書く
            pass
        else:
            home = os.getenv("HOME")
        nmlHome = os.path.join(home, WORKDIR)
        if not os.path.exists(nmlHome):
            os.mkdir(nmlHome)
        self.databasePath = os.path.join(nmlHome, DATABASE_FILE)
        self.systemDatabasePath = os.path.join(nmlHome, SYSTEM_DATABASE_FILE)

        db = Database(self.databasePath)
        db.ctTable()
        db.close()
        sdb = SystemDatabase(self.systemDatabasePath)
        sdb.ctTable()
        nid = sdb.getNicoid() if sdb.getNicoid() else u""
        npw = sdb.getNicopw() if sdb.getNicopw() else u""
        gid = sdb.getGmailid() if sdb.getGmailid() else u""
        gpw = sdb.getGmailpw() if sdb.getGmailpw() else u""
        sdr = sdb.getSavedir() if sdb.getSavedir() else u""
        sdb.close()

        self.nicoTable = NTable(nid, npw, gid, gpw, sdr)

        # begin wxGlade: NicoMovieLoadGUI.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.treeCtrl = gizmos.TreeListCtrl(self, -1, style=wx.TR_HAS_BUTTONS | wx.TR_NO_LINES | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_HIDE_ROOT | wx.TR_DEFAULT_STYLE)
        self.pnlCenter = wx.Panel(self, -1)
        self.lblUrl = wx.StaticText(self.pnlCenter, -1, "URL:")
        self.tclUrl = wx.TextCtrl(self.pnlCenter, -1, "", style=wx.TE_PROCESS_ENTER)
        self.pnlBottom = wx.Panel(self, -1)
        self.lblQueueList = wx.StaticText(self.pnlBottom, -1, "QueueList:")
        self.lclQueueList = wx.ListCtrl(self.pnlBottom, -1, style=wx.LC_REPORT | wx.LC_AUTOARRANGE | wx.LC_NO_HEADER | wx.SUNKEN_BORDER)
        self.lblLog = wx.StaticText(self.pnlBottom, -1, "Log:")
        self.tclLog = wx.TextCtrl(self.pnlBottom, -1, "", style=wx.TE_MULTILINE | wx.TE_READONLY)
        self.static_line_1 = wx.StaticLine(self, -1, style=wx.LI_VERTICAL)
        self.pnlRight = wx.Panel(self, -1)
        self.btnRss = wx.ToggleButton(self.pnlRight, -1, "RSS")
        self.btnAdd = wx.Button(self.pnlRight, -1, u"新規登録")
        self.btnLoad = wx.Button(self.pnlRight, -1, u"再ロード")
        self.btnClearLog = wx.Button(self.pnlRight, -1, u"ログ消去")
        self.btnDelete = wx.Button(self.pnlRight, -1, u"削除")
        self.btnSettings = wx.Button(self.pnlRight, -1, u"設定")
        self.btnExit = wx.Button(self.pnlRight, -1, "Exit")

        self.__set_properties()
        self.__do_layout()
        # end wxGlade
        self.__bind()
        self.__setTreeListCtrl()
        self.__set_QueueListCtrl()
        # other wigets
        self.dlgSettings = SettingsDialog(self.nicoTable, self.logging, self)
        # main
        self.nicoMain = NicoMovieLoadMain(self.databasePath, self.systemDatabasePath, self.logging)
        self.nicoMain.main()
        # timer
        timer = wx.Timer(self)
        timer.Start(3 * 1000)
        print "timer start"
Пример #8
0
    def register(self, mid):
        """
        register in database mid
        if mid is already registered, it marks unload

        mid: mylistid or movieid
        return: bool
        """
        db = Database(self.databasePath)
        if mid[0:2] == "sm":
            if db.extMovieidInTable(mid):
                db.setMovieState(mid, 0)
            else:
                apiMovie = NicovideoAPI(movie_id=mid)
                movieTitle = apiMovie.get_movie_title()
                db.addMovie(mid)
                db.setMovieTitle(mid, movieTitle)
        else:
            if db.extMylistInTable(mid):
                db.setMylistRss(mid, 1)
            else:
                api = NicovideoAPI(mylist_id=mid)
                mylistTitle = api.get_mylist_title().decode(self.sysenc)
                db.addMylist(mid)
                db.setMylistTitle(mylistTitle)
        db.close()