Esempio n. 1
0
def test_yta_caps(request, capsys, temparchive):
    ''' Test checking and amending the captions '''
    #Get path
    path = request.node.get_closest_marker("internal_path").args[0]
    dbPath = os.path.join(path, "archive.db")
    #Prepare database
    db = sqlite3.connect(dbPath)
    expID, expTitle, expCap = db.execute(
        "SELECT youtubeID,title,subtitles FROM videos WHERE id=1;").fetchone()
    db.execute("UPDATE videos SET subtitles=? WHERE id=1;", (None, ))
    db.commit()
    db.close()
    #Check subtitles
    ytarchiver.archive(['-u', path])
    captured = capsys.readouterr()
    #Compare
    assert "INFO: Video [{}] \"{}\" had captions added since archiving".format(
        expID, expTitle) in captured.out
    #Amend subtitles
    ytarchiver.archive(['-x', path])
    captured = capsys.readouterr()
    db = sqlite3.connect(dbPath)
    recCap = db.execute(
        "SELECT subtitles FROM videos WHERE id=1;").fetchone()[0]
    db.close()
    #Compare
    assert "INFO: Added subtitle \"{}\" for video \"{}\" to the database".format(
        "en", expID) in captured.out
    assert expCap == recCap
Esempio n. 2
0
def test_yta_all_caps(request, capsys, tempallarchive):
    ''' Test amending the captions for a dir of archives '''
    #Get path
    path = request.node.get_closest_marker("internal_path").args[0]
    #Prepare database
    exp = []
    for i in range(1, 4):
        dbID = (i * 2) - 1
        db = sqlite3.connect(os.path.join(path, str(i), "archive.db"))
        exp.append(
            db.execute("SELECT youtubeID,subtitles FROM videos WHERE id=?;",
                       (dbID, )).fetchone())
        db.execute("UPDATE videos SET subtitles=? WHERE id=?;", (None, dbID))
        db.commit()
        db.close()
    #Amend subtitles
    ytarchiver.archive(['-a', '-x', path])
    captured = capsys.readouterr()
    #Read database
    rec = []
    for i in range(1, 4):
        dbID = (i * 2) - 1
        db = sqlite3.connect(os.path.join(path, str(i), "archive.db"))
        rec.append(
            db.execute("SELECT subtitles FROM videos WHERE id=?;",
                       (dbID, )).fetchone()[0])
        db.close()
    #Compare
    for e in exp:
        assert "INFO: Added subtitle \"{}\" for video \"{}\" to the database".format(
            "en", e[0]) in captured.out
        assert e[1] in rec
Esempio n. 3
0
def test_yta_all_one(request, tempallarchive):
    ''' Test downloading one new video for a dir of archives '''
    #Get path
    path = request.node.get_closest_marker("internal_path").args[0]
    #Modify database
    exp = []
    for i in range(1, 3):
        db = sqlite3.connect(os.path.join(path, str(i), "archive.db"))
        exp.append(
            db.execute("SELECT youtubeID,title FROM videos WHERE id=?;",
                       (i, )).fetchone())
        db.execute("DELETE FROM videos WHERE id = ?;", (i, ))
        db.commit()
        db.close()
    #Download video
    t1 = int(time.time())
    ytarchiver.archive(['-a', '-hd', path])
    t2 = int(time.time())
    #Read database
    rec = []
    recUpdate = []
    for i in range(1, 3):
        db = sqlite3.connect(os.path.join(path, str(i), "archive.db"))
        rec.append(
            db.execute(
                "SELECT youtubeID,title FROM videos WHERE id = (SELECT MAX(id) FROM videos);"
            ).fetchone())
        recUpdate.append(
            db.execute(
                "SELECT lastupdate FROM channel WHERE id=1;").fetchone()[0])
        db.close()
    #Compare
    assert rec == exp
    for r in recUpdate:
        assert t1 <= r <= t2
