import click
import youtube_dl

from .config import storage_load
from .extractor import RdioIE

@click.command()
@click.option(u'-u', u'--user', help=u'A Rdio user')
@click.option(u'-p', u'--password', help=u'The password')
@click.argument(u'urls', required=True, nargs=-1)
def main(user, password, urls):
    storage = storage_load()
    with youtube_dl.YoutubeDL() as ydl:
        ydl.add_info_extractor(RdioIE(storage, user, password))
        ydl.download(urls)

import click
import youtube_dl

from .config import storage_load
from .extractor import RdioIE


def add_info_extractor_above_generic(ydl, ie):
    generic = ydl._ies.pop()
    ydl.add_info_extractor(ie)
    ydl.add_info_extractor(generic)


@click.command()
@click.option(u'-u', u'--user', help=u'A Rdio user')
@click.option(u'-p', u'--password', help=u'The password')
@click.argument(u'urls', required=True, nargs=-1)
def main(user, password, urls):
    storage = storage_load()
    with youtube_dl.YoutubeDL() as ydl:
        add_info_extractor_above_generic(ydl, RdioIE(storage, user, password))
        ydl.download(urls)

Fix generic extractor being always selected
Fix generic extractor being always selected

Turns out our extractor was being inserted *after* the GenericIE.
Now we are inserting our RdioIE right above GenericIE.

  import click
  import youtube_dl
  
  from .config import storage_load
  from .extractor import RdioIE
+ 
+ 
+ def add_info_extractor_above_generic(ydl, ie):
+     generic = ydl._ies.pop()
+     ydl.add_info_extractor(ie)
+     ydl.add_info_extractor(generic)
+ 
  
  @click.command()
  @click.option(u'-u', u'--user', help=u'A Rdio user')
  @click.option(u'-p', u'--password', help=u'The password')
  @click.argument(u'urls', required=True, nargs=-1)
  def main(user, password, urls):
      storage = storage_load()
      with youtube_dl.YoutubeDL() as ydl:
-         ydl.add_info_extractor(RdioIE(storage, user, password))
+         add_info_extractor_above_generic(ydl, RdioIE(storage, user, password))
          ydl.download(urls)
  
Fix generic extractor being always selected
## Code Before:
import click
import youtube_dl

from .config import storage_load
from .extractor import RdioIE

@click.command()
@click.option(u'-u', u'--user', help=u'A Rdio user')
@click.option(u'-p', u'--password', help=u'The password')
@click.argument(u'urls', required=True, nargs=-1)
def main(user, password, urls):
    storage = storage_load()
    with youtube_dl.YoutubeDL() as ydl:
        ydl.add_info_extractor(RdioIE(storage, user, password))
        ydl.download(urls)

## Instruction:
Fix generic extractor being always selected
## Code After:
import click
import youtube_dl

from .config import storage_load
from .extractor import RdioIE


def add_info_extractor_above_generic(ydl, ie):
    generic = ydl._ies.pop()
    ydl.add_info_extractor(ie)
    ydl.add_info_extractor(generic)


@click.command()
@click.option(u'-u', u'--user', help=u'A Rdio user')
@click.option(u'-p', u'--password', help=u'The password')
@click.argument(u'urls', required=True, nargs=-1)
def main(user, password, urls):
    storage = storage_load()
    with youtube_dl.YoutubeDL() as ydl:
        add_info_extractor_above_generic(ydl, RdioIE(storage, user, password))
        ydl.download(urls)
