this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

push albums and artists into db

+223 -48
+94 -45
src/db/album.odin
··· 7 7 import "core:mem" 8 8 import "core:testing" 9 9 10 - new_album :: proc(db: ^sqlite.Connection, album: types.Album) -> sqlite.Result_Code { 10 + new_album :: proc( 11 + db: ^sqlite.Connection, 12 + album: types.Album, 13 + allocator := context.allocator, 14 + ) -> sqlite.Result_Code { 15 + 16 + id := gen_id("album", allocator) 17 + defer delete(id, allocator) 18 + 19 + 20 + params := make([dynamic]sa.Query_Param, 2, 4, allocator) 21 + defer delete_dynamic_array(params) 22 + 23 + params[0] = sa.Query_Param{1, id} 24 + params[1] = sa.Query_Param{2, album.title} 25 + 26 + 27 + mb_id, mb_rg_id: string 28 + ok: bool 29 + 30 + mb_id, ok = album.mb_id.? 31 + if ok do append(&params, sa.Query_Param{3, mb_id}) 11 32 12 - id := gen_id("album") 13 - defer delete(id) 33 + mb_rg_id, ok = album.mb_rg_id.? 34 + if ok do append(&params, sa.Query_Param{4, mb_rg_id}) 14 35 15 36 return sa.execute( 16 37 db, 17 38 "INSERT INTO album (id, title, mb_id, mb_rg_id) VALUES (?, ?, ?, ?)", 18 - {{1, id}, {2, album.title}, {3, album.mb_id.?}, {4, album.mb_rg_id.?}}, 39 + params[:], 19 40 ) 20 41 } 21 42 43 + new_album_batch :: proc( 44 + db: ^sqlite.Connection, 45 + albums: []types.Album, 46 + allocator := context.allocator, 47 + ) -> sqlite.Result_Code { 22 48 23 - // ================ 24 - // Tests 25 - // ================ 49 + rc: sqlite.Result_Code 26 50 51 + n := len(albums) 27 52 28 - @(test) 29 - should_create_new_album :: proc(t: ^testing.T) { 30 53 54 + fmt.printfln("Starting transaction") 55 + rc = sa.execute(db, "BEGIN TRANSACTION;") 56 + assert(rc == .Ok) 31 57 32 - track: mem.Tracking_Allocator 33 - mem.tracking_allocator_init(&track, context.allocator) 34 - context.allocator = mem.tracking_allocator(&track) 35 - defer { 36 - if len(track.allocation_map) > 0 { 37 - fmt.eprintf("=== %v allocations not freed: ===\n", len(track.allocation_map)) 38 - for _, entry in track.allocation_map { 39 - fmt.eprintf("- %v bytes @ %v\n", entry.size, entry.location) 40 - } 41 - } 42 - if len(track.bad_free_array) > 0 { 43 - fmt.eprintf("=== %v incorrect frees: ===\n", len(track.bad_free_array)) 44 - for entry in track.bad_free_array { 45 - fmt.eprintf("- %p @ %v\n", entry.memory, entry.location) 46 - } 47 - } 48 - mem.tracking_allocator_destroy(&track) 58 + for album in albums { 59 + fmt.printfln("Inserting %v", album) 60 + rc = new_album(db, album, allocator) 61 + assert(rc == .Ok) 49 62 } 50 63 64 + fmt.printfln("Commiting transaction") 65 + rc = sa.execute(db, "COMMIT;") 66 + assert(rc == .Ok) 51 67 52 - db: ^sqlite.Connection 68 + return rc 69 + } 53 70 54 - if rc := sqlite.open(db_url, &db); rc != .Ok { 55 - fmt.panicf("failed to open database. result code {}", rc) 56 - } 57 - fmt.printfln("connected to database") 58 71 59 - defer { 60 - sqlite.close(db) 61 - fmt.printfln("\nconnection closed") 62 - } 72 + // ================ 73 + // Tests 74 + // ================ 63 75 64 - album := types.Album { 65 - id = "test", 66 - title = "Test title", 67 - mb_id = "asdf", 68 - mb_rg_id = "asdf", 69 - } 70 76 71 - rc := new_album(db, album) 72 - testing.expect(t, rc == .Ok) 73 - 74 - } 77 + // @(test) 78 + // should_create_new_album :: proc(t: ^testing.T) { 79 + // 80 + // 81 + // track: mem.Tracking_Allocator 82 + // mem.tracking_allocator_init(&track, context.allocator) 83 + // context.allocator = mem.tracking_allocator(&track) 84 + // defer { 85 + // if len(track.allocation_map) > 0 { 86 + // fmt.eprintf("=== %v allocations not freed: ===\n", len(track.allocation_map)) 87 + // for _, entry in track.allocation_map { 88 + // fmt.eprintf("- %v bytes @ %v\n", entry.size, entry.location) 89 + // } 90 + // } 91 + // if len(track.bad_free_array) > 0 { 92 + // fmt.eprintf("=== %v incorrect frees: ===\n", len(track.bad_free_array)) 93 + // for entry in track.bad_free_array { 94 + // fmt.eprintf("- %p @ %v\n", entry.memory, entry.location) 95 + // } 96 + // } 97 + // mem.tracking_allocator_destroy(&track) 98 + // } 99 + // 100 + // 101 + // db: ^sqlite.Connection 102 + // 103 + // if rc := sqlite.open(db_url, &db); rc != .Ok { 104 + // fmt.panicf("failed to open database. result code {}", rc) 105 + // } 106 + // fmt.printfln("connected to database") 107 + // 108 + // defer { 109 + // sqlite.close(db) 110 + // fmt.printfln("\nconnection closed") 111 + // } 112 + // 113 + // album := types.Album { 114 + // id = "test", 115 + // title = "Test title", 116 + // mb_id = "asdf", 117 + // mb_rg_id = "asdf", 118 + // } 119 + // 120 + // rc := new_album(db, album) 121 + // testing.expect(t, rc == .Ok) 122 + // 123 + // }
+17 -1
src/db/artist.odin
··· 17 17 id := gen_id("artist", allocator) 18 18 defer delete(id, allocator) 19 19 20 + 21 + params := make([dynamic]sa.Query_Param, 2, 4, allocator) 22 + defer delete_dynamic_array(params) 23 + params[0] = sa.Query_Param{1, id} 24 + params[1] = sa.Query_Param{2, artist.name} 25 + 26 + 27 + mb_id, acoust_id: string 28 + ok: bool 29 + 30 + mb_id, ok = artist.mb_id.? 31 + if ok do append(&params, sa.Query_Param{3, mb_id}) 32 + 33 + acoust_id, ok = artist.acoust_id.? 34 + if ok do append(&params, sa.Query_Param{4, acoust_id}) 35 + 20 36 return sa.execute( 21 37 db, 22 38 "INSERT INTO artist (id, name, mb_id, acoust_id) VALUES (?, ?, ?, ?)", 23 - {{1, id}, {2, artist.name}, {3, artist.mb_id.?}, {4, artist.acoust_id.?}}, 39 + params[:], 24 40 ) 25 41 } 26 42
+2
src/formats/flac.odin
··· 194 194 comment.album_artist = comment.artists[0] 195 195 } 196 196 197 + fmt.printfln("Comment %#v", comment) 198 + 197 199 return comment, nil 198 200 } 199 201
+5 -2
src/library/library.odin
··· 51 51 continue 52 52 } 53 53 54 - fmt.printfln("Found: %s", info.fullpath) 55 - append(&paths, info.fullpath) 54 + filePath := strings.clone(info.fullpath, allocator) 55 + 56 + fmt.printfln("Found: %s", filePath) 57 + append(&paths, filePath) 58 + fmt.printfln("inner Paths: %$v", paths) 56 59 } 57 60 58 61 fmt.printfln("=== Total ===")
+105
src/library/sync.odin
··· 1 + package library 2 + 3 + import sqlite "../../vendor/sqlite" 4 + import sa "../../vendor/sqlite/addons" 5 + import types "../core" 6 + import db "../db" 7 + import formats "../formats" 8 + import "core:fmt" 9 + import "core:mem" 10 + import "core:mem/virtual" 11 + import vmem "core:mem/virtual" 12 + import "core:os" 13 + import "core:path/filepath" 14 + import "core:slice" 15 + import "core:strings" 16 + import "core:testing" 17 + 18 + 19 + main :: proc() { 20 + 21 + dir_path := "../../test-data/" 22 + 23 + input_path, test_err := filepath.join({#directory, dir_path}, context.temp_allocator) 24 + assert(test_err == nil) 25 + 26 + arena: vmem.Arena 27 + arena_err := vmem.arena_init_growing(&arena) 28 + defer vmem.arena_destroy(&arena) 29 + 30 + assert(arena_err == nil, "Failed to initialize arena") 31 + 32 + arena_allocator := vmem.arena_allocator(&arena) 33 + 34 + paths_dyn := walk_dir(input_path, arena_allocator) 35 + defer delete_dynamic_array(paths_dyn) 36 + 37 + paths := paths_dyn[:] 38 + 39 + 40 + track: mem.Tracking_Allocator 41 + mem.tracking_allocator_init(&track, context.allocator, context.allocator) 42 + context.allocator = mem.tracking_allocator(&track) 43 + defer { 44 + if len(track.allocation_map) > 0 { 45 + fmt.eprintf("=== %v allocations not freed: ===\n", len(track.allocation_map)) 46 + for _, entry in track.allocation_map { 47 + fmt.eprintf("- %v bytes @ %v\n", entry.size, entry.location) 48 + } 49 + } 50 + if len(track.bad_free_array) > 0 { 51 + fmt.eprintf("=== %v incorrect frees: ===\n", len(track.bad_free_array)) 52 + for entry in track.bad_free_array { 53 + fmt.eprintf("- %p @ %v\n", entry.memory, entry.location) 54 + } 55 + } 56 + mem.tracking_allocator_destroy(&track) 57 + } 58 + 59 + 60 + db_conn: ^sqlite.Connection 61 + 62 + if rc := sqlite.open("oudio.db", &db_conn); rc != .Ok { 63 + fmt.panicf("failed to open database. result code {}", rc) 64 + } 65 + fmt.printfln("connected to database") 66 + 67 + defer { 68 + sqlite.close(db_conn) 69 + fmt.printfln("connection closed") 70 + } 71 + 72 + rc: sqlite.Result_Code 73 + 74 + 75 + for path in paths { 76 + fmt.printfln("Path: %s", path) 77 + 78 + file, ferr := os.open(path, {.Read}) 79 + assert(ferr == nil) 80 + 81 + flac, flac_err := formats.flac_read(file) 82 + 83 + os.close(file) 84 + assert(flac_err == nil) 85 + 86 + album := types.Album { 87 + id = "", 88 + title = flac.album, 89 + } 90 + 91 + artist := types.Artist { 92 + id = "", 93 + name = flac.album_artist, 94 + } 95 + 96 + fmt.printfln("Flac Comment %#v, artist %#v album %#v", flac, artist, album) 97 + 98 + rc = db.new_album(db_conn, album) 99 + assert(rc == .Ok) 100 + rc = db.new_artist(db_conn, artist) 101 + assert(rc == .Ok) 102 + formats.destroy_vorbis_comment(flac) 103 + } 104 + 105 + }