Esempio n. 4
0
def test_yta_one(request, temparchive):
    ''' Test downloading one new video '''
    #Get path
    path = request.node.get_closest_marker("internal_path").args[0]
    dbPath = os.path.join(path, "archive.db")
    #Modify database
    db = sqlite3.connect(dbPath)
    dbID, expYoutubeID, expTitle = db.execute(
        "SELECT id,youtubeID, title FROM videos WHERE id = (SELECT MAX(id) FROM videos);"
    ).fetchone()
    db.execute("DELETE FROM videos WHERE id = ?;", (dbID, ))
    db.commit()
    db.close()
    #Download video
    t1 = int(time.time())
    ytarchiver.archive(['-hd', path])
    t2 = int(time.time())
    #Read database
    db = sqlite3.connect(dbPath)
    recYoutubeID, recTitle, recRes = db.execute(
        "SELECT youtubeID, title, resolution FROM videos WHERE id = (SELECT MAX(id) FROM videos);"
    ).fetchone()
    recUpdate = db.execute(
        "SELECT lastupdate FROM channel WHERE id=1;").fetchone()[0]
    db.close()
    #Compare
    assert recYoutubeID == expYoutubeID
    assert recTitle == expTitle
    assert recRes == "Full HD"
    assert t1 <= recUpdate <= t2
Esempio n. 5
0
def test_yta_filter(request, capsys, temparchive):
    ''' Test filtering videos '''
    #Get path
    path = request.node.get_closest_marker("internal_path").args[0]
    #Prepare database
    db = sqlite3.connect(os.path.join(path, "archive.db"))
    db.execute("DELETE FROM videos;")
    db.commit()
    db.close()
    #Check filter
    filterStr = "uploader = 'wrong channel'"
    ytarchiver.archive(["--filter", filterStr, path])
    captured = capsys.readouterr()
    #Compare
    assert captured.out.count("does not pass filter uploader") == 6
Esempio n. 6
0
def test_yta_replace(request, temparchive):
    ''' Test video replacement '''
    #Get path
    path = request.node.get_closest_marker("internal_path").args[0]
    dbPath = os.path.join(path, "archive.db")
    #Prepare database
    db = sqlite3.connect(dbPath)
    expID, expName = db.execute(
        "SELECT youtubeID,filename FROM videos WHERE id=1;").fetchone()
    db.close()
    filePath = os.path.join(path, expName)
    #Check subtitles
    ytarchiver.archive(['-r', path, "en", expID])
    #Compare
    assert os.path.isfile(filePath)
Esempio n. 7
0
def test_yta_stat(request, temparchive):
    ''' Test updating the statistics '''
    #Get path
    path = request.node.get_closest_marker("internal_path").args[0]
    dbPath = os.path.join(path, "archive.db")
    #Update statistics
    t1 = int(time.time())
    ytarchiver.archive(['-s', path])
    t2 = int(time.time())
    #Read database
    db = sqlite3.connect(dbPath)
    recStats = [
        i[0] for i in db.execute(
            "SELECT statisticsupdated FROM videos;").fetchall()
    ]
    db.close()
    #Compare
    for r in recStats:
        assert t1 <= r <= t2
Esempio n. 8
0
def test_yta_file(request, temparchive):
    ''' Test downloading from file '''
    #Get path
    path = request.node.get_closest_marker("internal_path").args[0]
    dbPath = os.path.join(path, "archive.db")
    filePath = os.path.join(path, "file")
    expIDs = ["m-PGIQ6uwvk", "BBoaQvZOoFk"]
    #Prepare file
    with open(filePath, 'w') as f:
        f.write('\n'.join(expIDs))
    #Check subtitles
    ytarchiver.archive([path, "en", '-f', filePath])
    #Compare
    db = sqlite3.connect(dbPath)
    recIDs = [
        i[0] for i in db.execute("SELECT youtubeID FROM videos").fetchall()
    ]
    db.close()
    for i in expIDs:
        assert i in recIDs
Esempio n. 9
0
def _getcompletearchive(origDB):
    '''Copy the db to path, remove all videos from db and redownload them
    using ytarchiver -hd
    '''
    global temp_complete_archive
    #Check if already downloaded
    if not temp_complete_archive:
        #Prepare
        tempPath = os.path.join(os.environ["YTA_TESTDATA"], "temp_"+generateRandom(10))
        os.mkdir(tempPath)
        dbPath = os.path.join(tempPath, "archive.db")
        shutil.copyfile(origDB, dbPath)
        #Remove videos from database
        _db = sqlite3.connect(dbPath)
        _db.execute("DELETE FROM videos;")
        _db.execute("UPDATE channel SET playlist = \"PL0Stv0eTj3NuNh_dwtgScHauYOiTO35KX\" WHERE id = 1;") #Shorter playlist, only 3 videos
        _db.commit()
        _db.close()
        #Download
        ytarchiver.archive(['-hd', tempPath])
        #Save path
        temp_complete_archive = tempPath