<commit_before>#!/usr/bin/env python

import sys
import os
import fsquery

def puaq(): # print usage and quit
    print("Usage: %s path_with_playlists" % os.path.basename(__file__))
    sys.exit(1)

def getcontents(thefile):
    contents = ""
    with open(thefile, "r") as f:
        contents = f.read()
    return contents

def convert_clementine_playlist_to_python_list(filename):

    contents = getcontents(filename)
    if len(contents) == 0:
        print("%s is empty! Aborting." % filename)
        sys.exit(1)

    tracks = []

    ls = 0
    le = 0
    while True:
        ls = contents.find("<location>", ls)
        if ls == -1:
            # we are done
            break

        le = contents.find("</location>", ls+1)
        if le == -1:
            print("Malformatted playlist contents detected. Check starting at offset %s, playlist %s." % (filename, ls))

        location = contents[ls+len("<location>"):le]
        tracks.append(location)

        ls = le # advance to the next location

    return tracks

def proc(plfile):
    tracks = convert_clementine_playlist_to_python_list(plfile)
    print(tracks)

if __name__ == "__main__":
    if len(sys.argv) < 2:
        puaq()
<commit_msg>completed the clementine playlist sanity checker tool<commit_after>#!/usr/bin/env python

import sys
import os
import fsquery

def puaq(): # print usage and quit
    print("Usage: %s path_with_playlists" % os.path.basename(__file__))
    sys.exit(1)

def getcontents(thefile):
    contents = ""
    with open(thefile, "r") as f:
        contents = f.read()
    return contents

def convert_clementine_playlist_to_python_list(filename):

    contents = getcontents(filename)
    if len(contents) == 0:
        print("%s is empty! Aborting." % filename)
        sys.exit(1)

    tracks = []

    ls = 0
    le = 0
    while True:
        ls = contents.find("<location>", ls)
        if ls == -1:
            # we are done
            break

        le = contents.find("</location>", ls+1)
        if le == -1:
            print("Malformatted playlist contents detected. Check starting at offset %s, playlist %s." % (filename, ls))

        location = contents[ls+len("<location>"):le]
        track_found = location[7:] # append but also remove the 'file://'
        track_found = track_found.replace("&amp;", "&") # clementine stuff.
        tracks.append(track_found)

        ls = le # advance to the next location

    return tracks

def proc(plfile):
    tracks = convert_clementine_playlist_to_python_list(plfile)
    i=0
    for t in tracks:
        i+=1
        if not os.path.exists(t):
            print("(index %s): %s of playlist %s does not exist!" % (i, os.path.basename(t), os.path.basename(plfile)))
    print("\n")

if __name__ == "__main__":
    if len(sys.argv) < 2:
        puaq()

{'fraction_non_alphanumeric': 0.12664532194948416, 'fraction_numerical': 0.007470651013874066, 'mean_word_length': 2.537106918238994, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3941377', 'n_tokens_mistral': 934, 'n_tokens_neox': 891, 'n_words': 247}