It is currently 18 Nov 2019, 14:54
   
Text Size

Bug reports for Magarena 1.95

Moderators: melvin, beholder, ubeefx, ShawnieBoy, Lodici, CCGHQ Admins

Bug reports for Magarena 1.95

Postby melvin » 31 Dec 2018, 09:30

To help us in addressing bugs, the best way is to create an issue on the issue tracker. This lets us keep track each report separately and ensures it doesn't get lost.
https://github.com/magarena/magarena/issues (requires github account)

For game play bugs, please include a gameplay report zip file. You can create a gameplay report by opening the options menu (press Esc during a duel) and selecting the "Gameplay Report" menu item.

Less preferred is to post your report in this thread. (requires forum account)

You can report anonymously via gitreports, note that name/email if provided will be listed on the issue tracker.
https://gitreports.com/issue/magarena/magarena (no sign-up required, name/email optional)
User avatar
melvin
AI Programmer
 
Posts: 1057
Joined: 21 Mar 2010, 12:26
Location: Singapore
Has thanked: 36 times
Been thanked: 456 times

Re: Bug reports for Magarena 1.95

Postby muaddib » 20 Aug 2019, 09:16

Card images don't load from Internet. Fix it please.
User avatar
muaddib
Tester
 
Posts: 113
Joined: 03 Mar 2011, 08:37
Location: Russia
Has thanked: 0 time
Been thanked: 1 time

Re: Bug reports for Magarena 1.95

Postby hashborgir » 14 Sep 2019, 00:27

Hello. This is my first post. I hope all is well. Thank you for making this program, it's nice. It's the only one I have used besides MTG games on XBLA circa 2012 etc. and it's pretty awesome.

I ran into the same bug as muaddib above. It seems that the website domain has changed to scryfall and not only that, but filenames and searching don't match anymore, so the Magarena program fails to download the card images.

I took a look at the source code, and I must admit, I don't fully understand how everything is tied in together. I see a lot of awk scripts. I haven't used that in decades. If you would like help, I can help, but I'd need more information on how to contribute.

I've read the posts about copyright infringment and I think I understand them, and in case I have missed, please advise accordingly.

As for the bug above, I coded a little program in golang to download card images from scryfall

It seems that the card image url has changed to using some UU encoded string. So, I wrote a basic scraper using goquery.

This is the version that works (both versions compile).
Code: Select all
package main

import (
    "fmt"
    "github/PuerkitoBio/goquery"
    "io"
    "log"
    "net/http"
    "os"
    "strings"
)

func getCardData() {
  args := os.Args

  if len(args) < 1 {
      fmt.Println("Usage: mtg Name Of Card");
      os.Exit(1);
  }

  name_of_card := os.Args[1] // name of card from command line

  url := fmt.Sprintf("scryfall/search?q=%v", name_of_card)

  doc, err := goquery.NewDocument(url)
  if err != nil {
    log.Fatal(err)
  }

  // Find the review items
  doc.Find("a.card-grid-item-card").Each(func(i int, s *goquery.Selection) {
    card_img_url, card_img_url_exists := s.Find("img.card").Attr("src")
    card_name := s.Find(".card-grid-item-invisible-label").Text()+".jpg"
   
    if card_img_url_exists {
      fmt.Printf("%v : %v\n", strings.TrimSpace(card_name), strings.TrimSpace(card_img_url))
      downloadFile(card_img_url, "cards/"+card_name)
    }
  })
}

func downloadFile(url string, filepath string){
  os.Mkdir("cards", os.ModePerm)
 
  // Get the data
  resp, err := http.Get(url) 
  if err != nil {
    fmt.Println("Error while downloading", url, "-", err)
  }
  defer resp.Body.Close()
 
  if fileExists(filepath){
    fmt.Println("File exists!")
  } else {
    // Create the file
    out, err := os.Create(filepath)
    if err != nil {
      fmt.Println("Error while creating", filepath, "-", err)
    }
    defer out.Close()
   
    // Write the body to file
    _, err = io.Copy(out, resp.Body) 
    if err != nil {
      fmt.Println("Error while writing file data", filepath, "-", err)
    }
  }
}

func fileExists(filename string) bool {
  info, err := os.Stat(filename)
  if os.IsNotExist(err) {
    return false
  }
  return !info.IsDir()
}

func main() {
  getCardData()
}


