コード例 #1
0
ファイル: show.py プロジェクト: darkfeline/vocaran_tools
def show_main(week, raw=False):
    if week is None:
        for x in dm.check_songlists():
            x = dm.get_songlist(x)
            print_summary(x)
    else:
        path = dm.get_songlist_path(week)
        if not os.path.isfile(path):
            raise StructureError('{} is not a file.'.format(path))
        if raw:
            with open(path) as f:
                for line in f:
                    print(line, end="")
        else:
            x = dm.get_songlist(week)
            print_summary(x)
            for entry in x:
                print('-' * 10)
                print(
"""ID:{}
Name:{}
Artist:{}
Album:{}
Comment:{}
APIC:{}""".format(*iter(entry)))
コード例 #2
0
ファイル: remove.py プロジェクト: darkfeline/vocaran_tools
def remove_main(week):
    try:
        slist = dm.get_songlist(week)
    except (StructureError, FileFormatError) as e:
        print(str(e))
        raise ExitException(1)
    os.remove(slist.file)
コード例 #3
0
ファイル: dl.py プロジェクト: darkfeline/vocaran_tools
def dlmain(week, dlf, *args):

    """Parse song list file and pass on to dlloop

    filename is name of song list file.
    dlf is dl function to use.
    args is passed directly to dlloop().

    dlmain() also handles some personal defaults.  In particular:
    Comment fields are set to id if blank.
    apic are set to 'smile' if blank.

    """

    print('Loading song list...')
    slist = dm.get_songlist(week)
    if isinstance(slist, songlist.RankedSongList):
        print('Translate song list first')
        raise ExitException(1)
    # personal defaults here
    for entry in slist:
        if entry.comment == '':
            entry.comment = entry.id
        if entry.apic == '':
            entry.apic = 'smile'
    print('Downloading...')
    dlloop(dlf, slist, dm.get_songlist_path(week), *args)
    print('Marking song list as done...')
    slist.done = True
    slist.save()
    print('Done.')
コード例 #4
0
ファイル: translate.py プロジェクト: darkfeline/vocaran_tools
def translate_main(week, source):
    if source is None:
        print('Getting Vocaloid HTML for week {}...'.format(str(week)))
        src = 'src.tmp'
        get_vocaloidism(src, week)
    else:
        print('Using {} as src'.format(source))
        src = source
    print('parsing src...')
    ranks = parse.parse_vocaloidism(src)
    print('checking parsed links...')
    if parse.checklinks(ranks):
        raise FileFormatError('parse_vocaloidism links is incomplete.  ' + 
            'Check source and/or parse_vocaloidism', parse.checklinks(ranks))
    print('reading song list data...')
    slist = dm.get_songlist(week)
    print('converting ranks...')
    parse.convert_list(slist, ranks)
    print('saving...')
    slist.save()
    if source is None and os.path.isfile('src.tmp'):
        print('removing src.tmp...')
        os.remove('src.tmp')
    print('Done.')
コード例 #5
0
ファイル: dl.py プロジェクト: darkfeline/vocaran_tools
def dlloop(dlf, slist, path, force=False):

    """Loop the dl function over fields.

    Prints output for convenience.  Also handle pause/restore session.  File
    name illegal char handling is here ('/' replaced with '|')

    fields is the song list.
    dlf is the dl function to use.
    filename is the name of the song list file (to generate session dat file).
    force is boolean for whether to retry downloads on timeout.

    """

    import re

    re_illegal = re.compile(r'/')
    re_error = re.compile(r'[Errno 110]')

    try:
        rejects = dm.get_songlist(0)
    except StructureError:
        rejects = dm.make_songlist(0)

    sessionfile= dm.SESSION_FILE
    # load session
    if os.path.isfile(sessionfile):
        print('Loading last session...')
        j = load_session(sessionfile, path)
        if j < 0:
            print("Data file checksum differs from file; ignoring session")
            j = 0
    else:
        j = 0
    for i, entry in enumerate(slist):
        if i < j:
            continue
        bname = re_illegal.sub('|', entry.name) + '.mp3'
        name = os.path.join(dm.DOWNLOAD_DIR, bname)
        print("Fetching {} ({}/{})".format(bname, i + 1, len(slist)))
        while True:
            try:
                dlf(name, *entry)
            except KeyboardInterrupt as e:
                print('Writing current session...')
                save_session(sessionfile, path, i - 1)
                rejects.save()
                raise ExitException(0)
            except urllib.error.URLError as e:
                if re_error.search(str(e)):
                    if force:
                        print('URLError: retrying...')
                        continue
                    else:
                        save_session(sessionfile, path, i - 1)
                        rejects.save()
                        print('URLError: exiting...')
                        raise ExitException(1)
            except FileNotAvailableError:
                print('File not available; adding to rejects...')
                if slist.week != 0:
                    rejects.add(entry)
                break
            else:
                break
        print("Finished {} ({}/{})".format(bname, i + 1, len(slist)))
        rejects.save()