# Debugging a scanner

**URL:** <https://forums.plex.tv/t/debugging-a-scanner/58126>\
**Category:** Dev/API Corner\
**Tags:** scanner-agent-dev\
**Created:** [February 22, 2014, 7:32am UTC](https://forums.plex.tv/t/debugging-a-scanner/58126 "2014-02-22T07:32:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jesperordrup](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/jesperordrup/32/138174_2.png) [@jesperordrup](https://forums.plex.tv/u/jesperordrup)\
**Post date:** [February 22, 2014, 7:32am UTC](https://forums.plex.tv/t/debugging-a-scanner/58126/1 "2014-02-22T07:32:03Z")

</div>

How do you debug a scanner?

&nbsp;

Ive tried

&nbsp; &nbsp;Log.Debug('asdfasfdasdf')

&nbsp; &nbsp;Log('asdfasfdasdf')

&nbsp; &nbsp;

Both breaks the scanner and in the Plex Media scanner.log this appears:

&nbsp;

NameError: global name 'Log' is not defined

&nbsp;

I've also tried

&nbsp;

print('asdfasfdasdf')

&nbsp;

Which doesnt break anything but I cant find the output in any logs.

&nbsp;

best

Jesper

&nbsp;

ps. OSX

---

<div class="post-metadata">

**Author:** ![mmccurdy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mmccurdy/32/83290_2.png) [@mmccurdy](https://forums.plex.tv/u/mmccurdy)\
**Post date:** [March 4, 2014, 3:21pm UTC](https://forums.plex.tv/t/debugging-a-scanner/58126/2 "2014-03-04T15:21:31Z")

</div>

The Scanner does not run under the same plugin framework as everything else so ("Log()" won't work in that context). &nbsp;The best way to debug is probably to run the scanner from the command line and use regular print statements or logging as you already tried.

Here's some more info on how to do that:&nbsp;[https://plexapp.zendesk.com/hc/en-us/articles/201242707-Plex-Media-Scanner-via-Command-Line](https://plexapp.zendesk.com/hc/en-us/articles/201242707-Plex-Media-Scanner-via-Command-Line)

---

<div class="post-metadata">

**Author:** ![doublerebel](https://avatars.discourse-cdn.com/v4/letter/d/90ced4/32.png) [@doublerebel](https://forums.plex.tv/u/doublerebel)\
**Post date:** [April 27, 2014, 8:35pm UTC](https://forums.plex.tv/t/debugging-a-scanner/58126/3 "2014-04-27T20:35:36Z")

</div>

Here's how to run a scan script under the command line:

1. Change to the directory where the scan script is saved

```
$ cd /home/plex/Library/Application Support/Plex Media Server/Scanners/Movies/
```

2. &nbsp;Run the scan script with the library path set

```
$ PYTHONPATH=/var/lib/plexmediaserver/Resources/Plug-ins/Scanners.bundle/Contents/Resources/Common python2 Plex\ Series\ Scanner\ \(with\ disc\ image\ support\).py /path/to/test/with/scanner
```

Make sure not to put a trailing slash on the /path/to/test/with/scanner ! _(i.e. don't do /path/to/test/with/scanner/ )_

In the case of the Series scanner, I had to cut the \_\_main\_\_ code and post it at the end so it could find all the functions. &nbsp;Haven't gotten my scanner working quite right yet but that's another story...

---

<div class="post-metadata">

**Author:** ![johandw](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@johandw](https://forums.plex.tv/u/johandw)\
**Post date:** [September 22, 2014, 8:51am UTC](https://forums.plex.tv/t/debugging-a-scanner/58126/4 "2014-09-22T08:51:58Z")

</div>

Hi,

I wrote a very simplistic scanner for my dreambox recordings, which you can get here :&nbsp; [https://github.com/witjoh/enigma2\_dreambox\_scanner](https://github.com/witjoh/enigma2_dreambox_scanner)

Seems the scanning does work a bit, the movies are detected, but the metadata gathering does not use the name/year i thought I was passing using the mediaList array.&nbsp; But that's something I need to work out how this really works.

Whenever you do a force refresh, the /tmp/scanners.dbg will be overwritten.&nbsp; The output will be truncated whenever you will have an error in the code.

---

<div class="post-metadata">

**Author:** ![ZeroQI](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/zeroqi/32/6522_2.png) [@ZeroQI](https://forums.plex.tv/u/ZeroQI)\
**Post date:** [September 30, 2014, 9:15am UTC](https://forums.plex.tv/t/debugging-a-scanner/58126/5 "2014-09-30T09:15:38Z")

</div>

In my "Absolute Series Scanner" i implemented an output to a custom log (which i saw in another scanner thread), the only issue is that the path differs depending the OS, but does output logs like:

```
================================================================================
Scan: (root: 'G:\Anime', path='Zettai Karen Children', subdirs: ['G:\\Anime\\Zettai Karen Children\\metadata'], language: 'en')
From folder, show: 'Zettai Karen Children', year: 'None'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 1 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E01 Paranormal Jailbreak Schooler of Deadlock' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E01.Paranormal.Jailbreak.Schooler.of.Deadlock.mkv'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 2 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E02 The Melody of Assassination Ghost of WW2' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E02.The.Melody.of.Assassination.Ghost.of.WW2.mkv'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 3 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E03 Cleanliness and Pollution' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E03.Cleanliness.and.Pollution.mkv'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 4 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E04 Absolute Domain Children Territory' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E04.Absolute.Domain.Children.Territory.mkv'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 5 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E05 Strangers Portrait of the family' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E05.Strangers.Portrait.of.the.family.mkv'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 6 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E06 As True as a Lie' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E06.As.True.as.a.Lie.mkv'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 7 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E07 Generation Zero Part 1' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E07.Generation.Zero.Part.1.mkv'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 8 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E08 Generation Zero Part 2' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E08.Generation.Zero.Part.2.mkv'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 9 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E09 Catastrophe Pandoras box opens' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E09.Catastrophe.Pandoras.box.opens.mkv'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 10 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E10 Distant Paradise Original Sin' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E10.Distant.Paradise.Original.Sin.mkv'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 11 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E11 The Two Within the Storm Outlaws' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E11.The.Two.Within.the.Storm.Outlaws.mkv'
show: 'The Unlimited Hyoubu Kyousuke ', year: 'None', season: '01', ep: 12 found using standalone_episode_re_findall on cleaned string 'The Unlimited Hyoubu Kyousuke S01E12 To The Future Last Revolution' gotten from filename 'The.Unlimited.Hyoubu.Kyousuke.S01E12.To.The.Future.Last.Revolution.mkv'
```

&nbsp;

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [December 21, 2019, 1:23am UTC](https://forums.plex.tv/t/debugging-a-scanner/58126/6 "2019-12-21T01:23:53Z")

</div>

Closed on December 21, 2019, 1:23am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