And in this version I just tried to clean some stuff up, refactored some logic, and it compiles, but fails to download anything. It seems that upon debugging it fails at: card_img_url_exists returns bool false, so it doesn't download. I'm guessing because for some odd reason, goquery fails to fetch url into doc. Anyway, if someone knows golang and can help me, cool. Otherwise I might try python and beautiful soup for an mtg card scraper.
Code: Select all
package main

import (
    "fmt"
    "github/PuerkitoBio/goquery"
    "io"
    "log"
    "net/http"
    "net/url"
    "os"
    "strings"
)

func getCardData() {
  args := os.Args
 
  if len(args) < 1 {
      fmt.Println("Usage: mtg Name Of Card");
      os.Exit(1);
  }

  name_of_card := os.Args[1] // name of card from command line
  fmt.Println(name_of_card)

  _url := fmt.Sprintf("scryfall/search?q=%v", url.QueryEscape(name_of_card))
  fmt.Println(_url) 

  doc, err := goquery.NewDocument(_url)
  fmt.Println(_url)
  if err != nil {
    log.Fatal(err)
  }
  // Find the review items
  doc.Find("a.card-grid-item-card").Each(func(i int, s *goquery.Selection) {
    card_img_url, card_img_url_exists := s.Find("img.card").Attr("src")
    card_name := s.Find(".card-grid-item-invisible-label").Text()+".jpg"
   
    if card_img_url_exists {
      fmt.Printf("%v : %v\n", strings.TrimSpace(card_name), strings.TrimSpace(card_img_url))
      downloadFile(card_img_url, "cards/"+card_name)
    }
  })
 
}

func downloadFile(url string, filepath string){
  os.Mkdir("cards", os.ModePerm)
 
  // Get the data
  resp, err := http.Get(url) 
  if err != nil {
    fmt.Println("Error while downloading", url, "-", err)
  }
  defer resp.Body.Close()
 
  if fileExists(filepath){
    fmt.Println("File exists!")
  } else {
    // Create the file
    out, err := os.Create(filepath)
    if err != nil {
      fmt.Println("Error while creating", filepath, "-", err)
    }
    defer out.Close()
   
    // Write the body to file
    _, err = io.Copy(out, resp.Body) 
    if err != nil {
      fmt.Println("Error while writing file data", filepath, "-", err)
    }
  }
}

func fileExists(filename string) bool {
  info, err := os.Stat(filename)
  if os.IsNotExist(err) {
    return false
  }
  return !info.IsDir()
}

func main() {
  getCardData()
}
You can download the linux x64 binary here:

EDIT: It won't let me post a link to google drive where I've uploaded the binary as this is my first post and it considers it spammy.

Save the mtg binary anywhere, (/usr/local/bin/mtg works well) to run globally:
Code: Select all
mtg "Card Name"
or you can run it inside any active directory like this:
Code: Select all
./mtg "Card Name"
You can also take the
Code: Select all
standard_all.txt
or any of the txt files in

[url]github/magarena/magarena/tree/master/cards[/url]and run the following command in a bash shell

(if installed in /usr/local/bin)
while IFS="" read -r p || [ -n "$p" ]; do mtg $p ; done < standard_all.txt

(if running in current directory)
while IFS="" read -r p || [ -n "$p" ]; do ./mtg $p ; done < standard_all.txt


And it will use cardname as search term on scryfall, get a page of all the cards for that keyword/cardname, and download the images as 'Card Name.jpg' instead of /cards/normal/front/1/3/13f4bafe-0d21-47ba-8f16-0274107d618c.jpg?1562782879

It will generate a log like this:

Code: Select all
Zurgo Helmsmasher.jpg : scryfallurl/cards/normal/front/1/3/13f4bafe-0d21-47ba-8f16-0274107d618c.jpg?1562782879

If the file exists, then it will show the above message with the following:
File exists!

The reason I tried to clean up my code earlier was because when I compiled the first binary, I forgot to urlencode the card name, so anytime there is a space in a card name, it doesn't replace ' ' with '+', so scryfall only gets the first word in the multi-word card name.

Happy side effect of this is that it uses the first word as the keyword, and that not only matches the card you're looking for on scryfall, it also matches any cards that may have that string anywhere in the card name.

So this way, if on subsequent requests a certain card was already downloaded, it will inform you that it exists and not bother downloading it or saving it.

Within an hour I was able to download 6k images using only standard_all.txt standard edition cards.

It will show you the card image url, and the filename it was saved as. I came to this conclusion to save cards as 'Card Name.jpg' because in the Magarena folder I saw exactly that. /images/cards/ contained cards by their card name/title.

