Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Audio CD covers

by larsen (Parson)
on Sep 17, 2001 at 20:52 UTC ( #112901=CUFP: print w/ replies, xml ) Need Help??

  1. insert a CD in your cd-reader
  2. be sure your internet connection is up
  3. run this script
  4. print the .pdf file it will create
  5. use scissors
  6. feel guilty ;)

Related code:

Here the code:

#!/usr/bin/perl # cddb_cover.pl - 17/9/2001 # by Stefano Rodighiero # http://larsen.perlmonk.org use strict; # This script runs only under Linux (tested), # SunOS or NetBSD because it does use CDDB_get qw/get_cddb/; # "This module/script gets the CDDB info for # an audio cd. You need LINUX, SUNOS or NETBSD, # a cdrom drive and an active # internet connection in order to do that" # ( CDDB_get docs ) use PDF::Create; # A4 are 210x297 mm use constant A4_WIDTH => 612; use constant A4_HEIGHT => 792; use constant A4_BOX => [0, 0, 612, 792]; # A CD cover is 12cm side... use constant CD_WIDTH => 350; my %font_size = ( Small => 10, Medium => 15, Large => 20, ); my %config_cddb = ( CDDB_HOST => 'freedb.freedb.org', CDDB_PORT => '8880', CDDB_MODE => 'cddb', CD_DEVICE => '/dev/cdrom', input => 0 ); my %cd = get_cddb( \%config_cddb ); my $pdf = new PDF::Create( filename => $ARGV[0] || 'cover.pdf', Version => 1.2, PageMode => 'UseNone', Author => '', Creator => '', Title => 'Copertina' ); my $root = $pdf->new_page( Mediabox => [ A4_BOX ] ); my $font = $pdf->font( Subtype => 'Type1', Encoding => 'WinAnsiEncoding', BaseFont => 'Helvetica' ); my $page = $root->new_page; my $cover = { # Where front has to be put on the page? front_corner_x => 100, front_corner_y => 10, # The same for the back back_corner_x => 100, back_corner_y => 10 + CD_WIDTH + 10, }; draw_front( $page, \%cd ); draw_back( $page, \%cd ); $pdf->close; sub draw_front { my $page = shift; my $cd = shift; draw_CD_box( $page, $cover->{ 'front_corner_x' }, $cover->{ 'front_c +orner_y' }, "Front" ); $page->string( $font, $font_size{'Medium'}, $cover->{'front_corner_x'} + 5, $cover->{'front_corner_y'} + CD_WIDTH - $font_size{'Medium'}, $cd->{'artist'} ); # print "$cd->{'artist'}\n"; $page->string( $font, $font_size{'Large'}, $cover->{'front_corner_x'} + 5, $cover->{'front_corner_y'} + CD_WIDTH - 5 - $font_size{'Medium'} - +$font_size{'Large'}, $cd->{'title'} ); # print "$cd->{'title'}\n"; } sub draw_back { my $page = shift; my $cd = shift; draw_CD_box( $page, $cover->{ 'back_corner_x' }, $cover->{ 'back_cor +ner_y' }, "Back" ); my $initial_pos = $cover->{'back_corner_y'} + ($font_size{'Small'} * + $cd->{'tno'}); my $counter = 1; foreach my $title ( @{ $cd->{'track'}} ) { $page->string( $font, $font_size{'Small'}, $cover->{'back_corner_x'} + 5, $initial_pos - $font_size{'Small'} + * ($counter - 1), "$counter. " . $title ); ++$counter; # print "$counter. $title\n"; } } # Draw CD bounding box sub draw_CD_box { my $page = shift; my ($corner_x, $corner_y, $str) = @_; my @corner = ( [$corner_x, $corner_y], [$corner_x + CD_WIDTH, $corner_y], [$corner_x + CD_WIDTH, $corner_y + CD_WIDTH], [$corner_x, $corner_y + CD_WIDTH], [$corner_x, $corner_y] # yes, it's the first repeated. see below ); foreach( 0..3 ) { $page->line( @{$corner[$_]}, @{$corner[$_+1]} ); } # Put a string near the right-upper corner if ( $str ) { $page->string( $font, $font_size{'Small'}, $corner_x + CD_WIDTH + 5, $corner_y + CD_WIDTH - $font_size{'Smal +l'}, $str ); } }

Update: some minor editing (indentation, paragraph tag)
Update: added <readmore>, as suggested by Petruchio

Comment on Audio CD covers
Select or Download Code
Re: Audio CD covers
by John M. Dlugosz (Monsignor) on Sep 18, 2001 at 01:05 UTC
    Bummer that it doesn't work on Windows.

    For step 5, you can find a circular cutter at Wal-mart. I was inspired by someone who made his CD labels works of art.

    (I own a circular cutter, but always use a sharpie.)

      It depends on internals of CDDB_get. You could try to replace this module with another one. From CPAN there's, for example, CDDB.

      I've chosen CDDB_get 'cause I prefear its interface.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://112901]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2014-09-16 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (19 votes), past polls