I've got /cards populated with card images from scryfall, named after the card name. Now, I just don't know how to use them. I mean, I drop them in the /cards folder in Magarena images folder, but when I play the game, no cards show up.

Can you advise how to manually download images like this and where to put them and how to get the card artwork to display while playing Magarena.

Thank you.

I hope someone finds this useful. Once the card images have been downloaded, I assume they can be used with any MTG engine that uses the format 'Card Name.jpg'

Cheers!

P.S I had to remove all the hypertext links etc. from the post otherwise it won't let me post. Just fill in the proper domain names and you're good to go.
hashborgir
 
Posts: 8
Joined: 13 Sep 2019, 23:54
Has thanked: 0 time
Been thanked: 1 time

Re: Bug reports for Magarena 1.95

Postby melvin » 14 Sep 2019, 01:22

@hashborgir Thanks for looking into this. We appreciate the help.

A permanent fix for this to update the image property of each script file in https://github.com/magarena/magarena/tr ... na/scripts to use the correct URL.

There is no mechanism to do that at the moment. Feel free to use any method to do this, just submit the changes to the scripts as a pull request on our project https://github.com/magarena/magarena
User avatar
melvin
AI Programmer
 
Posts: 1057
Joined: 21 Mar 2010, 12:26
Location: Singapore
Has thanked: 36 times
Been thanked: 456 times

Re: Bug reports for Magarena 1.95

Postby melvin » 14 Sep 2019, 01:29

I did a quick check, the cards are working correctly what does not work is the token images that uses magiccards.info

Does your method work for tokens as well? The list of tokens where images cannot be downloaded is https://github.com/magarena/magarena/issues/1626 (I've fixed some but not all of them in commits listed on the issue page).
User avatar
melvin
AI Programmer
 
Posts: 1057
Joined: 21 Mar 2010, 12:26
Location: Singapore
Has thanked: 36 times
Been thanked: 456 times

Re: Bug reports for Magarena 1.95

Postby hashborgir » 14 Sep 2019, 03:27

github/magarena/magarena/commit/54fb042aaedb166c725ac39bb209392d82e3a08c

image=scryfall/cards/border_crop/en/trtr/12.jpg?1517813031

these links are also broken.

I might try python because I can't get golang to do my bidding thus far.

I'll try to find a way to match tokens from the search page to scripts/tokenfilename.txt and edit that file and replace the image= line with the new image link

Wish me luck!
hashborgir
 
Posts: 8
Joined: 13 Sep 2019, 23:54
Has thanked: 0 time
Been thanked: 1 time

Re: Bug reports for Magarena 1.95

Postby hashborgir » 14 Sep 2019, 03:36

I didn't realize the images were working. When I saw (since a lot of token files begin with _) the tokens not being able to be downloaded, I assumed no card images could be downloaded at all, so I wrote that program in golang.

Downloading using my scraper is a lot faster! :) And you can fill in any images using keywords. So that's helpful.

Why are the token card images named in this fashion, different from Card Name.jpg?

What is 'Germ TMC2' and 'Germ TMCA'? These are the titles for when you search for Germ on scryfall. What do they mean? (Sorry it's been a long time since I played magic). Can we use these somehow Magarena so if my program downloads 'Germ (TMCA).jpg', then Magarena would use it in tokens for whatever TMCA means. I hope it's an abbreviation of abiliies or something. T for Token, C for creature, M for I dunno, A, I dunno. If not, we can figure out some other solution.

If it's not that many card images left to modify, then no need to automate it, once can probably just fix those manually.

It would be nice to grab token images from a scraper too and save in /images/tokens and have magarena use it.
hashborgir
 
Posts: 8
Joined: 13 Sep 2019, 23:54
Has thanked: 0 time
Been thanked: 1 time

Re: Bug reports for Magarena 1.95

Postby hashborgir » 14 Sep 2019, 03:44

image=scryfall/cards/large/en/tdom/4.jpg

I see when I search for cleric on scryfall, I see sryfall/cards/normal/front/7/4/74791ac4-7297-4731-aff8-20130da8b4b7.jpg?1562702134 with the title Cleric (TDOM)

for this card for example:
name=0/1 black Serf creature token
token=Serf
image=magiccardsinfo/extras/token/eternal-masters/serf.jpg

Here the card on scryfall shows up as 'Serf (TEMA)'. Possible match here is 'serf' case insensitive.

If we can figure out a better naming scheme for token files and what filenames the token file images are saved as for Magarena (in magarena source), we can easily match them up with the new naming convention on scryfall and easily download images.

Let me know what you think.

Thanks.
hashborgir
 
Posts: 8
Joined: 13 Sep 2019, 23:54
Has thanked: 0 time
Been thanked: 1 time

Re: Bug reports for Magarena 1.95

Postby hashborgir » 14 Sep 2019, 03:54

Also I am happy to report that even though Magarena is failing to download any card images at all, I dumped 15,000 card images in /cards and now I've got artwork for most of the premade decks and everything. Looking pretty nice! :)

That's right. So far I've managed to scrape together 15,000 card images from scryfall. Good googa mooga!
hashborgir
 
Posts: 8
Joined: 13 Sep 2019, 23:54
Has thanked: 0 time
Been thanked: 1 time

Re: Bug reports for Magarena 1.95

Postby melvin » 14 Sep 2019, 04:51

hashborgir wrote:Why are the token card images named in this fashion, different from Card Name.jpg?
Good question. The reason is that the image file names need to be unique but there are many tokens with the same name, for example there is a token that is a 5/5 green Beast creature and another one that is 5/5 green Beast creature with trample.

hashborgir wrote:What is 'Germ TMC2' and 'Germ TMCA'?
These are the set which the token is printed. e.g.
TCM2 = Commander Anthology Volume II Tokens

Generally if a token is printed in several sets, we use the most recent printing but it is not terribly important to follow this.

hashborgir wrote:I'll try to find a way to match tokens from the search page to scripts/tokenfilename.txt and edit that file and replace the image= line with the new image link

Wish me luck!
All the best!

Btw, do you have a github account? It is easier for me to keep track of replies on the issue page, https://github.com/magarena/magarena/issues/1626 compared to this forum thread and for other developers to find this discussion. Let's move further discussion to the issue page.
User avatar
melvin
AI Programmer
 
Posts: 1057
Joined: 21 Mar 2010, 12:26
Location: Singapore
Has thanked: 36 times
Been thanked: 456 times

Re: Bug reports for Magarena 1.95

Postby hashborgir » 14 Sep 2019, 08:58

Ok, I can try that on github, sure.

Just wrote a token downloader.

You can compile the following source code in golang in linux to get a `tokens' binary.

Code: Select all
package main

import (
    "fmt"
    "github/PuerkitoBio/goquery"
    "github/fatih/color"
    "io"
    "log"
   
    "net/url"
    "os"
    "strings"
)

func getCardData() {
  args := os.Args
  a := color.New(color.FgGreen).Add(color.Underline)
  b := color.New(color.FgBlue).Add(color.Underline)
  c := color.New(color.FgMagenta).Add(color.Underline)
  d := color.New(color.FgYellow, color.Bold)
  r := color.New(color.FgRed, color.Bold)
  if len(args) < 3 {
    a.Println("Example Usage:")
    b.Println("tokens 'Token Type' 'Filename to Save As'")
    r.Println("tokens 'Germ' '0_0_black_Germ_creature_token.jpg'");
    os.Exit(1);
  }

  name_of_card := os.Args[1] // name of card from command line

  url := fmt.Sprintf("scryfall/search?q=%v", url.QueryEscape(name_of_card))
  fmt.Println("Accessing: "+url) 
  doc, err := goquery.NewDocument(url)
  if err != nil {
    log.Fatal(err)
  }

  doc.Find("a.card-grid-item-card").Each(func(i int, s *goquery.Selection) {
    card_img_url, card_img_url_exists := s.Find("img.card").Attr("src")
    card_name := os.Args[2]
   
    if card_img_url_exists {
      downloadFile(card_img_url, card_name)
      d.Println(strings.TrimSpace(card_name))
      c.Println(strings.TrimSpace(card_img_url))
      fmt.Println()
    }
  })
}

func downloadFile(url string, filepath string){
  os.Mkdir("cards", os.ModePerm)
 
  // Get the data
  resp, err := http.Get(url) 
  if err != nil {
    fmt.Println("Error while downloading", url, "-", err)
  }
  defer resp.Body.Close()
 
  if fileExists(filepath){
    dir, err := os.Getwd()
    if err != nil {
      log.Fatal(err)
    }
   
    r := color.New(color.FgRed, color.Bold)
    r.Println(dir+"/"+filepath+" exists!")
  } else {
    // Create the file
    out, err := os.Create(filepath)
    if err != nil {
      fmt.Println("Error while creating", filepath, "-", err)
    }
    defer out.Close()
   
    // Write the body to file
    _, err = io.Copy(out, resp.Body) 
    if err != nil {
      fmt.Println("Error while writing file data", filepath, "-", err)
    }
  }
}

func fileExists(filename string) bool {
  info, err := os.Stat(filename)
  if os.IsNotExist(err) {
    return false
  }
  return !info.IsDir()
}

func main() {
  getCardData()
}

I had to do some regex magic and extract the subtype= line from each of the *token* files in /scripts.

Then we can run my program like so:

Code: Select all

tokens '++is:token Elemental' '/home/stoned/bin/Magarena-1.95/Magarena/images/tokens/3_1_red_Elemental_creature_token_with_haste.jpg'
tokens '++is:token Elemental' '/home/stoned/bin/Magarena-1.95/Magarena/images/tokens/3_1_red_Elemental_creature_token_with_trample_and_haste.jpg'
tokens '++is:token Elemental' '/home/stoned/bin/Magarena-1.95/Magarena/images/tokens/3_1_red_Elemental_enchantment_creature_token_with_haste.jpg'
/home/stoned/bin/Magarena-1.95/Magarena/images/
Looks like I was able to grab generic token images. Not specific. Drop them in the /tokens folder and hopefully some of them should work.

Once I figure out some more stuff about Magarena, I'd be happy to fix some bugs and code some new features.
hashborgir
 
Posts: 8
Joined: 13 Sep 2019, 23:54
Has thanked: 0 time
Been thanked: 1 time

Re: Bug reports for Magarena 1.95

Postby hashborgir » 14 Sep 2019, 09:01

I'll read these but I'm going to see you on Github.
Last edited by hashborgir on 14 Sep 2019, 15:54, edited 1 time in total.
hashborgir
 
Posts: 8
Joined: 13 Sep 2019, 23:54
Has thanked: 0 time
Been thanked: 1 time

Re: Bug reports for Magarena 1.95

Postby hashborgir » 14 Sep 2019, 09:03

Please make the forums more usable for new users. Not being able to share links to offsite resources makes it harder.

Thank you.

Happy to report all the token images are now working for me too. I just had to write a program to grab the tokens, parse for subtype, search for subtype on scryfall, grab image, and save as desired filename.

Grabbed all the tokens in one go.

Code is up there, but had to remove some stuff due to this new user restriction. Let me know if anyone needs help. I'll be on github.
Last edited by hashborgir on 16 Sep 2019, 00:17, edited 1 time in total.
hashborgir
 
Posts: 8
Joined: 13 Sep 2019, 23:54
Has thanked: 0 time
Been thanked: 1 time

Re: Bug reports for Magarena 1.95

Postby muaddib » 09 Oct 2019, 06:39

Creature doesn't return on battlefield after Fairgrounds Warden leaves play (Fairgrounds Warden was exiled).
User avatar
muaddib
Tester
 
Posts: 113
Joined: 03 Mar 2011, 08:37
Location: Russia
Has thanked: 0 time
Been thanked: 1 time

Re: Bug reports for Magarena 1.95

Postby Huggybaby » 16 Oct 2019, 03:02

hashborgir wrote:Please make the forums more usable for new users. Not being able to share links to offsite resources makes it harder.

Thank you.

Happy to report all the token images are now working for me too. I just had to write a program to grab the tokens, parse for subtype, search for subtype on scryfall, grab image, and save as desired filename.

Grabbed all the tokens in one go.

Code is up there, but had to remove some stuff due to this new user restriction. Let me know if anyone needs help. I'll be on github.
First of all, thanks for contributing hashborgir, this is good stuff. 8)

We have a five posts restriction. (I think.) After that you can post anything you like. If not, you can PM me, or GoblinHero, and we will fix it.
The restrictions for early posting are unfortunate, but are from experience: I, just now, deleted a spambot, who had posted 150 times, since I had last checked my email. This isn't common...nor, sadly, is it uncommon.

Thanks again!
User avatar
Huggybaby
Administrator
 
Posts: 3089
Joined: 15 Jan 2006, 19:44
Location: Finally out of Atlanta
Has thanked: 588 times
Been thanked: 574 times


Return to Magarena

Who is online

Users browsing this forum: No registered users and 1 guest


Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 10 minutes)
Most users ever online was 546 on 15 Nov 2019, 10:18

Users browsing this forum: No registered users and 1 guest

Login Form